This file contains hidden or 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 stringTypePlugin (validator) { | |
| return function () { | |
| validator.add(function (metadata) { | |
| return metadata.type === 'string'; | |
| }, function (value) { | |
| return typeof value === 'string'; | |
| }) | |
| }; | |
| } |
This file contains hidden or 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
| import loadImage from 'load-image.js' | |
| /** | |
| * load images | |
| * @param {Array<String>} urls Images' urls | |
| * @promise {Array<Image>} | |
| **/ | |
| export default function loadImages (urls) { | |
| return Promise.all(urls.map(loadImage)) | |
| } |
This file contains hidden or 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
| // string -> Promise Image | |
| export function loadImage(url) { | |
| var image = new Image(); | |
| var promise = waitImage(image); | |
| image.src = url; | |
| return promise; | |
| } |
This file contains hidden or 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
| import {normalize} from 'path'; | |
| export default ResourcePath; | |
| function ResourcePath (value) { | |
| this.value = normalize(value); | |
| } | |
| ResourcePath.prototype.add = function () { | |
| var result = this.value; |
This file contains hidden or 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
| macro (enum) { | |
| rule { | |
| $name:ident (,) ... | |
| } => { | |
| Object.freeze({ | |
| $($name: {}) (,) ... | |
| }) | |
| } | |
| } |
This file contains hidden or 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
| let (delete) = macro { | |
| rule { $path:ident } => { } | |
| } | |
| macro (delete!) { | |
| rule { | |
| $path:ident | |
| } => { | |
| } |
This file contains hidden or 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
| var short = 'hello'; | |
| var long = 'hello world'; | |
| var result = ''; | |
| for (var i = -1, l = long.length; ++i < l;) { | |
| console.log(i % short.length); | |
| result += short[i % short.length]; | |
| } | |
| console.log(result); |
This file contains hidden or 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
| import workify from 'workify.js' | |
| function log (error, it) { | |
| if (error) throw error; | |
| console.log(it); | |
| } | |
| toLowerCase = workify(function (it) { return it.toLowerCase(); }); | |
| toLowerCase('HELLO', log); |
This file contains hidden or 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
| var inherit = require('inherit'); | |
| module.exports = AbstractError; | |
| inherit(AbstractError, Error) | |
| function AbstractError (message) { | |
| this.message = message; | |
| this.stack = (new Error()).stack; | |
| } |
This file contains hidden or 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
| module.exports = Something; | |
| function Something () {} | |
| Something.prototype.toJSON = function () { | |
| var clone = {}; | |
| var firstChar; | |
| var that = this; | |
| Object.keys(this).forEach(function (key) { | |
| var firstChar = key[0]; |