This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Author: Darren Schnare | |
// Keywords: aop,aspect,oriented,programming,javascript,pointcut | |
// License: MIT ( http://www.opensource.org/licenses/mit-license.php ) | |
// Repo: https://gist.github.com/1235559 | |
// Inspiration: http://karlagius.com/2008/04/25/aspect-oriented-programming-in-javascript/ | |
// Reference: http://docs.jboss.org/jbossaop/docs/2.0.0.GA/docs/aspect-framework/reference/en/html/advices.html | |
// Reference: http://static.springsource.org/spring/docs/2.0.x/reference/aop.html | |
// Appends the aop namespace to the specified scope (defaults to global). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Author: Darren Schnare | |
// Keywords: javascript,equality,testing,equals,object | |
// License: MIT ( http://www.opensource.org/licenses/mit-license.php ) | |
// Repo: https://gist.github.com/1251001 | |
// Creates an equals function within the specified scope. | |
(function(scope) { | |
// Determines if two objects have the same values. This is a | |
// recursive test that tests all objects through out the object | |
// tree. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Simple EcmaScript templating system. | |
* | |
* Templates are just functions that accept an object of | |
* properties and return a string. | |
* | |
* const Hello = (props = {}) => ` | |
* Hello ${props.message || 'World'}! | |
* ` | |
* console.log(Hello({ message: 'Mom' })) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Copyright 2020 Darren Schnare | |
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Read a command line option. Option names must start with '-'. | |
* | |
* Options: | |
* | |
* `required` Determines if the option must appear on the command line. | |
* | |
* `multi` Determines if the option can be specified more than once on the | |
* command line. Causes the return value to be an array. | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get the type name for a value. | |
* | |
* @example type(null) // 'Null' | |
* @example type(undefined) // 'Undefined' | |
* @example type(45) // 'Number' | |
* @example type('Hello') // 'String' | |
* @example type({}) // 'Object' | |
* @example type(/hi/) // 'RegExp' | |
* @example type(new Date()) // 'Date' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const check = (type, value) => { | |
if (typeof type !== 'string') { | |
throw new TypeError('Argument "type" must be a string') | |
} | |
const optional = /!\??$/.test(type) | |
const nullable = /\?!?$/.test(type) | |
type = type.replace(/!$|\?$/g, '').trim() | |
if (['null', 'undefined', ''].includes(type.toLowerCase())) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create our stage canvas. | |
var stage = document.createElement('canvas'); | |
stage.style.border = '1px solid #000'; | |
document.body.appendChild(stage); | |
// Create offscreen buffer for our text rendering. | |
// This way all we have to do is draw our buffer to | |
// the main canvas rather than drawing text each frame. | |
var textBuffer = document.createElement('canvas'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Business Object class object that acts as the root of an object hierarchy. | |
* Creates object instances that have methods marked as read-only and the object | |
* sealed, meaning no new properties can be added and behaviour cannot be changed | |
* without extending the class object (i.e. tamperproof). | |
* | |
* @example | |
* const Box = BObject.subClass({ | |
* className: 'Box', | |
* new ($base, width, height) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function validate (value, validators, message = 'Invalid value') { | |
validators = [].concat(validators) | |
if (typeof message !== 'string') { | |
throw Object.assign( | |
new Error('Argument "message" must be a string'), | |
{ | |
name: 'ArgumentError', | |
propertyName: 'message', | |
propertyValue: message | |
} |
NewerOlder