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
sequence | docstring
stringlengths 4
11.8k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 86
226
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
Rekord/rekord | build/rekord.js | function(properties)
{
if ( !isValue( properties ) )
{
return this.length;
}
var resolver = createPropertyResolver( properties );
var result = 0;
for (var i = 0; i < this.length; i++)
{
var resolved = resolver( this[ i ] );
if ( isValue( resolved ) )
{
result++;
}
}
return result;
} | javascript | function(properties)
{
if ( !isValue( properties ) )
{
return this.length;
}
var resolver = createPropertyResolver( properties );
var result = 0;
for (var i = 0; i < this.length; i++)
{
var resolved = resolver( this[ i ] );
if ( isValue( resolved ) )
{
result++;
}
}
return result;
} | [
"function",
"(",
"properties",
")",
"{",
"if",
"(",
"!",
"isValue",
"(",
"properties",
")",
")",
"{",
"return",
"this",
".",
"length",
";",
"}",
"var",
"resolver",
"=",
"createPropertyResolver",
"(",
"properties",
")",
";",
"var",
"result",
"=",
"0",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"resolved",
"=",
"resolver",
"(",
"this",
"[",
"i",
"]",
")",
";",
"if",
"(",
"isValue",
"(",
"resolved",
")",
")",
"{",
"result",
"++",
";",
"}",
"}",
"return",
"result",
";",
"}"
] | Counts the number of elements in this collection that has a value for the
given property expression.
```javascript
var c = Rekord.collect([{age: 2}, {age: 3}, {taco: 4}]);
c.count('age'); // 2
c.count('taco'); // 1
c.count(); // 3
```
@method
@memberof Rekord.Collection#
@param {propertyResolverInput} [properties] -
The expression which converts one value into another.
@return {Number} -
The number of elements that had values for the property expression.
@see Rekord.createPropertyResolver
@see Rekord.isValue | [
"Counts",
"the",
"number",
"of",
"elements",
"in",
"this",
"collection",
"that",
"has",
"a",
"value",
"for",
"the",
"given",
"property",
"expression",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L9012-L9033 | train |
|
Rekord/rekord | build/rekord.js | function(values, keys)
{
var valuesResolver = createPropertyResolver( values );
if ( keys )
{
var keysResolver = createPropertyResolver( keys );
var result = {};
for (var i = 0; i < this.length; i++)
{
var model = this[ i ];
var value = valuesResolver( model );
var key = keysResolver( model );
result[ key ] = value;
}
return result;
}
else
{
var result = [];
for (var i = 0; i < this.length; i++)
{
var model = this[ i ];
var value = valuesResolver( model );
result.push( value );
}
return result;
}
} | javascript | function(values, keys)
{
var valuesResolver = createPropertyResolver( values );
if ( keys )
{
var keysResolver = createPropertyResolver( keys );
var result = {};
for (var i = 0; i < this.length; i++)
{
var model = this[ i ];
var value = valuesResolver( model );
var key = keysResolver( model );
result[ key ] = value;
}
return result;
}
else
{
var result = [];
for (var i = 0; i < this.length; i++)
{
var model = this[ i ];
var value = valuesResolver( model );
result.push( value );
}
return result;
}
} | [
"function",
"(",
"values",
",",
"keys",
")",
"{",
"var",
"valuesResolver",
"=",
"createPropertyResolver",
"(",
"values",
")",
";",
"if",
"(",
"keys",
")",
"{",
"var",
"keysResolver",
"=",
"createPropertyResolver",
"(",
"keys",
")",
";",
"var",
"result",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"model",
"=",
"this",
"[",
"i",
"]",
";",
"var",
"value",
"=",
"valuesResolver",
"(",
"model",
")",
";",
"var",
"key",
"=",
"keysResolver",
"(",
"model",
")",
";",
"result",
"[",
"key",
"]",
"=",
"value",
";",
"}",
"return",
"result",
";",
"}",
"else",
"{",
"var",
"result",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"model",
"=",
"this",
"[",
"i",
"]",
";",
"var",
"value",
"=",
"valuesResolver",
"(",
"model",
")",
";",
"result",
".",
"push",
"(",
"value",
")",
";",
"}",
"return",
"result",
";",
"}",
"}"
] | Plucks values from elements in the collection. If only a `values` property
expression is given the result will be an array of resolved values. If the
`keys` property expression is given, the result will be an object where the
property of the object is determined by the key expression.
```javascript
var c = Rekord.collect([{age: 2, nm: 'T'}, {age: 4, nm: 'R'}, {age: 5, nm: 'G'}]);
c.pluck(); // c
c.pluck('age'); // [2, 4, 5]
c.pluck('age', 'nm'); // {T: e, R: 4, G: 5}
c.pluck(null, 'nm'); // {T: {age: 2, nm: 'T'}, R: {age: 4, nm: 'R'}, G: {age: 5, nm: 'G'}}
c.pluck('{age}-{nm}'); // ['2-T', '4-R', '5-G']
```
@method
@memberof Rekord.Collection#
@param {propertyResolverInput} [values] -
The expression which converts an element into a value to pluck.
@param {propertyResolverInput} [keys] -
The expression which converts an element into an object property (key).
@return {Array|Object} -
The plucked values.
@see Rekord.createPropertyResolver | [
"Plucks",
"values",
"from",
"elements",
"in",
"the",
"collection",
".",
"If",
"only",
"a",
"values",
"property",
"expression",
"is",
"given",
"the",
"result",
"will",
"be",
"an",
"array",
"of",
"resolved",
"values",
".",
"If",
"the",
"keys",
"property",
"expression",
"is",
"given",
"the",
"result",
"will",
"be",
"an",
"object",
"where",
"the",
"property",
"of",
"the",
"object",
"is",
"determined",
"by",
"the",
"key",
"expression",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L9060-L9094 | train |
|
Rekord/rekord | build/rekord.js | function(callback, context)
{
var callbackContext = context || this;
for (var i = 0; i < this.length; i++)
{
var item = this[ i ];
callback.call( callbackContext, item, i );
if ( this[ i ] !== item )
{
i--;
}
}
return this;
} | javascript | function(callback, context)
{
var callbackContext = context || this;
for (var i = 0; i < this.length; i++)
{
var item = this[ i ];
callback.call( callbackContext, item, i );
if ( this[ i ] !== item )
{
i--;
}
}
return this;
} | [
"function",
"(",
"callback",
",",
"context",
")",
"{",
"var",
"callbackContext",
"=",
"context",
"||",
"this",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"item",
"=",
"this",
"[",
"i",
"]",
";",
"callback",
".",
"call",
"(",
"callbackContext",
",",
"item",
",",
"i",
")",
";",
"if",
"(",
"this",
"[",
"i",
"]",
"!==",
"item",
")",
"{",
"i",
"--",
";",
"}",
"}",
"return",
"this",
";",
"}"
] | Iterates over each element in this collection and passes the element and
it's index to the given function. An optional function context can be given.
@method
@memberof Rekord.Collection#
@param {Function} callback -
The function to invoke for each element of this collection passing the
element and the index where it exists.
@param {Object} [context] -
The context to the callback function.
@return {Rekord.Collection} -
The reference to this collection. | [
"Iterates",
"over",
"each",
"element",
"in",
"this",
"collection",
"and",
"passes",
"the",
"element",
"and",
"it",
"s",
"index",
"to",
"the",
"given",
"function",
".",
"An",
"optional",
"function",
"context",
"can",
"be",
"given",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L9110-L9127 | train |
|
Rekord/rekord | build/rekord.js | function(callback, properties, values, equals)
{
var where = createWhere( properties, values, equals );
for (var i = 0; i < this.length; i++)
{
var item = this[ i ];
if ( where( item ) )
{
callback.call( this, item, i );
if ( this[ i ] !== item )
{
i--;
}
}
}
return this;
} | javascript | function(callback, properties, values, equals)
{
var where = createWhere( properties, values, equals );
for (var i = 0; i < this.length; i++)
{
var item = this[ i ];
if ( where( item ) )
{
callback.call( this, item, i );
if ( this[ i ] !== item )
{
i--;
}
}
}
return this;
} | [
"function",
"(",
"callback",
",",
"properties",
",",
"values",
",",
"equals",
")",
"{",
"var",
"where",
"=",
"createWhere",
"(",
"properties",
",",
"values",
",",
"equals",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"item",
"=",
"this",
"[",
"i",
"]",
";",
"if",
"(",
"where",
"(",
"item",
")",
")",
"{",
"callback",
".",
"call",
"(",
"this",
",",
"item",
",",
"i",
")",
";",
"if",
"(",
"this",
"[",
"i",
"]",
"!==",
"item",
")",
"{",
"i",
"--",
";",
"}",
"}",
"}",
"return",
"this",
";",
"}"
] | Iterates over each element in this collection that matches the where
expression and passes the element and it's index to the given function.
@method
@memberof Rekord.Collection#
@param {Function} callback -
The function to invoke for each element of this collection passing the
element and the index where it exists.
@param {whereInput} [properties] -
See {@link Rekord.createWhere}
@param {Any} [value] -
See {@link Rekord.createWhere}
@param {equalityCallback} [equals=Rekord.equalsStrict] -
See {@link Rekord.createWhere}
@return {Rekord.Collection} -
The reference to this collection.
@see Rekord.createWhere | [
"Iterates",
"over",
"each",
"element",
"in",
"this",
"collection",
"that",
"matches",
"the",
"where",
"expression",
"and",
"passes",
"the",
"element",
"and",
"it",
"s",
"index",
"to",
"the",
"given",
"function",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L9148-L9168 | train |
|
Rekord/rekord | build/rekord.js | function(reducer, initialValue)
{
for (var i = 0; i < this.length; i++)
{
initialValue = reducer( initialValue, this[ i ] );
}
return initialValue;
} | javascript | function(reducer, initialValue)
{
for (var i = 0; i < this.length; i++)
{
initialValue = reducer( initialValue, this[ i ] );
}
return initialValue;
} | [
"function",
"(",
"reducer",
",",
"initialValue",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"length",
";",
"i",
"++",
")",
"{",
"initialValue",
"=",
"reducer",
"(",
"initialValue",
",",
"this",
"[",
"i",
"]",
")",
";",
"}",
"return",
"initialValue",
";",
"}"
] | Reduces all the elements of this collection to a single value. All elements
are passed to a function which accepts the currently reduced value and the
current element and returns the new reduced value.
```javascript
var reduceIt = function(curr, elem) {
return curr + ( elem[0] * elem[1] );
};
var c = Rekord.collect([[2, 1], [3, 2], [5, 6]]);
c.reduce( reduceIt, 0 ); // 38
```
@method
@memberof Rekord.Collection#
@param {Function} reducer -
A function which accepts the current reduced value and an element and
returns the new reduced value.
@param {Any} [initialValue] -
The first value to pass to the reducer function.
@return {Any} -
The reduced value. | [
"Reduces",
"all",
"the",
"elements",
"of",
"this",
"collection",
"to",
"a",
"single",
"value",
".",
"All",
"elements",
"are",
"passed",
"to",
"a",
"function",
"which",
"accepts",
"the",
"currently",
"reduced",
"value",
"and",
"the",
"current",
"element",
"and",
"returns",
"the",
"new",
"reduced",
"value",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L9193-L9201 | train |
|
Rekord/rekord | build/rekord.js | function(properties, value, equals)
{
var where = createWhere( properties, value, equals );
for (var i = 0; i < this.length; i++)
{
var model = this[ i ];
if ( where( model ) )
{
return true;
}
}
return false;
} | javascript | function(properties, value, equals)
{
var where = createWhere( properties, value, equals );
for (var i = 0; i < this.length; i++)
{
var model = this[ i ];
if ( where( model ) )
{
return true;
}
}
return false;
} | [
"function",
"(",
"properties",
",",
"value",
",",
"equals",
")",
"{",
"var",
"where",
"=",
"createWhere",
"(",
"properties",
",",
"value",
",",
"equals",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"model",
"=",
"this",
"[",
"i",
"]",
";",
"if",
"(",
"where",
"(",
"model",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Determines whether at least one element in this collection matches the
given criteria.
```javascript
var c = Rekord.collect([{age: 2}, {age: 6}]);
c.contains('age', 2); // true
c.contains('age', 3); // false
c.contains('age'); // true
c.contains('name'); // false
```
@method
@memberof Rekord.Collection#
@param {whereInput} [properties] -
The expression used to create a function to test the elements in this
collection.
@param {Any} [value] -
When the first argument is a string this argument will be treated as a
value to compare to the value of the named property on the object passed
through the filter function.
@param {equalityCallback} [equals=Rekord.equalsStrict] -
An alternative function can be used to compare to values.
@return {Boolean} -
True if any of the elements passed the test function, otherwise false.
@see Rekord.createWhere | [
"Determines",
"whether",
"at",
"least",
"one",
"element",
"in",
"this",
"collection",
"matches",
"the",
"given",
"criteria",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L9294-L9309 | train |
|
Rekord/rekord | build/rekord.js | function(grouping)
{
var by = createPropertyResolver( grouping.by );
var having = createWhere( grouping.having, grouping.havingValue, grouping.havingEquals );
var select = grouping.select || {};
var map = {};
if ( isString( grouping.by ) )
{
if ( !(grouping.by in select) )
{
select[ grouping.by ] = 'first';
}
}
else if ( isArray( grouping.by ) )
{
for (var prop in grouping.by)
{
if ( !(prop in select) )
{
select[ prop ] = 'first';
}
}
}
for (var i = 0; i < this.length; i++)
{
var model = this[ i ];
var key = by( model );
var group = map[ key ];
if ( !group )
{
group = map[ key ] = this.cloneEmpty();
}
group.add( model, true );
}
var groupings = this.cloneEmpty();
groupings.setComparator( grouping.comparator, grouping.comparatorNullsFirst );
for (var key in map)
{
var grouped = {};
var groupArray = map[ key ];
for (var propName in select)
{
var aggregator = select[ propName ];
if ( isString( aggregator ) )
{
grouped[ propName ] = groupArray[ aggregator ]( propName );
}
else if ( isFunction( aggregator ) )
{
grouped[ propName ] = aggregator( groupArray, propName );
}
}
if ( grouping.track !== false )
{
grouped.$group = groupArray;
}
if ( grouping.count !== false )
{
grouped.$count = groupArray.length;
}
if ( having( grouped, groupArray ) )
{
groupings.push( grouped );
}
}
groupings.sort();
return groupings;
} | javascript | function(grouping)
{
var by = createPropertyResolver( grouping.by );
var having = createWhere( grouping.having, grouping.havingValue, grouping.havingEquals );
var select = grouping.select || {};
var map = {};
if ( isString( grouping.by ) )
{
if ( !(grouping.by in select) )
{
select[ grouping.by ] = 'first';
}
}
else if ( isArray( grouping.by ) )
{
for (var prop in grouping.by)
{
if ( !(prop in select) )
{
select[ prop ] = 'first';
}
}
}
for (var i = 0; i < this.length; i++)
{
var model = this[ i ];
var key = by( model );
var group = map[ key ];
if ( !group )
{
group = map[ key ] = this.cloneEmpty();
}
group.add( model, true );
}
var groupings = this.cloneEmpty();
groupings.setComparator( grouping.comparator, grouping.comparatorNullsFirst );
for (var key in map)
{
var grouped = {};
var groupArray = map[ key ];
for (var propName in select)
{
var aggregator = select[ propName ];
if ( isString( aggregator ) )
{
grouped[ propName ] = groupArray[ aggregator ]( propName );
}
else if ( isFunction( aggregator ) )
{
grouped[ propName ] = aggregator( groupArray, propName );
}
}
if ( grouping.track !== false )
{
grouped.$group = groupArray;
}
if ( grouping.count !== false )
{
grouped.$count = groupArray.length;
}
if ( having( grouped, groupArray ) )
{
groupings.push( grouped );
}
}
groupings.sort();
return groupings;
} | [
"function",
"(",
"grouping",
")",
"{",
"var",
"by",
"=",
"createPropertyResolver",
"(",
"grouping",
".",
"by",
")",
";",
"var",
"having",
"=",
"createWhere",
"(",
"grouping",
".",
"having",
",",
"grouping",
".",
"havingValue",
",",
"grouping",
".",
"havingEquals",
")",
";",
"var",
"select",
"=",
"grouping",
".",
"select",
"||",
"{",
"}",
";",
"var",
"map",
"=",
"{",
"}",
";",
"if",
"(",
"isString",
"(",
"grouping",
".",
"by",
")",
")",
"{",
"if",
"(",
"!",
"(",
"grouping",
".",
"by",
"in",
"select",
")",
")",
"{",
"select",
"[",
"grouping",
".",
"by",
"]",
"=",
"'first'",
";",
"}",
"}",
"else",
"if",
"(",
"isArray",
"(",
"grouping",
".",
"by",
")",
")",
"{",
"for",
"(",
"var",
"prop",
"in",
"grouping",
".",
"by",
")",
"{",
"if",
"(",
"!",
"(",
"prop",
"in",
"select",
")",
")",
"{",
"select",
"[",
"prop",
"]",
"=",
"'first'",
";",
"}",
"}",
"}",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"model",
"=",
"this",
"[",
"i",
"]",
";",
"var",
"key",
"=",
"by",
"(",
"model",
")",
";",
"var",
"group",
"=",
"map",
"[",
"key",
"]",
";",
"if",
"(",
"!",
"group",
")",
"{",
"group",
"=",
"map",
"[",
"key",
"]",
"=",
"this",
".",
"cloneEmpty",
"(",
")",
";",
"}",
"group",
".",
"add",
"(",
"model",
",",
"true",
")",
";",
"}",
"var",
"groupings",
"=",
"this",
".",
"cloneEmpty",
"(",
")",
";",
"groupings",
".",
"setComparator",
"(",
"grouping",
".",
"comparator",
",",
"grouping",
".",
"comparatorNullsFirst",
")",
";",
"for",
"(",
"var",
"key",
"in",
"map",
")",
"{",
"var",
"grouped",
"=",
"{",
"}",
";",
"var",
"groupArray",
"=",
"map",
"[",
"key",
"]",
";",
"for",
"(",
"var",
"propName",
"in",
"select",
")",
"{",
"var",
"aggregator",
"=",
"select",
"[",
"propName",
"]",
";",
"if",
"(",
"isString",
"(",
"aggregator",
")",
")",
"{",
"grouped",
"[",
"propName",
"]",
"=",
"groupArray",
"[",
"aggregator",
"]",
"(",
"propName",
")",
";",
"}",
"else",
"if",
"(",
"isFunction",
"(",
"aggregator",
")",
")",
"{",
"grouped",
"[",
"propName",
"]",
"=",
"aggregator",
"(",
"groupArray",
",",
"propName",
")",
";",
"}",
"}",
"if",
"(",
"grouping",
".",
"track",
"!==",
"false",
")",
"{",
"grouped",
".",
"$group",
"=",
"groupArray",
";",
"}",
"if",
"(",
"grouping",
".",
"count",
"!==",
"false",
")",
"{",
"grouped",
".",
"$count",
"=",
"groupArray",
".",
"length",
";",
"}",
"if",
"(",
"having",
"(",
"grouped",
",",
"groupArray",
")",
")",
"{",
"groupings",
".",
"push",
"(",
"grouped",
")",
";",
"}",
"}",
"groupings",
".",
"sort",
"(",
")",
";",
"return",
"groupings",
";",
"}"
] | Groups the elements into sub collections given some property expression to
use as the value to group by.
```javascript
var c = Rekord.collect([
{ name: 'Tom', age: 6, group: 'X' },
{ name: 'Jon', age: 7, group: 'X' },
{ name: 'Rob', age: 8, group: 'X' },
{ name: 'Bon', age: 9, group: 'Y' },
{ name: 'Ran', age: 10, group: 'Y' },
{ name: 'Man', age: 11, group: 'Y' },
{ name: 'Tac', age: 12, group: 'Z' }
]);
c.group({by: 'group'});
// [{group: 'X', $count: 3, $group: [...]},
// {group: 'Y', $count: 3, $group: [...]},
// {group: 'Z', $count: 1, $group: [.]}]
c.group({by: 'group', select: {age: 'avg', name: 'first'}});
// [{group: 'X', age: 7, name: 'Tom', $count: 3, $group: [...]},
// {group: 'Y', age: 9, name: 'Bon', $count: 3, $group: [...]},
// {group: 'Z', age: 12, name: 'Tac', $count: 1, $group: [.]}]
c.group({by: 'group', track: false, count: false});
// [{group: 'X'}, {group: 'Y'}, {group: 'Z'}]
var havingMoreThanOne = function(grouping, groupElements) {
return groupElements.length > 0;
};
c.group({by: 'group', select: {age: 'avg'}, comparator: '-age', having: havingMoreThanOne, track: false, count: false});
// [{group: 'Y', age: 9},
// {group: 'X', age: 7}]
```
@method
@memberof Rekord.Collection#
@param {Object} grouping -
An object specifying how elements in this collection are to be grouped
and what properties from the elements should be aggregated in the
resulting groupings.
- `by`: A property expression that resolves how elements will be grouped.
- `select`: An object which contains properties that should be aggregated where the value is the aggregate collection function to call (sum, avg, count, first, last, etc).
- `having`: A having expression which takes a grouping and the grouped elements and determines whether the grouping should be in the final result.
- `comparator`: A comparator for sorting the resulting collection of groupings.
- `comparatorNullsFirst`: Whether nulls should be sorted to the top.
- `track`: Whether all elements in the group should exist in a collection in the `$group` property of each grouping.
- `count`: Whether the number of elements in the group should be placed in the `$count` property of each grouping.
@return {Rekord.Collection} -
A collection of groupings. | [
"Groups",
"the",
"elements",
"into",
"sub",
"collections",
"given",
"some",
"property",
"expression",
"to",
"use",
"as",
"the",
"value",
"to",
"group",
"by",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L9363-L9444 | train |
|
Rekord/rekord | build/rekord.js | function(database, models, remoteData)
{
Class.props(this, {
database: database,
map: new Map()
});
this.map.values = this;
this.reset( models, remoteData );
return this;
} | javascript | function(database, models, remoteData)
{
Class.props(this, {
database: database,
map: new Map()
});
this.map.values = this;
this.reset( models, remoteData );
return this;
} | [
"function",
"(",
"database",
",",
"models",
",",
"remoteData",
")",
"{",
"Class",
".",
"props",
"(",
"this",
",",
"{",
"database",
":",
"database",
",",
"map",
":",
"new",
"Map",
"(",
")",
"}",
")",
";",
"this",
".",
"map",
".",
"values",
"=",
"this",
";",
"this",
".",
"reset",
"(",
"models",
",",
"remoteData",
")",
";",
"return",
"this",
";",
"}"
] | Initializes the model collection by setting the database, the initial set
of models, and whether the initial set of models is from a remote source.
@method
@memberof Rekord.ModelCollection#
@param {Rekord.Database} database -
The database for the models in this collection.
@param {modelInput[]} [models] -
The initial array of models in this collection.
@param {Boolean} [remoteData=false] -
If the models array is from a remote source. Remote sources place the
model directly into the database while local sources aren't stored in the
database until they're saved.
@return {Rekord.ModelCollection} -
The reference to this collection.
@emits Rekord.ModelCollection#reset | [
"Initializes",
"the",
"model",
"collection",
"by",
"setting",
"the",
"database",
"the",
"initial",
"set",
"of",
"models",
"and",
"whether",
"the",
"initial",
"set",
"of",
"models",
"is",
"from",
"a",
"remote",
"source",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L10088-L10099 | train |
|
Rekord/rekord | build/rekord.js | function(models, remoteData)
{
var map = this.map;
map.reset();
if ( isArray( models ) )
{
for (var i = 0; i < models.length; i++)
{
var model = models[ i ];
var parsed = this.parseModel( model, remoteData );
if ( parsed )
{
map.put( parsed.$key(), parsed );
}
}
}
else if ( isObject( models ) )
{
var parsed = this.parseModel( models, remoteData );
if ( parsed )
{
map.put( parsed.$key(), parsed );
}
}
this.trigger( Collection.Events.Reset, [this] );
this.sort();
return this;
} | javascript | function(models, remoteData)
{
var map = this.map;
map.reset();
if ( isArray( models ) )
{
for (var i = 0; i < models.length; i++)
{
var model = models[ i ];
var parsed = this.parseModel( model, remoteData );
if ( parsed )
{
map.put( parsed.$key(), parsed );
}
}
}
else if ( isObject( models ) )
{
var parsed = this.parseModel( models, remoteData );
if ( parsed )
{
map.put( parsed.$key(), parsed );
}
}
this.trigger( Collection.Events.Reset, [this] );
this.sort();
return this;
} | [
"function",
"(",
"models",
",",
"remoteData",
")",
"{",
"var",
"map",
"=",
"this",
".",
"map",
";",
"map",
".",
"reset",
"(",
")",
";",
"if",
"(",
"isArray",
"(",
"models",
")",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"models",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"model",
"=",
"models",
"[",
"i",
"]",
";",
"var",
"parsed",
"=",
"this",
".",
"parseModel",
"(",
"model",
",",
"remoteData",
")",
";",
"if",
"(",
"parsed",
")",
"{",
"map",
".",
"put",
"(",
"parsed",
".",
"$key",
"(",
")",
",",
"parsed",
")",
";",
"}",
"}",
"}",
"else",
"if",
"(",
"isObject",
"(",
"models",
")",
")",
"{",
"var",
"parsed",
"=",
"this",
".",
"parseModel",
"(",
"models",
",",
"remoteData",
")",
";",
"if",
"(",
"parsed",
")",
"{",
"map",
".",
"put",
"(",
"parsed",
".",
"$key",
"(",
")",
",",
"parsed",
")",
";",
"}",
"}",
"this",
".",
"trigger",
"(",
"Collection",
".",
"Events",
".",
"Reset",
",",
"[",
"this",
"]",
")",
";",
"this",
".",
"sort",
"(",
")",
";",
"return",
"this",
";",
"}"
] | Resets the models in this collection with a new collection of models.
@method
@memberof Rekord.ModelCollection#
@param {modelInput[]} [models] -
The initial array of models in this collection.
@param {Boolean} [remoteData=false] -
If the models array is from a remote source. Remote sources place the
model directly into the database while local sources aren't stored in the
database until they're saved.
@return {Rekord.ModelCollection} -
The reference to this collection.
@see Rekord.ModelCollection#parseModel
@emits Rekord.ModelCollection#reset | [
"Resets",
"the",
"models",
"in",
"this",
"collection",
"with",
"a",
"new",
"collection",
"of",
"models",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L10290-L10323 | train |
|
Rekord/rekord | build/rekord.js | function(key, model, delaySort)
{
this.map.put( key, model );
this.trigger( Collection.Events.Add, [this, model, this.map.indices[ key ]] );
if ( !delaySort )
{
this.sort();
}
} | javascript | function(key, model, delaySort)
{
this.map.put( key, model );
this.trigger( Collection.Events.Add, [this, model, this.map.indices[ key ]] );
if ( !delaySort )
{
this.sort();
}
} | [
"function",
"(",
"key",
",",
"model",
",",
"delaySort",
")",
"{",
"this",
".",
"map",
".",
"put",
"(",
"key",
",",
"model",
")",
";",
"this",
".",
"trigger",
"(",
"Collection",
".",
"Events",
".",
"Add",
",",
"[",
"this",
",",
"model",
",",
"this",
".",
"map",
".",
"indices",
"[",
"key",
"]",
"]",
")",
";",
"if",
"(",
"!",
"delaySort",
")",
"{",
"this",
".",
"sort",
"(",
")",
";",
"}",
"}"
] | Places a model in this collection providing a key to use.
@method
@memberof Rekord.ModelCollection#
@param {modelKey} key -
The key of the model.
@param {Rekord.Model} model -
The model instance to place in the collection.
@param {Boolean} [delaySort=false] -
Whether automatic sorting should be delayed until the user manually
calls {@link Rekord.ModelCollection#sort sort}.
@return {Rekord.ModelCollection} -
The reference to this collection.
@emits Rekord.ModelCollection#add
@emits Rekord.ModelCollection#sort | [
"Places",
"a",
"model",
"in",
"this",
"collection",
"providing",
"a",
"key",
"to",
"use",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L10374-L10383 | train |
|
Rekord/rekord | build/rekord.js | function(input, delaySort, remoteData)
{
var model = this.parseModel( input, remoteData );
var key = model.$key();
this.map.put( key, model );
this.trigger( Collection.Events.Add, [this, model, this.map.indices[ key ]] );
if ( !delaySort )
{
this.sort();
}
return this;
} | javascript | function(input, delaySort, remoteData)
{
var model = this.parseModel( input, remoteData );
var key = model.$key();
this.map.put( key, model );
this.trigger( Collection.Events.Add, [this, model, this.map.indices[ key ]] );
if ( !delaySort )
{
this.sort();
}
return this;
} | [
"function",
"(",
"input",
",",
"delaySort",
",",
"remoteData",
")",
"{",
"var",
"model",
"=",
"this",
".",
"parseModel",
"(",
"input",
",",
"remoteData",
")",
";",
"var",
"key",
"=",
"model",
".",
"$key",
"(",
")",
";",
"this",
".",
"map",
".",
"put",
"(",
"key",
",",
"model",
")",
";",
"this",
".",
"trigger",
"(",
"Collection",
".",
"Events",
".",
"Add",
",",
"[",
"this",
",",
"model",
",",
"this",
".",
"map",
".",
"indices",
"[",
"key",
"]",
"]",
")",
";",
"if",
"(",
"!",
"delaySort",
")",
"{",
"this",
".",
"sort",
"(",
")",
";",
"}",
"return",
"this",
";",
"}"
] | Adds a model to this collection - sorting the collection if a comparator
is set on this collection and `delaySort` is not a specified or a true
value.
@method
@memberof Rekord.ModelCollection#
@param {modelInput} input -
The model to add to this collection.
@param {Boolean} [delaySort=false] -
Whether automatic sorting should be delayed until the user manually
calls {@link Rekord.ModelCollection#sort sort}.
@param {Boolean} [remoteData=false] -
If the model is from a remote source. Remote sources place the model
directly into the database while local sources aren't stored in the
database until they're saved.
@return {Rekord.ModelCollection} -
The reference to this collection.
@emits Rekord.ModelCollection#add
@emits Rekord.ModelCollection#sort | [
"Adds",
"a",
"model",
"to",
"this",
"collection",
"-",
"sorting",
"the",
"collection",
"if",
"a",
"comparator",
"is",
"set",
"on",
"this",
"collection",
"and",
"delaySort",
"is",
"not",
"a",
"specified",
"or",
"a",
"true",
"value",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L10406-L10420 | train |
|
Rekord/rekord | build/rekord.js | function()
{
var values = AP.slice.apply( arguments );
var indices = [];
for (var i = 0; i < values.length; i++)
{
var model = this.parseModel( values[ i ] );
var key = model.$key();
this.map.put( key, model );
indices.push( this.map.indices[ key ] );
}
this.trigger( Collection.Events.Adds, [this, values, indices] );
this.sort();
return this.length;
} | javascript | function()
{
var values = AP.slice.apply( arguments );
var indices = [];
for (var i = 0; i < values.length; i++)
{
var model = this.parseModel( values[ i ] );
var key = model.$key();
this.map.put( key, model );
indices.push( this.map.indices[ key ] );
}
this.trigger( Collection.Events.Adds, [this, values, indices] );
this.sort();
return this.length;
} | [
"function",
"(",
")",
"{",
"var",
"values",
"=",
"AP",
".",
"slice",
".",
"apply",
"(",
"arguments",
")",
";",
"var",
"indices",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"values",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"model",
"=",
"this",
".",
"parseModel",
"(",
"values",
"[",
"i",
"]",
")",
";",
"var",
"key",
"=",
"model",
".",
"$key",
"(",
")",
";",
"this",
".",
"map",
".",
"put",
"(",
"key",
",",
"model",
")",
";",
"indices",
".",
"push",
"(",
"this",
".",
"map",
".",
"indices",
"[",
"key",
"]",
")",
";",
"}",
"this",
".",
"trigger",
"(",
"Collection",
".",
"Events",
".",
"Adds",
",",
"[",
"this",
",",
"values",
",",
"indices",
"]",
")",
";",
"this",
".",
"sort",
"(",
")",
";",
"return",
"this",
".",
"length",
";",
"}"
] | Adds one or more models to the end of this collection - sorting the
collection if a comparator is set on this collection.
@method
@memberof Rekord.ModelCollection#
@param {...modelInput} value -
The models to add to this collection.
@return {Number} -
The new length of this collection.
@emits Rekord.ModelCollection#add
@emits Rekord.ModelCollection#sort | [
"Adds",
"one",
"or",
"more",
"models",
"to",
"the",
"end",
"of",
"this",
"collection",
"-",
"sorting",
"the",
"collection",
"if",
"a",
"comparator",
"is",
"set",
"on",
"this",
"collection",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L10435-L10453 | train |
|
Rekord/rekord | build/rekord.js | function(models, delaySort, remoteData)
{
if ( isArray( models ) )
{
var indices = [];
for (var i = 0; i < models.length; i++)
{
var model = this.parseModel( models[ i ], remoteData );
var key = model.$key();
this.map.put( key, model );
indices.push( this.map.indices[ key ] );
}
this.trigger( Collection.Events.Adds, [this, models, indices] );
if ( !delaySort )
{
this.sort();
}
}
} | javascript | function(models, delaySort, remoteData)
{
if ( isArray( models ) )
{
var indices = [];
for (var i = 0; i < models.length; i++)
{
var model = this.parseModel( models[ i ], remoteData );
var key = model.$key();
this.map.put( key, model );
indices.push( this.map.indices[ key ] );
}
this.trigger( Collection.Events.Adds, [this, models, indices] );
if ( !delaySort )
{
this.sort();
}
}
} | [
"function",
"(",
"models",
",",
"delaySort",
",",
"remoteData",
")",
"{",
"if",
"(",
"isArray",
"(",
"models",
")",
")",
"{",
"var",
"indices",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"models",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"model",
"=",
"this",
".",
"parseModel",
"(",
"models",
"[",
"i",
"]",
",",
"remoteData",
")",
";",
"var",
"key",
"=",
"model",
".",
"$key",
"(",
")",
";",
"this",
".",
"map",
".",
"put",
"(",
"key",
",",
"model",
")",
";",
"indices",
".",
"push",
"(",
"this",
".",
"map",
".",
"indices",
"[",
"key",
"]",
")",
";",
"}",
"this",
".",
"trigger",
"(",
"Collection",
".",
"Events",
".",
"Adds",
",",
"[",
"this",
",",
"models",
",",
"indices",
"]",
")",
";",
"if",
"(",
"!",
"delaySort",
")",
"{",
"this",
".",
"sort",
"(",
")",
";",
"}",
"}",
"}"
] | Adds all models in the given array to this collection - sorting the
collection if a comparator is set on this collection and `delaySort` is
not specified or a true value.
@method
@memberof Rekord.ModelCollection#
@param {modelInput[]} models -
The models to add to this collection.
@param {Boolean} [delaySort=false] -
Whether automatic sorting should be delayed until the user manually
calls {@link Rekord.ModelCollection#sort sort}.
@param {Boolean} [remoteData=false] -
If the model is from a remote source. Remote sources place the model
directly into the database while local sources aren't stored in the
database until they're saved.
@return {Rekord.ModelCollection} -
The reference to this collection.
@emits Rekord.ModelCollection#adds
@emits Rekord.ModelCollection#sort | [
"Adds",
"all",
"models",
"in",
"the",
"given",
"array",
"to",
"this",
"collection",
"-",
"sorting",
"the",
"collection",
"if",
"a",
"comparator",
"is",
"set",
"on",
"this",
"collection",
"and",
"delaySort",
"is",
"not",
"specified",
"or",
"a",
"true",
"value",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L10492-L10514 | train |
|
Rekord/rekord | build/rekord.js | function(delaySort)
{
var removed = this[ 0 ];
this.map.removeAt( 0 );
this.trigger( Collection.Events.Remove, [this, removed, 0] );
if ( !delaySort )
{
this.sort();
}
return removed;
} | javascript | function(delaySort)
{
var removed = this[ 0 ];
this.map.removeAt( 0 );
this.trigger( Collection.Events.Remove, [this, removed, 0] );
if ( !delaySort )
{
this.sort();
}
return removed;
} | [
"function",
"(",
"delaySort",
")",
"{",
"var",
"removed",
"=",
"this",
"[",
"0",
"]",
";",
"this",
".",
"map",
".",
"removeAt",
"(",
"0",
")",
";",
"this",
".",
"trigger",
"(",
"Collection",
".",
"Events",
".",
"Remove",
",",
"[",
"this",
",",
"removed",
",",
"0",
"]",
")",
";",
"if",
"(",
"!",
"delaySort",
")",
"{",
"this",
".",
"sort",
"(",
")",
";",
"}",
"return",
"removed",
";",
"}"
] | Removes the first model in this collection and returns it - sorting the
collection if a comparator is set on this collection and `delaySort` is
no specified or a true value.
```javascript
var c = Rekord.collect(1, 2, 3, 4);
c.shift(); // 1
```
@method
@memberof Rekord.ModelCollection#
@param {Boolean} [delaySort=false] -
Whether automatic sorting should be delayed until the user manually
calls {@link Rekord.ModelCollection#sort sort}.
@return {Rekord.Model} -
The model removed from the beginning of the collection.
@emits Rekord.ModelCollection#remove
@emits Rekord.ModelCollection#sort | [
"Removes",
"the",
"first",
"model",
"in",
"this",
"collection",
"and",
"returns",
"it",
"-",
"sorting",
"the",
"collection",
"if",
"a",
"comparator",
"is",
"set",
"on",
"this",
"collection",
"and",
"delaySort",
"is",
"no",
"specified",
"or",
"a",
"true",
"value",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L10581-L10594 | train |
|
Rekord/rekord | build/rekord.js | function(i, delaySort)
{
var removing;
if (i >= 0 && i < this.length)
{
removing = this[ i ];
this.map.removeAt( i );
this.trigger( Collection.Events.Remove, [this, removing, i] );
if ( !delaySort )
{
this.sort();
}
}
return removing;
} | javascript | function(i, delaySort)
{
var removing;
if (i >= 0 && i < this.length)
{
removing = this[ i ];
this.map.removeAt( i );
this.trigger( Collection.Events.Remove, [this, removing, i] );
if ( !delaySort )
{
this.sort();
}
}
return removing;
} | [
"function",
"(",
"i",
",",
"delaySort",
")",
"{",
"var",
"removing",
";",
"if",
"(",
"i",
">=",
"0",
"&&",
"i",
"<",
"this",
".",
"length",
")",
"{",
"removing",
"=",
"this",
"[",
"i",
"]",
";",
"this",
".",
"map",
".",
"removeAt",
"(",
"i",
")",
";",
"this",
".",
"trigger",
"(",
"Collection",
".",
"Events",
".",
"Remove",
",",
"[",
"this",
",",
"removing",
",",
"i",
"]",
")",
";",
"if",
"(",
"!",
"delaySort",
")",
"{",
"this",
".",
"sort",
"(",
")",
";",
"}",
"}",
"return",
"removing",
";",
"}"
] | Removes the model in this collection at the given index `i` - sorting
the collection if a comparator is set on this collection and `delaySort` is
not specified or a true value.
@method
@memberof Rekord.ModelCollection#
@param {Number} i -
The index of the model to remove.
@param {Boolean} [delaySort=false] -
Whether automatic sorting should be delayed until the user manually
calls {@link Rekord.ModelCollection#sort sort}.
@return {Rekord.Model} -
The model removed, or undefined if the index was invalid.
@emits Rekord.ModelCollection#remove
@emits Rekord.ModelCollection#sort | [
"Removes",
"the",
"model",
"in",
"this",
"collection",
"at",
"the",
"given",
"index",
"i",
"-",
"sorting",
"the",
"collection",
"if",
"a",
"comparator",
"is",
"set",
"on",
"this",
"collection",
"and",
"delaySort",
"is",
"not",
"specified",
"or",
"a",
"true",
"value",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L10613-L10631 | train |
|
Rekord/rekord | build/rekord.js | function(input, delaySort)
{
var key = this.buildKeyFromInput( input );
var removing = this.map.get( key );
if ( removing )
{
var i = this.map.indices[ key ];
this.map.remove( key );
this.trigger( Collection.Events.Remove, [this, removing, i] );
if ( !delaySort )
{
this.sort();
}
}
return removing;
} | javascript | function(input, delaySort)
{
var key = this.buildKeyFromInput( input );
var removing = this.map.get( key );
if ( removing )
{
var i = this.map.indices[ key ];
this.map.remove( key );
this.trigger( Collection.Events.Remove, [this, removing, i] );
if ( !delaySort )
{
this.sort();
}
}
return removing;
} | [
"function",
"(",
"input",
",",
"delaySort",
")",
"{",
"var",
"key",
"=",
"this",
".",
"buildKeyFromInput",
"(",
"input",
")",
";",
"var",
"removing",
"=",
"this",
".",
"map",
".",
"get",
"(",
"key",
")",
";",
"if",
"(",
"removing",
")",
"{",
"var",
"i",
"=",
"this",
".",
"map",
".",
"indices",
"[",
"key",
"]",
";",
"this",
".",
"map",
".",
"remove",
"(",
"key",
")",
";",
"this",
".",
"trigger",
"(",
"Collection",
".",
"Events",
".",
"Remove",
",",
"[",
"this",
",",
"removing",
",",
"i",
"]",
")",
";",
"if",
"(",
"!",
"delaySort",
")",
"{",
"this",
".",
"sort",
"(",
")",
";",
"}",
"}",
"return",
"removing",
";",
"}"
] | Removes the given model from this collection if it exists - sorting the
collection if a comparator is set on this collection and `delaySort` is not
specified or a true value.
@method
@memberof Rekord.ModelCollection#
@param {modelInput} input -
The model to remove from this collection if it exists.
@param {Boolean} [delaySort=false] -
Whether automatic sorting should be delayed until the user manually
calls {@link Rekord.ModelCollection#sort sort}.
@param {equalityCallback} [equals=Rekord.equalsStrict] -
The function which determines whether one of the elements that exist in
this collection are equivalent to the given value.
@return {Rekord.Model} -
The element removed from this collection.
@emits Rekord.ModelCollection#remove
@emits Rekord.ModelCollection#sort | [
"Removes",
"the",
"given",
"model",
"from",
"this",
"collection",
"if",
"it",
"exists",
"-",
"sorting",
"the",
"collection",
"if",
"a",
"comparator",
"is",
"set",
"on",
"this",
"collection",
"and",
"delaySort",
"is",
"not",
"specified",
"or",
"a",
"true",
"value",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L10653-L10672 | train |
|
Rekord/rekord | build/rekord.js | function(inputs, delaySort)
{
var map = this.map;
var removed = [];
var removedIndices = [];
for (var i = 0; i < inputs.length; i++)
{
var key = this.buildKeyFromInput( inputs[ i ] );
var removing = map.get( key );
if ( removing )
{
removedIndices.push( map.indices[ key ] );
removed.push( removing );
}
}
removedIndices.sort();
for (var i = removedIndices.length - 1; i >= 0; i--)
{
map.removeAt( removedIndices[ i ] );
}
this.trigger( Collection.Events.Removes, [this, removed, removedIndices] );
if ( !delaySort )
{
this.sort();
}
return removed;
} | javascript | function(inputs, delaySort)
{
var map = this.map;
var removed = [];
var removedIndices = [];
for (var i = 0; i < inputs.length; i++)
{
var key = this.buildKeyFromInput( inputs[ i ] );
var removing = map.get( key );
if ( removing )
{
removedIndices.push( map.indices[ key ] );
removed.push( removing );
}
}
removedIndices.sort();
for (var i = removedIndices.length - 1; i >= 0; i--)
{
map.removeAt( removedIndices[ i ] );
}
this.trigger( Collection.Events.Removes, [this, removed, removedIndices] );
if ( !delaySort )
{
this.sort();
}
return removed;
} | [
"function",
"(",
"inputs",
",",
"delaySort",
")",
"{",
"var",
"map",
"=",
"this",
".",
"map",
";",
"var",
"removed",
"=",
"[",
"]",
";",
"var",
"removedIndices",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"inputs",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"key",
"=",
"this",
".",
"buildKeyFromInput",
"(",
"inputs",
"[",
"i",
"]",
")",
";",
"var",
"removing",
"=",
"map",
".",
"get",
"(",
"key",
")",
";",
"if",
"(",
"removing",
")",
"{",
"removedIndices",
".",
"push",
"(",
"map",
".",
"indices",
"[",
"key",
"]",
")",
";",
"removed",
".",
"push",
"(",
"removing",
")",
";",
"}",
"}",
"removedIndices",
".",
"sort",
"(",
")",
";",
"for",
"(",
"var",
"i",
"=",
"removedIndices",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"map",
".",
"removeAt",
"(",
"removedIndices",
"[",
"i",
"]",
")",
";",
"}",
"this",
".",
"trigger",
"(",
"Collection",
".",
"Events",
".",
"Removes",
",",
"[",
"this",
",",
"removed",
",",
"removedIndices",
"]",
")",
";",
"if",
"(",
"!",
"delaySort",
")",
"{",
"this",
".",
"sort",
"(",
")",
";",
"}",
"return",
"removed",
";",
"}"
] | Removes the given models from this collection - sorting the collection if
a comparator is set on this collection and `delaySort` is not specified or
a true value.
@method
@memberof Rekord.ModelCollection#
@param {modelInput[]} inputs -
The models to remove from this collection if they exist.
@param {Boolean} [delaySort=false] -
Whether automatic sorting should be delayed until the user manually
calls {@link Rekord.ModelCollection#sort sort}.
@return {Rekord.Model[]} -
The models removed from this collection.
@emits Rekord.ModelCollection#removes
@emits Rekord.ModelCollection#sort | [
"Removes",
"the",
"given",
"models",
"from",
"this",
"collection",
"-",
"sorting",
"the",
"collection",
"if",
"a",
"comparator",
"is",
"set",
"on",
"this",
"collection",
"and",
"delaySort",
"is",
"not",
"specified",
"or",
"a",
"true",
"value",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L10691-L10724 | train |
|
Rekord/rekord | build/rekord.js | function(input)
{
var key = this.buildKeyFromInput( input );
var index = this.map.indices[ key ];
return index === undefined ? -1 : index;
} | javascript | function(input)
{
var key = this.buildKeyFromInput( input );
var index = this.map.indices[ key ];
return index === undefined ? -1 : index;
} | [
"function",
"(",
"input",
")",
"{",
"var",
"key",
"=",
"this",
".",
"buildKeyFromInput",
"(",
"input",
")",
";",
"var",
"index",
"=",
"this",
".",
"map",
".",
"indices",
"[",
"key",
"]",
";",
"return",
"index",
"===",
"undefined",
"?",
"-",
"1",
":",
"index",
";",
"}"
] | Returns the index of the given model in this collection or returns -1
if the model doesn't exist in this collection.
@method
@memberof Rekord.ModelCollection#
@param {modelInput} input -
The model to search for.
@return {Number} -
The index of the model in this collection or -1 if it was not found. | [
"Returns",
"the",
"index",
"of",
"the",
"given",
"model",
"in",
"this",
"collection",
"or",
"returns",
"-",
"1",
"if",
"the",
"model",
"doesn",
"t",
"exist",
"in",
"this",
"collection",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L10737-L10743 | train |
|
Rekord/rekord | build/rekord.js | function(properties, value, equals)
{
var where = createWhere( properties, value, equals );
var hasChanges = function( model )
{
return where( model ) && model.$hasChanges();
};
return this.contains( hasChanges );
} | javascript | function(properties, value, equals)
{
var where = createWhere( properties, value, equals );
var hasChanges = function( model )
{
return where( model ) && model.$hasChanges();
};
return this.contains( hasChanges );
} | [
"function",
"(",
"properties",
",",
"value",
",",
"equals",
")",
"{",
"var",
"where",
"=",
"createWhere",
"(",
"properties",
",",
"value",
",",
"equals",
")",
";",
"var",
"hasChanges",
"=",
"function",
"(",
"model",
")",
"{",
"return",
"where",
"(",
"model",
")",
"&&",
"model",
".",
"$hasChanges",
"(",
")",
";",
"}",
";",
"return",
"this",
".",
"contains",
"(",
"hasChanges",
")",
";",
"}"
] | Returns whether this collection has at least one model with changes. An
additional where expression can be given to only check certain models.
@method
@memberof Rekord.ModelCollection#
@param {whereInput} [properties] -
See {@link Rekord.createWhere}
@param {Any} [value] -
See {@link Rekord.createWhere}
@param {equalityCallback} [equals=Rekord.equalsStrict] -
See {@link Rekord.createWhere}
@return {Boolean} -
True if at least one model has changes, otherwise false.
@see Rekord.createWhere
@see Rekord.Model#$hasChanges | [
"Returns",
"whether",
"this",
"collection",
"has",
"at",
"least",
"one",
"model",
"with",
"changes",
".",
"An",
"additional",
"where",
"expression",
"can",
"be",
"given",
"to",
"only",
"check",
"certain",
"models",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L11241-L11251 | train |
|
Rekord/rekord | build/rekord.js | function(properties, value, equals, out)
{
var where = createWhere( properties, value, equals );
var changes = out && out instanceof ModelCollection ? out : this.cloneEmpty();
this.each(function(model)
{
if ( where( model ) && model.$hasChanges() )
{
changes.put( model.$key(), model.$getChanges() );
}
});
return changes;
} | javascript | function(properties, value, equals, out)
{
var where = createWhere( properties, value, equals );
var changes = out && out instanceof ModelCollection ? out : this.cloneEmpty();
this.each(function(model)
{
if ( where( model ) && model.$hasChanges() )
{
changes.put( model.$key(), model.$getChanges() );
}
});
return changes;
} | [
"function",
"(",
"properties",
",",
"value",
",",
"equals",
",",
"out",
")",
"{",
"var",
"where",
"=",
"createWhere",
"(",
"properties",
",",
"value",
",",
"equals",
")",
";",
"var",
"changes",
"=",
"out",
"&&",
"out",
"instanceof",
"ModelCollection",
"?",
"out",
":",
"this",
".",
"cloneEmpty",
"(",
")",
";",
"this",
".",
"each",
"(",
"function",
"(",
"model",
")",
"{",
"if",
"(",
"where",
"(",
"model",
")",
"&&",
"model",
".",
"$hasChanges",
"(",
")",
")",
"{",
"changes",
".",
"put",
"(",
"model",
".",
"$key",
"(",
")",
",",
"model",
".",
"$getChanges",
"(",
")",
")",
";",
"}",
"}",
")",
";",
"return",
"changes",
";",
"}"
] | Returns a collection of all changes for each model. The changes are keyed
into the collection by the models key. An additional where expression can
be given to only check certain models.
@method
@memberof Rekord.ModelCollection#
@param {whereInput} [properties] -
See {@link Rekord.createWhere}
@param {Any} [value] -
See {@link Rekord.createWhere}
@param {equalityCallback} [equals=Rekord.equalsStrict] -
See {@link Rekord.createWhere}
@param {Rekord.ModelCollection} [out] -
The collection to add the changes to.
@return {Rekord.ModelCollection} -
The collection with all changes to models in this collection.
@see Rekord.createWhere
@see Rekord.Model#$hasChanges
@see Rekord.Model#$getChanges | [
"Returns",
"a",
"collection",
"of",
"all",
"changes",
"for",
"each",
"model",
".",
"The",
"changes",
"are",
"keyed",
"into",
"the",
"collection",
"by",
"the",
"models",
"key",
".",
"An",
"additional",
"where",
"expression",
"can",
"be",
"given",
"to",
"only",
"check",
"certain",
"models",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L11274-L11288 | train |
|
Rekord/rekord | build/rekord.js | function(cloneModels, cloneProperties)
{
var source = this;
if ( cloneModels )
{
source = [];
for (var i = 0; i < this.length; i++)
{
source[ i ] = this[ i ].$clone( cloneProperties );
}
}
return ModelCollection.create( this.database, source, true );
} | javascript | function(cloneModels, cloneProperties)
{
var source = this;
if ( cloneModels )
{
source = [];
for (var i = 0; i < this.length; i++)
{
source[ i ] = this[ i ].$clone( cloneProperties );
}
}
return ModelCollection.create( this.database, source, true );
} | [
"function",
"(",
"cloneModels",
",",
"cloneProperties",
")",
"{",
"var",
"source",
"=",
"this",
";",
"if",
"(",
"cloneModels",
")",
"{",
"source",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"length",
";",
"i",
"++",
")",
"{",
"source",
"[",
"i",
"]",
"=",
"this",
"[",
"i",
"]",
".",
"$clone",
"(",
"cloneProperties",
")",
";",
"}",
"}",
"return",
"ModelCollection",
".",
"create",
"(",
"this",
".",
"database",
",",
"source",
",",
"true",
")",
";",
"}"
] | Returns a clone of this collection. Optionally the models in this
collection can also be cloned.
@method
@memberof Rekord.ModelCollection#
@param {Boolean} [cloneModels=false] -
Whether or not the models should be cloned as well.
@param {Boolean} [cloneProperties] -
The properties object which defines what fields should be given a
different (non-cloned) value and which relations need to be cloned.
@return {Rekord.ModelCollection} -
The reference to a clone collection.
@see Rekord.Model#$clone | [
"Returns",
"a",
"clone",
"of",
"this",
"collection",
".",
"Optionally",
"the",
"models",
"in",
"this",
"collection",
"can",
"also",
"be",
"cloned",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L11335-L11350 | train |
|
Rekord/rekord | build/rekord.js | function(base, filter)
{
if ( this.base )
{
this.base.database.off( Database.Events.ModelUpdated, this.onModelUpdated );
}
ModelCollection.prototype.init.call( this, base.database );
Filtering.init.call( this, base, filter );
base.database.on( Database.Events.ModelUpdated, this.onModelUpdated );
return this;
} | javascript | function(base, filter)
{
if ( this.base )
{
this.base.database.off( Database.Events.ModelUpdated, this.onModelUpdated );
}
ModelCollection.prototype.init.call( this, base.database );
Filtering.init.call( this, base, filter );
base.database.on( Database.Events.ModelUpdated, this.onModelUpdated );
return this;
} | [
"function",
"(",
"base",
",",
"filter",
")",
"{",
"if",
"(",
"this",
".",
"base",
")",
"{",
"this",
".",
"base",
".",
"database",
".",
"off",
"(",
"Database",
".",
"Events",
".",
"ModelUpdated",
",",
"this",
".",
"onModelUpdated",
")",
";",
"}",
"ModelCollection",
".",
"prototype",
".",
"init",
".",
"call",
"(",
"this",
",",
"base",
".",
"database",
")",
";",
"Filtering",
".",
"init",
".",
"call",
"(",
"this",
",",
"base",
",",
"filter",
")",
";",
"base",
".",
"database",
".",
"on",
"(",
"Database",
".",
"Events",
".",
"ModelUpdated",
",",
"this",
".",
"onModelUpdated",
")",
";",
"return",
"this",
";",
"}"
] | Initializes the filtered collection by setting the base collection and the
filtering function.
@method
@memberof Rekord.FilteredModelCollection#
@param {Rekord.ModelCollection} base -
The model collection to listen to for changes to update this collection.
@param {whereCallback} filter -
The function which determines whether a model in the base collection
should exist in this collection.
@return {Rekord.FilteredModelCollection} -
The reference to this collection.
@emits Rekord.Collection#reset | [
"Initializes",
"the",
"filtered",
"collection",
"by",
"setting",
"the",
"base",
"collection",
"and",
"the",
"filtering",
"function",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L11448-L11462 | train |
|
Rekord/rekord | build/rekord.js | function(model)
{
var exists = this.has( model.$key() );
var matches = this.filter( model );
if ( exists && !matches )
{
this.remove( model );
}
if ( !exists && matches )
{
this.add( model );
}
} | javascript | function(model)
{
var exists = this.has( model.$key() );
var matches = this.filter( model );
if ( exists && !matches )
{
this.remove( model );
}
if ( !exists && matches )
{
this.add( model );
}
} | [
"function",
"(",
"model",
")",
"{",
"var",
"exists",
"=",
"this",
".",
"has",
"(",
"model",
".",
"$key",
"(",
")",
")",
";",
"var",
"matches",
"=",
"this",
".",
"filter",
"(",
"model",
")",
";",
"if",
"(",
"exists",
"&&",
"!",
"matches",
")",
"{",
"this",
".",
"remove",
"(",
"model",
")",
";",
"}",
"if",
"(",
"!",
"exists",
"&&",
"matches",
")",
"{",
"this",
".",
"add",
"(",
"model",
")",
";",
"}",
"}"
] | Handles the ModelUpdated event from the database. | [
"Handles",
"the",
"ModelUpdated",
"event",
"from",
"the",
"database",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L11520-L11533 | train |
|
Rekord/rekord | build/rekord.js | DiscriminateCollection | function DiscriminateCollection(collection, discriminator, discriminatorsToModel)
{
Class.props( collection,
{
discriminator: discriminator,
discriminatorsToModel: discriminatorsToModel
});
// Original Functions
var buildKeyFromInput = collection.buildKeyFromInput;
var parseModel = collection.parseModel;
var clone = collection.clone;
var cloneEmpty = collection.cloneEmpty;
Class.props( collection,
{
/**
* Builds a key from input. Discriminated collections only accept objects as
* input - otherwise there's no way to determine the discriminator. If the
* discriminator on the input doesn't map to a Rekord instance OR the input
* is not an object the input will be returned instead of a model instance.
*
* @param {modelInput} input -
* The input to create a key for.
* @return {Any} -
* The built key or the given input if a key could not be built.
*/
buildKeyFromInput: function(input)
{
if ( isObject( input ) )
{
var discriminatedValue = input[ this.discriminator ];
var model = this.discriminatorsToModel[ discriminatedValue ];
if ( model )
{
return model.Database.keyHandler.buildKeyFromInput( input );
}
}
return input;
},
/**
* Takes input and returns a model instance. The input is expected to be an
* object, any other type will return null.
*
* @param {modelInput} input -
* The input to parse to a model instance.
* @param {Boolean} [remoteData=false] -
* Whether or not the input is coming from a remote source.
* @return {Rekord.Model} -
* The model instance parsed or null if none was found.
*/
parseModel: function(input, remoteData)
{
if ( input instanceof Model )
{
return input;
}
var discriminatedValue = isValue( input ) ? input[ this.discriminator ] : null;
var model = this.discriminatorsToModel[ discriminatedValue ];
return model ? model.Database.parseModel( input, remoteData ) : null;
},
/**
* Returns a clone of this collection.
*
* @method
* @memberof Rekord.Collection#
* @return {Rekord.Collection} -
* The reference to a clone collection.
*/
clone: function()
{
return DiscriminateCollection( clone.apply( this ), discriminator, discriminatorsToModel );
},
/**
* Returns an empty clone of this collection.
*
* @method
* @memberof Rekord.Collection#
* @return {Rekord.Collection} -
* The reference to a clone collection.
*/
cloneEmpty: function()
{
return DiscriminateCollection( cloneEmpty.apply( this ), discriminator, discriminatorsToModel );
}
});
return collection;
} | javascript | function DiscriminateCollection(collection, discriminator, discriminatorsToModel)
{
Class.props( collection,
{
discriminator: discriminator,
discriminatorsToModel: discriminatorsToModel
});
// Original Functions
var buildKeyFromInput = collection.buildKeyFromInput;
var parseModel = collection.parseModel;
var clone = collection.clone;
var cloneEmpty = collection.cloneEmpty;
Class.props( collection,
{
/**
* Builds a key from input. Discriminated collections only accept objects as
* input - otherwise there's no way to determine the discriminator. If the
* discriminator on the input doesn't map to a Rekord instance OR the input
* is not an object the input will be returned instead of a model instance.
*
* @param {modelInput} input -
* The input to create a key for.
* @return {Any} -
* The built key or the given input if a key could not be built.
*/
buildKeyFromInput: function(input)
{
if ( isObject( input ) )
{
var discriminatedValue = input[ this.discriminator ];
var model = this.discriminatorsToModel[ discriminatedValue ];
if ( model )
{
return model.Database.keyHandler.buildKeyFromInput( input );
}
}
return input;
},
/**
* Takes input and returns a model instance. The input is expected to be an
* object, any other type will return null.
*
* @param {modelInput} input -
* The input to parse to a model instance.
* @param {Boolean} [remoteData=false] -
* Whether or not the input is coming from a remote source.
* @return {Rekord.Model} -
* The model instance parsed or null if none was found.
*/
parseModel: function(input, remoteData)
{
if ( input instanceof Model )
{
return input;
}
var discriminatedValue = isValue( input ) ? input[ this.discriminator ] : null;
var model = this.discriminatorsToModel[ discriminatedValue ];
return model ? model.Database.parseModel( input, remoteData ) : null;
},
/**
* Returns a clone of this collection.
*
* @method
* @memberof Rekord.Collection#
* @return {Rekord.Collection} -
* The reference to a clone collection.
*/
clone: function()
{
return DiscriminateCollection( clone.apply( this ), discriminator, discriminatorsToModel );
},
/**
* Returns an empty clone of this collection.
*
* @method
* @memberof Rekord.Collection#
* @return {Rekord.Collection} -
* The reference to a clone collection.
*/
cloneEmpty: function()
{
return DiscriminateCollection( cloneEmpty.apply( this ), discriminator, discriminatorsToModel );
}
});
return collection;
} | [
"function",
"DiscriminateCollection",
"(",
"collection",
",",
"discriminator",
",",
"discriminatorsToModel",
")",
"{",
"Class",
".",
"props",
"(",
"collection",
",",
"{",
"discriminator",
":",
"discriminator",
",",
"discriminatorsToModel",
":",
"discriminatorsToModel",
"}",
")",
";",
"var",
"buildKeyFromInput",
"=",
"collection",
".",
"buildKeyFromInput",
";",
"var",
"parseModel",
"=",
"collection",
".",
"parseModel",
";",
"var",
"clone",
"=",
"collection",
".",
"clone",
";",
"var",
"cloneEmpty",
"=",
"collection",
".",
"cloneEmpty",
";",
"Class",
".",
"props",
"(",
"collection",
",",
"{",
"buildKeyFromInput",
":",
"function",
"(",
"input",
")",
"{",
"if",
"(",
"isObject",
"(",
"input",
")",
")",
"{",
"var",
"discriminatedValue",
"=",
"input",
"[",
"this",
".",
"discriminator",
"]",
";",
"var",
"model",
"=",
"this",
".",
"discriminatorsToModel",
"[",
"discriminatedValue",
"]",
";",
"if",
"(",
"model",
")",
"{",
"return",
"model",
".",
"Database",
".",
"keyHandler",
".",
"buildKeyFromInput",
"(",
"input",
")",
";",
"}",
"}",
"return",
"input",
";",
"}",
",",
"parseModel",
":",
"function",
"(",
"input",
",",
"remoteData",
")",
"{",
"if",
"(",
"input",
"instanceof",
"Model",
")",
"{",
"return",
"input",
";",
"}",
"var",
"discriminatedValue",
"=",
"isValue",
"(",
"input",
")",
"?",
"input",
"[",
"this",
".",
"discriminator",
"]",
":",
"null",
";",
"var",
"model",
"=",
"this",
".",
"discriminatorsToModel",
"[",
"discriminatedValue",
"]",
";",
"return",
"model",
"?",
"model",
".",
"Database",
".",
"parseModel",
"(",
"input",
",",
"remoteData",
")",
":",
"null",
";",
"}",
",",
"clone",
":",
"function",
"(",
")",
"{",
"return",
"DiscriminateCollection",
"(",
"clone",
".",
"apply",
"(",
"this",
")",
",",
"discriminator",
",",
"discriminatorsToModel",
")",
";",
"}",
",",
"cloneEmpty",
":",
"function",
"(",
")",
"{",
"return",
"DiscriminateCollection",
"(",
"cloneEmpty",
".",
"apply",
"(",
"this",
")",
",",
"discriminator",
",",
"discriminatorsToModel",
")",
";",
"}",
"}",
")",
";",
"return",
"collection",
";",
"}"
] | Overrides functions in the given model collection to turn it into a collection
which contains models with a discriminator field.
@param {Rekord.ModelCollection} collection -
The collection instance with discriminated models.
@param {String} discriminator -
The name of the field which contains the discriminator.
@param {Object} discriminatorsToModel -
A map of discriminators to the Rekord instances.
@return {Rekord.ModelCollection} -
The reference to the given collection. | [
"Overrides",
"functions",
"in",
"the",
"given",
"model",
"collection",
"to",
"turn",
"it",
"into",
"a",
"collection",
"which",
"contains",
"models",
"with",
"a",
"discriminator",
"field",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L11770-L11867 | train |
Rekord/rekord | build/rekord.js | function(input)
{
if ( isObject( input ) )
{
var discriminatedValue = input[ this.discriminator ];
var model = this.discriminatorsToModel[ discriminatedValue ];
if ( model )
{
return model.Database.keyHandler.buildKeyFromInput( input );
}
}
return input;
} | javascript | function(input)
{
if ( isObject( input ) )
{
var discriminatedValue = input[ this.discriminator ];
var model = this.discriminatorsToModel[ discriminatedValue ];
if ( model )
{
return model.Database.keyHandler.buildKeyFromInput( input );
}
}
return input;
} | [
"function",
"(",
"input",
")",
"{",
"if",
"(",
"isObject",
"(",
"input",
")",
")",
"{",
"var",
"discriminatedValue",
"=",
"input",
"[",
"this",
".",
"discriminator",
"]",
";",
"var",
"model",
"=",
"this",
".",
"discriminatorsToModel",
"[",
"discriminatedValue",
"]",
";",
"if",
"(",
"model",
")",
"{",
"return",
"model",
".",
"Database",
".",
"keyHandler",
".",
"buildKeyFromInput",
"(",
"input",
")",
";",
"}",
"}",
"return",
"input",
";",
"}"
] | Builds a key from input. Discriminated collections only accept objects as
input - otherwise there's no way to determine the discriminator. If the
discriminator on the input doesn't map to a Rekord instance OR the input
is not an object the input will be returned instead of a model instance.
@param {modelInput} input -
The input to create a key for.
@return {Any} -
The built key or the given input if a key could not be built. | [
"Builds",
"a",
"key",
"from",
"input",
".",
"Discriminated",
"collections",
"only",
"accept",
"objects",
"as",
"input",
"-",
"otherwise",
"there",
"s",
"no",
"way",
"to",
"determine",
"the",
"discriminator",
".",
"If",
"the",
"discriminator",
"on",
"the",
"input",
"doesn",
"t",
"map",
"to",
"a",
"Rekord",
"instance",
"OR",
"the",
"input",
"is",
"not",
"an",
"object",
"the",
"input",
"will",
"be",
"returned",
"instead",
"of",
"a",
"model",
"instance",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L11798-L11812 | train |
|
Rekord/rekord | build/rekord.js | function(input, remoteData)
{
if ( input instanceof Model )
{
return input;
}
var discriminatedValue = isValue( input ) ? input[ this.discriminator ] : null;
var model = this.discriminatorsToModel[ discriminatedValue ];
return model ? model.Database.parseModel( input, remoteData ) : null;
} | javascript | function(input, remoteData)
{
if ( input instanceof Model )
{
return input;
}
var discriminatedValue = isValue( input ) ? input[ this.discriminator ] : null;
var model = this.discriminatorsToModel[ discriminatedValue ];
return model ? model.Database.parseModel( input, remoteData ) : null;
} | [
"function",
"(",
"input",
",",
"remoteData",
")",
"{",
"if",
"(",
"input",
"instanceof",
"Model",
")",
"{",
"return",
"input",
";",
"}",
"var",
"discriminatedValue",
"=",
"isValue",
"(",
"input",
")",
"?",
"input",
"[",
"this",
".",
"discriminator",
"]",
":",
"null",
";",
"var",
"model",
"=",
"this",
".",
"discriminatorsToModel",
"[",
"discriminatedValue",
"]",
";",
"return",
"model",
"?",
"model",
".",
"Database",
".",
"parseModel",
"(",
"input",
",",
"remoteData",
")",
":",
"null",
";",
"}"
] | Takes input and returns a model instance. The input is expected to be an
object, any other type will return null.
@param {modelInput} input -
The input to parse to a model instance.
@param {Boolean} [remoteData=false] -
Whether or not the input is coming from a remote source.
@return {Rekord.Model} -
The model instance parsed or null if none was found. | [
"Takes",
"input",
"and",
"returns",
"a",
"model",
"instance",
".",
"The",
"input",
"is",
"expected",
"to",
"be",
"an",
"object",
"any",
"other",
"type",
"will",
"return",
"null",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L11825-L11836 | train |
|
Rekord/rekord | build/rekord.js | function(database, field, options)
{
applyOptions( this, options, this.getDefaults( database, field, options ) );
this.database = database;
this.name = field;
this.options = options;
this.initialized = false;
this.property = this.property || (indexOf( database.fields, this.name ) !== false);
this.discriminated = !isEmpty( this.discriminators );
if ( this.discriminated )
{
if ( !Polymorphic )
{
throw 'Polymorphic feature is required to use the discriminated option.';
}
Class.props( this, Polymorphic );
}
this.setReferences( database, field, options );
} | javascript | function(database, field, options)
{
applyOptions( this, options, this.getDefaults( database, field, options ) );
this.database = database;
this.name = field;
this.options = options;
this.initialized = false;
this.property = this.property || (indexOf( database.fields, this.name ) !== false);
this.discriminated = !isEmpty( this.discriminators );
if ( this.discriminated )
{
if ( !Polymorphic )
{
throw 'Polymorphic feature is required to use the discriminated option.';
}
Class.props( this, Polymorphic );
}
this.setReferences( database, field, options );
} | [
"function",
"(",
"database",
",",
"field",
",",
"options",
")",
"{",
"applyOptions",
"(",
"this",
",",
"options",
",",
"this",
".",
"getDefaults",
"(",
"database",
",",
"field",
",",
"options",
")",
")",
";",
"this",
".",
"database",
"=",
"database",
";",
"this",
".",
"name",
"=",
"field",
";",
"this",
".",
"options",
"=",
"options",
";",
"this",
".",
"initialized",
"=",
"false",
";",
"this",
".",
"property",
"=",
"this",
".",
"property",
"||",
"(",
"indexOf",
"(",
"database",
".",
"fields",
",",
"this",
".",
"name",
")",
"!==",
"false",
")",
";",
"this",
".",
"discriminated",
"=",
"!",
"isEmpty",
"(",
"this",
".",
"discriminators",
")",
";",
"if",
"(",
"this",
".",
"discriminated",
")",
"{",
"if",
"(",
"!",
"Polymorphic",
")",
"{",
"throw",
"'Polymorphic feature is required to use the discriminated option.'",
";",
"}",
"Class",
".",
"props",
"(",
"this",
",",
"Polymorphic",
")",
";",
"}",
"this",
".",
"setReferences",
"(",
"database",
",",
"field",
",",
"options",
")",
";",
"}"
] | Initializes this relation with the given database, field, and options.
@param {Rekord.Database} database [description]
@param {String} field [description]
@param {Object} options [description] | [
"Initializes",
"this",
"relation",
"with",
"the",
"given",
"database",
"field",
"and",
"options",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L13758-L13780 | train |
|
rossj/rackit | lib/rackit.js | function (cb) {
o1._client.auth(function (err) {
if (err && !(err instanceof Error)) {
err = new Error(err.message || err);
}
if (!err) {
o1.config = {
storage : o1._client._serviceUrl
};
}
cb(err);
});
} | javascript | function (cb) {
o1._client.auth(function (err) {
if (err && !(err instanceof Error)) {
err = new Error(err.message || err);
}
if (!err) {
o1.config = {
storage : o1._client._serviceUrl
};
}
cb(err);
});
} | [
"function",
"(",
"cb",
")",
"{",
"o1",
".",
"_client",
".",
"auth",
"(",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
"&&",
"!",
"(",
"err",
"instanceof",
"Error",
")",
")",
"{",
"err",
"=",
"new",
"Error",
"(",
"err",
".",
"message",
"||",
"err",
")",
";",
"}",
"if",
"(",
"!",
"err",
")",
"{",
"o1",
".",
"config",
"=",
"{",
"storage",
":",
"o1",
".",
"_client",
".",
"_serviceUrl",
"}",
";",
"}",
"cb",
"(",
"err",
")",
";",
"}",
")",
";",
"}"
] | First authenticate with Cloud Files | [
"First",
"authenticate",
"with",
"Cloud",
"Files"
] | d5e5184980b00b993ef3eb448c2a5a763b9daf56 | https://github.com/rossj/rackit/blob/d5e5184980b00b993ef3eb448c2a5a763b9daf56/lib/rackit.js#L75-L88 | train |
|
rossj/rackit | lib/rackit.js | function (cb) {
if (o1.options.tempURLKey) {
o1._log('Setting temporary URL key for account...');
o1._client.setTemporaryUrlKey(o1.options.tempURLKey, cb);
} else {
cb();
}
} | javascript | function (cb) {
if (o1.options.tempURLKey) {
o1._log('Setting temporary URL key for account...');
o1._client.setTemporaryUrlKey(o1.options.tempURLKey, cb);
} else {
cb();
}
} | [
"function",
"(",
"cb",
")",
"{",
"if",
"(",
"o1",
".",
"options",
".",
"tempURLKey",
")",
"{",
"o1",
".",
"_log",
"(",
"'Setting temporary URL key for account...'",
")",
";",
"o1",
".",
"_client",
".",
"setTemporaryUrlKey",
"(",
"o1",
".",
"options",
".",
"tempURLKey",
",",
"cb",
")",
";",
"}",
"else",
"{",
"cb",
"(",
")",
";",
"}",
"}"
] | Set Account Metadata Key for public access | [
"Set",
"Account",
"Metadata",
"Key",
"for",
"public",
"access"
] | d5e5184980b00b993ef3eb448c2a5a763b9daf56 | https://github.com/rossj/rackit/blob/d5e5184980b00b993ef3eb448c2a5a763b9daf56/lib/rackit.js#L96-L103 | train |
|
rossj/rackit | lib/rackit.js | function (cb) {
o1._client.createContainer(sName, function (err, _container) {
if (err)
return cb(err);
// check that a parallel operation didn't just add the same container
container = _.find(o1.aContainers, { name : sName });
if (!container) {
o1.aContainers.push(_container);
container = _container;
}
cb();
});
} | javascript | function (cb) {
o1._client.createContainer(sName, function (err, _container) {
if (err)
return cb(err);
// check that a parallel operation didn't just add the same container
container = _.find(o1.aContainers, { name : sName });
if (!container) {
o1.aContainers.push(_container);
container = _container;
}
cb();
});
} | [
"function",
"(",
"cb",
")",
"{",
"o1",
".",
"_client",
".",
"createContainer",
"(",
"sName",
",",
"function",
"(",
"err",
",",
"_container",
")",
"{",
"if",
"(",
"err",
")",
"return",
"cb",
"(",
"err",
")",
";",
"container",
"=",
"_",
".",
"find",
"(",
"o1",
".",
"aContainers",
",",
"{",
"name",
":",
"sName",
"}",
")",
";",
"if",
"(",
"!",
"container",
")",
"{",
"o1",
".",
"aContainers",
".",
"push",
"(",
"_container",
")",
";",
"container",
"=",
"_container",
";",
"}",
"cb",
"(",
")",
";",
"}",
")",
";",
"}"
] | Create the container | [
"Create",
"the",
"container"
] | d5e5184980b00b993ef3eb448c2a5a763b9daf56 | https://github.com/rossj/rackit/blob/d5e5184980b00b993ef3eb448c2a5a763b9daf56/lib/rackit.js#L179-L194 | train |
|
rossj/rackit | lib/rackit.js | function (cb) {
if (!o1.options.useCDN)
return cb();
o1._log('CDN enabling the container');
container.enableCdn(function (err, _container) {
if (err)
return cb(err);
// check that a parallel operation didn't just CDN enable the same container
var index = _.findIndex(o1.aContainers, { name : sName });
container = o1.aContainers[index] = _container;
cb();
});
} | javascript | function (cb) {
if (!o1.options.useCDN)
return cb();
o1._log('CDN enabling the container');
container.enableCdn(function (err, _container) {
if (err)
return cb(err);
// check that a parallel operation didn't just CDN enable the same container
var index = _.findIndex(o1.aContainers, { name : sName });
container = o1.aContainers[index] = _container;
cb();
});
} | [
"function",
"(",
"cb",
")",
"{",
"if",
"(",
"!",
"o1",
".",
"options",
".",
"useCDN",
")",
"return",
"cb",
"(",
")",
";",
"o1",
".",
"_log",
"(",
"'CDN enabling the container'",
")",
";",
"container",
".",
"enableCdn",
"(",
"function",
"(",
"err",
",",
"_container",
")",
"{",
"if",
"(",
"err",
")",
"return",
"cb",
"(",
"err",
")",
";",
"var",
"index",
"=",
"_",
".",
"findIndex",
"(",
"o1",
".",
"aContainers",
",",
"{",
"name",
":",
"sName",
"}",
")",
";",
"container",
"=",
"o1",
".",
"aContainers",
"[",
"index",
"]",
"=",
"_container",
";",
"cb",
"(",
")",
";",
"}",
")",
";",
"}"
] | CDN enable the container, if necessary | [
"CDN",
"enable",
"the",
"container",
"if",
"necessary"
] | d5e5184980b00b993ef3eb448c2a5a763b9daf56 | https://github.com/rossj/rackit/blob/d5e5184980b00b993ef3eb448c2a5a763b9daf56/lib/rackit.js#L196-L213 | train |
|
rossj/rackit | lib/rackit.js | function (err, results) {
if (err) {
return cb(err);
}
// Generate file id
var id = options.filename || utils.uid(24);
//
// Generate the headers to be send to Rackspace
//
var headers = {};
// set the content-length of transfer-encoding as appropriate
if (fromFile) {
headers['content-length'] = results.stats.size;
} else {
if (source.headers && source.headers['content-length'])
headers['content-length'] = source.headers['content-length'];
else
headers['transfer-encoding'] = 'chunked';
}
// Add any additonal headers
var sKey;
for (sKey in options.headers) {
if (options.headers.hasOwnProperty(sKey)) {
headers[sKey] = options.headers[sKey];
}
}
//
// Generate the cloud request options
//
var _options = {
container : results.container.name,
remote : id,
headers : headers,
metadata : options.meta,
contentType : type
};
var readStream;
if (fromFile)
readStream = fs.createReadStream(source);
else {
readStream = source;
source.resume();
if (source.headers) {
// We want to remove any headers from the source stream so they don't clobber our own headers.
delete source.headers;
}
}
var writeStream = o1._client.upload(_options);
writeStream.on('error', cb);
writeStream.on('success', function (file) {
results.container.count++;
cb(null, results.container.name + '/' + id);
});
readStream.pipe(writeStream);
} | javascript | function (err, results) {
if (err) {
return cb(err);
}
// Generate file id
var id = options.filename || utils.uid(24);
//
// Generate the headers to be send to Rackspace
//
var headers = {};
// set the content-length of transfer-encoding as appropriate
if (fromFile) {
headers['content-length'] = results.stats.size;
} else {
if (source.headers && source.headers['content-length'])
headers['content-length'] = source.headers['content-length'];
else
headers['transfer-encoding'] = 'chunked';
}
// Add any additonal headers
var sKey;
for (sKey in options.headers) {
if (options.headers.hasOwnProperty(sKey)) {
headers[sKey] = options.headers[sKey];
}
}
//
// Generate the cloud request options
//
var _options = {
container : results.container.name,
remote : id,
headers : headers,
metadata : options.meta,
contentType : type
};
var readStream;
if (fromFile)
readStream = fs.createReadStream(source);
else {
readStream = source;
source.resume();
if (source.headers) {
// We want to remove any headers from the source stream so they don't clobber our own headers.
delete source.headers;
}
}
var writeStream = o1._client.upload(_options);
writeStream.on('error', cb);
writeStream.on('success', function (file) {
results.container.count++;
cb(null, results.container.name + '/' + id);
});
readStream.pipe(writeStream);
} | [
"function",
"(",
"err",
",",
"results",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"cb",
"(",
"err",
")",
";",
"}",
"var",
"id",
"=",
"options",
".",
"filename",
"||",
"utils",
".",
"uid",
"(",
"24",
")",
";",
"var",
"headers",
"=",
"{",
"}",
";",
"if",
"(",
"fromFile",
")",
"{",
"headers",
"[",
"'content-length'",
"]",
"=",
"results",
".",
"stats",
".",
"size",
";",
"}",
"else",
"{",
"if",
"(",
"source",
".",
"headers",
"&&",
"source",
".",
"headers",
"[",
"'content-length'",
"]",
")",
"headers",
"[",
"'content-length'",
"]",
"=",
"source",
".",
"headers",
"[",
"'content-length'",
"]",
";",
"else",
"headers",
"[",
"'transfer-encoding'",
"]",
"=",
"'chunked'",
";",
"}",
"var",
"sKey",
";",
"for",
"(",
"sKey",
"in",
"options",
".",
"headers",
")",
"{",
"if",
"(",
"options",
".",
"headers",
".",
"hasOwnProperty",
"(",
"sKey",
")",
")",
"{",
"headers",
"[",
"sKey",
"]",
"=",
"options",
".",
"headers",
"[",
"sKey",
"]",
";",
"}",
"}",
"var",
"_options",
"=",
"{",
"container",
":",
"results",
".",
"container",
".",
"name",
",",
"remote",
":",
"id",
",",
"headers",
":",
"headers",
",",
"metadata",
":",
"options",
".",
"meta",
",",
"contentType",
":",
"type",
"}",
";",
"var",
"readStream",
";",
"if",
"(",
"fromFile",
")",
"readStream",
"=",
"fs",
".",
"createReadStream",
"(",
"source",
")",
";",
"else",
"{",
"readStream",
"=",
"source",
";",
"source",
".",
"resume",
"(",
")",
";",
"if",
"(",
"source",
".",
"headers",
")",
"{",
"delete",
"source",
".",
"headers",
";",
"}",
"}",
"var",
"writeStream",
"=",
"o1",
".",
"_client",
".",
"upload",
"(",
"_options",
")",
";",
"writeStream",
".",
"on",
"(",
"'error'",
",",
"cb",
")",
";",
"writeStream",
".",
"on",
"(",
"'success'",
",",
"function",
"(",
"file",
")",
"{",
"results",
".",
"container",
".",
"count",
"++",
";",
"cb",
"(",
"null",
",",
"results",
".",
"container",
".",
"name",
"+",
"'/'",
"+",
"id",
")",
";",
"}",
")",
";",
"readStream",
".",
"pipe",
"(",
"writeStream",
")",
";",
"}"
] | Final function of parallel.. create the request to add the file | [
"Final",
"function",
"of",
"parallel",
"..",
"create",
"the",
"request",
"to",
"add",
"the",
"file"
] | d5e5184980b00b993ef3eb448c2a5a763b9daf56 | https://github.com/rossj/rackit/blob/d5e5184980b00b993ef3eb448c2a5a763b9daf56/lib/rackit.js#L328-L391 | train |
|
rossj/rackit | lib/rackit.js | function (err) {
var i;
// If the extended option is off, just return cloudpaths
if (!options.extended) {
i = aObjects.length;
while (i--) {
aObjects[i] = aObjects[i].cloudpath;
}
}
cb(err, err ? undefined : aObjects);
} | javascript | function (err) {
var i;
// If the extended option is off, just return cloudpaths
if (!options.extended) {
i = aObjects.length;
while (i--) {
aObjects[i] = aObjects[i].cloudpath;
}
}
cb(err, err ? undefined : aObjects);
} | [
"function",
"(",
"err",
")",
"{",
"var",
"i",
";",
"if",
"(",
"!",
"options",
".",
"extended",
")",
"{",
"i",
"=",
"aObjects",
".",
"length",
";",
"while",
"(",
"i",
"--",
")",
"{",
"aObjects",
"[",
"i",
"]",
"=",
"aObjects",
"[",
"i",
"]",
".",
"cloudpath",
";",
"}",
"}",
"cb",
"(",
"err",
",",
"err",
"?",
"undefined",
":",
"aObjects",
")",
";",
"}"
] | Final function of forEach | [
"Final",
"function",
"of",
"forEach"
] | d5e5184980b00b993ef3eb448c2a5a763b9daf56 | https://github.com/rossj/rackit/blob/d5e5184980b00b993ef3eb448c2a5a763b9daf56/lib/rackit.js#L429-L441 | train |
|
gerardobort/node-corenlp | examples/browser/tree/tree.js | collapse | function collapse(d) {
if (d.children) {
d._children = d.children;
d._children.forEach(collapse);
d.children = null;
}
} | javascript | function collapse(d) {
if (d.children) {
d._children = d.children;
d._children.forEach(collapse);
d.children = null;
}
} | [
"function",
"collapse",
"(",
"d",
")",
"{",
"if",
"(",
"d",
".",
"children",
")",
"{",
"d",
".",
"_children",
"=",
"d",
".",
"children",
";",
"d",
".",
"_children",
".",
"forEach",
"(",
"collapse",
")",
";",
"d",
".",
"children",
"=",
"null",
";",
"}",
"}"
] | Collapse the node and all it's children | [
"Collapse",
"the",
"node",
"and",
"all",
"it",
"s",
"children"
] | c4461168a58950130c904785e6e7386bcebdad09 | https://github.com/gerardobort/node-corenlp/blob/c4461168a58950130c904785e6e7386bcebdad09/examples/browser/tree/tree.js#L89-L95 | train |
gerardobort/node-corenlp | examples/browser/tree/tree.js | click | function click(d) {
if (d.children) {
d._children = d.children;
d.children = null;
} else {
d.children = d._children;
d._children = null;
}
update(d);
} | javascript | function click(d) {
if (d.children) {
d._children = d.children;
d.children = null;
} else {
d.children = d._children;
d._children = null;
}
update(d);
} | [
"function",
"click",
"(",
"d",
")",
"{",
"if",
"(",
"d",
".",
"children",
")",
"{",
"d",
".",
"_children",
"=",
"d",
".",
"children",
";",
"d",
".",
"children",
"=",
"null",
";",
"}",
"else",
"{",
"d",
".",
"children",
"=",
"d",
".",
"_children",
";",
"d",
".",
"_children",
"=",
"null",
";",
"}",
"update",
"(",
"d",
")",
";",
"}"
] | Toggle children on click. | [
"Toggle",
"children",
"on",
"click",
"."
] | c4461168a58950130c904785e6e7386bcebdad09 | https://github.com/gerardobort/node-corenlp/blob/c4461168a58950130c904785e6e7386bcebdad09/examples/browser/tree/tree.js#L225-L234 | train |
relution-io/relution-sdk | lib/core/cipher.js | encryptJson | function encryptJson(password, json) {
return Q.all([
randomBytes(pbkdf2SaltLen),
randomBytes(cipherIvLen)
]).spread(function (salt, iv) {
return pbkdf2(password, salt, pbkdf2Iterations, pbkdf2KeyLen, pbkdf2Digest).then(function (key) {
var cipher = crypto.createCipheriv(cipherAlgorithm, key, iv);
var value = cipher.update(JSON.stringify(json), 'utf8', 'base64');
value += cipher.final('base64');
var data = {
salt: salt.toString('base64'),
iv: iv.toString('base64'),
value: value
};
var tag = cipher.getAuthTag();
if (tag) {
data.tag = tag.toString('base64');
}
return data;
});
});
} | javascript | function encryptJson(password, json) {
return Q.all([
randomBytes(pbkdf2SaltLen),
randomBytes(cipherIvLen)
]).spread(function (salt, iv) {
return pbkdf2(password, salt, pbkdf2Iterations, pbkdf2KeyLen, pbkdf2Digest).then(function (key) {
var cipher = crypto.createCipheriv(cipherAlgorithm, key, iv);
var value = cipher.update(JSON.stringify(json), 'utf8', 'base64');
value += cipher.final('base64');
var data = {
salt: salt.toString('base64'),
iv: iv.toString('base64'),
value: value
};
var tag = cipher.getAuthTag();
if (tag) {
data.tag = tag.toString('base64');
}
return data;
});
});
} | [
"function",
"encryptJson",
"(",
"password",
",",
"json",
")",
"{",
"return",
"Q",
".",
"all",
"(",
"[",
"randomBytes",
"(",
"pbkdf2SaltLen",
")",
",",
"randomBytes",
"(",
"cipherIvLen",
")",
"]",
")",
".",
"spread",
"(",
"function",
"(",
"salt",
",",
"iv",
")",
"{",
"return",
"pbkdf2",
"(",
"password",
",",
"salt",
",",
"pbkdf2Iterations",
",",
"pbkdf2KeyLen",
",",
"pbkdf2Digest",
")",
".",
"then",
"(",
"function",
"(",
"key",
")",
"{",
"var",
"cipher",
"=",
"crypto",
".",
"createCipheriv",
"(",
"cipherAlgorithm",
",",
"key",
",",
"iv",
")",
";",
"var",
"value",
"=",
"cipher",
".",
"update",
"(",
"JSON",
".",
"stringify",
"(",
"json",
")",
",",
"'utf8'",
",",
"'base64'",
")",
";",
"value",
"+=",
"cipher",
".",
"final",
"(",
"'base64'",
")",
";",
"var",
"data",
"=",
"{",
"salt",
":",
"salt",
".",
"toString",
"(",
"'base64'",
")",
",",
"iv",
":",
"iv",
".",
"toString",
"(",
"'base64'",
")",
",",
"value",
":",
"value",
"}",
";",
"var",
"tag",
"=",
"cipher",
".",
"getAuthTag",
"(",
")",
";",
"if",
"(",
"tag",
")",
"{",
"data",
".",
"tag",
"=",
"tag",
".",
"toString",
"(",
"'base64'",
")",
";",
"}",
"return",
"data",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | encrypts a JSON object using a user-provided password.
This method is suitable for human-entered passwords and not appropriate for machine generated
passwords. Make sure to read regarding pbkdf2.
@param password of a human.
@param json to encode.
@return encoded json data.
@internal Not part of public API, exported for library use only. | [
"encrypts",
"a",
"JSON",
"object",
"using",
"a",
"user",
"-",
"provided",
"password",
"."
] | 776b8bd0c249428add03f97ba2d19092e709bc7b | https://github.com/relution-io/relution-sdk/blob/776b8bd0c249428add03f97ba2d19092e709bc7b/lib/core/cipher.js#L52-L73 | train |
relution-io/relution-sdk | lib/core/cipher.js | decryptJson | function decryptJson(password, data) {
var salt = new Buffer(data.salt, 'base64');
return pbkdf2(password, salt, pbkdf2Iterations, pbkdf2KeyLen, pbkdf2Digest).then(function (key) {
var iv = new Buffer(data.iv, 'base64');
var decipher = crypto.createDecipheriv(cipherAlgorithm, key, iv);
var tag = data.tag;
if (tag) {
decipher.setAuthTag(new Buffer(tag, 'base64'));
}
var value = decipher.update(data.value, 'base64', 'utf8');
value += decipher.final('utf8');
return value;
}).then(JSON.parse);
} | javascript | function decryptJson(password, data) {
var salt = new Buffer(data.salt, 'base64');
return pbkdf2(password, salt, pbkdf2Iterations, pbkdf2KeyLen, pbkdf2Digest).then(function (key) {
var iv = new Buffer(data.iv, 'base64');
var decipher = crypto.createDecipheriv(cipherAlgorithm, key, iv);
var tag = data.tag;
if (tag) {
decipher.setAuthTag(new Buffer(tag, 'base64'));
}
var value = decipher.update(data.value, 'base64', 'utf8');
value += decipher.final('utf8');
return value;
}).then(JSON.parse);
} | [
"function",
"decryptJson",
"(",
"password",
",",
"data",
")",
"{",
"var",
"salt",
"=",
"new",
"Buffer",
"(",
"data",
".",
"salt",
",",
"'base64'",
")",
";",
"return",
"pbkdf2",
"(",
"password",
",",
"salt",
",",
"pbkdf2Iterations",
",",
"pbkdf2KeyLen",
",",
"pbkdf2Digest",
")",
".",
"then",
"(",
"function",
"(",
"key",
")",
"{",
"var",
"iv",
"=",
"new",
"Buffer",
"(",
"data",
".",
"iv",
",",
"'base64'",
")",
";",
"var",
"decipher",
"=",
"crypto",
".",
"createDecipheriv",
"(",
"cipherAlgorithm",
",",
"key",
",",
"iv",
")",
";",
"var",
"tag",
"=",
"data",
".",
"tag",
";",
"if",
"(",
"tag",
")",
"{",
"decipher",
".",
"setAuthTag",
"(",
"new",
"Buffer",
"(",
"tag",
",",
"'base64'",
")",
")",
";",
"}",
"var",
"value",
"=",
"decipher",
".",
"update",
"(",
"data",
".",
"value",
",",
"'base64'",
",",
"'utf8'",
")",
";",
"value",
"+=",
"decipher",
".",
"final",
"(",
"'utf8'",
")",
";",
"return",
"value",
";",
"}",
")",
".",
"then",
"(",
"JSON",
".",
"parse",
")",
";",
"}"
] | decrypts some encoded json data.
@param password of a human.
@param data encoded json data.
@return json to decoded.
@internal Not part of public API, exported for library use only. | [
"decrypts",
"some",
"encoded",
"json",
"data",
"."
] | 776b8bd0c249428add03f97ba2d19092e709bc7b | https://github.com/relution-io/relution-sdk/blob/776b8bd0c249428add03f97ba2d19092e709bc7b/lib/core/cipher.js#L84-L97 | train |
banphlet/HubtelMobilePayment | lib/onlinecheckout.js | OnlineCheckout | function OnlineCheckout(body) {
if (!body) throw new Error('No data provided')
const config = this.config
const hubtelurl =
'https://api.hubtel.com/v1/merchantaccount/onlinecheckout/invoice/create'
const auth =
'Basic ' +
Buffer.from(config.clientid + ':' + config.secretid).toString('base64')
return request.post(hubtelurl, {
body: body,
headers: {
Authorization: auth,
'content-type': 'application/json',
},
json: true,
})
} | javascript | function OnlineCheckout(body) {
if (!body) throw new Error('No data provided')
const config = this.config
const hubtelurl =
'https://api.hubtel.com/v1/merchantaccount/onlinecheckout/invoice/create'
const auth =
'Basic ' +
Buffer.from(config.clientid + ':' + config.secretid).toString('base64')
return request.post(hubtelurl, {
body: body,
headers: {
Authorization: auth,
'content-type': 'application/json',
},
json: true,
})
} | [
"function",
"OnlineCheckout",
"(",
"body",
")",
"{",
"if",
"(",
"!",
"body",
")",
"throw",
"new",
"Error",
"(",
"'No data provided'",
")",
"const",
"config",
"=",
"this",
".",
"config",
"const",
"hubtelurl",
"=",
"'https://api.hubtel.com/v1/merchantaccount/onlinecheckout/invoice/create'",
"const",
"auth",
"=",
"'Basic '",
"+",
"Buffer",
".",
"from",
"(",
"config",
".",
"clientid",
"+",
"':'",
"+",
"config",
".",
"secretid",
")",
".",
"toString",
"(",
"'base64'",
")",
"return",
"request",
".",
"post",
"(",
"hubtelurl",
",",
"{",
"body",
":",
"body",
",",
"headers",
":",
"{",
"Authorization",
":",
"auth",
",",
"'content-type'",
":",
"'application/json'",
",",
"}",
",",
"json",
":",
"true",
",",
"}",
")",
"}"
] | Use Hubtel Online Checkout Service
@param {object} body | [
"Use",
"Hubtel",
"Online",
"Checkout",
"Service"
] | 6308e35e0d0c3a1567f94bfee3039f74eee8e480 | https://github.com/banphlet/HubtelMobilePayment/blob/6308e35e0d0c3a1567f94bfee3039f74eee8e480/lib/onlinecheckout.js#L7-L25 | train |
canjs/can-query-logic | compat/compat.js | function(raw){
var clone = canReflect.serialize(raw);
if(clone.page) {
clone[offset] = clone.page.start;
clone[limit] = (clone.page.end - clone.page.start) + 1;
delete clone.page;
}
return clone;
} | javascript | function(raw){
var clone = canReflect.serialize(raw);
if(clone.page) {
clone[offset] = clone.page.start;
clone[limit] = (clone.page.end - clone.page.start) + 1;
delete clone.page;
}
return clone;
} | [
"function",
"(",
"raw",
")",
"{",
"var",
"clone",
"=",
"canReflect",
".",
"serialize",
"(",
"raw",
")",
";",
"if",
"(",
"clone",
".",
"page",
")",
"{",
"clone",
"[",
"offset",
"]",
"=",
"clone",
".",
"page",
".",
"start",
";",
"clone",
"[",
"limit",
"]",
"=",
"(",
"clone",
".",
"page",
".",
"end",
"-",
"clone",
".",
"page",
".",
"start",
")",
"+",
"1",
";",
"delete",
"clone",
".",
"page",
";",
"}",
"return",
"clone",
";",
"}"
] | taking the normal format and putting it back page.start -> start page.end -> end | [
"taking",
"the",
"normal",
"format",
"and",
"putting",
"it",
"back",
"page",
".",
"start",
"-",
">",
"start",
"page",
".",
"end",
"-",
">",
"end"
] | fe32908e7aa36853362fbc1a4df276193247f38d | https://github.com/canjs/can-query-logic/blob/fe32908e7aa36853362fbc1a4df276193247f38d/compat/compat.js#L228-L236 | train |
|
saneki-discontinued/node-toxcore | lib/toxerror.js | ToxError | function ToxError(type, code, message) {
this.name = "ToxError";
this.type = ( type || "ToxError" );
this.code = ( code || 0 ); // 0 = unsuccessful
this.message = ( message || (this.type + ": " + this.code) );
Error.captureStackTrace(this, ToxError);
} | javascript | function ToxError(type, code, message) {
this.name = "ToxError";
this.type = ( type || "ToxError" );
this.code = ( code || 0 ); // 0 = unsuccessful
this.message = ( message || (this.type + ": " + this.code) );
Error.captureStackTrace(this, ToxError);
} | [
"function",
"ToxError",
"(",
"type",
",",
"code",
",",
"message",
")",
"{",
"this",
".",
"name",
"=",
"\"ToxError\"",
";",
"this",
".",
"type",
"=",
"(",
"type",
"||",
"\"ToxError\"",
")",
";",
"this",
".",
"code",
"=",
"(",
"code",
"||",
"0",
")",
";",
"this",
".",
"message",
"=",
"(",
"message",
"||",
"(",
"this",
".",
"type",
"+",
"\": \"",
"+",
"this",
".",
"code",
")",
")",
";",
"Error",
".",
"captureStackTrace",
"(",
"this",
",",
"ToxError",
")",
";",
"}"
] | Creates a ToxError instance
@class
@param {String} type of error
@param {Number} code of type
@param {String} message of error | [
"Creates",
"a",
"ToxError",
"instance"
] | 45dfb339f4e8a58888fca175528dee13f075824a | https://github.com/saneki-discontinued/node-toxcore/blob/45dfb339f4e8a58888fca175528dee13f075824a/lib/toxerror.js#L30-L36 | train |
banphlet/HubtelMobilePayment | lib/checkstatus.js | CheckStatus | function CheckStatus(token) {
if (!token) throw 'Invoice Token must be provided'
const config = this.config
const hubtelurl = `https://api.hubtel.com/v1/merchantaccount/onlinecheckout/invoice/status/${token}`
const auth =
'Basic ' +
Buffer.from(config.clientid + ':' + config.secretid).toString('base64')
return request.get(hubtelurl, {
headers: {
Authorization: auth,
'content-type': 'application/json',
},
json: true,
})
} | javascript | function CheckStatus(token) {
if (!token) throw 'Invoice Token must be provided'
const config = this.config
const hubtelurl = `https://api.hubtel.com/v1/merchantaccount/onlinecheckout/invoice/status/${token}`
const auth =
'Basic ' +
Buffer.from(config.clientid + ':' + config.secretid).toString('base64')
return request.get(hubtelurl, {
headers: {
Authorization: auth,
'content-type': 'application/json',
},
json: true,
})
} | [
"function",
"CheckStatus",
"(",
"token",
")",
"{",
"if",
"(",
"!",
"token",
")",
"throw",
"'Invoice Token must be provided'",
"const",
"config",
"=",
"this",
".",
"config",
"const",
"hubtelurl",
"=",
"`",
"${",
"token",
"}",
"`",
"const",
"auth",
"=",
"'Basic '",
"+",
"Buffer",
".",
"from",
"(",
"config",
".",
"clientid",
"+",
"':'",
"+",
"config",
".",
"secretid",
")",
".",
"toString",
"(",
"'base64'",
")",
"return",
"request",
".",
"get",
"(",
"hubtelurl",
",",
"{",
"headers",
":",
"{",
"Authorization",
":",
"auth",
",",
"'content-type'",
":",
"'application/json'",
",",
"}",
",",
"json",
":",
"true",
",",
"}",
")",
"}"
] | Check the Status of Hubtel online-checkout Transaction
@param {String} token | [
"Check",
"the",
"Status",
"of",
"Hubtel",
"online",
"-",
"checkout",
"Transaction"
] | 6308e35e0d0c3a1567f94bfee3039f74eee8e480 | https://github.com/banphlet/HubtelMobilePayment/blob/6308e35e0d0c3a1567f94bfee3039f74eee8e480/lib/checkstatus.js#L7-L22 | train |
canjs/can-query-logic | src/serializers/basic-query.js | hydrateAndValue | function hydrateAndValue(value, prop, SchemaType, hydrateChild) {
// The `SchemaType` is the type of value on `instances` of
// the schema. `Instances` values are different from `Set` values.
if (SchemaType) {
// If there's a `SetType`, we will use that
var SetType = SchemaType[setTypeSymbol];
if (SetType) {
/// If it exposes a hydrate, this means it can use the current hydrator to
// hydrate its children.
// I'm not sure why it's not taking the `unknown` hydrator instead.
if (SetType.hydrate) {
return SetType.hydrate(value, comparisonsConverter.hydrate);
}
// If the SetType implemented `union`, `intersection`, `difference`
// We can create instances of it directly.
else if (set.hasComparisons(SetType)) {
// Todo ... canReflect.new
return new SetType(value);
}
// If the SetType did not implement the comparison methods,
// it's probably just a "Value" comparison type. We will hydrate
// as a comparison converter, but create an instance of this `"Value"`
// comparison type within the comparison converter.
else {
// inner types
return comparisonsConverter.hydrate(value, function(value) {
return new SetType(value);
});
}
} else {
// There is a `SchemaType`, but it doesn't have a `SetType`.
// Can we create the SetType from the `SchemaType`?
if (makeEnum.canMakeEnumSetType(SchemaType)) {
if (!setTypeMap.has(SchemaType)) {
setTypeMap.set(SchemaType, makeEnum.makeEnumSetType(SchemaType));
}
SetType = setTypeMap.get(SchemaType);
return new SetType(value);
}
// It could also have a `ComparisonSetType` which are the values
// within the Maybe type.
else if (makeMaybe.canMakeMaybeSetType(SchemaType)) {
if (!setTypeMap.has(SchemaType)) {
setTypeMap.set(SchemaType, makeMaybe.makeMaybeSetTypes(SchemaType));
}
SetType = setTypeMap.get(SchemaType).Maybe;
return SetType.hydrate(value, comparisonsConverter.hydrate);
}
// We can't create the `SetType`, so lets hydrate with the default behavior.
else {
return comparisonsConverter.hydrate(value, hydrateChild);
}
}
} else {
// HERE {$gt: 1} -> new is.GreaterThan(1)
return comparisonsConverter.hydrate(value, hydrateChild);
}
} | javascript | function hydrateAndValue(value, prop, SchemaType, hydrateChild) {
// The `SchemaType` is the type of value on `instances` of
// the schema. `Instances` values are different from `Set` values.
if (SchemaType) {
// If there's a `SetType`, we will use that
var SetType = SchemaType[setTypeSymbol];
if (SetType) {
/// If it exposes a hydrate, this means it can use the current hydrator to
// hydrate its children.
// I'm not sure why it's not taking the `unknown` hydrator instead.
if (SetType.hydrate) {
return SetType.hydrate(value, comparisonsConverter.hydrate);
}
// If the SetType implemented `union`, `intersection`, `difference`
// We can create instances of it directly.
else if (set.hasComparisons(SetType)) {
// Todo ... canReflect.new
return new SetType(value);
}
// If the SetType did not implement the comparison methods,
// it's probably just a "Value" comparison type. We will hydrate
// as a comparison converter, but create an instance of this `"Value"`
// comparison type within the comparison converter.
else {
// inner types
return comparisonsConverter.hydrate(value, function(value) {
return new SetType(value);
});
}
} else {
// There is a `SchemaType`, but it doesn't have a `SetType`.
// Can we create the SetType from the `SchemaType`?
if (makeEnum.canMakeEnumSetType(SchemaType)) {
if (!setTypeMap.has(SchemaType)) {
setTypeMap.set(SchemaType, makeEnum.makeEnumSetType(SchemaType));
}
SetType = setTypeMap.get(SchemaType);
return new SetType(value);
}
// It could also have a `ComparisonSetType` which are the values
// within the Maybe type.
else if (makeMaybe.canMakeMaybeSetType(SchemaType)) {
if (!setTypeMap.has(SchemaType)) {
setTypeMap.set(SchemaType, makeMaybe.makeMaybeSetTypes(SchemaType));
}
SetType = setTypeMap.get(SchemaType).Maybe;
return SetType.hydrate(value, comparisonsConverter.hydrate);
}
// We can't create the `SetType`, so lets hydrate with the default behavior.
else {
return comparisonsConverter.hydrate(value, hydrateChild);
}
}
} else {
// HERE {$gt: 1} -> new is.GreaterThan(1)
return comparisonsConverter.hydrate(value, hydrateChild);
}
} | [
"function",
"hydrateAndValue",
"(",
"value",
",",
"prop",
",",
"SchemaType",
",",
"hydrateChild",
")",
"{",
"if",
"(",
"SchemaType",
")",
"{",
"var",
"SetType",
"=",
"SchemaType",
"[",
"setTypeSymbol",
"]",
";",
"if",
"(",
"SetType",
")",
"{",
"if",
"(",
"SetType",
".",
"hydrate",
")",
"{",
"return",
"SetType",
".",
"hydrate",
"(",
"value",
",",
"comparisonsConverter",
".",
"hydrate",
")",
";",
"}",
"else",
"if",
"(",
"set",
".",
"hasComparisons",
"(",
"SetType",
")",
")",
"{",
"return",
"new",
"SetType",
"(",
"value",
")",
";",
"}",
"else",
"{",
"return",
"comparisonsConverter",
".",
"hydrate",
"(",
"value",
",",
"function",
"(",
"value",
")",
"{",
"return",
"new",
"SetType",
"(",
"value",
")",
";",
"}",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"makeEnum",
".",
"canMakeEnumSetType",
"(",
"SchemaType",
")",
")",
"{",
"if",
"(",
"!",
"setTypeMap",
".",
"has",
"(",
"SchemaType",
")",
")",
"{",
"setTypeMap",
".",
"set",
"(",
"SchemaType",
",",
"makeEnum",
".",
"makeEnumSetType",
"(",
"SchemaType",
")",
")",
";",
"}",
"SetType",
"=",
"setTypeMap",
".",
"get",
"(",
"SchemaType",
")",
";",
"return",
"new",
"SetType",
"(",
"value",
")",
";",
"}",
"else",
"if",
"(",
"makeMaybe",
".",
"canMakeMaybeSetType",
"(",
"SchemaType",
")",
")",
"{",
"if",
"(",
"!",
"setTypeMap",
".",
"has",
"(",
"SchemaType",
")",
")",
"{",
"setTypeMap",
".",
"set",
"(",
"SchemaType",
",",
"makeMaybe",
".",
"makeMaybeSetTypes",
"(",
"SchemaType",
")",
")",
";",
"}",
"SetType",
"=",
"setTypeMap",
".",
"get",
"(",
"SchemaType",
")",
".",
"Maybe",
";",
"return",
"SetType",
".",
"hydrate",
"(",
"value",
",",
"comparisonsConverter",
".",
"hydrate",
")",
";",
"}",
"else",
"{",
"return",
"comparisonsConverter",
".",
"hydrate",
"(",
"value",
",",
"hydrateChild",
")",
";",
"}",
"}",
"}",
"else",
"{",
"return",
"comparisonsConverter",
".",
"hydrate",
"(",
"value",
",",
"hydrateChild",
")",
";",
"}",
"}"
] | This is used to hydrate a value directly within a `filter`'s And. | [
"This",
"is",
"used",
"to",
"hydrate",
"a",
"value",
"directly",
"within",
"a",
"filter",
"s",
"And",
"."
] | fe32908e7aa36853362fbc1a4df276193247f38d | https://github.com/canjs/can-query-logic/blob/fe32908e7aa36853362fbc1a4df276193247f38d/src/serializers/basic-query.js#L40-L98 | train |
relution-io/relution-sdk | lib/livedata/SyncContext.spec.js | loadCollection | function loadCollection(collection, data) {
return Q(collection.fetch()).then(function () {
// delete all before running tests
return Q.all(collection.models.slice().map(function (model) {
return model.destroy();
})).then(function () {
chai_1.assert.equal(collection.models.length, 0, 'collection must be empty initially after destroy');
return collection;
});
}).then(function (collection2) {
// load sample data into fresh database
chai_1.assert.equal(collection2, collection, 'same collection object');
return Q.all(data.map(function (attrs) {
return new TestModel(attrs, {
collection: collection2
}).save();
})).then(function () {
chai_1.assert.equal(collection2.models.length, data.length, 'collection was updated by async events');
return collection2;
});
});
} | javascript | function loadCollection(collection, data) {
return Q(collection.fetch()).then(function () {
// delete all before running tests
return Q.all(collection.models.slice().map(function (model) {
return model.destroy();
})).then(function () {
chai_1.assert.equal(collection.models.length, 0, 'collection must be empty initially after destroy');
return collection;
});
}).then(function (collection2) {
// load sample data into fresh database
chai_1.assert.equal(collection2, collection, 'same collection object');
return Q.all(data.map(function (attrs) {
return new TestModel(attrs, {
collection: collection2
}).save();
})).then(function () {
chai_1.assert.equal(collection2.models.length, data.length, 'collection was updated by async events');
return collection2;
});
});
} | [
"function",
"loadCollection",
"(",
"collection",
",",
"data",
")",
"{",
"return",
"Q",
"(",
"collection",
".",
"fetch",
"(",
")",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"return",
"Q",
".",
"all",
"(",
"collection",
".",
"models",
".",
"slice",
"(",
")",
".",
"map",
"(",
"function",
"(",
"model",
")",
"{",
"return",
"model",
".",
"destroy",
"(",
")",
";",
"}",
")",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"chai_1",
".",
"assert",
".",
"equal",
"(",
"collection",
".",
"models",
".",
"length",
",",
"0",
",",
"'collection must be empty initially after destroy'",
")",
";",
"return",
"collection",
";",
"}",
")",
";",
"}",
")",
".",
"then",
"(",
"function",
"(",
"collection2",
")",
"{",
"chai_1",
".",
"assert",
".",
"equal",
"(",
"collection2",
",",
"collection",
",",
"'same collection object'",
")",
";",
"return",
"Q",
".",
"all",
"(",
"data",
".",
"map",
"(",
"function",
"(",
"attrs",
")",
"{",
"return",
"new",
"TestModel",
"(",
"attrs",
",",
"{",
"collection",
":",
"collection2",
"}",
")",
".",
"save",
"(",
")",
";",
"}",
")",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"chai_1",
".",
"assert",
".",
"equal",
"(",
"collection2",
".",
"models",
".",
"length",
",",
"data",
".",
"length",
",",
"'collection was updated by async events'",
")",
";",
"return",
"collection2",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | loads data using collection, returns promise on collection, collection is empty afterwards | [
"loads",
"data",
"using",
"collection",
"returns",
"promise",
"on",
"collection",
"collection",
"is",
"empty",
"afterwards"
] | 776b8bd0c249428add03f97ba2d19092e709bc7b | https://github.com/relution-io/relution-sdk/blob/776b8bd0c249428add03f97ba2d19092e709bc7b/lib/livedata/SyncContext.spec.js#L71-L92 | train |
hhff/ember-chimp | addon/components/ember-chimp.js | endsWith | function endsWith(string, suffix) {
return string.indexOf(suffix, string.length - suffix.length) !== -1;
} | javascript | function endsWith(string, suffix) {
return string.indexOf(suffix, string.length - suffix.length) !== -1;
} | [
"function",
"endsWith",
"(",
"string",
",",
"suffix",
")",
"{",
"return",
"string",
".",
"indexOf",
"(",
"suffix",
",",
"string",
".",
"length",
"-",
"suffix",
".",
"length",
")",
"!==",
"-",
"1",
";",
"}"
] | A utility method for checking the end of a string
for a certain value.
@method endsWith
@param {String} string The string to check.
@param {String} suffix The suffix to check the string for.
@private
@return {Boolean} A boolean that indicates whether the suffix is present. | [
"A",
"utility",
"method",
"for",
"checking",
"the",
"end",
"of",
"a",
"string",
"for",
"a",
"certain",
"value",
"."
] | 796a737f58965f16ad574df19c44f77eca528df1 | https://github.com/hhff/ember-chimp/blob/796a737f58965f16ad574df19c44f77eca528df1/addon/components/ember-chimp.js#L22-L24 | train |
peerigon/erroz | lib/defaultRenderer.js | defaultRenderer | function defaultRenderer(template, data) {
return template.replace(/%\w+/g, function (match) {
return data[match.slice(1)];
});
} | javascript | function defaultRenderer(template, data) {
return template.replace(/%\w+/g, function (match) {
return data[match.slice(1)];
});
} | [
"function",
"defaultRenderer",
"(",
"template",
",",
"data",
")",
"{",
"return",
"template",
".",
"replace",
"(",
"/",
"%\\w+",
"/",
"g",
",",
"function",
"(",
"match",
")",
"{",
"return",
"data",
"[",
"match",
".",
"slice",
"(",
"1",
")",
"]",
";",
"}",
")",
";",
"}"
] | replaces all %placeHolder with data.placeHolder
@param {String} template
@param {Object} data
@returns {String} | [
"replaces",
"all",
"%placeHolder",
"with",
"data",
".",
"placeHolder"
] | 57adf5fa7a86680da2c6460b81aaaceaa57db6bd | https://github.com/peerigon/erroz/blob/57adf5fa7a86680da2c6460b81aaaceaa57db6bd/lib/defaultRenderer.js#L10-L14 | train |
relution-io/relution-sdk | lib/core/objectid.js | makeObjectID | function makeObjectID() {
return hexString(8, Date.now() / 1000) +
hexString(6, machineId) +
hexString(4, processId) +
hexString(6, counter++); // a 3-byte counter, starting with a random value.
} | javascript | function makeObjectID() {
return hexString(8, Date.now() / 1000) +
hexString(6, machineId) +
hexString(4, processId) +
hexString(6, counter++); // a 3-byte counter, starting with a random value.
} | [
"function",
"makeObjectID",
"(",
")",
"{",
"return",
"hexString",
"(",
"8",
",",
"Date",
".",
"now",
"(",
")",
"/",
"1000",
")",
"+",
"hexString",
"(",
"6",
",",
"machineId",
")",
"+",
"hexString",
"(",
"4",
",",
"processId",
")",
"+",
"hexString",
"(",
"6",
",",
"counter",
"++",
")",
";",
"}"
] | random-based impl of Mongo ObjectID | [
"random",
"-",
"based",
"impl",
"of",
"Mongo",
"ObjectID"
] | 776b8bd0c249428add03f97ba2d19092e709bc7b | https://github.com/relution-io/relution-sdk/blob/776b8bd0c249428add03f97ba2d19092e709bc7b/lib/core/objectid.js#L36-L41 | train |
fergiemcdowall/search-index-adder | lib/delete.js | function (key) {
if (key === undefined) {
that.push({
key: 'DOCUMENT' + sep + docId + sep,
lastPass: true
})
return end()
}
that.options.indexes.get(key, function (err, val) {
if (!err) {
that.push({
key: key,
value: val
})
}
pushValue(docFields[i++])
})
} | javascript | function (key) {
if (key === undefined) {
that.push({
key: 'DOCUMENT' + sep + docId + sep,
lastPass: true
})
return end()
}
that.options.indexes.get(key, function (err, val) {
if (!err) {
that.push({
key: key,
value: val
})
}
pushValue(docFields[i++])
})
} | [
"function",
"(",
"key",
")",
"{",
"if",
"(",
"key",
"===",
"undefined",
")",
"{",
"that",
".",
"push",
"(",
"{",
"key",
":",
"'DOCUMENT'",
"+",
"sep",
"+",
"docId",
"+",
"sep",
",",
"lastPass",
":",
"true",
"}",
")",
"return",
"end",
"(",
")",
"}",
"that",
".",
"options",
".",
"indexes",
".",
"get",
"(",
"key",
",",
"function",
"(",
"err",
",",
"val",
")",
"{",
"if",
"(",
"!",
"err",
")",
"{",
"that",
".",
"push",
"(",
"{",
"key",
":",
"key",
",",
"value",
":",
"val",
"}",
")",
"}",
"pushValue",
"(",
"docFields",
"[",
"i",
"++",
"]",
")",
"}",
")",
"}"
] | get value from db and push it to the stream | [
"get",
"value",
"from",
"db",
"and",
"push",
"it",
"to",
"the",
"stream"
] | 5c0fc40fbff4bb4912a5e8ba542cb88a650efd11 | https://github.com/fergiemcdowall/search-index-adder/blob/5c0fc40fbff4bb4912a5e8ba542cb88a650efd11/lib/delete.js#L43-L60 | train |
|
relution-io/relution-sdk | server/mongodb_rest.js | function(req, res, fromMessage) {
var name = req.params.name;
var doc = req.body;
var id = this.toId(req.params.id || doc._id);
if (typeof id === 'undefined' || id === '') {
return res.send(400, "invalid id.");
}
doc._id = id;
doc._time = new Date().getTime();
var collection = new mongodb.Collection(this.db, name);
collection.update(
{ "_id" : id },
doc,
{ safe:true, upsert:true },
function(err, n) {
if(err) {
res.send("Oops!: " + err);
} else {
if (n==0) {
res.send(404, 'Document not found!');
} else {
var msg = {
method: 'update',
id: doc._id,
time: doc._time,
data: doc
};
rest.onSuccess(name, msg, fromMessage);
res.send(doc);
}
}
}
);
} | javascript | function(req, res, fromMessage) {
var name = req.params.name;
var doc = req.body;
var id = this.toId(req.params.id || doc._id);
if (typeof id === 'undefined' || id === '') {
return res.send(400, "invalid id.");
}
doc._id = id;
doc._time = new Date().getTime();
var collection = new mongodb.Collection(this.db, name);
collection.update(
{ "_id" : id },
doc,
{ safe:true, upsert:true },
function(err, n) {
if(err) {
res.send("Oops!: " + err);
} else {
if (n==0) {
res.send(404, 'Document not found!');
} else {
var msg = {
method: 'update',
id: doc._id,
time: doc._time,
data: doc
};
rest.onSuccess(name, msg, fromMessage);
res.send(doc);
}
}
}
);
} | [
"function",
"(",
"req",
",",
"res",
",",
"fromMessage",
")",
"{",
"var",
"name",
"=",
"req",
".",
"params",
".",
"name",
";",
"var",
"doc",
"=",
"req",
".",
"body",
";",
"var",
"id",
"=",
"this",
".",
"toId",
"(",
"req",
".",
"params",
".",
"id",
"||",
"doc",
".",
"_id",
")",
";",
"if",
"(",
"typeof",
"id",
"===",
"'undefined'",
"||",
"id",
"===",
"''",
")",
"{",
"return",
"res",
".",
"send",
"(",
"400",
",",
"\"invalid id.\"",
")",
";",
"}",
"doc",
".",
"_id",
"=",
"id",
";",
"doc",
".",
"_time",
"=",
"new",
"Date",
"(",
")",
".",
"getTime",
"(",
")",
";",
"var",
"collection",
"=",
"new",
"mongodb",
".",
"Collection",
"(",
"this",
".",
"db",
",",
"name",
")",
";",
"collection",
".",
"update",
"(",
"{",
"\"_id\"",
":",
"id",
"}",
",",
"doc",
",",
"{",
"safe",
":",
"true",
",",
"upsert",
":",
"true",
"}",
",",
"function",
"(",
"err",
",",
"n",
")",
"{",
"if",
"(",
"err",
")",
"{",
"res",
".",
"send",
"(",
"\"Oops!: \"",
"+",
"err",
")",
";",
"}",
"else",
"{",
"if",
"(",
"n",
"==",
"0",
")",
"{",
"res",
".",
"send",
"(",
"404",
",",
"'Document not found!'",
")",
";",
"}",
"else",
"{",
"var",
"msg",
"=",
"{",
"method",
":",
"'update'",
",",
"id",
":",
"doc",
".",
"_id",
",",
"time",
":",
"doc",
".",
"_time",
",",
"data",
":",
"doc",
"}",
";",
"rest",
".",
"onSuccess",
"(",
"name",
",",
"msg",
",",
"fromMessage",
")",
";",
"res",
".",
"send",
"(",
"doc",
")",
";",
"}",
"}",
"}",
")",
";",
"}"
] | Update a document | [
"Update",
"a",
"document"
] | 776b8bd0c249428add03f97ba2d19092e709bc7b | https://github.com/relution-io/relution-sdk/blob/776b8bd0c249428add03f97ba2d19092e709bc7b/server/mongodb_rest.js#L185-L218 | train |
|
relution-io/relution-sdk | server/mongodb_rest.js | function(req, res, fromMessage) {
var name = req.params.name;
var id = this.toId(req.params.id);
if (typeof id === 'undefined' || id === '') {
return res.send(400, "invalid id.");
}
var doc = {};
doc._id = id;
doc._time = new Date().getTime();
var collection = new mongodb.Collection(this.db, name);
if (id === 'all' || id === 'clean') {
collection.drop(function (err) {
if(err) {
res.send(400, err);
} else {
var msg = {
method: 'delete',
id: doc._id,
time: doc._time
};
rest.onSuccess(name, msg, fromMessage);
res.send(doc);
}
});
} else {
collection.remove({ "_id" : id }, { }, function(err, n){
if(err) {
res.send(400, err);
} else {
if (n==0) {
res.send(404, 'Document not found!');
}
if (n > 0) {
var msg = {
method: 'delete',
id: doc._id,
time: doc._time,
data: doc
};
rest.onSuccess(name, msg, fromMessage);
res.send(doc);
}
}
}
);
}
} | javascript | function(req, res, fromMessage) {
var name = req.params.name;
var id = this.toId(req.params.id);
if (typeof id === 'undefined' || id === '') {
return res.send(400, "invalid id.");
}
var doc = {};
doc._id = id;
doc._time = new Date().getTime();
var collection = new mongodb.Collection(this.db, name);
if (id === 'all' || id === 'clean') {
collection.drop(function (err) {
if(err) {
res.send(400, err);
} else {
var msg = {
method: 'delete',
id: doc._id,
time: doc._time
};
rest.onSuccess(name, msg, fromMessage);
res.send(doc);
}
});
} else {
collection.remove({ "_id" : id }, { }, function(err, n){
if(err) {
res.send(400, err);
} else {
if (n==0) {
res.send(404, 'Document not found!');
}
if (n > 0) {
var msg = {
method: 'delete',
id: doc._id,
time: doc._time,
data: doc
};
rest.onSuccess(name, msg, fromMessage);
res.send(doc);
}
}
}
);
}
} | [
"function",
"(",
"req",
",",
"res",
",",
"fromMessage",
")",
"{",
"var",
"name",
"=",
"req",
".",
"params",
".",
"name",
";",
"var",
"id",
"=",
"this",
".",
"toId",
"(",
"req",
".",
"params",
".",
"id",
")",
";",
"if",
"(",
"typeof",
"id",
"===",
"'undefined'",
"||",
"id",
"===",
"''",
")",
"{",
"return",
"res",
".",
"send",
"(",
"400",
",",
"\"invalid id.\"",
")",
";",
"}",
"var",
"doc",
"=",
"{",
"}",
";",
"doc",
".",
"_id",
"=",
"id",
";",
"doc",
".",
"_time",
"=",
"new",
"Date",
"(",
")",
".",
"getTime",
"(",
")",
";",
"var",
"collection",
"=",
"new",
"mongodb",
".",
"Collection",
"(",
"this",
".",
"db",
",",
"name",
")",
";",
"if",
"(",
"id",
"===",
"'all'",
"||",
"id",
"===",
"'clean'",
")",
"{",
"collection",
".",
"drop",
"(",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"res",
".",
"send",
"(",
"400",
",",
"err",
")",
";",
"}",
"else",
"{",
"var",
"msg",
"=",
"{",
"method",
":",
"'delete'",
",",
"id",
":",
"doc",
".",
"_id",
",",
"time",
":",
"doc",
".",
"_time",
"}",
";",
"rest",
".",
"onSuccess",
"(",
"name",
",",
"msg",
",",
"fromMessage",
")",
";",
"res",
".",
"send",
"(",
"doc",
")",
";",
"}",
"}",
")",
";",
"}",
"else",
"{",
"collection",
".",
"remove",
"(",
"{",
"\"_id\"",
":",
"id",
"}",
",",
"{",
"}",
",",
"function",
"(",
"err",
",",
"n",
")",
"{",
"if",
"(",
"err",
")",
"{",
"res",
".",
"send",
"(",
"400",
",",
"err",
")",
";",
"}",
"else",
"{",
"if",
"(",
"n",
"==",
"0",
")",
"{",
"res",
".",
"send",
"(",
"404",
",",
"'Document not found!'",
")",
";",
"}",
"if",
"(",
"n",
">",
"0",
")",
"{",
"var",
"msg",
"=",
"{",
"method",
":",
"'delete'",
",",
"id",
":",
"doc",
".",
"_id",
",",
"time",
":",
"doc",
".",
"_time",
",",
"data",
":",
"doc",
"}",
";",
"rest",
".",
"onSuccess",
"(",
"name",
",",
"msg",
",",
"fromMessage",
")",
";",
"res",
".",
"send",
"(",
"doc",
")",
";",
"}",
"}",
"}",
")",
";",
"}",
"}"
] | Delete a contact | [
"Delete",
"a",
"contact"
] | 776b8bd0c249428add03f97ba2d19092e709bc7b | https://github.com/relution-io/relution-sdk/blob/776b8bd0c249428add03f97ba2d19092e709bc7b/server/mongodb_rest.js#L221-L267 | train |
|
relution-io/relution-sdk | server/mongodb_rest.js | function(entity, msg) {
if (!msg._id) {
msg._id = new ObjectID();
}
var collection = new mongodb.Collection(this.db, "__msg__" + entity);
if (msg.method === 'delete' && (msg.id === 'all' || msg.id === 'clean')) {
collection.remove(function () {
if (msg.id === 'all') {
collection.insert(msg, { safe: false } );
}
});
} else {
collection.insert(msg, { safe: false } );
}
} | javascript | function(entity, msg) {
if (!msg._id) {
msg._id = new ObjectID();
}
var collection = new mongodb.Collection(this.db, "__msg__" + entity);
if (msg.method === 'delete' && (msg.id === 'all' || msg.id === 'clean')) {
collection.remove(function () {
if (msg.id === 'all') {
collection.insert(msg, { safe: false } );
}
});
} else {
collection.insert(msg, { safe: false } );
}
} | [
"function",
"(",
"entity",
",",
"msg",
")",
"{",
"if",
"(",
"!",
"msg",
".",
"_id",
")",
"{",
"msg",
".",
"_id",
"=",
"new",
"ObjectID",
"(",
")",
";",
"}",
"var",
"collection",
"=",
"new",
"mongodb",
".",
"Collection",
"(",
"this",
".",
"db",
",",
"\"__msg__\"",
"+",
"entity",
")",
";",
"if",
"(",
"msg",
".",
"method",
"===",
"'delete'",
"&&",
"(",
"msg",
".",
"id",
"===",
"'all'",
"||",
"msg",
".",
"id",
"===",
"'clean'",
")",
")",
"{",
"collection",
".",
"remove",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"msg",
".",
"id",
"===",
"'all'",
")",
"{",
"collection",
".",
"insert",
"(",
"msg",
",",
"{",
"safe",
":",
"false",
"}",
")",
";",
"}",
"}",
")",
";",
"}",
"else",
"{",
"collection",
".",
"insert",
"(",
"msg",
",",
"{",
"safe",
":",
"false",
"}",
")",
";",
"}",
"}"
] | save a new change message | [
"save",
"a",
"new",
"change",
"message"
] | 776b8bd0c249428add03f97ba2d19092e709bc7b | https://github.com/relution-io/relution-sdk/blob/776b8bd0c249428add03f97ba2d19092e709bc7b/server/mongodb_rest.js#L270-L284 | train |
|
relution-io/relution-sdk | server/mongodb_rest.js | function(entity, time, callback) {
var collection = new mongodb.Collection(this.db, "__msg__" + entity);
time = parseInt(time);
if (time || time === 0) {
collection.ensureIndex(
{ time: 1, id: 1 },
{ unique:true, background:true, w:1 },
function(err, indexName) {
var cursor = collection.find({ time: { $gt: time } });
var id, lastMsg;
cursor.sort([['id', 1], ['time', 1]]).each(function(err, msg) {
if (msg && msg.id) {
// the same id, merge document
if (id && id === msg.id) {
if (lastMsg) {
msg = rest.mergeMessage(lastMsg, msg);
}
} else if (lastMsg) {
// send the document to the client
callback(lastMsg);
}
lastMsg = msg;
id = msg.id;
} else {
if (lastMsg) {
callback(lastMsg);
}
callback(null);
}
});
}
);
} else {
callback(null);
}
} | javascript | function(entity, time, callback) {
var collection = new mongodb.Collection(this.db, "__msg__" + entity);
time = parseInt(time);
if (time || time === 0) {
collection.ensureIndex(
{ time: 1, id: 1 },
{ unique:true, background:true, w:1 },
function(err, indexName) {
var cursor = collection.find({ time: { $gt: time } });
var id, lastMsg;
cursor.sort([['id', 1], ['time', 1]]).each(function(err, msg) {
if (msg && msg.id) {
// the same id, merge document
if (id && id === msg.id) {
if (lastMsg) {
msg = rest.mergeMessage(lastMsg, msg);
}
} else if (lastMsg) {
// send the document to the client
callback(lastMsg);
}
lastMsg = msg;
id = msg.id;
} else {
if (lastMsg) {
callback(lastMsg);
}
callback(null);
}
});
}
);
} else {
callback(null);
}
} | [
"function",
"(",
"entity",
",",
"time",
",",
"callback",
")",
"{",
"var",
"collection",
"=",
"new",
"mongodb",
".",
"Collection",
"(",
"this",
".",
"db",
",",
"\"__msg__\"",
"+",
"entity",
")",
";",
"time",
"=",
"parseInt",
"(",
"time",
")",
";",
"if",
"(",
"time",
"||",
"time",
"===",
"0",
")",
"{",
"collection",
".",
"ensureIndex",
"(",
"{",
"time",
":",
"1",
",",
"id",
":",
"1",
"}",
",",
"{",
"unique",
":",
"true",
",",
"background",
":",
"true",
",",
"w",
":",
"1",
"}",
",",
"function",
"(",
"err",
",",
"indexName",
")",
"{",
"var",
"cursor",
"=",
"collection",
".",
"find",
"(",
"{",
"time",
":",
"{",
"$gt",
":",
"time",
"}",
"}",
")",
";",
"var",
"id",
",",
"lastMsg",
";",
"cursor",
".",
"sort",
"(",
"[",
"[",
"'id'",
",",
"1",
"]",
",",
"[",
"'time'",
",",
"1",
"]",
"]",
")",
".",
"each",
"(",
"function",
"(",
"err",
",",
"msg",
")",
"{",
"if",
"(",
"msg",
"&&",
"msg",
".",
"id",
")",
"{",
"if",
"(",
"id",
"&&",
"id",
"===",
"msg",
".",
"id",
")",
"{",
"if",
"(",
"lastMsg",
")",
"{",
"msg",
"=",
"rest",
".",
"mergeMessage",
"(",
"lastMsg",
",",
"msg",
")",
";",
"}",
"}",
"else",
"if",
"(",
"lastMsg",
")",
"{",
"callback",
"(",
"lastMsg",
")",
";",
"}",
"lastMsg",
"=",
"msg",
";",
"id",
"=",
"msg",
".",
"id",
";",
"}",
"else",
"{",
"if",
"(",
"lastMsg",
")",
"{",
"callback",
"(",
"lastMsg",
")",
";",
"}",
"callback",
"(",
"null",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"callback",
"(",
"null",
")",
";",
"}",
"}"
] | read the change message, since time | [
"read",
"the",
"change",
"message",
"since",
"time"
] | 776b8bd0c249428add03f97ba2d19092e709bc7b | https://github.com/relution-io/relution-sdk/blob/776b8bd0c249428add03f97ba2d19092e709bc7b/server/mongodb_rest.js#L287-L322 | train |
|
relution-io/relution-sdk | lib/livedata/SyncEndpoint.js | hashCode | function hashCode() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i - 0] = arguments[_i];
}
var hash = 0;
for (var i = 0; i < args.length; ++i) {
var str = args[i] || '';
for (var j = 0, l = str.length; j < l; ++j) {
var char = str.charCodeAt(j);
hash = ((hash << 5) - hash) + char;
hash |= 0; // Convert to 32bit integer
}
}
return hash;
} | javascript | function hashCode() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i - 0] = arguments[_i];
}
var hash = 0;
for (var i = 0; i < args.length; ++i) {
var str = args[i] || '';
for (var j = 0, l = str.length; j < l; ++j) {
var char = str.charCodeAt(j);
hash = ((hash << 5) - hash) + char;
hash |= 0; // Convert to 32bit integer
}
}
return hash;
} | [
"function",
"hashCode",
"(",
")",
"{",
"var",
"args",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"_i",
"=",
"0",
";",
"_i",
"<",
"arguments",
".",
"length",
";",
"_i",
"++",
")",
"{",
"args",
"[",
"_i",
"-",
"0",
"]",
"=",
"arguments",
"[",
"_i",
"]",
";",
"}",
"var",
"hash",
"=",
"0",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"args",
".",
"length",
";",
"++",
"i",
")",
"{",
"var",
"str",
"=",
"args",
"[",
"i",
"]",
"||",
"''",
";",
"for",
"(",
"var",
"j",
"=",
"0",
",",
"l",
"=",
"str",
".",
"length",
";",
"j",
"<",
"l",
";",
"++",
"j",
")",
"{",
"var",
"char",
"=",
"str",
".",
"charCodeAt",
"(",
"j",
")",
";",
"hash",
"=",
"(",
"(",
"hash",
"<<",
"5",
")",
"-",
"hash",
")",
"+",
"char",
";",
"hash",
"|=",
"0",
";",
"}",
"}",
"return",
"hash",
";",
"}"
] | very simple hash coding implementation.
@internal For library use only. | [
"very",
"simple",
"hash",
"coding",
"implementation",
"."
] | 776b8bd0c249428add03f97ba2d19092e709bc7b | https://github.com/relution-io/relution-sdk/blob/776b8bd0c249428add03f97ba2d19092e709bc7b/lib/livedata/SyncEndpoint.js#L31-L46 | train |
flumedb/aligned-block-file | blocks.js | readInteger | function readInteger(width, reader) {
return function (start, cb) {
var i = Math.floor(start/block_size)
var _i = start%block_size
//if the UInt32BE aligns with in a block
//read directly and it's 3x faster.
if(_i < block_size - width)
get(i, function (err, block) {
if(err) return cb(err)
var value = reader(block, start%block_size)
cb(null, value)
})
//but handle overlapping reads this easier way
//instead of messing around with bitwise ops
else
read(start, start+width, function (err, buf, bytes_read) {
if(err) return cb(err)
var value = reader(buf, 0);
cb(isNaN(value) ? new Error('Number is too large') : null, value)
})
}
} | javascript | function readInteger(width, reader) {
return function (start, cb) {
var i = Math.floor(start/block_size)
var _i = start%block_size
//if the UInt32BE aligns with in a block
//read directly and it's 3x faster.
if(_i < block_size - width)
get(i, function (err, block) {
if(err) return cb(err)
var value = reader(block, start%block_size)
cb(null, value)
})
//but handle overlapping reads this easier way
//instead of messing around with bitwise ops
else
read(start, start+width, function (err, buf, bytes_read) {
if(err) return cb(err)
var value = reader(buf, 0);
cb(isNaN(value) ? new Error('Number is too large') : null, value)
})
}
} | [
"function",
"readInteger",
"(",
"width",
",",
"reader",
")",
"{",
"return",
"function",
"(",
"start",
",",
"cb",
")",
"{",
"var",
"i",
"=",
"Math",
".",
"floor",
"(",
"start",
"/",
"block_size",
")",
"var",
"_i",
"=",
"start",
"%",
"block_size",
"if",
"(",
"_i",
"<",
"block_size",
"-",
"width",
")",
"get",
"(",
"i",
",",
"function",
"(",
"err",
",",
"block",
")",
"{",
"if",
"(",
"err",
")",
"return",
"cb",
"(",
"err",
")",
"var",
"value",
"=",
"reader",
"(",
"block",
",",
"start",
"%",
"block_size",
")",
"cb",
"(",
"null",
",",
"value",
")",
"}",
")",
"else",
"read",
"(",
"start",
",",
"start",
"+",
"width",
",",
"function",
"(",
"err",
",",
"buf",
",",
"bytes_read",
")",
"{",
"if",
"(",
"err",
")",
"return",
"cb",
"(",
"err",
")",
"var",
"value",
"=",
"reader",
"(",
"buf",
",",
"0",
")",
";",
"cb",
"(",
"isNaN",
"(",
"value",
")",
"?",
"new",
"Error",
"(",
"'Number is too large'",
")",
":",
"null",
",",
"value",
")",
"}",
")",
"}",
"}"
] | start by reading the end of the last block. this must always be kept in memory. | [
"start",
"by",
"reading",
"the",
"end",
"of",
"the",
"last",
"block",
".",
"this",
"must",
"always",
"be",
"kept",
"in",
"memory",
"."
] | 5361e46459f0836e2c8ec597d795c42a1a783d91 | https://github.com/flumedb/aligned-block-file/blob/5361e46459f0836e2c8ec597d795c42a1a783d91/blocks.js#L85-L107 | train |
relution-io/relution-sdk | server/backend/routes/push.js | init | function init(app) {
app.post('/api/v1/push/registration',
/**
* register the device on the push Service
*
* @param req containing body JSON to pass as input.
* @param res result of call is provided as JSON body data.
* @param next function to invoke error handling.
*/
function serviceCall(req, res, next) {
Q(pushService.registerPushDevice(req.body)).then(res.json.bind(res), next).done();
});
app.post('/api/v1/push',
/**
* posts push notification(s).
*
* @param req containing body JSON to pass as input.
* @param res result of call is provided as JSON body data.
* @param next function to invoke error handling.
*/
function serviceCall(req, res, next) {
Q(pushService.postPushNotification(req.body)).then(res.json.bind(res), next).done();
});
app.get('/api/v1/push/:uuid',
/**
* gets push notification status.
*
* @param req containing body JSON to pass as input.
* @param res result of call is provided as JSON body data.
* @param next function to invoke error handling.
*/
function serviceCall(req, res, next) {
Q(pushService.fetchPushNotification(req.params.uuid)).then(res.json.bind(res), next).done();
});
} | javascript | function init(app) {
app.post('/api/v1/push/registration',
/**
* register the device on the push Service
*
* @param req containing body JSON to pass as input.
* @param res result of call is provided as JSON body data.
* @param next function to invoke error handling.
*/
function serviceCall(req, res, next) {
Q(pushService.registerPushDevice(req.body)).then(res.json.bind(res), next).done();
});
app.post('/api/v1/push',
/**
* posts push notification(s).
*
* @param req containing body JSON to pass as input.
* @param res result of call is provided as JSON body data.
* @param next function to invoke error handling.
*/
function serviceCall(req, res, next) {
Q(pushService.postPushNotification(req.body)).then(res.json.bind(res), next).done();
});
app.get('/api/v1/push/:uuid',
/**
* gets push notification status.
*
* @param req containing body JSON to pass as input.
* @param res result of call is provided as JSON body data.
* @param next function to invoke error handling.
*/
function serviceCall(req, res, next) {
Q(pushService.fetchPushNotification(req.params.uuid)).then(res.json.bind(res), next).done();
});
} | [
"function",
"init",
"(",
"app",
")",
"{",
"app",
".",
"post",
"(",
"'/api/v1/push/registration'",
",",
"function",
"serviceCall",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"Q",
"(",
"pushService",
".",
"registerPushDevice",
"(",
"req",
".",
"body",
")",
")",
".",
"then",
"(",
"res",
".",
"json",
".",
"bind",
"(",
"res",
")",
",",
"next",
")",
".",
"done",
"(",
")",
";",
"}",
")",
";",
"app",
".",
"post",
"(",
"'/api/v1/push'",
",",
"function",
"serviceCall",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"Q",
"(",
"pushService",
".",
"postPushNotification",
"(",
"req",
".",
"body",
")",
")",
".",
"then",
"(",
"res",
".",
"json",
".",
"bind",
"(",
"res",
")",
",",
"next",
")",
".",
"done",
"(",
")",
";",
"}",
")",
";",
"app",
".",
"get",
"(",
"'/api/v1/push/:uuid'",
",",
"function",
"serviceCall",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"Q",
"(",
"pushService",
".",
"fetchPushNotification",
"(",
"req",
".",
"params",
".",
"uuid",
")",
")",
".",
"then",
"(",
"res",
".",
"json",
".",
"bind",
"(",
"res",
")",
",",
"next",
")",
".",
"done",
"(",
")",
";",
"}",
")",
";",
"}"
] | module providing direct access to push.
registers a push target device.
<p>
The method attempts fetching an existing device using the metadata
information given. This either works by providing a UUID or using
heuristics based on information typically extracted using Cordova device
plugin. The latter approach solves the potential problem when the client
is uninstalled and reinstalled so that device local information is lost.
</p>
<p>
If it finds one, that device is updated. Otherwise a new
device is created and stored in the database.
</p>
@link [RelutionSDK Push APi](https://relution-io.github.io/relution-sdk/modules/_push_push_.html)
@param app express.js application to hook into. | [
"module",
"providing",
"direct",
"access",
"to",
"push",
"."
] | 776b8bd0c249428add03f97ba2d19092e709bc7b | https://github.com/relution-io/relution-sdk/blob/776b8bd0c249428add03f97ba2d19092e709bc7b/server/backend/routes/push.js#L24-L58 | train |
relution-io/relution-sdk | server/backend/routes/push.js | serviceCall | function serviceCall(req, res, next) {
Q(pushService.registerPushDevice(req.body)).then(res.json.bind(res), next).done();
} | javascript | function serviceCall(req, res, next) {
Q(pushService.registerPushDevice(req.body)).then(res.json.bind(res), next).done();
} | [
"function",
"serviceCall",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"Q",
"(",
"pushService",
".",
"registerPushDevice",
"(",
"req",
".",
"body",
")",
")",
".",
"then",
"(",
"res",
".",
"json",
".",
"bind",
"(",
"res",
")",
",",
"next",
")",
".",
"done",
"(",
")",
";",
"}"
] | register the device on the push Service
@param req containing body JSON to pass as input.
@param res result of call is provided as JSON body data.
@param next function to invoke error handling. | [
"register",
"the",
"device",
"on",
"the",
"push",
"Service"
] | 776b8bd0c249428add03f97ba2d19092e709bc7b | https://github.com/relution-io/relution-sdk/blob/776b8bd0c249428add03f97ba2d19092e709bc7b/server/backend/routes/push.js#L33-L35 | train |
syntax-tree/hast-util-to-parse5 | index.js | patch | function patch(node, p5, parentSchema) {
var schema = parentSchema
var position = node.position
var children = node.children
var childNodes = []
var length = children ? children.length : 0
var index = -1
var child
if (node.type === 'element') {
if (schema.space === 'html' && node.tagName === 'svg') {
schema = svg
}
p5.namespaceURI = ns[schema.space]
}
while (++index < length) {
child = one(children[index], schema)
child.parentNode = p5
childNodes[index] = child
}
if (node.type === 'element' || node.type === 'root') {
p5.childNodes = childNodes
}
if (position && position.start && position.end) {
p5.sourceCodeLocation = {
startLine: position.start.line,
startCol: position.start.column,
startOffset: position.start.offset,
endLine: position.end.line,
endCol: position.end.column,
endOffset: position.end.offset
}
}
return p5
} | javascript | function patch(node, p5, parentSchema) {
var schema = parentSchema
var position = node.position
var children = node.children
var childNodes = []
var length = children ? children.length : 0
var index = -1
var child
if (node.type === 'element') {
if (schema.space === 'html' && node.tagName === 'svg') {
schema = svg
}
p5.namespaceURI = ns[schema.space]
}
while (++index < length) {
child = one(children[index], schema)
child.parentNode = p5
childNodes[index] = child
}
if (node.type === 'element' || node.type === 'root') {
p5.childNodes = childNodes
}
if (position && position.start && position.end) {
p5.sourceCodeLocation = {
startLine: position.start.line,
startCol: position.start.column,
startOffset: position.start.offset,
endLine: position.end.line,
endCol: position.end.column,
endOffset: position.end.offset
}
}
return p5
} | [
"function",
"patch",
"(",
"node",
",",
"p5",
",",
"parentSchema",
")",
"{",
"var",
"schema",
"=",
"parentSchema",
"var",
"position",
"=",
"node",
".",
"position",
"var",
"children",
"=",
"node",
".",
"children",
"var",
"childNodes",
"=",
"[",
"]",
"var",
"length",
"=",
"children",
"?",
"children",
".",
"length",
":",
"0",
"var",
"index",
"=",
"-",
"1",
"var",
"child",
"if",
"(",
"node",
".",
"type",
"===",
"'element'",
")",
"{",
"if",
"(",
"schema",
".",
"space",
"===",
"'html'",
"&&",
"node",
".",
"tagName",
"===",
"'svg'",
")",
"{",
"schema",
"=",
"svg",
"}",
"p5",
".",
"namespaceURI",
"=",
"ns",
"[",
"schema",
".",
"space",
"]",
"}",
"while",
"(",
"++",
"index",
"<",
"length",
")",
"{",
"child",
"=",
"one",
"(",
"children",
"[",
"index",
"]",
",",
"schema",
")",
"child",
".",
"parentNode",
"=",
"p5",
"childNodes",
"[",
"index",
"]",
"=",
"child",
"}",
"if",
"(",
"node",
".",
"type",
"===",
"'element'",
"||",
"node",
".",
"type",
"===",
"'root'",
")",
"{",
"p5",
".",
"childNodes",
"=",
"childNodes",
"}",
"if",
"(",
"position",
"&&",
"position",
".",
"start",
"&&",
"position",
".",
"end",
")",
"{",
"p5",
".",
"sourceCodeLocation",
"=",
"{",
"startLine",
":",
"position",
".",
"start",
".",
"line",
",",
"startCol",
":",
"position",
".",
"start",
".",
"column",
",",
"startOffset",
":",
"position",
".",
"start",
".",
"offset",
",",
"endLine",
":",
"position",
".",
"end",
".",
"line",
",",
"endCol",
":",
"position",
".",
"end",
".",
"column",
",",
"endOffset",
":",
"position",
".",
"end",
".",
"offset",
"}",
"}",
"return",
"p5",
"}"
] | Patch specific properties. | [
"Patch",
"specific",
"properties",
"."
] | d1a90057eca4a38986e94c2220b692531d678335 | https://github.com/syntax-tree/hast-util-to-parse5/blob/d1a90057eca4a38986e94c2220b692531d678335/index.js#L112-L151 | train |
relution-io/relution-sdk | lib/web/urls.js | resolveServer | function resolveServer(path, options) {
if (options === void 0) { options = {}; }
var serverUrl = options.serverUrl || init.initOptions.serverUrl;
if (path) {
if (serverUrl) {
path = url.resolve(serverUrl, path);
}
}
else {
path = serverUrl;
}
return url.resolve(path, '/');
} | javascript | function resolveServer(path, options) {
if (options === void 0) { options = {}; }
var serverUrl = options.serverUrl || init.initOptions.serverUrl;
if (path) {
if (serverUrl) {
path = url.resolve(serverUrl, path);
}
}
else {
path = serverUrl;
}
return url.resolve(path, '/');
} | [
"function",
"resolveServer",
"(",
"path",
",",
"options",
")",
"{",
"if",
"(",
"options",
"===",
"void",
"0",
")",
"{",
"options",
"=",
"{",
"}",
";",
"}",
"var",
"serverUrl",
"=",
"options",
".",
"serverUrl",
"||",
"init",
".",
"initOptions",
".",
"serverUrl",
";",
"if",
"(",
"path",
")",
"{",
"if",
"(",
"serverUrl",
")",
"{",
"path",
"=",
"url",
".",
"resolve",
"(",
"serverUrl",
",",
"path",
")",
";",
"}",
"}",
"else",
"{",
"path",
"=",
"serverUrl",
";",
"}",
"return",
"url",
".",
"resolve",
"(",
"path",
",",
"'/'",
")",
";",
"}"
] | computes a server url from a given path.
@param path path to resolve, relative or absolute.
@param options of server in effect.
@return {string} absolute URL of server. | [
"computes",
"a",
"server",
"url",
"from",
"a",
"given",
"path",
"."
] | 776b8bd0c249428add03f97ba2d19092e709bc7b | https://github.com/relution-io/relution-sdk/blob/776b8bd0c249428add03f97ba2d19092e709bc7b/lib/web/urls.js#L36-L48 | train |
relution-io/relution-sdk | lib/web/urls.js | resolveUrl | function resolveUrl(path, options) {
if (options === void 0) { options = {}; }
var serverUrl = resolveServer(path, options);
if (!serverUrl) {
return path;
}
if (path.charAt(0) !== '/') {
// construct full application url
var tenantOrga = options.tenantOrga;
if (!tenantOrga) {
// following extracts the tenantOrga set on the specific server
var serverObj = server.Server.getInstance(serverUrl);
tenantOrga = serverObj.applyOptions({
serverUrl: serverUrl
}).tenantOrga;
if (!tenantOrga) {
tenantOrga = init.initOptions.tenantOrga;
if (!tenantOrga) {
var organization = serverObj.organization;
if (organization) {
tenantOrga = organization.uniqueName;
}
}
}
}
var application = options.application || init.initOptions.application;
serverUrl = url.resolve(serverUrl, '/' + tenantOrga + '/' + application + '/');
}
return url.resolve(serverUrl, path);
} | javascript | function resolveUrl(path, options) {
if (options === void 0) { options = {}; }
var serverUrl = resolveServer(path, options);
if (!serverUrl) {
return path;
}
if (path.charAt(0) !== '/') {
// construct full application url
var tenantOrga = options.tenantOrga;
if (!tenantOrga) {
// following extracts the tenantOrga set on the specific server
var serverObj = server.Server.getInstance(serverUrl);
tenantOrga = serverObj.applyOptions({
serverUrl: serverUrl
}).tenantOrga;
if (!tenantOrga) {
tenantOrga = init.initOptions.tenantOrga;
if (!tenantOrga) {
var organization = serverObj.organization;
if (organization) {
tenantOrga = organization.uniqueName;
}
}
}
}
var application = options.application || init.initOptions.application;
serverUrl = url.resolve(serverUrl, '/' + tenantOrga + '/' + application + '/');
}
return url.resolve(serverUrl, path);
} | [
"function",
"resolveUrl",
"(",
"path",
",",
"options",
")",
"{",
"if",
"(",
"options",
"===",
"void",
"0",
")",
"{",
"options",
"=",
"{",
"}",
";",
"}",
"var",
"serverUrl",
"=",
"resolveServer",
"(",
"path",
",",
"options",
")",
";",
"if",
"(",
"!",
"serverUrl",
")",
"{",
"return",
"path",
";",
"}",
"if",
"(",
"path",
".",
"charAt",
"(",
"0",
")",
"!==",
"'/'",
")",
"{",
"var",
"tenantOrga",
"=",
"options",
".",
"tenantOrga",
";",
"if",
"(",
"!",
"tenantOrga",
")",
"{",
"var",
"serverObj",
"=",
"server",
".",
"Server",
".",
"getInstance",
"(",
"serverUrl",
")",
";",
"tenantOrga",
"=",
"serverObj",
".",
"applyOptions",
"(",
"{",
"serverUrl",
":",
"serverUrl",
"}",
")",
".",
"tenantOrga",
";",
"if",
"(",
"!",
"tenantOrga",
")",
"{",
"tenantOrga",
"=",
"init",
".",
"initOptions",
".",
"tenantOrga",
";",
"if",
"(",
"!",
"tenantOrga",
")",
"{",
"var",
"organization",
"=",
"serverObj",
".",
"organization",
";",
"if",
"(",
"organization",
")",
"{",
"tenantOrga",
"=",
"organization",
".",
"uniqueName",
";",
"}",
"}",
"}",
"}",
"var",
"application",
"=",
"options",
".",
"application",
"||",
"init",
".",
"initOptions",
".",
"application",
";",
"serverUrl",
"=",
"url",
".",
"resolve",
"(",
"serverUrl",
",",
"'/'",
"+",
"tenantOrga",
"+",
"'/'",
"+",
"application",
"+",
"'/'",
")",
";",
"}",
"return",
"url",
".",
"resolve",
"(",
"serverUrl",
",",
"path",
")",
";",
"}"
] | computes a url from a given path.
- absolute URLs are used as is, e.g.
``http://192.168.0.10:8080/mway/myapp/api/v1/some_endpoint`` stays as is,
- machine-relative URLs beginning with ``/`` are resolved against the Relution server logged
into, so that ``/gofer/.../rest/...``-style URLs work as expected, for example
``/mway/myapp/api/v1/some_endpoint`` resolves as above when logged into
``http://192.168.0.10:8080``,
- context-relative URLs such as ``api/v1/...`` are resolved using the Relution server logged in,
the ``uniqueName`` of the ``currentOrganization`` and the application name, for example
``api/v1/some_endpoint`` resolves as above when application myapp logged into
``http://192.168.0.10:8080`` using a user of organization mway provided currentOrganization
was not changed explicitly to something else.
@param path path to resolve.
@param options of server in effect.
@return {string} absolute URL of path on current server. | [
"computes",
"a",
"url",
"from",
"a",
"given",
"path",
"."
] | 776b8bd0c249428add03f97ba2d19092e709bc7b | https://github.com/relution-io/relution-sdk/blob/776b8bd0c249428add03f97ba2d19092e709bc7b/lib/web/urls.js#L69-L98 | train |
relution-io/relution-sdk | lib/web/urls.js | resolveApp | function resolveApp(baseAliasOrNameOrApp, options) {
if (options === void 0) { options = {}; }
// defaults on arguments given
var url;
if (!baseAliasOrNameOrApp) {
url = options.application || init.initOptions.application;
}
else if (_.isString(baseAliasOrNameOrApp)) {
url = baseAliasOrNameOrApp;
}
else {
url = baseAliasOrNameOrApp.baseAlias || baseAliasOrNameOrApp.name;
}
// application must not include the leading slash for resolveUrl to do the job
url = url.replace(/\/?(.*)/, '$1');
// resolve local path against application
return resolveUrl('.', _.defaults({
application: url
}, options));
} | javascript | function resolveApp(baseAliasOrNameOrApp, options) {
if (options === void 0) { options = {}; }
// defaults on arguments given
var url;
if (!baseAliasOrNameOrApp) {
url = options.application || init.initOptions.application;
}
else if (_.isString(baseAliasOrNameOrApp)) {
url = baseAliasOrNameOrApp;
}
else {
url = baseAliasOrNameOrApp.baseAlias || baseAliasOrNameOrApp.name;
}
// application must not include the leading slash for resolveUrl to do the job
url = url.replace(/\/?(.*)/, '$1');
// resolve local path against application
return resolveUrl('.', _.defaults({
application: url
}, options));
} | [
"function",
"resolveApp",
"(",
"baseAliasOrNameOrApp",
",",
"options",
")",
"{",
"if",
"(",
"options",
"===",
"void",
"0",
")",
"{",
"options",
"=",
"{",
"}",
";",
"}",
"var",
"url",
";",
"if",
"(",
"!",
"baseAliasOrNameOrApp",
")",
"{",
"url",
"=",
"options",
".",
"application",
"||",
"init",
".",
"initOptions",
".",
"application",
";",
"}",
"else",
"if",
"(",
"_",
".",
"isString",
"(",
"baseAliasOrNameOrApp",
")",
")",
"{",
"url",
"=",
"baseAliasOrNameOrApp",
";",
"}",
"else",
"{",
"url",
"=",
"baseAliasOrNameOrApp",
".",
"baseAlias",
"||",
"baseAliasOrNameOrApp",
".",
"name",
";",
"}",
"url",
"=",
"url",
".",
"replace",
"(",
"/",
"\\/?(.*)",
"/",
",",
"'$1'",
")",
";",
"return",
"resolveUrl",
"(",
"'.'",
",",
"_",
".",
"defaults",
"(",
"{",
"application",
":",
"url",
"}",
",",
"options",
")",
")",
";",
"}"
] | computes the basepath of a BaaS application.
@param baseAliasOrNameOrApp baseAlias of application, may be name when baseAlias is not changed
by developer or application metadata object of Relution server.
@param options of server in effect.
@return {string} absolute URL of application alias on current server. | [
"computes",
"the",
"basepath",
"of",
"a",
"BaaS",
"application",
"."
] | 776b8bd0c249428add03f97ba2d19092e709bc7b | https://github.com/relution-io/relution-sdk/blob/776b8bd0c249428add03f97ba2d19092e709bc7b/lib/web/urls.js#L108-L127 | train |
relution-io/relution-sdk | lib/livedata/Store.js | isStore | function isStore(object) {
if (!object || typeof object !== 'object') {
return false;
}
else if ('isStore' in object) {
diag.debug.assert(function () { return object.isStore === Store.prototype.isPrototypeOf(object); });
return object.isStore;
}
else {
return Store.prototype.isPrototypeOf(object);
}
} | javascript | function isStore(object) {
if (!object || typeof object !== 'object') {
return false;
}
else if ('isStore' in object) {
diag.debug.assert(function () { return object.isStore === Store.prototype.isPrototypeOf(object); });
return object.isStore;
}
else {
return Store.prototype.isPrototypeOf(object);
}
} | [
"function",
"isStore",
"(",
"object",
")",
"{",
"if",
"(",
"!",
"object",
"||",
"typeof",
"object",
"!==",
"'object'",
")",
"{",
"return",
"false",
";",
"}",
"else",
"if",
"(",
"'isStore'",
"in",
"object",
")",
"{",
"diag",
".",
"debug",
".",
"assert",
"(",
"function",
"(",
")",
"{",
"return",
"object",
".",
"isStore",
"===",
"Store",
".",
"prototype",
".",
"isPrototypeOf",
"(",
"object",
")",
";",
"}",
")",
";",
"return",
"object",
".",
"isStore",
";",
"}",
"else",
"{",
"return",
"Store",
".",
"prototype",
".",
"isPrototypeOf",
"(",
"object",
")",
";",
"}",
"}"
] | tests whether a given object is a Store.
@param {object} object to check.
@return {boolean} whether object is a Store. | [
"tests",
"whether",
"a",
"given",
"object",
"is",
"a",
"Store",
"."
] | 776b8bd0c249428add03f97ba2d19092e709bc7b | https://github.com/relution-io/relution-sdk/blob/776b8bd0c249428add03f97ba2d19092e709bc7b/lib/livedata/Store.js#L37-L48 | train |
swagen/swagen | lib/utils.js | loadConfig | function loadConfig(justJson) {
if (!justJson) {
const configScript = path.resolve(currentDir, configScriptFileName);
if (fs.existsSync(configScript)) {
return require(configScript);
}
}
const configJson = path.resolve(currentDir, configJsonFileName);
if (fs.existsSync(configJson)) {
return require(configJson);
}
const errorMessage = [
`Specify a ${configScriptFileName} or ${configJsonFileName} file to configure the swagen tool.`,
``,
`To create a configuration file in the current directory, use the following command:`,
``,
` swagen init`,
``,
`This will ask you a series of questions and generate a configuration file based on your answers.`
].join(os.EOL);
throw errorMessage;
} | javascript | function loadConfig(justJson) {
if (!justJson) {
const configScript = path.resolve(currentDir, configScriptFileName);
if (fs.existsSync(configScript)) {
return require(configScript);
}
}
const configJson = path.resolve(currentDir, configJsonFileName);
if (fs.existsSync(configJson)) {
return require(configJson);
}
const errorMessage = [
`Specify a ${configScriptFileName} or ${configJsonFileName} file to configure the swagen tool.`,
``,
`To create a configuration file in the current directory, use the following command:`,
``,
` swagen init`,
``,
`This will ask you a series of questions and generate a configuration file based on your answers.`
].join(os.EOL);
throw errorMessage;
} | [
"function",
"loadConfig",
"(",
"justJson",
")",
"{",
"if",
"(",
"!",
"justJson",
")",
"{",
"const",
"configScript",
"=",
"path",
".",
"resolve",
"(",
"currentDir",
",",
"configScriptFileName",
")",
";",
"if",
"(",
"fs",
".",
"existsSync",
"(",
"configScript",
")",
")",
"{",
"return",
"require",
"(",
"configScript",
")",
";",
"}",
"}",
"const",
"configJson",
"=",
"path",
".",
"resolve",
"(",
"currentDir",
",",
"configJsonFileName",
")",
";",
"if",
"(",
"fs",
".",
"existsSync",
"(",
"configJson",
")",
")",
"{",
"return",
"require",
"(",
"configJson",
")",
";",
"}",
"const",
"errorMessage",
"=",
"[",
"`",
"${",
"configScriptFileName",
"}",
"${",
"configJsonFileName",
"}",
"`",
",",
"`",
"`",
",",
"`",
"`",
",",
"`",
"`",
",",
"`",
"`",
",",
"`",
"`",
",",
"`",
"`",
"]",
".",
"join",
"(",
"os",
".",
"EOL",
")",
";",
"throw",
"errorMessage",
";",
"}"
] | Loads the correct configuration from the current directory.
@returns {Object} Configuration object | [
"Loads",
"the",
"correct",
"configuration",
"from",
"the",
"current",
"directory",
"."
] | cd8b032942d9fa9184243012ceecfeb179948340 | https://github.com/swagen/swagen/blob/cd8b032942d9fa9184243012ceecfeb179948340/lib/utils.js#L39-L62 | train |
relution-io/relution-sdk | server/backend/routes/connectors.js | init | function init(app) {
app.post('/api/v1/connectors/:connection',
/**
* installs session data such as credentials.
*
* @param req containing body JSON to pass as input.
* @param res result of call is provided as JSON body data.
* @param next function to invoke error handling.
*/
function serviceCall(req, res, next) {
connector.configureSession(req.params.connection, req.body);
res.send(204); // success --> 204 no content
});
app.post('/api/v1/connectors/:connection/:call',
/**
* calls directly into a service connection.
*
* @param req containing body JSON to pass as input.
* @param res result of call is provided as JSON body data.
* @param next function to invoke error handling.
*/
function serviceCall(req, res, next) {
connector.runCall(req.params.connection, req.params.call, req.body).then(res.json.bind(res), next).done();
});
} | javascript | function init(app) {
app.post('/api/v1/connectors/:connection',
/**
* installs session data such as credentials.
*
* @param req containing body JSON to pass as input.
* @param res result of call is provided as JSON body data.
* @param next function to invoke error handling.
*/
function serviceCall(req, res, next) {
connector.configureSession(req.params.connection, req.body);
res.send(204); // success --> 204 no content
});
app.post('/api/v1/connectors/:connection/:call',
/**
* calls directly into a service connection.
*
* @param req containing body JSON to pass as input.
* @param res result of call is provided as JSON body data.
* @param next function to invoke error handling.
*/
function serviceCall(req, res, next) {
connector.runCall(req.params.connection, req.params.call, req.body).then(res.json.bind(res), next).done();
});
} | [
"function",
"init",
"(",
"app",
")",
"{",
"app",
".",
"post",
"(",
"'/api/v1/connectors/:connection'",
",",
"function",
"serviceCall",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"connector",
".",
"configureSession",
"(",
"req",
".",
"params",
".",
"connection",
",",
"req",
".",
"body",
")",
";",
"res",
".",
"send",
"(",
"204",
")",
";",
"}",
")",
";",
"app",
".",
"post",
"(",
"'/api/v1/connectors/:connection/:call'",
",",
"function",
"serviceCall",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"connector",
".",
"runCall",
"(",
"req",
".",
"params",
".",
"connection",
",",
"req",
".",
"params",
".",
"call",
",",
"req",
".",
"body",
")",
".",
"then",
"(",
"res",
".",
"json",
".",
"bind",
"(",
"res",
")",
",",
"next",
")",
".",
"done",
"(",
")",
";",
"}",
")",
";",
"}"
] | module providing direct access to connectors.
Used by Relution SDK connectors module for direct access to backend servers. If you do not want
or need this functionality, the routes defined herein can be removed.
@param app express.js application to hook into. | [
"module",
"providing",
"direct",
"access",
"to",
"connectors",
"."
] | 776b8bd0c249428add03f97ba2d19092e709bc7b | https://github.com/relution-io/relution-sdk/blob/776b8bd0c249428add03f97ba2d19092e709bc7b/server/backend/routes/connectors.js#L16-L40 | train |
relution-io/relution-sdk | server/backend/routes/connectors.js | serviceCall | function serviceCall(req, res, next) {
connector.configureSession(req.params.connection, req.body);
res.send(204); // success --> 204 no content
} | javascript | function serviceCall(req, res, next) {
connector.configureSession(req.params.connection, req.body);
res.send(204); // success --> 204 no content
} | [
"function",
"serviceCall",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"connector",
".",
"configureSession",
"(",
"req",
".",
"params",
".",
"connection",
",",
"req",
".",
"body",
")",
";",
"res",
".",
"send",
"(",
"204",
")",
";",
"}"
] | installs session data such as credentials.
@param req containing body JSON to pass as input.
@param res result of call is provided as JSON body data.
@param next function to invoke error handling. | [
"installs",
"session",
"data",
"such",
"as",
"credentials",
"."
] | 776b8bd0c249428add03f97ba2d19092e709bc7b | https://github.com/relution-io/relution-sdk/blob/776b8bd0c249428add03f97ba2d19092e709bc7b/server/backend/routes/connectors.js#L25-L28 | train |
relution-io/relution-sdk | server/backend/routes/connectors.js | serviceCall | function serviceCall(req, res, next) {
connector.runCall(req.params.connection, req.params.call, req.body).then(res.json.bind(res), next).done();
} | javascript | function serviceCall(req, res, next) {
connector.runCall(req.params.connection, req.params.call, req.body).then(res.json.bind(res), next).done();
} | [
"function",
"serviceCall",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"connector",
".",
"runCall",
"(",
"req",
".",
"params",
".",
"connection",
",",
"req",
".",
"params",
".",
"call",
",",
"req",
".",
"body",
")",
".",
"then",
"(",
"res",
".",
"json",
".",
"bind",
"(",
"res",
")",
",",
"next",
")",
".",
"done",
"(",
")",
";",
"}"
] | calls directly into a service connection.
@param req containing body JSON to pass as input.
@param res result of call is provided as JSON body data.
@param next function to invoke error handling. | [
"calls",
"directly",
"into",
"a",
"service",
"connection",
"."
] | 776b8bd0c249428add03f97ba2d19092e709bc7b | https://github.com/relution-io/relution-sdk/blob/776b8bd0c249428add03f97ba2d19092e709bc7b/server/backend/routes/connectors.js#L37-L39 | train |
saneki-discontinued/node-toxcore | examples/bin/old/promises-example.js | function(callback) {
// Asynchronously set our name and status message using promises
Promise.join(
tox.setNameAsync('Bluebird'),
tox.setStatusMessageAsync('Some status message')
).then(function() {
console.log('Successfully set name and status message!');
callback();
}).catch(function(err) {
console.error('Error (initSelf):', err);
callback(err);
});
} | javascript | function(callback) {
// Asynchronously set our name and status message using promises
Promise.join(
tox.setNameAsync('Bluebird'),
tox.setStatusMessageAsync('Some status message')
).then(function() {
console.log('Successfully set name and status message!');
callback();
}).catch(function(err) {
console.error('Error (initSelf):', err);
callback(err);
});
} | [
"function",
"(",
"callback",
")",
"{",
"Promise",
".",
"join",
"(",
"tox",
".",
"setNameAsync",
"(",
"'Bluebird'",
")",
",",
"tox",
".",
"setStatusMessageAsync",
"(",
"'Some status message'",
")",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"console",
".",
"log",
"(",
"'Successfully set name and status message!'",
")",
";",
"callback",
"(",
")",
";",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"'Error (initSelf):'",
",",
"err",
")",
";",
"callback",
"(",
"err",
")",
";",
"}",
")",
";",
"}"
] | Initialize ourself. Sets name and status message.
@private | [
"Initialize",
"ourself",
".",
"Sets",
"name",
"and",
"status",
"message",
"."
] | 45dfb339f4e8a58888fca175528dee13f075824a | https://github.com/saneki-discontinued/node-toxcore/blob/45dfb339f4e8a58888fca175528dee13f075824a/examples/bin/old/promises-example.js#L72-L84 | train |
|
saneki-discontinued/node-toxcore | examples/bin/old/promises-example.js | function(callback) {
tox.on('friendRequest', function(evt) {
console.log('Accepting friend request from ' + evt.publicKeyHex());
// Automatically accept the request
tox.addFriendNoRequestAsync(evt.publicKey()).then(function() {
console.log('Successfully accepted the friend request!');
}).catch(function(err) {
console.error('Couldn\'t accept the friend request:', err);
});
});
tox.on('friendMessage', function(evt) {
console.log('Message from friend ' + evt.friend() + ': ' + evt.message());
// Echo message back to friend
tox.sendMessageAsync(evt.friend(), evt.message()).then(function(receipt) {
console.log('Echoed message back to friend, received receipt ' + receipt);
}).catch(function(err) {
console.error('Couldn\'t echo message back to friend:', err);
});
});
// Setup friendMessage callback to listen for groupchat invite requests
tox.on('friendMessage', function(evt) {
if(evt.message() === 'invite text') {
tox.inviteAsync(evt.friend(), groupchats['text']).then(function() {
console.log('Invited ' + evt.friend() + ' to the text groupchat');
});
} else if(evt.message() === 'invite av') {
tox.inviteAsync(evt.friend(), groupchats['av']).then(function() {
console.log('Invited ' + evt.friend() + ' to the audio/video groupchat');
});
}
});
callback();
} | javascript | function(callback) {
tox.on('friendRequest', function(evt) {
console.log('Accepting friend request from ' + evt.publicKeyHex());
// Automatically accept the request
tox.addFriendNoRequestAsync(evt.publicKey()).then(function() {
console.log('Successfully accepted the friend request!');
}).catch(function(err) {
console.error('Couldn\'t accept the friend request:', err);
});
});
tox.on('friendMessage', function(evt) {
console.log('Message from friend ' + evt.friend() + ': ' + evt.message());
// Echo message back to friend
tox.sendMessageAsync(evt.friend(), evt.message()).then(function(receipt) {
console.log('Echoed message back to friend, received receipt ' + receipt);
}).catch(function(err) {
console.error('Couldn\'t echo message back to friend:', err);
});
});
// Setup friendMessage callback to listen for groupchat invite requests
tox.on('friendMessage', function(evt) {
if(evt.message() === 'invite text') {
tox.inviteAsync(evt.friend(), groupchats['text']).then(function() {
console.log('Invited ' + evt.friend() + ' to the text groupchat');
});
} else if(evt.message() === 'invite av') {
tox.inviteAsync(evt.friend(), groupchats['av']).then(function() {
console.log('Invited ' + evt.friend() + ' to the audio/video groupchat');
});
}
});
callback();
} | [
"function",
"(",
"callback",
")",
"{",
"tox",
".",
"on",
"(",
"'friendRequest'",
",",
"function",
"(",
"evt",
")",
"{",
"console",
".",
"log",
"(",
"'Accepting friend request from '",
"+",
"evt",
".",
"publicKeyHex",
"(",
")",
")",
";",
"tox",
".",
"addFriendNoRequestAsync",
"(",
"evt",
".",
"publicKey",
"(",
")",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"console",
".",
"log",
"(",
"'Successfully accepted the friend request!'",
")",
";",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"'Couldn\\'t accept the friend request:'",
",",
"\\'",
")",
";",
"}",
")",
";",
"}",
")",
";",
"err",
"tox",
".",
"on",
"(",
"'friendMessage'",
",",
"function",
"(",
"evt",
")",
"{",
"console",
".",
"log",
"(",
"'Message from friend '",
"+",
"evt",
".",
"friend",
"(",
")",
"+",
"': '",
"+",
"evt",
".",
"message",
"(",
")",
")",
";",
"tox",
".",
"sendMessageAsync",
"(",
"evt",
".",
"friend",
"(",
")",
",",
"evt",
".",
"message",
"(",
")",
")",
".",
"then",
"(",
"function",
"(",
"receipt",
")",
"{",
"console",
".",
"log",
"(",
"'Echoed message back to friend, received receipt '",
"+",
"receipt",
")",
";",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"'Couldn\\'t echo message back to friend:'",
",",
"\\'",
")",
";",
"}",
")",
";",
"}",
")",
";",
"err",
"}"
] | Initialize our callbacks, listening for friend requests and messages. | [
"Initialize",
"our",
"callbacks",
"listening",
"for",
"friend",
"requests",
"and",
"messages",
"."
] | 45dfb339f4e8a58888fca175528dee13f075824a | https://github.com/saneki-discontinued/node-toxcore/blob/45dfb339f4e8a58888fca175528dee13f075824a/examples/bin/old/promises-example.js#L89-L124 | train |
|
saneki-discontinued/node-toxcore | examples/bin/old/promises-example.js | function(callback) {
async.parallelAsync([
tox.addGroupchat.bind(tox),
tox.getAV().addGroupchat.bind(tox.getAV())
]).then(function(results) {
groupchats['text'] = results[0];
groupchats['av'] = results[1];
}).finally(callback);
} | javascript | function(callback) {
async.parallelAsync([
tox.addGroupchat.bind(tox),
tox.getAV().addGroupchat.bind(tox.getAV())
]).then(function(results) {
groupchats['text'] = results[0];
groupchats['av'] = results[1];
}).finally(callback);
} | [
"function",
"(",
"callback",
")",
"{",
"async",
".",
"parallelAsync",
"(",
"[",
"tox",
".",
"addGroupchat",
".",
"bind",
"(",
"tox",
")",
",",
"tox",
".",
"getAV",
"(",
")",
".",
"addGroupchat",
".",
"bind",
"(",
"tox",
".",
"getAV",
"(",
")",
")",
"]",
")",
".",
"then",
"(",
"function",
"(",
"results",
")",
"{",
"groupchats",
"[",
"'text'",
"]",
"=",
"results",
"[",
"0",
"]",
";",
"groupchats",
"[",
"'av'",
"]",
"=",
"results",
"[",
"1",
"]",
";",
"}",
")",
".",
"finally",
"(",
"callback",
")",
";",
"}"
] | Initialize the groupchats, and call the callback when finished. | [
"Initialize",
"the",
"groupchats",
"and",
"call",
"the",
"callback",
"when",
"finished",
"."
] | 45dfb339f4e8a58888fca175528dee13f075824a | https://github.com/saneki-discontinued/node-toxcore/blob/45dfb339f4e8a58888fca175528dee13f075824a/examples/bin/old/promises-example.js#L129-L137 | train |
|
swagen/swagen | cli.js | handleCommandError | function handleCommandError(ex) {
// If the command throws an exception, display the error message and command help.
if (ex instanceof Error) {
console.log(chalk.red(ex.message));
} else {
console.log(chalk.red(ex));
}
console.log();
const helpArgs = {
_: [command]
};
helpCommand(helpArgs);
} | javascript | function handleCommandError(ex) {
// If the command throws an exception, display the error message and command help.
if (ex instanceof Error) {
console.log(chalk.red(ex.message));
} else {
console.log(chalk.red(ex));
}
console.log();
const helpArgs = {
_: [command]
};
helpCommand(helpArgs);
} | [
"function",
"handleCommandError",
"(",
"ex",
")",
"{",
"if",
"(",
"ex",
"instanceof",
"Error",
")",
"{",
"console",
".",
"log",
"(",
"chalk",
".",
"red",
"(",
"ex",
".",
"message",
")",
")",
";",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"chalk",
".",
"red",
"(",
"ex",
")",
")",
";",
"}",
"console",
".",
"log",
"(",
")",
";",
"const",
"helpArgs",
"=",
"{",
"_",
":",
"[",
"command",
"]",
"}",
";",
"helpCommand",
"(",
"helpArgs",
")",
";",
"}"
] | If the command throws an exception, display the error message and command help
@param {*} ex The thrown exception | [
"If",
"the",
"command",
"throws",
"an",
"exception",
"display",
"the",
"error",
"message",
"and",
"command",
"help"
] | cd8b032942d9fa9184243012ceecfeb179948340 | https://github.com/swagen/swagen/blob/cd8b032942d9fa9184243012ceecfeb179948340/cli.js#L57-L69 | train |
saneki-discontinued/node-toxcore | lib/old/toxencryptsave.js | function(tox, opts) {
// If one argument and not tox, assume opts
if(arguments.length === 1 && !(tox instanceof Tox)) {
opts = tox;
tox = undefined;
}
if(!(tox instanceof Tox)) {
tox = undefined;
//var err = new Error('Tox instance required for ToxEncryptSave');
//throw err;
}
if(!opts) {
opts = {};
}
this._tox = tox;
this._libpath = opts['path'];
if(opts['sync'] === undefined || opts['sync'] === null) {
this._sync = true;
} else {
this._sync = !!opts['sync'];
}
this._toxencryptsave = this.createLibrary(this._libpath);
} | javascript | function(tox, opts) {
// If one argument and not tox, assume opts
if(arguments.length === 1 && !(tox instanceof Tox)) {
opts = tox;
tox = undefined;
}
if(!(tox instanceof Tox)) {
tox = undefined;
//var err = new Error('Tox instance required for ToxEncryptSave');
//throw err;
}
if(!opts) {
opts = {};
}
this._tox = tox;
this._libpath = opts['path'];
if(opts['sync'] === undefined || opts['sync'] === null) {
this._sync = true;
} else {
this._sync = !!opts['sync'];
}
this._toxencryptsave = this.createLibrary(this._libpath);
} | [
"function",
"(",
"tox",
",",
"opts",
")",
"{",
"if",
"(",
"arguments",
".",
"length",
"===",
"1",
"&&",
"!",
"(",
"tox",
"instanceof",
"Tox",
")",
")",
"{",
"opts",
"=",
"tox",
";",
"tox",
"=",
"undefined",
";",
"}",
"if",
"(",
"!",
"(",
"tox",
"instanceof",
"Tox",
")",
")",
"{",
"tox",
"=",
"undefined",
";",
"}",
"if",
"(",
"!",
"opts",
")",
"{",
"opts",
"=",
"{",
"}",
";",
"}",
"this",
".",
"_tox",
"=",
"tox",
";",
"this",
".",
"_libpath",
"=",
"opts",
"[",
"'path'",
"]",
";",
"if",
"(",
"opts",
"[",
"'sync'",
"]",
"===",
"undefined",
"||",
"opts",
"[",
"'sync'",
"]",
"===",
"null",
")",
"{",
"this",
".",
"_sync",
"=",
"true",
";",
"}",
"else",
"{",
"this",
".",
"_sync",
"=",
"!",
"!",
"opts",
"[",
"'sync'",
"]",
";",
"}",
"this",
".",
"_toxencryptsave",
"=",
"this",
".",
"createLibrary",
"(",
"this",
".",
"_libpath",
")",
";",
"}"
] | Construct a new ToxEncryptSave.
@class
@param {Tox} [tox] Tox instance
@param {Object} [opts] Options
@param {String} [opts.path] toxencryptsave library path, will
use the default if not specified
@param {Boolean} [opts.sync=true] If true, will have async methods behave
like sync methods if no callback given | [
"Construct",
"a",
"new",
"ToxEncryptSave",
"."
] | 45dfb339f4e8a58888fca175528dee13f075824a | https://github.com/saneki-discontinued/node-toxcore/blob/45dfb339f4e8a58888fca175528dee13f075824a/lib/old/toxencryptsave.js#L47-L74 | train |
|
banphlet/HubtelMobilePayment | index.js | HubtelMobilePayment | function HubtelMobilePayment({
secretid = required('secretid'),
clientid = required('clientid'),
merchantaccnumber = required('merchantaccnumber'),
}) {
this.config = {}
this.config['clientid'] = clientid
this.config['secretid'] = secretid
this.config['merchantaccnumber'] = merchantaccnumber
this.hubtelurl = 'https://api.hubtel.com/v1/merchantaccount/'
} | javascript | function HubtelMobilePayment({
secretid = required('secretid'),
clientid = required('clientid'),
merchantaccnumber = required('merchantaccnumber'),
}) {
this.config = {}
this.config['clientid'] = clientid
this.config['secretid'] = secretid
this.config['merchantaccnumber'] = merchantaccnumber
this.hubtelurl = 'https://api.hubtel.com/v1/merchantaccount/'
} | [
"function",
"HubtelMobilePayment",
"(",
"{",
"secretid",
"=",
"required",
"(",
"'secretid'",
")",
",",
"clientid",
"=",
"required",
"(",
"'clientid'",
")",
",",
"merchantaccnumber",
"=",
"required",
"(",
"'merchantaccnumber'",
")",
",",
"}",
")",
"{",
"this",
".",
"config",
"=",
"{",
"}",
"this",
".",
"config",
"[",
"'clientid'",
"]",
"=",
"clientid",
"this",
".",
"config",
"[",
"'secretid'",
"]",
"=",
"secretid",
"this",
".",
"config",
"[",
"'merchantaccnumber'",
"]",
"=",
"merchantaccnumber",
"this",
".",
"hubtelurl",
"=",
"'https://api.hubtel.com/v1/merchantaccount/'",
"}"
] | Set up Hubtel authentication
@param {object} data | [
"Set",
"up",
"Hubtel",
"authentication"
] | 6308e35e0d0c3a1567f94bfee3039f74eee8e480 | https://github.com/banphlet/HubtelMobilePayment/blob/6308e35e0d0c3a1567f94bfee3039f74eee8e480/index.js#L13-L23 | train |
silvermine/eslint-plugin-silvermine | lib/rules/brace-style.js | validateCurlyPair | function validateCurlyPair(openingCurly, closingCurly) {
const tokenBeforeOpeningCurly = sourceCode.getTokenBefore(openingCurly),
tokenAfterOpeningCurly = sourceCode.getTokenAfter(openingCurly),
tokenBeforeClosingCurly = sourceCode.getTokenBefore(closingCurly),
singleLineException = params.allowSingleLine && astUtils.isTokenOnSameLine(openingCurly, closingCurly),
isOpeningCurlyOnSameLine = astUtils.isTokenOnSameLine(openingCurly, tokenAfterOpeningCurly),
isClosingCurlyOnSameLine = astUtils.isTokenOnSameLine(tokenBeforeClosingCurly, closingCurly);
if (style !== 'allman' && !astUtils.isTokenOnSameLine(tokenBeforeOpeningCurly, openingCurly)) {
context.report({
node: openingCurly,
messageId: 'nextLineOpen',
fix: removeNewlineBetween(tokenBeforeOpeningCurly, openingCurly),
});
}
if (style === 'allman' && astUtils.isTokenOnSameLine(tokenBeforeOpeningCurly, openingCurly) && !singleLineException) {
context.report({
node: openingCurly,
messageId: 'sameLineOpen',
fix: (fixer) => fixer.insertTextBefore(openingCurly, '\n'),
});
}
if (isOpeningCurlyOnSameLine && tokenAfterOpeningCurly !== closingCurly && !singleLineException) {
context.report({
node: openingCurly,
messageId: 'blockSameLine',
fix: (fixer) => fixer.insertTextAfter(openingCurly, '\n'),
});
}
if (tokenBeforeClosingCurly !== openingCurly && !singleLineException && isClosingCurlyOnSameLine) {
context.report({
node: closingCurly,
messageId: 'singleLineClose',
fix: (fixer) => fixer.insertTextBefore(closingCurly, '\n'),
});
}
} | javascript | function validateCurlyPair(openingCurly, closingCurly) {
const tokenBeforeOpeningCurly = sourceCode.getTokenBefore(openingCurly),
tokenAfterOpeningCurly = sourceCode.getTokenAfter(openingCurly),
tokenBeforeClosingCurly = sourceCode.getTokenBefore(closingCurly),
singleLineException = params.allowSingleLine && astUtils.isTokenOnSameLine(openingCurly, closingCurly),
isOpeningCurlyOnSameLine = astUtils.isTokenOnSameLine(openingCurly, tokenAfterOpeningCurly),
isClosingCurlyOnSameLine = astUtils.isTokenOnSameLine(tokenBeforeClosingCurly, closingCurly);
if (style !== 'allman' && !astUtils.isTokenOnSameLine(tokenBeforeOpeningCurly, openingCurly)) {
context.report({
node: openingCurly,
messageId: 'nextLineOpen',
fix: removeNewlineBetween(tokenBeforeOpeningCurly, openingCurly),
});
}
if (style === 'allman' && astUtils.isTokenOnSameLine(tokenBeforeOpeningCurly, openingCurly) && !singleLineException) {
context.report({
node: openingCurly,
messageId: 'sameLineOpen',
fix: (fixer) => fixer.insertTextBefore(openingCurly, '\n'),
});
}
if (isOpeningCurlyOnSameLine && tokenAfterOpeningCurly !== closingCurly && !singleLineException) {
context.report({
node: openingCurly,
messageId: 'blockSameLine',
fix: (fixer) => fixer.insertTextAfter(openingCurly, '\n'),
});
}
if (tokenBeforeClosingCurly !== openingCurly && !singleLineException && isClosingCurlyOnSameLine) {
context.report({
node: closingCurly,
messageId: 'singleLineClose',
fix: (fixer) => fixer.insertTextBefore(closingCurly, '\n'),
});
}
} | [
"function",
"validateCurlyPair",
"(",
"openingCurly",
",",
"closingCurly",
")",
"{",
"const",
"tokenBeforeOpeningCurly",
"=",
"sourceCode",
".",
"getTokenBefore",
"(",
"openingCurly",
")",
",",
"tokenAfterOpeningCurly",
"=",
"sourceCode",
".",
"getTokenAfter",
"(",
"openingCurly",
")",
",",
"tokenBeforeClosingCurly",
"=",
"sourceCode",
".",
"getTokenBefore",
"(",
"closingCurly",
")",
",",
"singleLineException",
"=",
"params",
".",
"allowSingleLine",
"&&",
"astUtils",
".",
"isTokenOnSameLine",
"(",
"openingCurly",
",",
"closingCurly",
")",
",",
"isOpeningCurlyOnSameLine",
"=",
"astUtils",
".",
"isTokenOnSameLine",
"(",
"openingCurly",
",",
"tokenAfterOpeningCurly",
")",
",",
"isClosingCurlyOnSameLine",
"=",
"astUtils",
".",
"isTokenOnSameLine",
"(",
"tokenBeforeClosingCurly",
",",
"closingCurly",
")",
";",
"if",
"(",
"style",
"!==",
"'allman'",
"&&",
"!",
"astUtils",
".",
"isTokenOnSameLine",
"(",
"tokenBeforeOpeningCurly",
",",
"openingCurly",
")",
")",
"{",
"context",
".",
"report",
"(",
"{",
"node",
":",
"openingCurly",
",",
"messageId",
":",
"'nextLineOpen'",
",",
"fix",
":",
"removeNewlineBetween",
"(",
"tokenBeforeOpeningCurly",
",",
"openingCurly",
")",
",",
"}",
")",
";",
"}",
"if",
"(",
"style",
"===",
"'allman'",
"&&",
"astUtils",
".",
"isTokenOnSameLine",
"(",
"tokenBeforeOpeningCurly",
",",
"openingCurly",
")",
"&&",
"!",
"singleLineException",
")",
"{",
"context",
".",
"report",
"(",
"{",
"node",
":",
"openingCurly",
",",
"messageId",
":",
"'sameLineOpen'",
",",
"fix",
":",
"(",
"fixer",
")",
"=>",
"fixer",
".",
"insertTextBefore",
"(",
"openingCurly",
",",
"'\\n'",
")",
",",
"}",
")",
";",
"}",
"\\n",
"if",
"(",
"isOpeningCurlyOnSameLine",
"&&",
"tokenAfterOpeningCurly",
"!==",
"closingCurly",
"&&",
"!",
"singleLineException",
")",
"{",
"context",
".",
"report",
"(",
"{",
"node",
":",
"openingCurly",
",",
"messageId",
":",
"'blockSameLine'",
",",
"fix",
":",
"(",
"fixer",
")",
"=>",
"fixer",
".",
"insertTextAfter",
"(",
"openingCurly",
",",
"'\\n'",
")",
",",
"}",
")",
";",
"}",
"}"
] | Validates a pair of curly brackets based on the user's config
@param {Token} openingCurly The opening curly bracket
@param {Token} closingCurly The closing curly bracket
@returns {void} | [
"Validates",
"a",
"pair",
"of",
"curly",
"brackets",
"based",
"on",
"the",
"user",
"s",
"config"
] | 2eac37fcaa4cfa86ad7a36793e4a8908e90bfbb6 | https://github.com/silvermine/eslint-plugin-silvermine/blob/2eac37fcaa4cfa86ad7a36793e4a8908e90bfbb6/lib/rules/brace-style.js#L97-L137 | train |
relution-io/relution-sdk | lib/livedata/Model.js | isModel | function isModel(object) {
if (!object || typeof object !== 'object') {
return false;
}
else if ('isModel' in object) {
diag.debug.assert(function () { return object.isModel === Model.prototype.isPrototypeOf(object); });
return object.isModel;
}
else {
return Model.prototype.isPrototypeOf(object);
}
} | javascript | function isModel(object) {
if (!object || typeof object !== 'object') {
return false;
}
else if ('isModel' in object) {
diag.debug.assert(function () { return object.isModel === Model.prototype.isPrototypeOf(object); });
return object.isModel;
}
else {
return Model.prototype.isPrototypeOf(object);
}
} | [
"function",
"isModel",
"(",
"object",
")",
"{",
"if",
"(",
"!",
"object",
"||",
"typeof",
"object",
"!==",
"'object'",
")",
"{",
"return",
"false",
";",
"}",
"else",
"if",
"(",
"'isModel'",
"in",
"object",
")",
"{",
"diag",
".",
"debug",
".",
"assert",
"(",
"function",
"(",
")",
"{",
"return",
"object",
".",
"isModel",
"===",
"Model",
".",
"prototype",
".",
"isPrototypeOf",
"(",
"object",
")",
";",
"}",
")",
";",
"return",
"object",
".",
"isModel",
";",
"}",
"else",
"{",
"return",
"Model",
".",
"prototype",
".",
"isPrototypeOf",
"(",
"object",
")",
";",
"}",
"}"
] | tests whether a given object is a Model.
@param {object} object to check.
@return {boolean} whether object is a Model. | [
"tests",
"whether",
"a",
"given",
"object",
"is",
"a",
"Model",
"."
] | 776b8bd0c249428add03f97ba2d19092e709bc7b | https://github.com/relution-io/relution-sdk/blob/776b8bd0c249428add03f97ba2d19092e709bc7b/lib/livedata/Model.js#L40-L51 | train |
saneki-discontinued/node-toxcore | examples/bin/dns-example.js | function(dnsaddr) {
var domain = getAddressDomain(dnsaddr);
if(domain !== undefined && clients[domain] !== undefined)
return clients[domain];
} | javascript | function(dnsaddr) {
var domain = getAddressDomain(dnsaddr);
if(domain !== undefined && clients[domain] !== undefined)
return clients[domain];
} | [
"function",
"(",
"dnsaddr",
")",
"{",
"var",
"domain",
"=",
"getAddressDomain",
"(",
"dnsaddr",
")",
";",
"if",
"(",
"domain",
"!==",
"undefined",
"&&",
"clients",
"[",
"domain",
"]",
"!==",
"undefined",
")",
"return",
"clients",
"[",
"domain",
"]",
";",
"}"
] | Get the ToxDns client for a specific address.
@param {String} dnsaddr - Address (ex. '[email protected]')
@return {ToxDns} client to use for the given address, or undefined if none
for the address domain | [
"Get",
"the",
"ToxDns",
"client",
"for",
"a",
"specific",
"address",
"."
] | 45dfb339f4e8a58888fca175528dee13f075824a | https://github.com/saneki-discontinued/node-toxcore/blob/45dfb339f4e8a58888fca175528dee13f075824a/examples/bin/dns-example.js#L47-L51 | train |
|
saneki-discontinued/node-toxcore | lib/toxdns.js | function(opts) {
if(!opts) opts = {};
var libpath = opts['path'];
var key = opts['key'];
this._library = this._createLibrary(libpath);
this._initKey(key);
this._initHandle(this._key);
} | javascript | function(opts) {
if(!opts) opts = {};
var libpath = opts['path'];
var key = opts['key'];
this._library = this._createLibrary(libpath);
this._initKey(key);
this._initHandle(this._key);
} | [
"function",
"(",
"opts",
")",
"{",
"if",
"(",
"!",
"opts",
")",
"opts",
"=",
"{",
"}",
";",
"var",
"libpath",
"=",
"opts",
"[",
"'path'",
"]",
";",
"var",
"key",
"=",
"opts",
"[",
"'key'",
"]",
";",
"this",
".",
"_library",
"=",
"this",
".",
"_createLibrary",
"(",
"libpath",
")",
";",
"this",
".",
"_initKey",
"(",
"key",
")",
";",
"this",
".",
"_initHandle",
"(",
"this",
".",
"_key",
")",
";",
"}"
] | Creates a ToxDns instance.
@class
@param {Object} [opts] Options
@param {String} [opts.path] Path to libtoxdns.so
@param {(Buffer|String)} [opts.key] Public key of ToxDns3 service | [
"Creates",
"a",
"ToxDns",
"instance",
"."
] | 45dfb339f4e8a58888fca175528dee13f075824a | https://github.com/saneki-discontinued/node-toxcore/blob/45dfb339f4e8a58888fca175528dee13f075824a/lib/toxdns.js#L50-L58 | train |
|
canjs/can-query-logic | src/types/values-not.js | function(not, primitive){
// NOT(5) U 5
if( set.isEqual( not.value, primitive) ) {
return set.UNIVERSAL;
}
// NOT(4) U 6
else {
throw new Error("Not,Identity Union is not filled out");
}
} | javascript | function(not, primitive){
// NOT(5) U 5
if( set.isEqual( not.value, primitive) ) {
return set.UNIVERSAL;
}
// NOT(4) U 6
else {
throw new Error("Not,Identity Union is not filled out");
}
} | [
"function",
"(",
"not",
",",
"primitive",
")",
"{",
"if",
"(",
"set",
".",
"isEqual",
"(",
"not",
".",
"value",
",",
"primitive",
")",
")",
"{",
"return",
"set",
".",
"UNIVERSAL",
";",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"\"Not,Identity Union is not filled out\"",
")",
";",
"}",
"}"
] | not 5 and not 6 | [
"not",
"5",
"and",
"not",
"6"
] | fe32908e7aa36853362fbc1a4df276193247f38d | https://github.com/canjs/can-query-logic/blob/fe32908e7aa36853362fbc1a4df276193247f38d/src/types/values-not.js#L49-L58 | train |
|
dalekjs/dalek-internal-webdriver | lib/driver.js | function (url, options) {
return Object.keys(options).reduce(this._replacePlaceholderInUrl.bind(this, options), url);
} | javascript | function (url, options) {
return Object.keys(options).reduce(this._replacePlaceholderInUrl.bind(this, options), url);
} | [
"function",
"(",
"url",
",",
"options",
")",
"{",
"return",
"Object",
".",
"keys",
"(",
"options",
")",
".",
"reduce",
"(",
"this",
".",
"_replacePlaceholderInUrl",
".",
"bind",
"(",
"this",
",",
"options",
")",
",",
"url",
")",
";",
"}"
] | Parses an JSON Wire protocol dummy url
@method parseUrl
@param {string} url URL with placeholders
@param {object} options List of url options
@return {string} url Parsed URL | [
"Parses",
"an",
"JSON",
"Wire",
"protocol",
"dummy",
"url"
] | 1b857e99f0ef5d045f355eabcf991378ed98279c | https://github.com/dalekjs/dalek-internal-webdriver/blob/1b857e99f0ef5d045f355eabcf991378ed98279c/lib/driver.js#L53-L55 | train |
|
dalekjs/dalek-internal-webdriver | lib/driver.js | function (options, cb, wd, params) {
// if no cb is given, generate a body with the `desiredCapabilities` object
if (!cb) {
// check if we have parameters set up
if (Object.keys(params).length > 0) {
return JSON.stringify(params);
}
return '';
}
// invoke the given callback & stringify
var data = cb.call(wd, params);
return data === null ? '{}' : JSON.stringify(data);
} | javascript | function (options, cb, wd, params) {
// if no cb is given, generate a body with the `desiredCapabilities` object
if (!cb) {
// check if we have parameters set up
if (Object.keys(params).length > 0) {
return JSON.stringify(params);
}
return '';
}
// invoke the given callback & stringify
var data = cb.call(wd, params);
return data === null ? '{}' : JSON.stringify(data);
} | [
"function",
"(",
"options",
",",
"cb",
",",
"wd",
",",
"params",
")",
"{",
"if",
"(",
"!",
"cb",
")",
"{",
"if",
"(",
"Object",
".",
"keys",
"(",
"params",
")",
".",
"length",
">",
"0",
")",
"{",
"return",
"JSON",
".",
"stringify",
"(",
"params",
")",
";",
"}",
"return",
"''",
";",
"}",
"var",
"data",
"=",
"cb",
".",
"call",
"(",
"wd",
",",
"params",
")",
";",
"return",
"data",
"===",
"null",
"?",
"'{}'",
":",
"JSON",
".",
"stringify",
"(",
"data",
")",
";",
"}"
] | Generates the message body for webdriver client requests of type POST
@method generateBody
@param {object} options Browser options (name, bin path, etc.)
@param {function|undefined} cb Callback function that should be invoked to generate the message body
@param {Dalek.Internal.Webdriver} wd Webdriver base object
@param {object} params Parameters that should be part of the message body
@return {string} body Serialized JSON of body request data | [
"Generates",
"the",
"message",
"body",
"for",
"webdriver",
"client",
"requests",
"of",
"type",
"POST"
] | 1b857e99f0ef5d045f355eabcf991378ed98279c | https://github.com/dalekjs/dalek-internal-webdriver/blob/1b857e99f0ef5d045f355eabcf991378ed98279c/lib/driver.js#L113-L126 | train |
|
dalekjs/dalek-internal-webdriver | lib/driver.js | function (hostname, port, prefix, url, method, body, auth) {
var options = {
hostname: hostname,
port: port,
path: prefix + url,
method: method,
headers: {
'Content-Type': 'application/json;charset=utf-8',
'Content-Length': Buffer.byteLength(body, 'utf8')
}
};
// check if auth information is available
if (auth) {
options.auth = auth;
}
return options;
} | javascript | function (hostname, port, prefix, url, method, body, auth) {
var options = {
hostname: hostname,
port: port,
path: prefix + url,
method: method,
headers: {
'Content-Type': 'application/json;charset=utf-8',
'Content-Length': Buffer.byteLength(body, 'utf8')
}
};
// check if auth information is available
if (auth) {
options.auth = auth;
}
return options;
} | [
"function",
"(",
"hostname",
",",
"port",
",",
"prefix",
",",
"url",
",",
"method",
",",
"body",
",",
"auth",
")",
"{",
"var",
"options",
"=",
"{",
"hostname",
":",
"hostname",
",",
"port",
":",
"port",
",",
"path",
":",
"prefix",
"+",
"url",
",",
"method",
":",
"method",
",",
"headers",
":",
"{",
"'Content-Type'",
":",
"'application/json;charset=utf-8'",
",",
"'Content-Length'",
":",
"Buffer",
".",
"byteLength",
"(",
"body",
",",
"'utf8'",
")",
"}",
"}",
";",
"if",
"(",
"auth",
")",
"{",
"options",
".",
"auth",
"=",
"auth",
";",
"}",
"return",
"options",
";",
"}"
] | Generates the request options for a webdriver client request
@method generateRequestOptions
@param {string} hostname Hostname of the webdriver server
@param {integer} port Port of the webdriver server
@param {string} prefix Url address prefix of the webdriver endpoint
@param {string} url Url of the webdriver method
@param {string} method Request method e.g. (GET, POST, DELETE, PUT)
@param {string} body The message body of the request
@return {object} options Request options | [
"Generates",
"the",
"request",
"options",
"for",
"a",
"webdriver",
"client",
"request"
] | 1b857e99f0ef5d045f355eabcf991378ed98279c | https://github.com/dalekjs/dalek-internal-webdriver/blob/1b857e99f0ef5d045f355eabcf991378ed98279c/lib/driver.js#L141-L159 | train |
|
dalekjs/dalek-internal-webdriver | lib/driver.js | function (remote, driver) {
return function webdriverCommand() {
var deferred = Q.defer();
// the request meta data
var params = Driver.generateParamset(remote.params, arguments);
var body = Driver.generateBody({}, remote.onRequest, this, params);
var options = Driver.generateRequestOptions(this.opts.host, this.opts.port, this.opts.path, Driver.parseUrl(remote.url, this.options), remote.method, body, this.opts.auth);
// generate the request, wait for response & fire the request
var req = new http.ClientRequest(options);
req.on('response', driver._onResponse.bind(this, driver, remote, options, deferred));
req.end(body);
return deferred.promise;
};
} | javascript | function (remote, driver) {
return function webdriverCommand() {
var deferred = Q.defer();
// the request meta data
var params = Driver.generateParamset(remote.params, arguments);
var body = Driver.generateBody({}, remote.onRequest, this, params);
var options = Driver.generateRequestOptions(this.opts.host, this.opts.port, this.opts.path, Driver.parseUrl(remote.url, this.options), remote.method, body, this.opts.auth);
// generate the request, wait for response & fire the request
var req = new http.ClientRequest(options);
req.on('response', driver._onResponse.bind(this, driver, remote, options, deferred));
req.end(body);
return deferred.promise;
};
} | [
"function",
"(",
"remote",
",",
"driver",
")",
"{",
"return",
"function",
"webdriverCommand",
"(",
")",
"{",
"var",
"deferred",
"=",
"Q",
".",
"defer",
"(",
")",
";",
"var",
"params",
"=",
"Driver",
".",
"generateParamset",
"(",
"remote",
".",
"params",
",",
"arguments",
")",
";",
"var",
"body",
"=",
"Driver",
".",
"generateBody",
"(",
"{",
"}",
",",
"remote",
".",
"onRequest",
",",
"this",
",",
"params",
")",
";",
"var",
"options",
"=",
"Driver",
".",
"generateRequestOptions",
"(",
"this",
".",
"opts",
".",
"host",
",",
"this",
".",
"opts",
".",
"port",
",",
"this",
".",
"opts",
".",
"path",
",",
"Driver",
".",
"parseUrl",
"(",
"remote",
".",
"url",
",",
"this",
".",
"options",
")",
",",
"remote",
".",
"method",
",",
"body",
",",
"this",
".",
"opts",
".",
"auth",
")",
";",
"var",
"req",
"=",
"new",
"http",
".",
"ClientRequest",
"(",
"options",
")",
";",
"req",
".",
"on",
"(",
"'response'",
",",
"driver",
".",
"_onResponse",
".",
"bind",
"(",
"this",
",",
"driver",
",",
"remote",
",",
"options",
",",
"deferred",
")",
")",
";",
"req",
".",
"end",
"(",
"body",
")",
";",
"return",
"deferred",
".",
"promise",
";",
"}",
";",
"}"
] | Generates the webdriver callback function
@method _generateWebdriverCommand
@param {object} remote Dummy request body (function name, url, method)
@param {DalekJs.Internal.Driver} driver Driver instance
@return {function} webdriverCommand Generated webdriver command function
@private | [
"Generates",
"the",
"webdriver",
"callback",
"function"
] | 1b857e99f0ef5d045f355eabcf991378ed98279c | https://github.com/dalekjs/dalek-internal-webdriver/blob/1b857e99f0ef5d045f355eabcf991378ed98279c/lib/driver.js#L188-L203 | train |
|
dalekjs/dalek-internal-webdriver | lib/driver.js | function (driver, remote, options, deferred, response) {
this.data = '';
response.on('data', driver._concatDataChunks.bind(this));
response.on('end', driver._onResponseEnd.bind(this, driver, response, remote, options, deferred));
return this;
} | javascript | function (driver, remote, options, deferred, response) {
this.data = '';
response.on('data', driver._concatDataChunks.bind(this));
response.on('end', driver._onResponseEnd.bind(this, driver, response, remote, options, deferred));
return this;
} | [
"function",
"(",
"driver",
",",
"remote",
",",
"options",
",",
"deferred",
",",
"response",
")",
"{",
"this",
".",
"data",
"=",
"''",
";",
"response",
".",
"on",
"(",
"'data'",
",",
"driver",
".",
"_concatDataChunks",
".",
"bind",
"(",
"this",
")",
")",
";",
"response",
".",
"on",
"(",
"'end'",
",",
"driver",
".",
"_onResponseEnd",
".",
"bind",
"(",
"this",
",",
"driver",
",",
"response",
",",
"remote",
",",
"options",
",",
"deferred",
")",
")",
";",
"return",
"this",
";",
"}"
] | Response callback function
@method _onResponse
@param {DalekJs.Internal.Driver} driver Driver instance
@param {object} remote Dummy request body (function name, url, method)
@param {object} options Request options (method, port, path, headers, etc.)
@param {object} deferred Webdriver command deferred
@param {object} response Response from the webdriver server
@chainable
@private | [
"Response",
"callback",
"function"
] | 1b857e99f0ef5d045f355eabcf991378ed98279c | https://github.com/dalekjs/dalek-internal-webdriver/blob/1b857e99f0ef5d045f355eabcf991378ed98279c/lib/driver.js#L218-L223 | train |
|
dalekjs/dalek-internal-webdriver | lib/driver.js | function (driver, response, remote, options, deferred) {
return driver[(response.statusCode === 500 ? '_onError' : '_onSuccess')].bind(this)(driver, response, remote, options, deferred);
} | javascript | function (driver, response, remote, options, deferred) {
return driver[(response.statusCode === 500 ? '_onError' : '_onSuccess')].bind(this)(driver, response, remote, options, deferred);
} | [
"function",
"(",
"driver",
",",
"response",
",",
"remote",
",",
"options",
",",
"deferred",
")",
"{",
"return",
"driver",
"[",
"(",
"response",
".",
"statusCode",
"===",
"500",
"?",
"'_onError'",
":",
"'_onSuccess'",
")",
"]",
".",
"bind",
"(",
"this",
")",
"(",
"driver",
",",
"response",
",",
"remote",
",",
"options",
",",
"deferred",
")",
";",
"}"
] | Response end callback function
@method _onResponseEnd
@param {DalekJs.Internal.Driver} driver Driver instance
@param {object} response Response from the webdriver server
@param {object} remote Dummy request body (function name, url, method)
@param {object} options Request options (method, port, path, headers, etc.)
@param {object} deferred Webdriver command deferred
@chainable
@priavte | [
"Response",
"end",
"callback",
"function"
] | 1b857e99f0ef5d045f355eabcf991378ed98279c | https://github.com/dalekjs/dalek-internal-webdriver/blob/1b857e99f0ef5d045f355eabcf991378ed98279c/lib/driver.js#L251-L253 | train |
|
dalekjs/dalek-internal-webdriver | lib/driver.js | function (driver, response, remote, options, deferred) {
// Provide a default error handler to prevent hangs.
if (!remote.onError) {
remote.onError = function (request, remote, options, deferred, data) {
data = JSON.parse(data);
var value = -1;
if (typeof data.value.message === 'string') {
var msg = JSON.parse(data.value.message);
value = msg.errorMessage;
}
deferred.resolve(JSON.stringify({'sessionId': data.sessionId, value: value}));
};
}
remote.onError.call(this, response, remote, options, deferred, this.data);
return this;
} | javascript | function (driver, response, remote, options, deferred) {
// Provide a default error handler to prevent hangs.
if (!remote.onError) {
remote.onError = function (request, remote, options, deferred, data) {
data = JSON.parse(data);
var value = -1;
if (typeof data.value.message === 'string') {
var msg = JSON.parse(data.value.message);
value = msg.errorMessage;
}
deferred.resolve(JSON.stringify({'sessionId': data.sessionId, value: value}));
};
}
remote.onError.call(this, response, remote, options, deferred, this.data);
return this;
} | [
"function",
"(",
"driver",
",",
"response",
",",
"remote",
",",
"options",
",",
"deferred",
")",
"{",
"if",
"(",
"!",
"remote",
".",
"onError",
")",
"{",
"remote",
".",
"onError",
"=",
"function",
"(",
"request",
",",
"remote",
",",
"options",
",",
"deferred",
",",
"data",
")",
"{",
"data",
"=",
"JSON",
".",
"parse",
"(",
"data",
")",
";",
"var",
"value",
"=",
"-",
"1",
";",
"if",
"(",
"typeof",
"data",
".",
"value",
".",
"message",
"===",
"'string'",
")",
"{",
"var",
"msg",
"=",
"JSON",
".",
"parse",
"(",
"data",
".",
"value",
".",
"message",
")",
";",
"value",
"=",
"msg",
".",
"errorMessage",
";",
"}",
"deferred",
".",
"resolve",
"(",
"JSON",
".",
"stringify",
"(",
"{",
"'sessionId'",
":",
"data",
".",
"sessionId",
",",
"value",
":",
"value",
"}",
")",
")",
";",
"}",
";",
"}",
"remote",
".",
"onError",
".",
"call",
"(",
"this",
",",
"response",
",",
"remote",
",",
"options",
",",
"deferred",
",",
"this",
".",
"data",
")",
";",
"return",
"this",
";",
"}"
] | On error callback function
@method _onError
@param {DalekJs.Internal.Driver} driver Driver instance
@param {object} response Response from the webdriver server
@param {object} remote Dummy request body (function name, url, method)
@param {object} options Request options (method, port, path, headers, etc.)
@param {object} deferred Webdriver command deferred
@chainable
@private | [
"On",
"error",
"callback",
"function"
] | 1b857e99f0ef5d045f355eabcf991378ed98279c | https://github.com/dalekjs/dalek-internal-webdriver/blob/1b857e99f0ef5d045f355eabcf991378ed98279c/lib/driver.js#L268-L283 | train |
|
dalekjs/dalek-internal-webdriver | lib/driver.js | function (driver, response, remote, options, deferred) {
// log response data
this.events.emit('driver:webdriver:response', {
statusCode: response.statusCode,
method: response.req.method,
path: response.req.path,
data: this.data
});
if (remote.onResponse) {
remote.onResponse.call(this, response, remote, options, deferred, this.data);
} else {
deferred.resolve(this.data);
}
return this;
} | javascript | function (driver, response, remote, options, deferred) {
// log response data
this.events.emit('driver:webdriver:response', {
statusCode: response.statusCode,
method: response.req.method,
path: response.req.path,
data: this.data
});
if (remote.onResponse) {
remote.onResponse.call(this, response, remote, options, deferred, this.data);
} else {
deferred.resolve(this.data);
}
return this;
} | [
"function",
"(",
"driver",
",",
"response",
",",
"remote",
",",
"options",
",",
"deferred",
")",
"{",
"this",
".",
"events",
".",
"emit",
"(",
"'driver:webdriver:response'",
",",
"{",
"statusCode",
":",
"response",
".",
"statusCode",
",",
"method",
":",
"response",
".",
"req",
".",
"method",
",",
"path",
":",
"response",
".",
"req",
".",
"path",
",",
"data",
":",
"this",
".",
"data",
"}",
")",
";",
"if",
"(",
"remote",
".",
"onResponse",
")",
"{",
"remote",
".",
"onResponse",
".",
"call",
"(",
"this",
",",
"response",
",",
"remote",
",",
"options",
",",
"deferred",
",",
"this",
".",
"data",
")",
";",
"}",
"else",
"{",
"deferred",
".",
"resolve",
"(",
"this",
".",
"data",
")",
";",
"}",
"return",
"this",
";",
"}"
] | On success callback function
@method _onSuccess
@param {DalekJs.Internal.Driver} driver Driver instance
@param {object} response Response from the webdriver server
@param {object} remote Dummy request body (function name, url, method)
@param {object} options Request options (method, port, path, headers, etc.)
@param {object} deferred Webdriver command deferred
@chainable
@private | [
"On",
"success",
"callback",
"function"
] | 1b857e99f0ef5d045f355eabcf991378ed98279c | https://github.com/dalekjs/dalek-internal-webdriver/blob/1b857e99f0ef5d045f355eabcf991378ed98279c/lib/driver.js#L298-L313 | train |
|
swagen/swagen | lib/generate/index.js | handleFileSwagger | function handleFileSwagger(profile, profileKey) {
const inputFilePath = path.resolve(currentDir, profile.file);
console.log(chalk`{green [${profileKey}]} Input swagger file : {cyan ${inputFilePath}}`);
fs.readFile(inputFilePath, 'utf8', (error, swagger) => {
if (error) {
console.log(chalk`{red Cannot read swagger file '{bold ${profile.file}}'.}`);
console.log(chalk.red(error));
} else {
handleSwagger(swagger, profile, profileKey);
}
});
} | javascript | function handleFileSwagger(profile, profileKey) {
const inputFilePath = path.resolve(currentDir, profile.file);
console.log(chalk`{green [${profileKey}]} Input swagger file : {cyan ${inputFilePath}}`);
fs.readFile(inputFilePath, 'utf8', (error, swagger) => {
if (error) {
console.log(chalk`{red Cannot read swagger file '{bold ${profile.file}}'.}`);
console.log(chalk.red(error));
} else {
handleSwagger(swagger, profile, profileKey);
}
});
} | [
"function",
"handleFileSwagger",
"(",
"profile",
",",
"profileKey",
")",
"{",
"const",
"inputFilePath",
"=",
"path",
".",
"resolve",
"(",
"currentDir",
",",
"profile",
".",
"file",
")",
";",
"console",
".",
"log",
"(",
"chalk",
"`",
"${",
"profileKey",
"}",
"${",
"inputFilePath",
"}",
"`",
")",
";",
"fs",
".",
"readFile",
"(",
"inputFilePath",
",",
"'utf8'",
",",
"(",
"error",
",",
"swagger",
")",
"=>",
"{",
"if",
"(",
"error",
")",
"{",
"console",
".",
"log",
"(",
"chalk",
"`",
"${",
"profile",
".",
"file",
"}",
"`",
")",
";",
"console",
".",
"log",
"(",
"chalk",
".",
"red",
"(",
"error",
")",
")",
";",
"}",
"else",
"{",
"handleSwagger",
"(",
"swagger",
",",
"profile",
",",
"profileKey",
")",
";",
"}",
"}",
")",
";",
"}"
] | Reads the swagger json from a file specified in the profile.
@param {Profile} profile - The profile being handled.
@param {String} profileKey - The name of the profile. | [
"Reads",
"the",
"swagger",
"json",
"from",
"a",
"file",
"specified",
"in",
"the",
"profile",
"."
] | cd8b032942d9fa9184243012ceecfeb179948340 | https://github.com/swagen/swagen/blob/cd8b032942d9fa9184243012ceecfeb179948340/lib/generate/index.js#L73-L84 | train |
swagen/swagen | lib/generate/index.js | handleUrlSwagger | function handleUrlSwagger(profile, profileKey) {
console.log(chalk`{green [${profileKey}]} Input swagger URL : {cyan ${profile.url}}`);
const options = {
rejectUnauthorized: false
};
needle.get(profile.url, options, (err, resp, body) => {
if (err) {
console.log(chalk`{red Cannot read swagger URL '{bold ${profile.url}}'.}`);
console.log(chalk.red(err));
} else {
handleSwagger(body, profile, profileKey);
}
});
} | javascript | function handleUrlSwagger(profile, profileKey) {
console.log(chalk`{green [${profileKey}]} Input swagger URL : {cyan ${profile.url}}`);
const options = {
rejectUnauthorized: false
};
needle.get(profile.url, options, (err, resp, body) => {
if (err) {
console.log(chalk`{red Cannot read swagger URL '{bold ${profile.url}}'.}`);
console.log(chalk.red(err));
} else {
handleSwagger(body, profile, profileKey);
}
});
} | [
"function",
"handleUrlSwagger",
"(",
"profile",
",",
"profileKey",
")",
"{",
"console",
".",
"log",
"(",
"chalk",
"`",
"${",
"profileKey",
"}",
"${",
"profile",
".",
"url",
"}",
"`",
")",
";",
"const",
"options",
"=",
"{",
"rejectUnauthorized",
":",
"false",
"}",
";",
"needle",
".",
"get",
"(",
"profile",
".",
"url",
",",
"options",
",",
"(",
"err",
",",
"resp",
",",
"body",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"console",
".",
"log",
"(",
"chalk",
"`",
"${",
"profile",
".",
"url",
"}",
"`",
")",
";",
"console",
".",
"log",
"(",
"chalk",
".",
"red",
"(",
"err",
")",
")",
";",
"}",
"else",
"{",
"handleSwagger",
"(",
"body",
",",
"profile",
",",
"profileKey",
")",
";",
"}",
"}",
")",
";",
"}"
] | Reads the swagger json from a URL specified in the profile.
@param {Profile} profile The profile being handled.
@param {String} profileKey The name of the profile. | [
"Reads",
"the",
"swagger",
"json",
"from",
"a",
"URL",
"specified",
"in",
"the",
"profile",
"."
] | cd8b032942d9fa9184243012ceecfeb179948340 | https://github.com/swagen/swagen/blob/cd8b032942d9fa9184243012ceecfeb179948340/lib/generate/index.js#L91-L104 | train |
swagen/swagen | lib/generate/index.js | verifyProfile | function verifyProfile(profile, profileKey) {
if (!profile.file && !profile.url) {
throw new Error(`[${profileKey}] Must specify a file or url in the configuration.`);
}
if (!profile.output) {
throw new Error(`[${profileKey}] Must specify an output file path in the configuration.`);
}
if (!profile.generator) {
throw new Error(`[${profileKey}] Must specify a generator in the configuration.`);
}
if (profile.generator.toLowerCase() === 'core') {
throw new Error(`[${profileKey}] Invalid generator ${profile.generator}. This name is reserved.`);
}
if (profile.generator.match(/^[\w-]+-language$/i)) {
throw new Error(`[${profileKey}] Invalid generator ${profile.generator}. The -language suffix is reserved for language helper packages.`);
}
profile.debug = profile.debug || {};
profile.filters = profile.filters || {};
profile.transforms = profile.transforms || {};
profile.options = profile.options || {};
} | javascript | function verifyProfile(profile, profileKey) {
if (!profile.file && !profile.url) {
throw new Error(`[${profileKey}] Must specify a file or url in the configuration.`);
}
if (!profile.output) {
throw new Error(`[${profileKey}] Must specify an output file path in the configuration.`);
}
if (!profile.generator) {
throw new Error(`[${profileKey}] Must specify a generator in the configuration.`);
}
if (profile.generator.toLowerCase() === 'core') {
throw new Error(`[${profileKey}] Invalid generator ${profile.generator}. This name is reserved.`);
}
if (profile.generator.match(/^[\w-]+-language$/i)) {
throw new Error(`[${profileKey}] Invalid generator ${profile.generator}. The -language suffix is reserved for language helper packages.`);
}
profile.debug = profile.debug || {};
profile.filters = profile.filters || {};
profile.transforms = profile.transforms || {};
profile.options = profile.options || {};
} | [
"function",
"verifyProfile",
"(",
"profile",
",",
"profileKey",
")",
"{",
"if",
"(",
"!",
"profile",
".",
"file",
"&&",
"!",
"profile",
".",
"url",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"profileKey",
"}",
"`",
")",
";",
"}",
"if",
"(",
"!",
"profile",
".",
"output",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"profileKey",
"}",
"`",
")",
";",
"}",
"if",
"(",
"!",
"profile",
".",
"generator",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"profileKey",
"}",
"`",
")",
";",
"}",
"if",
"(",
"profile",
".",
"generator",
".",
"toLowerCase",
"(",
")",
"===",
"'core'",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"profileKey",
"}",
"${",
"profile",
".",
"generator",
"}",
"`",
")",
";",
"}",
"if",
"(",
"profile",
".",
"generator",
".",
"match",
"(",
"/",
"^[\\w-]+-language$",
"/",
"i",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"profileKey",
"}",
"${",
"profile",
".",
"generator",
"}",
"`",
")",
";",
"}",
"profile",
".",
"debug",
"=",
"profile",
".",
"debug",
"||",
"{",
"}",
";",
"profile",
".",
"filters",
"=",
"profile",
".",
"filters",
"||",
"{",
"}",
";",
"profile",
".",
"transforms",
"=",
"profile",
".",
"transforms",
"||",
"{",
"}",
";",
"profile",
".",
"options",
"=",
"profile",
".",
"options",
"||",
"{",
"}",
";",
"}"
] | Ensure that the profile structure is valid. | [
"Ensure",
"that",
"the",
"profile",
"structure",
"is",
"valid",
"."
] | cd8b032942d9fa9184243012ceecfeb179948340 | https://github.com/swagen/swagen/blob/cd8b032942d9fa9184243012ceecfeb179948340/lib/generate/index.js#L109-L129 | train |
swagen/swagen | lib/generate/index.js | processInputs | function processInputs(config) {
for (const profileKey in config) {
const profile = config[profileKey];
if (profile.skip) {
continue;
}
verifyProfile(profile, profileKey);
if (profile.file) {
handleFileSwagger(profile, profileKey);
} else {
handleUrlSwagger(profile, profileKey);
}
}
} | javascript | function processInputs(config) {
for (const profileKey in config) {
const profile = config[profileKey];
if (profile.skip) {
continue;
}
verifyProfile(profile, profileKey);
if (profile.file) {
handleFileSwagger(profile, profileKey);
} else {
handleUrlSwagger(profile, profileKey);
}
}
} | [
"function",
"processInputs",
"(",
"config",
")",
"{",
"for",
"(",
"const",
"profileKey",
"in",
"config",
")",
"{",
"const",
"profile",
"=",
"config",
"[",
"profileKey",
"]",
";",
"if",
"(",
"profile",
".",
"skip",
")",
"{",
"continue",
";",
"}",
"verifyProfile",
"(",
"profile",
",",
"profileKey",
")",
";",
"if",
"(",
"profile",
".",
"file",
")",
"{",
"handleFileSwagger",
"(",
"profile",
",",
"profileKey",
")",
";",
"}",
"else",
"{",
"handleUrlSwagger",
"(",
"profile",
",",
"profileKey",
")",
";",
"}",
"}",
"}"
] | Iterates through each profile in the config and handles the swagger.
@param {Object} config Configuration object | [
"Iterates",
"through",
"each",
"profile",
"in",
"the",
"config",
"and",
"handles",
"the",
"swagger",
"."
] | cd8b032942d9fa9184243012ceecfeb179948340 | https://github.com/swagen/swagen/blob/cd8b032942d9fa9184243012ceecfeb179948340/lib/generate/index.js#L135-L150 | train |
phase2/generator-gadget | generators/lib/drupalProjectVersion.js | toMinorRange | function toMinorRange(version) {
var regex = /^\d+\.\d+/;
var range = version.match(regex);
if (range) {
return '^' + range[0];
}
else {
var regex = /^\d+\.x/;
var range = version.match(regex);
if (range) {
return range[0];
}
}
return version;
} | javascript | function toMinorRange(version) {
var regex = /^\d+\.\d+/;
var range = version.match(regex);
if (range) {
return '^' + range[0];
}
else {
var regex = /^\d+\.x/;
var range = version.match(regex);
if (range) {
return range[0];
}
}
return version;
} | [
"function",
"toMinorRange",
"(",
"version",
")",
"{",
"var",
"regex",
"=",
"/",
"^\\d+\\.\\d+",
"/",
";",
"var",
"range",
"=",
"version",
".",
"match",
"(",
"regex",
")",
";",
"if",
"(",
"range",
")",
"{",
"return",
"'^'",
"+",
"range",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"var",
"regex",
"=",
"/",
"^\\d+\\.x",
"/",
";",
"var",
"range",
"=",
"version",
".",
"match",
"(",
"regex",
")",
";",
"if",
"(",
"range",
")",
"{",
"return",
"range",
"[",
"0",
"]",
";",
"}",
"}",
"return",
"version",
";",
"}"
] | Convert a semantic version to a minor range.
In composer.json entries for Drupal core or other major projects, we often
want to designate the version similar to '^8.2'. This code converts version
strings that may have a pre-release suffix to such a range.
Furthermore, there are some edge cases wherein we may want to take a version
that is already a minor range, such as 8.x, and use it as is. | [
"Convert",
"a",
"semantic",
"version",
"to",
"a",
"minor",
"range",
"."
] | 8ebc9a6f7592ebc37844cd2aec346c2e00aaa91d | https://github.com/phase2/generator-gadget/blob/8ebc9a6f7592ebc37844cd2aec346c2e00aaa91d/generators/lib/drupalProjectVersion.js#L113-L128 | train |
phase2/generator-gadget | generators/lib/drupalProjectVersion.js | toDrupalMajorVersion | function toDrupalMajorVersion(version) {
var regex = /^(\d+)\.\d+\.[x\d+]/;
var match = version.match(regex)
if (match) {
return match[1] + '.x';
}
return version;
} | javascript | function toDrupalMajorVersion(version) {
var regex = /^(\d+)\.\d+\.[x\d+]/;
var match = version.match(regex)
if (match) {
return match[1] + '.x';
}
return version;
} | [
"function",
"toDrupalMajorVersion",
"(",
"version",
")",
"{",
"var",
"regex",
"=",
"/",
"^(\\d+)\\.\\d+\\.[x\\d+]",
"/",
";",
"var",
"match",
"=",
"version",
".",
"match",
"(",
"regex",
")",
"if",
"(",
"match",
")",
"{",
"return",
"match",
"[",
"1",
"]",
"+",
"'.x'",
";",
"}",
"return",
"version",
";",
"}"
] | The Drupal update system uses a pre-semver approach of version numbering.
Major versions must be in the form of "8.x", as opposed to other semver
ranges or version numbers. | [
"The",
"Drupal",
"update",
"system",
"uses",
"a",
"pre",
"-",
"semver",
"approach",
"of",
"version",
"numbering",
"."
] | 8ebc9a6f7592ebc37844cd2aec346c2e00aaa91d | https://github.com/phase2/generator-gadget/blob/8ebc9a6f7592ebc37844cd2aec346c2e00aaa91d/generators/lib/drupalProjectVersion.js#L136-L144 | train |
phase2/generator-gadget | generators/lib/drupalProjectVersion.js | isCached | function isCached(project, majorVersion) {
var cid = project+majorVersion;
return cache[cid] && cache[cid].short_name[0] == project && cache[cid].api_version[0] == majorVersion;
} | javascript | function isCached(project, majorVersion) {
var cid = project+majorVersion;
return cache[cid] && cache[cid].short_name[0] == project && cache[cid].api_version[0] == majorVersion;
} | [
"function",
"isCached",
"(",
"project",
",",
"majorVersion",
")",
"{",
"var",
"cid",
"=",
"project",
"+",
"majorVersion",
";",
"return",
"cache",
"[",
"cid",
"]",
"&&",
"cache",
"[",
"cid",
"]",
".",
"short_name",
"[",
"0",
"]",
"==",
"project",
"&&",
"cache",
"[",
"cid",
"]",
".",
"api_version",
"[",
"0",
"]",
"==",
"majorVersion",
";",
"}"
] | Determine if we have successfully cached the release data. | [
"Determine",
"if",
"we",
"have",
"successfully",
"cached",
"the",
"release",
"data",
"."
] | 8ebc9a6f7592ebc37844cd2aec346c2e00aaa91d | https://github.com/phase2/generator-gadget/blob/8ebc9a6f7592ebc37844cd2aec346c2e00aaa91d/generators/lib/drupalProjectVersion.js#L149-L152 | train |
GenesysPureEngage/provisioning-client-js | src/internal/code-gen/provisioning-api/model/AddUserDataData.js | function(userName, firstName, lastName, password) {
var _this = this;
_this['userName'] = userName;
_this['firstName'] = firstName;
_this['lastName'] = lastName;
_this['password'] = password;
} | javascript | function(userName, firstName, lastName, password) {
var _this = this;
_this['userName'] = userName;
_this['firstName'] = firstName;
_this['lastName'] = lastName;
_this['password'] = password;
} | [
"function",
"(",
"userName",
",",
"firstName",
",",
"lastName",
",",
"password",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"_this",
"[",
"'userName'",
"]",
"=",
"userName",
";",
"_this",
"[",
"'firstName'",
"]",
"=",
"firstName",
";",
"_this",
"[",
"'lastName'",
"]",
"=",
"lastName",
";",
"_this",
"[",
"'password'",
"]",
"=",
"password",
";",
"}"
] | The AddUserDataData model module.
@module model/AddUserDataData
@version 9.0.000.46.3206
Constructs a new <code>AddUserDataData</code>.
@alias module:model/AddUserDataData
@class
@param userName {String} The user's unique login.
@param firstName {String} The user's first name.
@param lastName {String} The user's last name.
@param password {String} The user's password as plain text. | [
"The",
"AddUserDataData",
"model",
"module",
"."
] | 8d5e1ed6bf75bedf1a580091b9f197670ea98041 | https://github.com/GenesysPureEngage/provisioning-client-js/blob/8d5e1ed6bf75bedf1a580091b9f197670ea98041/src/internal/code-gen/provisioning-api/model/AddUserDataData.js#L51-L79 | train |
|
canjs/can-query-logic | src/types/basic-query.js | BasicQuery | function BasicQuery(query) {
assign(this, query);
if (!this.filter) {
this.filter = set.UNIVERSAL;
}
if (!this.page) {
this.page = new RecordRange();
}
if (!this.sort) {
this.sort = "id";
}
if (typeof this.sort === "string") {
this.sort = new DefaultSort(this.sort);
}
} | javascript | function BasicQuery(query) {
assign(this, query);
if (!this.filter) {
this.filter = set.UNIVERSAL;
}
if (!this.page) {
this.page = new RecordRange();
}
if (!this.sort) {
this.sort = "id";
}
if (typeof this.sort === "string") {
this.sort = new DefaultSort(this.sort);
}
} | [
"function",
"BasicQuery",
"(",
"query",
")",
"{",
"assign",
"(",
"this",
",",
"query",
")",
";",
"if",
"(",
"!",
"this",
".",
"filter",
")",
"{",
"this",
".",
"filter",
"=",
"set",
".",
"UNIVERSAL",
";",
"}",
"if",
"(",
"!",
"this",
".",
"page",
")",
"{",
"this",
".",
"page",
"=",
"new",
"RecordRange",
"(",
")",
";",
"}",
"if",
"(",
"!",
"this",
".",
"sort",
")",
"{",
"this",
".",
"sort",
"=",
"\"id\"",
";",
"}",
"if",
"(",
"typeof",
"this",
".",
"sort",
"===",
"\"string\"",
")",
"{",
"this",
".",
"sort",
"=",
"new",
"DefaultSort",
"(",
"this",
".",
"sort",
")",
";",
"}",
"}"
] | Define the BasicQuery type | [
"Define",
"the",
"BasicQuery",
"type"
] | fe32908e7aa36853362fbc1a4df276193247f38d | https://github.com/canjs/can-query-logic/blob/fe32908e7aa36853362fbc1a4df276193247f38d/src/types/basic-query.js#L136-L150 | train |
JS-DevTools/globify | lib/parsed-args.js | ParsedArgs | function ParsedArgs (args) {
/**
* The command to run ("browserify" or "watchify")
* @type {string}
*/
this.cmd = "browserify";
/**
* The base directory for the entry-file glob pattern.
* See {@link helpers#getBaseDir} for details.
* @type {string}
*/
this.baseDir = "";
/**
* Options for how the entry-file glob pattern should be parsed.
* For example if an --exclude argument is specified, then `globOptions.ignore` will be set accordingly.
* @type {object}
*/
this.globOptions = { ignore: []};
/**
* The index of the entry-file glob argument.
* If there is no entry-file argument, or it's not a glob pattern, then this will be -1.
* @type {number}
*/
this.globIndex = -1;
/**
* The index of the outfile argument.
* If there is no outfile argument, or it's not a glob pattern, then this will be -1;
* @type {number}
*/
this.outfileIndex = -1;
/**
* The arguments to pass to browserify.
* If {@link globIndex} or {@link outfileIndex} are set, then the corresponding elements in
* this array will be the corresponding functions.
* @type {Array}
*/
this.args = [];
args = args || [];
while (args.length > 0) {
parseOutfile(args, this) ||
parseExclude(args, this) ||
parseWatch(args, this) ||
parseSubArgs(args, this) ||
parseDashArgs(args, this) ||
parseGlobs(args, this) ||
passThrough(args, this);
}
} | javascript | function ParsedArgs (args) {
/**
* The command to run ("browserify" or "watchify")
* @type {string}
*/
this.cmd = "browserify";
/**
* The base directory for the entry-file glob pattern.
* See {@link helpers#getBaseDir} for details.
* @type {string}
*/
this.baseDir = "";
/**
* Options for how the entry-file glob pattern should be parsed.
* For example if an --exclude argument is specified, then `globOptions.ignore` will be set accordingly.
* @type {object}
*/
this.globOptions = { ignore: []};
/**
* The index of the entry-file glob argument.
* If there is no entry-file argument, or it's not a glob pattern, then this will be -1.
* @type {number}
*/
this.globIndex = -1;
/**
* The index of the outfile argument.
* If there is no outfile argument, or it's not a glob pattern, then this will be -1;
* @type {number}
*/
this.outfileIndex = -1;
/**
* The arguments to pass to browserify.
* If {@link globIndex} or {@link outfileIndex} are set, then the corresponding elements in
* this array will be the corresponding functions.
* @type {Array}
*/
this.args = [];
args = args || [];
while (args.length > 0) {
parseOutfile(args, this) ||
parseExclude(args, this) ||
parseWatch(args, this) ||
parseSubArgs(args, this) ||
parseDashArgs(args, this) ||
parseGlobs(args, this) ||
passThrough(args, this);
}
} | [
"function",
"ParsedArgs",
"(",
"args",
")",
"{",
"this",
".",
"cmd",
"=",
"\"browserify\"",
";",
"this",
".",
"baseDir",
"=",
"\"\"",
";",
"this",
".",
"globOptions",
"=",
"{",
"ignore",
":",
"[",
"]",
"}",
";",
"this",
".",
"globIndex",
"=",
"-",
"1",
";",
"this",
".",
"outfileIndex",
"=",
"-",
"1",
";",
"this",
".",
"args",
"=",
"[",
"]",
";",
"args",
"=",
"args",
"||",
"[",
"]",
";",
"while",
"(",
"args",
".",
"length",
">",
"0",
")",
"{",
"parseOutfile",
"(",
"args",
",",
"this",
")",
"||",
"parseExclude",
"(",
"args",
",",
"this",
")",
"||",
"parseWatch",
"(",
"args",
",",
"this",
")",
"||",
"parseSubArgs",
"(",
"args",
",",
"this",
")",
"||",
"parseDashArgs",
"(",
"args",
",",
"this",
")",
"||",
"parseGlobs",
"(",
"args",
",",
"this",
")",
"||",
"passThrough",
"(",
"args",
",",
"this",
")",
";",
"}",
"}"
] | Parses the command-line arguments and replaces glob patterns with functions to expand those patterns.
@param {string[]} args - All command-line arguments, most of which will simply be passed to Browserify
@constructor | [
"Parses",
"the",
"command",
"-",
"line",
"arguments",
"and",
"replaces",
"glob",
"patterns",
"with",
"functions",
"to",
"expand",
"those",
"patterns",
"."
] | 650a0a8727982427c5d1d66e1094b0e23a15a8b6 | https://github.com/JS-DevTools/globify/blob/650a0a8727982427c5d1d66e1094b0e23a15a8b6/lib/parsed-args.js#L16-L69 | train |
relution-io/relution-sdk | lib/livedata/WebSqlStore.js | openDatabase | function openDatabase(options) {
var db;
var sqlitePlugin = 'sqlitePlugin';
if (global[sqlitePlugin]) {
// device implementation
options = _.clone(options);
if (!options.key) {
if (options.security) {
options.key = options.security;
delete options.security;
}
else if (options.credentials) {
options.key = cipher.hashJsonSync(options.credentials, 'sha256').toString('hex');
delete options.credentials;
}
}
if (!options.location) {
options.location = 2;
}
db = global[sqlitePlugin].openDatabase(options);
}
else if (global['openDatabase']) {
// native implementation
db = global['openDatabase'](options.name, options.version || '', options.description || '', options.size || 1024 * 1024);
}
else if (process && !process['browser']) {
// node.js implementation
var websql = void 0;
try {
websql = require('websql');
}
catch (error) {
diag.debug.warn(error);
}
if (websql) {
db = websql(options.name, options.version || '', options.description || '', options.size || 1024 * 1024);
}
}
if (!db) {
// when this is reached no supported implementation is present
throw new Error('WebSQL implementation is not available');
}
return db;
} | javascript | function openDatabase(options) {
var db;
var sqlitePlugin = 'sqlitePlugin';
if (global[sqlitePlugin]) {
// device implementation
options = _.clone(options);
if (!options.key) {
if (options.security) {
options.key = options.security;
delete options.security;
}
else if (options.credentials) {
options.key = cipher.hashJsonSync(options.credentials, 'sha256').toString('hex');
delete options.credentials;
}
}
if (!options.location) {
options.location = 2;
}
db = global[sqlitePlugin].openDatabase(options);
}
else if (global['openDatabase']) {
// native implementation
db = global['openDatabase'](options.name, options.version || '', options.description || '', options.size || 1024 * 1024);
}
else if (process && !process['browser']) {
// node.js implementation
var websql = void 0;
try {
websql = require('websql');
}
catch (error) {
diag.debug.warn(error);
}
if (websql) {
db = websql(options.name, options.version || '', options.description || '', options.size || 1024 * 1024);
}
}
if (!db) {
// when this is reached no supported implementation is present
throw new Error('WebSQL implementation is not available');
}
return db;
} | [
"function",
"openDatabase",
"(",
"options",
")",
"{",
"var",
"db",
";",
"var",
"sqlitePlugin",
"=",
"'sqlitePlugin'",
";",
"if",
"(",
"global",
"[",
"sqlitePlugin",
"]",
")",
"{",
"options",
"=",
"_",
".",
"clone",
"(",
"options",
")",
";",
"if",
"(",
"!",
"options",
".",
"key",
")",
"{",
"if",
"(",
"options",
".",
"security",
")",
"{",
"options",
".",
"key",
"=",
"options",
".",
"security",
";",
"delete",
"options",
".",
"security",
";",
"}",
"else",
"if",
"(",
"options",
".",
"credentials",
")",
"{",
"options",
".",
"key",
"=",
"cipher",
".",
"hashJsonSync",
"(",
"options",
".",
"credentials",
",",
"'sha256'",
")",
".",
"toString",
"(",
"'hex'",
")",
";",
"delete",
"options",
".",
"credentials",
";",
"}",
"}",
"if",
"(",
"!",
"options",
".",
"location",
")",
"{",
"options",
".",
"location",
"=",
"2",
";",
"}",
"db",
"=",
"global",
"[",
"sqlitePlugin",
"]",
".",
"openDatabase",
"(",
"options",
")",
";",
"}",
"else",
"if",
"(",
"global",
"[",
"'openDatabase'",
"]",
")",
"{",
"db",
"=",
"global",
"[",
"'openDatabase'",
"]",
"(",
"options",
".",
"name",
",",
"options",
".",
"version",
"||",
"''",
",",
"options",
".",
"description",
"||",
"''",
",",
"options",
".",
"size",
"||",
"1024",
"*",
"1024",
")",
";",
"}",
"else",
"if",
"(",
"process",
"&&",
"!",
"process",
"[",
"'browser'",
"]",
")",
"{",
"var",
"websql",
"=",
"void",
"0",
";",
"try",
"{",
"websql",
"=",
"require",
"(",
"'websql'",
")",
";",
"}",
"catch",
"(",
"error",
")",
"{",
"diag",
".",
"debug",
".",
"warn",
"(",
"error",
")",
";",
"}",
"if",
"(",
"websql",
")",
"{",
"db",
"=",
"websql",
"(",
"options",
".",
"name",
",",
"options",
".",
"version",
"||",
"''",
",",
"options",
".",
"description",
"||",
"''",
",",
"options",
".",
"size",
"||",
"1024",
"*",
"1024",
")",
";",
"}",
"}",
"if",
"(",
"!",
"db",
")",
"{",
"throw",
"new",
"Error",
"(",
"'WebSQL implementation is not available'",
")",
";",
"}",
"return",
"db",
";",
"}"
] | openDatabase of browser or via require websql.
@internal Not public API, exported for testing purposes only! | [
"openDatabase",
"of",
"browser",
"or",
"via",
"require",
"websql",
"."
] | 776b8bd0c249428add03f97ba2d19092e709bc7b | https://github.com/relution-io/relution-sdk/blob/776b8bd0c249428add03f97ba2d19092e709bc7b/lib/livedata/WebSqlStore.js#L43-L86 | train |
peerigon/erroz | lib/index.js | erroz | function erroz(error) {
var errorFn = function (data) {
//apply all attributes on the instance
for (var errKey in errorFn.prototype) {
if (errorFn.prototype.hasOwnProperty(errKey)) {
this[errKey] = errorFn.prototype[errKey];
}
}
//overwrite message if invoked with string
if (typeof data === "string") {
this.message = data;
data = {};
}
this.data = data || {};
this.message = this.message || erroz.options.renderMessage(error.template || "", this.data);
errorFn.super_.call(this, this.constructor);
};
util.inherits(errorFn, AbstractError);
//add static error properties (name, status, etc)
for (var errKey in error) {
if (error.hasOwnProperty(errKey)) {
errorFn.prototype[errKey] = error[errKey];
}
}
/**
* return an object containing only JSend attributes
* @returns {{status: *, code: *, message: *, data: (*|string|Object[]|Object|String)}}
*/
errorFn.prototype.toJSend = function () {
var data = this.data;
if (erroz.options.includeStack && this.stack) {
data.stack = this.stack;
}
if (!this.status) {
this.status = deriveStatusFromStatusCode(this.statusCode);
}
return {
status: this.status,
code: this.code,
message: this.message,
data: data
};
};
return errorFn;
} | javascript | function erroz(error) {
var errorFn = function (data) {
//apply all attributes on the instance
for (var errKey in errorFn.prototype) {
if (errorFn.prototype.hasOwnProperty(errKey)) {
this[errKey] = errorFn.prototype[errKey];
}
}
//overwrite message if invoked with string
if (typeof data === "string") {
this.message = data;
data = {};
}
this.data = data || {};
this.message = this.message || erroz.options.renderMessage(error.template || "", this.data);
errorFn.super_.call(this, this.constructor);
};
util.inherits(errorFn, AbstractError);
//add static error properties (name, status, etc)
for (var errKey in error) {
if (error.hasOwnProperty(errKey)) {
errorFn.prototype[errKey] = error[errKey];
}
}
/**
* return an object containing only JSend attributes
* @returns {{status: *, code: *, message: *, data: (*|string|Object[]|Object|String)}}
*/
errorFn.prototype.toJSend = function () {
var data = this.data;
if (erroz.options.includeStack && this.stack) {
data.stack = this.stack;
}
if (!this.status) {
this.status = deriveStatusFromStatusCode(this.statusCode);
}
return {
status: this.status,
code: this.code,
message: this.message,
data: data
};
};
return errorFn;
} | [
"function",
"erroz",
"(",
"error",
")",
"{",
"var",
"errorFn",
"=",
"function",
"(",
"data",
")",
"{",
"for",
"(",
"var",
"errKey",
"in",
"errorFn",
".",
"prototype",
")",
"{",
"if",
"(",
"errorFn",
".",
"prototype",
".",
"hasOwnProperty",
"(",
"errKey",
")",
")",
"{",
"this",
"[",
"errKey",
"]",
"=",
"errorFn",
".",
"prototype",
"[",
"errKey",
"]",
";",
"}",
"}",
"if",
"(",
"typeof",
"data",
"===",
"\"string\"",
")",
"{",
"this",
".",
"message",
"=",
"data",
";",
"data",
"=",
"{",
"}",
";",
"}",
"this",
".",
"data",
"=",
"data",
"||",
"{",
"}",
";",
"this",
".",
"message",
"=",
"this",
".",
"message",
"||",
"erroz",
".",
"options",
".",
"renderMessage",
"(",
"error",
".",
"template",
"||",
"\"\"",
",",
"this",
".",
"data",
")",
";",
"errorFn",
".",
"super_",
".",
"call",
"(",
"this",
",",
"this",
".",
"constructor",
")",
";",
"}",
";",
"util",
".",
"inherits",
"(",
"errorFn",
",",
"AbstractError",
")",
";",
"for",
"(",
"var",
"errKey",
"in",
"error",
")",
"{",
"if",
"(",
"error",
".",
"hasOwnProperty",
"(",
"errKey",
")",
")",
"{",
"errorFn",
".",
"prototype",
"[",
"errKey",
"]",
"=",
"error",
"[",
"errKey",
"]",
";",
"}",
"}",
"errorFn",
".",
"prototype",
".",
"toJSend",
"=",
"function",
"(",
")",
"{",
"var",
"data",
"=",
"this",
".",
"data",
";",
"if",
"(",
"erroz",
".",
"options",
".",
"includeStack",
"&&",
"this",
".",
"stack",
")",
"{",
"data",
".",
"stack",
"=",
"this",
".",
"stack",
";",
"}",
"if",
"(",
"!",
"this",
".",
"status",
")",
"{",
"this",
".",
"status",
"=",
"deriveStatusFromStatusCode",
"(",
"this",
".",
"statusCode",
")",
";",
"}",
"return",
"{",
"status",
":",
"this",
".",
"status",
",",
"code",
":",
"this",
".",
"code",
",",
"message",
":",
"this",
".",
"message",
",",
"data",
":",
"data",
"}",
";",
"}",
";",
"return",
"errorFn",
";",
"}"
] | generate Error-classes based on ErrozError
@param error
@returns {Function} | [
"generate",
"Error",
"-",
"classes",
"based",
"on",
"ErrozError"
] | 57adf5fa7a86680da2c6460b81aaaceaa57db6bd | https://github.com/peerigon/erroz/blob/57adf5fa7a86680da2c6460b81aaaceaa57db6bd/lib/index.js#L14-L71 | train |
OpusCapita/npm-scripts | bin/update-changelog.js | metadata | function metadata(log, value) {
var lines = value.split('\n');
log.commit = lines[0].split(' ')[1];
log.author = lines[1].split(':')[1].trim();
log.date = lines[2].slice(8);
return log
} | javascript | function metadata(log, value) {
var lines = value.split('\n');
log.commit = lines[0].split(' ')[1];
log.author = lines[1].split(':')[1].trim();
log.date = lines[2].slice(8);
return log
} | [
"function",
"metadata",
"(",
"log",
",",
"value",
")",
"{",
"var",
"lines",
"=",
"value",
".",
"split",
"(",
"'\\n'",
")",
";",
"\\n",
"log",
".",
"commit",
"=",
"lines",
"[",
"0",
"]",
".",
"split",
"(",
"' '",
")",
"[",
"1",
"]",
";",
"log",
".",
"author",
"=",
"lines",
"[",
"1",
"]",
".",
"split",
"(",
"':'",
")",
"[",
"1",
"]",
".",
"trim",
"(",
")",
";",
"log",
".",
"date",
"=",
"lines",
"[",
"2",
"]",
".",
"slice",
"(",
"8",
")",
";",
"}"
] | parse git log | [
"parse",
"git",
"log"
] | d70c80f48ebbd862c84617de834d239cecd17023 | https://github.com/OpusCapita/npm-scripts/blob/d70c80f48ebbd862c84617de834d239cecd17023/bin/update-changelog.js#L36-L42 | train |
djgrant/heidelberg | js/lib/hammer.js | stopDefaultBrowserBehavior | function stopDefaultBrowserBehavior(element, css_props) {
if(!css_props || !element || !element.style) {
return;
}
// with css properties for modern browsers
Hammer.utils.each(['webkit', 'khtml', 'moz', 'Moz', 'ms', 'o', ''], function(vendor) {
Hammer.utils.each(css_props, function(value, prop) {
// vender prefix at the property
if(vendor) {
prop = vendor + prop.substring(0, 1).toUpperCase() + prop.substring(1);
}
// set the style
if(prop in element.style) {
element.style[prop] = value;
}
});
});
// also the disable onselectstart
if(css_props.userSelect == 'none') {
element.onselectstart = function() {
return false;
};
}
// and disable ondragstart
if(css_props.userDrag == 'none') {
element.ondragstart = function() {
return false;
};
}
} | javascript | function stopDefaultBrowserBehavior(element, css_props) {
if(!css_props || !element || !element.style) {
return;
}
// with css properties for modern browsers
Hammer.utils.each(['webkit', 'khtml', 'moz', 'Moz', 'ms', 'o', ''], function(vendor) {
Hammer.utils.each(css_props, function(value, prop) {
// vender prefix at the property
if(vendor) {
prop = vendor + prop.substring(0, 1).toUpperCase() + prop.substring(1);
}
// set the style
if(prop in element.style) {
element.style[prop] = value;
}
});
});
// also the disable onselectstart
if(css_props.userSelect == 'none') {
element.onselectstart = function() {
return false;
};
}
// and disable ondragstart
if(css_props.userDrag == 'none') {
element.ondragstart = function() {
return false;
};
}
} | [
"function",
"stopDefaultBrowserBehavior",
"(",
"element",
",",
"css_props",
")",
"{",
"if",
"(",
"!",
"css_props",
"||",
"!",
"element",
"||",
"!",
"element",
".",
"style",
")",
"{",
"return",
";",
"}",
"Hammer",
".",
"utils",
".",
"each",
"(",
"[",
"'webkit'",
",",
"'khtml'",
",",
"'moz'",
",",
"'Moz'",
",",
"'ms'",
",",
"'o'",
",",
"''",
"]",
",",
"function",
"(",
"vendor",
")",
"{",
"Hammer",
".",
"utils",
".",
"each",
"(",
"css_props",
",",
"function",
"(",
"value",
",",
"prop",
")",
"{",
"if",
"(",
"vendor",
")",
"{",
"prop",
"=",
"vendor",
"+",
"prop",
".",
"substring",
"(",
"0",
",",
"1",
")",
".",
"toUpperCase",
"(",
")",
"+",
"prop",
".",
"substring",
"(",
"1",
")",
";",
"}",
"if",
"(",
"prop",
"in",
"element",
".",
"style",
")",
"{",
"element",
".",
"style",
"[",
"prop",
"]",
"=",
"value",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"if",
"(",
"css_props",
".",
"userSelect",
"==",
"'none'",
")",
"{",
"element",
".",
"onselectstart",
"=",
"function",
"(",
")",
"{",
"return",
"false",
";",
"}",
";",
"}",
"if",
"(",
"css_props",
".",
"userDrag",
"==",
"'none'",
")",
"{",
"element",
".",
"ondragstart",
"=",
"function",
"(",
")",
"{",
"return",
"false",
";",
"}",
";",
"}",
"}"
] | stop browser default behavior with css props
@param {HtmlElement} element
@param {Object} css_props | [
"stop",
"browser",
"default",
"behavior",
"with",
"css",
"props"
] | 151e254962055c1c4d7705a5eb277b96cb9a7849 | https://github.com/djgrant/heidelberg/blob/151e254962055c1c4d7705a5eb277b96cb9a7849/js/lib/hammer.js#L303-L335 | train |
djgrant/heidelberg | js/lib/hammer.js | detect | function detect(eventData) {
if(!this.current || this.stopped) {
return;
}
// extend event data with calculations about scale, distance etc
eventData = this.extendEventData(eventData);
// instance options
var inst_options = this.current.inst.options;
// call Hammer.gesture handlers
Hammer.utils.each(this.gestures, function(gesture) {
// only when the instance options have enabled this gesture
if(!this.stopped && inst_options[gesture.name] !== false) {
// if a handler returns false, we stop with the detection
if(gesture.handler.call(gesture, eventData, this.current.inst) === false) {
this.stopDetect();
return false;
}
}
}, this);
// store as previous event event
if(this.current) {
this.current.lastEvent = eventData;
}
// endevent, but not the last touch, so dont stop
if(eventData.eventType == Hammer.EVENT_END && !eventData.touches.length - 1) {
this.stopDetect();
}
return eventData;
} | javascript | function detect(eventData) {
if(!this.current || this.stopped) {
return;
}
// extend event data with calculations about scale, distance etc
eventData = this.extendEventData(eventData);
// instance options
var inst_options = this.current.inst.options;
// call Hammer.gesture handlers
Hammer.utils.each(this.gestures, function(gesture) {
// only when the instance options have enabled this gesture
if(!this.stopped && inst_options[gesture.name] !== false) {
// if a handler returns false, we stop with the detection
if(gesture.handler.call(gesture, eventData, this.current.inst) === false) {
this.stopDetect();
return false;
}
}
}, this);
// store as previous event event
if(this.current) {
this.current.lastEvent = eventData;
}
// endevent, but not the last touch, so dont stop
if(eventData.eventType == Hammer.EVENT_END && !eventData.touches.length - 1) {
this.stopDetect();
}
return eventData;
} | [
"function",
"detect",
"(",
"eventData",
")",
"{",
"if",
"(",
"!",
"this",
".",
"current",
"||",
"this",
".",
"stopped",
")",
"{",
"return",
";",
"}",
"eventData",
"=",
"this",
".",
"extendEventData",
"(",
"eventData",
")",
";",
"var",
"inst_options",
"=",
"this",
".",
"current",
".",
"inst",
".",
"options",
";",
"Hammer",
".",
"utils",
".",
"each",
"(",
"this",
".",
"gestures",
",",
"function",
"(",
"gesture",
")",
"{",
"if",
"(",
"!",
"this",
".",
"stopped",
"&&",
"inst_options",
"[",
"gesture",
".",
"name",
"]",
"!==",
"false",
")",
"{",
"if",
"(",
"gesture",
".",
"handler",
".",
"call",
"(",
"gesture",
",",
"eventData",
",",
"this",
".",
"current",
".",
"inst",
")",
"===",
"false",
")",
"{",
"this",
".",
"stopDetect",
"(",
")",
";",
"return",
"false",
";",
"}",
"}",
"}",
",",
"this",
")",
";",
"if",
"(",
"this",
".",
"current",
")",
"{",
"this",
".",
"current",
".",
"lastEvent",
"=",
"eventData",
";",
"}",
"if",
"(",
"eventData",
".",
"eventType",
"==",
"Hammer",
".",
"EVENT_END",
"&&",
"!",
"eventData",
".",
"touches",
".",
"length",
"-",
"1",
")",
"{",
"this",
".",
"stopDetect",
"(",
")",
";",
"}",
"return",
"eventData",
";",
"}"
] | Hammer.gesture detection
@param {Object} eventData | [
"Hammer",
".",
"gesture",
"detection"
] | 151e254962055c1c4d7705a5eb277b96cb9a7849 | https://github.com/djgrant/heidelberg/blob/151e254962055c1c4d7705a5eb277b96cb9a7849/js/lib/hammer.js#L816-L850 | train |
djgrant/heidelberg | js/lib/hammer.js | stopDetect | function stopDetect() {
// clone current data to the store as the previous gesture
// used for the double tap gesture, since this is an other gesture detect session
this.previous = Hammer.utils.extend({}, this.current);
// reset the current
this.current = null;
// stopped!
this.stopped = true;
} | javascript | function stopDetect() {
// clone current data to the store as the previous gesture
// used for the double tap gesture, since this is an other gesture detect session
this.previous = Hammer.utils.extend({}, this.current);
// reset the current
this.current = null;
// stopped!
this.stopped = true;
} | [
"function",
"stopDetect",
"(",
")",
"{",
"this",
".",
"previous",
"=",
"Hammer",
".",
"utils",
".",
"extend",
"(",
"{",
"}",
",",
"this",
".",
"current",
")",
";",
"this",
".",
"current",
"=",
"null",
";",
"this",
".",
"stopped",
"=",
"true",
";",
"}"
] | clear the Hammer.gesture vars
this is called on endDetect, but can also be used when a final Hammer.gesture has been detected
to stop other Hammer.gestures from being fired | [
"clear",
"the",
"Hammer",
".",
"gesture",
"vars",
"this",
"is",
"called",
"on",
"endDetect",
"but",
"can",
"also",
"be",
"used",
"when",
"a",
"final",
"Hammer",
".",
"gesture",
"has",
"been",
"detected",
"to",
"stop",
"other",
"Hammer",
".",
"gestures",
"from",
"being",
"fired"
] | 151e254962055c1c4d7705a5eb277b96cb9a7849 | https://github.com/djgrant/heidelberg/blob/151e254962055c1c4d7705a5eb277b96cb9a7849/js/lib/hammer.js#L858-L868 | train |
djgrant/heidelberg | js/lib/hammer.js | register | function register(gesture) {
// add an enable gesture options if there is no given
var options = gesture.defaults || {};
if(options[gesture.name] === undefined) {
options[gesture.name] = true;
}
// extend Hammer default options with the Hammer.gesture options
Hammer.utils.extend(Hammer.defaults, options, true);
// set its index
gesture.index = gesture.index || 1000;
// add Hammer.gesture to the list
this.gestures.push(gesture);
// sort the list by index
this.gestures.sort(function(a, b) {
if(a.index < b.index) { return -1; }
if(a.index > b.index) { return 1; }
return 0;
});
return this.gestures;
} | javascript | function register(gesture) {
// add an enable gesture options if there is no given
var options = gesture.defaults || {};
if(options[gesture.name] === undefined) {
options[gesture.name] = true;
}
// extend Hammer default options with the Hammer.gesture options
Hammer.utils.extend(Hammer.defaults, options, true);
// set its index
gesture.index = gesture.index || 1000;
// add Hammer.gesture to the list
this.gestures.push(gesture);
// sort the list by index
this.gestures.sort(function(a, b) {
if(a.index < b.index) { return -1; }
if(a.index > b.index) { return 1; }
return 0;
});
return this.gestures;
} | [
"function",
"register",
"(",
"gesture",
")",
"{",
"var",
"options",
"=",
"gesture",
".",
"defaults",
"||",
"{",
"}",
";",
"if",
"(",
"options",
"[",
"gesture",
".",
"name",
"]",
"===",
"undefined",
")",
"{",
"options",
"[",
"gesture",
".",
"name",
"]",
"=",
"true",
";",
"}",
"Hammer",
".",
"utils",
".",
"extend",
"(",
"Hammer",
".",
"defaults",
",",
"options",
",",
"true",
")",
";",
"gesture",
".",
"index",
"=",
"gesture",
".",
"index",
"||",
"1000",
";",
"this",
".",
"gestures",
".",
"push",
"(",
"gesture",
")",
";",
"this",
".",
"gestures",
".",
"sort",
"(",
"function",
"(",
"a",
",",
"b",
")",
"{",
"if",
"(",
"a",
".",
"index",
"<",
"b",
".",
"index",
")",
"{",
"return",
"-",
"1",
";",
"}",
"if",
"(",
"a",
".",
"index",
">",
"b",
".",
"index",
")",
"{",
"return",
"1",
";",
"}",
"return",
"0",
";",
"}",
")",
";",
"return",
"this",
".",
"gestures",
";",
"}"
] | register new gesture
@param {Object} gesture object, see gestures.js for documentation
@returns {Array} gestures | [
"register",
"new",
"gesture"
] | 151e254962055c1c4d7705a5eb277b96cb9a7849 | https://github.com/djgrant/heidelberg/blob/151e254962055c1c4d7705a5eb277b96cb9a7849/js/lib/hammer.js#L943-L967 | train |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.