id
int32
0
58k
repo
stringlengths
5
67
path
stringlengths
4
116
func_name
stringlengths
0
58
original_string
stringlengths
52
373k
language
stringclasses
1 value
code
stringlengths
52
373k
code_tokens
list
docstring
stringlengths
4
11.8k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
86
226
44,000
WebReflection/es-class
build/es-class.max.amd.js
addMixins
function addMixins(mixins, target, inherits, isNOTExtendingNative) { for (var source, init = [], i = 0; i < mixins.length; i++ ) { source = transformMixin(mixins[i]); if (hOP.call(source, INIT)) { init.push(source[INIT]); } copyOwn(source, target, inherits, false, false, isNOTExtendingNative); } return init; }
javascript
function addMixins(mixins, target, inherits, isNOTExtendingNative) { for (var source, init = [], i = 0; i < mixins.length; i++ ) { source = transformMixin(mixins[i]); if (hOP.call(source, INIT)) { init.push(source[INIT]); } copyOwn(source, target, inherits, false, false, isNOTExtendingNative); } return init; }
[ "function", "addMixins", "(", "mixins", ",", "target", ",", "inherits", ",", "isNOTExtendingNative", ")", "{", "for", "(", "var", "source", ",", "init", "=", "[", "]", ",", "i", "=", "0", ";", "i", "<", "mixins", ".", "length", ";", "i", "++", ")", "{", "source", "=", "transformMixin", "(", "mixins", "[", "i", "]", ")", ";", "if", "(", "hOP", ".", "call", "(", "source", ",", "INIT", ")", ")", "{", "init", ".", "push", "(", "source", "[", "INIT", "]", ")", ";", "}", "copyOwn", "(", "source", ",", "target", ",", "inherits", ",", "false", ",", "false", ",", "isNOTExtendingNative", ")", ";", "}", "return", "init", ";", "}" ]
copy all imported enumerable methods and properties
[ "copy", "all", "imported", "enumerable", "methods", "and", "properties" ]
8e3f3b65a67955d11e15820e8f44e2cdaac4bd50
https://github.com/WebReflection/es-class/blob/8e3f3b65a67955d11e15820e8f44e2cdaac4bd50/build/es-class.max.amd.js#L219-L232
44,001
WebReflection/es-class
build/es-class.max.amd.js
copyMerged
function copyMerged(source, target) { for (var key, descriptor, value, tvalue, names = oK(source), i = 0; i < names.length; i++ ) { key = names[i]; descriptor = gOPD(source, key); // target already has this property if (hOP.call(target, key)) { // verify the descriptor can be merged if (hOP.call(descriptor, VALUE)) { value = descriptor[VALUE]; // which means, verify it's an object if (isObject(value)) { // in such case, verify the target can be modified descriptor = gOPD(target, key); // meaning verify it's a data descriptor if (hOP.call(descriptor, VALUE)) { tvalue = descriptor[VALUE]; // and it's actually an object if (isObject(tvalue)) { copyMerged(value, tvalue); } } } } } else { // target has no property at all if (hOP.call(descriptor, VALUE)) { // copy deep if it's an object copyValueIfObject(descriptor, copyDeep); } defineProperty(target, key, descriptor); } } }
javascript
function copyMerged(source, target) { for (var key, descriptor, value, tvalue, names = oK(source), i = 0; i < names.length; i++ ) { key = names[i]; descriptor = gOPD(source, key); // target already has this property if (hOP.call(target, key)) { // verify the descriptor can be merged if (hOP.call(descriptor, VALUE)) { value = descriptor[VALUE]; // which means, verify it's an object if (isObject(value)) { // in such case, verify the target can be modified descriptor = gOPD(target, key); // meaning verify it's a data descriptor if (hOP.call(descriptor, VALUE)) { tvalue = descriptor[VALUE]; // and it's actually an object if (isObject(tvalue)) { copyMerged(value, tvalue); } } } } } else { // target has no property at all if (hOP.call(descriptor, VALUE)) { // copy deep if it's an object copyValueIfObject(descriptor, copyDeep); } defineProperty(target, key, descriptor); } } }
[ "function", "copyMerged", "(", "source", ",", "target", ")", "{", "for", "(", "var", "key", ",", "descriptor", ",", "value", ",", "tvalue", ",", "names", "=", "oK", "(", "source", ")", ",", "i", "=", "0", ";", "i", "<", "names", ".", "length", ";", "i", "++", ")", "{", "key", "=", "names", "[", "i", "]", ";", "descriptor", "=", "gOPD", "(", "source", ",", "key", ")", ";", "// target already has this property", "if", "(", "hOP", ".", "call", "(", "target", ",", "key", ")", ")", "{", "// verify the descriptor can be merged", "if", "(", "hOP", ".", "call", "(", "descriptor", ",", "VALUE", ")", ")", "{", "value", "=", "descriptor", "[", "VALUE", "]", ";", "// which means, verify it's an object", "if", "(", "isObject", "(", "value", ")", ")", "{", "// in such case, verify the target can be modified", "descriptor", "=", "gOPD", "(", "target", ",", "key", ")", ";", "// meaning verify it's a data descriptor", "if", "(", "hOP", ".", "call", "(", "descriptor", ",", "VALUE", ")", ")", "{", "tvalue", "=", "descriptor", "[", "VALUE", "]", ";", "// and it's actually an object", "if", "(", "isObject", "(", "tvalue", ")", ")", "{", "copyMerged", "(", "value", ",", "tvalue", ")", ";", "}", "}", "}", "}", "}", "else", "{", "// target has no property at all", "if", "(", "hOP", ".", "call", "(", "descriptor", ",", "VALUE", ")", ")", "{", "// copy deep if it's an object", "copyValueIfObject", "(", "descriptor", ",", "copyDeep", ")", ";", "}", "defineProperty", "(", "target", ",", "key", ",", "descriptor", ")", ";", "}", "}", "}" ]
given two objects, performs a deep copy per each property not present in the target otherwise merges, without overwriting, all properties within the object
[ "given", "two", "objects", "performs", "a", "deep", "copy", "per", "each", "property", "not", "present", "in", "the", "target", "otherwise", "merges", "without", "overwriting", "all", "properties", "within", "the", "object" ]
8e3f3b65a67955d11e15820e8f44e2cdaac4bd50
https://github.com/WebReflection/es-class/blob/8e3f3b65a67955d11e15820e8f44e2cdaac4bd50/build/es-class.max.amd.js#L256-L292
44,002
WebReflection/es-class
build/es-class.max.amd.js
copyOwn
function copyOwn(source, target, inherits, publicStatic, allowInit, isNOTExtendingNative) { for (var key, noFunctionCheck = typeof source !== 'function', names = oK(source), i = 0; i < names.length; i++ ) { key = names[i]; if ( (noFunctionCheck || indexOf.call(nativeFunctionOPN, key) < 0) && isNotASpecialKey(key, allowInit) ) { if (hOP.call(target, key)) { warn('duplicated: ' + key.toString()); } setProperty(inherits, target, key, gOPD(source, key), publicStatic, isNOTExtendingNative); } } }
javascript
function copyOwn(source, target, inherits, publicStatic, allowInit, isNOTExtendingNative) { for (var key, noFunctionCheck = typeof source !== 'function', names = oK(source), i = 0; i < names.length; i++ ) { key = names[i]; if ( (noFunctionCheck || indexOf.call(nativeFunctionOPN, key) < 0) && isNotASpecialKey(key, allowInit) ) { if (hOP.call(target, key)) { warn('duplicated: ' + key.toString()); } setProperty(inherits, target, key, gOPD(source, key), publicStatic, isNOTExtendingNative); } } }
[ "function", "copyOwn", "(", "source", ",", "target", ",", "inherits", ",", "publicStatic", ",", "allowInit", ",", "isNOTExtendingNative", ")", "{", "for", "(", "var", "key", ",", "noFunctionCheck", "=", "typeof", "source", "!==", "'function'", ",", "names", "=", "oK", "(", "source", ")", ",", "i", "=", "0", ";", "i", "<", "names", ".", "length", ";", "i", "++", ")", "{", "key", "=", "names", "[", "i", "]", ";", "if", "(", "(", "noFunctionCheck", "||", "indexOf", ".", "call", "(", "nativeFunctionOPN", ",", "key", ")", "<", "0", ")", "&&", "isNotASpecialKey", "(", "key", ",", "allowInit", ")", ")", "{", "if", "(", "hOP", ".", "call", "(", "target", ",", "key", ")", ")", "{", "warn", "(", "'duplicated: '", "+", "key", ".", "toString", "(", ")", ")", ";", "}", "setProperty", "(", "inherits", ",", "target", ",", "key", ",", "gOPD", "(", "source", ",", "key", ")", ",", "publicStatic", ",", "isNOTExtendingNative", ")", ";", "}", "}", "}" ]
configure source own properties in the target
[ "configure", "source", "own", "properties", "in", "the", "target" ]
8e3f3b65a67955d11e15820e8f44e2cdaac4bd50
https://github.com/WebReflection/es-class/blob/8e3f3b65a67955d11e15820e8f44e2cdaac4bd50/build/es-class.max.amd.js#L295-L313
44,003
WebReflection/es-class
build/es-class.max.amd.js
copyValueIfObject
function copyValueIfObject(where, how) { var what = where[VALUE]; if (isObject(what)) { where[VALUE] = how(what); } }
javascript
function copyValueIfObject(where, how) { var what = where[VALUE]; if (isObject(what)) { where[VALUE] = how(what); } }
[ "function", "copyValueIfObject", "(", "where", ",", "how", ")", "{", "var", "what", "=", "where", "[", "VALUE", "]", ";", "if", "(", "isObject", "(", "what", ")", ")", "{", "where", "[", "VALUE", "]", "=", "how", "(", "what", ")", ";", "}", "}" ]
shortcut to copy objects into descriptor.value
[ "shortcut", "to", "copy", "objects", "into", "descriptor", ".", "value" ]
8e3f3b65a67955d11e15820e8f44e2cdaac4bd50
https://github.com/WebReflection/es-class/blob/8e3f3b65a67955d11e15820e8f44e2cdaac4bd50/build/es-class.max.amd.js#L316-L321
44,004
WebReflection/es-class
build/es-class.max.amd.js
createConstructor
function createConstructor(hasParentPrototype, parent) { var Class = function Class() {}; return hasParentPrototype && ('' + parent) !== ('' + Class) ? function Class() { return parent.apply(this, arguments); } : Class ; }
javascript
function createConstructor(hasParentPrototype, parent) { var Class = function Class() {}; return hasParentPrototype && ('' + parent) !== ('' + Class) ? function Class() { return parent.apply(this, arguments); } : Class ; }
[ "function", "createConstructor", "(", "hasParentPrototype", ",", "parent", ")", "{", "var", "Class", "=", "function", "Class", "(", ")", "{", "}", ";", "return", "hasParentPrototype", "&&", "(", "''", "+", "parent", ")", "!==", "(", "''", "+", "Class", ")", "?", "function", "Class", "(", ")", "{", "return", "parent", ".", "apply", "(", "this", ",", "arguments", ")", ";", "}", ":", "Class", ";", "}" ]
return the right constructor analyzing the parent. if the parent is empty there is no need to call it.
[ "return", "the", "right", "constructor", "analyzing", "the", "parent", ".", "if", "the", "parent", "is", "empty", "there", "is", "no", "need", "to", "call", "it", "." ]
8e3f3b65a67955d11e15820e8f44e2cdaac4bd50
https://github.com/WebReflection/es-class/blob/8e3f3b65a67955d11e15820e8f44e2cdaac4bd50/build/es-class.max.amd.js#L326-L334
44,005
WebReflection/es-class
build/es-class.max.amd.js
define
function define(target, key, value, publicStatic) { var configurable = isConfigurable(key, publicStatic); defineProperty(target, key, { enumerable: false, // was: publicStatic, configurable: configurable, writable: configurable, value: value }); }
javascript
function define(target, key, value, publicStatic) { var configurable = isConfigurable(key, publicStatic); defineProperty(target, key, { enumerable: false, // was: publicStatic, configurable: configurable, writable: configurable, value: value }); }
[ "function", "define", "(", "target", ",", "key", ",", "value", ",", "publicStatic", ")", "{", "var", "configurable", "=", "isConfigurable", "(", "key", ",", "publicStatic", ")", ";", "defineProperty", "(", "target", ",", "key", ",", "{", "enumerable", ":", "false", ",", "// was: publicStatic,", "configurable", ":", "configurable", ",", "writable", ":", "configurable", ",", "value", ":", "value", "}", ")", ";", "}" ]
common defineProperty wrapper
[ "common", "defineProperty", "wrapper" ]
8e3f3b65a67955d11e15820e8f44e2cdaac4bd50
https://github.com/WebReflection/es-class/blob/8e3f3b65a67955d11e15820e8f44e2cdaac4bd50/build/es-class.max.amd.js#L337-L345
44,006
WebReflection/es-class
build/es-class.max.amd.js
isNotASpecialKey
function isNotASpecialKey(key, allowInit) { return key !== CONSTRUCTOR && key !== EXTENDS && key !== IMPLEMENTS && // Blackberry 7 and old WebKit bug only: // user defined functions have // enumerable prototype and constructor key !== PROTOTYPE && key !== STATIC && key !== SUPER && key !== WITH && (allowInit || key !== INIT); }
javascript
function isNotASpecialKey(key, allowInit) { return key !== CONSTRUCTOR && key !== EXTENDS && key !== IMPLEMENTS && // Blackberry 7 and old WebKit bug only: // user defined functions have // enumerable prototype and constructor key !== PROTOTYPE && key !== STATIC && key !== SUPER && key !== WITH && (allowInit || key !== INIT); }
[ "function", "isNotASpecialKey", "(", "key", ",", "allowInit", ")", "{", "return", "key", "!==", "CONSTRUCTOR", "&&", "key", "!==", "EXTENDS", "&&", "key", "!==", "IMPLEMENTS", "&&", "// Blackberry 7 and old WebKit bug only:", "// user defined functions have", "// enumerable prototype and constructor", "key", "!==", "PROTOTYPE", "&&", "key", "!==", "STATIC", "&&", "key", "!==", "SUPER", "&&", "key", "!==", "WITH", "&&", "(", "allowInit", "||", "key", "!==", "INIT", ")", ";", "}" ]
verifies a key is not special for the class
[ "verifies", "a", "key", "is", "not", "special", "for", "the", "class" ]
8e3f3b65a67955d11e15820e8f44e2cdaac4bd50
https://github.com/WebReflection/es-class/blob/8e3f3b65a67955d11e15820e8f44e2cdaac4bd50/build/es-class.max.amd.js#L364-L376
44,007
WebReflection/es-class
build/es-class.max.amd.js
isPublicStatic
function isPublicStatic(key) { for(var c, i = 0; i < key.length; i++) { c = key.charCodeAt(i); if ((c < 65 || 90 < c) && c !== 95) { return false; } } return true; }
javascript
function isPublicStatic(key) { for(var c, i = 0; i < key.length; i++) { c = key.charCodeAt(i); if ((c < 65 || 90 < c) && c !== 95) { return false; } } return true; }
[ "function", "isPublicStatic", "(", "key", ")", "{", "for", "(", "var", "c", ",", "i", "=", "0", ";", "i", "<", "key", ".", "length", ";", "i", "++", ")", "{", "c", "=", "key", ".", "charCodeAt", "(", "i", ")", ";", "if", "(", "(", "c", "<", "65", "||", "90", "<", "c", ")", "&&", "c", "!==", "95", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
verifies the entire string is upper case and contains eventually an underscore used to avoid RegExp for non RegExp aware environment
[ "verifies", "the", "entire", "string", "is", "upper", "case", "and", "contains", "eventually", "an", "underscore", "used", "to", "avoid", "RegExp", "for", "non", "RegExp", "aware", "environment" ]
8e3f3b65a67955d11e15820e8f44e2cdaac4bd50
https://github.com/WebReflection/es-class/blob/8e3f3b65a67955d11e15820e8f44e2cdaac4bd50/build/es-class.max.amd.js#L387-L395
44,008
WebReflection/es-class
build/es-class.max.amd.js
transformMixin
function transformMixin(trait) { if (isObject(trait)) return trait; else { var i, key, keys, object, proto; if (trait.isClass) { if (trait.length) { warn((trait.name || 'Class') + ' should not expect arguments'); } for ( object = {init: trait}, proto = trait.prototype; proto && proto !== Object.prototype; proto = gPO(proto) ) { for (i = 0, keys = oK(proto); i < keys.length; i++) { key = keys[i]; if (isNotASpecialKey(key, false) && !hOP.call(object, key)) { defineProperty(object, key, gOPD(proto, key)); } } } } else { for ( i = 0, object = {}, proto = trait({}), keys = oK(proto); i < keys.length; i++ ) { key = keys[i]; if (key !== INIT) { // if this key is the mixin one if (~key.toString().indexOf('mixin:init') && isArray(proto[key])) { // set the init simply as own method object.init = proto[key][0]; } else { // simply assign the descriptor defineProperty(object, key, gOPD(proto, key)); } } } } return object; } }
javascript
function transformMixin(trait) { if (isObject(trait)) return trait; else { var i, key, keys, object, proto; if (trait.isClass) { if (trait.length) { warn((trait.name || 'Class') + ' should not expect arguments'); } for ( object = {init: trait}, proto = trait.prototype; proto && proto !== Object.prototype; proto = gPO(proto) ) { for (i = 0, keys = oK(proto); i < keys.length; i++) { key = keys[i]; if (isNotASpecialKey(key, false) && !hOP.call(object, key)) { defineProperty(object, key, gOPD(proto, key)); } } } } else { for ( i = 0, object = {}, proto = trait({}), keys = oK(proto); i < keys.length; i++ ) { key = keys[i]; if (key !== INIT) { // if this key is the mixin one if (~key.toString().indexOf('mixin:init') && isArray(proto[key])) { // set the init simply as own method object.init = proto[key][0]; } else { // simply assign the descriptor defineProperty(object, key, gOPD(proto, key)); } } } } return object; } }
[ "function", "transformMixin", "(", "trait", ")", "{", "if", "(", "isObject", "(", "trait", ")", ")", "return", "trait", ";", "else", "{", "var", "i", ",", "key", ",", "keys", ",", "object", ",", "proto", ";", "if", "(", "trait", ".", "isClass", ")", "{", "if", "(", "trait", ".", "length", ")", "{", "warn", "(", "(", "trait", ".", "name", "||", "'Class'", ")", "+", "' should not expect arguments'", ")", ";", "}", "for", "(", "object", "=", "{", "init", ":", "trait", "}", ",", "proto", "=", "trait", ".", "prototype", ";", "proto", "&&", "proto", "!==", "Object", ".", "prototype", ";", "proto", "=", "gPO", "(", "proto", ")", ")", "{", "for", "(", "i", "=", "0", ",", "keys", "=", "oK", "(", "proto", ")", ";", "i", "<", "keys", ".", "length", ";", "i", "++", ")", "{", "key", "=", "keys", "[", "i", "]", ";", "if", "(", "isNotASpecialKey", "(", "key", ",", "false", ")", "&&", "!", "hOP", ".", "call", "(", "object", ",", "key", ")", ")", "{", "defineProperty", "(", "object", ",", "key", ",", "gOPD", "(", "proto", ",", "key", ")", ")", ";", "}", "}", "}", "}", "else", "{", "for", "(", "i", "=", "0", ",", "object", "=", "{", "}", ",", "proto", "=", "trait", "(", "{", "}", ")", ",", "keys", "=", "oK", "(", "proto", ")", ";", "i", "<", "keys", ".", "length", ";", "i", "++", ")", "{", "key", "=", "keys", "[", "i", "]", ";", "if", "(", "key", "!==", "INIT", ")", "{", "// if this key is the mixin one", "if", "(", "~", "key", ".", "toString", "(", ")", ".", "indexOf", "(", "'mixin:init'", ")", "&&", "isArray", "(", "proto", "[", "key", "]", ")", ")", "{", "// set the init simply as own method", "object", ".", "init", "=", "proto", "[", "key", "]", "[", "0", "]", ";", "}", "else", "{", "// simply assign the descriptor", "defineProperty", "(", "object", ",", "key", ",", "gOPD", "(", "proto", ",", "key", ")", ")", ";", "}", "}", "}", "}", "return", "object", ";", "}", "}" ]
will eventually convert classes or constructors into trait objects, before assigning them as such
[ "will", "eventually", "convert", "classes", "or", "constructors", "into", "trait", "objects", "before", "assigning", "them", "as", "such" ]
8e3f3b65a67955d11e15820e8f44e2cdaac4bd50
https://github.com/WebReflection/es-class/blob/8e3f3b65a67955d11e15820e8f44e2cdaac4bd50/build/es-class.max.amd.js#L399-L443
44,009
WebReflection/es-class
build/es-class.max.amd.js
setProperty
function setProperty(inherits, target, key, descriptor, publicStatic, isNOTExtendingNative) { var hasValue = hOP.call(descriptor, VALUE), configurable, value ; if (publicStatic) { if (hOP.call(target, key)) { // in case the value is not a static one if ( inherits && isObject(target[key]) && isObject(inherits[CONSTRUCTOR][key]) ) { copyMerged(inherits[CONSTRUCTOR][key], target[key]); } return; } else if (hasValue) { // in case it's an object perform a deep copy copyValueIfObject(descriptor, copyDeep); } } else if (hasValue) { value = descriptor[VALUE]; if (typeof value === 'function' && trustSuper(value)) { descriptor[VALUE] = wrap(inherits, key, value, publicStatic); } } else if (isNOTExtendingNative) { wrapGetOrSet(inherits, key, descriptor, 'get'); wrapGetOrSet(inherits, key, descriptor, 'set'); } configurable = isConfigurable(key, publicStatic); descriptor.enumerable = false; // was: publicStatic; descriptor.configurable = configurable; if (hasValue) { descriptor.writable = configurable; } defineProperty(target, key, descriptor); }
javascript
function setProperty(inherits, target, key, descriptor, publicStatic, isNOTExtendingNative) { var hasValue = hOP.call(descriptor, VALUE), configurable, value ; if (publicStatic) { if (hOP.call(target, key)) { // in case the value is not a static one if ( inherits && isObject(target[key]) && isObject(inherits[CONSTRUCTOR][key]) ) { copyMerged(inherits[CONSTRUCTOR][key], target[key]); } return; } else if (hasValue) { // in case it's an object perform a deep copy copyValueIfObject(descriptor, copyDeep); } } else if (hasValue) { value = descriptor[VALUE]; if (typeof value === 'function' && trustSuper(value)) { descriptor[VALUE] = wrap(inherits, key, value, publicStatic); } } else if (isNOTExtendingNative) { wrapGetOrSet(inherits, key, descriptor, 'get'); wrapGetOrSet(inherits, key, descriptor, 'set'); } configurable = isConfigurable(key, publicStatic); descriptor.enumerable = false; // was: publicStatic; descriptor.configurable = configurable; if (hasValue) { descriptor.writable = configurable; } defineProperty(target, key, descriptor); }
[ "function", "setProperty", "(", "inherits", ",", "target", ",", "key", ",", "descriptor", ",", "publicStatic", ",", "isNOTExtendingNative", ")", "{", "var", "hasValue", "=", "hOP", ".", "call", "(", "descriptor", ",", "VALUE", ")", ",", "configurable", ",", "value", ";", "if", "(", "publicStatic", ")", "{", "if", "(", "hOP", ".", "call", "(", "target", ",", "key", ")", ")", "{", "// in case the value is not a static one", "if", "(", "inherits", "&&", "isObject", "(", "target", "[", "key", "]", ")", "&&", "isObject", "(", "inherits", "[", "CONSTRUCTOR", "]", "[", "key", "]", ")", ")", "{", "copyMerged", "(", "inherits", "[", "CONSTRUCTOR", "]", "[", "key", "]", ",", "target", "[", "key", "]", ")", ";", "}", "return", ";", "}", "else", "if", "(", "hasValue", ")", "{", "// in case it's an object perform a deep copy", "copyValueIfObject", "(", "descriptor", ",", "copyDeep", ")", ";", "}", "}", "else", "if", "(", "hasValue", ")", "{", "value", "=", "descriptor", "[", "VALUE", "]", ";", "if", "(", "typeof", "value", "===", "'function'", "&&", "trustSuper", "(", "value", ")", ")", "{", "descriptor", "[", "VALUE", "]", "=", "wrap", "(", "inherits", ",", "key", ",", "value", ",", "publicStatic", ")", ";", "}", "}", "else", "if", "(", "isNOTExtendingNative", ")", "{", "wrapGetOrSet", "(", "inherits", ",", "key", ",", "descriptor", ",", "'get'", ")", ";", "wrapGetOrSet", "(", "inherits", ",", "key", ",", "descriptor", ",", "'set'", ")", ";", "}", "configurable", "=", "isConfigurable", "(", "key", ",", "publicStatic", ")", ";", "descriptor", ".", "enumerable", "=", "false", ";", "// was: publicStatic;", "descriptor", ".", "configurable", "=", "configurable", ";", "if", "(", "hasValue", ")", "{", "descriptor", ".", "writable", "=", "configurable", ";", "}", "defineProperty", "(", "target", ",", "key", ",", "descriptor", ")", ";", "}" ]
set a property via defineProperty using a common descriptor only if properties where not defined yet. If publicStatic is true, properties are both non configurable and non writable
[ "set", "a", "property", "via", "defineProperty", "using", "a", "common", "descriptor", "only", "if", "properties", "where", "not", "defined", "yet", ".", "If", "publicStatic", "is", "true", "properties", "are", "both", "non", "configurable", "and", "non", "writable" ]
8e3f3b65a67955d11e15820e8f44e2cdaac4bd50
https://github.com/WebReflection/es-class/blob/8e3f3b65a67955d11e15820e8f44e2cdaac4bd50/build/es-class.max.amd.js#L448-L485
44,010
WebReflection/es-class
build/es-class.max.amd.js
verifyImplementations
function verifyImplementations(interfaces, target) { for (var current, key, i = 0; i < interfaces.length; i++ ) { current = interfaces[i]; for (key in current) { if (hOP.call(current, key) && !hOP.call(target, key)) { warn(key.toString() + ' is not implemented'); } } } }
javascript
function verifyImplementations(interfaces, target) { for (var current, key, i = 0; i < interfaces.length; i++ ) { current = interfaces[i]; for (key in current) { if (hOP.call(current, key) && !hOP.call(target, key)) { warn(key.toString() + ' is not implemented'); } } } }
[ "function", "verifyImplementations", "(", "interfaces", ",", "target", ")", "{", "for", "(", "var", "current", ",", "key", ",", "i", "=", "0", ";", "i", "<", "interfaces", ".", "length", ";", "i", "++", ")", "{", "current", "=", "interfaces", "[", "i", "]", ";", "for", "(", "key", "in", "current", ")", "{", "if", "(", "hOP", ".", "call", "(", "current", ",", "key", ")", "&&", "!", "hOP", ".", "call", "(", "target", ",", "key", ")", ")", "{", "warn", "(", "key", ".", "toString", "(", ")", "+", "' is not implemented'", ")", ";", "}", "}", "}", "}" ]
basic check against expected properties or methods used when `implements` is used
[ "basic", "check", "against", "expected", "properties", "or", "methods", "used", "when", "implements", "is", "used" ]
8e3f3b65a67955d11e15820e8f44e2cdaac4bd50
https://github.com/WebReflection/es-class/blob/8e3f3b65a67955d11e15820e8f44e2cdaac4bd50/build/es-class.max.amd.js#L489-L502
44,011
yoshuawuyts/vel
index.js
vel
function vel (rend) { assert.equal(typeof rend, 'function') var update = null render.toString = toString render.render = render render.vtree = vtree return render // render the element's vdom tree to DOM nodes // which can be mounted on the DOM // any? -> DOMNode function render (state) { if (update) return update(state) const loop = mainLoop(state, renderFn(rend), vdom) update = loop.update return loop.target } // render the element's vdom tree to a string // any? -> str function toString (state) { return toHtml(renderFn(rend)(state)) } // Get the element's vdom tree. // any? -> obj function vtree (state) { return rend(h, state) } }
javascript
function vel (rend) { assert.equal(typeof rend, 'function') var update = null render.toString = toString render.render = render render.vtree = vtree return render // render the element's vdom tree to DOM nodes // which can be mounted on the DOM // any? -> DOMNode function render (state) { if (update) return update(state) const loop = mainLoop(state, renderFn(rend), vdom) update = loop.update return loop.target } // render the element's vdom tree to a string // any? -> str function toString (state) { return toHtml(renderFn(rend)(state)) } // Get the element's vdom tree. // any? -> obj function vtree (state) { return rend(h, state) } }
[ "function", "vel", "(", "rend", ")", "{", "assert", ".", "equal", "(", "typeof", "rend", ",", "'function'", ")", "var", "update", "=", "null", "render", ".", "toString", "=", "toString", "render", ".", "render", "=", "render", "render", ".", "vtree", "=", "vtree", "return", "render", "// render the element's vdom tree to DOM nodes", "// which can be mounted on the DOM", "// any? -> DOMNode", "function", "render", "(", "state", ")", "{", "if", "(", "update", ")", "return", "update", "(", "state", ")", "const", "loop", "=", "mainLoop", "(", "state", ",", "renderFn", "(", "rend", ")", ",", "vdom", ")", "update", "=", "loop", ".", "update", "return", "loop", ".", "target", "}", "// render the element's vdom tree to a string", "// any? -> str", "function", "toString", "(", "state", ")", "{", "return", "toHtml", "(", "renderFn", "(", "rend", ")", "(", "state", ")", ")", "}", "// Get the element's vdom tree.", "// any? -> obj", "function", "vtree", "(", "state", ")", "{", "return", "rend", "(", "h", ",", "state", ")", "}", "}" ]
initialize a new virtual element fn -> null
[ "initialize", "a", "new", "virtual", "element", "fn", "-", ">", "null" ]
7c8b701da8a034937150b76974754d6c0fb1aef0
https://github.com/yoshuawuyts/vel/blob/7c8b701da8a034937150b76974754d6c0fb1aef0/index.js#L18-L48
44,012
yoshuawuyts/vel
index.js
render
function render (state) { if (update) return update(state) const loop = mainLoop(state, renderFn(rend), vdom) update = loop.update return loop.target }
javascript
function render (state) { if (update) return update(state) const loop = mainLoop(state, renderFn(rend), vdom) update = loop.update return loop.target }
[ "function", "render", "(", "state", ")", "{", "if", "(", "update", ")", "return", "update", "(", "state", ")", "const", "loop", "=", "mainLoop", "(", "state", ",", "renderFn", "(", "rend", ")", ",", "vdom", ")", "update", "=", "loop", ".", "update", "return", "loop", ".", "target", "}" ]
render the element's vdom tree to DOM nodes which can be mounted on the DOM any? -> DOMNode
[ "render", "the", "element", "s", "vdom", "tree", "to", "DOM", "nodes", "which", "can", "be", "mounted", "on", "the", "DOM", "any?", "-", ">", "DOMNode" ]
7c8b701da8a034937150b76974754d6c0fb1aef0
https://github.com/yoshuawuyts/vel/blob/7c8b701da8a034937150b76974754d6c0fb1aef0/index.js#L30-L35
44,013
DanielBaulig/chat.io
lib/chat.io.js
disconnect
function disconnect(socket) { if (socket.namespace.name === '') return socket.disconnect(); socket.packet({type:'disconnect'}); socket.manager.onLeave(socket, socket.namespace.name); socket.$emit('disconnect', 'booted'); }
javascript
function disconnect(socket) { if (socket.namespace.name === '') return socket.disconnect(); socket.packet({type:'disconnect'}); socket.manager.onLeave(socket, socket.namespace.name); socket.$emit('disconnect', 'booted'); }
[ "function", "disconnect", "(", "socket", ")", "{", "if", "(", "socket", ".", "namespace", ".", "name", "===", "''", ")", "return", "socket", ".", "disconnect", "(", ")", ";", "socket", ".", "packet", "(", "{", "type", ":", "'disconnect'", "}", ")", ";", "socket", ".", "manager", ".", "onLeave", "(", "socket", ",", "socket", ".", "namespace", ".", "name", ")", ";", "socket", ".", "$emit", "(", "'disconnect'", ",", "'booted'", ")", ";", "}" ]
hack until socket.disconnect is fixed
[ "hack", "until", "socket", ".", "disconnect", "is", "fixed" ]
cd99c6ccd90487bfab459c45a375a192f7baf242
https://github.com/DanielBaulig/chat.io/blob/cd99c6ccd90487bfab459c45a375a192f7baf242/lib/chat.io.js#L13-L18
44,014
feross/location-history
index.js
back
function back (self, cb, cancel) { if (!cb) cb = noop if (self._back.length === 0 || self._pending) return cb(null) var previous = self._back.pop() var current = self.current() load(self, previous, done) function done (err) { if (err) return cb(err) if (!cancel) self._forward.push(current) self._current = previous unload(self, current) cb(null) } }
javascript
function back (self, cb, cancel) { if (!cb) cb = noop if (self._back.length === 0 || self._pending) return cb(null) var previous = self._back.pop() var current = self.current() load(self, previous, done) function done (err) { if (err) return cb(err) if (!cancel) self._forward.push(current) self._current = previous unload(self, current) cb(null) } }
[ "function", "back", "(", "self", ",", "cb", ",", "cancel", ")", "{", "if", "(", "!", "cb", ")", "cb", "=", "noop", "if", "(", "self", ".", "_back", ".", "length", "===", "0", "||", "self", ".", "_pending", ")", "return", "cb", "(", "null", ")", "var", "previous", "=", "self", ".", "_back", ".", "pop", "(", ")", "var", "current", "=", "self", ".", "current", "(", ")", "load", "(", "self", ",", "previous", ",", "done", ")", "function", "done", "(", "err", ")", "{", "if", "(", "err", ")", "return", "cb", "(", "err", ")", "if", "(", "!", "cancel", ")", "self", ".", "_forward", ".", "push", "(", "current", ")", "self", ".", "_current", "=", "previous", "unload", "(", "self", ",", "current", ")", "cb", "(", "null", ")", "}", "}" ]
Goes back to the previous screen If 'cancel' is true, removes the current screen from history If 'cancel' if false, the user can return by going forward
[ "Goes", "back", "to", "the", "previous", "screen", "If", "cancel", "is", "true", "removes", "the", "current", "screen", "from", "history", "If", "cancel", "if", "false", "the", "user", "can", "return", "by", "going", "forward" ]
b20392494dc0aef81afd4b4102dbd2da74d5ab7a
https://github.com/feross/location-history/blob/b20392494dc0aef81afd4b4102dbd2da74d5ab7a/index.js#L39-L54
44,015
dcodeIO/colour.js
colour.js
addProperty
function addProperty(col, func) { // Exposed on top of the namespace colour[col] = function(str) { return func.apply(str); }; // And on top of all strings try { String.prototype.__defineGetter__(col, func); definedGetters[col] = func; } catch (e) {} // #25 }
javascript
function addProperty(col, func) { // Exposed on top of the namespace colour[col] = function(str) { return func.apply(str); }; // And on top of all strings try { String.prototype.__defineGetter__(col, func); definedGetters[col] = func; } catch (e) {} // #25 }
[ "function", "addProperty", "(", "col", ",", "func", ")", "{", "// Exposed on top of the namespace", "colour", "[", "col", "]", "=", "function", "(", "str", ")", "{", "return", "func", ".", "apply", "(", "str", ")", ";", "}", ";", "// And on top of all strings", "try", "{", "String", ".", "prototype", ".", "__defineGetter__", "(", "col", ",", "func", ")", ";", "definedGetters", "[", "col", "]", "=", "func", ";", "}", "catch", "(", "e", ")", "{", "}", "// #25", "}" ]
Prototypes the string object to have additional properties that wraps the current string in colours when accessed. @param {string} col Colour / property name @param {function(string):string} func Wrapper function @private
[ "Prototypes", "the", "string", "object", "to", "have", "additional", "properties", "that", "wraps", "the", "current", "string", "in", "colours", "when", "accessed", "." ]
66a2f044ac9d8b1ae12062dbbc434c621c08368f
https://github.com/dcodeIO/colour.js/blob/66a2f044ac9d8b1ae12062dbbc434c621c08368f/colour.js#L136-L146
44,016
dcodeIO/colour.js
colour.js
stylize
function stylize(str, style) { if (colour.mode == 'console') { return consoleStyles[style][0] + str + consoleStyles[style][1]; } else if (colour.mode == 'browser') { return browserStyles[style][0] + str + browserStyles[style][1]; } else if (colour.mode == 'browser-css') { return cssStyles[style][0] + str + browserStyles[style][1]; } return str+''; }
javascript
function stylize(str, style) { if (colour.mode == 'console') { return consoleStyles[style][0] + str + consoleStyles[style][1]; } else if (colour.mode == 'browser') { return browserStyles[style][0] + str + browserStyles[style][1]; } else if (colour.mode == 'browser-css') { return cssStyles[style][0] + str + browserStyles[style][1]; } return str+''; }
[ "function", "stylize", "(", "str", ",", "style", ")", "{", "if", "(", "colour", ".", "mode", "==", "'console'", ")", "{", "return", "consoleStyles", "[", "style", "]", "[", "0", "]", "+", "str", "+", "consoleStyles", "[", "style", "]", "[", "1", "]", ";", "}", "else", "if", "(", "colour", ".", "mode", "==", "'browser'", ")", "{", "return", "browserStyles", "[", "style", "]", "[", "0", "]", "+", "str", "+", "browserStyles", "[", "style", "]", "[", "1", "]", ";", "}", "else", "if", "(", "colour", ".", "mode", "==", "'browser-css'", ")", "{", "return", "cssStyles", "[", "style", "]", "[", "0", "]", "+", "str", "+", "browserStyles", "[", "style", "]", "[", "1", "]", ";", "}", "return", "str", "+", "''", ";", "}" ]
Applies a style to a string. @param {string} str String to stylize @param {string} style Style to apply @returns {string} @private
[ "Applies", "a", "style", "to", "a", "string", "." ]
66a2f044ac9d8b1ae12062dbbc434c621c08368f
https://github.com/dcodeIO/colour.js/blob/66a2f044ac9d8b1ae12062dbbc434c621c08368f/colour.js#L198-L207
44,017
dcodeIO/colour.js
colour.js
applyTheme
function applyTheme(theme) { Object.keys(theme).forEach(function(prop) { if (prototypeBlacklist.indexOf(prop) >= 0) { return; } if (typeof theme[prop] == 'string') { // Multiple colours white-space seperated #45, e.g. "red bold", #18 theme[prop] = theme[prop].split(' '); } addProperty(prop, function () { var ret = this; for (var t=0; t<theme[prop].length; t++) { ret = colour[theme[prop][t]](ret); } return ret; }); }); }
javascript
function applyTheme(theme) { Object.keys(theme).forEach(function(prop) { if (prototypeBlacklist.indexOf(prop) >= 0) { return; } if (typeof theme[prop] == 'string') { // Multiple colours white-space seperated #45, e.g. "red bold", #18 theme[prop] = theme[prop].split(' '); } addProperty(prop, function () { var ret = this; for (var t=0; t<theme[prop].length; t++) { ret = colour[theme[prop][t]](ret); } return ret; }); }); }
[ "function", "applyTheme", "(", "theme", ")", "{", "Object", ".", "keys", "(", "theme", ")", ".", "forEach", "(", "function", "(", "prop", ")", "{", "if", "(", "prototypeBlacklist", ".", "indexOf", "(", "prop", ")", ">=", "0", ")", "{", "return", ";", "}", "if", "(", "typeof", "theme", "[", "prop", "]", "==", "'string'", ")", "{", "// Multiple colours white-space seperated #45, e.g. \"red bold\", #18", "theme", "[", "prop", "]", "=", "theme", "[", "prop", "]", ".", "split", "(", "' '", ")", ";", "}", "addProperty", "(", "prop", ",", "function", "(", ")", "{", "var", "ret", "=", "this", ";", "for", "(", "var", "t", "=", "0", ";", "t", "<", "theme", "[", "prop", "]", ".", "length", ";", "t", "++", ")", "{", "ret", "=", "colour", "[", "theme", "[", "prop", "]", "[", "t", "]", "]", "(", "ret", ")", ";", "}", "return", "ret", ";", "}", ")", ";", "}", ")", ";", "}" ]
Applies a theme. @param {!Object} theme Theme to apply
[ "Applies", "a", "theme", "." ]
66a2f044ac9d8b1ae12062dbbc434c621c08368f
https://github.com/dcodeIO/colour.js/blob/66a2f044ac9d8b1ae12062dbbc434c621c08368f/colour.js#L233-L250
44,018
dcodeIO/colour.js
colour.js
sequencer
function sequencer(map) { return function () { if (this == undefined) return ""; var i=0; return String.prototype.split.apply(this, [""]).map(map).join(""); }; }
javascript
function sequencer(map) { return function () { if (this == undefined) return ""; var i=0; return String.prototype.split.apply(this, [""]).map(map).join(""); }; }
[ "function", "sequencer", "(", "map", ")", "{", "return", "function", "(", ")", "{", "if", "(", "this", "==", "undefined", ")", "return", "\"\"", ";", "var", "i", "=", "0", ";", "return", "String", ".", "prototype", ".", "split", ".", "apply", "(", "this", ",", "[", "\"\"", "]", ")", ".", "map", "(", "map", ")", ".", "join", "(", "\"\"", ")", ";", "}", ";", "}" ]
Extends a mapper with the current index inside the string as a second argument. @param {function(string, number):string} map Sequencing function @returns {function(string):string} Wrapped sequencer @private
[ "Extends", "a", "mapper", "with", "the", "current", "index", "inside", "the", "string", "as", "a", "second", "argument", "." ]
66a2f044ac9d8b1ae12062dbbc434c621c08368f
https://github.com/dcodeIO/colour.js/blob/66a2f044ac9d8b1ae12062dbbc434c621c08368f/colour.js#L282-L288
44,019
sequitur/blotter
lib/engine.js
choiceListener
function choiceListener(index) { return function (event) { event.preventDefault(); if (choicesAnimating) return; clearChoiceListeners(); story.ChooseChoiceIndex(index); saveGame(index); clearOldChoices().then(() => progressGame()); } }
javascript
function choiceListener(index) { return function (event) { event.preventDefault(); if (choicesAnimating) return; clearChoiceListeners(); story.ChooseChoiceIndex(index); saveGame(index); clearOldChoices().then(() => progressGame()); } }
[ "function", "choiceListener", "(", "index", ")", "{", "return", "function", "(", "event", ")", "{", "event", ".", "preventDefault", "(", ")", ";", "if", "(", "choicesAnimating", ")", "return", ";", "clearChoiceListeners", "(", ")", ";", "story", ".", "ChooseChoiceIndex", "(", "index", ")", ";", "saveGame", "(", "index", ")", ";", "clearOldChoices", "(", ")", ".", "then", "(", "(", ")", "=>", "progressGame", "(", ")", ")", ";", "}", "}" ]
Create a listener function to attach to one of the li elements that represents a player choice.
[ "Create", "a", "listener", "function", "to", "attach", "to", "one", "of", "the", "li", "elements", "that", "represents", "a", "player", "choice", "." ]
f2f22e6ff95e6e0c19ea2c3d939bad63b2de6830
https://github.com/sequitur/blotter/blob/f2f22e6ff95e6e0c19ea2c3d939bad63b2de6830/lib/engine.js#L212-L221
44,020
sequitur/blotter
lib/engine.js
createChoiceListener
function createChoiceListener(li, index) { li.clickListener = choiceListener(index); li.addEventListener('click', li.clickListener); li.clearListener = (function () { this.removeEventListener('click', this.clickListener); }).bind(li); }
javascript
function createChoiceListener(li, index) { li.clickListener = choiceListener(index); li.addEventListener('click', li.clickListener); li.clearListener = (function () { this.removeEventListener('click', this.clickListener); }).bind(li); }
[ "function", "createChoiceListener", "(", "li", ",", "index", ")", "{", "li", ".", "clickListener", "=", "choiceListener", "(", "index", ")", ";", "li", ".", "addEventListener", "(", "'click'", ",", "li", ".", "clickListener", ")", ";", "li", ".", "clearListener", "=", "(", "function", "(", ")", "{", "this", ".", "removeEventListener", "(", "'click'", ",", "this", ".", "clickListener", ")", ";", "}", ")", ".", "bind", "(", "li", ")", ";", "}" ]
Attach that listener to the element.
[ "Attach", "that", "listener", "to", "the", "element", "." ]
f2f22e6ff95e6e0c19ea2c3d939bad63b2de6830
https://github.com/sequitur/blotter/blob/f2f22e6ff95e6e0c19ea2c3d939bad63b2de6830/lib/engine.js#L246-L252
44,021
sequitur/blotter
lib/engine.js
clearChoiceListeners
function clearChoiceListeners() { const lis = document.querySelectorAll('li'); Array.from(lis).forEach(li => { if (li.clearListener) li.clearListener(); }) }
javascript
function clearChoiceListeners() { const lis = document.querySelectorAll('li'); Array.from(lis).forEach(li => { if (li.clearListener) li.clearListener(); }) }
[ "function", "clearChoiceListeners", "(", ")", "{", "const", "lis", "=", "document", ".", "querySelectorAll", "(", "'li'", ")", ";", "Array", ".", "from", "(", "lis", ")", ".", "forEach", "(", "li", "=>", "{", "if", "(", "li", ".", "clearListener", ")", "li", ".", "clearListener", "(", ")", ";", "}", ")", "}" ]
Clean up event listeners from choices once one of them was selected.
[ "Clean", "up", "event", "listeners", "from", "choices", "once", "one", "of", "them", "was", "selected", "." ]
f2f22e6ff95e6e0c19ea2c3d939bad63b2de6830
https://github.com/sequitur/blotter/blob/f2f22e6ff95e6e0c19ea2c3d939bad63b2de6830/lib/engine.js#L255-L260
44,022
sequitur/blotter
lib/engine.js
createChoiceUl
function createChoiceUl () { const lis = story.currentChoices .map(choice => { const li = document.createElement('li'); li.innerHTML = choice.text; createChoiceListener(li, choice.index); return li; }); const ul = document.createElement('ul'); Array.from(lis).forEach(li => ul.appendChild(li)); ul.className = "choices current"; return ul; }
javascript
function createChoiceUl () { const lis = story.currentChoices .map(choice => { const li = document.createElement('li'); li.innerHTML = choice.text; createChoiceListener(li, choice.index); return li; }); const ul = document.createElement('ul'); Array.from(lis).forEach(li => ul.appendChild(li)); ul.className = "choices current"; return ul; }
[ "function", "createChoiceUl", "(", ")", "{", "const", "lis", "=", "story", ".", "currentChoices", ".", "map", "(", "choice", "=>", "{", "const", "li", "=", "document", ".", "createElement", "(", "'li'", ")", ";", "li", ".", "innerHTML", "=", "choice", ".", "text", ";", "createChoiceListener", "(", "li", ",", "choice", ".", "index", ")", ";", "return", "li", ";", "}", ")", ";", "const", "ul", "=", "document", ".", "createElement", "(", "'ul'", ")", ";", "Array", ".", "from", "(", "lis", ")", ".", "forEach", "(", "li", "=>", "ul", ".", "appendChild", "(", "li", ")", ")", ";", "ul", ".", "className", "=", "\"choices current\"", ";", "return", "ul", ";", "}" ]
Create the ul element that contains a batch of choices.
[ "Create", "the", "ul", "element", "that", "contains", "a", "batch", "of", "choices", "." ]
f2f22e6ff95e6e0c19ea2c3d939bad63b2de6830
https://github.com/sequitur/blotter/blob/f2f22e6ff95e6e0c19ea2c3d939bad63b2de6830/lib/engine.js#L263-L275
44,023
sequitur/blotter
lib/engine.js
placeChoices
function placeChoices () { const ul = createChoiceUl(); ul.addEventListener('animationend', () => choicesAnimating = false); choicesAnimating = true; choiceDiv.appendChild(ul); }
javascript
function placeChoices () { const ul = createChoiceUl(); ul.addEventListener('animationend', () => choicesAnimating = false); choicesAnimating = true; choiceDiv.appendChild(ul); }
[ "function", "placeChoices", "(", ")", "{", "const", "ul", "=", "createChoiceUl", "(", ")", ";", "ul", ".", "addEventListener", "(", "'animationend'", ",", "(", ")", "=>", "choicesAnimating", "=", "false", ")", ";", "choicesAnimating", "=", "true", ";", "choiceDiv", ".", "appendChild", "(", "ul", ")", ";", "}" ]
Insert a choice list into the container div.
[ "Insert", "a", "choice", "list", "into", "the", "container", "div", "." ]
f2f22e6ff95e6e0c19ea2c3d939bad63b2de6830
https://github.com/sequitur/blotter/blob/f2f22e6ff95e6e0c19ea2c3d939bad63b2de6830/lib/engine.js#L278-L283
44,024
sequitur/blotter
lib/engine.js
clearOldChoices
function clearOldChoices () { const oldChoices = choiceDiv.querySelector('.choices.current'); return new Promise(resolve => { oldChoices.addEventListener('transitionend', () => { oldChoices.remove(); resolve(); }); oldChoices.className = "choices old"; }) }
javascript
function clearOldChoices () { const oldChoices = choiceDiv.querySelector('.choices.current'); return new Promise(resolve => { oldChoices.addEventListener('transitionend', () => { oldChoices.remove(); resolve(); }); oldChoices.className = "choices old"; }) }
[ "function", "clearOldChoices", "(", ")", "{", "const", "oldChoices", "=", "choiceDiv", ".", "querySelector", "(", "'.choices.current'", ")", ";", "return", "new", "Promise", "(", "resolve", "=>", "{", "oldChoices", ".", "addEventListener", "(", "'transitionend'", ",", "(", ")", "=>", "{", "oldChoices", ".", "remove", "(", ")", ";", "resolve", "(", ")", ";", "}", ")", ";", "oldChoices", ".", "className", "=", "\"choices old\"", ";", "}", ")", "}" ]
Mark used choice lists as old and remove them from the view.
[ "Mark", "used", "choice", "lists", "as", "old", "and", "remove", "them", "from", "the", "view", "." ]
f2f22e6ff95e6e0c19ea2c3d939bad63b2de6830
https://github.com/sequitur/blotter/blob/f2f22e6ff95e6e0c19ea2c3d939bad63b2de6830/lib/engine.js#L286-L295
44,025
wala/jsdelta
src/delta_multi.js
deltaDebugFiles
function deltaDebugFiles(file) { try { logging.increaseIndentation(); state.fileUnderTest = file; logging.logTargetChange(file, state.tmpDir); // try removing fileUnderTest completely var backup = makeBackupFileName(); fs.renameSync(file, backup); if (options.predicate.test(state.mainFileTmpDir)) { return true; } else { // if that fails, then restore the fileUnderTest fs.renameSync(backup, file); if (fs.statSync(file).isDirectory()) { var performedAtLeastOneReduction = false; readDirSorted(file).forEach(function (child) { // recurse on all files in the directory performedAtLeastOneReduction |= deltaDebugFiles(child); }); return performedAtLeastOneReduction; } else { // specialized reductions if (isJsOrJsonFile(file)) { return delta_single.reduce(makeOptionsForSingleFileMode(file)); } return false; } } } finally { logging.decreaseIndentation(); } }
javascript
function deltaDebugFiles(file) { try { logging.increaseIndentation(); state.fileUnderTest = file; logging.logTargetChange(file, state.tmpDir); // try removing fileUnderTest completely var backup = makeBackupFileName(); fs.renameSync(file, backup); if (options.predicate.test(state.mainFileTmpDir)) { return true; } else { // if that fails, then restore the fileUnderTest fs.renameSync(backup, file); if (fs.statSync(file).isDirectory()) { var performedAtLeastOneReduction = false; readDirSorted(file).forEach(function (child) { // recurse on all files in the directory performedAtLeastOneReduction |= deltaDebugFiles(child); }); return performedAtLeastOneReduction; } else { // specialized reductions if (isJsOrJsonFile(file)) { return delta_single.reduce(makeOptionsForSingleFileMode(file)); } return false; } } } finally { logging.decreaseIndentation(); } }
[ "function", "deltaDebugFiles", "(", "file", ")", "{", "try", "{", "logging", ".", "increaseIndentation", "(", ")", ";", "state", ".", "fileUnderTest", "=", "file", ";", "logging", ".", "logTargetChange", "(", "file", ",", "state", ".", "tmpDir", ")", ";", "// try removing fileUnderTest completely", "var", "backup", "=", "makeBackupFileName", "(", ")", ";", "fs", ".", "renameSync", "(", "file", ",", "backup", ")", ";", "if", "(", "options", ".", "predicate", ".", "test", "(", "state", ".", "mainFileTmpDir", ")", ")", "{", "return", "true", ";", "}", "else", "{", "// if that fails, then restore the fileUnderTest", "fs", ".", "renameSync", "(", "backup", ",", "file", ")", ";", "if", "(", "fs", ".", "statSync", "(", "file", ")", ".", "isDirectory", "(", ")", ")", "{", "var", "performedAtLeastOneReduction", "=", "false", ";", "readDirSorted", "(", "file", ")", ".", "forEach", "(", "function", "(", "child", ")", "{", "// recurse on all files in the directory", "performedAtLeastOneReduction", "|=", "deltaDebugFiles", "(", "child", ")", ";", "}", ")", ";", "return", "performedAtLeastOneReduction", ";", "}", "else", "{", "// specialized reductions", "if", "(", "isJsOrJsonFile", "(", "file", ")", ")", "{", "return", "delta_single", ".", "reduce", "(", "makeOptionsForSingleFileMode", "(", "file", ")", ")", ";", "}", "return", "false", ";", "}", "}", "}", "finally", "{", "logging", ".", "decreaseIndentation", "(", ")", ";", "}", "}" ]
Recursively pass through the file-hierarchy and invoke delta_single.main on all files @return boolean true if at least one reduction was performed successfully.
[ "Recursively", "pass", "through", "the", "file", "-", "hierarchy", "and", "invoke", "delta_single", ".", "main", "on", "all", "files" ]
355febea1ee23e9e909ba2bfa087ffb2499a3295
https://github.com/wala/jsdelta/blob/355febea1ee23e9e909ba2bfa087ffb2499a3295/src/delta_multi.js#L127-L159
44,026
ariatemplates/hashspace
docs/libs/jx.js
function () { var http = false; // Use IE's ActiveX items to load the file. if (typeof ActiveXObject != 'undefined') { try { http = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { http = false; } } // If ActiveX is not available, use the XMLHttpRequest of Firefox/Mozilla etc. to load the document. } else if (window.XMLHttpRequest) { try { http = new XMLHttpRequest(); } catch (e) { http = false; } } return http; }
javascript
function () { var http = false; // Use IE's ActiveX items to load the file. if (typeof ActiveXObject != 'undefined') { try { http = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { http = false; } } // If ActiveX is not available, use the XMLHttpRequest of Firefox/Mozilla etc. to load the document. } else if (window.XMLHttpRequest) { try { http = new XMLHttpRequest(); } catch (e) { http = false; } } return http; }
[ "function", "(", ")", "{", "var", "http", "=", "false", ";", "// Use IE's ActiveX items to load the file.", "if", "(", "typeof", "ActiveXObject", "!=", "'undefined'", ")", "{", "try", "{", "http", "=", "new", "ActiveXObject", "(", "\"Msxml2.XMLHTTP\"", ")", ";", "}", "catch", "(", "e", ")", "{", "try", "{", "http", "=", "new", "ActiveXObject", "(", "\"Microsoft.XMLHTTP\"", ")", ";", "}", "catch", "(", "E", ")", "{", "http", "=", "false", ";", "}", "}", "// If ActiveX is not available, use the XMLHttpRequest of Firefox/Mozilla etc. to load the document.", "}", "else", "if", "(", "window", ".", "XMLHttpRequest", ")", "{", "try", "{", "http", "=", "new", "XMLHttpRequest", "(", ")", ";", "}", "catch", "(", "e", ")", "{", "http", "=", "false", ";", "}", "}", "return", "http", ";", "}" ]
Create a xmlHttpRequest object - this is the constructor.
[ "Create", "a", "xmlHttpRequest", "object", "-", "this", "is", "the", "constructor", "." ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/docs/libs/jx.js#L7-L29
44,027
mljs/fft
src/FFTUtils.js
ifft2DArray
function ifft2DArray(ft, ftRows, ftCols) { var tempTransform = new Array(ftRows * ftCols); var nRows = ftRows / 2; var nCols = (ftCols - 1) * 2; // reverse transform columns FFT.init(nRows); var tmpCols = {re: new Array(nRows), im: new Array(nRows)}; var iRow, iCol; for (iCol = 0; iCol < ftCols; iCol++) { for (iRow = nRows - 1; iRow >= 0; iRow--) { tmpCols.re[iRow] = ft[(iRow * 2) * ftCols + iCol]; tmpCols.im[iRow] = ft[(iRow * 2 + 1) * ftCols + iCol]; } //Unnormalized inverse transform FFT.bt(tmpCols.re, tmpCols.im); for (iRow = nRows - 1; iRow >= 0; iRow--) { tempTransform[(iRow * 2) * ftCols + iCol] = tmpCols.re[iRow]; tempTransform[(iRow * 2 + 1) * ftCols + iCol] = tmpCols.im[iRow]; } } // reverse row transform var finalTransform = new Array(nRows * nCols); FFT.init(nCols); var tmpRows = {re: new Array(nCols), im: new Array(nCols)}; var scale = nCols * nRows; for (iRow = 0; iRow < ftRows; iRow += 2) { tmpRows.re[0] = tempTransform[iRow * ftCols]; tmpRows.im[0] = tempTransform[(iRow + 1) * ftCols]; for (iCol = 1; iCol < ftCols; iCol++) { tmpRows.re[iCol] = tempTransform[iRow * ftCols + iCol]; tmpRows.im[iCol] = tempTransform[(iRow + 1) * ftCols + iCol]; tmpRows.re[nCols - iCol] = tempTransform[iRow * ftCols + iCol]; tmpRows.im[nCols - iCol] = -tempTransform[(iRow + 1) * ftCols + iCol]; } //Unnormalized inverse transform FFT.bt(tmpRows.re, tmpRows.im); var indexB = (iRow / 2) * nCols; for (iCol = nCols - 1; iCol >= 0; iCol--) { finalTransform[indexB + iCol] = tmpRows.re[iCol] / scale; } } return finalTransform; }
javascript
function ifft2DArray(ft, ftRows, ftCols) { var tempTransform = new Array(ftRows * ftCols); var nRows = ftRows / 2; var nCols = (ftCols - 1) * 2; // reverse transform columns FFT.init(nRows); var tmpCols = {re: new Array(nRows), im: new Array(nRows)}; var iRow, iCol; for (iCol = 0; iCol < ftCols; iCol++) { for (iRow = nRows - 1; iRow >= 0; iRow--) { tmpCols.re[iRow] = ft[(iRow * 2) * ftCols + iCol]; tmpCols.im[iRow] = ft[(iRow * 2 + 1) * ftCols + iCol]; } //Unnormalized inverse transform FFT.bt(tmpCols.re, tmpCols.im); for (iRow = nRows - 1; iRow >= 0; iRow--) { tempTransform[(iRow * 2) * ftCols + iCol] = tmpCols.re[iRow]; tempTransform[(iRow * 2 + 1) * ftCols + iCol] = tmpCols.im[iRow]; } } // reverse row transform var finalTransform = new Array(nRows * nCols); FFT.init(nCols); var tmpRows = {re: new Array(nCols), im: new Array(nCols)}; var scale = nCols * nRows; for (iRow = 0; iRow < ftRows; iRow += 2) { tmpRows.re[0] = tempTransform[iRow * ftCols]; tmpRows.im[0] = tempTransform[(iRow + 1) * ftCols]; for (iCol = 1; iCol < ftCols; iCol++) { tmpRows.re[iCol] = tempTransform[iRow * ftCols + iCol]; tmpRows.im[iCol] = tempTransform[(iRow + 1) * ftCols + iCol]; tmpRows.re[nCols - iCol] = tempTransform[iRow * ftCols + iCol]; tmpRows.im[nCols - iCol] = -tempTransform[(iRow + 1) * ftCols + iCol]; } //Unnormalized inverse transform FFT.bt(tmpRows.re, tmpRows.im); var indexB = (iRow / 2) * nCols; for (iCol = nCols - 1; iCol >= 0; iCol--) { finalTransform[indexB + iCol] = tmpRows.re[iCol] / scale; } } return finalTransform; }
[ "function", "ifft2DArray", "(", "ft", ",", "ftRows", ",", "ftCols", ")", "{", "var", "tempTransform", "=", "new", "Array", "(", "ftRows", "*", "ftCols", ")", ";", "var", "nRows", "=", "ftRows", "/", "2", ";", "var", "nCols", "=", "(", "ftCols", "-", "1", ")", "*", "2", ";", "// reverse transform columns", "FFT", ".", "init", "(", "nRows", ")", ";", "var", "tmpCols", "=", "{", "re", ":", "new", "Array", "(", "nRows", ")", ",", "im", ":", "new", "Array", "(", "nRows", ")", "}", ";", "var", "iRow", ",", "iCol", ";", "for", "(", "iCol", "=", "0", ";", "iCol", "<", "ftCols", ";", "iCol", "++", ")", "{", "for", "(", "iRow", "=", "nRows", "-", "1", ";", "iRow", ">=", "0", ";", "iRow", "--", ")", "{", "tmpCols", ".", "re", "[", "iRow", "]", "=", "ft", "[", "(", "iRow", "*", "2", ")", "*", "ftCols", "+", "iCol", "]", ";", "tmpCols", ".", "im", "[", "iRow", "]", "=", "ft", "[", "(", "iRow", "*", "2", "+", "1", ")", "*", "ftCols", "+", "iCol", "]", ";", "}", "//Unnormalized inverse transform", "FFT", ".", "bt", "(", "tmpCols", ".", "re", ",", "tmpCols", ".", "im", ")", ";", "for", "(", "iRow", "=", "nRows", "-", "1", ";", "iRow", ">=", "0", ";", "iRow", "--", ")", "{", "tempTransform", "[", "(", "iRow", "*", "2", ")", "*", "ftCols", "+", "iCol", "]", "=", "tmpCols", ".", "re", "[", "iRow", "]", ";", "tempTransform", "[", "(", "iRow", "*", "2", "+", "1", ")", "*", "ftCols", "+", "iCol", "]", "=", "tmpCols", ".", "im", "[", "iRow", "]", ";", "}", "}", "// reverse row transform", "var", "finalTransform", "=", "new", "Array", "(", "nRows", "*", "nCols", ")", ";", "FFT", ".", "init", "(", "nCols", ")", ";", "var", "tmpRows", "=", "{", "re", ":", "new", "Array", "(", "nCols", ")", ",", "im", ":", "new", "Array", "(", "nCols", ")", "}", ";", "var", "scale", "=", "nCols", "*", "nRows", ";", "for", "(", "iRow", "=", "0", ";", "iRow", "<", "ftRows", ";", "iRow", "+=", "2", ")", "{", "tmpRows", ".", "re", "[", "0", "]", "=", "tempTransform", "[", "iRow", "*", "ftCols", "]", ";", "tmpRows", ".", "im", "[", "0", "]", "=", "tempTransform", "[", "(", "iRow", "+", "1", ")", "*", "ftCols", "]", ";", "for", "(", "iCol", "=", "1", ";", "iCol", "<", "ftCols", ";", "iCol", "++", ")", "{", "tmpRows", ".", "re", "[", "iCol", "]", "=", "tempTransform", "[", "iRow", "*", "ftCols", "+", "iCol", "]", ";", "tmpRows", ".", "im", "[", "iCol", "]", "=", "tempTransform", "[", "(", "iRow", "+", "1", ")", "*", "ftCols", "+", "iCol", "]", ";", "tmpRows", ".", "re", "[", "nCols", "-", "iCol", "]", "=", "tempTransform", "[", "iRow", "*", "ftCols", "+", "iCol", "]", ";", "tmpRows", ".", "im", "[", "nCols", "-", "iCol", "]", "=", "-", "tempTransform", "[", "(", "iRow", "+", "1", ")", "*", "ftCols", "+", "iCol", "]", ";", "}", "//Unnormalized inverse transform", "FFT", ".", "bt", "(", "tmpRows", ".", "re", ",", "tmpRows", ".", "im", ")", ";", "var", "indexB", "=", "(", "iRow", "/", "2", ")", "*", "nCols", ";", "for", "(", "iCol", "=", "nCols", "-", "1", ";", "iCol", ">=", "0", ";", "iCol", "--", ")", "{", "finalTransform", "[", "indexB", "+", "iCol", "]", "=", "tmpRows", ".", "re", "[", "iCol", "]", "/", "scale", ";", "}", "}", "return", "finalTransform", ";", "}" ]
Calculates the inverse of a 2D Fourier transform @param ft @param ftRows @param ftCols @return
[ "Calculates", "the", "inverse", "of", "a", "2D", "Fourier", "transform" ]
436ff9535ded13393f359b50d55c68e94e2e8d51
https://github.com/mljs/fft/blob/436ff9535ded13393f359b50d55c68e94e2e8d51/src/FFTUtils.js#L13-L57
44,028
mljs/fft
src/FFTUtils.js
convolute2DI
function convolute2DI(ftSignal, ftFilter, ftRows, ftCols) { var re, im; for (var iRow = 0; iRow < ftRows / 2; iRow++) { for (var iCol = 0; iCol < ftCols; iCol++) { // re = ftSignal[(iRow * 2) * ftCols + iCol] * ftFilter[(iRow * 2) * ftCols + iCol] - ftSignal[(iRow * 2 + 1) * ftCols + iCol] * ftFilter[(iRow * 2 + 1) * ftCols + iCol]; im = ftSignal[(iRow * 2) * ftCols + iCol] * ftFilter[(iRow * 2 + 1) * ftCols + iCol] + ftSignal[(iRow * 2 + 1) * ftCols + iCol] * ftFilter[(iRow * 2) * ftCols + iCol]; // ftSignal[(iRow * 2) * ftCols + iCol] = re; ftSignal[(iRow * 2 + 1) * ftCols + iCol] = im; } } }
javascript
function convolute2DI(ftSignal, ftFilter, ftRows, ftCols) { var re, im; for (var iRow = 0; iRow < ftRows / 2; iRow++) { for (var iCol = 0; iCol < ftCols; iCol++) { // re = ftSignal[(iRow * 2) * ftCols + iCol] * ftFilter[(iRow * 2) * ftCols + iCol] - ftSignal[(iRow * 2 + 1) * ftCols + iCol] * ftFilter[(iRow * 2 + 1) * ftCols + iCol]; im = ftSignal[(iRow * 2) * ftCols + iCol] * ftFilter[(iRow * 2 + 1) * ftCols + iCol] + ftSignal[(iRow * 2 + 1) * ftCols + iCol] * ftFilter[(iRow * 2) * ftCols + iCol]; // ftSignal[(iRow * 2) * ftCols + iCol] = re; ftSignal[(iRow * 2 + 1) * ftCols + iCol] = im; } } }
[ "function", "convolute2DI", "(", "ftSignal", ",", "ftFilter", ",", "ftRows", ",", "ftCols", ")", "{", "var", "re", ",", "im", ";", "for", "(", "var", "iRow", "=", "0", ";", "iRow", "<", "ftRows", "/", "2", ";", "iRow", "++", ")", "{", "for", "(", "var", "iCol", "=", "0", ";", "iCol", "<", "ftCols", ";", "iCol", "++", ")", "{", "//", "re", "=", "ftSignal", "[", "(", "iRow", "*", "2", ")", "*", "ftCols", "+", "iCol", "]", "*", "ftFilter", "[", "(", "iRow", "*", "2", ")", "*", "ftCols", "+", "iCol", "]", "-", "ftSignal", "[", "(", "iRow", "*", "2", "+", "1", ")", "*", "ftCols", "+", "iCol", "]", "*", "ftFilter", "[", "(", "iRow", "*", "2", "+", "1", ")", "*", "ftCols", "+", "iCol", "]", ";", "im", "=", "ftSignal", "[", "(", "iRow", "*", "2", ")", "*", "ftCols", "+", "iCol", "]", "*", "ftFilter", "[", "(", "iRow", "*", "2", "+", "1", ")", "*", "ftCols", "+", "iCol", "]", "+", "ftSignal", "[", "(", "iRow", "*", "2", "+", "1", ")", "*", "ftCols", "+", "iCol", "]", "*", "ftFilter", "[", "(", "iRow", "*", "2", ")", "*", "ftCols", "+", "iCol", "]", ";", "//", "ftSignal", "[", "(", "iRow", "*", "2", ")", "*", "ftCols", "+", "iCol", "]", "=", "re", ";", "ftSignal", "[", "(", "iRow", "*", "2", "+", "1", ")", "*", "ftCols", "+", "iCol", "]", "=", "im", ";", "}", "}", "}" ]
In place version of convolute 2D @param ftSignal @param ftFilter @param ftRows @param ftCols @return
[ "In", "place", "version", "of", "convolute", "2D" ]
436ff9535ded13393f359b50d55c68e94e2e8d51
https://github.com/mljs/fft/blob/436ff9535ded13393f359b50d55c68e94e2e8d51/src/FFTUtils.js#L187-L205
44,029
mljs/fft
src/FFTUtils.js
crop
function crop(data, rows, cols, nRows, nCols) { if (rows === nRows && cols === nCols) { //Do nothing. Returns the same input!!! Be careful return data; } var output = new Array(nCols * nRows); var shiftR = Math.floor((rows - nRows) / 2); var shiftC = Math.floor((cols - nCols) / 2); var destinyRow, sourceRow, i, j; for (i = 0; i < nRows; i++) { destinyRow = i * nCols; sourceRow = (i + shiftR) * cols; for (j = 0; j < nCols; j++) { output[destinyRow + j] = data[sourceRow + (j + shiftC)]; } } return output; }
javascript
function crop(data, rows, cols, nRows, nCols) { if (rows === nRows && cols === nCols) { //Do nothing. Returns the same input!!! Be careful return data; } var output = new Array(nCols * nRows); var shiftR = Math.floor((rows - nRows) / 2); var shiftC = Math.floor((cols - nCols) / 2); var destinyRow, sourceRow, i, j; for (i = 0; i < nRows; i++) { destinyRow = i * nCols; sourceRow = (i + shiftR) * cols; for (j = 0; j < nCols; j++) { output[destinyRow + j] = data[sourceRow + (j + shiftC)]; } } return output; }
[ "function", "crop", "(", "data", ",", "rows", ",", "cols", ",", "nRows", ",", "nCols", ")", "{", "if", "(", "rows", "===", "nRows", "&&", "cols", "===", "nCols", ")", "{", "//Do nothing. Returns the same input!!! Be careful", "return", "data", ";", "}", "var", "output", "=", "new", "Array", "(", "nCols", "*", "nRows", ")", ";", "var", "shiftR", "=", "Math", ".", "floor", "(", "(", "rows", "-", "nRows", ")", "/", "2", ")", ";", "var", "shiftC", "=", "Math", ".", "floor", "(", "(", "cols", "-", "nCols", ")", "/", "2", ")", ";", "var", "destinyRow", ",", "sourceRow", ",", "i", ",", "j", ";", "for", "(", "i", "=", "0", ";", "i", "<", "nRows", ";", "i", "++", ")", "{", "destinyRow", "=", "i", "*", "nCols", ";", "sourceRow", "=", "(", "i", "+", "shiftR", ")", "*", "cols", ";", "for", "(", "j", "=", "0", ";", "j", "<", "nCols", ";", "j", "++", ")", "{", "output", "[", "destinyRow", "+", "j", "]", "=", "data", "[", "sourceRow", "+", "(", "j", "+", "shiftC", ")", "]", ";", "}", "}", "return", "output", ";", "}" ]
Crop the given matrix to fit the corresponding number of rows and columns
[ "Crop", "the", "given", "matrix", "to", "fit", "the", "corresponding", "number", "of", "rows", "and", "columns" ]
436ff9535ded13393f359b50d55c68e94e2e8d51
https://github.com/mljs/fft/blob/436ff9535ded13393f359b50d55c68e94e2e8d51/src/FFTUtils.js#L295-L316
44,030
ariatemplates/hashspace
hsp/rt/cptwrapper.js
function (Cptfn) { if (!Cptfn || Cptfn.constructor !== Function) { log.error("[CptWrapper] Invalid Component constructor!"); } else { this.cpt = new Cptfn(); this.nodeInstance = null; // reference to set the node instance adirty when an attribute changes this.root=null; // reference to the root template node this.initialized = false; this.needsRefresh = true; // update attribute values for simpler processing var atts = this.cpt.$attributes, att, bnd; if (atts) { for (var k in atts) { att = atts[k]; if (k.match(/^on/)) { // this is a callback if (!att.type) { log.error("Attribute type 'callback' should be set to '" + k + "'"); } else if (att.type !== "callback") { log.error("Attribute type 'callback' should be set to '" + k + "' instead of: " + att.type); att.type = "callback"; } continue; } bnd = att.binding; // set the internal _binding value 0=none 1=1-way 2=2-way if (bnd) { bnd = BINDING_VALUES[bnd]; if (bnd !== undefined) { att._binding = bnd; } else { log.error("Invalid attribute binding value: " + att.binding); att._binding = 0; } } else { att._binding = 0; } // check type if (att.type) { if (att.type === "callback") { log.error("Attribute of type 'callback' must start with 'on' - please rename: " + k); } else if (ATTRIBUTE_TYPES[att.type] === undefined) { log.error("Invalid attribute type: " + att.type); att.type = 'string'; } } else { att.type = 'string'; } } } } }
javascript
function (Cptfn) { if (!Cptfn || Cptfn.constructor !== Function) { log.error("[CptWrapper] Invalid Component constructor!"); } else { this.cpt = new Cptfn(); this.nodeInstance = null; // reference to set the node instance adirty when an attribute changes this.root=null; // reference to the root template node this.initialized = false; this.needsRefresh = true; // update attribute values for simpler processing var atts = this.cpt.$attributes, att, bnd; if (atts) { for (var k in atts) { att = atts[k]; if (k.match(/^on/)) { // this is a callback if (!att.type) { log.error("Attribute type 'callback' should be set to '" + k + "'"); } else if (att.type !== "callback") { log.error("Attribute type 'callback' should be set to '" + k + "' instead of: " + att.type); att.type = "callback"; } continue; } bnd = att.binding; // set the internal _binding value 0=none 1=1-way 2=2-way if (bnd) { bnd = BINDING_VALUES[bnd]; if (bnd !== undefined) { att._binding = bnd; } else { log.error("Invalid attribute binding value: " + att.binding); att._binding = 0; } } else { att._binding = 0; } // check type if (att.type) { if (att.type === "callback") { log.error("Attribute of type 'callback' must start with 'on' - please rename: " + k); } else if (ATTRIBUTE_TYPES[att.type] === undefined) { log.error("Invalid attribute type: " + att.type); att.type = 'string'; } } else { att.type = 'string'; } } } } }
[ "function", "(", "Cptfn", ")", "{", "if", "(", "!", "Cptfn", "||", "Cptfn", ".", "constructor", "!==", "Function", ")", "{", "log", ".", "error", "(", "\"[CptWrapper] Invalid Component constructor!\"", ")", ";", "}", "else", "{", "this", ".", "cpt", "=", "new", "Cptfn", "(", ")", ";", "this", ".", "nodeInstance", "=", "null", ";", "// reference to set the node instance adirty when an attribute changes", "this", ".", "root", "=", "null", ";", "// reference to the root template node", "this", ".", "initialized", "=", "false", ";", "this", ".", "needsRefresh", "=", "true", ";", "// update attribute values for simpler processing", "var", "atts", "=", "this", ".", "cpt", ".", "$attributes", ",", "att", ",", "bnd", ";", "if", "(", "atts", ")", "{", "for", "(", "var", "k", "in", "atts", ")", "{", "att", "=", "atts", "[", "k", "]", ";", "if", "(", "k", ".", "match", "(", "/", "^on", "/", ")", ")", "{", "// this is a callback", "if", "(", "!", "att", ".", "type", ")", "{", "log", ".", "error", "(", "\"Attribute type 'callback' should be set to '\"", "+", "k", "+", "\"'\"", ")", ";", "}", "else", "if", "(", "att", ".", "type", "!==", "\"callback\"", ")", "{", "log", ".", "error", "(", "\"Attribute type 'callback' should be set to '\"", "+", "k", "+", "\"' instead of: \"", "+", "att", ".", "type", ")", ";", "att", ".", "type", "=", "\"callback\"", ";", "}", "continue", ";", "}", "bnd", "=", "att", ".", "binding", ";", "// set the internal _binding value 0=none 1=1-way 2=2-way", "if", "(", "bnd", ")", "{", "bnd", "=", "BINDING_VALUES", "[", "bnd", "]", ";", "if", "(", "bnd", "!==", "undefined", ")", "{", "att", ".", "_binding", "=", "bnd", ";", "}", "else", "{", "log", ".", "error", "(", "\"Invalid attribute binding value: \"", "+", "att", ".", "binding", ")", ";", "att", ".", "_binding", "=", "0", ";", "}", "}", "else", "{", "att", ".", "_binding", "=", "0", ";", "}", "// check type", "if", "(", "att", ".", "type", ")", "{", "if", "(", "att", ".", "type", "===", "\"callback\"", ")", "{", "log", ".", "error", "(", "\"Attribute of type 'callback' must start with 'on' - please rename: \"", "+", "k", ")", ";", "}", "else", "if", "(", "ATTRIBUTE_TYPES", "[", "att", ".", "type", "]", "===", "undefined", ")", "{", "log", ".", "error", "(", "\"Invalid attribute type: \"", "+", "att", ".", "type", ")", ";", "att", ".", "type", "=", "'string'", ";", "}", "}", "else", "{", "att", ".", "type", "=", "'string'", ";", "}", "}", "}", "}", "}" ]
Observer constructor. @param Cptfn {Function} the component constructor
[ "Observer", "constructor", "." ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/rt/cptwrapper.js#L96-L151
44,031
ariatemplates/hashspace
hsp/rt/cptwrapper.js
function (change) { var chg = change, cpt = this.cpt; if (change.constructor === Array) { if (change.length > 0) { chg = change[0]; } else { log.error('[CptNode] Invalid change - nbr of changes: '+change.length); return; } } this.needsRefresh=true; var nm = chg.name; // property name if (nm === "") { return; // doesn't make sens (!) } var callControllerCb = true; // true if the onXXXChange() callback must be called on the controller var att, isAttributeChange = false; if (cpt.$attributes) { att = cpt.$attributes[nm]; isAttributeChange = (att !== undefined); if (isAttributeChange) { // adapt type if applicable var t = att.type; if (t) { var v = ATTRIBUTE_TYPES[t].convert(chg.newValue, att); chg.newValue = v; cpt[nm] = v; // change is already raised, no need to trigger another one through json.set() } } if (isAttributeChange && this.nodeInstance) { // notify attribute changes to the node instance (and the host) if attribute has a 2-way binding if (att._binding === 2) { chg.newValue = this.cpt[nm]; // attribute value may have been changed by the controller this.nodeInstance.onAttributeChange(chg); } } if (isAttributeChange) { // check if cb must be called depending on binding mode if (att._binding === 0) { callControllerCb = false; } } } if (callControllerCb) { if (this.processingChange === true) { // don't re-enter the change loop if we are already processing changes return; } this.processingChange = true; try { // calculate the callback name (e.g. onValueChange for the 'value' property) var cbnm=''; if (isAttributeChange) { cbnm=att.onchange; } if (!cbnm) { cbnm = ["$on", nm.charAt(0).toUpperCase(), nm.slice(1), "Change"].join(''); } if (cpt[cbnm]) { cpt[cbnm].call(cpt, chg.newValue, chg.oldValue); } } finally { this.processingChange = false; } } }
javascript
function (change) { var chg = change, cpt = this.cpt; if (change.constructor === Array) { if (change.length > 0) { chg = change[0]; } else { log.error('[CptNode] Invalid change - nbr of changes: '+change.length); return; } } this.needsRefresh=true; var nm = chg.name; // property name if (nm === "") { return; // doesn't make sens (!) } var callControllerCb = true; // true if the onXXXChange() callback must be called on the controller var att, isAttributeChange = false; if (cpt.$attributes) { att = cpt.$attributes[nm]; isAttributeChange = (att !== undefined); if (isAttributeChange) { // adapt type if applicable var t = att.type; if (t) { var v = ATTRIBUTE_TYPES[t].convert(chg.newValue, att); chg.newValue = v; cpt[nm] = v; // change is already raised, no need to trigger another one through json.set() } } if (isAttributeChange && this.nodeInstance) { // notify attribute changes to the node instance (and the host) if attribute has a 2-way binding if (att._binding === 2) { chg.newValue = this.cpt[nm]; // attribute value may have been changed by the controller this.nodeInstance.onAttributeChange(chg); } } if (isAttributeChange) { // check if cb must be called depending on binding mode if (att._binding === 0) { callControllerCb = false; } } } if (callControllerCb) { if (this.processingChange === true) { // don't re-enter the change loop if we are already processing changes return; } this.processingChange = true; try { // calculate the callback name (e.g. onValueChange for the 'value' property) var cbnm=''; if (isAttributeChange) { cbnm=att.onchange; } if (!cbnm) { cbnm = ["$on", nm.charAt(0).toUpperCase(), nm.slice(1), "Change"].join(''); } if (cpt[cbnm]) { cpt[cbnm].call(cpt, chg.newValue, chg.oldValue); } } finally { this.processingChange = false; } } }
[ "function", "(", "change", ")", "{", "var", "chg", "=", "change", ",", "cpt", "=", "this", ".", "cpt", ";", "if", "(", "change", ".", "constructor", "===", "Array", ")", "{", "if", "(", "change", ".", "length", ">", "0", ")", "{", "chg", "=", "change", "[", "0", "]", ";", "}", "else", "{", "log", ".", "error", "(", "'[CptNode] Invalid change - nbr of changes: '", "+", "change", ".", "length", ")", ";", "return", ";", "}", "}", "this", ".", "needsRefresh", "=", "true", ";", "var", "nm", "=", "chg", ".", "name", ";", "// property name", "if", "(", "nm", "===", "\"\"", ")", "{", "return", ";", "// doesn't make sens (!)", "}", "var", "callControllerCb", "=", "true", ";", "// true if the onXXXChange() callback must be called on the controller", "var", "att", ",", "isAttributeChange", "=", "false", ";", "if", "(", "cpt", ".", "$attributes", ")", "{", "att", "=", "cpt", ".", "$attributes", "[", "nm", "]", ";", "isAttributeChange", "=", "(", "att", "!==", "undefined", ")", ";", "if", "(", "isAttributeChange", ")", "{", "// adapt type if applicable", "var", "t", "=", "att", ".", "type", ";", "if", "(", "t", ")", "{", "var", "v", "=", "ATTRIBUTE_TYPES", "[", "t", "]", ".", "convert", "(", "chg", ".", "newValue", ",", "att", ")", ";", "chg", ".", "newValue", "=", "v", ";", "cpt", "[", "nm", "]", "=", "v", ";", "// change is already raised, no need to trigger another one through json.set()", "}", "}", "if", "(", "isAttributeChange", "&&", "this", ".", "nodeInstance", ")", "{", "// notify attribute changes to the node instance (and the host) if attribute has a 2-way binding", "if", "(", "att", ".", "_binding", "===", "2", ")", "{", "chg", ".", "newValue", "=", "this", ".", "cpt", "[", "nm", "]", ";", "// attribute value may have been changed by the controller", "this", ".", "nodeInstance", ".", "onAttributeChange", "(", "chg", ")", ";", "}", "}", "if", "(", "isAttributeChange", ")", "{", "// check if cb must be called depending on binding mode", "if", "(", "att", ".", "_binding", "===", "0", ")", "{", "callControllerCb", "=", "false", ";", "}", "}", "}", "if", "(", "callControllerCb", ")", "{", "if", "(", "this", ".", "processingChange", "===", "true", ")", "{", "// don't re-enter the change loop if we are already processing changes", "return", ";", "}", "this", ".", "processingChange", "=", "true", ";", "try", "{", "// calculate the callback name (e.g. onValueChange for the 'value' property)", "var", "cbnm", "=", "''", ";", "if", "(", "isAttributeChange", ")", "{", "cbnm", "=", "att", ".", "onchange", ";", "}", "if", "(", "!", "cbnm", ")", "{", "cbnm", "=", "[", "\"$on\"", ",", "nm", ".", "charAt", "(", "0", ")", ".", "toUpperCase", "(", ")", ",", "nm", ".", "slice", "(", "1", ")", ",", "\"Change\"", "]", ".", "join", "(", "''", ")", ";", "}", "if", "(", "cpt", "[", "cbnm", "]", ")", "{", "cpt", "[", "cbnm", "]", ".", "call", "(", "cpt", ",", "chg", ".", "newValue", ",", "chg", ".", "oldValue", ")", ";", "}", "}", "finally", "{", "this", ".", "processingChange", "=", "false", ";", "}", "}", "}" ]
Check if not already in event handler stack and call the change event handler
[ "Check", "if", "not", "already", "in", "event", "handler", "stack", "and", "call", "the", "change", "event", "handler" ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/rt/cptwrapper.js#L276-L348
44,032
ariatemplates/hashspace
hsp/rt/cptwrapper.js
createCptWrapper
function createCptWrapper(Ctl, cptArgs) { var cw = new CptWrapper(Ctl), att, t, v; // will also create a new controller instance if (cptArgs) { var cpt=cw.cpt, ni=cptArgs.nodeInstance; if (ni.isCptComponent || ni.isCptAttElement) { // set the nodeInstance reference on the component var $attributes=cptArgs.$attributes, $content=cptArgs.$content; cw.nodeInstance = ni; cw.cpt.nodeInstance = ni; if ($attributes) { for (var k in $attributes) { // set the template attribute value on the component instance if ($attributes.hasOwnProperty(k)) { att=cw.cpt.$attributes[k]; t=att.type; v=$attributes[k]; if (t && ATTRIBUTE_TYPES[t]) { // in case of invalid type an error should already have been logged // a type is defined - so let's convert the value v=ATTRIBUTE_TYPES[t].convert(v, att); } json.set(cpt,k,v); } } } if ($content) { if (cpt.$content) { log.error(ni+" Component controller cannot use '$content' for another property than child attribute elements"); } else { // create the content property on the component instance json.set(cpt,"$content",$content); } } } } return cw; }
javascript
function createCptWrapper(Ctl, cptArgs) { var cw = new CptWrapper(Ctl), att, t, v; // will also create a new controller instance if (cptArgs) { var cpt=cw.cpt, ni=cptArgs.nodeInstance; if (ni.isCptComponent || ni.isCptAttElement) { // set the nodeInstance reference on the component var $attributes=cptArgs.$attributes, $content=cptArgs.$content; cw.nodeInstance = ni; cw.cpt.nodeInstance = ni; if ($attributes) { for (var k in $attributes) { // set the template attribute value on the component instance if ($attributes.hasOwnProperty(k)) { att=cw.cpt.$attributes[k]; t=att.type; v=$attributes[k]; if (t && ATTRIBUTE_TYPES[t]) { // in case of invalid type an error should already have been logged // a type is defined - so let's convert the value v=ATTRIBUTE_TYPES[t].convert(v, att); } json.set(cpt,k,v); } } } if ($content) { if (cpt.$content) { log.error(ni+" Component controller cannot use '$content' for another property than child attribute elements"); } else { // create the content property on the component instance json.set(cpt,"$content",$content); } } } } return cw; }
[ "function", "createCptWrapper", "(", "Ctl", ",", "cptArgs", ")", "{", "var", "cw", "=", "new", "CptWrapper", "(", "Ctl", ")", ",", "att", ",", "t", ",", "v", ";", "// will also create a new controller instance", "if", "(", "cptArgs", ")", "{", "var", "cpt", "=", "cw", ".", "cpt", ",", "ni", "=", "cptArgs", ".", "nodeInstance", ";", "if", "(", "ni", ".", "isCptComponent", "||", "ni", ".", "isCptAttElement", ")", "{", "// set the nodeInstance reference on the component", "var", "$attributes", "=", "cptArgs", ".", "$attributes", ",", "$content", "=", "cptArgs", ".", "$content", ";", "cw", ".", "nodeInstance", "=", "ni", ";", "cw", ".", "cpt", ".", "nodeInstance", "=", "ni", ";", "if", "(", "$attributes", ")", "{", "for", "(", "var", "k", "in", "$attributes", ")", "{", "// set the template attribute value on the component instance", "if", "(", "$attributes", ".", "hasOwnProperty", "(", "k", ")", ")", "{", "att", "=", "cw", ".", "cpt", ".", "$attributes", "[", "k", "]", ";", "t", "=", "att", ".", "type", ";", "v", "=", "$attributes", "[", "k", "]", ";", "if", "(", "t", "&&", "ATTRIBUTE_TYPES", "[", "t", "]", ")", "{", "// in case of invalid type an error should already have been logged", "// a type is defined - so let's convert the value", "v", "=", "ATTRIBUTE_TYPES", "[", "t", "]", ".", "convert", "(", "v", ",", "att", ")", ";", "}", "json", ".", "set", "(", "cpt", ",", "k", ",", "v", ")", ";", "}", "}", "}", "if", "(", "$content", ")", "{", "if", "(", "cpt", ".", "$content", ")", "{", "log", ".", "error", "(", "ni", "+", "\" Component controller cannot use '$content' for another property than child attribute elements\"", ")", ";", "}", "else", "{", "// create the content property on the component instance", "json", ".", "set", "(", "cpt", ",", "\"$content\"", ",", "$content", ")", ";", "}", "}", "}", "}", "return", "cw", ";", "}" ]
Create a Component wrapper and initialize it correctly according to the attributes passed as arguments @param {Object} cptArgs the component arguments e.g. { nodeInstance:x, $attributes:{att1:{}, att2:{}}, $content:[] }
[ "Create", "a", "Component", "wrapper", "and", "initialize", "it", "correctly", "according", "to", "the", "attributes", "passed", "as", "arguments" ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/rt/cptwrapper.js#L388-L428
44,033
fardog/node-xkcd-password
index.js
XKCDPassword
function XKCDPassword() { if (!(this instanceof XKCDPassword)) return new XKCDPassword() var self = this events.EventEmitter.call(self) self.wordlist = null self.wordfile = null // if we've got a wordlist at the ready self.ready = false self.initialized = false return this }
javascript
function XKCDPassword() { if (!(this instanceof XKCDPassword)) return new XKCDPassword() var self = this events.EventEmitter.call(self) self.wordlist = null self.wordfile = null // if we've got a wordlist at the ready self.ready = false self.initialized = false return this }
[ "function", "XKCDPassword", "(", ")", "{", "if", "(", "!", "(", "this", "instanceof", "XKCDPassword", ")", ")", "return", "new", "XKCDPassword", "(", ")", "var", "self", "=", "this", "events", ".", "EventEmitter", ".", "call", "(", "self", ")", "self", ".", "wordlist", "=", "null", "self", ".", "wordfile", "=", "null", "// if we've got a wordlist at the ready", "self", ".", "ready", "=", "false", "self", ".", "initialized", "=", "false", "return", "this", "}" ]
Creates the password generator. @constructor @since 0.0.1 @returns {Generator} the word generator
[ "Creates", "the", "password", "generator", "." ]
a45ec266a7489977b83e9cdf48239e7adf269271
https://github.com/fardog/node-xkcd-password/blob/a45ec266a7489977b83e9cdf48239e7adf269271/index.js#L34-L49
44,034
mljs/fft
src/fftlib.js
fft2d
function fft2d(re, im) { var tre = [], tim = [], i = 0; // x-axis for (var y = 0; y < _n; y++) { i = y * _n; for (var x1 = 0; x1 < _n; x1++) { tre[x1] = re[x1 + i]; tim[x1] = im[x1 + i]; } fft1d(tre, tim); for (var x2 = 0; x2 < _n; x2++) { re[x2 + i] = tre[x2]; im[x2 + i] = tim[x2]; } } // y-axis for (var x = 0; x < _n; x++) { for (var y1 = 0; y1 < _n; y1++) { i = x + y1 * _n; tre[y1] = re[i]; tim[y1] = im[i]; } fft1d(tre, tim); for (var y2 = 0; y2 < _n; y2++) { i = x + y2 * _n; re[i] = tre[y2]; im[i] = tim[y2]; } } }
javascript
function fft2d(re, im) { var tre = [], tim = [], i = 0; // x-axis for (var y = 0; y < _n; y++) { i = y * _n; for (var x1 = 0; x1 < _n; x1++) { tre[x1] = re[x1 + i]; tim[x1] = im[x1 + i]; } fft1d(tre, tim); for (var x2 = 0; x2 < _n; x2++) { re[x2 + i] = tre[x2]; im[x2 + i] = tim[x2]; } } // y-axis for (var x = 0; x < _n; x++) { for (var y1 = 0; y1 < _n; y1++) { i = x + y1 * _n; tre[y1] = re[i]; tim[y1] = im[i]; } fft1d(tre, tim); for (var y2 = 0; y2 < _n; y2++) { i = x + y2 * _n; re[i] = tre[y2]; im[i] = tim[y2]; } } }
[ "function", "fft2d", "(", "re", ",", "im", ")", "{", "var", "tre", "=", "[", "]", ",", "tim", "=", "[", "]", ",", "i", "=", "0", ";", "// x-axis", "for", "(", "var", "y", "=", "0", ";", "y", "<", "_n", ";", "y", "++", ")", "{", "i", "=", "y", "*", "_n", ";", "for", "(", "var", "x1", "=", "0", ";", "x1", "<", "_n", ";", "x1", "++", ")", "{", "tre", "[", "x1", "]", "=", "re", "[", "x1", "+", "i", "]", ";", "tim", "[", "x1", "]", "=", "im", "[", "x1", "+", "i", "]", ";", "}", "fft1d", "(", "tre", ",", "tim", ")", ";", "for", "(", "var", "x2", "=", "0", ";", "x2", "<", "_n", ";", "x2", "++", ")", "{", "re", "[", "x2", "+", "i", "]", "=", "tre", "[", "x2", "]", ";", "im", "[", "x2", "+", "i", "]", "=", "tim", "[", "x2", "]", ";", "}", "}", "// y-axis", "for", "(", "var", "x", "=", "0", ";", "x", "<", "_n", ";", "x", "++", ")", "{", "for", "(", "var", "y1", "=", "0", ";", "y1", "<", "_n", ";", "y1", "++", ")", "{", "i", "=", "x", "+", "y1", "*", "_n", ";", "tre", "[", "y1", "]", "=", "re", "[", "i", "]", ";", "tim", "[", "y1", "]", "=", "im", "[", "i", "]", ";", "}", "fft1d", "(", "tre", ",", "tim", ")", ";", "for", "(", "var", "y2", "=", "0", ";", "y2", "<", "_n", ";", "y2", "++", ")", "{", "i", "=", "x", "+", "y2", "*", "_n", ";", "re", "[", "i", "]", "=", "tre", "[", "y2", "]", ";", "im", "[", "i", "]", "=", "tim", "[", "y2", "]", ";", "}", "}", "}" ]
2D-FFT Not very useful if the number of rows have to be equal to cols
[ "2D", "-", "FFT", "Not", "very", "useful", "if", "the", "number", "of", "rows", "have", "to", "be", "equal", "to", "cols" ]
436ff9535ded13393f359b50d55c68e94e2e8d51
https://github.com/mljs/fft/blob/436ff9535ded13393f359b50d55c68e94e2e8d51/src/fftlib.js#L42-L73
44,035
mljs/fft
src/fftlib.js
ifft2d
function ifft2d(re, im) { var tre = [], tim = [], i = 0; // x-axis for (var y = 0; y < _n; y++) { i = y * _n; for (var x1 = 0; x1 < _n; x1++) { tre[x1] = re[x1 + i]; tim[x1] = im[x1 + i]; } ifft1d(tre, tim); for (var x2 = 0; x2 < _n; x2++) { re[x2 + i] = tre[x2]; im[x2 + i] = tim[x2]; } } // y-axis for (var x = 0; x < _n; x++) { for (var y1 = 0; y1 < _n; y1++) { i = x + y1 * _n; tre[y1] = re[i]; tim[y1] = im[i]; } ifft1d(tre, tim); for (var y2 = 0; y2 < _n; y2++) { i = x + y2 * _n; re[i] = tre[y2]; im[i] = tim[y2]; } } }
javascript
function ifft2d(re, im) { var tre = [], tim = [], i = 0; // x-axis for (var y = 0; y < _n; y++) { i = y * _n; for (var x1 = 0; x1 < _n; x1++) { tre[x1] = re[x1 + i]; tim[x1] = im[x1 + i]; } ifft1d(tre, tim); for (var x2 = 0; x2 < _n; x2++) { re[x2 + i] = tre[x2]; im[x2 + i] = tim[x2]; } } // y-axis for (var x = 0; x < _n; x++) { for (var y1 = 0; y1 < _n; y1++) { i = x + y1 * _n; tre[y1] = re[i]; tim[y1] = im[i]; } ifft1d(tre, tim); for (var y2 = 0; y2 < _n; y2++) { i = x + y2 * _n; re[i] = tre[y2]; im[i] = tim[y2]; } } }
[ "function", "ifft2d", "(", "re", ",", "im", ")", "{", "var", "tre", "=", "[", "]", ",", "tim", "=", "[", "]", ",", "i", "=", "0", ";", "// x-axis", "for", "(", "var", "y", "=", "0", ";", "y", "<", "_n", ";", "y", "++", ")", "{", "i", "=", "y", "*", "_n", ";", "for", "(", "var", "x1", "=", "0", ";", "x1", "<", "_n", ";", "x1", "++", ")", "{", "tre", "[", "x1", "]", "=", "re", "[", "x1", "+", "i", "]", ";", "tim", "[", "x1", "]", "=", "im", "[", "x1", "+", "i", "]", ";", "}", "ifft1d", "(", "tre", ",", "tim", ")", ";", "for", "(", "var", "x2", "=", "0", ";", "x2", "<", "_n", ";", "x2", "++", ")", "{", "re", "[", "x2", "+", "i", "]", "=", "tre", "[", "x2", "]", ";", "im", "[", "x2", "+", "i", "]", "=", "tim", "[", "x2", "]", ";", "}", "}", "// y-axis", "for", "(", "var", "x", "=", "0", ";", "x", "<", "_n", ";", "x", "++", ")", "{", "for", "(", "var", "y1", "=", "0", ";", "y1", "<", "_n", ";", "y1", "++", ")", "{", "i", "=", "x", "+", "y1", "*", "_n", ";", "tre", "[", "y1", "]", "=", "re", "[", "i", "]", ";", "tim", "[", "y1", "]", "=", "im", "[", "i", "]", ";", "}", "ifft1d", "(", "tre", ",", "tim", ")", ";", "for", "(", "var", "y2", "=", "0", ";", "y2", "<", "_n", ";", "y2", "++", ")", "{", "i", "=", "x", "+", "y2", "*", "_n", ";", "re", "[", "i", "]", "=", "tre", "[", "y2", "]", ";", "im", "[", "i", "]", "=", "tim", "[", "y2", "]", ";", "}", "}", "}" ]
2D-IFFT
[ "2D", "-", "IFFT" ]
436ff9535ded13393f359b50d55c68e94e2e8d51
https://github.com/mljs/fft/blob/436ff9535ded13393f359b50d55c68e94e2e8d51/src/fftlib.js#L76-L107
44,036
ariatemplates/hashspace
hsp/compiler/jsgenerator/processors.js
formatExpression
function formatExpression (expression, firstIndex, walker) { var category = expression.category, codeStmts, code = '', nextIndex = firstIndex; var exprIndex = firstIndex; var expAst; if (category === 'jsexptext') { //compile the expression to detect errors and parse-out identifiers try { expAst = exParser(expression.value); exIdentifiers(expAst).forEach(function(ident){ walker.addGlobalRef(ident); }); codeStmts = ['e', exprIndex, ':[9,"', ('' + expression.value).replace(/"/g, "\\\"").replace(/\\\\"/g, "\\\""), '"']; if (expression.bound === false) { codeStmts.push(',false'); } codeStmts.push(']'); code = codeStmts.join(''); } catch (err) { walker.logError("Invalid expression: '" + expression.value + "'", expression); } nextIndex++; } else { walker.logError("Unsupported expression: " + category, expression); } return { code : code, ast: expAst, exprIdx : exprIndex, nextIndex : nextIndex }; }
javascript
function formatExpression (expression, firstIndex, walker) { var category = expression.category, codeStmts, code = '', nextIndex = firstIndex; var exprIndex = firstIndex; var expAst; if (category === 'jsexptext') { //compile the expression to detect errors and parse-out identifiers try { expAst = exParser(expression.value); exIdentifiers(expAst).forEach(function(ident){ walker.addGlobalRef(ident); }); codeStmts = ['e', exprIndex, ':[9,"', ('' + expression.value).replace(/"/g, "\\\"").replace(/\\\\"/g, "\\\""), '"']; if (expression.bound === false) { codeStmts.push(',false'); } codeStmts.push(']'); code = codeStmts.join(''); } catch (err) { walker.logError("Invalid expression: '" + expression.value + "'", expression); } nextIndex++; } else { walker.logError("Unsupported expression: " + category, expression); } return { code : code, ast: expAst, exprIdx : exprIndex, nextIndex : nextIndex }; }
[ "function", "formatExpression", "(", "expression", ",", "firstIndex", ",", "walker", ")", "{", "var", "category", "=", "expression", ".", "category", ",", "codeStmts", ",", "code", "=", "''", ",", "nextIndex", "=", "firstIndex", ";", "var", "exprIndex", "=", "firstIndex", ";", "var", "expAst", ";", "if", "(", "category", "===", "'jsexptext'", ")", "{", "//compile the expression to detect errors and parse-out identifiers", "try", "{", "expAst", "=", "exParser", "(", "expression", ".", "value", ")", ";", "exIdentifiers", "(", "expAst", ")", ".", "forEach", "(", "function", "(", "ident", ")", "{", "walker", ".", "addGlobalRef", "(", "ident", ")", ";", "}", ")", ";", "codeStmts", "=", "[", "'e'", ",", "exprIndex", ",", "':[9,\"'", ",", "(", "''", "+", "expression", ".", "value", ")", ".", "replace", "(", "/", "\"", "/", "g", ",", "\"\\\\\\\"\"", ")", ".", "replace", "(", "/", "\\\\\\\\\"", "/", "g", ",", "\"\\\\\\\"\"", ")", ",", "'\"'", "]", ";", "if", "(", "expression", ".", "bound", "===", "false", ")", "{", "codeStmts", ".", "push", "(", "',false'", ")", ";", "}", "codeStmts", ".", "push", "(", "']'", ")", ";", "code", "=", "codeStmts", ".", "join", "(", "''", ")", ";", "}", "catch", "(", "err", ")", "{", "walker", ".", "logError", "(", "\"Invalid expression: '\"", "+", "expression", ".", "value", "+", "\"'\"", ",", "expression", ")", ";", "}", "nextIndex", "++", ";", "}", "else", "{", "walker", ".", "logError", "(", "\"Unsupported expression: \"", "+", "category", ",", "expression", ")", ";", "}", "return", "{", "code", ":", "code", ",", "ast", ":", "expAst", ",", "exprIdx", ":", "exprIndex", ",", "nextIndex", ":", "nextIndex", "}", ";", "}" ]
Formats an expression according to its category. @param {Object} expression the expression to format. @param {Integer} firstIndex index of the expression. @param {TemplateWalker} walker the template walker instance. @return {Object} the expression string and the next expression index that can be used
[ "Formats", "an", "expression", "according", "to", "its", "category", "." ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/compiler/jsgenerator/processors.js#L343-L377
44,037
ariatemplates/hashspace
hsp/compiler/jsgenerator/processors.js
formatTextBlock
function formatTextBlock (node, nextExprIndex, walker) { var content = node.content, item, exprArray = [], args = [], index = 0; // idx is the index in the $text array // (=args) for (var i = 0; i < content.length; i++) { item = content[i]; if (item.type === "text") { if (index % 2 === 0) { // even index: arg must be a string args[index] = '"' + escapeNewLines(item.value.replace(/"/g, "\\\"")) + '"'; index++; } else { // odd index: arg must be an expression - so add the text to the previous item if (index > 0) { args[index - 1] = args[index - 1].slice(0, -1) + escapeNewLines(item.value.replace(/"/g, "\\\"")) + '"'; } else { // we should never get there as index is odd ! walker.logError("Invalid textblock structure", node); } } } else if (item.type === "expression") { if (index % 2 === 0) { // even index: arg must be a string args[index] = '""'; index++; } var expr = formatExpression(item, nextExprIndex, walker); nextExprIndex = expr.nextIndex; if (expr.code) { if (expr.ast instanceof Array) { //it is a multi-statement expression that is not allowed in this context walker.logError("Invalid expression: " + item.value, item); args[index] = 0; // invalid expression } else { exprArray.push(expr.code); args[index] = expr.exprIdx; // expression index } } else { args[index] = 0; // invalid expression } index++; } } return { exprArg : exprArray.length ? '{' + exprArray.join(",") + '}' : "0", nextIndex : nextExprIndex, blockArgs : args.length ? '[' + args.join(',') + ']' : "[]" }; }
javascript
function formatTextBlock (node, nextExprIndex, walker) { var content = node.content, item, exprArray = [], args = [], index = 0; // idx is the index in the $text array // (=args) for (var i = 0; i < content.length; i++) { item = content[i]; if (item.type === "text") { if (index % 2 === 0) { // even index: arg must be a string args[index] = '"' + escapeNewLines(item.value.replace(/"/g, "\\\"")) + '"'; index++; } else { // odd index: arg must be an expression - so add the text to the previous item if (index > 0) { args[index - 1] = args[index - 1].slice(0, -1) + escapeNewLines(item.value.replace(/"/g, "\\\"")) + '"'; } else { // we should never get there as index is odd ! walker.logError("Invalid textblock structure", node); } } } else if (item.type === "expression") { if (index % 2 === 0) { // even index: arg must be a string args[index] = '""'; index++; } var expr = formatExpression(item, nextExprIndex, walker); nextExprIndex = expr.nextIndex; if (expr.code) { if (expr.ast instanceof Array) { //it is a multi-statement expression that is not allowed in this context walker.logError("Invalid expression: " + item.value, item); args[index] = 0; // invalid expression } else { exprArray.push(expr.code); args[index] = expr.exprIdx; // expression index } } else { args[index] = 0; // invalid expression } index++; } } return { exprArg : exprArray.length ? '{' + exprArray.join(",") + '}' : "0", nextIndex : nextExprIndex, blockArgs : args.length ? '[' + args.join(',') + ']' : "[]" }; }
[ "function", "formatTextBlock", "(", "node", ",", "nextExprIndex", ",", "walker", ")", "{", "var", "content", "=", "node", ".", "content", ",", "item", ",", "exprArray", "=", "[", "]", ",", "args", "=", "[", "]", ",", "index", "=", "0", ";", "// idx is the index in the $text array", "// (=args)", "for", "(", "var", "i", "=", "0", ";", "i", "<", "content", ".", "length", ";", "i", "++", ")", "{", "item", "=", "content", "[", "i", "]", ";", "if", "(", "item", ".", "type", "===", "\"text\"", ")", "{", "if", "(", "index", "%", "2", "===", "0", ")", "{", "// even index: arg must be a string", "args", "[", "index", "]", "=", "'\"'", "+", "escapeNewLines", "(", "item", ".", "value", ".", "replace", "(", "/", "\"", "/", "g", ",", "\"\\\\\\\"\"", ")", ")", "+", "'\"'", ";", "index", "++", ";", "}", "else", "{", "// odd index: arg must be an expression - so add the text to the previous item", "if", "(", "index", ">", "0", ")", "{", "args", "[", "index", "-", "1", "]", "=", "args", "[", "index", "-", "1", "]", ".", "slice", "(", "0", ",", "-", "1", ")", "+", "escapeNewLines", "(", "item", ".", "value", ".", "replace", "(", "/", "\"", "/", "g", ",", "\"\\\\\\\"\"", ")", ")", "+", "'\"'", ";", "}", "else", "{", "// we should never get there as index is odd !", "walker", ".", "logError", "(", "\"Invalid textblock structure\"", ",", "node", ")", ";", "}", "}", "}", "else", "if", "(", "item", ".", "type", "===", "\"expression\"", ")", "{", "if", "(", "index", "%", "2", "===", "0", ")", "{", "// even index: arg must be a string", "args", "[", "index", "]", "=", "'\"\"'", ";", "index", "++", ";", "}", "var", "expr", "=", "formatExpression", "(", "item", ",", "nextExprIndex", ",", "walker", ")", ";", "nextExprIndex", "=", "expr", ".", "nextIndex", ";", "if", "(", "expr", ".", "code", ")", "{", "if", "(", "expr", ".", "ast", "instanceof", "Array", ")", "{", "//it is a multi-statement expression that is not allowed in this context", "walker", ".", "logError", "(", "\"Invalid expression: \"", "+", "item", ".", "value", ",", "item", ")", ";", "args", "[", "index", "]", "=", "0", ";", "// invalid expression", "}", "else", "{", "exprArray", ".", "push", "(", "expr", ".", "code", ")", ";", "args", "[", "index", "]", "=", "expr", ".", "exprIdx", ";", "// expression index", "}", "}", "else", "{", "args", "[", "index", "]", "=", "0", ";", "// invalid expression", "}", "index", "++", ";", "}", "}", "return", "{", "exprArg", ":", "exprArray", ".", "length", "?", "'{'", "+", "exprArray", ".", "join", "(", "\",\"", ")", "+", "'}'", ":", "\"0\"", ",", "nextIndex", ":", "nextExprIndex", ",", "blockArgs", ":", "args", ".", "length", "?", "'['", "+", "args", ".", "join", "(", "','", ")", "+", "']'", ":", "\"[]\"", "}", ";", "}" ]
Format the textblock content for textblock and attribute nodes. @param {Node} node the current Node object as built by the treebuilder. @param {Integer} nextExprIndex the index of the next expression. @param {TreeWalker} walker the template walker instance. @return {Object} a snippet of Javascript code built from the node.
[ "Format", "the", "textblock", "content", "for", "textblock", "and", "attribute", "nodes", "." ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/compiler/jsgenerator/processors.js#L386-L434
44,038
ariatemplates/hashspace
hsp/rt/log.js
formatValue
function formatValue(v,depth) { if (depth===undefined || depth===null) { depth=1; } var tp=typeof(v), val; if (v===null) { return "null"; } else if (v===undefined) { return "undefined"; } else if (tp==='object') { if (depth>0) { var properties=[]; if (v.constructor===Array) { for (var i=0,sz=v.length;sz>i;i++) { val=v[i]; if (typeof(val)==='string') { properties.push(i+':"'+formatValue(val,depth-1)+'"'); } else { properties.push(i+":"+formatValue(val,depth-1)); } } return "["+properties.join(", ")+"]"; } else { var keys=[]; for (var k in v) { if (k.match(/^\+/)) { // this is a meta-data property continue; } keys.push(k); } // sort keys as IE 8 uses a different order than other browsers keys.sort(lexicalSort); for (var i=0,sz=keys.length;sz>i;i++) { val=v[keys[i]]; if (typeof(val)==='string') { properties.push(keys[i]+':"'+formatValue(val,depth-1)+'"'); } else { properties.push(keys[i]+':'+formatValue(val,depth-1)); } } return "{"+properties.join(", ")+"}"; } } else { if (v.constructor===Array) { return "Array["+v.length+"]"; } else if (v.constructor===Function) { return "Function"; } else { return "Object"; } } } else if (tp==='function') { return "Function"; } else { return ''+v; } }
javascript
function formatValue(v,depth) { if (depth===undefined || depth===null) { depth=1; } var tp=typeof(v), val; if (v===null) { return "null"; } else if (v===undefined) { return "undefined"; } else if (tp==='object') { if (depth>0) { var properties=[]; if (v.constructor===Array) { for (var i=0,sz=v.length;sz>i;i++) { val=v[i]; if (typeof(val)==='string') { properties.push(i+':"'+formatValue(val,depth-1)+'"'); } else { properties.push(i+":"+formatValue(val,depth-1)); } } return "["+properties.join(", ")+"]"; } else { var keys=[]; for (var k in v) { if (k.match(/^\+/)) { // this is a meta-data property continue; } keys.push(k); } // sort keys as IE 8 uses a different order than other browsers keys.sort(lexicalSort); for (var i=0,sz=keys.length;sz>i;i++) { val=v[keys[i]]; if (typeof(val)==='string') { properties.push(keys[i]+':"'+formatValue(val,depth-1)+'"'); } else { properties.push(keys[i]+':'+formatValue(val,depth-1)); } } return "{"+properties.join(", ")+"}"; } } else { if (v.constructor===Array) { return "Array["+v.length+"]"; } else if (v.constructor===Function) { return "Function"; } else { return "Object"; } } } else if (tp==='function') { return "Function"; } else { return ''+v; } }
[ "function", "formatValue", "(", "v", ",", "depth", ")", "{", "if", "(", "depth", "===", "undefined", "||", "depth", "===", "null", ")", "{", "depth", "=", "1", ";", "}", "var", "tp", "=", "typeof", "(", "v", ")", ",", "val", ";", "if", "(", "v", "===", "null", ")", "{", "return", "\"null\"", ";", "}", "else", "if", "(", "v", "===", "undefined", ")", "{", "return", "\"undefined\"", ";", "}", "else", "if", "(", "tp", "===", "'object'", ")", "{", "if", "(", "depth", ">", "0", ")", "{", "var", "properties", "=", "[", "]", ";", "if", "(", "v", ".", "constructor", "===", "Array", ")", "{", "for", "(", "var", "i", "=", "0", ",", "sz", "=", "v", ".", "length", ";", "sz", ">", "i", ";", "i", "++", ")", "{", "val", "=", "v", "[", "i", "]", ";", "if", "(", "typeof", "(", "val", ")", "===", "'string'", ")", "{", "properties", ".", "push", "(", "i", "+", "':\"'", "+", "formatValue", "(", "val", ",", "depth", "-", "1", ")", "+", "'\"'", ")", ";", "}", "else", "{", "properties", ".", "push", "(", "i", "+", "\":\"", "+", "formatValue", "(", "val", ",", "depth", "-", "1", ")", ")", ";", "}", "}", "return", "\"[\"", "+", "properties", ".", "join", "(", "\", \"", ")", "+", "\"]\"", ";", "}", "else", "{", "var", "keys", "=", "[", "]", ";", "for", "(", "var", "k", "in", "v", ")", "{", "if", "(", "k", ".", "match", "(", "/", "^\\+", "/", ")", ")", "{", "// this is a meta-data property", "continue", ";", "}", "keys", ".", "push", "(", "k", ")", ";", "}", "// sort keys as IE 8 uses a different order than other browsers", "keys", ".", "sort", "(", "lexicalSort", ")", ";", "for", "(", "var", "i", "=", "0", ",", "sz", "=", "keys", ".", "length", ";", "sz", ">", "i", ";", "i", "++", ")", "{", "val", "=", "v", "[", "keys", "[", "i", "]", "]", ";", "if", "(", "typeof", "(", "val", ")", "===", "'string'", ")", "{", "properties", ".", "push", "(", "keys", "[", "i", "]", "+", "':\"'", "+", "formatValue", "(", "val", ",", "depth", "-", "1", ")", "+", "'\"'", ")", ";", "}", "else", "{", "properties", ".", "push", "(", "keys", "[", "i", "]", "+", "':'", "+", "formatValue", "(", "val", ",", "depth", "-", "1", ")", ")", ";", "}", "}", "return", "\"{\"", "+", "properties", ".", "join", "(", "\", \"", ")", "+", "\"}\"", ";", "}", "}", "else", "{", "if", "(", "v", ".", "constructor", "===", "Array", ")", "{", "return", "\"Array[\"", "+", "v", ".", "length", "+", "\"]\"", ";", "}", "else", "if", "(", "v", ".", "constructor", "===", "Function", ")", "{", "return", "\"Function\"", ";", "}", "else", "{", "return", "\"Object\"", ";", "}", "}", "}", "else", "if", "(", "tp", "===", "'function'", ")", "{", "return", "\"Function\"", ";", "}", "else", "{", "return", "''", "+", "v", ";", "}", "}" ]
Format a JS entity for the log @param v {Object} the value to format @param depth {Number} the formatting of objects and arrays (default: 1)
[ "Format", "a", "JS", "entity", "for", "the", "log" ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/rt/log.js#L248-L306
44,039
ariatemplates/hashspace
hsp/expressions/manipulator.js
function(scope, defaultValue) { var val = evaluator(tree, scope); if( typeof defaultValue === 'undefined') { return val; } else { return (val === undefined || val === null || val != val) ? defaultValue : val; } }
javascript
function(scope, defaultValue) { var val = evaluator(tree, scope); if( typeof defaultValue === 'undefined') { return val; } else { return (val === undefined || val === null || val != val) ? defaultValue : val; } }
[ "function", "(", "scope", ",", "defaultValue", ")", "{", "var", "val", "=", "evaluator", "(", "tree", ",", "scope", ")", ";", "if", "(", "typeof", "defaultValue", "===", "'undefined'", ")", "{", "return", "val", ";", "}", "else", "{", "return", "(", "val", "===", "undefined", "||", "val", "===", "null", "||", "val", "!=", "val", ")", "?", "defaultValue", ":", "val", ";", "}", "}" ]
Evaluates an expression against a scope @param scope @return {*} - value of an expression in a given scope
[ "Evaluates", "an", "expression", "against", "a", "scope" ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/expressions/manipulator.js#L38-L45
44,040
ariatemplates/hashspace
hsp/expressions/manipulator.js
function(scope, newValue) { if (!isAssignable) { throw new Error('Expression "' + input + '" is not assignable'); } if (tree.a === 'idn') { json.set(scope, tree.v, newValue); } else if (tree.a === 'bnr') { json.set(evaluator(tree.l, scope), evaluator(tree.r, scope), newValue); } }
javascript
function(scope, newValue) { if (!isAssignable) { throw new Error('Expression "' + input + '" is not assignable'); } if (tree.a === 'idn') { json.set(scope, tree.v, newValue); } else if (tree.a === 'bnr') { json.set(evaluator(tree.l, scope), evaluator(tree.r, scope), newValue); } }
[ "function", "(", "scope", ",", "newValue", ")", "{", "if", "(", "!", "isAssignable", ")", "{", "throw", "new", "Error", "(", "'Expression \"'", "+", "input", "+", "'\" is not assignable'", ")", ";", "}", "if", "(", "tree", ".", "a", "===", "'idn'", ")", "{", "json", ".", "set", "(", "scope", ",", "tree", ".", "v", ",", "newValue", ")", ";", "}", "else", "if", "(", "tree", ".", "a", "===", "'bnr'", ")", "{", "json", ".", "set", "(", "evaluator", "(", "tree", ".", "l", ",", "scope", ")", ",", "evaluator", "(", "tree", ".", "r", ",", "scope", ")", ",", "newValue", ")", ";", "}", "}" ]
Sets value of an expression on a scope. Not all expressions are assignable. @param scope - scope that should be modified @param {*} a new value for a given expression and scope
[ "Sets", "value", "of", "an", "expression", "on", "a", "scope", ".", "Not", "all", "expressions", "are", "assignable", "." ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/expressions/manipulator.js#L52-L62
44,041
sbisbee/sag-js
src/server.private.js
setURLParameter
function setURLParameter(url, key, value) { if(typeof url !== 'string') { throw new Error('URLs must be a string'); } if(urlUtils) { //node.js url = urlUtils.parse(url); url.search = ((url.search) ? url.search + '&' : '?') + key + '=' + value; url = urlUtils.format(url); } else { //browser url = url.split('?'); url[1] = ((url[1]) ? url[1] + '&' : '') + key + '=' + value; url = url.join('?'); } return url; }
javascript
function setURLParameter(url, key, value) { if(typeof url !== 'string') { throw new Error('URLs must be a string'); } if(urlUtils) { //node.js url = urlUtils.parse(url); url.search = ((url.search) ? url.search + '&' : '?') + key + '=' + value; url = urlUtils.format(url); } else { //browser url = url.split('?'); url[1] = ((url[1]) ? url[1] + '&' : '') + key + '=' + value; url = url.join('?'); } return url; }
[ "function", "setURLParameter", "(", "url", ",", "key", ",", "value", ")", "{", "if", "(", "typeof", "url", "!==", "'string'", ")", "{", "throw", "new", "Error", "(", "'URLs must be a string'", ")", ";", "}", "if", "(", "urlUtils", ")", "{", "//node.js", "url", "=", "urlUtils", ".", "parse", "(", "url", ")", ";", "url", ".", "search", "=", "(", "(", "url", ".", "search", ")", "?", "url", ".", "search", "+", "'&'", ":", "'?'", ")", "+", "key", "+", "'='", "+", "value", ";", "url", "=", "urlUtils", ".", "format", "(", "url", ")", ";", "}", "else", "{", "//browser", "url", "=", "url", ".", "split", "(", "'?'", ")", ";", "url", "[", "1", "]", "=", "(", "(", "url", "[", "1", "]", ")", "?", "url", "[", "1", "]", "+", "'&'", ":", "''", ")", "+", "key", "+", "'='", "+", "value", ";", "url", "=", "url", ".", "join", "(", "'?'", ")", ";", "}", "return", "url", ";", "}" ]
Adds a query param to a URL.
[ "Adds", "a", "query", "param", "to", "a", "URL", "." ]
f9aa69d07e2e6320894bb63859ff293c2285a586
https://github.com/sbisbee/sag-js/blob/f9aa69d07e2e6320894bb63859ff293c2285a586/src/server.private.js#L242-L265
44,042
vigneshshanmugam/js-cpa
lib/hash.js
hashcons
function hashcons(node) { const keys = t.VISITOR_KEYS[node.type]; if (!keys) return; let hash = hashcode(node); for (const key of keys) { const subNode = node[key]; if (Array.isArray(subNode)) { for (const child of subNode) { if (child) { hash += hashcons(child); } } } else if (subNode) { hash += hashcons(subNode); } } return hash; }
javascript
function hashcons(node) { const keys = t.VISITOR_KEYS[node.type]; if (!keys) return; let hash = hashcode(node); for (const key of keys) { const subNode = node[key]; if (Array.isArray(subNode)) { for (const child of subNode) { if (child) { hash += hashcons(child); } } } else if (subNode) { hash += hashcons(subNode); } } return hash; }
[ "function", "hashcons", "(", "node", ")", "{", "const", "keys", "=", "t", ".", "VISITOR_KEYS", "[", "node", ".", "type", "]", ";", "if", "(", "!", "keys", ")", "return", ";", "let", "hash", "=", "hashcode", "(", "node", ")", ";", "for", "(", "const", "key", "of", "keys", ")", "{", "const", "subNode", "=", "node", "[", "key", "]", ";", "if", "(", "Array", ".", "isArray", "(", "subNode", ")", ")", "{", "for", "(", "const", "child", "of", "subNode", ")", "{", "if", "(", "child", ")", "{", "hash", "+=", "hashcons", "(", "child", ")", ";", "}", "}", "}", "else", "if", "(", "subNode", ")", "{", "hash", "+=", "hashcons", "(", "subNode", ")", ";", "}", "}", "return", "hash", ";", "}" ]
Hashconsing - return the hash of an ASTNode computed recursively @param {ASTNode} node
[ "Hashconsing", "-", "return", "the", "hash", "of", "an", "ASTNode", "computed", "recursively" ]
ebcc5952ecc1909cbe5e3ca69a974409b65ccdf8
https://github.com/vigneshshanmugam/js-cpa/blob/ebcc5952ecc1909cbe5e3ca69a974409b65ccdf8/lib/hash.js#L12-L33
44,043
ariatemplates/hashspace
hsp/compiler/jsgenerator/jsvalidator/validator.js
formatError
function formatError (error, input) { var message = error.toString().replace(/\s*\(\d*\:\d*\)\s*$/i, ''); // remove line number / col number var beforeMatch = ('' + input.slice(0, error.pos)).match(/.*$/i); var afterMatch = ('' + input.slice(error.pos)).match(/.*/i); var before = beforeMatch ? beforeMatch[0] : ''; var after = afterMatch ? afterMatch[0] : ''; // Prepare line info for txt display var cursorPos = before.length; var errChar = (after.length) ? after.slice(0, 1) : 'X'; var lineStr = before + after; var lncursor = []; for (var i = 0; i < lineStr.length; i++) { lncursor[i] = (i === cursorPos) ? '^' : '-'; } var lineInfoTxt = lineStr + '\r\n' + lncursor.join(''); // Prepare line info for HTML display var lineInfoHTML = ['<span class="code">', before, '<span class="error" title="', message, '">', errChar, '</span>', after.slice(1), '</span>'].join(''); return { description : message, lineInfoTxt : lineInfoTxt, lineInfoHTML : lineInfoHTML, code : lineStr, line : error.loc ? error.loc.line : -1, column : error.loc ? error.loc.column : -1 }; }
javascript
function formatError (error, input) { var message = error.toString().replace(/\s*\(\d*\:\d*\)\s*$/i, ''); // remove line number / col number var beforeMatch = ('' + input.slice(0, error.pos)).match(/.*$/i); var afterMatch = ('' + input.slice(error.pos)).match(/.*/i); var before = beforeMatch ? beforeMatch[0] : ''; var after = afterMatch ? afterMatch[0] : ''; // Prepare line info for txt display var cursorPos = before.length; var errChar = (after.length) ? after.slice(0, 1) : 'X'; var lineStr = before + after; var lncursor = []; for (var i = 0; i < lineStr.length; i++) { lncursor[i] = (i === cursorPos) ? '^' : '-'; } var lineInfoTxt = lineStr + '\r\n' + lncursor.join(''); // Prepare line info for HTML display var lineInfoHTML = ['<span class="code">', before, '<span class="error" title="', message, '">', errChar, '</span>', after.slice(1), '</span>'].join(''); return { description : message, lineInfoTxt : lineInfoTxt, lineInfoHTML : lineInfoHTML, code : lineStr, line : error.loc ? error.loc.line : -1, column : error.loc ? error.loc.column : -1 }; }
[ "function", "formatError", "(", "error", ",", "input", ")", "{", "var", "message", "=", "error", ".", "toString", "(", ")", ".", "replace", "(", "/", "\\s*\\(\\d*\\:\\d*\\)\\s*$", "/", "i", ",", "''", ")", ";", "// remove line number / col number", "var", "beforeMatch", "=", "(", "''", "+", "input", ".", "slice", "(", "0", ",", "error", ".", "pos", ")", ")", ".", "match", "(", "/", ".*$", "/", "i", ")", ";", "var", "afterMatch", "=", "(", "''", "+", "input", ".", "slice", "(", "error", ".", "pos", ")", ")", ".", "match", "(", "/", ".*", "/", "i", ")", ";", "var", "before", "=", "beforeMatch", "?", "beforeMatch", "[", "0", "]", ":", "''", ";", "var", "after", "=", "afterMatch", "?", "afterMatch", "[", "0", "]", ":", "''", ";", "// Prepare line info for txt display", "var", "cursorPos", "=", "before", ".", "length", ";", "var", "errChar", "=", "(", "after", ".", "length", ")", "?", "after", ".", "slice", "(", "0", ",", "1", ")", ":", "'X'", ";", "var", "lineStr", "=", "before", "+", "after", ";", "var", "lncursor", "=", "[", "]", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "lineStr", ".", "length", ";", "i", "++", ")", "{", "lncursor", "[", "i", "]", "=", "(", "i", "===", "cursorPos", ")", "?", "'^'", ":", "'-'", ";", "}", "var", "lineInfoTxt", "=", "lineStr", "+", "'\\r\\n'", "+", "lncursor", ".", "join", "(", "''", ")", ";", "// Prepare line info for HTML display", "var", "lineInfoHTML", "=", "[", "'<span class=\"code\">'", ",", "before", ",", "'<span class=\"error\" title=\"'", ",", "message", ",", "'\">'", ",", "errChar", ",", "'</span>'", ",", "after", ".", "slice", "(", "1", ")", ",", "'</span>'", "]", ".", "join", "(", "''", ")", ";", "return", "{", "description", ":", "message", ",", "lineInfoTxt", ":", "lineInfoTxt", ",", "lineInfoHTML", ":", "lineInfoHTML", ",", "code", ":", "lineStr", ",", "line", ":", "error", ".", "loc", "?", "error", ".", "loc", ".", "line", ":", "-", "1", ",", "column", ":", "error", ".", "loc", "?", "error", ".", "loc", ".", "column", ":", "-", "1", "}", ";", "}" ]
Formats the error as an error structure with line extract information. @param {Object} error the exception. @param {String} input the Javascript string. @return {Object} the structured error.
[ "Formats", "the", "error", "as", "an", "error", "structure", "with", "line", "extract", "information", "." ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/compiler/jsgenerator/jsvalidator/validator.js#L34-L65
44,044
bbx10/node-htu21d
index.js
raspi_i2c_devname
function raspi_i2c_devname() { try { var revisionBuffer = fs.readFileSync('/sys/module/bcm2708/parameters/boardrev'); var revisionInt = parseInt(revisionBuffer.toString(), 10); //console.log('Raspberry Pi board revision: ', revisionInt); // Older boards use i2c-0, newer boards use i2c-1 if ((revisionInt === 2) || (revisionInt === 3)) { return '/dev/i2c-0'; } else { return '/dev/i2c-1'; } } catch(e) { if (e.code === 'ENOENT') { //console.log('Not a Raspberry Pi'); return ''; } else { throw e; } } }
javascript
function raspi_i2c_devname() { try { var revisionBuffer = fs.readFileSync('/sys/module/bcm2708/parameters/boardrev'); var revisionInt = parseInt(revisionBuffer.toString(), 10); //console.log('Raspberry Pi board revision: ', revisionInt); // Older boards use i2c-0, newer boards use i2c-1 if ((revisionInt === 2) || (revisionInt === 3)) { return '/dev/i2c-0'; } else { return '/dev/i2c-1'; } } catch(e) { if (e.code === 'ENOENT') { //console.log('Not a Raspberry Pi'); return ''; } else { throw e; } } }
[ "function", "raspi_i2c_devname", "(", ")", "{", "try", "{", "var", "revisionBuffer", "=", "fs", ".", "readFileSync", "(", "'/sys/module/bcm2708/parameters/boardrev'", ")", ";", "var", "revisionInt", "=", "parseInt", "(", "revisionBuffer", ".", "toString", "(", ")", ",", "10", ")", ";", "//console.log('Raspberry Pi board revision: ', revisionInt);", "// Older boards use i2c-0, newer boards use i2c-1", "if", "(", "(", "revisionInt", "===", "2", ")", "||", "(", "revisionInt", "===", "3", ")", ")", "{", "return", "'/dev/i2c-0'", ";", "}", "else", "{", "return", "'/dev/i2c-1'", ";", "}", "}", "catch", "(", "e", ")", "{", "if", "(", "e", ".", "code", "===", "'ENOENT'", ")", "{", "//console.log('Not a Raspberry Pi');", "return", "''", ";", "}", "else", "{", "throw", "e", ";", "}", "}", "}" ]
If the system is a Raspberry Pi return the correct i2c device name. Else return empty string.
[ "If", "the", "system", "is", "a", "Raspberry", "Pi", "return", "the", "correct", "i2c", "device", "name", ".", "Else", "return", "empty", "string", "." ]
135e81b53ab5e98282cb16ea9d27ce193dc9bf0a
https://github.com/bbx10/node-htu21d/blob/135e81b53ab5e98282cb16ea9d27ce193dc9bf0a/index.js#L154-L177
44,045
ariatemplates/hashspace
hsp/rt/cptcomponent.js
function() { // determine if cpt supports template arguments if (this.template) { // as template can be changed dynamically we have to sync the constructor this.ctlConstuctor=this.template.controllerConstructor; } var ctlProto=this.ctlConstuctor.prototype; this.ctlAttributes=ctlProto.$attributes; this.ctlElements=ctlProto.$elements; // load template arguments this.loadCptAttElements(); // load child elements before processing the template var cptArgs={ nodeInstance:this, $attributes:{}, $content:null }; var attributes=cptArgs.$attributes, att; if (this.atts) { // some attributes have been passed to this instance - so we push them to cptArgs // so that they are set on the controller when the template are rendered var atts = this.atts, eh = this.eh, pvs = this.vscope, nm; if (atts) { for (var i = 0, sz = this.atts.length; sz > i; i++) { att = atts[i]; nm = att.name; if (this.ctlAttributes[nm].type!=="template") { attributes[nm]=att.getValue(eh, pvs, null); } } } } if (this.tplAttributes) { var tpa=this.tplAttributes; for (var k in tpa) { // set the template attribute value on the controller if (tpa.hasOwnProperty(k)) { attributes[k]=tpa[k]; } } } if (this.childElements) { cptArgs.$content=this.getControllerContent(); } return cptArgs; }
javascript
function() { // determine if cpt supports template arguments if (this.template) { // as template can be changed dynamically we have to sync the constructor this.ctlConstuctor=this.template.controllerConstructor; } var ctlProto=this.ctlConstuctor.prototype; this.ctlAttributes=ctlProto.$attributes; this.ctlElements=ctlProto.$elements; // load template arguments this.loadCptAttElements(); // load child elements before processing the template var cptArgs={ nodeInstance:this, $attributes:{}, $content:null }; var attributes=cptArgs.$attributes, att; if (this.atts) { // some attributes have been passed to this instance - so we push them to cptArgs // so that they are set on the controller when the template are rendered var atts = this.atts, eh = this.eh, pvs = this.vscope, nm; if (atts) { for (var i = 0, sz = this.atts.length; sz > i; i++) { att = atts[i]; nm = att.name; if (this.ctlAttributes[nm].type!=="template") { attributes[nm]=att.getValue(eh, pvs, null); } } } } if (this.tplAttributes) { var tpa=this.tplAttributes; for (var k in tpa) { // set the template attribute value on the controller if (tpa.hasOwnProperty(k)) { attributes[k]=tpa[k]; } } } if (this.childElements) { cptArgs.$content=this.getControllerContent(); } return cptArgs; }
[ "function", "(", ")", "{", "// determine if cpt supports template arguments", "if", "(", "this", ".", "template", ")", "{", "// as template can be changed dynamically we have to sync the constructor", "this", ".", "ctlConstuctor", "=", "this", ".", "template", ".", "controllerConstructor", ";", "}", "var", "ctlProto", "=", "this", ".", "ctlConstuctor", ".", "prototype", ";", "this", ".", "ctlAttributes", "=", "ctlProto", ".", "$attributes", ";", "this", ".", "ctlElements", "=", "ctlProto", ".", "$elements", ";", "// load template arguments", "this", ".", "loadCptAttElements", "(", ")", ";", "// load child elements before processing the template", "var", "cptArgs", "=", "{", "nodeInstance", ":", "this", ",", "$attributes", ":", "{", "}", ",", "$content", ":", "null", "}", ";", "var", "attributes", "=", "cptArgs", ".", "$attributes", ",", "att", ";", "if", "(", "this", ".", "atts", ")", "{", "// some attributes have been passed to this instance - so we push them to cptArgs", "// so that they are set on the controller when the template are rendered", "var", "atts", "=", "this", ".", "atts", ",", "eh", "=", "this", ".", "eh", ",", "pvs", "=", "this", ".", "vscope", ",", "nm", ";", "if", "(", "atts", ")", "{", "for", "(", "var", "i", "=", "0", ",", "sz", "=", "this", ".", "atts", ".", "length", ";", "sz", ">", "i", ";", "i", "++", ")", "{", "att", "=", "atts", "[", "i", "]", ";", "nm", "=", "att", ".", "name", ";", "if", "(", "this", ".", "ctlAttributes", "[", "nm", "]", ".", "type", "!==", "\"template\"", ")", "{", "attributes", "[", "nm", "]", "=", "att", ".", "getValue", "(", "eh", ",", "pvs", ",", "null", ")", ";", "}", "}", "}", "}", "if", "(", "this", ".", "tplAttributes", ")", "{", "var", "tpa", "=", "this", ".", "tplAttributes", ";", "for", "(", "var", "k", "in", "tpa", ")", "{", "// set the template attribute value on the controller", "if", "(", "tpa", ".", "hasOwnProperty", "(", "k", ")", ")", "{", "attributes", "[", "k", "]", "=", "tpa", "[", "k", "]", ";", "}", "}", "}", "if", "(", "this", ".", "childElements", ")", "{", "cptArgs", ".", "$content", "=", "this", ".", "getControllerContent", "(", ")", ";", "}", "return", "cptArgs", ";", "}" ]
Process and retrieve the component arguments that are needed to init the component template
[ "Process", "and", "retrieve", "the", "component", "arguments", "that", "are", "needed", "to", "init", "the", "component", "template" ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/rt/cptcomponent.js#L61-L110
44,046
ariatemplates/hashspace
hsp/rt/cptcomponent.js
function(localPropOnly) { if (this.ctlWrapper) { this.ctlWrapper.$dispose(); this.ctlWrapper=null; this.controller=null; } this.ctlAttributes=null; this.cleanObjectProperties(localPropOnly); this.ctlConstuctor=null; var tpa=this.tplAttributes; if (tpa) { for (var k in tpa) { if (tpa.hasOwnProperty(k)) { tpa[k].$dispose(); } } } var ag=this._attGenerators; if (ag) { for (var k in ag) { if (ag.hasOwnProperty(k)) { ag[k].$dispose(); } } } var en=this.attEltNodes; if (en) { for (var i=0,sz=en.length; sz>i; i++) { en[i].$dispose(); } this.attEltNodes=null; } }
javascript
function(localPropOnly) { if (this.ctlWrapper) { this.ctlWrapper.$dispose(); this.ctlWrapper=null; this.controller=null; } this.ctlAttributes=null; this.cleanObjectProperties(localPropOnly); this.ctlConstuctor=null; var tpa=this.tplAttributes; if (tpa) { for (var k in tpa) { if (tpa.hasOwnProperty(k)) { tpa[k].$dispose(); } } } var ag=this._attGenerators; if (ag) { for (var k in ag) { if (ag.hasOwnProperty(k)) { ag[k].$dispose(); } } } var en=this.attEltNodes; if (en) { for (var i=0,sz=en.length; sz>i; i++) { en[i].$dispose(); } this.attEltNodes=null; } }
[ "function", "(", "localPropOnly", ")", "{", "if", "(", "this", ".", "ctlWrapper", ")", "{", "this", ".", "ctlWrapper", ".", "$dispose", "(", ")", ";", "this", ".", "ctlWrapper", "=", "null", ";", "this", ".", "controller", "=", "null", ";", "}", "this", ".", "ctlAttributes", "=", "null", ";", "this", ".", "cleanObjectProperties", "(", "localPropOnly", ")", ";", "this", ".", "ctlConstuctor", "=", "null", ";", "var", "tpa", "=", "this", ".", "tplAttributes", ";", "if", "(", "tpa", ")", "{", "for", "(", "var", "k", "in", "tpa", ")", "{", "if", "(", "tpa", ".", "hasOwnProperty", "(", "k", ")", ")", "{", "tpa", "[", "k", "]", ".", "$dispose", "(", ")", ";", "}", "}", "}", "var", "ag", "=", "this", ".", "_attGenerators", ";", "if", "(", "ag", ")", "{", "for", "(", "var", "k", "in", "ag", ")", "{", "if", "(", "ag", ".", "hasOwnProperty", "(", "k", ")", ")", "{", "ag", "[", "k", "]", ".", "$dispose", "(", ")", ";", "}", "}", "}", "var", "en", "=", "this", ".", "attEltNodes", ";", "if", "(", "en", ")", "{", "for", "(", "var", "i", "=", "0", ",", "sz", "=", "en", ".", "length", ";", "sz", ">", "i", ";", "i", "++", ")", "{", "en", "[", "i", "]", ".", "$dispose", "(", ")", ";", "}", "this", ".", "attEltNodes", "=", "null", ";", "}", "}" ]
Safely cut all dependencies before object is deleted @param {Boolean} localPropOnly if true only local properties will be deleted (optional) must be used when a new instance is created to adapt to a path change
[ "Safely", "cut", "all", "dependencies", "before", "object", "is", "deleted" ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/rt/cptcomponent.js#L140-L172
44,047
ariatemplates/hashspace
hsp/rt/cptcomponent.js
function () { this.attEltNodes=null; this._attGenerators=null; // determine the possible template attribute names var tpAttNames={}, ca=this.ctlAttributes, defaultTplAtt=null, lastTplAtt=null, count=0; for (var k in ca) { if (ca.hasOwnProperty(k) && ca[k].type==="template") { // k is defined in the controller attributes collection // so k is a valid template attribute name tpAttNames[k]=true; count++; if (ca[k].defaultContent) { defaultTplAtt=k; } lastTplAtt=k; } } // if there is only one template attribute it will be automatically considered as default if (!defaultTplAtt) { if (count===1) { defaultTplAtt=lastTplAtt; } else if (count>1) { // error: a default must be defined log.error(this+" A default content element must be defined when multiple content elements are supported"); // use last as default defaultTplAtt=lastTplAtt; } } // check if a default attribute element has to be created and create it if necessary this.manageDefaultAttElt(defaultTplAtt); // Analyze node attributes to see if a template attribute is passed as text attribute var atts=this.atts, att, nm; if (atts) { for (var k in atts) { if (!atts.hasOwnProperty(k)) continue; att=atts[k]; nm=att.name; if (tpAttNames[nm]) { // nm is a template attribute passed as text attribute if (this.tplAttributes && this.tplAttributes[nm]) { // already defined: raise an error log.error(this+" Component attribute '" + nm + "' is defined multiple times - please check"); } else { // create new tpl Attribute Text Node and add it to the tplAttributes collection if (!att.generator) { var txtNode; if (att.value) { // static value txtNode = new $TextNode(0,[""+att.value]); } else { // dynamic value using expressions txtNode = new $TextNode(this.exps,atts[k].textcfg); } if (!this._attGenerators) { this._attGenerators = []; } att.generator = new $CptAttElement(nm,0,0,0,[txtNode]); // name, exps, attcfg, ehcfg, children this._attGenerators.push(att.generator); } // generate a real $CptAttElement using the TextNode as child element var ni=att.generator.createNodeInstance(this); ni.isCptContent=true; if (!this.attEltNodes) { this.attEltNodes=[]; } this.attEltNodes.push(ni); // attribute elements will automatically register through registerAttElement() } } } } this.retrieveAttElements(); }
javascript
function () { this.attEltNodes=null; this._attGenerators=null; // determine the possible template attribute names var tpAttNames={}, ca=this.ctlAttributes, defaultTplAtt=null, lastTplAtt=null, count=0; for (var k in ca) { if (ca.hasOwnProperty(k) && ca[k].type==="template") { // k is defined in the controller attributes collection // so k is a valid template attribute name tpAttNames[k]=true; count++; if (ca[k].defaultContent) { defaultTplAtt=k; } lastTplAtt=k; } } // if there is only one template attribute it will be automatically considered as default if (!defaultTplAtt) { if (count===1) { defaultTplAtt=lastTplAtt; } else if (count>1) { // error: a default must be defined log.error(this+" A default content element must be defined when multiple content elements are supported"); // use last as default defaultTplAtt=lastTplAtt; } } // check if a default attribute element has to be created and create it if necessary this.manageDefaultAttElt(defaultTplAtt); // Analyze node attributes to see if a template attribute is passed as text attribute var atts=this.atts, att, nm; if (atts) { for (var k in atts) { if (!atts.hasOwnProperty(k)) continue; att=atts[k]; nm=att.name; if (tpAttNames[nm]) { // nm is a template attribute passed as text attribute if (this.tplAttributes && this.tplAttributes[nm]) { // already defined: raise an error log.error(this+" Component attribute '" + nm + "' is defined multiple times - please check"); } else { // create new tpl Attribute Text Node and add it to the tplAttributes collection if (!att.generator) { var txtNode; if (att.value) { // static value txtNode = new $TextNode(0,[""+att.value]); } else { // dynamic value using expressions txtNode = new $TextNode(this.exps,atts[k].textcfg); } if (!this._attGenerators) { this._attGenerators = []; } att.generator = new $CptAttElement(nm,0,0,0,[txtNode]); // name, exps, attcfg, ehcfg, children this._attGenerators.push(att.generator); } // generate a real $CptAttElement using the TextNode as child element var ni=att.generator.createNodeInstance(this); ni.isCptContent=true; if (!this.attEltNodes) { this.attEltNodes=[]; } this.attEltNodes.push(ni); // attribute elements will automatically register through registerAttElement() } } } } this.retrieveAttElements(); }
[ "function", "(", ")", "{", "this", ".", "attEltNodes", "=", "null", ";", "this", ".", "_attGenerators", "=", "null", ";", "// determine the possible template attribute names", "var", "tpAttNames", "=", "{", "}", ",", "ca", "=", "this", ".", "ctlAttributes", ",", "defaultTplAtt", "=", "null", ",", "lastTplAtt", "=", "null", ",", "count", "=", "0", ";", "for", "(", "var", "k", "in", "ca", ")", "{", "if", "(", "ca", ".", "hasOwnProperty", "(", "k", ")", "&&", "ca", "[", "k", "]", ".", "type", "===", "\"template\"", ")", "{", "// k is defined in the controller attributes collection", "// so k is a valid template attribute name", "tpAttNames", "[", "k", "]", "=", "true", ";", "count", "++", ";", "if", "(", "ca", "[", "k", "]", ".", "defaultContent", ")", "{", "defaultTplAtt", "=", "k", ";", "}", "lastTplAtt", "=", "k", ";", "}", "}", "// if there is only one template attribute it will be automatically considered as default", "if", "(", "!", "defaultTplAtt", ")", "{", "if", "(", "count", "===", "1", ")", "{", "defaultTplAtt", "=", "lastTplAtt", ";", "}", "else", "if", "(", "count", ">", "1", ")", "{", "// error: a default must be defined", "log", ".", "error", "(", "this", "+", "\" A default content element must be defined when multiple content elements are supported\"", ")", ";", "// use last as default", "defaultTplAtt", "=", "lastTplAtt", ";", "}", "}", "// check if a default attribute element has to be created and create it if necessary", "this", ".", "manageDefaultAttElt", "(", "defaultTplAtt", ")", ";", "// Analyze node attributes to see if a template attribute is passed as text attribute", "var", "atts", "=", "this", ".", "atts", ",", "att", ",", "nm", ";", "if", "(", "atts", ")", "{", "for", "(", "var", "k", "in", "atts", ")", "{", "if", "(", "!", "atts", ".", "hasOwnProperty", "(", "k", ")", ")", "continue", ";", "att", "=", "atts", "[", "k", "]", ";", "nm", "=", "att", ".", "name", ";", "if", "(", "tpAttNames", "[", "nm", "]", ")", "{", "// nm is a template attribute passed as text attribute", "if", "(", "this", ".", "tplAttributes", "&&", "this", ".", "tplAttributes", "[", "nm", "]", ")", "{", "// already defined: raise an error", "log", ".", "error", "(", "this", "+", "\" Component attribute '\"", "+", "nm", "+", "\"' is defined multiple times - please check\"", ")", ";", "}", "else", "{", "// create new tpl Attribute Text Node and add it to the tplAttributes collection", "if", "(", "!", "att", ".", "generator", ")", "{", "var", "txtNode", ";", "if", "(", "att", ".", "value", ")", "{", "// static value", "txtNode", "=", "new", "$TextNode", "(", "0", ",", "[", "\"\"", "+", "att", ".", "value", "]", ")", ";", "}", "else", "{", "// dynamic value using expressions", "txtNode", "=", "new", "$TextNode", "(", "this", ".", "exps", ",", "atts", "[", "k", "]", ".", "textcfg", ")", ";", "}", "if", "(", "!", "this", ".", "_attGenerators", ")", "{", "this", ".", "_attGenerators", "=", "[", "]", ";", "}", "att", ".", "generator", "=", "new", "$CptAttElement", "(", "nm", ",", "0", ",", "0", ",", "0", ",", "[", "txtNode", "]", ")", ";", "// name, exps, attcfg, ehcfg, children", "this", ".", "_attGenerators", ".", "push", "(", "att", ".", "generator", ")", ";", "}", "// generate a real $CptAttElement using the TextNode as child element", "var", "ni", "=", "att", ".", "generator", ".", "createNodeInstance", "(", "this", ")", ";", "ni", ".", "isCptContent", "=", "true", ";", "if", "(", "!", "this", ".", "attEltNodes", ")", "{", "this", ".", "attEltNodes", "=", "[", "]", ";", "}", "this", ".", "attEltNodes", ".", "push", "(", "ni", ")", ";", "// attribute elements will automatically register through registerAttElement()", "}", "}", "}", "}", "this", ".", "retrieveAttElements", "(", ")", ";", "}" ]
Load the component sub-nodes that correspond to template attributes
[ "Load", "the", "component", "sub", "-", "nodes", "that", "correspond", "to", "template", "attributes" ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/rt/cptcomponent.js#L177-L255
44,048
ariatemplates/hashspace
hsp/rt/cptcomponent.js
function (defaultTplAtt) { if (!this.children) { return; } // TODO memoize result at prototype level to avoid processing this multiple times var ct=this.getCptContentType(), loadCpts=true; if (ct==="ERROR") { loadCpts=false; log.error(this.info+" Component content cannot mix attribute elements with content elements"); } else if (ct!=="ATTELT") { if (defaultTplAtt) { // ct is CONTENT or INDEFINITE - so we create a default attribute element var catt=new $CptAttElement(defaultTplAtt,0,0,0,this.children); // name, exps, attcfg, ehcfg, children // add this default cpt att element as unique child this.children=[catt]; } else { // there is no defaultTplAtt loadCpts=false; } } if (loadCpts) { var ni, cn=this.children, sz=cn.length; if (!this.attEltNodes) { this.attEltNodes=[]; } for (var i=0;sz>i;i++) { if (!cn[i].isEmptyTextNode) { ni=cn[i].createNodeInstance(this); ni.isCptContent=true; this.attEltNodes.push(ni); // attribute elements will automatically register through registerAttElement() } } } }
javascript
function (defaultTplAtt) { if (!this.children) { return; } // TODO memoize result at prototype level to avoid processing this multiple times var ct=this.getCptContentType(), loadCpts=true; if (ct==="ERROR") { loadCpts=false; log.error(this.info+" Component content cannot mix attribute elements with content elements"); } else if (ct!=="ATTELT") { if (defaultTplAtt) { // ct is CONTENT or INDEFINITE - so we create a default attribute element var catt=new $CptAttElement(defaultTplAtt,0,0,0,this.children); // name, exps, attcfg, ehcfg, children // add this default cpt att element as unique child this.children=[catt]; } else { // there is no defaultTplAtt loadCpts=false; } } if (loadCpts) { var ni, cn=this.children, sz=cn.length; if (!this.attEltNodes) { this.attEltNodes=[]; } for (var i=0;sz>i;i++) { if (!cn[i].isEmptyTextNode) { ni=cn[i].createNodeInstance(this); ni.isCptContent=true; this.attEltNodes.push(ni); // attribute elements will automatically register through registerAttElement() } } } }
[ "function", "(", "defaultTplAtt", ")", "{", "if", "(", "!", "this", ".", "children", ")", "{", "return", ";", "}", "// TODO memoize result at prototype level to avoid processing this multiple times", "var", "ct", "=", "this", ".", "getCptContentType", "(", ")", ",", "loadCpts", "=", "true", ";", "if", "(", "ct", "===", "\"ERROR\"", ")", "{", "loadCpts", "=", "false", ";", "log", ".", "error", "(", "this", ".", "info", "+", "\" Component content cannot mix attribute elements with content elements\"", ")", ";", "}", "else", "if", "(", "ct", "!==", "\"ATTELT\"", ")", "{", "if", "(", "defaultTplAtt", ")", "{", "// ct is CONTENT or INDEFINITE - so we create a default attribute element", "var", "catt", "=", "new", "$CptAttElement", "(", "defaultTplAtt", ",", "0", ",", "0", ",", "0", ",", "this", ".", "children", ")", ";", "// name, exps, attcfg, ehcfg, children", "// add this default cpt att element as unique child", "this", ".", "children", "=", "[", "catt", "]", ";", "}", "else", "{", "// there is no defaultTplAtt", "loadCpts", "=", "false", ";", "}", "}", "if", "(", "loadCpts", ")", "{", "var", "ni", ",", "cn", "=", "this", ".", "children", ",", "sz", "=", "cn", ".", "length", ";", "if", "(", "!", "this", ".", "attEltNodes", ")", "{", "this", ".", "attEltNodes", "=", "[", "]", ";", "}", "for", "(", "var", "i", "=", "0", ";", "sz", ">", "i", ";", "i", "++", ")", "{", "if", "(", "!", "cn", "[", "i", "]", ".", "isEmptyTextNode", ")", "{", "ni", "=", "cn", "[", "i", "]", ".", "createNodeInstance", "(", "this", ")", ";", "ni", ".", "isCptContent", "=", "true", ";", "this", ".", "attEltNodes", ".", "push", "(", "ni", ")", ";", "// attribute elements will automatically register through registerAttElement()", "}", "}", "}", "}" ]
Check if a default attribute element has to be created and create one if necessary
[ "Check", "if", "a", "default", "attribute", "element", "has", "to", "be", "created", "and", "create", "one", "if", "necessary" ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/rt/cptcomponent.js#L260-L298
44,049
ariatemplates/hashspace
hsp/rt/cptcomponent.js
function() { var aen=this.attEltNodes; if (!aen) { return null; } var attElts=[], cta=this.ctlAttributes; for (var i=0,sz=aen.length; sz>i;i++) { aen[i].registerAttElements(attElts); } // check that all elements are valid (i.e. have valid names) var nm, elt, ok, elts=[], cte=this.ctlElements? this.ctlElements : []; for (var i=0,sz=attElts.length; sz>i; i++) { elt=attElts[i]; nm=elt.name; ok=true; if (cta && cta[nm]) { // valid tpl attribute if (!this.tplAttributes) { this.tplAttributes={}; } this.tplAttributes[nm]=elt; ok = false; } else { if (!nm) { log.error(this+" Invalid attribute element (unnamed)"); ok=false; } else if (!cte[nm]) { log.error(this+" Invalid attribute element: @"+nm); ok=false; } } if (ok) { elts.push(elt); } } if (elts.length===0) { elts=null; } this.childElements=elts; return elts; }
javascript
function() { var aen=this.attEltNodes; if (!aen) { return null; } var attElts=[], cta=this.ctlAttributes; for (var i=0,sz=aen.length; sz>i;i++) { aen[i].registerAttElements(attElts); } // check that all elements are valid (i.e. have valid names) var nm, elt, ok, elts=[], cte=this.ctlElements? this.ctlElements : []; for (var i=0,sz=attElts.length; sz>i; i++) { elt=attElts[i]; nm=elt.name; ok=true; if (cta && cta[nm]) { // valid tpl attribute if (!this.tplAttributes) { this.tplAttributes={}; } this.tplAttributes[nm]=elt; ok = false; } else { if (!nm) { log.error(this+" Invalid attribute element (unnamed)"); ok=false; } else if (!cte[nm]) { log.error(this+" Invalid attribute element: @"+nm); ok=false; } } if (ok) { elts.push(elt); } } if (elts.length===0) { elts=null; } this.childElements=elts; return elts; }
[ "function", "(", ")", "{", "var", "aen", "=", "this", ".", "attEltNodes", ";", "if", "(", "!", "aen", ")", "{", "return", "null", ";", "}", "var", "attElts", "=", "[", "]", ",", "cta", "=", "this", ".", "ctlAttributes", ";", "for", "(", "var", "i", "=", "0", ",", "sz", "=", "aen", ".", "length", ";", "sz", ">", "i", ";", "i", "++", ")", "{", "aen", "[", "i", "]", ".", "registerAttElements", "(", "attElts", ")", ";", "}", "// check that all elements are valid (i.e. have valid names)", "var", "nm", ",", "elt", ",", "ok", ",", "elts", "=", "[", "]", ",", "cte", "=", "this", ".", "ctlElements", "?", "this", ".", "ctlElements", ":", "[", "]", ";", "for", "(", "var", "i", "=", "0", ",", "sz", "=", "attElts", ".", "length", ";", "sz", ">", "i", ";", "i", "++", ")", "{", "elt", "=", "attElts", "[", "i", "]", ";", "nm", "=", "elt", ".", "name", ";", "ok", "=", "true", ";", "if", "(", "cta", "&&", "cta", "[", "nm", "]", ")", "{", "// valid tpl attribute", "if", "(", "!", "this", ".", "tplAttributes", ")", "{", "this", ".", "tplAttributes", "=", "{", "}", ";", "}", "this", ".", "tplAttributes", "[", "nm", "]", "=", "elt", ";", "ok", "=", "false", ";", "}", "else", "{", "if", "(", "!", "nm", ")", "{", "log", ".", "error", "(", "this", "+", "\" Invalid attribute element (unnamed)\"", ")", ";", "ok", "=", "false", ";", "}", "else", "if", "(", "!", "cte", "[", "nm", "]", ")", "{", "log", ".", "error", "(", "this", "+", "\" Invalid attribute element: @\"", "+", "nm", ")", ";", "ok", "=", "false", ";", "}", "}", "if", "(", "ok", ")", "{", "elts", ".", "push", "(", "elt", ")", ";", "}", "}", "if", "(", "elts", ".", "length", "===", "0", ")", "{", "elts", "=", "null", ";", "}", "this", ".", "childElements", "=", "elts", ";", "return", "elts", ";", "}" ]
Retrieve all child attribute elements and update the tplAttributes and childElements collections
[ "Retrieve", "all", "child", "attribute", "elements", "and", "update", "the", "tplAttributes", "and", "childElements", "collections" ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/rt/cptcomponent.js#L304-L344
44,050
ariatemplates/hashspace
hsp/rt/cptcomponent.js
function() { var ce=this.childElements; if (!ce || !ce.length) { return; } var cw; for (var i=0,sz=ce.length;sz>i;i++) { cw=ce[i].ctlWrapper; if (cw && !cw.initialized) { cw.init(null,this.controller); } } }
javascript
function() { var ce=this.childElements; if (!ce || !ce.length) { return; } var cw; for (var i=0,sz=ce.length;sz>i;i++) { cw=ce[i].ctlWrapper; if (cw && !cw.initialized) { cw.init(null,this.controller); } } }
[ "function", "(", ")", "{", "var", "ce", "=", "this", ".", "childElements", ";", "if", "(", "!", "ce", "||", "!", "ce", ".", "length", ")", "{", "return", ";", "}", "var", "cw", ";", "for", "(", "var", "i", "=", "0", ",", "sz", "=", "ce", ".", "length", ";", "sz", ">", "i", ";", "i", "++", ")", "{", "cw", "=", "ce", "[", "i", "]", ".", "ctlWrapper", ";", "if", "(", "cw", "&&", "!", "cw", ".", "initialized", ")", "{", "cw", ".", "init", "(", "null", ",", "this", ".", "controller", ")", ";", "}", "}", "}" ]
Initializes the attribute elements of type component that have not been already initialized
[ "Initializes", "the", "attribute", "elements", "of", "type", "component", "that", "have", "not", "been", "already", "initialized" ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/rt/cptcomponent.js#L350-L362
44,051
ariatemplates/hashspace
hsp/rt/cptcomponent.js
function (evt) { var evh = this.evtHandlers, et = evt.type; if (evh) { for (var i = 0, sz = evh.length; sz > i; i++) { if (evh[i].evtType === et) { evh[i].executeCb(evt, this.eh, this.parent.vscope); break; } } } }
javascript
function (evt) { var evh = this.evtHandlers, et = evt.type; if (evh) { for (var i = 0, sz = evh.length; sz > i; i++) { if (evh[i].evtType === et) { evh[i].executeCb(evt, this.eh, this.parent.vscope); break; } } } }
[ "function", "(", "evt", ")", "{", "var", "evh", "=", "this", ".", "evtHandlers", ",", "et", "=", "evt", ".", "type", ";", "if", "(", "evh", ")", "{", "for", "(", "var", "i", "=", "0", ",", "sz", "=", "evh", ".", "length", ";", "sz", ">", "i", ";", "i", "++", ")", "{", "if", "(", "evh", "[", "i", "]", ".", "evtType", "===", "et", ")", "{", "evh", "[", "i", "]", ".", "executeCb", "(", "evt", ",", "this", ".", "eh", ",", "this", ".", "parent", ".", "vscope", ")", ";", "break", ";", "}", "}", "}", "}" ]
Callback called by the controller observer when the controller raises an event
[ "Callback", "called", "by", "the", "controller", "observer", "when", "the", "controller", "raises", "an", "event" ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/rt/cptcomponent.js#L382-L392
44,052
ariatemplates/hashspace
hsp/rt/cptcomponent.js
function (prevNode, newNode) { if (prevNode === newNode) { return; } TNode.replaceNodeBy.call(this,prevNode, newNode); var aen=this.attEltNodes; if (aen) { for (var i=0,sz=aen.length; sz>i;i++) { aen[i].replaceNodeBy(prevNode, newNode); } } }
javascript
function (prevNode, newNode) { if (prevNode === newNode) { return; } TNode.replaceNodeBy.call(this,prevNode, newNode); var aen=this.attEltNodes; if (aen) { for (var i=0,sz=aen.length; sz>i;i++) { aen[i].replaceNodeBy(prevNode, newNode); } } }
[ "function", "(", "prevNode", ",", "newNode", ")", "{", "if", "(", "prevNode", "===", "newNode", ")", "{", "return", ";", "}", "TNode", ".", "replaceNodeBy", ".", "call", "(", "this", ",", "prevNode", ",", "newNode", ")", ";", "var", "aen", "=", "this", ".", "attEltNodes", ";", "if", "(", "aen", ")", "{", "for", "(", "var", "i", "=", "0", ",", "sz", "=", "aen", ".", "length", ";", "sz", ">", "i", ";", "i", "++", ")", "{", "aen", "[", "i", "]", ".", "replaceNodeBy", "(", "prevNode", ",", "newNode", ")", ";", "}", "}", "}" ]
Recursively replace the DOM node by another node if it matches the preNode passed as argument
[ "Recursively", "replace", "the", "DOM", "node", "by", "another", "node", "if", "it", "matches", "the", "preNode", "passed", "as", "argument" ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/rt/cptcomponent.js#L397-L408
44,053
ariatemplates/hashspace
hsp/rt/cptcomponent.js
function() { var c=[], ce=this.childElements, celts=this.ctlElements, eltType; if (ce && ce.length) { for (var i=0, sz=ce.length;sz>i;i++) { eltType=celts[ce[i].name].type; if (eltType==="component") { c.push(ce[i].controller); } else if (eltType==="template") { c.push(ce[i]); } else { log.error(this+" Invalid element type: "+eltType); } } } return c.length>0? c : null; }
javascript
function() { var c=[], ce=this.childElements, celts=this.ctlElements, eltType; if (ce && ce.length) { for (var i=0, sz=ce.length;sz>i;i++) { eltType=celts[ce[i].name].type; if (eltType==="component") { c.push(ce[i].controller); } else if (eltType==="template") { c.push(ce[i]); } else { log.error(this+" Invalid element type: "+eltType); } } } return c.length>0? c : null; }
[ "function", "(", ")", "{", "var", "c", "=", "[", "]", ",", "ce", "=", "this", ".", "childElements", ",", "celts", "=", "this", ".", "ctlElements", ",", "eltType", ";", "if", "(", "ce", "&&", "ce", ".", "length", ")", "{", "for", "(", "var", "i", "=", "0", ",", "sz", "=", "ce", ".", "length", ";", "sz", ">", "i", ";", "i", "++", ")", "{", "eltType", "=", "celts", "[", "ce", "[", "i", "]", ".", "name", "]", ".", "type", ";", "if", "(", "eltType", "===", "\"component\"", ")", "{", "c", ".", "push", "(", "ce", "[", "i", "]", ".", "controller", ")", ";", "}", "else", "if", "(", "eltType", "===", "\"template\"", ")", "{", "c", ".", "push", "(", "ce", "[", "i", "]", ")", ";", "}", "else", "{", "log", ".", "error", "(", "this", "+", "\" Invalid element type: \"", "+", "eltType", ")", ";", "}", "}", "}", "return", "c", ".", "length", ">", "0", "?", "c", ":", "null", ";", "}" ]
Calculate the content array that will be set on component's controller
[ "Calculate", "the", "content", "array", "that", "will", "be", "set", "on", "component", "s", "controller" ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/rt/cptcomponent.js#L413-L428
44,054
ariatemplates/hashspace
hsp/rt/cptcomponent.js
function () { if (this.edirty) { var en=this.attEltNodes; if (en) { for (var i=0,sz=en.length; sz>i; i++) { en[i].refresh(); } // if content changed we have to rebuild childElements this.retrieveAttElements(); this.initChildComponents(); } // Change content of the controller json.set(this.controller,"$content",this.getControllerContent()); this.edirty=false; } // warning: the following refresh may change the component type and // as such ctlWrapper could become null if new component is a template $CptNode.refresh.call(this); if (this.ctlWrapper) { // refresh cpt through $refresh if need be this.ctlWrapper.refresh(); } }
javascript
function () { if (this.edirty) { var en=this.attEltNodes; if (en) { for (var i=0,sz=en.length; sz>i; i++) { en[i].refresh(); } // if content changed we have to rebuild childElements this.retrieveAttElements(); this.initChildComponents(); } // Change content of the controller json.set(this.controller,"$content",this.getControllerContent()); this.edirty=false; } // warning: the following refresh may change the component type and // as such ctlWrapper could become null if new component is a template $CptNode.refresh.call(this); if (this.ctlWrapper) { // refresh cpt through $refresh if need be this.ctlWrapper.refresh(); } }
[ "function", "(", ")", "{", "if", "(", "this", ".", "edirty", ")", "{", "var", "en", "=", "this", ".", "attEltNodes", ";", "if", "(", "en", ")", "{", "for", "(", "var", "i", "=", "0", ",", "sz", "=", "en", ".", "length", ";", "sz", ">", "i", ";", "i", "++", ")", "{", "en", "[", "i", "]", ".", "refresh", "(", ")", ";", "}", "// if content changed we have to rebuild childElements", "this", ".", "retrieveAttElements", "(", ")", ";", "this", ".", "initChildComponents", "(", ")", ";", "}", "// Change content of the controller", "json", ".", "set", "(", "this", ".", "controller", ",", "\"$content\"", ",", "this", ".", "getControllerContent", "(", ")", ")", ";", "this", ".", "edirty", "=", "false", ";", "}", "// warning: the following refresh may change the component type and", "// as such ctlWrapper could become null if new component is a template", "$CptNode", ".", "refresh", ".", "call", "(", "this", ")", ";", "if", "(", "this", ".", "ctlWrapper", ")", "{", "// refresh cpt through $refresh if need be", "this", ".", "ctlWrapper", ".", "refresh", "(", ")", ";", "}", "}" ]
Refresh the sub-template arguments and the child nodes, if needed
[ "Refresh", "the", "sub", "-", "template", "arguments", "and", "the", "child", "nodes", "if", "needed" ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/rt/cptcomponent.js#L433-L456
44,055
floridoo/scarab
lib/routing.js
getAction
function getAction(controllerName, actionName) { controllerName = controllerName.camelize(); var controller = app.controllers[controllerName]; if (controller === undefined && app.models[controllerName]) controller = defaultController; if (controller) return controller[actionName || 'index']; else return null; }
javascript
function getAction(controllerName, actionName) { controllerName = controllerName.camelize(); var controller = app.controllers[controllerName]; if (controller === undefined && app.models[controllerName]) controller = defaultController; if (controller) return controller[actionName || 'index']; else return null; }
[ "function", "getAction", "(", "controllerName", ",", "actionName", ")", "{", "controllerName", "=", "controllerName", ".", "camelize", "(", ")", ";", "var", "controller", "=", "app", ".", "controllers", "[", "controllerName", "]", ";", "if", "(", "controller", "===", "undefined", "&&", "app", ".", "models", "[", "controllerName", "]", ")", "controller", "=", "defaultController", ";", "if", "(", "controller", ")", "return", "controller", "[", "actionName", "||", "'index'", "]", ";", "else", "return", "null", ";", "}" ]
Find the action function based on controller name and action name. If no controller but a model is found, the default controller is taken. @param {String} controllerName controller name @param {String} actionName action name @return {Function} action function
[ "Find", "the", "action", "function", "based", "on", "controller", "name", "and", "action", "name", ".", "If", "no", "controller", "but", "a", "model", "is", "found", "the", "default", "controller", "is", "taken", "." ]
377ebd79563b8fa654bb18324aed00d72500e7f6
https://github.com/floridoo/scarab/blob/377ebd79563b8fa654bb18324aed00d72500e7f6/lib/routing.js#L18-L28
44,056
floridoo/scarab
lib/routing.js
addSingleRoute
function addSingleRoute(verb, routePath, controllerName, actionName) { // add controller and action fields to the request var reqExtender = function(req, res, next) { req.controller = controllerName; req.action = actionName || 'index'; next(); }; var params = [routePath, reqExtender]; params = params.concat(getPolicies(controllerName, actionName)); params.push(getAction(controllerName, actionName)); app[verb].apply(app, params); }
javascript
function addSingleRoute(verb, routePath, controllerName, actionName) { // add controller and action fields to the request var reqExtender = function(req, res, next) { req.controller = controllerName; req.action = actionName || 'index'; next(); }; var params = [routePath, reqExtender]; params = params.concat(getPolicies(controllerName, actionName)); params.push(getAction(controllerName, actionName)); app[verb].apply(app, params); }
[ "function", "addSingleRoute", "(", "verb", ",", "routePath", ",", "controllerName", ",", "actionName", ")", "{", "// add controller and action fields to the request", "var", "reqExtender", "=", "function", "(", "req", ",", "res", ",", "next", ")", "{", "req", ".", "controller", "=", "controllerName", ";", "req", ".", "action", "=", "actionName", "||", "'index'", ";", "next", "(", ")", ";", "}", ";", "var", "params", "=", "[", "routePath", ",", "reqExtender", "]", ";", "params", "=", "params", ".", "concat", "(", "getPolicies", "(", "controllerName", ",", "actionName", ")", ")", ";", "params", ".", "push", "(", "getAction", "(", "controllerName", ",", "actionName", ")", ")", ";", "app", "[", "verb", "]", ".", "apply", "(", "app", ",", "params", ")", ";", "}" ]
adds a single route @param {String} verb HTTP verb @param {String} routePath routing path @param {String} controllerName controller name @param {String} actionName action name
[ "adds", "a", "single", "route" ]
377ebd79563b8fa654bb18324aed00d72500e7f6
https://github.com/floridoo/scarab/blob/377ebd79563b8fa654bb18324aed00d72500e7f6/lib/routing.js#L37-L50
44,057
floridoo/scarab
lib/routing.js
function(req, res, next) { req.controller = controllerName; req.action = actionName || 'index'; next(); }
javascript
function(req, res, next) { req.controller = controllerName; req.action = actionName || 'index'; next(); }
[ "function", "(", "req", ",", "res", ",", "next", ")", "{", "req", ".", "controller", "=", "controllerName", ";", "req", ".", "action", "=", "actionName", "||", "'index'", ";", "next", "(", ")", ";", "}" ]
add controller and action fields to the request
[ "add", "controller", "and", "action", "fields", "to", "the", "request" ]
377ebd79563b8fa654bb18324aed00d72500e7f6
https://github.com/floridoo/scarab/blob/377ebd79563b8fa654bb18324aed00d72500e7f6/lib/routing.js#L39-L43
44,058
floridoo/scarab
lib/routing.js
getPolicies
function getPolicies(controller, action) { var policies = config.policies; var currentPolicies = []; if (policies[controller] && policies[controller][action]) { currentPolicies = policies[controller][action]; } else if (Object.isString(policies[controller])) { currentPolicies = policies[controller]; } else if (policies[controller] && policies[controller]['*']) { currentPolicies = policies[controller]['*']; } else if (policies['*']) { currentPolicies = policies['*']; } if (currentPolicies === true) { currentPolicies = []; } if (!Object.isArray(currentPolicies)) { currentPolicies = [currentPolicies]; } currentPolicies = currentPolicies.map(function(policy) { var policyPath = path.join(config.rootDir, config.paths.policies, policy); return require(policyPath); }); return currentPolicies; }
javascript
function getPolicies(controller, action) { var policies = config.policies; var currentPolicies = []; if (policies[controller] && policies[controller][action]) { currentPolicies = policies[controller][action]; } else if (Object.isString(policies[controller])) { currentPolicies = policies[controller]; } else if (policies[controller] && policies[controller]['*']) { currentPolicies = policies[controller]['*']; } else if (policies['*']) { currentPolicies = policies['*']; } if (currentPolicies === true) { currentPolicies = []; } if (!Object.isArray(currentPolicies)) { currentPolicies = [currentPolicies]; } currentPolicies = currentPolicies.map(function(policy) { var policyPath = path.join(config.rootDir, config.paths.policies, policy); return require(policyPath); }); return currentPolicies; }
[ "function", "getPolicies", "(", "controller", ",", "action", ")", "{", "var", "policies", "=", "config", ".", "policies", ";", "var", "currentPolicies", "=", "[", "]", ";", "if", "(", "policies", "[", "controller", "]", "&&", "policies", "[", "controller", "]", "[", "action", "]", ")", "{", "currentPolicies", "=", "policies", "[", "controller", "]", "[", "action", "]", ";", "}", "else", "if", "(", "Object", ".", "isString", "(", "policies", "[", "controller", "]", ")", ")", "{", "currentPolicies", "=", "policies", "[", "controller", "]", ";", "}", "else", "if", "(", "policies", "[", "controller", "]", "&&", "policies", "[", "controller", "]", "[", "'*'", "]", ")", "{", "currentPolicies", "=", "policies", "[", "controller", "]", "[", "'*'", "]", ";", "}", "else", "if", "(", "policies", "[", "'*'", "]", ")", "{", "currentPolicies", "=", "policies", "[", "'*'", "]", ";", "}", "if", "(", "currentPolicies", "===", "true", ")", "{", "currentPolicies", "=", "[", "]", ";", "}", "if", "(", "!", "Object", ".", "isArray", "(", "currentPolicies", ")", ")", "{", "currentPolicies", "=", "[", "currentPolicies", "]", ";", "}", "currentPolicies", "=", "currentPolicies", ".", "map", "(", "function", "(", "policy", ")", "{", "var", "policyPath", "=", "path", ".", "join", "(", "config", ".", "rootDir", ",", "config", ".", "paths", ".", "policies", ",", "policy", ")", ";", "return", "require", "(", "policyPath", ")", ";", "}", ")", ";", "return", "currentPolicies", ";", "}" ]
gets the policies in effect for a given controller and action @param {String} controller @param {String} action @return {Array} policies
[ "gets", "the", "policies", "in", "effect", "for", "a", "given", "controller", "and", "action" ]
377ebd79563b8fa654bb18324aed00d72500e7f6
https://github.com/floridoo/scarab/blob/377ebd79563b8fa654bb18324aed00d72500e7f6/lib/routing.js#L58-L84
44,059
floridoo/scarab
lib/routing.js
addResourceRoute
function addResourceRoute(routePath, controllerName) { resourceRouting.forEach(function(route) { var actionPath = route.path.replace(':controller', controllerName); route.verbs.forEach(function (verb) { addSingleRoute(verb, actionPath, controllerName, route.target.action); }); }); }
javascript
function addResourceRoute(routePath, controllerName) { resourceRouting.forEach(function(route) { var actionPath = route.path.replace(':controller', controllerName); route.verbs.forEach(function (verb) { addSingleRoute(verb, actionPath, controllerName, route.target.action); }); }); }
[ "function", "addResourceRoute", "(", "routePath", ",", "controllerName", ")", "{", "resourceRouting", ".", "forEach", "(", "function", "(", "route", ")", "{", "var", "actionPath", "=", "route", ".", "path", ".", "replace", "(", "':controller'", ",", "controllerName", ")", ";", "route", ".", "verbs", ".", "forEach", "(", "function", "(", "verb", ")", "{", "addSingleRoute", "(", "verb", ",", "actionPath", ",", "controllerName", ",", "route", ".", "target", ".", "action", ")", ";", "}", ")", ";", "}", ")", ";", "}" ]
add a resource route @param {String} routePath route path @param {String} controllerName controller name
[ "add", "a", "resource", "route" ]
377ebd79563b8fa654bb18324aed00d72500e7f6
https://github.com/floridoo/scarab/blob/377ebd79563b8fa654bb18324aed00d72500e7f6/lib/routing.js#L108-L115
44,060
floridoo/scarab
lib/routing.js
addStaticRoute
function addStaticRoute(routePath, targets) { if (!Object.isArray(targets)) { targets = [targets]; } targets.forEach(function(target) { if (target) app.use(routePath, app.middleware.static(path.resolve(config.rootDir, target))); }); }
javascript
function addStaticRoute(routePath, targets) { if (!Object.isArray(targets)) { targets = [targets]; } targets.forEach(function(target) { if (target) app.use(routePath, app.middleware.static(path.resolve(config.rootDir, target))); }); }
[ "function", "addStaticRoute", "(", "routePath", ",", "targets", ")", "{", "if", "(", "!", "Object", ".", "isArray", "(", "targets", ")", ")", "{", "targets", "=", "[", "targets", "]", ";", "}", "targets", ".", "forEach", "(", "function", "(", "target", ")", "{", "if", "(", "target", ")", "app", ".", "use", "(", "routePath", ",", "app", ".", "middleware", ".", "static", "(", "path", ".", "resolve", "(", "config", ".", "rootDir", ",", "target", ")", ")", ")", ";", "}", ")", ";", "}" ]
add a static route @param {String} routePath route path @param {String} target target path (relative to the scarab root)
[ "add", "a", "static", "route" ]
377ebd79563b8fa654bb18324aed00d72500e7f6
https://github.com/floridoo/scarab/blob/377ebd79563b8fa654bb18324aed00d72500e7f6/lib/routing.js#L122-L130
44,061
floridoo/scarab
lib/routing.js
parseRoute
function parseRoute(route, target) { var verbs, routePath, routeParts; routeParts = route.split(' '); if (routeParts.length === 1) { verbs = ['all']; routePath = routeParts[0]; } else { verbs = routeParts[0].split(','); verbs.map(function (verb) { return verb.trim().toLowerCase(); }); routePath = routeParts[1]; } return {verbs: verbs, path: routePath, target: target}; }
javascript
function parseRoute(route, target) { var verbs, routePath, routeParts; routeParts = route.split(' '); if (routeParts.length === 1) { verbs = ['all']; routePath = routeParts[0]; } else { verbs = routeParts[0].split(','); verbs.map(function (verb) { return verb.trim().toLowerCase(); }); routePath = routeParts[1]; } return {verbs: verbs, path: routePath, target: target}; }
[ "function", "parseRoute", "(", "route", ",", "target", ")", "{", "var", "verbs", ",", "routePath", ",", "routeParts", ";", "routeParts", "=", "route", ".", "split", "(", "' '", ")", ";", "if", "(", "routeParts", ".", "length", "===", "1", ")", "{", "verbs", "=", "[", "'all'", "]", ";", "routePath", "=", "routeParts", "[", "0", "]", ";", "}", "else", "{", "verbs", "=", "routeParts", "[", "0", "]", ".", "split", "(", "','", ")", ";", "verbs", ".", "map", "(", "function", "(", "verb", ")", "{", "return", "verb", ".", "trim", "(", ")", ".", "toLowerCase", "(", ")", ";", "}", ")", ";", "routePath", "=", "routeParts", "[", "1", "]", ";", "}", "return", "{", "verbs", ":", "verbs", ",", "path", ":", "routePath", ",", "target", ":", "target", "}", ";", "}" ]
parse a route @param {String} route a route definition @param {Object} target target definition @return {Object} route parsed into verbs, path and target
[ "parse", "a", "route" ]
377ebd79563b8fa654bb18324aed00d72500e7f6
https://github.com/floridoo/scarab/blob/377ebd79563b8fa654bb18324aed00d72500e7f6/lib/routing.js#L169-L184
44,062
vega/vega-runtime
src/parameters.js
parseParameter
function parseParameter(spec, ctx, params) { if (!spec || !isObject(spec)) return spec; for (var i=0, n=PARSERS.length, p; i<n; ++i) { p = PARSERS[i]; if (spec.hasOwnProperty(p.key)) { return p.parse(spec, ctx, params); } } return spec; }
javascript
function parseParameter(spec, ctx, params) { if (!spec || !isObject(spec)) return spec; for (var i=0, n=PARSERS.length, p; i<n; ++i) { p = PARSERS[i]; if (spec.hasOwnProperty(p.key)) { return p.parse(spec, ctx, params); } } return spec; }
[ "function", "parseParameter", "(", "spec", ",", "ctx", ",", "params", ")", "{", "if", "(", "!", "spec", "||", "!", "isObject", "(", "spec", ")", ")", "return", "spec", ";", "for", "(", "var", "i", "=", "0", ",", "n", "=", "PARSERS", ".", "length", ",", "p", ";", "i", "<", "n", ";", "++", "i", ")", "{", "p", "=", "PARSERS", "[", "i", "]", ";", "if", "(", "spec", ".", "hasOwnProperty", "(", "p", ".", "key", ")", ")", "{", "return", "p", ".", "parse", "(", "spec", ",", "ctx", ",", "params", ")", ";", "}", "}", "return", "spec", ";", "}" ]
Parse a single parameter.
[ "Parse", "a", "single", "parameter", "." ]
05491b95035b70d5bafb05c5eebef9fa0c06c509
https://github.com/vega/vega-runtime/blob/05491b95035b70d5bafb05c5eebef9fa0c06c509/src/parameters.js#L26-L36
44,063
vega/vega-runtime
src/parameters.js
getExpression
function getExpression(_, ctx, params) { if (_.$params) { // parse expression parameters parseParameters(_.$params, ctx, params); } var k = 'e:' + _.$expr + '_' + _.$name; return ctx.fn[k] || (ctx.fn[k] = accessor(parameterExpression(_.$expr, ctx), _.$fields, _.$name)); }
javascript
function getExpression(_, ctx, params) { if (_.$params) { // parse expression parameters parseParameters(_.$params, ctx, params); } var k = 'e:' + _.$expr + '_' + _.$name; return ctx.fn[k] || (ctx.fn[k] = accessor(parameterExpression(_.$expr, ctx), _.$fields, _.$name)); }
[ "function", "getExpression", "(", "_", ",", "ctx", ",", "params", ")", "{", "if", "(", "_", ".", "$params", ")", "{", "// parse expression parameters", "parseParameters", "(", "_", ".", "$params", ",", "ctx", ",", "params", ")", ";", "}", "var", "k", "=", "'e:'", "+", "_", ".", "$expr", "+", "'_'", "+", "_", ".", "$name", ";", "return", "ctx", ".", "fn", "[", "k", "]", "||", "(", "ctx", ".", "fn", "[", "k", "]", "=", "accessor", "(", "parameterExpression", "(", "_", ".", "$expr", ",", "ctx", ")", ",", "_", ".", "$fields", ",", "_", ".", "$name", ")", ")", ";", "}" ]
Resolve an expression reference.
[ "Resolve", "an", "expression", "reference", "." ]
05491b95035b70d5bafb05c5eebef9fa0c06c509
https://github.com/vega/vega-runtime/blob/05491b95035b70d5bafb05c5eebef9fa0c06c509/src/parameters.js#L61-L68
44,064
vega/vega-runtime
src/parameters.js
getKey
function getKey(_, ctx) { var k = 'k:' + _.$key + '_' + (!!_.$flat); return ctx.fn[k] || (ctx.fn[k] = key(_.$key, _.$flat)); }
javascript
function getKey(_, ctx) { var k = 'k:' + _.$key + '_' + (!!_.$flat); return ctx.fn[k] || (ctx.fn[k] = key(_.$key, _.$flat)); }
[ "function", "getKey", "(", "_", ",", "ctx", ")", "{", "var", "k", "=", "'k:'", "+", "_", ".", "$key", "+", "'_'", "+", "(", "!", "!", "_", ".", "$flat", ")", ";", "return", "ctx", ".", "fn", "[", "k", "]", "||", "(", "ctx", ".", "fn", "[", "k", "]", "=", "key", "(", "_", ".", "$key", ",", "_", ".", "$flat", ")", ")", ";", "}" ]
Resolve a key accessor reference.
[ "Resolve", "a", "key", "accessor", "reference", "." ]
05491b95035b70d5bafb05c5eebef9fa0c06c509
https://github.com/vega/vega-runtime/blob/05491b95035b70d5bafb05c5eebef9fa0c06c509/src/parameters.js#L73-L76
44,065
vega/vega-runtime
src/parameters.js
getField
function getField(_, ctx) { if (!_.$field) return null; var k = 'f:' + _.$field + '_' + _.$name; return ctx.fn[k] || (ctx.fn[k] = field(_.$field, _.$name)); }
javascript
function getField(_, ctx) { if (!_.$field) return null; var k = 'f:' + _.$field + '_' + _.$name; return ctx.fn[k] || (ctx.fn[k] = field(_.$field, _.$name)); }
[ "function", "getField", "(", "_", ",", "ctx", ")", "{", "if", "(", "!", "_", ".", "$field", ")", "return", "null", ";", "var", "k", "=", "'f:'", "+", "_", ".", "$field", "+", "'_'", "+", "_", ".", "$name", ";", "return", "ctx", ".", "fn", "[", "k", "]", "||", "(", "ctx", ".", "fn", "[", "k", "]", "=", "field", "(", "_", ".", "$field", ",", "_", ".", "$name", ")", ")", ";", "}" ]
Resolve a field accessor reference.
[ "Resolve", "a", "field", "accessor", "reference", "." ]
05491b95035b70d5bafb05c5eebef9fa0c06c509
https://github.com/vega/vega-runtime/blob/05491b95035b70d5bafb05c5eebef9fa0c06c509/src/parameters.js#L81-L85
44,066
vega/vega-runtime
src/parameters.js
getCompare
function getCompare(_, ctx) { var k = 'c:' + _.$compare + '_' + _.$order, c = array(_.$compare).map(function(_) { return (_ && _.$tupleid) ? tupleid : _; }); return ctx.fn[k] || (ctx.fn[k] = compare(c, _.$order)); }
javascript
function getCompare(_, ctx) { var k = 'c:' + _.$compare + '_' + _.$order, c = array(_.$compare).map(function(_) { return (_ && _.$tupleid) ? tupleid : _; }); return ctx.fn[k] || (ctx.fn[k] = compare(c, _.$order)); }
[ "function", "getCompare", "(", "_", ",", "ctx", ")", "{", "var", "k", "=", "'c:'", "+", "_", ".", "$compare", "+", "'_'", "+", "_", ".", "$order", ",", "c", "=", "array", "(", "_", ".", "$compare", ")", ".", "map", "(", "function", "(", "_", ")", "{", "return", "(", "_", "&&", "_", ".", "$tupleid", ")", "?", "tupleid", ":", "_", ";", "}", ")", ";", "return", "ctx", ".", "fn", "[", "k", "]", "||", "(", "ctx", ".", "fn", "[", "k", "]", "=", "compare", "(", "c", ",", "_", ".", "$order", ")", ")", ";", "}" ]
Resolve a comparator function reference.
[ "Resolve", "a", "comparator", "function", "reference", "." ]
05491b95035b70d5bafb05c5eebef9fa0c06c509
https://github.com/vega/vega-runtime/blob/05491b95035b70d5bafb05c5eebef9fa0c06c509/src/parameters.js#L90-L96
44,067
vega/vega-runtime
src/parameters.js
getEncode
function getEncode(_, ctx) { var spec = _.$encode, encode = {}, name, enc; for (name in spec) { enc = spec[name]; encode[name] = accessor(encodeExpression(enc.$expr, ctx), enc.$fields); encode[name].output = enc.$output; } return encode; }
javascript
function getEncode(_, ctx) { var spec = _.$encode, encode = {}, name, enc; for (name in spec) { enc = spec[name]; encode[name] = accessor(encodeExpression(enc.$expr, ctx), enc.$fields); encode[name].output = enc.$output; } return encode; }
[ "function", "getEncode", "(", "_", ",", "ctx", ")", "{", "var", "spec", "=", "_", ".", "$encode", ",", "encode", "=", "{", "}", ",", "name", ",", "enc", ";", "for", "(", "name", "in", "spec", ")", "{", "enc", "=", "spec", "[", "name", "]", ";", "encode", "[", "name", "]", "=", "accessor", "(", "encodeExpression", "(", "enc", ".", "$expr", ",", "ctx", ")", ",", "enc", ".", "$fields", ")", ";", "encode", "[", "name", "]", ".", "output", "=", "enc", ".", "$output", ";", "}", "return", "encode", ";", "}" ]
Resolve an encode operator reference.
[ "Resolve", "an", "encode", "operator", "reference", "." ]
05491b95035b70d5bafb05c5eebef9fa0c06c509
https://github.com/vega/vega-runtime/blob/05491b95035b70d5bafb05c5eebef9fa0c06c509/src/parameters.js#L101-L111
44,068
vega/vega-runtime
src/parameters.js
getSubflow
function getSubflow(_, ctx) { var spec = _.$subflow; return function(dataflow, key, parent) { var subctx = parseDataflow(spec, ctx.fork()), op = subctx.get(spec.operators[0].id), p = subctx.signals.parent; if (p) p.set(parent); return op; }; }
javascript
function getSubflow(_, ctx) { var spec = _.$subflow; return function(dataflow, key, parent) { var subctx = parseDataflow(spec, ctx.fork()), op = subctx.get(spec.operators[0].id), p = subctx.signals.parent; if (p) p.set(parent); return op; }; }
[ "function", "getSubflow", "(", "_", ",", "ctx", ")", "{", "var", "spec", "=", "_", ".", "$subflow", ";", "return", "function", "(", "dataflow", ",", "key", ",", "parent", ")", "{", "var", "subctx", "=", "parseDataflow", "(", "spec", ",", "ctx", ".", "fork", "(", ")", ")", ",", "op", "=", "subctx", ".", "get", "(", "spec", ".", "operators", "[", "0", "]", ".", "id", ")", ",", "p", "=", "subctx", ".", "signals", ".", "parent", ";", "if", "(", "p", ")", "p", ".", "set", "(", "parent", ")", ";", "return", "op", ";", "}", ";", "}" ]
Resolve a recursive subflow specification.
[ "Resolve", "a", "recursive", "subflow", "specification", "." ]
05491b95035b70d5bafb05c5eebef9fa0c06c509
https://github.com/vega/vega-runtime/blob/05491b95035b70d5bafb05c5eebef9fa0c06c509/src/parameters.js#L123-L132
44,069
vutran/hot-reload-server
lib/index.js
start
function start() { // Listen to the port app.listen(hrsConfigs.port, function (err) { if (err) { info(err); } info('Running on http://%s:%s', hrsConfigs.address, hrsConfigs.port); }); }
javascript
function start() { // Listen to the port app.listen(hrsConfigs.port, function (err) { if (err) { info(err); } info('Running on http://%s:%s', hrsConfigs.address, hrsConfigs.port); }); }
[ "function", "start", "(", ")", "{", "// Listen to the port", "app", ".", "listen", "(", "hrsConfigs", ".", "port", ",", "function", "(", "err", ")", "{", "if", "(", "err", ")", "{", "info", "(", "err", ")", ";", "}", "info", "(", "'Running on http://%s:%s'", ",", "hrsConfigs", ".", "address", ",", "hrsConfigs", ".", "port", ")", ";", "}", ")", ";", "}" ]
Starts the hot-reload-server
[ "Starts", "the", "hot", "-", "reload", "-", "server" ]
c02a838350b8f98975900c4a0486d39cb3b13ce4
https://github.com/vutran/hot-reload-server/blob/c02a838350b8f98975900c4a0486d39cb3b13ce4/lib/index.js#L35-L43
44,070
franck34/qjobs
examples/simple.js
function(args,next) { // do nothing now but in 1 sec setTimeout(function() { // if i'm job id 10 or 20, let's add // another job dynamicaly in the queue. // It can be usefull for network operation (retry on timeout) if (args._jobId==10||args._jobId==20) { myQueueJobs.add(myjob,[999,'bla '+args._jobId]); } next(); },Math.random(1000)*2000); }
javascript
function(args,next) { // do nothing now but in 1 sec setTimeout(function() { // if i'm job id 10 or 20, let's add // another job dynamicaly in the queue. // It can be usefull for network operation (retry on timeout) if (args._jobId==10||args._jobId==20) { myQueueJobs.add(myjob,[999,'bla '+args._jobId]); } next(); },Math.random(1000)*2000); }
[ "function", "(", "args", ",", "next", ")", "{", "// do nothing now but in 1 sec", "setTimeout", "(", "function", "(", ")", "{", "// if i'm job id 10 or 20, let's add", "// another job dynamicaly in the queue.", "// It can be usefull for network operation (retry on timeout)", "if", "(", "args", ".", "_jobId", "==", "10", "||", "args", ".", "_jobId", "==", "20", ")", "{", "myQueueJobs", ".", "add", "(", "myjob", ",", "[", "999", ",", "'bla '", "+", "args", ".", "_jobId", "]", ")", ";", "}", "next", "(", ")", ";", "}", ",", "Math", ".", "random", "(", "1000", ")", "*", "2000", ")", ";", "}" ]
My non blocking main job
[ "My", "non", "blocking", "main", "job" ]
e065459d6cbfcadaa20c0aadc1d0a6c836b39aa1
https://github.com/franck34/qjobs/blob/e065459d6cbfcadaa20c0aadc1d0a6c836b39aa1/examples/simple.js#L3-L18
44,071
ariatemplates/hashspace
hsp/compiler/treebuilder/syntaxTree.js
isVoidElement
function isVoidElement(elName) { var result = false; if (elName && elName.toLowerCase) { result = VOID_HTML_ELEMENTS.hasOwnProperty(elName.toLowerCase()); } return result; }
javascript
function isVoidElement(elName) { var result = false; if (elName && elName.toLowerCase) { result = VOID_HTML_ELEMENTS.hasOwnProperty(elName.toLowerCase()); } return result; }
[ "function", "isVoidElement", "(", "elName", ")", "{", "var", "result", "=", "false", ";", "if", "(", "elName", "&&", "elName", ".", "toLowerCase", ")", "{", "result", "=", "VOID_HTML_ELEMENTS", ".", "hasOwnProperty", "(", "elName", ".", "toLowerCase", "(", ")", ")", ";", "}", "return", "result", ";", "}" ]
Checks if an element is a void one. @param {String} the element name. @return {Boolean} true if the element is a void one.
[ "Checks", "if", "an", "element", "is", "a", "void", "one", "." ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/compiler/treebuilder/syntaxTree.js#L30-L36
44,072
ariatemplates/hashspace
hsp/compiler/treebuilder/syntaxTree.js
function (blockList) { this.errors = []; this.tree = new Node("file", null); this.tree.content = []; this._advance(blockList, 0, this.tree.content); this._postProcessTree(); }
javascript
function (blockList) { this.errors = []; this.tree = new Node("file", null); this.tree.content = []; this._advance(blockList, 0, this.tree.content); this._postProcessTree(); }
[ "function", "(", "blockList", ")", "{", "this", ".", "errors", "=", "[", "]", ";", "this", ".", "tree", "=", "new", "Node", "(", "\"file\"", ",", "null", ")", ";", "this", ".", "tree", ".", "content", "=", "[", "]", ";", "this", ".", "_advance", "(", "blockList", ",", "0", ",", "this", ".", "tree", ".", "content", ")", ";", "this", ".", "_postProcessTree", "(", ")", ";", "}" ]
Generate the syntax tree from the root block list. @param {Object} blockList the block list.
[ "Generate", "the", "syntax", "tree", "from", "the", "root", "block", "list", "." ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/compiler/treebuilder/syntaxTree.js#L69-L77
44,073
ariatemplates/hashspace
hsp/compiler/treebuilder/syntaxTree.js
function (description, errdesc) { //TODO: errdesc is a bit vague var desc = { description : description }; if (errdesc) { if (errdesc.line) { // Integers desc.line = errdesc.line; desc.column = errdesc.column; } if (errdesc.code) { // String desc.code = errdesc.code; } if (errdesc.suberrors) { // Array of String desc.suberrors = errdesc.suberrors; } } this.errors.push(desc); }
javascript
function (description, errdesc) { //TODO: errdesc is a bit vague var desc = { description : description }; if (errdesc) { if (errdesc.line) { // Integers desc.line = errdesc.line; desc.column = errdesc.column; } if (errdesc.code) { // String desc.code = errdesc.code; } if (errdesc.suberrors) { // Array of String desc.suberrors = errdesc.suberrors; } } this.errors.push(desc); }
[ "function", "(", "description", ",", "errdesc", ")", "{", "//TODO: errdesc is a bit vague", "var", "desc", "=", "{", "description", ":", "description", "}", ";", "if", "(", "errdesc", ")", "{", "if", "(", "errdesc", ".", "line", ")", "{", "// Integers", "desc", ".", "line", "=", "errdesc", ".", "line", ";", "desc", ".", "column", "=", "errdesc", ".", "column", ";", "}", "if", "(", "errdesc", ".", "code", ")", "{", "// String", "desc", ".", "code", "=", "errdesc", ".", "code", ";", "}", "if", "(", "errdesc", ".", "suberrors", ")", "{", "// Array of String", "desc", ".", "suberrors", "=", "errdesc", ".", "suberrors", ";", "}", "}", "this", ".", "errors", ".", "push", "(", "desc", ")", ";", "}" ]
Adds an error to the current error list. @param {String} description the error description @param {Object} errdesc additional object (block, node, ...) which can contain additional info about the error (line/column number, code).
[ "Adds", "an", "error", "to", "the", "current", "error", "list", "." ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/compiler/treebuilder/syntaxTree.js#L84-L103
44,074
ariatemplates/hashspace
hsp/compiler/treebuilder/syntaxTree.js
function(expAst, attribute) { //verify that an event handler is a function call if (expAst && isEventHandlerAttr(attribute.name) && expAst.v !== '(') { this._logError("Event handler attribute only support function expressions", attribute.value[0]); } }
javascript
function(expAst, attribute) { //verify that an event handler is a function call if (expAst && isEventHandlerAttr(attribute.name) && expAst.v !== '(') { this._logError("Event handler attribute only support function expressions", attribute.value[0]); } }
[ "function", "(", "expAst", ",", "attribute", ")", "{", "//verify that an event handler is a function call", "if", "(", "expAst", "&&", "isEventHandlerAttr", "(", "attribute", ".", "name", ")", "&&", "expAst", ".", "v", "!==", "'('", ")", "{", "this", ".", "_logError", "(", "\"Event handler attribute only support function expressions\"", ",", "attribute", ".", "value", "[", "0", "]", ")", ";", "}", "}" ]
Logs an error if the value of an event handler attribute is not a function expression.
[ "Logs", "an", "error", "if", "the", "value", "of", "an", "event", "handler", "attribute", "is", "not", "a", "function", "expression", "." ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/compiler/treebuilder/syntaxTree.js#L123-L128
44,075
ariatemplates/hashspace
hsp/compiler/treebuilder/syntaxTree.js
function (blocks, startIndex, out, optEndFn) { var block, type; if (blocks) { for (var i = startIndex; i < blocks.length; i++) { block = blocks[i]; type = block.type; if (optEndFn && optEndFn(type, block.name)) { // we stop here return i; } //by convention, a block of type xyz is managed by a __xyz function in the class if (this["__" + type]) { i = this["__" + type](i, blocks, out); } else { this._logError("Invalid statement: " + type, block); } } return blocks.length; } }
javascript
function (blocks, startIndex, out, optEndFn) { var block, type; if (blocks) { for (var i = startIndex; i < blocks.length; i++) { block = blocks[i]; type = block.type; if (optEndFn && optEndFn(type, block.name)) { // we stop here return i; } //by convention, a block of type xyz is managed by a __xyz function in the class if (this["__" + type]) { i = this["__" + type](i, blocks, out); } else { this._logError("Invalid statement: " + type, block); } } return blocks.length; } }
[ "function", "(", "blocks", ",", "startIndex", ",", "out", ",", "optEndFn", ")", "{", "var", "block", ",", "type", ";", "if", "(", "blocks", ")", "{", "for", "(", "var", "i", "=", "startIndex", ";", "i", "<", "blocks", ".", "length", ";", "i", "++", ")", "{", "block", "=", "blocks", "[", "i", "]", ";", "type", "=", "block", ".", "type", ";", "if", "(", "optEndFn", "&&", "optEndFn", "(", "type", ",", "block", ".", "name", ")", ")", "{", "// we stop here", "return", "i", ";", "}", "//by convention, a block of type xyz is managed by a __xyz function in the class ", "if", "(", "this", "[", "\"__\"", "+", "type", "]", ")", "{", "i", "=", "this", "[", "\"__\"", "+", "type", "]", "(", "i", ",", "blocks", ",", "out", ")", ";", "}", "else", "{", "this", ".", "_logError", "(", "\"Invalid statement: \"", "+", "type", ",", "block", ")", ";", "}", "}", "return", "blocks", ".", "length", ";", "}", "}" ]
Process a list of blocks and advance the cursor index that scans the collection. @param {Array} blocks the full list of blocks. @param {Integer} startIndex the index from which the process has to start. @param {Array} out the output as an array of Node. @param {Function} optEndFn an optional end function that takes a node type as argument. @return {Integer} the index of the block where the function stopped or -1 if all blocks have been handled.
[ "Process", "a", "list", "of", "blocks", "and", "advance", "the", "cursor", "index", "that", "scans", "the", "collection", "." ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/compiler/treebuilder/syntaxTree.js#L138-L158
44,076
ariatemplates/hashspace
hsp/compiler/treebuilder/syntaxTree.js
function() { var nodes = this.tree.content; for (var i = 0; i < nodes.length; i++) { if (nodes[i].type === "template") { this._processNodeContent(nodes[i].content,nodes[i]); } } }
javascript
function() { var nodes = this.tree.content; for (var i = 0; i < nodes.length; i++) { if (nodes[i].type === "template") { this._processNodeContent(nodes[i].content,nodes[i]); } } }
[ "function", "(", ")", "{", "var", "nodes", "=", "this", ".", "tree", ".", "content", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "nodes", ".", "length", ";", "i", "++", ")", "{", "if", "(", "nodes", "[", "i", "]", ".", "type", "===", "\"template\"", ")", "{", "this", ".", "_processNodeContent", "(", "nodes", "[", "i", "]", ".", "content", ",", "nodes", "[", "i", "]", ")", ";", "}", "}", "}" ]
Post validation once the tree is properly parsed.
[ "Post", "validation", "once", "the", "tree", "is", "properly", "parsed", "." ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/compiler/treebuilder/syntaxTree.js#L163-L170
44,077
ariatemplates/hashspace
hsp/compiler/treebuilder/syntaxTree.js
function(nodeList, parent) { // Ensure that {let} nodes are always at the beginning of a containter element var node, contentFound = false; // true when a node different from let is found for (var i = 0; i < nodeList.length; i++) { node = nodeList[i]; //console.log(i+":"+node.type) if (node.type === "comment") { continue; } if (node.type==="text") { // tolerate static white space text if (node.value.match(/^\s*$/)) { continue; } } if (node.type === "let") { if (contentFound) { // error: let must be defined before any piece of content this._logError("Let statements must be defined at the beginning of a block", node); } else { parent.needSubScope = true; } } else { contentFound = true; if (node.content) { this._processNodeContent(node.content, node); } if (node.content1) { this._processNodeContent(node.content1, node); } if (node.content2) { this._processNodeContent(node.content2, node); } } } }
javascript
function(nodeList, parent) { // Ensure that {let} nodes are always at the beginning of a containter element var node, contentFound = false; // true when a node different from let is found for (var i = 0; i < nodeList.length; i++) { node = nodeList[i]; //console.log(i+":"+node.type) if (node.type === "comment") { continue; } if (node.type==="text") { // tolerate static white space text if (node.value.match(/^\s*$/)) { continue; } } if (node.type === "let") { if (contentFound) { // error: let must be defined before any piece of content this._logError("Let statements must be defined at the beginning of a block", node); } else { parent.needSubScope = true; } } else { contentFound = true; if (node.content) { this._processNodeContent(node.content, node); } if (node.content1) { this._processNodeContent(node.content1, node); } if (node.content2) { this._processNodeContent(node.content2, node); } } } }
[ "function", "(", "nodeList", ",", "parent", ")", "{", "// Ensure that {let} nodes are always at the beginning of a containter element", "var", "node", ",", "contentFound", "=", "false", ";", "// true when a node different from let is found", "for", "(", "var", "i", "=", "0", ";", "i", "<", "nodeList", ".", "length", ";", "i", "++", ")", "{", "node", "=", "nodeList", "[", "i", "]", ";", "//console.log(i+\":\"+node.type)", "if", "(", "node", ".", "type", "===", "\"comment\"", ")", "{", "continue", ";", "}", "if", "(", "node", ".", "type", "===", "\"text\"", ")", "{", "// tolerate static white space text", "if", "(", "node", ".", "value", ".", "match", "(", "/", "^\\s*$", "/", ")", ")", "{", "continue", ";", "}", "}", "if", "(", "node", ".", "type", "===", "\"let\"", ")", "{", "if", "(", "contentFound", ")", "{", "// error: let must be defined before any piece of content", "this", ".", "_logError", "(", "\"Let statements must be defined at the beginning of a block\"", ",", "node", ")", ";", "}", "else", "{", "parent", ".", "needSubScope", "=", "true", ";", "}", "}", "else", "{", "contentFound", "=", "true", ";", "if", "(", "node", ".", "content", ")", "{", "this", ".", "_processNodeContent", "(", "node", ".", "content", ",", "node", ")", ";", "}", "if", "(", "node", ".", "content1", ")", "{", "this", ".", "_processNodeContent", "(", "node", ".", "content1", ",", "node", ")", ";", "}", "if", "(", "node", ".", "content2", ")", "{", "this", ".", "_processNodeContent", "(", "node", ".", "content2", ",", "node", ")", ";", "}", "}", "}", "}" ]
Validates the content of a container node. @param {Array} nodeList the content of a container node @param {Node} parent the parent node
[ "Validates", "the", "content", "of", "a", "container", "node", "." ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/compiler/treebuilder/syntaxTree.js#L177-L212
44,078
ariatemplates/hashspace
hsp/compiler/treebuilder/syntaxTree.js
function (index, blocks, out) { var node = new Node("template"); var block = blocks[index]; var validationResults = this._processTemplateStart(block.attributes, block.closingBrace); if (validationResults.errors.length > 0) { this._logError("Invalid template declaration", { line: block.line, column : block.column, code: validationResults.code, suberrors: validationResults.errors }); } node.name = block.name; if (block.controller) { node.controller = block.controller; node.controller.ref = block.controllerRef; } else if (block.args) { node.args = block.args; // check args for (var i=0; i < node.args.length; i++) { if (reservedKeywords[node.args[i]]) { this._logError("Reserved keywords cannot be used as template argument: "+node.args[i], block); } } } node.isExport = (block.modifier !== null && block.modifier.type === "export"); node.isExportModule = (block.modifier !== null && block.modifier.type === "export-module"); node.startLine = block.line; node.endLine = block.endLine; node.content = []; out.push(node); if (!block.closed) { this._logError("Missing end template statement", block); } // parse sub-list of blocks this._advance(block.content, 0, node.content); return index; }
javascript
function (index, blocks, out) { var node = new Node("template"); var block = blocks[index]; var validationResults = this._processTemplateStart(block.attributes, block.closingBrace); if (validationResults.errors.length > 0) { this._logError("Invalid template declaration", { line: block.line, column : block.column, code: validationResults.code, suberrors: validationResults.errors }); } node.name = block.name; if (block.controller) { node.controller = block.controller; node.controller.ref = block.controllerRef; } else if (block.args) { node.args = block.args; // check args for (var i=0; i < node.args.length; i++) { if (reservedKeywords[node.args[i]]) { this._logError("Reserved keywords cannot be used as template argument: "+node.args[i], block); } } } node.isExport = (block.modifier !== null && block.modifier.type === "export"); node.isExportModule = (block.modifier !== null && block.modifier.type === "export-module"); node.startLine = block.line; node.endLine = block.endLine; node.content = []; out.push(node); if (!block.closed) { this._logError("Missing end template statement", block); } // parse sub-list of blocks this._advance(block.content, 0, node.content); return index; }
[ "function", "(", "index", ",", "blocks", ",", "out", ")", "{", "var", "node", "=", "new", "Node", "(", "\"template\"", ")", ";", "var", "block", "=", "blocks", "[", "index", "]", ";", "var", "validationResults", "=", "this", ".", "_processTemplateStart", "(", "block", ".", "attributes", ",", "block", ".", "closingBrace", ")", ";", "if", "(", "validationResults", ".", "errors", ".", "length", ">", "0", ")", "{", "this", ".", "_logError", "(", "\"Invalid template declaration\"", ",", "{", "line", ":", "block", ".", "line", ",", "column", ":", "block", ".", "column", ",", "code", ":", "validationResults", ".", "code", ",", "suberrors", ":", "validationResults", ".", "errors", "}", ")", ";", "}", "node", ".", "name", "=", "block", ".", "name", ";", "if", "(", "block", ".", "controller", ")", "{", "node", ".", "controller", "=", "block", ".", "controller", ";", "node", ".", "controller", ".", "ref", "=", "block", ".", "controllerRef", ";", "}", "else", "if", "(", "block", ".", "args", ")", "{", "node", ".", "args", "=", "block", ".", "args", ";", "// check args", "for", "(", "var", "i", "=", "0", ";", "i", "<", "node", ".", "args", ".", "length", ";", "i", "++", ")", "{", "if", "(", "reservedKeywords", "[", "node", ".", "args", "[", "i", "]", "]", ")", "{", "this", ".", "_logError", "(", "\"Reserved keywords cannot be used as template argument: \"", "+", "node", ".", "args", "[", "i", "]", ",", "block", ")", ";", "}", "}", "}", "node", ".", "isExport", "=", "(", "block", ".", "modifier", "!==", "null", "&&", "block", ".", "modifier", ".", "type", "===", "\"export\"", ")", ";", "node", ".", "isExportModule", "=", "(", "block", ".", "modifier", "!==", "null", "&&", "block", ".", "modifier", ".", "type", "===", "\"export-module\"", ")", ";", "node", ".", "startLine", "=", "block", ".", "line", ";", "node", ".", "endLine", "=", "block", ".", "endLine", ";", "node", ".", "content", "=", "[", "]", ";", "out", ".", "push", "(", "node", ")", ";", "if", "(", "!", "block", ".", "closed", ")", "{", "this", ".", "_logError", "(", "\"Missing end template statement\"", ",", "block", ")", ";", "}", "// parse sub-list of blocks", "this", ".", "_advance", "(", "block", ".", "content", ",", "0", ",", "node", ".", "content", ")", ";", "return", "index", ";", "}" ]
Manages a template block. @param {Array} blocks the full list of blocks. @param {Integer} index the index of the block to manage. @param {Array} out the output as an array of Node. @return {Integer} the index of the block where the function stopped or -1 if all blocks have been handled.
[ "Manages", "a", "template", "block", "." ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/compiler/treebuilder/syntaxTree.js#L363-L404
44,079
ariatemplates/hashspace
hsp/compiler/treebuilder/syntaxTree.js
function (index, blocks, out) { var node = new Node("plaintext"), block = blocks[index]; node.value = block.value; out.push(node); return index; }
javascript
function (index, blocks, out) { var node = new Node("plaintext"), block = blocks[index]; node.value = block.value; out.push(node); return index; }
[ "function", "(", "index", ",", "blocks", ",", "out", ")", "{", "var", "node", "=", "new", "Node", "(", "\"plaintext\"", ")", ",", "block", "=", "blocks", "[", "index", "]", ";", "node", ".", "value", "=", "block", ".", "value", ";", "out", ".", "push", "(", "node", ")", ";", "return", "index", ";", "}" ]
Manages a text block. @param {Array} blocks the full list of blocks. @param {Integer} index the index of the block to manage. @param {Array} out the output as an array of Node. @return {Integer} the index of the block where the function stopped or -1 if all blocks have been handled.
[ "Manages", "a", "text", "block", "." ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/compiler/treebuilder/syntaxTree.js#L413-L418
44,080
ariatemplates/hashspace
hsp/compiler/treebuilder/syntaxTree.js
function (index, blocks, out) { var node = new Node("log"), block = blocks[index]; node.line = block.line; node.column = block.column; node.exprs = block.exprs; out.push(node); return index; }
javascript
function (index, blocks, out) { var node = new Node("log"), block = blocks[index]; node.line = block.line; node.column = block.column; node.exprs = block.exprs; out.push(node); return index; }
[ "function", "(", "index", ",", "blocks", ",", "out", ")", "{", "var", "node", "=", "new", "Node", "(", "\"log\"", ")", ",", "block", "=", "blocks", "[", "index", "]", ";", "node", ".", "line", "=", "block", ".", "line", ";", "node", ".", "column", "=", "block", ".", "column", ";", "node", ".", "exprs", "=", "block", ".", "exprs", ";", "out", ".", "push", "(", "node", ")", ";", "return", "index", ";", "}" ]
Manages a log statement. @param {Array} blocks the full list of blocks. @param {Integer} index the index of the block to manage. @param {Array} out the output as an array of Node. @return {Integer} the index of the block where the function stopped or -1 if all blocks have been handled.
[ "Manages", "a", "log", "statement", "." ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/compiler/treebuilder/syntaxTree.js#L443-L450
44,081
ariatemplates/hashspace
hsp/compiler/treebuilder/syntaxTree.js
function (index, blocks, out) { //creates the if node var node = new Node("if"), block = blocks[index], lastValidIndex = index; node.condition = { "category": block.condition.category, "value": block.condition.value, "line": block.condition.line, "column": block.condition.column }; node.condition.bound = true; //TODO: what does it mean? node.content1 = []; out.push(node); var endFound = false, out2 = node.content1; //process the content of the if block, until one of the if end is found (i.e. endif, else or elseif), if any while (!endFound) { //fills node.content1 with the next blocks index = this._advance(blocks, index + 1, out2, this._ifEndTypes); if (index < 0 || !blocks[index]) { this._logError("Missing end if statement", blocks[lastValidIndex]); endFound = true; } else { var type = blocks[index].type; if (type === "endif") { endFound = true; } else if (type === "else") { //loop will restrat, filling node.content2 with the next blocks node.content2 = []; out2 = node.content2; lastValidIndex = index; } else if (type === "elseif") { // consider as a standard else statement node.content2 = []; out2 = node.content2; lastValidIndex = index; endFound = true; // process as if it were an if node index = this.__if(index, blocks, out2); } } } return index; }
javascript
function (index, blocks, out) { //creates the if node var node = new Node("if"), block = blocks[index], lastValidIndex = index; node.condition = { "category": block.condition.category, "value": block.condition.value, "line": block.condition.line, "column": block.condition.column }; node.condition.bound = true; //TODO: what does it mean? node.content1 = []; out.push(node); var endFound = false, out2 = node.content1; //process the content of the if block, until one of the if end is found (i.e. endif, else or elseif), if any while (!endFound) { //fills node.content1 with the next blocks index = this._advance(blocks, index + 1, out2, this._ifEndTypes); if (index < 0 || !blocks[index]) { this._logError("Missing end if statement", blocks[lastValidIndex]); endFound = true; } else { var type = blocks[index].type; if (type === "endif") { endFound = true; } else if (type === "else") { //loop will restrat, filling node.content2 with the next blocks node.content2 = []; out2 = node.content2; lastValidIndex = index; } else if (type === "elseif") { // consider as a standard else statement node.content2 = []; out2 = node.content2; lastValidIndex = index; endFound = true; // process as if it were an if node index = this.__if(index, blocks, out2); } } } return index; }
[ "function", "(", "index", ",", "blocks", ",", "out", ")", "{", "//creates the if node", "var", "node", "=", "new", "Node", "(", "\"if\"", ")", ",", "block", "=", "blocks", "[", "index", "]", ",", "lastValidIndex", "=", "index", ";", "node", ".", "condition", "=", "{", "\"category\"", ":", "block", ".", "condition", ".", "category", ",", "\"value\"", ":", "block", ".", "condition", ".", "value", ",", "\"line\"", ":", "block", ".", "condition", ".", "line", ",", "\"column\"", ":", "block", ".", "condition", ".", "column", "}", ";", "node", ".", "condition", ".", "bound", "=", "true", ";", "//TODO: what does it mean?", "node", ".", "content1", "=", "[", "]", ";", "out", ".", "push", "(", "node", ")", ";", "var", "endFound", "=", "false", ",", "out2", "=", "node", ".", "content1", ";", "//process the content of the if block, until one of the if end is found (i.e. endif, else or elseif), if any", "while", "(", "!", "endFound", ")", "{", "//fills node.content1 with the next blocks", "index", "=", "this", ".", "_advance", "(", "blocks", ",", "index", "+", "1", ",", "out2", ",", "this", ".", "_ifEndTypes", ")", ";", "if", "(", "index", "<", "0", "||", "!", "blocks", "[", "index", "]", ")", "{", "this", ".", "_logError", "(", "\"Missing end if statement\"", ",", "blocks", "[", "lastValidIndex", "]", ")", ";", "endFound", "=", "true", ";", "}", "else", "{", "var", "type", "=", "blocks", "[", "index", "]", ".", "type", ";", "if", "(", "type", "===", "\"endif\"", ")", "{", "endFound", "=", "true", ";", "}", "else", "if", "(", "type", "===", "\"else\"", ")", "{", "//loop will restrat, filling node.content2 with the next blocks", "node", ".", "content2", "=", "[", "]", ";", "out2", "=", "node", ".", "content2", ";", "lastValidIndex", "=", "index", ";", "}", "else", "if", "(", "type", "===", "\"elseif\"", ")", "{", "// consider as a standard else statement", "node", ".", "content2", "=", "[", "]", ";", "out2", "=", "node", ".", "content2", ";", "lastValidIndex", "=", "index", ";", "endFound", "=", "true", ";", "// process as if it were an if node", "index", "=", "this", ".", "__if", "(", "index", ",", "blocks", ",", "out2", ")", ";", "}", "}", "}", "return", "index", ";", "}" ]
Manages an if block. @param {Array} blocks the full list of blocks. @param {Integer} index the index of the block to manage. @param {Array} out the output as an array of Node. @return {Integer} the index of the block where the function stopped or -1 if all blocks have been handled.
[ "Manages", "an", "if", "block", "." ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/compiler/treebuilder/syntaxTree.js#L562-L606
44,082
ariatemplates/hashspace
hsp/compiler/treebuilder/syntaxTree.js
function (index, blocks, out) { //creates the foreach node var node = new Node("foreach"), block = blocks[index]; node.item = block.item; node.key = block.key; node.collection = block.colref; node.content = []; out.push(node); //fills node.content with the next blocks, until an endforeach is found, if any var nextIndex = this._advance(blocks, index + 1, node.content, this._foreachEndTypes); if (nextIndex < 0 || !blocks[nextIndex]) { this._logError("Missing end foreach statement", blocks[index]); } return nextIndex; }
javascript
function (index, blocks, out) { //creates the foreach node var node = new Node("foreach"), block = blocks[index]; node.item = block.item; node.key = block.key; node.collection = block.colref; node.content = []; out.push(node); //fills node.content with the next blocks, until an endforeach is found, if any var nextIndex = this._advance(blocks, index + 1, node.content, this._foreachEndTypes); if (nextIndex < 0 || !blocks[nextIndex]) { this._logError("Missing end foreach statement", blocks[index]); } return nextIndex; }
[ "function", "(", "index", ",", "blocks", ",", "out", ")", "{", "//creates the foreach node", "var", "node", "=", "new", "Node", "(", "\"foreach\"", ")", ",", "block", "=", "blocks", "[", "index", "]", ";", "node", ".", "item", "=", "block", ".", "item", ";", "node", ".", "key", "=", "block", ".", "key", ";", "node", ".", "collection", "=", "block", ".", "colref", ";", "node", ".", "content", "=", "[", "]", ";", "out", ".", "push", "(", "node", ")", ";", "//fills node.content with the next blocks, until an endforeach is found, if any", "var", "nextIndex", "=", "this", ".", "_advance", "(", "blocks", ",", "index", "+", "1", ",", "node", ".", "content", ",", "this", ".", "_foreachEndTypes", ")", ";", "if", "(", "nextIndex", "<", "0", "||", "!", "blocks", "[", "nextIndex", "]", ")", "{", "this", ".", "_logError", "(", "\"Missing end foreach statement\"", ",", "blocks", "[", "index", "]", ")", ";", "}", "return", "nextIndex", ";", "}" ]
Manages a foreach block. @param {Array} blocks the full list of blocks. @param {Integer} index the index of the block to manage. @param {Array} out the output as an array of Node. @return {Integer} the index of the block where the function stopped or -1 if all blocks have been handled.
[ "Manages", "a", "foreach", "block", "." ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/compiler/treebuilder/syntaxTree.js#L666-L683
44,083
ariatemplates/hashspace
hsp/compiler/treebuilder/syntaxTree.js
function (index, blocks, out) { var block = blocks[index]; if (isVoidElement(block.name)) { block.closed=true; } return this._elementOrComponent("element", index, blocks, out); }
javascript
function (index, blocks, out) { var block = blocks[index]; if (isVoidElement(block.name)) { block.closed=true; } return this._elementOrComponent("element", index, blocks, out); }
[ "function", "(", "index", ",", "blocks", ",", "out", ")", "{", "var", "block", "=", "blocks", "[", "index", "]", ";", "if", "(", "isVoidElement", "(", "block", ".", "name", ")", ")", "{", "block", ".", "closed", "=", "true", ";", "}", "return", "this", ".", "_elementOrComponent", "(", "\"element\"", ",", "index", ",", "blocks", ",", "out", ")", ";", "}" ]
Manages an element block. @param {Array} blocks the full list of blocks. @param {Integer} index the index of the block to manage. @param {Array} out the output as an array of Node. @return {Integer} the index of the block where the function stopped or -1 if all blocks have been handled.
[ "Manages", "an", "element", "block", "." ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/compiler/treebuilder/syntaxTree.js#L715-L721
44,084
ariatemplates/hashspace
hsp/compiler/treebuilder/syntaxTree.js
function (blockType, index, blocks, out) { var node = new Node(blockType), block = blocks[index], blockValue, expAst; node.name = block.name; node.closed = block.closed; if (block.ref) { // only for components node.ref = block.ref; } // Handle attributes var attributes = block.attributes, attribute, outAttribute; node.attributes = []; for (var i = 0; i < attributes.length; i++) { attribute = attributes[i]; //invalid attribute if (attribute.type === "invalidattribute") { for (var j = 0; j < attribute.errors.length; j++) { var error = attribute.errors[j]; var msg = "Invalid attribute"; if (error.errorType === "name") { msg = "Invalid attribute name: \\\"" + error.value + "\\\""; } else if (error.errorType === "value" || error.errorType === "tail") { var valueAsString = ""; for (var k = 0; k < error.value.length; k++) { var errorBlock = error.value[k]; if (k === 0) { error.line = errorBlock.line; error.column = errorBlock.column; } if (errorBlock.type === "expression") { valueAsString += "{" + errorBlock.value + "}"; var expAst = this._validateExpressionBlock(errorBlock); this._validateEventHandlerAttr(expAst, attribute); } else { valueAsString += errorBlock.value; } } if (typeof error.tail === "undefined") { msg = "Invalid attribute value: \\\"" + valueAsString + "\\\""; } else { msg = "Attribute value \\\"" + valueAsString + "\\\" has trailing chars: " + error.tail; } } else if (error.errorType === "invalidquotes") { msg = "Missing quote(s) around attribute value: " + error.value.replace("\"", "\\\""); } this._logError(msg, error); } continue; } //valid attribute var length = attribute.value.length; if (length === 0) { // this case arises when the attribute is empty - so let's create an empty text node if (attribute.value === "") { // attribute has no value - e.g. autocomplete in an input element outAttribute = { name : attribute.name, type : "name", line : attribute.line, column : attribute.column }; node.attributes.push(outAttribute); continue; } else { attribute.value.push({ type : "text", value : "" }); } length = 1; } if (length === 1) { // literal or expression var type = attribute.value[0].type; if (type === "text" || type === "expression") { outAttribute = attribute.value[0]; outAttribute.name = attribute.name; if (type === "expression") { expAst = this._validateExpressionBlock(outAttribute); this._validateEventHandlerAttr(expAst, attribute); } } else { this._logError("Invalid attribute type: " + type, attribute); continue; } } else { // length > 1 so attribute is a text block // if attribute is an event handler, raise an error if (isEventHandlerAttr(attribute.name)) { this._logError("Event handler attributes don't support text and expression mix", attribute); } //check expression attributes for syntax errors for (var j=0; j<length; j++) { blockValue = attribute.value[j]; if (blockValue.type === "expression") { expAst = this._validateExpressionBlock(blockValue); this._validateEventHandlerAttr(expAst, attribute); } } outAttribute = { name : attribute.name, type : "textblock", content : attribute.value }; } node.attributes.push(outAttribute); } //fills node.content with the next blocks, until an matching end element is found, if any node.content = []; out.push(node); if (!block.closed) { var endFound = false, blockName = block.name; while (!endFound) { index = this._advance(blocks, index + 1, node.content, function (type, name) { return (type === "end" + blockType); // && name===blockName }); if (index < 0 || !blocks[index]) { if (blockType==="component") { blockName="#"+this._getComponentPathAsString(block.ref); } // we didn't find any endelement or endcomponent this._logError("Missing end " + blockType + " </" + blockName + ">", block); endFound = true; } else { // check if the end name is correct var endBlock = blocks[index]; if (endBlock.type === "endelement" || endBlock.type === "endcptattribute") { if (endBlock.name !== blockName) { this._logError("Missing end " + blockType + " </" + blockName + ">", block); index -= 1; // the current end element/component may be caught by a container element } } else { // endcomponent var beginPath = this._getComponentPathAsString(block.ref), endPath = this._getComponentPathAsString(endBlock.ref); if (beginPath !== endPath) { this._logError("Missing end component </#" + beginPath + ">", block); index -= 1; // the current end element/component may be caught by a container element } } endFound = true; } } } return index; }
javascript
function (blockType, index, blocks, out) { var node = new Node(blockType), block = blocks[index], blockValue, expAst; node.name = block.name; node.closed = block.closed; if (block.ref) { // only for components node.ref = block.ref; } // Handle attributes var attributes = block.attributes, attribute, outAttribute; node.attributes = []; for (var i = 0; i < attributes.length; i++) { attribute = attributes[i]; //invalid attribute if (attribute.type === "invalidattribute") { for (var j = 0; j < attribute.errors.length; j++) { var error = attribute.errors[j]; var msg = "Invalid attribute"; if (error.errorType === "name") { msg = "Invalid attribute name: \\\"" + error.value + "\\\""; } else if (error.errorType === "value" || error.errorType === "tail") { var valueAsString = ""; for (var k = 0; k < error.value.length; k++) { var errorBlock = error.value[k]; if (k === 0) { error.line = errorBlock.line; error.column = errorBlock.column; } if (errorBlock.type === "expression") { valueAsString += "{" + errorBlock.value + "}"; var expAst = this._validateExpressionBlock(errorBlock); this._validateEventHandlerAttr(expAst, attribute); } else { valueAsString += errorBlock.value; } } if (typeof error.tail === "undefined") { msg = "Invalid attribute value: \\\"" + valueAsString + "\\\""; } else { msg = "Attribute value \\\"" + valueAsString + "\\\" has trailing chars: " + error.tail; } } else if (error.errorType === "invalidquotes") { msg = "Missing quote(s) around attribute value: " + error.value.replace("\"", "\\\""); } this._logError(msg, error); } continue; } //valid attribute var length = attribute.value.length; if (length === 0) { // this case arises when the attribute is empty - so let's create an empty text node if (attribute.value === "") { // attribute has no value - e.g. autocomplete in an input element outAttribute = { name : attribute.name, type : "name", line : attribute.line, column : attribute.column }; node.attributes.push(outAttribute); continue; } else { attribute.value.push({ type : "text", value : "" }); } length = 1; } if (length === 1) { // literal or expression var type = attribute.value[0].type; if (type === "text" || type === "expression") { outAttribute = attribute.value[0]; outAttribute.name = attribute.name; if (type === "expression") { expAst = this._validateExpressionBlock(outAttribute); this._validateEventHandlerAttr(expAst, attribute); } } else { this._logError("Invalid attribute type: " + type, attribute); continue; } } else { // length > 1 so attribute is a text block // if attribute is an event handler, raise an error if (isEventHandlerAttr(attribute.name)) { this._logError("Event handler attributes don't support text and expression mix", attribute); } //check expression attributes for syntax errors for (var j=0; j<length; j++) { blockValue = attribute.value[j]; if (blockValue.type === "expression") { expAst = this._validateExpressionBlock(blockValue); this._validateEventHandlerAttr(expAst, attribute); } } outAttribute = { name : attribute.name, type : "textblock", content : attribute.value }; } node.attributes.push(outAttribute); } //fills node.content with the next blocks, until an matching end element is found, if any node.content = []; out.push(node); if (!block.closed) { var endFound = false, blockName = block.name; while (!endFound) { index = this._advance(blocks, index + 1, node.content, function (type, name) { return (type === "end" + blockType); // && name===blockName }); if (index < 0 || !blocks[index]) { if (blockType==="component") { blockName="#"+this._getComponentPathAsString(block.ref); } // we didn't find any endelement or endcomponent this._logError("Missing end " + blockType + " </" + blockName + ">", block); endFound = true; } else { // check if the end name is correct var endBlock = blocks[index]; if (endBlock.type === "endelement" || endBlock.type === "endcptattribute") { if (endBlock.name !== blockName) { this._logError("Missing end " + blockType + " </" + blockName + ">", block); index -= 1; // the current end element/component may be caught by a container element } } else { // endcomponent var beginPath = this._getComponentPathAsString(block.ref), endPath = this._getComponentPathAsString(endBlock.ref); if (beginPath !== endPath) { this._logError("Missing end component </#" + beginPath + ">", block); index -= 1; // the current end element/component may be caught by a container element } } endFound = true; } } } return index; }
[ "function", "(", "blockType", ",", "index", ",", "blocks", ",", "out", ")", "{", "var", "node", "=", "new", "Node", "(", "blockType", ")", ",", "block", "=", "blocks", "[", "index", "]", ",", "blockValue", ",", "expAst", ";", "node", ".", "name", "=", "block", ".", "name", ";", "node", ".", "closed", "=", "block", ".", "closed", ";", "if", "(", "block", ".", "ref", ")", "{", "// only for components", "node", ".", "ref", "=", "block", ".", "ref", ";", "}", "// Handle attributes", "var", "attributes", "=", "block", ".", "attributes", ",", "attribute", ",", "outAttribute", ";", "node", ".", "attributes", "=", "[", "]", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "attributes", ".", "length", ";", "i", "++", ")", "{", "attribute", "=", "attributes", "[", "i", "]", ";", "//invalid attribute", "if", "(", "attribute", ".", "type", "===", "\"invalidattribute\"", ")", "{", "for", "(", "var", "j", "=", "0", ";", "j", "<", "attribute", ".", "errors", ".", "length", ";", "j", "++", ")", "{", "var", "error", "=", "attribute", ".", "errors", "[", "j", "]", ";", "var", "msg", "=", "\"Invalid attribute\"", ";", "if", "(", "error", ".", "errorType", "===", "\"name\"", ")", "{", "msg", "=", "\"Invalid attribute name: \\\\\\\"\"", "+", "error", ".", "value", "+", "\"\\\\\\\"\"", ";", "}", "else", "if", "(", "error", ".", "errorType", "===", "\"value\"", "||", "error", ".", "errorType", "===", "\"tail\"", ")", "{", "var", "valueAsString", "=", "\"\"", ";", "for", "(", "var", "k", "=", "0", ";", "k", "<", "error", ".", "value", ".", "length", ";", "k", "++", ")", "{", "var", "errorBlock", "=", "error", ".", "value", "[", "k", "]", ";", "if", "(", "k", "===", "0", ")", "{", "error", ".", "line", "=", "errorBlock", ".", "line", ";", "error", ".", "column", "=", "errorBlock", ".", "column", ";", "}", "if", "(", "errorBlock", ".", "type", "===", "\"expression\"", ")", "{", "valueAsString", "+=", "\"{\"", "+", "errorBlock", ".", "value", "+", "\"}\"", ";", "var", "expAst", "=", "this", ".", "_validateExpressionBlock", "(", "errorBlock", ")", ";", "this", ".", "_validateEventHandlerAttr", "(", "expAst", ",", "attribute", ")", ";", "}", "else", "{", "valueAsString", "+=", "errorBlock", ".", "value", ";", "}", "}", "if", "(", "typeof", "error", ".", "tail", "===", "\"undefined\"", ")", "{", "msg", "=", "\"Invalid attribute value: \\\\\\\"\"", "+", "valueAsString", "+", "\"\\\\\\\"\"", ";", "}", "else", "{", "msg", "=", "\"Attribute value \\\\\\\"\"", "+", "valueAsString", "+", "\"\\\\\\\" has trailing chars: \"", "+", "error", ".", "tail", ";", "}", "}", "else", "if", "(", "error", ".", "errorType", "===", "\"invalidquotes\"", ")", "{", "msg", "=", "\"Missing quote(s) around attribute value: \"", "+", "error", ".", "value", ".", "replace", "(", "\"\\\"\"", ",", "\"\\\\\\\"\"", ")", ";", "}", "this", ".", "_logError", "(", "msg", ",", "error", ")", ";", "}", "continue", ";", "}", "//valid attribute", "var", "length", "=", "attribute", ".", "value", ".", "length", ";", "if", "(", "length", "===", "0", ")", "{", "// this case arises when the attribute is empty - so let's create an empty text node", "if", "(", "attribute", ".", "value", "===", "\"\"", ")", "{", "// attribute has no value - e.g. autocomplete in an input element", "outAttribute", "=", "{", "name", ":", "attribute", ".", "name", ",", "type", ":", "\"name\"", ",", "line", ":", "attribute", ".", "line", ",", "column", ":", "attribute", ".", "column", "}", ";", "node", ".", "attributes", ".", "push", "(", "outAttribute", ")", ";", "continue", ";", "}", "else", "{", "attribute", ".", "value", ".", "push", "(", "{", "type", ":", "\"text\"", ",", "value", ":", "\"\"", "}", ")", ";", "}", "length", "=", "1", ";", "}", "if", "(", "length", "===", "1", ")", "{", "// literal or expression", "var", "type", "=", "attribute", ".", "value", "[", "0", "]", ".", "type", ";", "if", "(", "type", "===", "\"text\"", "||", "type", "===", "\"expression\"", ")", "{", "outAttribute", "=", "attribute", ".", "value", "[", "0", "]", ";", "outAttribute", ".", "name", "=", "attribute", ".", "name", ";", "if", "(", "type", "===", "\"expression\"", ")", "{", "expAst", "=", "this", ".", "_validateExpressionBlock", "(", "outAttribute", ")", ";", "this", ".", "_validateEventHandlerAttr", "(", "expAst", ",", "attribute", ")", ";", "}", "}", "else", "{", "this", ".", "_logError", "(", "\"Invalid attribute type: \"", "+", "type", ",", "attribute", ")", ";", "continue", ";", "}", "}", "else", "{", "// length > 1 so attribute is a text block", "// if attribute is an event handler, raise an error", "if", "(", "isEventHandlerAttr", "(", "attribute", ".", "name", ")", ")", "{", "this", ".", "_logError", "(", "\"Event handler attributes don't support text and expression mix\"", ",", "attribute", ")", ";", "}", "//check expression attributes for syntax errors", "for", "(", "var", "j", "=", "0", ";", "j", "<", "length", ";", "j", "++", ")", "{", "blockValue", "=", "attribute", ".", "value", "[", "j", "]", ";", "if", "(", "blockValue", ".", "type", "===", "\"expression\"", ")", "{", "expAst", "=", "this", ".", "_validateExpressionBlock", "(", "blockValue", ")", ";", "this", ".", "_validateEventHandlerAttr", "(", "expAst", ",", "attribute", ")", ";", "}", "}", "outAttribute", "=", "{", "name", ":", "attribute", ".", "name", ",", "type", ":", "\"textblock\"", ",", "content", ":", "attribute", ".", "value", "}", ";", "}", "node", ".", "attributes", ".", "push", "(", "outAttribute", ")", ";", "}", "//fills node.content with the next blocks, until an matching end element is found, if any", "node", ".", "content", "=", "[", "]", ";", "out", ".", "push", "(", "node", ")", ";", "if", "(", "!", "block", ".", "closed", ")", "{", "var", "endFound", "=", "false", ",", "blockName", "=", "block", ".", "name", ";", "while", "(", "!", "endFound", ")", "{", "index", "=", "this", ".", "_advance", "(", "blocks", ",", "index", "+", "1", ",", "node", ".", "content", ",", "function", "(", "type", ",", "name", ")", "{", "return", "(", "type", "===", "\"end\"", "+", "blockType", ")", ";", "// && name===blockName", "}", ")", ";", "if", "(", "index", "<", "0", "||", "!", "blocks", "[", "index", "]", ")", "{", "if", "(", "blockType", "===", "\"component\"", ")", "{", "blockName", "=", "\"#\"", "+", "this", ".", "_getComponentPathAsString", "(", "block", ".", "ref", ")", ";", "}", "// we didn't find any endelement or endcomponent", "this", ".", "_logError", "(", "\"Missing end \"", "+", "blockType", "+", "\" </\"", "+", "blockName", "+", "\">\"", ",", "block", ")", ";", "endFound", "=", "true", ";", "}", "else", "{", "// check if the end name is correct", "var", "endBlock", "=", "blocks", "[", "index", "]", ";", "if", "(", "endBlock", ".", "type", "===", "\"endelement\"", "||", "endBlock", ".", "type", "===", "\"endcptattribute\"", ")", "{", "if", "(", "endBlock", ".", "name", "!==", "blockName", ")", "{", "this", ".", "_logError", "(", "\"Missing end \"", "+", "blockType", "+", "\" </\"", "+", "blockName", "+", "\">\"", ",", "block", ")", ";", "index", "-=", "1", ";", "// the current end element/component may be caught by a container element", "}", "}", "else", "{", "// endcomponent", "var", "beginPath", "=", "this", ".", "_getComponentPathAsString", "(", "block", ".", "ref", ")", ",", "endPath", "=", "this", ".", "_getComponentPathAsString", "(", "endBlock", ".", "ref", ")", ";", "if", "(", "beginPath", "!==", "endPath", ")", "{", "this", ".", "_logError", "(", "\"Missing end component </#\"", "+", "beginPath", "+", "\">\"", ",", "block", ")", ";", "index", "-=", "1", ";", "// the current end element/component may be caught by a container element", "}", "}", "endFound", "=", "true", ";", "}", "}", "}", "return", "index", ";", "}" ]
Processing function for elements, components and component attributes @arg blockType {String} "element", "component" or "cptattribute". @param {Array} blocks the full list of blocks. @param {Integer} index the index of the block to manage. @param {Array} out the output as an array of Node. @return {Integer} the index of the block where the function stopped or -1 if all blocks have been handled.
[ "Processing", "function", "for", "elements", "components", "and", "component", "attributes" ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/compiler/treebuilder/syntaxTree.js#L753-L912
44,085
ariatemplates/hashspace
hsp/compiler/treebuilder/syntaxTree.js
function(ref) { if (ref.category !== "objectref" || !ref.path || !ref.path.length || !ref.path.join) { return null; } return ref.path.join("."); }
javascript
function(ref) { if (ref.category !== "objectref" || !ref.path || !ref.path.length || !ref.path.join) { return null; } return ref.path.join("."); }
[ "function", "(", "ref", ")", "{", "if", "(", "ref", ".", "category", "!==", "\"objectref\"", "||", "!", "ref", ".", "path", "||", "!", "ref", ".", "path", ".", "length", "||", "!", "ref", ".", "path", ".", "join", ")", "{", "return", "null", ";", "}", "return", "ref", ".", "path", ".", "join", "(", "\".\"", ")", ";", "}" ]
Transform a component path into a string - useful for error checking If path is invalid null is returned @param {Object} ref the ref structure returned by the PEG parser for components and endcomponents @retrun {String} the path as a string
[ "Transform", "a", "component", "path", "into", "a", "string", "-", "useful", "for", "error", "checking", "If", "path", "is", "invalid", "null", "is", "returned" ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/compiler/treebuilder/syntaxTree.js#L920-L925
44,086
ariatemplates/hashspace
hsp/compiler/treebuilder/syntaxTree.js
function (index, blocks, out) { // only called in case of error var block = blocks[index]; var msg = "Invalid HTML element syntax"; if (block.code && block.code.match(/^<\/?@/)) { //when it starts with <@ or </@ msg = "Invalid component attribute syntax"; } this._logError(msg, block); return index; }
javascript
function (index, blocks, out) { // only called in case of error var block = blocks[index]; var msg = "Invalid HTML element syntax"; if (block.code && block.code.match(/^<\/?@/)) { //when it starts with <@ or </@ msg = "Invalid component attribute syntax"; } this._logError(msg, block); return index; }
[ "function", "(", "index", ",", "blocks", ",", "out", ")", "{", "// only called in case of error", "var", "block", "=", "blocks", "[", "index", "]", ";", "var", "msg", "=", "\"Invalid HTML element syntax\"", ";", "if", "(", "block", ".", "code", "&&", "block", ".", "code", ".", "match", "(", "/", "^<\\/?@", "/", ")", ")", "{", "//when it starts with <@ or </@", "msg", "=", "\"Invalid component attribute syntax\"", ";", "}", "this", ".", "_logError", "(", "msg", ",", "block", ")", ";", "return", "index", ";", "}" ]
Catches invalid element errors. @param {Array} blocks the full list of blocks. @param {Integer} index the index of the block to manage. @param {Array} out the output as an array of Node. @return {Integer} the index of the block where the function stopped or -1 if all blocks have been handled.
[ "Catches", "invalid", "element", "errors", "." ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/compiler/treebuilder/syntaxTree.js#L934-L944
44,087
ariatemplates/hashspace
hsp/compiler/treebuilder/syntaxTree.js
function (index, blocks, out) { // only called in case of error, i.e not digested by _elementOrComponent var block = blocks[index], name = block.name; if (isVoidElement(name)) { this._logError("The end element </" + name + "> was rejected as <" + name + "> is a void HTML element and can't have a closing element", block); } else { this._logError("End element </" + name + "> does not match any <" + name + "> element", block); } return index; }
javascript
function (index, blocks, out) { // only called in case of error, i.e not digested by _elementOrComponent var block = blocks[index], name = block.name; if (isVoidElement(name)) { this._logError("The end element </" + name + "> was rejected as <" + name + "> is a void HTML element and can't have a closing element", block); } else { this._logError("End element </" + name + "> does not match any <" + name + "> element", block); } return index; }
[ "function", "(", "index", ",", "blocks", ",", "out", ")", "{", "// only called in case of error, i.e not digested by _elementOrComponent", "var", "block", "=", "blocks", "[", "index", "]", ",", "name", "=", "block", ".", "name", ";", "if", "(", "isVoidElement", "(", "name", ")", ")", "{", "this", ".", "_logError", "(", "\"The end element </\"", "+", "name", "+", "\"> was rejected as <\"", "+", "name", "+", "\"> is a void HTML element and can't have a closing element\"", ",", "block", ")", ";", "}", "else", "{", "this", ".", "_logError", "(", "\"End element </\"", "+", "name", "+", "\"> does not match any <\"", "+", "name", "+", "\"> element\"", ",", "block", ")", ";", "}", "return", "index", ";", "}" ]
Captures isolated end elements to raise an error. @param {Array} blocks the full list of blocks. @param {Integer} index the index of the block to manage. @param {Array} out the output as an array of Node. @return {Integer} the index of the block where the function stopped or -1 if all blocks have been handled.
[ "Captures", "isolated", "end", "elements", "to", "raise", "an", "error", "." ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/compiler/treebuilder/syntaxTree.js#L964-L973
44,088
ariatemplates/hashspace
hsp/compiler/treebuilder/syntaxTree.js
function (index, blocks, out) { // only called in case of error, i.e not digested by _elementOrComponent var block = blocks[index], path = this._getComponentPathAsString(block.ref) ; this._logError("End component </#" + path + "> does not match any <#" + path + "> component", block); return index; }
javascript
function (index, blocks, out) { // only called in case of error, i.e not digested by _elementOrComponent var block = blocks[index], path = this._getComponentPathAsString(block.ref) ; this._logError("End component </#" + path + "> does not match any <#" + path + "> component", block); return index; }
[ "function", "(", "index", ",", "blocks", ",", "out", ")", "{", "// only called in case of error, i.e not digested by _elementOrComponent", "var", "block", "=", "blocks", "[", "index", "]", ",", "path", "=", "this", ".", "_getComponentPathAsString", "(", "block", ".", "ref", ")", ";", "this", ".", "_logError", "(", "\"End component </#\"", "+", "path", "+", "\"> does not match any <#\"", "+", "path", "+", "\"> component\"", ",", "block", ")", ";", "return", "index", ";", "}" ]
Captures isolated end components to raise an error. @param {Array} blocks the full list of blocks. @param {Integer} index the index of the block to manage. @param {Array} out the output as an array of Node. @return {Integer} the index of the block where the function stopped or -1 if all blocks have been handled.
[ "Captures", "isolated", "end", "components", "to", "raise", "an", "error", "." ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/compiler/treebuilder/syntaxTree.js#L982-L987
44,089
mbouclas/loopback-connector-mailgun
lib/mailgun.js
Connector
function Connector(settings) { this.mailgun = Mailgun({apiKey: settings.apikey, domain: settings.domain}); }
javascript
function Connector(settings) { this.mailgun = Mailgun({apiKey: settings.apikey, domain: settings.domain}); }
[ "function", "Connector", "(", "settings", ")", "{", "this", ".", "mailgun", "=", "Mailgun", "(", "{", "apiKey", ":", "settings", ".", "apikey", ",", "domain", ":", "settings", ".", "domain", "}", ")", ";", "}" ]
Configure and create an instance of the connector
[ "Configure", "and", "create", "an", "instance", "of", "the", "connector" ]
9ab78b861da4f568a6b2be1af7f27e3ad11e006d
https://github.com/mbouclas/loopback-connector-mailgun/blob/9ab78b861da4f568a6b2be1af7f27e3ad11e006d/lib/mailgun.js#L15-L17
44,090
ariatemplates/hashspace
hsp/json.js
callObservers
function callObservers(object, chgeset) { var ln = object[OBSERVER_PROPERTY]; if (ln) { var elt; for (var i = 0, sz = ln.length; sz > i; i++) { elt = ln[i]; if (elt.constructor === Function) { elt(chgeset); } } } }
javascript
function callObservers(object, chgeset) { var ln = object[OBSERVER_PROPERTY]; if (ln) { var elt; for (var i = 0, sz = ln.length; sz > i; i++) { elt = ln[i]; if (elt.constructor === Function) { elt(chgeset); } } } }
[ "function", "callObservers", "(", "object", ",", "chgeset", ")", "{", "var", "ln", "=", "object", "[", "OBSERVER_PROPERTY", "]", ";", "if", "(", "ln", ")", "{", "var", "elt", ";", "for", "(", "var", "i", "=", "0", ",", "sz", "=", "ln", ".", "length", ";", "sz", ">", "i", ";", "i", "++", ")", "{", "elt", "=", "ln", "[", "i", "]", ";", "if", "(", "elt", ".", "constructor", "===", "Function", ")", "{", "elt", "(", "chgeset", ")", ";", "}", "}", "}", "}" ]
Call all observers for a givent object @param {Object} object reference to the object that is being observed @param {Array} chgeset an array of change descriptors (cf. changeDesc())
[ "Call", "all", "observers", "for", "a", "givent", "object" ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/json.js#L222-L233
44,091
ariatemplates/hashspace
hsp/json.js
function (object, property, value) { if (object[OBSERVER_PROPERTY]) { var existed = ownProperty.call(object, property), oldVal = object[property]; delete object[property]; if (existed) { var chgset=[changeDesc(object, property, object[property], oldVal, "deleted")]; callObservers(object, chgset); } } else { delete object[property]; } }
javascript
function (object, property, value) { if (object[OBSERVER_PROPERTY]) { var existed = ownProperty.call(object, property), oldVal = object[property]; delete object[property]; if (existed) { var chgset=[changeDesc(object, property, object[property], oldVal, "deleted")]; callObservers(object, chgset); } } else { delete object[property]; } }
[ "function", "(", "object", ",", "property", ",", "value", ")", "{", "if", "(", "object", "[", "OBSERVER_PROPERTY", "]", ")", "{", "var", "existed", "=", "ownProperty", ".", "call", "(", "object", ",", "property", ")", ",", "oldVal", "=", "object", "[", "property", "]", ";", "delete", "object", "[", "property", "]", ";", "if", "(", "existed", ")", "{", "var", "chgset", "=", "[", "changeDesc", "(", "object", ",", "property", ",", "object", "[", "property", "]", ",", "oldVal", ",", "\"deleted\"", ")", "]", ";", "callObservers", "(", "object", ",", "chgset", ")", ";", "}", "}", "else", "{", "delete", "object", "[", "property", "]", ";", "}", "}" ]
Delete a property in a JSON object and automatically notifies all observers of the change
[ "Delete", "a", "property", "in", "a", "JSON", "object", "and", "automatically", "notifies", "all", "observers", "of", "the", "change" ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/json.js#L275-L287
44,092
ariatemplates/hashspace
hsp/rt.js
function (tplctxt, scopevars, ctlWrapper, ctlInitArgs, rootscope) { var vs = rootscope ? Object.create(rootscope) : {}, nm, argNames = []; // array of argument names if (scopevars) { for (var i = 0, sz = scopevars.length; sz > i; i += 2) { nm = scopevars[i]; vs[nm] = scopevars[i + 1]; // feed the vscope argNames.push(nm); } } vs["$scope"] = vs; // self reference (used for variables - cf. expression handler) var root = null; if (tplctxt.$constructor && tplctxt.$constructor === $CptNode) { // we use the component node as root node root = tplctxt; root.init(vs, this.nodedefs, argNames, ctlWrapper, ctlInitArgs); } else { root = new $RootNode(vs, this.nodedefs, argNames, ctlWrapper, ctlInitArgs); } return root; }
javascript
function (tplctxt, scopevars, ctlWrapper, ctlInitArgs, rootscope) { var vs = rootscope ? Object.create(rootscope) : {}, nm, argNames = []; // array of argument names if (scopevars) { for (var i = 0, sz = scopevars.length; sz > i; i += 2) { nm = scopevars[i]; vs[nm] = scopevars[i + 1]; // feed the vscope argNames.push(nm); } } vs["$scope"] = vs; // self reference (used for variables - cf. expression handler) var root = null; if (tplctxt.$constructor && tplctxt.$constructor === $CptNode) { // we use the component node as root node root = tplctxt; root.init(vs, this.nodedefs, argNames, ctlWrapper, ctlInitArgs); } else { root = new $RootNode(vs, this.nodedefs, argNames, ctlWrapper, ctlInitArgs); } return root; }
[ "function", "(", "tplctxt", ",", "scopevars", ",", "ctlWrapper", ",", "ctlInitArgs", ",", "rootscope", ")", "{", "var", "vs", "=", "rootscope", "?", "Object", ".", "create", "(", "rootscope", ")", ":", "{", "}", ",", "nm", ",", "argNames", "=", "[", "]", ";", "// array of argument names", "if", "(", "scopevars", ")", "{", "for", "(", "var", "i", "=", "0", ",", "sz", "=", "scopevars", ".", "length", ";", "sz", ">", "i", ";", "i", "+=", "2", ")", "{", "nm", "=", "scopevars", "[", "i", "]", ";", "vs", "[", "nm", "]", "=", "scopevars", "[", "i", "+", "1", "]", ";", "// feed the vscope", "argNames", ".", "push", "(", "nm", ")", ";", "}", "}", "vs", "[", "\"$scope\"", "]", "=", "vs", ";", "// self reference (used for variables - cf. expression handler)", "var", "root", "=", "null", ";", "if", "(", "tplctxt", ".", "$constructor", "&&", "tplctxt", ".", "$constructor", "===", "$CptNode", ")", "{", "// we use the component node as root node", "root", "=", "tplctxt", ";", "root", ".", "init", "(", "vs", ",", "this", ".", "nodedefs", ",", "argNames", ",", "ctlWrapper", ",", "ctlInitArgs", ")", ";", "}", "else", "{", "root", "=", "new", "$RootNode", "(", "vs", ",", "this", ".", "nodedefs", ",", "argNames", ",", "ctlWrapper", ",", "ctlInitArgs", ")", ";", "}", "return", "root", ";", "}" ]
Main method called to generate the document fragment associated to a template for a given set of arguments This creates a new set of node instances from the node definitions passed in the ng constructor @param {Array} scopevars the list of the scope variables (actually the template arguments) - e.g. ["person",person] odd indexes correspond to argument values / even indexes correspond to argument names @param {Object} ctlWrapper the controller observer - if any @param {Map} ctlInitAtts the init value of the controller attributes (optional) - e.g. {value:'123',mandatory:true} @param {Object} rootscope the parent root scope object containing the reference to the global objects accessible from the template file scope
[ "Main", "method", "called", "to", "generate", "the", "document", "fragment", "associated", "to", "a", "template", "for", "a", "given", "set", "of", "arguments", "This", "creates", "a", "new", "set", "of", "node", "instances", "from", "the", "node", "definitions", "passed", "in", "the", "ng", "constructor" ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/rt.js#L49-L70
44,093
ariatemplates/hashspace
hsp/rt.js
getGlobalRef
function getGlobalRef(name) { var r=global[name]; if (r===undefined) { r=null; } return r; }
javascript
function getGlobalRef(name) { var r=global[name]; if (r===undefined) { r=null; } return r; }
[ "function", "getGlobalRef", "(", "name", ")", "{", "var", "r", "=", "global", "[", "name", "]", ";", "if", "(", "r", "===", "undefined", ")", "{", "r", "=", "null", ";", "}", "return", "r", ";", "}" ]
Return the global reference corresponding to a given name This function is used by template to retrieve global references that are first searched in the template module scope, then in the hashspace global object. Null is returned if no reference is found @param {String} name the name of the reference to look for @param {Object} obj the object found in the module scope
[ "Return", "the", "global", "reference", "corresponding", "to", "a", "given", "name", "This", "function", "is", "used", "by", "template", "to", "retrieve", "global", "references", "that", "are", "first", "searched", "in", "the", "template", "module", "scope", "then", "in", "the", "hashspace", "global", "object", ".", "Null", "is", "returned", "if", "no", "reference", "is", "found" ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/rt.js#L106-L112
44,094
ariatemplates/hashspace
hsp/compiler/jsgenerator/index.js
_validate
function _validate (code, lineMap) { var validationResult = jsv.validate(code); var result = {isValid: validationResult.isValid}; if (!validationResult.isValid) { // translate error line numbers var error, lineNumber; for (var i = 0; i < validationResult.errors.length; i++) { error = validationResult.errors[i]; lineNumber = error.line; error.line = -1; // to avoid sending a wrong line in case of pb for (var j = 0; j < lineMap.length; j++) { if (lineMap[j] === lineNumber) { error.line = j; // original line nbr break; } } } result.errors = validationResult.errors; } return result; }
javascript
function _validate (code, lineMap) { var validationResult = jsv.validate(code); var result = {isValid: validationResult.isValid}; if (!validationResult.isValid) { // translate error line numbers var error, lineNumber; for (var i = 0; i < validationResult.errors.length; i++) { error = validationResult.errors[i]; lineNumber = error.line; error.line = -1; // to avoid sending a wrong line in case of pb for (var j = 0; j < lineMap.length; j++) { if (lineMap[j] === lineNumber) { error.line = j; // original line nbr break; } } } result.errors = validationResult.errors; } return result; }
[ "function", "_validate", "(", "code", ",", "lineMap", ")", "{", "var", "validationResult", "=", "jsv", ".", "validate", "(", "code", ")", ";", "var", "result", "=", "{", "isValid", ":", "validationResult", ".", "isValid", "}", ";", "if", "(", "!", "validationResult", ".", "isValid", ")", "{", "// translate error line numbers", "var", "error", ",", "lineNumber", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "validationResult", ".", "errors", ".", "length", ";", "i", "++", ")", "{", "error", "=", "validationResult", ".", "errors", "[", "i", "]", ";", "lineNumber", "=", "error", ".", "line", ";", "error", ".", "line", "=", "-", "1", ";", "// to avoid sending a wrong line in case of pb", "for", "(", "var", "j", "=", "0", ";", "j", "<", "lineMap", ".", "length", ";", "j", "++", ")", "{", "if", "(", "lineMap", "[", "j", "]", "===", "lineNumber", ")", "{", "error", ".", "line", "=", "j", ";", "// original line nbr", "break", ";", "}", "}", "}", "result", ".", "errors", "=", "validationResult", ".", "errors", ";", "}", "return", "result", ";", "}" ]
Validates a javascript string using the jsvalidator module, and generates an error report if not valid. @param {String} code the javascript string. @param {Object} lineMap the line mapping between the source template and the compiled one @return {Object} a result map
[ "Validates", "a", "javascript", "string", "using", "the", "jsvalidator", "module", "and", "generates", "an", "error", "report", "if", "not", "valid", "." ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/compiler/jsgenerator/index.js#L102-L123
44,095
ariatemplates/hashspace
hsp/compiler/jsgenerator/index.js
_getErrorScript
function _getErrorScript (errors, fileName) { var result = ''; if (errors && errors.length) { var err=errors[0]; var ctxt={ type:"error", file:fileName, code:err.code, line:err.line, column:err.column }; var suberrors = err.suberrors; var suberrorsJsStr = ""; // varargs, should end up as sth like '"a", "b", "c"' if (suberrors && suberrors.length > 0) { var out = []; for (var k = 0; k < suberrors.length; k++) { out[k] = _toDoubleQuotedJsString(suberrors[k], '==> '); } suberrorsJsStr = out.join(', ') + ', '; } var descriptionJsStr = _toDoubleQuotedJsString(err.description); var metadata = JSON.stringify(ctxt, null); result = ['\r\nrequire("hsp/rt/log").error(', descriptionJsStr, ',', suberrorsJsStr, metadata ,');\r\n'].join(""); } return result; }
javascript
function _getErrorScript (errors, fileName) { var result = ''; if (errors && errors.length) { var err=errors[0]; var ctxt={ type:"error", file:fileName, code:err.code, line:err.line, column:err.column }; var suberrors = err.suberrors; var suberrorsJsStr = ""; // varargs, should end up as sth like '"a", "b", "c"' if (suberrors && suberrors.length > 0) { var out = []; for (var k = 0; k < suberrors.length; k++) { out[k] = _toDoubleQuotedJsString(suberrors[k], '==> '); } suberrorsJsStr = out.join(', ') + ', '; } var descriptionJsStr = _toDoubleQuotedJsString(err.description); var metadata = JSON.stringify(ctxt, null); result = ['\r\nrequire("hsp/rt/log").error(', descriptionJsStr, ',', suberrorsJsStr, metadata ,');\r\n'].join(""); } return result; }
[ "function", "_getErrorScript", "(", "errors", ",", "fileName", ")", "{", "var", "result", "=", "''", ";", "if", "(", "errors", "&&", "errors", ".", "length", ")", "{", "var", "err", "=", "errors", "[", "0", "]", ";", "var", "ctxt", "=", "{", "type", ":", "\"error\"", ",", "file", ":", "fileName", ",", "code", ":", "err", ".", "code", ",", "line", ":", "err", ".", "line", ",", "column", ":", "err", ".", "column", "}", ";", "var", "suberrors", "=", "err", ".", "suberrors", ";", "var", "suberrorsJsStr", "=", "\"\"", ";", "// varargs, should end up as sth like '\"a\", \"b\", \"c\"'", "if", "(", "suberrors", "&&", "suberrors", ".", "length", ">", "0", ")", "{", "var", "out", "=", "[", "]", ";", "for", "(", "var", "k", "=", "0", ";", "k", "<", "suberrors", ".", "length", ";", "k", "++", ")", "{", "out", "[", "k", "]", "=", "_toDoubleQuotedJsString", "(", "suberrors", "[", "k", "]", ",", "'==> '", ")", ";", "}", "suberrorsJsStr", "=", "out", ".", "join", "(", "', '", ")", "+", "', '", ";", "}", "var", "descriptionJsStr", "=", "_toDoubleQuotedJsString", "(", "err", ".", "description", ")", ";", "var", "metadata", "=", "JSON", ".", "stringify", "(", "ctxt", ",", "null", ")", ";", "result", "=", "[", "'\\r\\nrequire(\"hsp/rt/log\").error('", ",", "descriptionJsStr", ",", "','", ",", "suberrorsJsStr", ",", "metadata", ",", "');\\r\\n'", "]", ".", "join", "(", "\"\"", ")", ";", "}", "return", "result", ";", "}" ]
Generate an error script to include in the template compiled script in order to show errors in the browser when the script is loaded @param {Array} errors the errror list @param {String} fileName the name of the file being compiled @return {String} the javascript snippet to be included
[ "Generate", "an", "error", "script", "to", "include", "in", "the", "template", "compiled", "script", "in", "order", "to", "show", "errors", "in", "the", "browser", "when", "the", "script", "is", "loaded" ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/compiler/jsgenerator/index.js#L131-L156
44,096
ariatemplates/hashspace
hsp/compiler/jsgenerator/index.js
_generateLineMap
function _generateLineMap (res, file) { if (res.errors && res.errors.length) { return; } var syntaxTree = res.syntaxTree, templates = []; // identify the templates in the syntax tree for (var i = 0; i < syntaxTree.length; i++) { if (syntaxTree[i].type === 'template') { templates.push(syntaxTree[i]); } } var nbrOfLinesInCompiledTemplate = 5; //all generated templates got fixed no of LOC var lineMap = [], pos = HEADER_SZ, template; var pos1 = -1; // position of the next template start var pos2 = -1; // position of the next template end var tplIdx = -1; // position of the current template for (var i = 0; i < (file.split(/\n/g).length + 1); i++) { if (i === 0 || i === pos2) { // end of current template: let's determine next pos1 and pos2 tplIdx = (i === 0) ? 0 : tplIdx + 1; if (tplIdx < templates.length) { // there is another template template = templates[tplIdx]; pos1 = template.startLine; pos2 = Math.max(template.endLine, pos1); } else { // last template has been found tplIdx = pos1 = pos2 = -1; } if (i === 0) { lineMap[0] = 0; } i++; } if (i === pos1) { for (var j = pos1; j < (pos2 + 1); j++) { // all lines are set to the template start lineMap[i] = pos; i++; } pos += nbrOfLinesInCompiledTemplate; i -= 2; // to enter the i===pos2 clause at next step } else { lineMap[i] = pos; pos++; } } return lineMap; }
javascript
function _generateLineMap (res, file) { if (res.errors && res.errors.length) { return; } var syntaxTree = res.syntaxTree, templates = []; // identify the templates in the syntax tree for (var i = 0; i < syntaxTree.length; i++) { if (syntaxTree[i].type === 'template') { templates.push(syntaxTree[i]); } } var nbrOfLinesInCompiledTemplate = 5; //all generated templates got fixed no of LOC var lineMap = [], pos = HEADER_SZ, template; var pos1 = -1; // position of the next template start var pos2 = -1; // position of the next template end var tplIdx = -1; // position of the current template for (var i = 0; i < (file.split(/\n/g).length + 1); i++) { if (i === 0 || i === pos2) { // end of current template: let's determine next pos1 and pos2 tplIdx = (i === 0) ? 0 : tplIdx + 1; if (tplIdx < templates.length) { // there is another template template = templates[tplIdx]; pos1 = template.startLine; pos2 = Math.max(template.endLine, pos1); } else { // last template has been found tplIdx = pos1 = pos2 = -1; } if (i === 0) { lineMap[0] = 0; } i++; } if (i === pos1) { for (var j = pos1; j < (pos2 + 1); j++) { // all lines are set to the template start lineMap[i] = pos; i++; } pos += nbrOfLinesInCompiledTemplate; i -= 2; // to enter the i===pos2 clause at next step } else { lineMap[i] = pos; pos++; } } return lineMap; }
[ "function", "_generateLineMap", "(", "res", ",", "file", ")", "{", "if", "(", "res", ".", "errors", "&&", "res", ".", "errors", ".", "length", ")", "{", "return", ";", "}", "var", "syntaxTree", "=", "res", ".", "syntaxTree", ",", "templates", "=", "[", "]", ";", "// identify the templates in the syntax tree", "for", "(", "var", "i", "=", "0", ";", "i", "<", "syntaxTree", ".", "length", ";", "i", "++", ")", "{", "if", "(", "syntaxTree", "[", "i", "]", ".", "type", "===", "'template'", ")", "{", "templates", ".", "push", "(", "syntaxTree", "[", "i", "]", ")", ";", "}", "}", "var", "nbrOfLinesInCompiledTemplate", "=", "5", ";", "//all generated templates got fixed no of LOC", "var", "lineMap", "=", "[", "]", ",", "pos", "=", "HEADER_SZ", ",", "template", ";", "var", "pos1", "=", "-", "1", ";", "// position of the next template start", "var", "pos2", "=", "-", "1", ";", "// position of the next template end", "var", "tplIdx", "=", "-", "1", ";", "// position of the current template", "for", "(", "var", "i", "=", "0", ";", "i", "<", "(", "file", ".", "split", "(", "/", "\\n", "/", "g", ")", ".", "length", "+", "1", ")", ";", "i", "++", ")", "{", "if", "(", "i", "===", "0", "||", "i", "===", "pos2", ")", "{", "// end of current template: let's determine next pos1 and pos2", "tplIdx", "=", "(", "i", "===", "0", ")", "?", "0", ":", "tplIdx", "+", "1", ";", "if", "(", "tplIdx", "<", "templates", ".", "length", ")", "{", "// there is another template", "template", "=", "templates", "[", "tplIdx", "]", ";", "pos1", "=", "template", ".", "startLine", ";", "pos2", "=", "Math", ".", "max", "(", "template", ".", "endLine", ",", "pos1", ")", ";", "}", "else", "{", "// last template has been found", "tplIdx", "=", "pos1", "=", "pos2", "=", "-", "1", ";", "}", "if", "(", "i", "===", "0", ")", "{", "lineMap", "[", "0", "]", "=", "0", ";", "}", "i", "++", ";", "}", "if", "(", "i", "===", "pos1", ")", "{", "for", "(", "var", "j", "=", "pos1", ";", "j", "<", "(", "pos2", "+", "1", ")", ";", "j", "++", ")", "{", "// all lines are set to the template start", "lineMap", "[", "i", "]", "=", "pos", ";", "i", "++", ";", "}", "pos", "+=", "nbrOfLinesInCompiledTemplate", ";", "i", "-=", "2", ";", "// to enter the i===pos2 clause at next step", "}", "else", "{", "lineMap", "[", "i", "]", "=", "pos", ";", "pos", "++", ";", "}", "}", "return", "lineMap", ";", "}" ]
Generate the line map of a compilatin result @param {JSON} res the result object of a compilation - cf. compile function @param {String} file the template file (before compilation)
[ "Generate", "the", "line", "map", "of", "a", "compilatin", "result" ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/compiler/jsgenerator/index.js#L173-L223
44,097
ariatemplates/hashspace
hsp/propobserver.js
function () { json.unobserve(this.target, this.callback); this.props=null; this.callback=null; this.target=null; }
javascript
function () { json.unobserve(this.target, this.callback); this.props=null; this.callback=null; this.target=null; }
[ "function", "(", ")", "{", "json", ".", "unobserve", "(", "this", ".", "target", ",", "this", ".", "callback", ")", ";", "this", ".", "props", "=", "null", ";", "this", ".", "callback", "=", "null", ";", "this", ".", "target", "=", "null", ";", "}" ]
Safely delete all internal dependencies Must be called before deleting the object
[ "Safely", "delete", "all", "internal", "dependencies", "Must", "be", "called", "before", "deleting", "the", "object" ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/propobserver.js#L40-L45
44,098
ariatemplates/hashspace
hsp/propobserver.js
function (observer, property) { if (!property) property = ALL; var arr = this.props[property]; if (!arr) { // property is not observed yet arr = []; this.props[property] = arr; } arr.push(observer); }
javascript
function (observer, property) { if (!property) property = ALL; var arr = this.props[property]; if (!arr) { // property is not observed yet arr = []; this.props[property] = arr; } arr.push(observer); }
[ "function", "(", "observer", ",", "property", ")", "{", "if", "(", "!", "property", ")", "property", "=", "ALL", ";", "var", "arr", "=", "this", ".", "props", "[", "property", "]", ";", "if", "(", "!", "arr", ")", "{", "// property is not observed yet", "arr", "=", "[", "]", ";", "this", ".", "props", "[", "property", "]", "=", "arr", ";", "}", "arr", ".", "push", "(", "observer", ")", ";", "}" ]
Add a new observer for a given property @param {object} observer object with a onPropChange() method @param {string} property the property name to observe (optional)
[ "Add", "a", "new", "observer", "for", "a", "given", "property" ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/propobserver.js#L51-L61
44,099
ariatemplates/hashspace
hsp/propobserver.js
PropObserver_notifyChanges
function PropObserver_notifyChanges (chglist) { var c; for (var i = 0, sz = chglist.length; sz > i; i++) { c = chglist[i]; if (!c) continue; // check if we listen to this property if (this.props[c.name]) { PropObserver_notifyChange(this, c, c.name); } } if (this.props[ALL]) { PropObserver_notifyChange(this, c, ALL); } }
javascript
function PropObserver_notifyChanges (chglist) { var c; for (var i = 0, sz = chglist.length; sz > i; i++) { c = chglist[i]; if (!c) continue; // check if we listen to this property if (this.props[c.name]) { PropObserver_notifyChange(this, c, c.name); } } if (this.props[ALL]) { PropObserver_notifyChange(this, c, ALL); } }
[ "function", "PropObserver_notifyChanges", "(", "chglist", ")", "{", "var", "c", ";", "for", "(", "var", "i", "=", "0", ",", "sz", "=", "chglist", ".", "length", ";", "sz", ">", "i", ";", "i", "++", ")", "{", "c", "=", "chglist", "[", "i", "]", ";", "if", "(", "!", "c", ")", "continue", ";", "// check if we listen to this property", "if", "(", "this", ".", "props", "[", "c", ".", "name", "]", ")", "{", "PropObserver_notifyChange", "(", "this", ",", "c", ",", "c", ".", "name", ")", ";", "}", "}", "if", "(", "this", ".", "props", "[", "ALL", "]", ")", "{", "PropObserver_notifyChange", "(", "this", ",", "c", ",", "ALL", ")", ";", "}", "}" ]
Notify the change to the registered observers i.e. call their onPropChange method with the change description as parameter @private
[ "Notify", "the", "change", "to", "the", "registered", "observers", "i", ".", "e", ".", "call", "their", "onPropChange", "method", "with", "the", "change", "description", "as", "parameter" ]
24cb510288566eba0e33ff55949adb54c0a89fac
https://github.com/ariatemplates/hashspace/blob/24cb510288566eba0e33ff55949adb54c0a89fac/hsp/propobserver.js#L91-L105