id int32 0 58k | repo stringlengths 5 67 | path stringlengths 4 116 | func_name stringlengths 0 58 | original_string stringlengths 52 373k | language stringclasses 1 value | code stringlengths 52 373k | code_tokens list | docstring stringlengths 4 11.8k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 86 226 |
|---|---|---|---|---|---|---|---|---|---|---|---|
22,900 | smoketurner/serverless-vpc-plugin | src/vpce.js | buildLambdaVPCEndpointSecurityGroup | function buildLambdaVPCEndpointSecurityGroup({ name = 'LambdaEndpointSecurityGroup' } = {}) {
return {
[name]: {
Type: 'AWS::EC2::SecurityGroup',
Properties: {
GroupDescription: 'Lambda access to VPC endpoints',
VpcId: {
Ref: 'VPC',
},
SecurityGroupIngress: [
{
SourceSecurityGroupId: {
Ref: 'LambdaExecutionSecurityGroup',
},
Description: 'Allow inbound HTTPS traffic from LambdaExecutionSecurityGroup',
IpProtocol: 'tcp',
FromPort: 443,
ToPort: 443,
},
],
Tags: [
{
Key: 'Name',
Value: {
'Fn::Join': [
'-',
[
{
Ref: 'AWS::StackName',
},
'lambda-endpoint',
],
],
},
},
],
},
},
};
} | javascript | function buildLambdaVPCEndpointSecurityGroup({ name = 'LambdaEndpointSecurityGroup' } = {}) {
return {
[name]: {
Type: 'AWS::EC2::SecurityGroup',
Properties: {
GroupDescription: 'Lambda access to VPC endpoints',
VpcId: {
Ref: 'VPC',
},
SecurityGroupIngress: [
{
SourceSecurityGroupId: {
Ref: 'LambdaExecutionSecurityGroup',
},
Description: 'Allow inbound HTTPS traffic from LambdaExecutionSecurityGroup',
IpProtocol: 'tcp',
FromPort: 443,
ToPort: 443,
},
],
Tags: [
{
Key: 'Name',
Value: {
'Fn::Join': [
'-',
[
{
Ref: 'AWS::StackName',
},
'lambda-endpoint',
],
],
},
},
],
},
},
};
} | [
"function",
"buildLambdaVPCEndpointSecurityGroup",
"(",
"{",
"name",
"=",
"'LambdaEndpointSecurityGroup'",
"}",
"=",
"{",
"}",
")",
"{",
"return",
"{",
"[",
"name",
"]",
":",
"{",
"Type",
":",
"'AWS::EC2::SecurityGroup'",
",",
"Properties",
":",
"{",
"GroupDescription",
":",
"'Lambda access to VPC endpoints'",
",",
"VpcId",
":",
"{",
"Ref",
":",
"'VPC'",
",",
"}",
",",
"SecurityGroupIngress",
":",
"[",
"{",
"SourceSecurityGroupId",
":",
"{",
"Ref",
":",
"'LambdaExecutionSecurityGroup'",
",",
"}",
",",
"Description",
":",
"'Allow inbound HTTPS traffic from LambdaExecutionSecurityGroup'",
",",
"IpProtocol",
":",
"'tcp'",
",",
"FromPort",
":",
"443",
",",
"ToPort",
":",
"443",
",",
"}",
",",
"]",
",",
"Tags",
":",
"[",
"{",
"Key",
":",
"'Name'",
",",
"Value",
":",
"{",
"'Fn::Join'",
":",
"[",
"'-'",
",",
"[",
"{",
"Ref",
":",
"'AWS::StackName'",
",",
"}",
",",
"'lambda-endpoint'",
",",
"]",
",",
"]",
",",
"}",
",",
"}",
",",
"]",
",",
"}",
",",
"}",
",",
"}",
";",
"}"
] | Build a SecurityGroup to allow the Lambda's access to VPC endpoints over HTTPS.
@param {Object} params
@return {Object} | [
"Build",
"a",
"SecurityGroup",
"to",
"allow",
"the",
"Lambda",
"s",
"access",
"to",
"VPC",
"endpoints",
"over",
"HTTPS",
"."
] | 21a862ac01cc14fc5699fc9d7978bd736622cc1d | https://github.com/smoketurner/serverless-vpc-plugin/blob/21a862ac01cc14fc5699fc9d7978bd736622cc1d/src/vpce.js#L118-L157 |
22,901 | smoketurner/serverless-vpc-plugin | src/outputs.js | buildOutputs | function buildOutputs(createBastionHost = false) {
const outputs = {
VPC: {
Description: 'VPC logical resource ID',
Value: {
Ref: 'VPC',
},
},
LambdaExecutionSecurityGroupId: {
Description:
'Security Group logical resource ID that the Lambda functions use when executing within the VPC',
Value: {
Ref: 'LambdaExecutionSecurityGroup',
},
},
};
if (createBastionHost) {
outputs.BastionSSHUser = {
Description: 'SSH username for the Bastion host',
Value: 'ec2-user',
};
outputs.BastionEIP = {
Description: 'Public IP of Bastion host',
Value: {
Ref: 'BastionEIP',
},
};
}
return outputs;
} | javascript | function buildOutputs(createBastionHost = false) {
const outputs = {
VPC: {
Description: 'VPC logical resource ID',
Value: {
Ref: 'VPC',
},
},
LambdaExecutionSecurityGroupId: {
Description:
'Security Group logical resource ID that the Lambda functions use when executing within the VPC',
Value: {
Ref: 'LambdaExecutionSecurityGroup',
},
},
};
if (createBastionHost) {
outputs.BastionSSHUser = {
Description: 'SSH username for the Bastion host',
Value: 'ec2-user',
};
outputs.BastionEIP = {
Description: 'Public IP of Bastion host',
Value: {
Ref: 'BastionEIP',
},
};
}
return outputs;
} | [
"function",
"buildOutputs",
"(",
"createBastionHost",
"=",
"false",
")",
"{",
"const",
"outputs",
"=",
"{",
"VPC",
":",
"{",
"Description",
":",
"'VPC logical resource ID'",
",",
"Value",
":",
"{",
"Ref",
":",
"'VPC'",
",",
"}",
",",
"}",
",",
"LambdaExecutionSecurityGroupId",
":",
"{",
"Description",
":",
"'Security Group logical resource ID that the Lambda functions use when executing within the VPC'",
",",
"Value",
":",
"{",
"Ref",
":",
"'LambdaExecutionSecurityGroup'",
",",
"}",
",",
"}",
",",
"}",
";",
"if",
"(",
"createBastionHost",
")",
"{",
"outputs",
".",
"BastionSSHUser",
"=",
"{",
"Description",
":",
"'SSH username for the Bastion host'",
",",
"Value",
":",
"'ec2-user'",
",",
"}",
";",
"outputs",
".",
"BastionEIP",
"=",
"{",
"Description",
":",
"'Public IP of Bastion host'",
",",
"Value",
":",
"{",
"Ref",
":",
"'BastionEIP'",
",",
"}",
",",
"}",
";",
"}",
"return",
"outputs",
";",
"}"
] | Build CloudFormation Outputs on common resources
@param {Boolean} createBastionHost
@return {Object} | [
"Build",
"CloudFormation",
"Outputs",
"on",
"common",
"resources"
] | 21a862ac01cc14fc5699fc9d7978bd736622cc1d | https://github.com/smoketurner/serverless-vpc-plugin/blob/21a862ac01cc14fc5699fc9d7978bd736622cc1d/src/outputs.js#L7-L38 |
22,902 | vm-component/vimo | build/doc-builder/theme/fixtures/documents/probe.js | processNestedOperator | function processNestedOperator( path, operand ) {
var opKeys = Object.keys( operand );
return {
operation : opKeys[ 0 ],
operands : [operand[ opKeys[ 0 ] ]],
path : path
};
} | javascript | function processNestedOperator( path, operand ) {
var opKeys = Object.keys( operand );
return {
operation : opKeys[ 0 ],
operands : [operand[ opKeys[ 0 ] ]],
path : path
};
} | [
"function",
"processNestedOperator",
"(",
"path",
",",
"operand",
")",
"{",
"var",
"opKeys",
"=",
"Object",
".",
"keys",
"(",
"operand",
")",
";",
"return",
"{",
"operation",
":",
"opKeys",
"[",
"0",
"]",
",",
"operands",
":",
"[",
"operand",
"[",
"opKeys",
"[",
"0",
"]",
"]",
"]",
",",
"path",
":",
"path",
"}",
";",
"}"
] | Processes a nested operator by picking the operator out of the expression object. Returns a formatted object that can be used for querying
@private
@param {string} path The path to element to work with
@param {object} operand The operands to use for the query
@return {object} A formatted operation definition | [
"Processes",
"a",
"nested",
"operator",
"by",
"picking",
"the",
"operator",
"out",
"of",
"the",
"expression",
"object",
".",
"Returns",
"a",
"formatted",
"object",
"that",
"can",
"be",
"used",
"for",
"querying"
] | 52b4f66fd3f1d244e8e6b72f9d0fa7aa675c78a7 | https://github.com/vm-component/vimo/blob/52b4f66fd3f1d244e8e6b72f9d0fa7aa675c78a7/build/doc-builder/theme/fixtures/documents/probe.js#L33-L40 |
22,903 | vm-component/vimo | build/doc-builder/theme/fixtures/documents/probe.js | processExpressionObject | function processExpressionObject( val, key ) {
var operator;
if ( sys.isObject( val ) ) {
var opKeys = Object.keys( val );
var op = opKeys[ 0 ];
if ( sys.indexOf( nestedOps, op ) > -1 ) {
operator = processNestedOperator( key, val );
} else if ( sys.indexOf( prefixOps, key ) > -1 ) {
operator = processPrefixOperator( key, val );
} else if ( op === "$regex" ) {
// special handling for regex options
operator = processNestedOperator( key, val );
} else if ( op === "$elemMatch" ) {
// elemMatch is just a weird duck
operator = {
path : key,
operation : op,
operands : []
};
sys.each( val[ op ], function ( entry ) {
operator.operands = parseQueryExpression( entry );
} );
}
else {
throw new Error( "Unrecognized operator" );
}
} else {
operator = processNestedOperator( key, { $eq : val } );
}
return operator;
} | javascript | function processExpressionObject( val, key ) {
var operator;
if ( sys.isObject( val ) ) {
var opKeys = Object.keys( val );
var op = opKeys[ 0 ];
if ( sys.indexOf( nestedOps, op ) > -1 ) {
operator = processNestedOperator( key, val );
} else if ( sys.indexOf( prefixOps, key ) > -1 ) {
operator = processPrefixOperator( key, val );
} else if ( op === "$regex" ) {
// special handling for regex options
operator = processNestedOperator( key, val );
} else if ( op === "$elemMatch" ) {
// elemMatch is just a weird duck
operator = {
path : key,
operation : op,
operands : []
};
sys.each( val[ op ], function ( entry ) {
operator.operands = parseQueryExpression( entry );
} );
}
else {
throw new Error( "Unrecognized operator" );
}
} else {
operator = processNestedOperator( key, { $eq : val } );
}
return operator;
} | [
"function",
"processExpressionObject",
"(",
"val",
",",
"key",
")",
"{",
"var",
"operator",
";",
"if",
"(",
"sys",
".",
"isObject",
"(",
"val",
")",
")",
"{",
"var",
"opKeys",
"=",
"Object",
".",
"keys",
"(",
"val",
")",
";",
"var",
"op",
"=",
"opKeys",
"[",
"0",
"]",
";",
"if",
"(",
"sys",
".",
"indexOf",
"(",
"nestedOps",
",",
"op",
")",
">",
"-",
"1",
")",
"{",
"operator",
"=",
"processNestedOperator",
"(",
"key",
",",
"val",
")",
";",
"}",
"else",
"if",
"(",
"sys",
".",
"indexOf",
"(",
"prefixOps",
",",
"key",
")",
">",
"-",
"1",
")",
"{",
"operator",
"=",
"processPrefixOperator",
"(",
"key",
",",
"val",
")",
";",
"}",
"else",
"if",
"(",
"op",
"===",
"\"$regex\"",
")",
"{",
"// special handling for regex options",
"operator",
"=",
"processNestedOperator",
"(",
"key",
",",
"val",
")",
";",
"}",
"else",
"if",
"(",
"op",
"===",
"\"$elemMatch\"",
")",
"{",
"// elemMatch is just a weird duck",
"operator",
"=",
"{",
"path",
":",
"key",
",",
"operation",
":",
"op",
",",
"operands",
":",
"[",
"]",
"}",
";",
"sys",
".",
"each",
"(",
"val",
"[",
"op",
"]",
",",
"function",
"(",
"entry",
")",
"{",
"operator",
".",
"operands",
"=",
"parseQueryExpression",
"(",
"entry",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"\"Unrecognized operator\"",
")",
";",
"}",
"}",
"else",
"{",
"operator",
"=",
"processNestedOperator",
"(",
"key",
",",
"{",
"$eq",
":",
"val",
"}",
")",
";",
"}",
"return",
"operator",
";",
"}"
] | Interrogates a single query expression object and calls the appropriate handler for its contents
@private
@param {object} val The expression
@param {object} key The prefix
@returns {object} A formatted operation definition | [
"Interrogates",
"a",
"single",
"query",
"expression",
"object",
"and",
"calls",
"the",
"appropriate",
"handler",
"for",
"its",
"contents"
] | 52b4f66fd3f1d244e8e6b72f9d0fa7aa675c78a7 | https://github.com/vm-component/vimo/blob/52b4f66fd3f1d244e8e6b72f9d0fa7aa675c78a7/build/doc-builder/theme/fixtures/documents/probe.js#L49-L80 |
22,904 | vm-component/vimo | build/doc-builder/theme/fixtures/documents/probe.js | processPrefixOperator | function processPrefixOperator( operation, operand ) {
var component = {
operation : operation,
path : null,
operands : []
};
if ( sys.isArray( operand ) ) {
//if it is an array we need to loop through the array and parse each operand
//if it is an array we need to loop through the array and parse each operand
sys.each( operand, function ( obj ) {
sys.each( obj, function ( val, key ) {
component.operands.push( processExpressionObject( val, key ) );
} );
} );
} else {
//otherwise it is an object and we can parse it directly
sys.each( operand, function ( val, key ) {
component.operands.push( processExpressionObject( val, key ) );
} );
}
return component;
} | javascript | function processPrefixOperator( operation, operand ) {
var component = {
operation : operation,
path : null,
operands : []
};
if ( sys.isArray( operand ) ) {
//if it is an array we need to loop through the array and parse each operand
//if it is an array we need to loop through the array and parse each operand
sys.each( operand, function ( obj ) {
sys.each( obj, function ( val, key ) {
component.operands.push( processExpressionObject( val, key ) );
} );
} );
} else {
//otherwise it is an object and we can parse it directly
sys.each( operand, function ( val, key ) {
component.operands.push( processExpressionObject( val, key ) );
} );
}
return component;
} | [
"function",
"processPrefixOperator",
"(",
"operation",
",",
"operand",
")",
"{",
"var",
"component",
"=",
"{",
"operation",
":",
"operation",
",",
"path",
":",
"null",
",",
"operands",
":",
"[",
"]",
"}",
";",
"if",
"(",
"sys",
".",
"isArray",
"(",
"operand",
")",
")",
"{",
"//if it is an array we need to loop through the array and parse each operand",
"//if it is an array we need to loop through the array and parse each operand",
"sys",
".",
"each",
"(",
"operand",
",",
"function",
"(",
"obj",
")",
"{",
"sys",
".",
"each",
"(",
"obj",
",",
"function",
"(",
"val",
",",
"key",
")",
"{",
"component",
".",
"operands",
".",
"push",
"(",
"processExpressionObject",
"(",
"val",
",",
"key",
")",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"//otherwise it is an object and we can parse it directly",
"sys",
".",
"each",
"(",
"operand",
",",
"function",
"(",
"val",
",",
"key",
")",
"{",
"component",
".",
"operands",
".",
"push",
"(",
"processExpressionObject",
"(",
"val",
",",
"key",
")",
")",
";",
"}",
")",
";",
"}",
"return",
"component",
";",
"}"
] | Processes a prefixed operator and then passes control to the nested operator method to pick out the contained values
@private
@param {string} operation The operation prefix
@param {object} operand The operands to use for the query
@return {object} A formatted operation definition | [
"Processes",
"a",
"prefixed",
"operator",
"and",
"then",
"passes",
"control",
"to",
"the",
"nested",
"operator",
"method",
"to",
"pick",
"out",
"the",
"contained",
"values"
] | 52b4f66fd3f1d244e8e6b72f9d0fa7aa675c78a7 | https://github.com/vm-component/vimo/blob/52b4f66fd3f1d244e8e6b72f9d0fa7aa675c78a7/build/doc-builder/theme/fixtures/documents/probe.js#L89-L112 |
22,905 | vm-component/vimo | build/doc-builder/theme/fixtures/documents/probe.js | parseQueryExpression | function parseQueryExpression( obj ) {
if ( sys.size( obj ) > 1 ) {
var arr = sys.map( obj, function ( v, k ) {
var entry = {};
entry[k] = v;
return entry;
} );
obj = {
$and : arr
};
}
var payload = [];
sys.each( obj, function ( val, key ) {
var exprObj = processExpressionObject( val, key );
if ( exprObj.operation === "$regex" ) {
exprObj.options = val.$options;
}
payload.push( exprObj );
} );
return payload;
} | javascript | function parseQueryExpression( obj ) {
if ( sys.size( obj ) > 1 ) {
var arr = sys.map( obj, function ( v, k ) {
var entry = {};
entry[k] = v;
return entry;
} );
obj = {
$and : arr
};
}
var payload = [];
sys.each( obj, function ( val, key ) {
var exprObj = processExpressionObject( val, key );
if ( exprObj.operation === "$regex" ) {
exprObj.options = val.$options;
}
payload.push( exprObj );
} );
return payload;
} | [
"function",
"parseQueryExpression",
"(",
"obj",
")",
"{",
"if",
"(",
"sys",
".",
"size",
"(",
"obj",
")",
">",
"1",
")",
"{",
"var",
"arr",
"=",
"sys",
".",
"map",
"(",
"obj",
",",
"function",
"(",
"v",
",",
"k",
")",
"{",
"var",
"entry",
"=",
"{",
"}",
";",
"entry",
"[",
"k",
"]",
"=",
"v",
";",
"return",
"entry",
";",
"}",
")",
";",
"obj",
"=",
"{",
"$and",
":",
"arr",
"}",
";",
"}",
"var",
"payload",
"=",
"[",
"]",
";",
"sys",
".",
"each",
"(",
"obj",
",",
"function",
"(",
"val",
",",
"key",
")",
"{",
"var",
"exprObj",
"=",
"processExpressionObject",
"(",
"val",
",",
"key",
")",
";",
"if",
"(",
"exprObj",
".",
"operation",
"===",
"\"$regex\"",
")",
"{",
"exprObj",
".",
"options",
"=",
"val",
".",
"$options",
";",
"}",
"payload",
".",
"push",
"(",
"exprObj",
")",
";",
"}",
")",
";",
"return",
"payload",
";",
"}"
] | Parses a query request and builds an object that can used to process a query target
@private
@param {object} obj The expression object
@returns {object} All components of the expression in a kind of execution tree | [
"Parses",
"a",
"query",
"request",
"and",
"builds",
"an",
"object",
"that",
"can",
"used",
"to",
"process",
"a",
"query",
"target"
] | 52b4f66fd3f1d244e8e6b72f9d0fa7aa675c78a7 | https://github.com/vm-component/vimo/blob/52b4f66fd3f1d244e8e6b72f9d0fa7aa675c78a7/build/doc-builder/theme/fixtures/documents/probe.js#L121-L145 |
22,906 | vm-component/vimo | build/doc-builder/theme/fixtures/documents/probe.js | reachin | function reachin( path, record ) {
var context = record;
var part;
var _i;
var _len;
for ( _i = 0, _len = path.length; _i < _len; _i++ ) {
part = path[_i];
context = context[part];
if ( sys.isNull( context ) || sys.isUndefined( context ) ) {
break;
}
}
return context;
} | javascript | function reachin( path, record ) {
var context = record;
var part;
var _i;
var _len;
for ( _i = 0, _len = path.length; _i < _len; _i++ ) {
part = path[_i];
context = context[part];
if ( sys.isNull( context ) || sys.isUndefined( context ) ) {
break;
}
}
return context;
} | [
"function",
"reachin",
"(",
"path",
",",
"record",
")",
"{",
"var",
"context",
"=",
"record",
";",
"var",
"part",
";",
"var",
"_i",
";",
"var",
"_len",
";",
"for",
"(",
"_i",
"=",
"0",
",",
"_len",
"=",
"path",
".",
"length",
";",
"_i",
"<",
"_len",
";",
"_i",
"++",
")",
"{",
"part",
"=",
"path",
"[",
"_i",
"]",
";",
"context",
"=",
"context",
"[",
"part",
"]",
";",
"if",
"(",
"sys",
".",
"isNull",
"(",
"context",
")",
"||",
"sys",
".",
"isUndefined",
"(",
"context",
")",
")",
"{",
"break",
";",
"}",
"}",
"return",
"context",
";",
"}"
] | Reaches into an object and allows you to get at a value deeply nested in an object
@private
@param {array} path The split path of the element to work with
@param {object} record The record to reach into
@return {*} Whatever was found in the record | [
"Reaches",
"into",
"an",
"object",
"and",
"allows",
"you",
"to",
"get",
"at",
"a",
"value",
"deeply",
"nested",
"in",
"an",
"object"
] | 52b4f66fd3f1d244e8e6b72f9d0fa7aa675c78a7 | https://github.com/vm-component/vimo/blob/52b4f66fd3f1d244e8e6b72f9d0fa7aa675c78a7/build/doc-builder/theme/fixtures/documents/probe.js#L174-L189 |
22,907 | vm-component/vimo | build/doc-builder/theme/fixtures/documents/probe.js | execQuery | function execQuery( obj, qu, shortCircuit, stopOnFirst ) {
var arrayResults = [];
var keyResults = [];
sys.each( obj, function ( record, key ) {
var expr, result, test, _i, _len;
for ( _i = 0, _len = qu.length; _i < _len; _i++ ) {
expr = qu[_i];
if ( expr.splitPath ) {
test = reachin( expr.splitPath, record, expr.operation );
}
result = operations[expr.operation]( expr, test, record );
if ( result ) {
arrayResults.push( record );
keyResults.push( key );
}
if ( !result && shortCircuit ) {
break;
}
}
if ( arrayResults.length > 0 && stopOnFirst ) {
return false;
}
} );
return {
arrayResults : arrayResults,
keyResults : keyResults
};
} | javascript | function execQuery( obj, qu, shortCircuit, stopOnFirst ) {
var arrayResults = [];
var keyResults = [];
sys.each( obj, function ( record, key ) {
var expr, result, test, _i, _len;
for ( _i = 0, _len = qu.length; _i < _len; _i++ ) {
expr = qu[_i];
if ( expr.splitPath ) {
test = reachin( expr.splitPath, record, expr.operation );
}
result = operations[expr.operation]( expr, test, record );
if ( result ) {
arrayResults.push( record );
keyResults.push( key );
}
if ( !result && shortCircuit ) {
break;
}
}
if ( arrayResults.length > 0 && stopOnFirst ) {
return false;
}
} );
return {
arrayResults : arrayResults,
keyResults : keyResults
};
} | [
"function",
"execQuery",
"(",
"obj",
",",
"qu",
",",
"shortCircuit",
",",
"stopOnFirst",
")",
"{",
"var",
"arrayResults",
"=",
"[",
"]",
";",
"var",
"keyResults",
"=",
"[",
"]",
";",
"sys",
".",
"each",
"(",
"obj",
",",
"function",
"(",
"record",
",",
"key",
")",
"{",
"var",
"expr",
",",
"result",
",",
"test",
",",
"_i",
",",
"_len",
";",
"for",
"(",
"_i",
"=",
"0",
",",
"_len",
"=",
"qu",
".",
"length",
";",
"_i",
"<",
"_len",
";",
"_i",
"++",
")",
"{",
"expr",
"=",
"qu",
"[",
"_i",
"]",
";",
"if",
"(",
"expr",
".",
"splitPath",
")",
"{",
"test",
"=",
"reachin",
"(",
"expr",
".",
"splitPath",
",",
"record",
",",
"expr",
".",
"operation",
")",
";",
"}",
"result",
"=",
"operations",
"[",
"expr",
".",
"operation",
"]",
"(",
"expr",
",",
"test",
",",
"record",
")",
";",
"if",
"(",
"result",
")",
"{",
"arrayResults",
".",
"push",
"(",
"record",
")",
";",
"keyResults",
".",
"push",
"(",
"key",
")",
";",
"}",
"if",
"(",
"!",
"result",
"&&",
"shortCircuit",
")",
"{",
"break",
";",
"}",
"}",
"if",
"(",
"arrayResults",
".",
"length",
">",
"0",
"&&",
"stopOnFirst",
")",
"{",
"return",
"false",
";",
"}",
"}",
")",
";",
"return",
"{",
"arrayResults",
":",
"arrayResults",
",",
"keyResults",
":",
"keyResults",
"}",
";",
"}"
] | Executes a query by traversing a document and evaluating each record
@private
@param {array|object} obj The object to query
@param {object} qu The query to execute
@param {?boolean} shortCircuit When true, the condition that matches the query stops evaluation for that record, otherwise all conditions have to be met
@param {?boolean} stopOnFirst When true all evaluation stops after the first record is found to match the conditons | [
"Executes",
"a",
"query",
"by",
"traversing",
"a",
"document",
"and",
"evaluating",
"each",
"record"
] | 52b4f66fd3f1d244e8e6b72f9d0fa7aa675c78a7 | https://github.com/vm-component/vimo/blob/52b4f66fd3f1d244e8e6b72f9d0fa7aa675c78a7/build/doc-builder/theme/fixtures/documents/probe.js#L698-L726 |
22,908 | DonutEspresso/big-json | tools/changelog.js | categorizeCommits | function categorizeCommits(rawCommits) {
const categorizedCommits = {};
// create a bucket of rawCommits by type:
// { fixes: [], upgrades: [], breaking: [] }
rawCommits.forEach(function(commit) {
const capType = capitalize(commit.type);
if (!categorizedCommits.hasOwnProperty(capType)) {
categorizedCommits[capType] = [];
}
categorizedCommits[capType].push(commit);
});
return categorizedCommits;
} | javascript | function categorizeCommits(rawCommits) {
const categorizedCommits = {};
// create a bucket of rawCommits by type:
// { fixes: [], upgrades: [], breaking: [] }
rawCommits.forEach(function(commit) {
const capType = capitalize(commit.type);
if (!categorizedCommits.hasOwnProperty(capType)) {
categorizedCommits[capType] = [];
}
categorizedCommits[capType].push(commit);
});
return categorizedCommits;
} | [
"function",
"categorizeCommits",
"(",
"rawCommits",
")",
"{",
"const",
"categorizedCommits",
"=",
"{",
"}",
";",
"// create a bucket of rawCommits by type:",
"// { fixes: [], upgrades: [], breaking: [] }",
"rawCommits",
".",
"forEach",
"(",
"function",
"(",
"commit",
")",
"{",
"const",
"capType",
"=",
"capitalize",
"(",
"commit",
".",
"type",
")",
";",
"if",
"(",
"!",
"categorizedCommits",
".",
"hasOwnProperty",
"(",
"capType",
")",
")",
"{",
"categorizedCommits",
"[",
"capType",
"]",
"=",
"[",
"]",
";",
"}",
"categorizedCommits",
"[",
"capType",
"]",
".",
"push",
"(",
"commit",
")",
";",
"}",
")",
";",
"return",
"categorizedCommits",
";",
"}"
] | categorize raw commits into types of commits for consumption into md.
@function categorizeCommits
@param {Array} rawCommits array of objects describing commits
@return {Object} | [
"categorize",
"raw",
"commits",
"into",
"types",
"of",
"commits",
"for",
"consumption",
"into",
"md",
"."
] | a26eacf659db71d8e5e0a619ef73bccce05354f0 | https://github.com/DonutEspresso/big-json/blob/a26eacf659db71d8e5e0a619ef73bccce05354f0/tools/changelog.js#L509-L527 |
22,909 | DonutEspresso/big-json | lib/index.js | createStringifyStream | function createStringifyStream(opts) {
assert.object(opts, 'opts');
assert.ok(Array.isArray(opts.body) || typeof opts.body === 'object',
'opts.body must be an array or object');
return stringifyStreamFactory(opts.body, null, null, true);
} | javascript | function createStringifyStream(opts) {
assert.object(opts, 'opts');
assert.ok(Array.isArray(opts.body) || typeof opts.body === 'object',
'opts.body must be an array or object');
return stringifyStreamFactory(opts.body, null, null, true);
} | [
"function",
"createStringifyStream",
"(",
"opts",
")",
"{",
"assert",
".",
"object",
"(",
"opts",
",",
"'opts'",
")",
";",
"assert",
".",
"ok",
"(",
"Array",
".",
"isArray",
"(",
"opts",
".",
"body",
")",
"||",
"typeof",
"opts",
".",
"body",
"===",
"'object'",
",",
"'opts.body must be an array or object'",
")",
";",
"return",
"stringifyStreamFactory",
"(",
"opts",
".",
"body",
",",
"null",
",",
"null",
",",
"true",
")",
";",
"}"
] | create a JSON.stringify readable stream.
@public
@param {Object} opts an options object
@param {Object} opts.body the JS object to JSON.stringify
@function createStringifyStream
@return {Stream} | [
"create",
"a",
"JSON",
".",
"stringify",
"readable",
"stream",
"."
] | a26eacf659db71d8e5e0a619ef73bccce05354f0 | https://github.com/DonutEspresso/big-json/blob/a26eacf659db71d8e5e0a619ef73bccce05354f0/lib/index.js#L68-L74 |
22,910 | DonutEspresso/big-json | lib/index.js | parse | function parse(opts, callback) {
assert.object(opts, 'opts');
assert.string(opts.body, 'opts.body');
assert.func(callback, 'callback');
const sourceStream = intoStream(opts.body);
const parseStream = createParseStream();
const cb = once(callback);
parseStream.on('data', function(data) {
return cb(null, data);
});
parseStream.on('error', function(err) {
return cb(err);
});
sourceStream.pipe(parseStream);
} | javascript | function parse(opts, callback) {
assert.object(opts, 'opts');
assert.string(opts.body, 'opts.body');
assert.func(callback, 'callback');
const sourceStream = intoStream(opts.body);
const parseStream = createParseStream();
const cb = once(callback);
parseStream.on('data', function(data) {
return cb(null, data);
});
parseStream.on('error', function(err) {
return cb(err);
});
sourceStream.pipe(parseStream);
} | [
"function",
"parse",
"(",
"opts",
",",
"callback",
")",
"{",
"assert",
".",
"object",
"(",
"opts",
",",
"'opts'",
")",
";",
"assert",
".",
"string",
"(",
"opts",
".",
"body",
",",
"'opts.body'",
")",
";",
"assert",
".",
"func",
"(",
"callback",
",",
"'callback'",
")",
";",
"const",
"sourceStream",
"=",
"intoStream",
"(",
"opts",
".",
"body",
")",
";",
"const",
"parseStream",
"=",
"createParseStream",
"(",
")",
";",
"const",
"cb",
"=",
"once",
"(",
"callback",
")",
";",
"parseStream",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"data",
")",
"{",
"return",
"cb",
"(",
"null",
",",
"data",
")",
";",
"}",
")",
";",
"parseStream",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"err",
")",
"{",
"return",
"cb",
"(",
"err",
")",
";",
"}",
")",
";",
"sourceStream",
".",
"pipe",
"(",
"parseStream",
")",
";",
"}"
] | stream based JSON.parse. async function signature to abstract over streams.
@public
@param {Object} opts options to pass to parse stream
@param {String} opts.body string to parse
@param {Function} callback a callback function
@return {Object} the parsed JSON object | [
"stream",
"based",
"JSON",
".",
"parse",
".",
"async",
"function",
"signature",
"to",
"abstract",
"over",
"streams",
"."
] | a26eacf659db71d8e5e0a619ef73bccce05354f0 | https://github.com/DonutEspresso/big-json/blob/a26eacf659db71d8e5e0a619ef73bccce05354f0/lib/index.js#L85-L103 |
22,911 | DonutEspresso/big-json | lib/index.js | stringify | function stringify(opts, callback) {
assert.object(opts, 'opts');
assert.func(callback, 'callback');
let stringified = '';
const stringifyStream = createStringifyStream(opts);
const passthroughStream = new stream.PassThrough();
const cb = once(callback);
// setup the passthrough stream as a sink
passthroughStream.on('data', function(chunk) {
stringified += chunk;
});
passthroughStream.on('end', function() {
return cb(null, stringified);
});
// don't know what errors stringify stream may emit, but pass them back
// up.
stringifyStream.on('error', function(err) {
return cb(err);
});
stringifyStream.pipe(passthroughStream);
} | javascript | function stringify(opts, callback) {
assert.object(opts, 'opts');
assert.func(callback, 'callback');
let stringified = '';
const stringifyStream = createStringifyStream(opts);
const passthroughStream = new stream.PassThrough();
const cb = once(callback);
// setup the passthrough stream as a sink
passthroughStream.on('data', function(chunk) {
stringified += chunk;
});
passthroughStream.on('end', function() {
return cb(null, stringified);
});
// don't know what errors stringify stream may emit, but pass them back
// up.
stringifyStream.on('error', function(err) {
return cb(err);
});
stringifyStream.pipe(passthroughStream);
} | [
"function",
"stringify",
"(",
"opts",
",",
"callback",
")",
"{",
"assert",
".",
"object",
"(",
"opts",
",",
"'opts'",
")",
";",
"assert",
".",
"func",
"(",
"callback",
",",
"'callback'",
")",
";",
"let",
"stringified",
"=",
"''",
";",
"const",
"stringifyStream",
"=",
"createStringifyStream",
"(",
"opts",
")",
";",
"const",
"passthroughStream",
"=",
"new",
"stream",
".",
"PassThrough",
"(",
")",
";",
"const",
"cb",
"=",
"once",
"(",
"callback",
")",
";",
"// setup the passthrough stream as a sink",
"passthroughStream",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"chunk",
")",
"{",
"stringified",
"+=",
"chunk",
";",
"}",
")",
";",
"passthroughStream",
".",
"on",
"(",
"'end'",
",",
"function",
"(",
")",
"{",
"return",
"cb",
"(",
"null",
",",
"stringified",
")",
";",
"}",
")",
";",
"// don't know what errors stringify stream may emit, but pass them back",
"// up.",
"stringifyStream",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"err",
")",
"{",
"return",
"cb",
"(",
"err",
")",
";",
"}",
")",
";",
"stringifyStream",
".",
"pipe",
"(",
"passthroughStream",
")",
";",
"}"
] | stream based JSON.stringify. async function signature to abstract over
streams.
@public
@param {Object} opts options to pass to stringify stream
@param {Function} callback a callback function
@function stringify
@return {Object} the parsed JSON object | [
"stream",
"based",
"JSON",
".",
"stringify",
".",
"async",
"function",
"signature",
"to",
"abstract",
"over",
"streams",
"."
] | a26eacf659db71d8e5e0a619ef73bccce05354f0 | https://github.com/DonutEspresso/big-json/blob/a26eacf659db71d8e5e0a619ef73bccce05354f0/lib/index.js#L115-L140 |
22,912 | cliffano/nestor | lib/cli/job.js | read | function read(cb) {
return function (name, args) {
function resultCb(result) {
var status = util.statusByColor(result.color);
var color = util.colorByStatus(status, result.color);
console.log('%s | %s', name, text.__(status)[color]);
result.healthReport.forEach(function (report) {
console.log(' - %s', report.description);
});
}
function jenkinsCb(jenkins) {
jenkins.readJob(name, cli.exitCb(null, resultCb));
}
cb(args, jenkinsCb);
};
} | javascript | function read(cb) {
return function (name, args) {
function resultCb(result) {
var status = util.statusByColor(result.color);
var color = util.colorByStatus(status, result.color);
console.log('%s | %s', name, text.__(status)[color]);
result.healthReport.forEach(function (report) {
console.log(' - %s', report.description);
});
}
function jenkinsCb(jenkins) {
jenkins.readJob(name, cli.exitCb(null, resultCb));
}
cb(args, jenkinsCb);
};
} | [
"function",
"read",
"(",
"cb",
")",
"{",
"return",
"function",
"(",
"name",
",",
"args",
")",
"{",
"function",
"resultCb",
"(",
"result",
")",
"{",
"var",
"status",
"=",
"util",
".",
"statusByColor",
"(",
"result",
".",
"color",
")",
";",
"var",
"color",
"=",
"util",
".",
"colorByStatus",
"(",
"status",
",",
"result",
".",
"color",
")",
";",
"console",
".",
"log",
"(",
"'%s | %s'",
",",
"name",
",",
"text",
".",
"__",
"(",
"status",
")",
"[",
"color",
"]",
")",
";",
"result",
".",
"healthReport",
".",
"forEach",
"(",
"function",
"(",
"report",
")",
"{",
"console",
".",
"log",
"(",
"' - %s'",
",",
"report",
".",
"description",
")",
";",
"}",
")",
";",
"}",
"function",
"jenkinsCb",
"(",
"jenkins",
")",
"{",
"jenkins",
".",
"readJob",
"(",
"name",
",",
"cli",
".",
"exitCb",
"(",
"null",
",",
"resultCb",
")",
")",
";",
"}",
"cb",
"(",
"args",
",",
"jenkinsCb",
")",
";",
"}",
";",
"}"
] | Get a handler that calls Jenkins API to retrieve information about a job.
Job status and health reports will be logged when there's no error.
@param {Function} cb: callback for argument handling
@return Jenkins API handler function | [
"Get",
"a",
"handler",
"that",
"calls",
"Jenkins",
"API",
"to",
"retrieve",
"information",
"about",
"a",
"job",
".",
"Job",
"status",
"and",
"health",
"reports",
"will",
"be",
"logged",
"when",
"there",
"s",
"no",
"error",
"."
] | aa7e964e372bef376bab59b3f3cb5d847f76290d | https://github.com/cliffano/nestor/blob/aa7e964e372bef376bab59b3f3cb5d847f76290d/lib/cli/job.js#L35-L50 |
22,913 | cliffano/nestor | lib/cli/job.js | update | function update(cb) {
return function (name, configFile, args) {
function resultCb(result) {
console.log(text.__('Job %s was updated successfully'), name);
}
function jenkinsCb(jenkins) {
var config = fs.readFileSync(configFile).toString();
jenkins.updateJob(name, config, cli.exitCb(null, resultCb));
}
cb(args, jenkinsCb);
};
} | javascript | function update(cb) {
return function (name, configFile, args) {
function resultCb(result) {
console.log(text.__('Job %s was updated successfully'), name);
}
function jenkinsCb(jenkins) {
var config = fs.readFileSync(configFile).toString();
jenkins.updateJob(name, config, cli.exitCb(null, resultCb));
}
cb(args, jenkinsCb);
};
} | [
"function",
"update",
"(",
"cb",
")",
"{",
"return",
"function",
"(",
"name",
",",
"configFile",
",",
"args",
")",
"{",
"function",
"resultCb",
"(",
"result",
")",
"{",
"console",
".",
"log",
"(",
"text",
".",
"__",
"(",
"'Job %s was updated successfully'",
")",
",",
"name",
")",
";",
"}",
"function",
"jenkinsCb",
"(",
"jenkins",
")",
"{",
"var",
"config",
"=",
"fs",
".",
"readFileSync",
"(",
"configFile",
")",
".",
"toString",
"(",
")",
";",
"jenkins",
".",
"updateJob",
"(",
"name",
",",
"config",
",",
"cli",
".",
"exitCb",
"(",
"null",
",",
"resultCb",
")",
")",
";",
"}",
"cb",
"(",
"args",
",",
"jenkinsCb",
")",
";",
"}",
";",
"}"
] | Get a handler that calls Jenkins API to update a job with specific configuration.
Success job update message will be logged when there's no error.
@param {Function} cb: callback for argument handling
@return Jenkins API handler function | [
"Get",
"a",
"handler",
"that",
"calls",
"Jenkins",
"API",
"to",
"update",
"a",
"job",
"with",
"specific",
"configuration",
".",
"Success",
"job",
"update",
"message",
"will",
"be",
"logged",
"when",
"there",
"s",
"no",
"error",
"."
] | aa7e964e372bef376bab59b3f3cb5d847f76290d | https://github.com/cliffano/nestor/blob/aa7e964e372bef376bab59b3f3cb5d847f76290d/lib/cli/job.js#L95-L106 |
22,914 | cliffano/nestor | lib/cli/job.js | _console | function _console(cb) {
return function (name, buildNumber, args) {
if (!args) {
args = buildNumber;
buildNumber = null;
}
function jenkinsCb(jenkins) {
// console does not trigger any build, interval is set to 0 (no-pending delay time)
var interval = 0;
var stream = jenkins.streamJobConsole(name, buildNumber, interval, cli.exit);
stream.pipe(process.stdout, { end: false });
}
cb(args, jenkinsCb);
};
} | javascript | function _console(cb) {
return function (name, buildNumber, args) {
if (!args) {
args = buildNumber;
buildNumber = null;
}
function jenkinsCb(jenkins) {
// console does not trigger any build, interval is set to 0 (no-pending delay time)
var interval = 0;
var stream = jenkins.streamJobConsole(name, buildNumber, interval, cli.exit);
stream.pipe(process.stdout, { end: false });
}
cb(args, jenkinsCb);
};
} | [
"function",
"_console",
"(",
"cb",
")",
"{",
"return",
"function",
"(",
"name",
",",
"buildNumber",
",",
"args",
")",
"{",
"if",
"(",
"!",
"args",
")",
"{",
"args",
"=",
"buildNumber",
";",
"buildNumber",
"=",
"null",
";",
"}",
"function",
"jenkinsCb",
"(",
"jenkins",
")",
"{",
"// console does not trigger any build, interval is set to 0 (no-pending delay time)",
"var",
"interval",
"=",
"0",
";",
"var",
"stream",
"=",
"jenkins",
".",
"streamJobConsole",
"(",
"name",
",",
"buildNumber",
",",
"interval",
",",
"cli",
".",
"exit",
")",
";",
"stream",
".",
"pipe",
"(",
"process",
".",
"stdout",
",",
"{",
"end",
":",
"false",
"}",
")",
";",
"}",
"cb",
"(",
"args",
",",
"jenkinsCb",
")",
";",
"}",
";",
"}"
] | Get a handler that calls Jenkins API to stream console output.
@param {Function} cb: callback for argument handling
@return Jenkins API handler function | [
"Get",
"a",
"handler",
"that",
"calls",
"Jenkins",
"API",
"to",
"stream",
"console",
"output",
"."
] | aa7e964e372bef376bab59b3f3cb5d847f76290d | https://github.com/cliffano/nestor/blob/aa7e964e372bef376bab59b3f3cb5d847f76290d/lib/cli/job.js#L235-L252 |
22,915 | cliffano/nestor | lib/cli/job.js | enable | function enable(cb) {
return function (name, args) {
function resultCb(result) {
console.log(text.__('Job %s was enabled successfully'), name);
}
function jenkinsCb(jenkins) {
jenkins.enableJob(name, cli.exitCb(null, resultCb));
}
cb(args, jenkinsCb);
};
} | javascript | function enable(cb) {
return function (name, args) {
function resultCb(result) {
console.log(text.__('Job %s was enabled successfully'), name);
}
function jenkinsCb(jenkins) {
jenkins.enableJob(name, cli.exitCb(null, resultCb));
}
cb(args, jenkinsCb);
};
} | [
"function",
"enable",
"(",
"cb",
")",
"{",
"return",
"function",
"(",
"name",
",",
"args",
")",
"{",
"function",
"resultCb",
"(",
"result",
")",
"{",
"console",
".",
"log",
"(",
"text",
".",
"__",
"(",
"'Job %s was enabled successfully'",
")",
",",
"name",
")",
";",
"}",
"function",
"jenkinsCb",
"(",
"jenkins",
")",
"{",
"jenkins",
".",
"enableJob",
"(",
"name",
",",
"cli",
".",
"exitCb",
"(",
"null",
",",
"resultCb",
")",
")",
";",
"}",
"cb",
"(",
"args",
",",
"jenkinsCb",
")",
";",
"}",
";",
"}"
] | Get a handler that calls Jenkins API to enable a job.
Success job enabled message will be logged when there's no error.
@param {Function} cb: callback for argument handling
@return Jenkins API handler function | [
"Get",
"a",
"handler",
"that",
"calls",
"Jenkins",
"API",
"to",
"enable",
"a",
"job",
".",
"Success",
"job",
"enabled",
"message",
"will",
"be",
"logged",
"when",
"there",
"s",
"no",
"error",
"."
] | aa7e964e372bef376bab59b3f3cb5d847f76290d | https://github.com/cliffano/nestor/blob/aa7e964e372bef376bab59b3f3cb5d847f76290d/lib/cli/job.js#L261-L271 |
22,916 | cliffano/nestor | lib/cli/job.js | copy | function copy(cb) {
return function (existingName, newName, args) {
function resultCb(result) {
console.log(text.__('Job %s was copied to job %s'), existingName, newName);
}
function jenkinsCb(jenkins) {
jenkins.copyJob(existingName, newName, cli.exitCb(null, resultCb));
}
cb(args, jenkinsCb);
};
} | javascript | function copy(cb) {
return function (existingName, newName, args) {
function resultCb(result) {
console.log(text.__('Job %s was copied to job %s'), existingName, newName);
}
function jenkinsCb(jenkins) {
jenkins.copyJob(existingName, newName, cli.exitCb(null, resultCb));
}
cb(args, jenkinsCb);
};
} | [
"function",
"copy",
"(",
"cb",
")",
"{",
"return",
"function",
"(",
"existingName",
",",
"newName",
",",
"args",
")",
"{",
"function",
"resultCb",
"(",
"result",
")",
"{",
"console",
".",
"log",
"(",
"text",
".",
"__",
"(",
"'Job %s was copied to job %s'",
")",
",",
"existingName",
",",
"newName",
")",
";",
"}",
"function",
"jenkinsCb",
"(",
"jenkins",
")",
"{",
"jenkins",
".",
"copyJob",
"(",
"existingName",
",",
"newName",
",",
"cli",
".",
"exitCb",
"(",
"null",
",",
"resultCb",
")",
")",
";",
"}",
"cb",
"(",
"args",
",",
"jenkinsCb",
")",
";",
"}",
";",
"}"
] | Get a handler that calls Jenkins API to copy a job into a new job.
Success job copy message will be logged when there's no error.
@param {Function} cb: callback for argument handling
@return Jenkins API handler function | [
"Get",
"a",
"handler",
"that",
"calls",
"Jenkins",
"API",
"to",
"copy",
"a",
"job",
"into",
"a",
"new",
"job",
".",
"Success",
"job",
"copy",
"message",
"will",
"be",
"logged",
"when",
"there",
"s",
"no",
"error",
"."
] | aa7e964e372bef376bab59b3f3cb5d847f76290d | https://github.com/cliffano/nestor/blob/aa7e964e372bef376bab59b3f3cb5d847f76290d/lib/cli/job.js#L299-L309 |
22,917 | cliffano/nestor | lib/cli/view.js | fetchConfig | function fetchConfig(cb) {
return function (name, args) {
function resultCb(result) {
console.log(result);
}
function jenkinsCb(jenkins) {
jenkins.fetchViewConfig(name, cli.exitCb(null, resultCb));
}
cb(args, jenkinsCb);
};
} | javascript | function fetchConfig(cb) {
return function (name, args) {
function resultCb(result) {
console.log(result);
}
function jenkinsCb(jenkins) {
jenkins.fetchViewConfig(name, cli.exitCb(null, resultCb));
}
cb(args, jenkinsCb);
};
} | [
"function",
"fetchConfig",
"(",
"cb",
")",
"{",
"return",
"function",
"(",
"name",
",",
"args",
")",
"{",
"function",
"resultCb",
"(",
"result",
")",
"{",
"console",
".",
"log",
"(",
"result",
")",
";",
"}",
"function",
"jenkinsCb",
"(",
"jenkins",
")",
"{",
"jenkins",
".",
"fetchViewConfig",
"(",
"name",
",",
"cli",
".",
"exitCb",
"(",
"null",
",",
"resultCb",
")",
")",
";",
"}",
"cb",
"(",
"args",
",",
"jenkinsCb",
")",
";",
"}",
";",
"}"
] | Get a handler that calls Jenkins API to fetch a view configuration.
Jenkins view config.xml will be logged when there's no error.
@param {Function} cb: callback for argument handling
@return Jenkins API handler function | [
"Get",
"a",
"handler",
"that",
"calls",
"Jenkins",
"API",
"to",
"fetch",
"a",
"view",
"configuration",
".",
"Jenkins",
"view",
"config",
".",
"xml",
"will",
"be",
"logged",
"when",
"there",
"s",
"no",
"error",
"."
] | aa7e964e372bef376bab59b3f3cb5d847f76290d | https://github.com/cliffano/nestor/blob/aa7e964e372bef376bab59b3f3cb5d847f76290d/lib/cli/view.js#L52-L62 |
22,918 | cliffano/nestor | lib/api/view.js | update | function update(name, config, cb) {
this.remoteAccessApi.postViewConfig(name, config, this.opts.headers, cb);
} | javascript | function update(name, config, cb) {
this.remoteAccessApi.postViewConfig(name, config, this.opts.headers, cb);
} | [
"function",
"update",
"(",
"name",
",",
"config",
",",
"cb",
")",
"{",
"this",
".",
"remoteAccessApi",
".",
"postViewConfig",
"(",
"name",
",",
"config",
",",
"this",
".",
"opts",
".",
"headers",
",",
"cb",
")",
";",
"}"
] | Update a view with specified configuration
@param {String} name: Jenkins view name
@param {String} config: Jenkins view config.xml
@param {Function} cb: standard cb(err, result) callback | [
"Update",
"a",
"view",
"with",
"specified",
"configuration"
] | aa7e964e372bef376bab59b3f3cb5d847f76290d | https://github.com/cliffano/nestor/blob/aa7e964e372bef376bab59b3f3cb5d847f76290d/lib/api/view.js#L36-L38 |
22,919 | cliffano/nestor | lib/api/jenkins.js | discover | function discover(host, cb) {
const TIMEOUT = 5000;
var socket = dgram.createSocket('udp4');
var buffer = new Buffer(text.__('Long live Jenkins!'));
var parser = new xml2js.Parser();
socket.on('error', function (err) {
socket.close();
cb(err);
});
socket.on('message', function (result) {
socket.close();
parser.addListener('end', function (result) {
cb(null, result);
});
parser.parseString(result);
});
socket.send(buffer, 0, buffer.length, 33848, host, function (err, result) {
if (err) {
socket.close();
cb(err);
}
});
setTimeout(function () {
cb(new Error(text.__('Unable to find any Jenkins instance on %s', host)));
}, TIMEOUT);
} | javascript | function discover(host, cb) {
const TIMEOUT = 5000;
var socket = dgram.createSocket('udp4');
var buffer = new Buffer(text.__('Long live Jenkins!'));
var parser = new xml2js.Parser();
socket.on('error', function (err) {
socket.close();
cb(err);
});
socket.on('message', function (result) {
socket.close();
parser.addListener('end', function (result) {
cb(null, result);
});
parser.parseString(result);
});
socket.send(buffer, 0, buffer.length, 33848, host, function (err, result) {
if (err) {
socket.close();
cb(err);
}
});
setTimeout(function () {
cb(new Error(text.__('Unable to find any Jenkins instance on %s', host)));
}, TIMEOUT);
} | [
"function",
"discover",
"(",
"host",
",",
"cb",
")",
"{",
"const",
"TIMEOUT",
"=",
"5000",
";",
"var",
"socket",
"=",
"dgram",
".",
"createSocket",
"(",
"'udp4'",
")",
";",
"var",
"buffer",
"=",
"new",
"Buffer",
"(",
"text",
".",
"__",
"(",
"'Long live Jenkins!'",
")",
")",
";",
"var",
"parser",
"=",
"new",
"xml2js",
".",
"Parser",
"(",
")",
";",
"socket",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"err",
")",
"{",
"socket",
".",
"close",
"(",
")",
";",
"cb",
"(",
"err",
")",
";",
"}",
")",
";",
"socket",
".",
"on",
"(",
"'message'",
",",
"function",
"(",
"result",
")",
"{",
"socket",
".",
"close",
"(",
")",
";",
"parser",
".",
"addListener",
"(",
"'end'",
",",
"function",
"(",
"result",
")",
"{",
"cb",
"(",
"null",
",",
"result",
")",
";",
"}",
")",
";",
"parser",
".",
"parseString",
"(",
"result",
")",
";",
"}",
")",
";",
"socket",
".",
"send",
"(",
"buffer",
",",
"0",
",",
"buffer",
".",
"length",
",",
"33848",
",",
"host",
",",
"function",
"(",
"err",
",",
"result",
")",
"{",
"if",
"(",
"err",
")",
"{",
"socket",
".",
"close",
"(",
")",
";",
"cb",
"(",
"err",
")",
";",
"}",
"}",
")",
";",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"cb",
"(",
"new",
"Error",
"(",
"text",
".",
"__",
"(",
"'Unable to find any Jenkins instance on %s'",
",",
"host",
")",
")",
")",
";",
"}",
",",
"TIMEOUT",
")",
";",
"}"
] | Discover whether there's a Jenkins instance running on the specified host.
@param {String} host: hostname
@param {Function} cb: standard cb(err, result) callback | [
"Discover",
"whether",
"there",
"s",
"a",
"Jenkins",
"instance",
"running",
"on",
"the",
"specified",
"host",
"."
] | aa7e964e372bef376bab59b3f3cb5d847f76290d | https://github.com/cliffano/nestor/blob/aa7e964e372bef376bab59b3f3cb5d847f76290d/lib/api/jenkins.js#L33-L64 |
22,920 | cliffano/nestor | lib/api/jenkins.js | version | function version(cb) {
function _cb(err, result, response) {
if (err) {
cb(err);
} else if (response.headers['x-jenkins']) {
cb(null, response.headers['x-jenkins']);
} else {
cb(new Error(text.__('Not a Jenkins server')));
}
}
this.remoteAccessApi.headJenkins(_cb);
} | javascript | function version(cb) {
function _cb(err, result, response) {
if (err) {
cb(err);
} else if (response.headers['x-jenkins']) {
cb(null, response.headers['x-jenkins']);
} else {
cb(new Error(text.__('Not a Jenkins server')));
}
}
this.remoteAccessApi.headJenkins(_cb);
} | [
"function",
"version",
"(",
"cb",
")",
"{",
"function",
"_cb",
"(",
"err",
",",
"result",
",",
"response",
")",
"{",
"if",
"(",
"err",
")",
"{",
"cb",
"(",
"err",
")",
";",
"}",
"else",
"if",
"(",
"response",
".",
"headers",
"[",
"'x-jenkins'",
"]",
")",
"{",
"cb",
"(",
"null",
",",
"response",
".",
"headers",
"[",
"'x-jenkins'",
"]",
")",
";",
"}",
"else",
"{",
"cb",
"(",
"new",
"Error",
"(",
"text",
".",
"__",
"(",
"'Not a Jenkins server'",
")",
")",
")",
";",
"}",
"}",
"this",
".",
"remoteAccessApi",
".",
"headJenkins",
"(",
"_cb",
")",
";",
"}"
] | Retrieve Jenkins version number from x-jenkins header.
If x-jenkins header does not exist, then it's assumed that the server is not a Jenkins instance.
@param {Function} cb: standard cb(err, result) callback | [
"Retrieve",
"Jenkins",
"version",
"number",
"from",
"x",
"-",
"jenkins",
"header",
".",
"If",
"x",
"-",
"jenkins",
"header",
"does",
"not",
"exist",
"then",
"it",
"s",
"assumed",
"that",
"the",
"server",
"is",
"not",
"a",
"Jenkins",
"instance",
"."
] | aa7e964e372bef376bab59b3f3cb5d847f76290d | https://github.com/cliffano/nestor/blob/aa7e964e372bef376bab59b3f3cb5d847f76290d/lib/api/jenkins.js#L103-L115 |
22,921 | cliffano/nestor | lib/jenkins.js | executorSummary | function executorSummary(computers) {
var data = {};
computers.forEach(function (computer) {
var idleCount = 0;
var activeCount = 0;
data[computer.displayName] = { executors: [] };
computer.executors.forEach(function (executor) {
data[computer.displayName].executors.push({
idle: executor.idle,
stuck: executor.likelyStuck,
progress: executor.progress,
name: (!executor.idle && executor.currentExecutable.url) ?
executor.currentExecutable.url.replace(/.*\/job\//, '').replace(/\/.*/, '') :
undefined
});
if (executor.idle) {
idleCount += 1;
} else {
activeCount += 1;
}
});
var summary = [];
if (activeCount > 0) {
summary.push(text.__('%d active', activeCount));
}
if (idleCount > 0) {
summary.push(text.__('%d idle', idleCount));
}
data[computer.displayName].summary = summary.join(', ');
});
return data;
} | javascript | function executorSummary(computers) {
var data = {};
computers.forEach(function (computer) {
var idleCount = 0;
var activeCount = 0;
data[computer.displayName] = { executors: [] };
computer.executors.forEach(function (executor) {
data[computer.displayName].executors.push({
idle: executor.idle,
stuck: executor.likelyStuck,
progress: executor.progress,
name: (!executor.idle && executor.currentExecutable.url) ?
executor.currentExecutable.url.replace(/.*\/job\//, '').replace(/\/.*/, '') :
undefined
});
if (executor.idle) {
idleCount += 1;
} else {
activeCount += 1;
}
});
var summary = [];
if (activeCount > 0) {
summary.push(text.__('%d active', activeCount));
}
if (idleCount > 0) {
summary.push(text.__('%d idle', idleCount));
}
data[computer.displayName].summary = summary.join(', ');
});
return data;
} | [
"function",
"executorSummary",
"(",
"computers",
")",
"{",
"var",
"data",
"=",
"{",
"}",
";",
"computers",
".",
"forEach",
"(",
"function",
"(",
"computer",
")",
"{",
"var",
"idleCount",
"=",
"0",
";",
"var",
"activeCount",
"=",
"0",
";",
"data",
"[",
"computer",
".",
"displayName",
"]",
"=",
"{",
"executors",
":",
"[",
"]",
"}",
";",
"computer",
".",
"executors",
".",
"forEach",
"(",
"function",
"(",
"executor",
")",
"{",
"data",
"[",
"computer",
".",
"displayName",
"]",
".",
"executors",
".",
"push",
"(",
"{",
"idle",
":",
"executor",
".",
"idle",
",",
"stuck",
":",
"executor",
".",
"likelyStuck",
",",
"progress",
":",
"executor",
".",
"progress",
",",
"name",
":",
"(",
"!",
"executor",
".",
"idle",
"&&",
"executor",
".",
"currentExecutable",
".",
"url",
")",
"?",
"executor",
".",
"currentExecutable",
".",
"url",
".",
"replace",
"(",
"/",
".*\\/job\\/",
"/",
",",
"''",
")",
".",
"replace",
"(",
"/",
"\\/.*",
"/",
",",
"''",
")",
":",
"undefined",
"}",
")",
";",
"if",
"(",
"executor",
".",
"idle",
")",
"{",
"idleCount",
"+=",
"1",
";",
"}",
"else",
"{",
"activeCount",
"+=",
"1",
";",
"}",
"}",
")",
";",
"var",
"summary",
"=",
"[",
"]",
";",
"if",
"(",
"activeCount",
">",
"0",
")",
"{",
"summary",
".",
"push",
"(",
"text",
".",
"__",
"(",
"'%d active'",
",",
"activeCount",
")",
")",
";",
"}",
"if",
"(",
"idleCount",
">",
"0",
")",
"{",
"summary",
".",
"push",
"(",
"text",
".",
"__",
"(",
"'%d idle'",
",",
"idleCount",
")",
")",
";",
"}",
"data",
"[",
"computer",
".",
"displayName",
"]",
".",
"summary",
"=",
"summary",
".",
"join",
"(",
"', '",
")",
";",
"}",
")",
";",
"return",
"data",
";",
"}"
] | Summarise executor information from computers array.
@param {Array} computers: computers array, part of Jenkins#computer result
@return executor summary object | [
"Summarise",
"executor",
"information",
"from",
"computers",
"array",
"."
] | aa7e964e372bef376bab59b3f3cb5d847f76290d | https://github.com/cliffano/nestor/blob/aa7e964e372bef376bab59b3f3cb5d847f76290d/lib/jenkins.js#L107-L147 |
22,922 | cliffano/nestor | lib/jenkins.js | monitor | function monitor(opts, cb) {
var self = this;
function singleJobResultCb(err, result) {
if (!err) {
result = util.statusByColor(result.color);
}
cb(err, result);
}
// when there are multiple jobs, status is derived following these rules:
// - fail if any job has Jenkins color red
// - warn if any job has Jenkins color yellow but no red
// - non-success (e.g. notbuilt) if any job has Jenkins color status but no red and yellow
// - success only if all jobs are either blue or green
function multiJobsResultCb(err, result) {
if (!err) {
var hasRed = false;
var hasYellow = false;
var hasNonSuccess = false;
var hasSuccess = false;
var successColor;
var nonSuccessColor;
result.jobs.forEach(function (job) {
if (job.color === 'red') {
hasRed = true;
}
if (job.color === 'yellow') {
hasYellow = true;
}
if (['red', 'yellow', 'blue', 'green'].indexOf(job.color) === -1) {
hasNonSuccess = true;
nonSuccessColor = job.color;
}
if (job.color === 'blue' || job.color === 'green') {
hasSuccess = true;
successColor = job.color;
}
});
var resultColor;
if (hasRed) {
resultColor = 'red';
} else if (hasYellow) {
resultColor = 'yellow';
} else if (hasNonSuccess) {
resultColor = nonSuccessColor;
} else {
resultColor = successColor;
}
result = util.statusByColor(resultColor);
}
cb(err, result);
}
function _notify() {
if (opts.job) {
self.readJob(opts.job, singleJobResultCb);
} else if (opts.view) {
self.readView(opts.view, multiJobsResultCb);
} else {
self.info(multiJobsResultCb);
}
}
_notify();
new cron.CronJob(opts.schedule || '0 * * * * *', _notify).start();
} | javascript | function monitor(opts, cb) {
var self = this;
function singleJobResultCb(err, result) {
if (!err) {
result = util.statusByColor(result.color);
}
cb(err, result);
}
// when there are multiple jobs, status is derived following these rules:
// - fail if any job has Jenkins color red
// - warn if any job has Jenkins color yellow but no red
// - non-success (e.g. notbuilt) if any job has Jenkins color status but no red and yellow
// - success only if all jobs are either blue or green
function multiJobsResultCb(err, result) {
if (!err) {
var hasRed = false;
var hasYellow = false;
var hasNonSuccess = false;
var hasSuccess = false;
var successColor;
var nonSuccessColor;
result.jobs.forEach(function (job) {
if (job.color === 'red') {
hasRed = true;
}
if (job.color === 'yellow') {
hasYellow = true;
}
if (['red', 'yellow', 'blue', 'green'].indexOf(job.color) === -1) {
hasNonSuccess = true;
nonSuccessColor = job.color;
}
if (job.color === 'blue' || job.color === 'green') {
hasSuccess = true;
successColor = job.color;
}
});
var resultColor;
if (hasRed) {
resultColor = 'red';
} else if (hasYellow) {
resultColor = 'yellow';
} else if (hasNonSuccess) {
resultColor = nonSuccessColor;
} else {
resultColor = successColor;
}
result = util.statusByColor(resultColor);
}
cb(err, result);
}
function _notify() {
if (opts.job) {
self.readJob(opts.job, singleJobResultCb);
} else if (opts.view) {
self.readView(opts.view, multiJobsResultCb);
} else {
self.info(multiJobsResultCb);
}
}
_notify();
new cron.CronJob(opts.schedule || '0 * * * * *', _notify).start();
} | [
"function",
"monitor",
"(",
"opts",
",",
"cb",
")",
"{",
"var",
"self",
"=",
"this",
";",
"function",
"singleJobResultCb",
"(",
"err",
",",
"result",
")",
"{",
"if",
"(",
"!",
"err",
")",
"{",
"result",
"=",
"util",
".",
"statusByColor",
"(",
"result",
".",
"color",
")",
";",
"}",
"cb",
"(",
"err",
",",
"result",
")",
";",
"}",
"// when there are multiple jobs, status is derived following these rules:",
"// - fail if any job has Jenkins color red",
"// - warn if any job has Jenkins color yellow but no red",
"// - non-success (e.g. notbuilt) if any job has Jenkins color status but no red and yellow",
"// - success only if all jobs are either blue or green",
"function",
"multiJobsResultCb",
"(",
"err",
",",
"result",
")",
"{",
"if",
"(",
"!",
"err",
")",
"{",
"var",
"hasRed",
"=",
"false",
";",
"var",
"hasYellow",
"=",
"false",
";",
"var",
"hasNonSuccess",
"=",
"false",
";",
"var",
"hasSuccess",
"=",
"false",
";",
"var",
"successColor",
";",
"var",
"nonSuccessColor",
";",
"result",
".",
"jobs",
".",
"forEach",
"(",
"function",
"(",
"job",
")",
"{",
"if",
"(",
"job",
".",
"color",
"===",
"'red'",
")",
"{",
"hasRed",
"=",
"true",
";",
"}",
"if",
"(",
"job",
".",
"color",
"===",
"'yellow'",
")",
"{",
"hasYellow",
"=",
"true",
";",
"}",
"if",
"(",
"[",
"'red'",
",",
"'yellow'",
",",
"'blue'",
",",
"'green'",
"]",
".",
"indexOf",
"(",
"job",
".",
"color",
")",
"===",
"-",
"1",
")",
"{",
"hasNonSuccess",
"=",
"true",
";",
"nonSuccessColor",
"=",
"job",
".",
"color",
";",
"}",
"if",
"(",
"job",
".",
"color",
"===",
"'blue'",
"||",
"job",
".",
"color",
"===",
"'green'",
")",
"{",
"hasSuccess",
"=",
"true",
";",
"successColor",
"=",
"job",
".",
"color",
";",
"}",
"}",
")",
";",
"var",
"resultColor",
";",
"if",
"(",
"hasRed",
")",
"{",
"resultColor",
"=",
"'red'",
";",
"}",
"else",
"if",
"(",
"hasYellow",
")",
"{",
"resultColor",
"=",
"'yellow'",
";",
"}",
"else",
"if",
"(",
"hasNonSuccess",
")",
"{",
"resultColor",
"=",
"nonSuccessColor",
";",
"}",
"else",
"{",
"resultColor",
"=",
"successColor",
";",
"}",
"result",
"=",
"util",
".",
"statusByColor",
"(",
"resultColor",
")",
";",
"}",
"cb",
"(",
"err",
",",
"result",
")",
";",
"}",
"function",
"_notify",
"(",
")",
"{",
"if",
"(",
"opts",
".",
"job",
")",
"{",
"self",
".",
"readJob",
"(",
"opts",
".",
"job",
",",
"singleJobResultCb",
")",
";",
"}",
"else",
"if",
"(",
"opts",
".",
"view",
")",
"{",
"self",
".",
"readView",
"(",
"opts",
".",
"view",
",",
"multiJobsResultCb",
")",
";",
"}",
"else",
"{",
"self",
".",
"info",
"(",
"multiJobsResultCb",
")",
";",
"}",
"}",
"_notify",
"(",
")",
";",
"new",
"cron",
".",
"CronJob",
"(",
"opts",
".",
"schedule",
"||",
"'0 * * * * *'",
",",
"_notify",
")",
".",
"start",
"(",
")",
";",
"}"
] | Monitor Jenkins latest build status on a set interval.
@param {Object} opts: optional
- job: Jenkins job name
- view: Jenkins view name
- schedule: cron scheduling definition in standard * * * * * * format, default: 0 * * * * * (every minute)
@param {Function} cb: standard cb(err, result) callback | [
"Monitor",
"Jenkins",
"latest",
"build",
"status",
"on",
"a",
"set",
"interval",
"."
] | aa7e964e372bef376bab59b3f3cb5d847f76290d | https://github.com/cliffano/nestor/blob/aa7e964e372bef376bab59b3f3cb5d847f76290d/lib/jenkins.js#L158-L229 |
22,923 | cliffano/nestor | lib/api/util.js | htmlError | function htmlError(result, cb) {
var message = result.body
.match(/<h1>Error<\/h1>.+<\/p>/).toString()
.replace(/<h1>Error<\/h1>/, '')
.replace(/<\/?p>/g, '');
cb(new Error(message));
} | javascript | function htmlError(result, cb) {
var message = result.body
.match(/<h1>Error<\/h1>.+<\/p>/).toString()
.replace(/<h1>Error<\/h1>/, '')
.replace(/<\/?p>/g, '');
cb(new Error(message));
} | [
"function",
"htmlError",
"(",
"result",
",",
"cb",
")",
"{",
"var",
"message",
"=",
"result",
".",
"body",
".",
"match",
"(",
"/",
"<h1>Error<\\/h1>.+<\\/p>",
"/",
")",
".",
"toString",
"(",
")",
".",
"replace",
"(",
"/",
"<h1>Error<\\/h1>",
"/",
",",
"''",
")",
".",
"replace",
"(",
"/",
"<\\/?p>",
"/",
"g",
",",
"''",
")",
";",
"cb",
"(",
"new",
"Error",
"(",
"message",
")",
")",
";",
"}"
] | Parse HTML error page from Jenkins, pass the error message to the callback.
This error is usually the response body of error 400.
@param {Object} result: result of the sent request
@param {Function} cb: standard cb(err, result) callback | [
"Parse",
"HTML",
"error",
"page",
"from",
"Jenkins",
"pass",
"the",
"error",
"message",
"to",
"the",
"callback",
".",
"This",
"error",
"is",
"usually",
"the",
"response",
"body",
"of",
"error",
"400",
"."
] | aa7e964e372bef376bab59b3f3cb5d847f76290d | https://github.com/cliffano/nestor/blob/aa7e964e372bef376bab59b3f3cb5d847f76290d/lib/api/util.js#L40-L46 |
22,924 | cliffano/nestor | lib/api/util.js | jobBuildNotFoundError | function jobBuildNotFoundError(name, buildNumber) {
return function (result, cb) {
cb(new Error(text.__('Job %s build %d does not exist', name, buildNumber)));
};
} | javascript | function jobBuildNotFoundError(name, buildNumber) {
return function (result, cb) {
cb(new Error(text.__('Job %s build %d does not exist', name, buildNumber)));
};
} | [
"function",
"jobBuildNotFoundError",
"(",
"name",
",",
"buildNumber",
")",
"{",
"return",
"function",
"(",
"result",
",",
"cb",
")",
"{",
"cb",
"(",
"new",
"Error",
"(",
"text",
".",
"__",
"(",
"'Job %s build %d does not exist'",
",",
"name",
",",
"buildNumber",
")",
")",
")",
";",
"}",
";",
"}"
] | Create a 'job or build not found' error handler function.
@param {String} name: the job name
@param {Number} buildNumber: the job's build number
@return a handler function | [
"Create",
"a",
"job",
"or",
"build",
"not",
"found",
"error",
"handler",
"function",
"."
] | aa7e964e372bef376bab59b3f3cb5d847f76290d | https://github.com/cliffano/nestor/blob/aa7e964e372bef376bab59b3f3cb5d847f76290d/lib/api/util.js#L67-L71 |
22,925 | cliffano/nestor | lib/api/job.js | create | function create(name, config, cb) {
var opts = {
body: config,
contentType: 'application/xml',
};
this.remoteAccessApi.postCreateItem(name, _.merge(opts, this.opts.headers), cb);
} | javascript | function create(name, config, cb) {
var opts = {
body: config,
contentType: 'application/xml',
};
this.remoteAccessApi.postCreateItem(name, _.merge(opts, this.opts.headers), cb);
} | [
"function",
"create",
"(",
"name",
",",
"config",
",",
"cb",
")",
"{",
"var",
"opts",
"=",
"{",
"body",
":",
"config",
",",
"contentType",
":",
"'application/xml'",
",",
"}",
";",
"this",
".",
"remoteAccessApi",
".",
"postCreateItem",
"(",
"name",
",",
"_",
".",
"merge",
"(",
"opts",
",",
"this",
".",
"opts",
".",
"headers",
")",
",",
"cb",
")",
";",
"}"
] | Create a job with specified configuration.
@param {String} name: Jenkins job name
@param {String} config: Jenkins job config.xml
@param {Function} cb: standard cb(err, result) callback | [
"Create",
"a",
"job",
"with",
"specified",
"configuration",
"."
] | aa7e964e372bef376bab59b3f3cb5d847f76290d | https://github.com/cliffano/nestor/blob/aa7e964e372bef376bab59b3f3cb5d847f76290d/lib/api/job.js#L14-L20 |
22,926 | cliffano/nestor | lib/api/job.js | update | function update(name, config, cb) {
this.remoteAccessApi.postJobConfig(name, config, this.opts.headers, cb);
} | javascript | function update(name, config, cb) {
this.remoteAccessApi.postJobConfig(name, config, this.opts.headers, cb);
} | [
"function",
"update",
"(",
"name",
",",
"config",
",",
"cb",
")",
"{",
"this",
".",
"remoteAccessApi",
".",
"postJobConfig",
"(",
"name",
",",
"config",
",",
"this",
".",
"opts",
".",
"headers",
",",
"cb",
")",
";",
"}"
] | Update a job with specified configuration
@param {String} name: Jenkins job name
@param {String} config: Jenkins job config.xml
@param {Function} cb: standard cb(err, result) callback | [
"Update",
"a",
"job",
"with",
"specified",
"configuration"
] | aa7e964e372bef376bab59b3f3cb5d847f76290d | https://github.com/cliffano/nestor/blob/aa7e964e372bef376bab59b3f3cb5d847f76290d/lib/api/job.js#L50-L52 |
22,927 | cliffano/nestor | lib/api/job.js | build | function build(name, params, cb) {
var body = { parameter: [] } ;
_.keys(params).forEach(function (key) {
body.parameter.push({ name: key, value: params[key] });
});
var opts = {
token: 'nestor'
};
this.remoteAccessApi.postJobBuild(name, JSON.stringify(body), _.merge(opts, this.opts.headers), cb);
} | javascript | function build(name, params, cb) {
var body = { parameter: [] } ;
_.keys(params).forEach(function (key) {
body.parameter.push({ name: key, value: params[key] });
});
var opts = {
token: 'nestor'
};
this.remoteAccessApi.postJobBuild(name, JSON.stringify(body), _.merge(opts, this.opts.headers), cb);
} | [
"function",
"build",
"(",
"name",
",",
"params",
",",
"cb",
")",
"{",
"var",
"body",
"=",
"{",
"parameter",
":",
"[",
"]",
"}",
";",
"_",
".",
"keys",
"(",
"params",
")",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"body",
".",
"parameter",
".",
"push",
"(",
"{",
"name",
":",
"key",
",",
"value",
":",
"params",
"[",
"key",
"]",
"}",
")",
";",
"}",
")",
";",
"var",
"opts",
"=",
"{",
"token",
":",
"'nestor'",
"}",
";",
"this",
".",
"remoteAccessApi",
".",
"postJobBuild",
"(",
"name",
",",
"JSON",
".",
"stringify",
"(",
"body",
")",
",",
"_",
".",
"merge",
"(",
"opts",
",",
"this",
".",
"opts",
".",
"headers",
")",
",",
"cb",
")",
";",
"}"
] | Build a job.
@param {String} name: Jenkins job name
@param {Object|String} params: build parameters key-value pairs, passed as object or 'a=b&c=d' string
@param {Function} cb: standard cb(err, result) callback | [
"Build",
"a",
"job",
"."
] | aa7e964e372bef376bab59b3f3cb5d847f76290d | https://github.com/cliffano/nestor/blob/aa7e964e372bef376bab59b3f3cb5d847f76290d/lib/api/job.js#L71-L80 |
22,928 | cliffano/nestor | lib/api/job.js | copy | function copy(existingName, newName, cb) {
var opts = {
mode: 'copy',
from: existingName,
contentType: 'text/plain',
};
this.remoteAccessApi.postCreateItem(newName, _.merge(opts, this.opts.headers), cb);
} | javascript | function copy(existingName, newName, cb) {
var opts = {
mode: 'copy',
from: existingName,
contentType: 'text/plain',
};
this.remoteAccessApi.postCreateItem(newName, _.merge(opts, this.opts.headers), cb);
} | [
"function",
"copy",
"(",
"existingName",
",",
"newName",
",",
"cb",
")",
"{",
"var",
"opts",
"=",
"{",
"mode",
":",
"'copy'",
",",
"from",
":",
"existingName",
",",
"contentType",
":",
"'text/plain'",
",",
"}",
";",
"this",
".",
"remoteAccessApi",
".",
"postCreateItem",
"(",
"newName",
",",
"_",
".",
"merge",
"(",
"opts",
",",
"this",
".",
"opts",
".",
"headers",
")",
",",
"cb",
")",
";",
"}"
] | Copy an existing job into a new job.
@param {String} existingName: existing Jenkins job name to copy from
@param {String} newName: new Jenkins job name to copy to
@param {Function} cb: standard cb(err, result) callback | [
"Copy",
"an",
"existing",
"job",
"into",
"a",
"new",
"job",
"."
] | aa7e964e372bef376bab59b3f3cb5d847f76290d | https://github.com/cliffano/nestor/blob/aa7e964e372bef376bab59b3f3cb5d847f76290d/lib/api/job.js#L204-L211 |
22,929 | cliffano/nestor | lib/cli/jenkins.js | dashboard | function dashboard(cb) {
return function (args) {
function resultCb(result) {
var jobs = result.jobs;
if (_.isEmpty(jobs)) {
console.log(text.__('Jobless Jenkins'));
} else {
jobs.forEach(function (job) {
var status = util.statusByColor(job.color);
var color = util.colorByStatus(status, job.color);
console.log('%s - %s', text.__(status)[color], job.name);
});
}
}
function jenkinsCb(jenkins) {
jenkins.info(cli.exitCb(null, resultCb));
}
cb(args, jenkinsCb);
};
} | javascript | function dashboard(cb) {
return function (args) {
function resultCb(result) {
var jobs = result.jobs;
if (_.isEmpty(jobs)) {
console.log(text.__('Jobless Jenkins'));
} else {
jobs.forEach(function (job) {
var status = util.statusByColor(job.color);
var color = util.colorByStatus(status, job.color);
console.log('%s - %s', text.__(status)[color], job.name);
});
}
}
function jenkinsCb(jenkins) {
jenkins.info(cli.exitCb(null, resultCb));
}
cb(args, jenkinsCb);
};
} | [
"function",
"dashboard",
"(",
"cb",
")",
"{",
"return",
"function",
"(",
"args",
")",
"{",
"function",
"resultCb",
"(",
"result",
")",
"{",
"var",
"jobs",
"=",
"result",
".",
"jobs",
";",
"if",
"(",
"_",
".",
"isEmpty",
"(",
"jobs",
")",
")",
"{",
"console",
".",
"log",
"(",
"text",
".",
"__",
"(",
"'Jobless Jenkins'",
")",
")",
";",
"}",
"else",
"{",
"jobs",
".",
"forEach",
"(",
"function",
"(",
"job",
")",
"{",
"var",
"status",
"=",
"util",
".",
"statusByColor",
"(",
"job",
".",
"color",
")",
";",
"var",
"color",
"=",
"util",
".",
"colorByStatus",
"(",
"status",
",",
"job",
".",
"color",
")",
";",
"console",
".",
"log",
"(",
"'%s - %s'",
",",
"text",
".",
"__",
"(",
"status",
")",
"[",
"color",
"]",
",",
"job",
".",
"name",
")",
";",
"}",
")",
";",
"}",
"}",
"function",
"jenkinsCb",
"(",
"jenkins",
")",
"{",
"jenkins",
".",
"info",
"(",
"cli",
".",
"exitCb",
"(",
"null",
",",
"resultCb",
")",
")",
";",
"}",
"cb",
"(",
"args",
",",
"jenkinsCb",
")",
";",
"}",
";",
"}"
] | Get a handler that calls Jenkins API to get a list of all jobs on the Jenkins instance.
@param {Function} cb: callback for argument handling
@return Jenkins API handler function | [
"Get",
"a",
"handler",
"that",
"calls",
"Jenkins",
"API",
"to",
"get",
"a",
"list",
"of",
"all",
"jobs",
"on",
"the",
"Jenkins",
"instance",
"."
] | aa7e964e372bef376bab59b3f3cb5d847f76290d | https://github.com/cliffano/nestor/blob/aa7e964e372bef376bab59b3f3cb5d847f76290d/lib/cli/jenkins.js#L14-L33 |
22,930 | cliffano/nestor | lib/cli/jenkins.js | discover | function discover(cb) {
return function (host, args) {
if (!args) {
args = host || {};
host = 'localhost';
}
function resultCb(result) {
console.log(text.__('Jenkins ver. %s is running on %s'),
result.hudson.version[0],
(result.hudson.url && result.hudson.url[0]) ? result.hudson.url[0] : host);
}
function jenkinsCb(jenkins) {
jenkins.discover(host, cli.exitCb(null, resultCb));
}
cb(args, jenkinsCb);
};
} | javascript | function discover(cb) {
return function (host, args) {
if (!args) {
args = host || {};
host = 'localhost';
}
function resultCb(result) {
console.log(text.__('Jenkins ver. %s is running on %s'),
result.hudson.version[0],
(result.hudson.url && result.hudson.url[0]) ? result.hudson.url[0] : host);
}
function jenkinsCb(jenkins) {
jenkins.discover(host, cli.exitCb(null, resultCb));
}
cb(args, jenkinsCb);
};
} | [
"function",
"discover",
"(",
"cb",
")",
"{",
"return",
"function",
"(",
"host",
",",
"args",
")",
"{",
"if",
"(",
"!",
"args",
")",
"{",
"args",
"=",
"host",
"||",
"{",
"}",
";",
"host",
"=",
"'localhost'",
";",
"}",
"function",
"resultCb",
"(",
"result",
")",
"{",
"console",
".",
"log",
"(",
"text",
".",
"__",
"(",
"'Jenkins ver. %s is running on %s'",
")",
",",
"result",
".",
"hudson",
".",
"version",
"[",
"0",
"]",
",",
"(",
"result",
".",
"hudson",
".",
"url",
"&&",
"result",
".",
"hudson",
".",
"url",
"[",
"0",
"]",
")",
"?",
"result",
".",
"hudson",
".",
"url",
"[",
"0",
"]",
":",
"host",
")",
";",
"}",
"function",
"jenkinsCb",
"(",
"jenkins",
")",
"{",
"jenkins",
".",
"discover",
"(",
"host",
",",
"cli",
".",
"exitCb",
"(",
"null",
",",
"resultCb",
")",
")",
";",
"}",
"cb",
"(",
"args",
",",
"jenkinsCb",
")",
";",
"}",
";",
"}"
] | Get a handler that calls Jenkins API to discover a Jenkins instance on specified host.
@param {Function} cb: callback for argument handling
@return Jenkins API handler function | [
"Get",
"a",
"handler",
"that",
"calls",
"Jenkins",
"API",
"to",
"discover",
"a",
"Jenkins",
"instance",
"on",
"specified",
"host",
"."
] | aa7e964e372bef376bab59b3f3cb5d847f76290d | https://github.com/cliffano/nestor/blob/aa7e964e372bef376bab59b3f3cb5d847f76290d/lib/cli/jenkins.js#L41-L57 |
22,931 | cliffano/nestor | lib/cli/jenkins.js | executor | function executor(cb) {
return function (args) {
function resultCb(result) {
var computers = result.computer;
if (_.isEmpty(computers)) {
console.log(text.__('No executor found'));
} else {
var data = Jenkins.executorSummary(computers);
_.keys(data).forEach(function (computer) {
console.log('+ %s | %s', computer, data[computer].summary);
data[computer].executors.forEach(function (executor) {
if (!executor.idle) {
console.log(' - %s | %s%%s', executor.name, executor.progress, (executor.stuck) ? text.__(' stuck!') : '');
}
});
});
}
}
function jenkinsCb(jenkins) {
jenkins.computer(cli.exitCb(null, resultCb));
}
cb(args, jenkinsCb);
};
} | javascript | function executor(cb) {
return function (args) {
function resultCb(result) {
var computers = result.computer;
if (_.isEmpty(computers)) {
console.log(text.__('No executor found'));
} else {
var data = Jenkins.executorSummary(computers);
_.keys(data).forEach(function (computer) {
console.log('+ %s | %s', computer, data[computer].summary);
data[computer].executors.forEach(function (executor) {
if (!executor.idle) {
console.log(' - %s | %s%%s', executor.name, executor.progress, (executor.stuck) ? text.__(' stuck!') : '');
}
});
});
}
}
function jenkinsCb(jenkins) {
jenkins.computer(cli.exitCb(null, resultCb));
}
cb(args, jenkinsCb);
};
} | [
"function",
"executor",
"(",
"cb",
")",
"{",
"return",
"function",
"(",
"args",
")",
"{",
"function",
"resultCb",
"(",
"result",
")",
"{",
"var",
"computers",
"=",
"result",
".",
"computer",
";",
"if",
"(",
"_",
".",
"isEmpty",
"(",
"computers",
")",
")",
"{",
"console",
".",
"log",
"(",
"text",
".",
"__",
"(",
"'No executor found'",
")",
")",
";",
"}",
"else",
"{",
"var",
"data",
"=",
"Jenkins",
".",
"executorSummary",
"(",
"computers",
")",
";",
"_",
".",
"keys",
"(",
"data",
")",
".",
"forEach",
"(",
"function",
"(",
"computer",
")",
"{",
"console",
".",
"log",
"(",
"'+ %s | %s'",
",",
"computer",
",",
"data",
"[",
"computer",
"]",
".",
"summary",
")",
";",
"data",
"[",
"computer",
"]",
".",
"executors",
".",
"forEach",
"(",
"function",
"(",
"executor",
")",
"{",
"if",
"(",
"!",
"executor",
".",
"idle",
")",
"{",
"console",
".",
"log",
"(",
"' - %s | %s%%s'",
",",
"executor",
".",
"name",
",",
"executor",
".",
"progress",
",",
"(",
"executor",
".",
"stuck",
")",
"?",
"text",
".",
"__",
"(",
"' stuck!'",
")",
":",
"''",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}",
"}",
"function",
"jenkinsCb",
"(",
"jenkins",
")",
"{",
"jenkins",
".",
"computer",
"(",
"cli",
".",
"exitCb",
"(",
"null",
",",
"resultCb",
")",
")",
";",
"}",
"cb",
"(",
"args",
",",
"jenkinsCb",
")",
";",
"}",
";",
"}"
] | Get a handler that calls Jenkins API to display executors information per computer
@param {Function} cb: callback for argument handling
@return Jenkins API handler function | [
"Get",
"a",
"handler",
"that",
"calls",
"Jenkins",
"API",
"to",
"display",
"executors",
"information",
"per",
"computer"
] | aa7e964e372bef376bab59b3f3cb5d847f76290d | https://github.com/cliffano/nestor/blob/aa7e964e372bef376bab59b3f3cb5d847f76290d/lib/cli/jenkins.js#L65-L93 |
22,932 | cliffano/nestor | lib/cli/jenkins.js | feed | function feed(cb) {
return function (args) {
function resultCb(result) {
result.forEach(function (article) {
console.log(article.title);
});
}
function jenkinsCb(jenkins) {
if (args.job) {
jenkins.parseJobFeed(args.job, cli.exitCb(null, resultCb));
} else if (args.view) {
jenkins.parseViewFeed(args.view, cli.exitCb(null, resultCb));
} else {
jenkins.parseFeed(cli.exitCb(null, resultCb));
}
}
cb(args, jenkinsCb);
};
} | javascript | function feed(cb) {
return function (args) {
function resultCb(result) {
result.forEach(function (article) {
console.log(article.title);
});
}
function jenkinsCb(jenkins) {
if (args.job) {
jenkins.parseJobFeed(args.job, cli.exitCb(null, resultCb));
} else if (args.view) {
jenkins.parseViewFeed(args.view, cli.exitCb(null, resultCb));
} else {
jenkins.parseFeed(cli.exitCb(null, resultCb));
}
}
cb(args, jenkinsCb);
};
} | [
"function",
"feed",
"(",
"cb",
")",
"{",
"return",
"function",
"(",
"args",
")",
"{",
"function",
"resultCb",
"(",
"result",
")",
"{",
"result",
".",
"forEach",
"(",
"function",
"(",
"article",
")",
"{",
"console",
".",
"log",
"(",
"article",
".",
"title",
")",
";",
"}",
")",
";",
"}",
"function",
"jenkinsCb",
"(",
"jenkins",
")",
"{",
"if",
"(",
"args",
".",
"job",
")",
"{",
"jenkins",
".",
"parseJobFeed",
"(",
"args",
".",
"job",
",",
"cli",
".",
"exitCb",
"(",
"null",
",",
"resultCb",
")",
")",
";",
"}",
"else",
"if",
"(",
"args",
".",
"view",
")",
"{",
"jenkins",
".",
"parseViewFeed",
"(",
"args",
".",
"view",
",",
"cli",
".",
"exitCb",
"(",
"null",
",",
"resultCb",
")",
")",
";",
"}",
"else",
"{",
"jenkins",
".",
"parseFeed",
"(",
"cli",
".",
"exitCb",
"(",
"null",
",",
"resultCb",
")",
")",
";",
"}",
"}",
"cb",
"(",
"args",
",",
"jenkinsCb",
")",
";",
"}",
";",
"}"
] | Get a handler that calls Jenkins API to retrieve feed.
Feed contains articles.
@param {Function} cb: callback for argument handling
@return Jenkins API handler function | [
"Get",
"a",
"handler",
"that",
"calls",
"Jenkins",
"API",
"to",
"retrieve",
"feed",
".",
"Feed",
"contains",
"articles",
"."
] | aa7e964e372bef376bab59b3f3cb5d847f76290d | https://github.com/cliffano/nestor/blob/aa7e964e372bef376bab59b3f3cb5d847f76290d/lib/cli/jenkins.js#L102-L120 |
22,933 | cliffano/nestor | lib/cli/util.js | colorByStatus | function colorByStatus(status, jenkinsColor) {
var color;
if (jenkinsColor) {
// Jenkins color value can contain either a color, color_anime, or status in job.color field,
// hence to get color/status value out of the mix we need to remove the postfix _anime,
// _anime postfix only exists on a job currently being built
jenkinsColor = jenkinsColor.replace(/_anime$/, '');
color = (COLOR_STATUS[jenkinsColor] && COLOR_STATUS[jenkinsColor][0]) ? jenkinsColor : 'grey';
} else {
color = 'grey';
_.keys(COLOR_STATUS).forEach(function (_color) {
COLOR_STATUS[_color].forEach(function (_status) {
if (_status === status) {
color = _color;
}
});
});
}
return color;
} | javascript | function colorByStatus(status, jenkinsColor) {
var color;
if (jenkinsColor) {
// Jenkins color value can contain either a color, color_anime, or status in job.color field,
// hence to get color/status value out of the mix we need to remove the postfix _anime,
// _anime postfix only exists on a job currently being built
jenkinsColor = jenkinsColor.replace(/_anime$/, '');
color = (COLOR_STATUS[jenkinsColor] && COLOR_STATUS[jenkinsColor][0]) ? jenkinsColor : 'grey';
} else {
color = 'grey';
_.keys(COLOR_STATUS).forEach(function (_color) {
COLOR_STATUS[_color].forEach(function (_status) {
if (_status === status) {
color = _color;
}
});
});
}
return color;
} | [
"function",
"colorByStatus",
"(",
"status",
",",
"jenkinsColor",
")",
"{",
"var",
"color",
";",
"if",
"(",
"jenkinsColor",
")",
"{",
"// Jenkins color value can contain either a color, color_anime, or status in job.color field,",
"// hence to get color/status value out of the mix we need to remove the postfix _anime,",
"// _anime postfix only exists on a job currently being built",
"jenkinsColor",
"=",
"jenkinsColor",
".",
"replace",
"(",
"/",
"_anime$",
"/",
",",
"''",
")",
";",
"color",
"=",
"(",
"COLOR_STATUS",
"[",
"jenkinsColor",
"]",
"&&",
"COLOR_STATUS",
"[",
"jenkinsColor",
"]",
"[",
"0",
"]",
")",
"?",
"jenkinsColor",
":",
"'grey'",
";",
"}",
"else",
"{",
"color",
"=",
"'grey'",
";",
"_",
".",
"keys",
"(",
"COLOR_STATUS",
")",
".",
"forEach",
"(",
"function",
"(",
"_color",
")",
"{",
"COLOR_STATUS",
"[",
"_color",
"]",
".",
"forEach",
"(",
"function",
"(",
"_status",
")",
"{",
"if",
"(",
"_status",
"===",
"status",
")",
"{",
"color",
"=",
"_color",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}",
"return",
"color",
";",
"}"
] | Get color based on status and Jenkins status color.
Jenkins status color will take precedence over status because
Jenkins uses either blue or green as the color for ok status.
Color property can contain either color or status text.
Hence the need for mapping color to status text in the case where value is really color.
This is used in conjunction with statusByColor function.
@param {String} status: Jenkins status
@param {String} jenkinsColor: Jenkins status color
@return the status text | [
"Get",
"color",
"based",
"on",
"status",
"and",
"Jenkins",
"status",
"color",
".",
"Jenkins",
"status",
"color",
"will",
"take",
"precedence",
"over",
"status",
"because",
"Jenkins",
"uses",
"either",
"blue",
"or",
"green",
"as",
"the",
"color",
"for",
"ok",
"status",
"."
] | aa7e964e372bef376bab59b3f3cb5d847f76290d | https://github.com/cliffano/nestor/blob/aa7e964e372bef376bab59b3f3cb5d847f76290d/lib/cli/util.js#L24-L46 |
22,934 | cliffano/nestor | lib/cli/util.js | statusByColor | function statusByColor(jenkinsColor) {
if (jenkinsColor) {
// Jenkins color value can contain either a color, color_anime, or status in job.color field,
// hence to get color/status value out of the mix we need to remove the postfix _anime,
// _anime postfix only exists on a job currently being built
jenkinsColor = jenkinsColor.replace(/_anime$/, '');
status = (COLOR_STATUS[jenkinsColor]) ? COLOR_STATUS[jenkinsColor][0] : jenkinsColor;
} else {
status = 'unknown';
}
return status;
} | javascript | function statusByColor(jenkinsColor) {
if (jenkinsColor) {
// Jenkins color value can contain either a color, color_anime, or status in job.color field,
// hence to get color/status value out of the mix we need to remove the postfix _anime,
// _anime postfix only exists on a job currently being built
jenkinsColor = jenkinsColor.replace(/_anime$/, '');
status = (COLOR_STATUS[jenkinsColor]) ? COLOR_STATUS[jenkinsColor][0] : jenkinsColor;
} else {
status = 'unknown';
}
return status;
} | [
"function",
"statusByColor",
"(",
"jenkinsColor",
")",
"{",
"if",
"(",
"jenkinsColor",
")",
"{",
"// Jenkins color value can contain either a color, color_anime, or status in job.color field,",
"// hence to get color/status value out of the mix we need to remove the postfix _anime,",
"// _anime postfix only exists on a job currently being built",
"jenkinsColor",
"=",
"jenkinsColor",
".",
"replace",
"(",
"/",
"_anime$",
"/",
",",
"''",
")",
";",
"status",
"=",
"(",
"COLOR_STATUS",
"[",
"jenkinsColor",
"]",
")",
"?",
"COLOR_STATUS",
"[",
"jenkinsColor",
"]",
"[",
"0",
"]",
":",
"jenkinsColor",
";",
"}",
"else",
"{",
"status",
"=",
"'unknown'",
";",
"}",
"return",
"status",
";",
"}"
] | Get status based on the value of color property.
Color property can contain either color or status text.
Hence the need for mapping color to status text in the case where value is really color.
This is used in conjunction with colorByStatus function.
@param {String} jenkinsColor: Jenkins status color
@return the status text | [
"Get",
"status",
"based",
"on",
"the",
"value",
"of",
"color",
"property",
"."
] | aa7e964e372bef376bab59b3f3cb5d847f76290d | https://github.com/cliffano/nestor/blob/aa7e964e372bef376bab59b3f3cb5d847f76290d/lib/cli/util.js#L58-L73 |
22,935 | bevacqua/insane | parser.js | parsePart | function parsePart () {
chars = true;
parseTag();
var same = html === last;
last = html;
if (same) { // discard, because it's invalid
html = '';
}
} | javascript | function parsePart () {
chars = true;
parseTag();
var same = html === last;
last = html;
if (same) { // discard, because it's invalid
html = '';
}
} | [
"function",
"parsePart",
"(",
")",
"{",
"chars",
"=",
"true",
";",
"parseTag",
"(",
")",
";",
"var",
"same",
"=",
"html",
"===",
"last",
";",
"last",
"=",
"html",
";",
"if",
"(",
"same",
")",
"{",
"// discard, because it's invalid",
"html",
"=",
"''",
";",
"}",
"}"
] | clean up any remaining tags | [
"clean",
"up",
"any",
"remaining",
"tags"
] | 7f5a809f44a37e7d11ee5343b2d8bca4be6ba4ae | https://github.com/bevacqua/insane/blob/7f5a809f44a37e7d11ee5343b2d8bca4be6ba4ae/parser.js#L31-L41 |
22,936 | iosphere/elm-i18n | index.js | build | function build(outputDir) {
let exec = require("child_process").exec;
let elmFile = path.join(argv.src, argv.elmFile);
let cmd = "elm-make " + elmFile + " --yes --output " + argv.output + "/" + argv.language + ".js";
console.log(cmd);
exec(cmd, (err, stdout, stderr) => {
if(err) {
console.error(err);
return;
}
console.log(stdout);
});
} | javascript | function build(outputDir) {
let exec = require("child_process").exec;
let elmFile = path.join(argv.src, argv.elmFile);
let cmd = "elm-make " + elmFile + " --yes --output " + argv.output + "/" + argv.language + ".js";
console.log(cmd);
exec(cmd, (err, stdout, stderr) => {
if(err) {
console.error(err);
return;
}
console.log(stdout);
});
} | [
"function",
"build",
"(",
"outputDir",
")",
"{",
"let",
"exec",
"=",
"require",
"(",
"\"child_process\"",
")",
".",
"exec",
";",
"let",
"elmFile",
"=",
"path",
".",
"join",
"(",
"argv",
".",
"src",
",",
"argv",
".",
"elmFile",
")",
";",
"let",
"cmd",
"=",
"\"elm-make \"",
"+",
"elmFile",
"+",
"\" --yes --output \"",
"+",
"argv",
".",
"output",
"+",
"\"/\"",
"+",
"argv",
".",
"language",
"+",
"\".js\"",
";",
"console",
".",
"log",
"(",
"cmd",
")",
";",
"exec",
"(",
"cmd",
",",
"(",
"err",
",",
"stdout",
",",
"stderr",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"err",
")",
";",
"return",
";",
"}",
"console",
".",
"log",
"(",
"stdout",
")",
";",
"}",
")",
";",
"}"
] | build - Builds the elm app with the current language.
@param {type} outputDir The directory to which the elm build should be written.
Files will be named according to the current language | [
"build",
"-",
"Builds",
"the",
"elm",
"app",
"with",
"the",
"current",
"language",
"."
] | 8d4e571868390800ed64d530c8354b74949cf433 | https://github.com/iosphere/elm-i18n/blob/8d4e571868390800ed64d530c8354b74949cf433/index.js#L88-L100 |
22,937 | iosphere/elm-i18n | extractor.js | handleExport | function handleExport(resultString) {
if (resultString === "") {
process.exit(500);
}
let targetPath = path.join(currentDir, argv.exportOutput);
fs.writeFileSync(targetPath, resultString);
console.log("Finished writing csv file to:", targetPath);
} | javascript | function handleExport(resultString) {
if (resultString === "") {
process.exit(500);
}
let targetPath = path.join(currentDir, argv.exportOutput);
fs.writeFileSync(targetPath, resultString);
console.log("Finished writing csv file to:", targetPath);
} | [
"function",
"handleExport",
"(",
"resultString",
")",
"{",
"if",
"(",
"resultString",
"===",
"\"\"",
")",
"{",
"process",
".",
"exit",
"(",
"500",
")",
";",
"}",
"let",
"targetPath",
"=",
"path",
".",
"join",
"(",
"currentDir",
",",
"argv",
".",
"exportOutput",
")",
";",
"fs",
".",
"writeFileSync",
"(",
"targetPath",
",",
"resultString",
")",
";",
"console",
".",
"log",
"(",
"\"Finished writing csv file to:\"",
",",
"targetPath",
")",
";",
"}"
] | handleExport - Handles the csv string generated by elm and saves it to exportOutput.
@param {String} resultString A CSV string of all translations. | [
"handleExport",
"-",
"Handles",
"the",
"csv",
"string",
"generated",
"by",
"elm",
"and",
"saves",
"it",
"to",
"exportOutput",
"."
] | 8d4e571868390800ed64d530c8354b74949cf433 | https://github.com/iosphere/elm-i18n/blob/8d4e571868390800ed64d530c8354b74949cf433/extractor.js#L91-L99 |
22,938 | iosphere/elm-i18n | dist/elm.js | htmlToProgram | function htmlToProgram(vnode)
{
var emptyBag = batch(_elm_lang$core$Native_List.Nil);
var noChange = _elm_lang$core$Native_Utils.Tuple2(
_elm_lang$core$Native_Utils.Tuple0,
emptyBag
);
return _elm_lang$virtual_dom$VirtualDom$program({
init: noChange,
view: function(model) { return main; },
update: F2(function(msg, model) { return noChange; }),
subscriptions: function (model) { return emptyBag; }
});
} | javascript | function htmlToProgram(vnode)
{
var emptyBag = batch(_elm_lang$core$Native_List.Nil);
var noChange = _elm_lang$core$Native_Utils.Tuple2(
_elm_lang$core$Native_Utils.Tuple0,
emptyBag
);
return _elm_lang$virtual_dom$VirtualDom$program({
init: noChange,
view: function(model) { return main; },
update: F2(function(msg, model) { return noChange; }),
subscriptions: function (model) { return emptyBag; }
});
} | [
"function",
"htmlToProgram",
"(",
"vnode",
")",
"{",
"var",
"emptyBag",
"=",
"batch",
"(",
"_elm_lang$core$Native_List",
".",
"Nil",
")",
";",
"var",
"noChange",
"=",
"_elm_lang$core$Native_Utils",
".",
"Tuple2",
"(",
"_elm_lang$core$Native_Utils",
".",
"Tuple0",
",",
"emptyBag",
")",
";",
"return",
"_elm_lang$virtual_dom$VirtualDom$program",
"(",
"{",
"init",
":",
"noChange",
",",
"view",
":",
"function",
"(",
"model",
")",
"{",
"return",
"main",
";",
"}",
",",
"update",
":",
"F2",
"(",
"function",
"(",
"msg",
",",
"model",
")",
"{",
"return",
"noChange",
";",
"}",
")",
",",
"subscriptions",
":",
"function",
"(",
"model",
")",
"{",
"return",
"emptyBag",
";",
"}",
"}",
")",
";",
"}"
] | HTML TO PROGRAM | [
"HTML",
"TO",
"PROGRAM"
] | 8d4e571868390800ed64d530c8354b74949cf433 | https://github.com/iosphere/elm-i18n/blob/8d4e571868390800ed64d530c8354b74949cf433/dist/elm.js#L2400-L2414 |
22,939 | iosphere/elm-i18n | dist/elm.js | spawnLoop | function spawnLoop(init, onMessage)
{
var andThen = _elm_lang$core$Native_Scheduler.andThen;
function loop(state)
{
var handleMsg = _elm_lang$core$Native_Scheduler.receive(function(msg) {
return onMessage(msg, state);
});
return A2(andThen, loop, handleMsg);
}
var task = A2(andThen, loop, init);
return _elm_lang$core$Native_Scheduler.rawSpawn(task);
} | javascript | function spawnLoop(init, onMessage)
{
var andThen = _elm_lang$core$Native_Scheduler.andThen;
function loop(state)
{
var handleMsg = _elm_lang$core$Native_Scheduler.receive(function(msg) {
return onMessage(msg, state);
});
return A2(andThen, loop, handleMsg);
}
var task = A2(andThen, loop, init);
return _elm_lang$core$Native_Scheduler.rawSpawn(task);
} | [
"function",
"spawnLoop",
"(",
"init",
",",
"onMessage",
")",
"{",
"var",
"andThen",
"=",
"_elm_lang$core$Native_Scheduler",
".",
"andThen",
";",
"function",
"loop",
"(",
"state",
")",
"{",
"var",
"handleMsg",
"=",
"_elm_lang$core$Native_Scheduler",
".",
"receive",
"(",
"function",
"(",
"msg",
")",
"{",
"return",
"onMessage",
"(",
"msg",
",",
"state",
")",
";",
"}",
")",
";",
"return",
"A2",
"(",
"andThen",
",",
"loop",
",",
"handleMsg",
")",
";",
"}",
"var",
"task",
"=",
"A2",
"(",
"andThen",
",",
"loop",
",",
"init",
")",
";",
"return",
"_elm_lang$core$Native_Scheduler",
".",
"rawSpawn",
"(",
"task",
")",
";",
"}"
] | HELPER for STATEFUL LOOPS | [
"HELPER",
"for",
"STATEFUL",
"LOOPS"
] | 8d4e571868390800ed64d530c8354b74949cf433 | https://github.com/iosphere/elm-i18n/blob/8d4e571868390800ed64d530c8354b74949cf433/dist/elm.js#L2545-L2560 |
22,940 | superbrothers/capturejs | lib/capturejs.js | createPageHandler | function createPageHandler(page) {
if (DEBUG && !page.phantom) inspectArgs("createPageHandler: ", page);
phPage = page;
var matches;
if (option.viewportsize) {
matches = option.viewportsize.match(/^(\d+)x(\d+)$/);
if (matches !== null) {
page.property("viewportSize", {width: matches[1], height: matches[2]});
}
}
if (option.cliprect) {
matches = option.cliprect.match(/^(\d+)x(\d+)x(\d+)x(\d+)$/);
if (matches !== null) {
page.setting("clipRect", {top: matches[1], left: matches[2],
width: matches[3], height: matches[4]});
}
}
if (option["user-agent"]) {
page.setting("userAgent", option["user-agent"]);
}
if (option.zoomfactor) {
page.setting("zoomFactor", parseFloat(option.zoomfactor));
}
if (option.timeout) {
timer = setTimeout(function () {
var err = `capturejs: cannot access ${option.uri}: request timed out`;
console.error(err);
phInstance.exit();
process.nextTick(function () { callback(err) });
}, +option.timeout);
}
return page.open(option.uri);
} | javascript | function createPageHandler(page) {
if (DEBUG && !page.phantom) inspectArgs("createPageHandler: ", page);
phPage = page;
var matches;
if (option.viewportsize) {
matches = option.viewportsize.match(/^(\d+)x(\d+)$/);
if (matches !== null) {
page.property("viewportSize", {width: matches[1], height: matches[2]});
}
}
if (option.cliprect) {
matches = option.cliprect.match(/^(\d+)x(\d+)x(\d+)x(\d+)$/);
if (matches !== null) {
page.setting("clipRect", {top: matches[1], left: matches[2],
width: matches[3], height: matches[4]});
}
}
if (option["user-agent"]) {
page.setting("userAgent", option["user-agent"]);
}
if (option.zoomfactor) {
page.setting("zoomFactor", parseFloat(option.zoomfactor));
}
if (option.timeout) {
timer = setTimeout(function () {
var err = `capturejs: cannot access ${option.uri}: request timed out`;
console.error(err);
phInstance.exit();
process.nextTick(function () { callback(err) });
}, +option.timeout);
}
return page.open(option.uri);
} | [
"function",
"createPageHandler",
"(",
"page",
")",
"{",
"if",
"(",
"DEBUG",
"&&",
"!",
"page",
".",
"phantom",
")",
"inspectArgs",
"(",
"\"createPageHandler: \"",
",",
"page",
")",
";",
"phPage",
"=",
"page",
";",
"var",
"matches",
";",
"if",
"(",
"option",
".",
"viewportsize",
")",
"{",
"matches",
"=",
"option",
".",
"viewportsize",
".",
"match",
"(",
"/",
"^(\\d+)x(\\d+)$",
"/",
")",
";",
"if",
"(",
"matches",
"!==",
"null",
")",
"{",
"page",
".",
"property",
"(",
"\"viewportSize\"",
",",
"{",
"width",
":",
"matches",
"[",
"1",
"]",
",",
"height",
":",
"matches",
"[",
"2",
"]",
"}",
")",
";",
"}",
"}",
"if",
"(",
"option",
".",
"cliprect",
")",
"{",
"matches",
"=",
"option",
".",
"cliprect",
".",
"match",
"(",
"/",
"^(\\d+)x(\\d+)x(\\d+)x(\\d+)$",
"/",
")",
";",
"if",
"(",
"matches",
"!==",
"null",
")",
"{",
"page",
".",
"setting",
"(",
"\"clipRect\"",
",",
"{",
"top",
":",
"matches",
"[",
"1",
"]",
",",
"left",
":",
"matches",
"[",
"2",
"]",
",",
"width",
":",
"matches",
"[",
"3",
"]",
",",
"height",
":",
"matches",
"[",
"4",
"]",
"}",
")",
";",
"}",
"}",
"if",
"(",
"option",
"[",
"\"user-agent\"",
"]",
")",
"{",
"page",
".",
"setting",
"(",
"\"userAgent\"",
",",
"option",
"[",
"\"user-agent\"",
"]",
")",
";",
"}",
"if",
"(",
"option",
".",
"zoomfactor",
")",
"{",
"page",
".",
"setting",
"(",
"\"zoomFactor\"",
",",
"parseFloat",
"(",
"option",
".",
"zoomfactor",
")",
")",
";",
"}",
"if",
"(",
"option",
".",
"timeout",
")",
"{",
"timer",
"=",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"var",
"err",
"=",
"`",
"${",
"option",
".",
"uri",
"}",
"`",
";",
"console",
".",
"error",
"(",
"err",
")",
";",
"phInstance",
".",
"exit",
"(",
")",
";",
"process",
".",
"nextTick",
"(",
"function",
"(",
")",
"{",
"callback",
"(",
"err",
")",
"}",
")",
";",
"}",
",",
"+",
"option",
".",
"timeout",
")",
";",
"}",
"return",
"page",
".",
"open",
"(",
"option",
".",
"uri",
")",
";",
"}"
] | Configure page settings then open a new page in PhantomJS. | [
"Configure",
"page",
"settings",
"then",
"open",
"a",
"new",
"page",
"in",
"PhantomJS",
"."
] | a29082451784713799ae4647665a2092ad2b0633 | https://github.com/superbrothers/capturejs/blob/a29082451784713799ae4647665a2092ad2b0633/lib/capturejs.js#L73-L112 |
22,941 | superbrothers/capturejs | lib/capturejs.js | reportStatus | function reportStatus(status) {
if (DEBUG && status !== "success") inspectArgs("reportStatus: ", status);
if (status === "fail") {
var err = `capturejs: cannot access ${option.uri}: failed to open page`;
console.error(err);
phInstance.exit();
process.nextTick(callback, err);
} else {
return phPage;
}
} | javascript | function reportStatus(status) {
if (DEBUG && status !== "success") inspectArgs("reportStatus: ", status);
if (status === "fail") {
var err = `capturejs: cannot access ${option.uri}: failed to open page`;
console.error(err);
phInstance.exit();
process.nextTick(callback, err);
} else {
return phPage;
}
} | [
"function",
"reportStatus",
"(",
"status",
")",
"{",
"if",
"(",
"DEBUG",
"&&",
"status",
"!==",
"\"success\"",
")",
"inspectArgs",
"(",
"\"reportStatus: \"",
",",
"status",
")",
";",
"if",
"(",
"status",
"===",
"\"fail\"",
")",
"{",
"var",
"err",
"=",
"`",
"${",
"option",
".",
"uri",
"}",
"`",
";",
"console",
".",
"error",
"(",
"err",
")",
";",
"phInstance",
".",
"exit",
"(",
")",
";",
"process",
".",
"nextTick",
"(",
"callback",
",",
"err",
")",
";",
"}",
"else",
"{",
"return",
"phPage",
";",
"}",
"}"
] | Log status messages, and close PhantomJS on failure. | [
"Log",
"status",
"messages",
"and",
"close",
"PhantomJS",
"on",
"failure",
"."
] | a29082451784713799ae4647665a2092ad2b0633 | https://github.com/superbrothers/capturejs/blob/a29082451784713799ae4647665a2092ad2b0633/lib/capturejs.js#L117-L128 |
22,942 | superbrothers/capturejs | lib/capturejs.js | manipulatePage | function manipulatePage(page) {
if (DEBUG && !page.phantom) inspectArgs("manipulatePage: ", page);
if (timer !== undefined) {
clearTimeout(timer);
}
// Inject an external script file.
if (option["javascript-file"]) {
page.injectJs(option["javascript-file"]);
}
// Inject an in-line script from the command line.
if (option["inject-script"]) {
var injectScript = option["inject-script"];
injectScript = (typeof injectScript === "function") ?
injectScript.toString() : `function() { ${injectScript} }`;
page.evaluateJavaScript(injectScript);
}
if (option.waitcapturedelay) {
setTimeout(function () { return page }, +option.waitcapturedelay);
} else {
return page;
}
} | javascript | function manipulatePage(page) {
if (DEBUG && !page.phantom) inspectArgs("manipulatePage: ", page);
if (timer !== undefined) {
clearTimeout(timer);
}
// Inject an external script file.
if (option["javascript-file"]) {
page.injectJs(option["javascript-file"]);
}
// Inject an in-line script from the command line.
if (option["inject-script"]) {
var injectScript = option["inject-script"];
injectScript = (typeof injectScript === "function") ?
injectScript.toString() : `function() { ${injectScript} }`;
page.evaluateJavaScript(injectScript);
}
if (option.waitcapturedelay) {
setTimeout(function () { return page }, +option.waitcapturedelay);
} else {
return page;
}
} | [
"function",
"manipulatePage",
"(",
"page",
")",
"{",
"if",
"(",
"DEBUG",
"&&",
"!",
"page",
".",
"phantom",
")",
"inspectArgs",
"(",
"\"manipulatePage: \"",
",",
"page",
")",
";",
"if",
"(",
"timer",
"!==",
"undefined",
")",
"{",
"clearTimeout",
"(",
"timer",
")",
";",
"}",
"// Inject an external script file.",
"if",
"(",
"option",
"[",
"\"javascript-file\"",
"]",
")",
"{",
"page",
".",
"injectJs",
"(",
"option",
"[",
"\"javascript-file\"",
"]",
")",
";",
"}",
"// Inject an in-line script from the command line.",
"if",
"(",
"option",
"[",
"\"inject-script\"",
"]",
")",
"{",
"var",
"injectScript",
"=",
"option",
"[",
"\"inject-script\"",
"]",
";",
"injectScript",
"=",
"(",
"typeof",
"injectScript",
"===",
"\"function\"",
")",
"?",
"injectScript",
".",
"toString",
"(",
")",
":",
"`",
"${",
"injectScript",
"}",
"`",
";",
"page",
".",
"evaluateJavaScript",
"(",
"injectScript",
")",
";",
"}",
"if",
"(",
"option",
".",
"waitcapturedelay",
")",
"{",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"return",
"page",
"}",
",",
"+",
"option",
".",
"waitcapturedelay",
")",
";",
"}",
"else",
"{",
"return",
"page",
";",
"}",
"}"
] | Inject JavaScript into the open page. | [
"Inject",
"JavaScript",
"into",
"the",
"open",
"page",
"."
] | a29082451784713799ae4647665a2092ad2b0633 | https://github.com/superbrothers/capturejs/blob/a29082451784713799ae4647665a2092ad2b0633/lib/capturejs.js#L133-L158 |
22,943 | superbrothers/capturejs | lib/capturejs.js | captureImage | function captureImage(page) {
if (DEBUG && !page.phantom) inspectArgs("captureImage: ", page);
if (option.selector) {
let getElement = [ "function () {",
, "document.body.bgColor = 'white';"
, `var elem = document.querySelector('${option.selector}');`
, "return (elem !== null) ? elem.getBoundingClientRect() : null; };"
].join("");
return page.evaluateJavaScript(getElement);
}
} | javascript | function captureImage(page) {
if (DEBUG && !page.phantom) inspectArgs("captureImage: ", page);
if (option.selector) {
let getElement = [ "function () {",
, "document.body.bgColor = 'white';"
, `var elem = document.querySelector('${option.selector}');`
, "return (elem !== null) ? elem.getBoundingClientRect() : null; };"
].join("");
return page.evaluateJavaScript(getElement);
}
} | [
"function",
"captureImage",
"(",
"page",
")",
"{",
"if",
"(",
"DEBUG",
"&&",
"!",
"page",
".",
"phantom",
")",
"inspectArgs",
"(",
"\"captureImage: \"",
",",
"page",
")",
";",
"if",
"(",
"option",
".",
"selector",
")",
"{",
"let",
"getElement",
"=",
"[",
"\"function () {\"",
",",
",",
"\"document.body.bgColor = 'white';\"",
",",
"`",
"${",
"option",
".",
"selector",
"}",
"`",
",",
"\"return (elem !== null) ? elem.getBoundingClientRect() : null; };\"",
"]",
".",
"join",
"(",
"\"\"",
")",
";",
"return",
"page",
".",
"evaluateJavaScript",
"(",
"getElement",
")",
";",
"}",
"}"
] | Capture the specified image. | [
"Capture",
"the",
"specified",
"image",
"."
] | a29082451784713799ae4647665a2092ad2b0633 | https://github.com/superbrothers/capturejs/blob/a29082451784713799ae4647665a2092ad2b0633/lib/capturejs.js#L163-L175 |
22,944 | superbrothers/capturejs | lib/capturejs.js | saveImage | function saveImage(rect) {
if (DEBUG && rect && !rect.bottom) inspectArgs("saveImage: ", rect);
if (rect && typeof rect.bottom === "number") {
phPage.property("clipRect", rect);
}
// Set a timeout to give the page a chance to render.
setTimeout(function () {
phPage.render(option.output)
.then(function () {
phInstance.exit();
// process.removeListener("uncaughtException", onUncaughtException);
process.nextTick(callback);
});
}, option.renderdelay || 250);
} | javascript | function saveImage(rect) {
if (DEBUG && rect && !rect.bottom) inspectArgs("saveImage: ", rect);
if (rect && typeof rect.bottom === "number") {
phPage.property("clipRect", rect);
}
// Set a timeout to give the page a chance to render.
setTimeout(function () {
phPage.render(option.output)
.then(function () {
phInstance.exit();
// process.removeListener("uncaughtException", onUncaughtException);
process.nextTick(callback);
});
}, option.renderdelay || 250);
} | [
"function",
"saveImage",
"(",
"rect",
")",
"{",
"if",
"(",
"DEBUG",
"&&",
"rect",
"&&",
"!",
"rect",
".",
"bottom",
")",
"inspectArgs",
"(",
"\"saveImage: \"",
",",
"rect",
")",
";",
"if",
"(",
"rect",
"&&",
"typeof",
"rect",
".",
"bottom",
"===",
"\"number\"",
")",
"{",
"phPage",
".",
"property",
"(",
"\"clipRect\"",
",",
"rect",
")",
";",
"}",
"// Set a timeout to give the page a chance to render.",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"phPage",
".",
"render",
"(",
"option",
".",
"output",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"phInstance",
".",
"exit",
"(",
")",
";",
"// process.removeListener(\"uncaughtException\", onUncaughtException);",
"process",
".",
"nextTick",
"(",
"callback",
")",
";",
"}",
")",
";",
"}",
",",
"option",
".",
"renderdelay",
"||",
"250",
")",
";",
"}"
] | Output the saved image to the specified file. | [
"Output",
"the",
"saved",
"image",
"to",
"the",
"specified",
"file",
"."
] | a29082451784713799ae4647665a2092ad2b0633 | https://github.com/superbrothers/capturejs/blob/a29082451784713799ae4647665a2092ad2b0633/lib/capturejs.js#L180-L196 |
22,945 | shobhitsharma/embedo | embedo.js | ajax | function ajax(url, options, callback) {
if (typeof options === 'function') {
callback = options;
options = {};
}
callback = callback || function () {};
var xhr = new XMLHttpRequest();
xhr.onload = function () {
if (xhr.status >= 400) {
return callback(new Error(xhr.responseText || xhr.statusText));
}
try {
return callback(null, JSON.parse(xhr.responseText));
} catch (e) {
return callback(new Error('invalid_response'));
}
};
xhr.onerror = function (err) {
return callback(err);
};
xhr.open('GET', url);
xhr.send();
} | javascript | function ajax(url, options, callback) {
if (typeof options === 'function') {
callback = options;
options = {};
}
callback = callback || function () {};
var xhr = new XMLHttpRequest();
xhr.onload = function () {
if (xhr.status >= 400) {
return callback(new Error(xhr.responseText || xhr.statusText));
}
try {
return callback(null, JSON.parse(xhr.responseText));
} catch (e) {
return callback(new Error('invalid_response'));
}
};
xhr.onerror = function (err) {
return callback(err);
};
xhr.open('GET', url);
xhr.send();
} | [
"function",
"ajax",
"(",
"url",
",",
"options",
",",
"callback",
")",
"{",
"if",
"(",
"typeof",
"options",
"===",
"'function'",
")",
"{",
"callback",
"=",
"options",
";",
"options",
"=",
"{",
"}",
";",
"}",
"callback",
"=",
"callback",
"||",
"function",
"(",
")",
"{",
"}",
";",
"var",
"xhr",
"=",
"new",
"XMLHttpRequest",
"(",
")",
";",
"xhr",
".",
"onload",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"xhr",
".",
"status",
">=",
"400",
")",
"{",
"return",
"callback",
"(",
"new",
"Error",
"(",
"xhr",
".",
"responseText",
"||",
"xhr",
".",
"statusText",
")",
")",
";",
"}",
"try",
"{",
"return",
"callback",
"(",
"null",
",",
"JSON",
".",
"parse",
"(",
"xhr",
".",
"responseText",
")",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"return",
"callback",
"(",
"new",
"Error",
"(",
"'invalid_response'",
")",
")",
";",
"}",
"}",
";",
"xhr",
".",
"onerror",
"=",
"function",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
";",
"xhr",
".",
"open",
"(",
"'GET'",
",",
"url",
")",
";",
"xhr",
".",
"send",
"(",
")",
";",
"}"
] | XHR HTTP Requests
@param {string} url
@param {object} options
@param {Function} callback | [
"XHR",
"HTTP",
"Requests"
] | 8578c4125ecf475f4cdbd412f13d8687e816cda5 | https://github.com/shobhitsharma/embedo/blob/8578c4125ecf475f4cdbd412f13d8687e816cda5/embedo.js#L494-L516 |
22,946 | shobhitsharma/embedo | embedo.js | relative_px | function relative_px(type, value) {
var w = window,
d = document,
e = d.documentElement,
g = d.body,
x = w.innerWidth || e.clientWidth || g.clientWidth,
y = w.innerHeight || e.clientHeight || g.clientHeight;
if (type === 'vw') {
return (x * parseFloat(value)) / 100;
} else if (type === 'vh') {
return (y * parseFloat(value)) / 100;
} else {
return undefined;
}
} | javascript | function relative_px(type, value) {
var w = window,
d = document,
e = d.documentElement,
g = d.body,
x = w.innerWidth || e.clientWidth || g.clientWidth,
y = w.innerHeight || e.clientHeight || g.clientHeight;
if (type === 'vw') {
return (x * parseFloat(value)) / 100;
} else if (type === 'vh') {
return (y * parseFloat(value)) / 100;
} else {
return undefined;
}
} | [
"function",
"relative_px",
"(",
"type",
",",
"value",
")",
"{",
"var",
"w",
"=",
"window",
",",
"d",
"=",
"document",
",",
"e",
"=",
"d",
".",
"documentElement",
",",
"g",
"=",
"d",
".",
"body",
",",
"x",
"=",
"w",
".",
"innerWidth",
"||",
"e",
".",
"clientWidth",
"||",
"g",
".",
"clientWidth",
",",
"y",
"=",
"w",
".",
"innerHeight",
"||",
"e",
".",
"clientHeight",
"||",
"g",
".",
"clientHeight",
";",
"if",
"(",
"type",
"===",
"'vw'",
")",
"{",
"return",
"(",
"x",
"*",
"parseFloat",
"(",
"value",
")",
")",
"/",
"100",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"'vh'",
")",
"{",
"return",
"(",
"y",
"*",
"parseFloat",
"(",
"value",
")",
")",
"/",
"100",
";",
"}",
"else",
"{",
"return",
"undefined",
";",
"}",
"}"
] | Converts vw or vh to PX | [
"Converts",
"vw",
"or",
"vh",
"to",
"PX"
] | 8578c4125ecf475f4cdbd412f13d8687e816cda5 | https://github.com/shobhitsharma/embedo/blob/8578c4125ecf475f4cdbd412f13d8687e816cda5/embedo.js#L589-L604 |
22,947 | shobhitsharma/embedo | embedo.js | percent_px | function percent_px(el, prop, percent) {
var parent_width = Embedo.utils.compute(el.parentNode, prop, true);
percent = parseFloat(percent);
return parent_width * (percent / 100);
} | javascript | function percent_px(el, prop, percent) {
var parent_width = Embedo.utils.compute(el.parentNode, prop, true);
percent = parseFloat(percent);
return parent_width * (percent / 100);
} | [
"function",
"percent_px",
"(",
"el",
",",
"prop",
",",
"percent",
")",
"{",
"var",
"parent_width",
"=",
"Embedo",
".",
"utils",
".",
"compute",
"(",
"el",
".",
"parentNode",
",",
"prop",
",",
"true",
")",
";",
"percent",
"=",
"parseFloat",
"(",
"percent",
")",
";",
"return",
"parent_width",
"*",
"(",
"percent",
"/",
"100",
")",
";",
"}"
] | Converts % to PX | [
"Converts",
"%",
"to",
"PX"
] | 8578c4125ecf475f4cdbd412f13d8687e816cda5 | https://github.com/shobhitsharma/embedo/blob/8578c4125ecf475f4cdbd412f13d8687e816cda5/embedo.js#L607-L611 |
22,948 | CMUI/CMUI | src/js/btn.js | _iniBtnWrapper | function _iniBtnWrapper() {
var $wrapper = gearbox.dom.$body || gearbox.dom.$root
$wrapper.on('click', function (ev) {
var $target = gearbox.$(ev.target)
if ($target.hasClass(CLS_BTN_WRAPPER) && !$target.hasClass(CLS_BTN_DISABLED)) {
var $btnWrapper = $target
var selBtn = ([].concat('.' + CLS_BTN, BTN_ELEM_TAGS)).join(', ')
var $btn = $btnWrapper.find(selBtn).first()
if (!$btn.hasClass(CLS_BTN_DISABLED)) {
$btn.trigger('click')
}
}
})
} | javascript | function _iniBtnWrapper() {
var $wrapper = gearbox.dom.$body || gearbox.dom.$root
$wrapper.on('click', function (ev) {
var $target = gearbox.$(ev.target)
if ($target.hasClass(CLS_BTN_WRAPPER) && !$target.hasClass(CLS_BTN_DISABLED)) {
var $btnWrapper = $target
var selBtn = ([].concat('.' + CLS_BTN, BTN_ELEM_TAGS)).join(', ')
var $btn = $btnWrapper.find(selBtn).first()
if (!$btn.hasClass(CLS_BTN_DISABLED)) {
$btn.trigger('click')
}
}
})
} | [
"function",
"_iniBtnWrapper",
"(",
")",
"{",
"var",
"$wrapper",
"=",
"gearbox",
".",
"dom",
".",
"$body",
"||",
"gearbox",
".",
"dom",
".",
"$root",
"$wrapper",
".",
"on",
"(",
"'click'",
",",
"function",
"(",
"ev",
")",
"{",
"var",
"$target",
"=",
"gearbox",
".",
"$",
"(",
"ev",
".",
"target",
")",
"if",
"(",
"$target",
".",
"hasClass",
"(",
"CLS_BTN_WRAPPER",
")",
"&&",
"!",
"$target",
".",
"hasClass",
"(",
"CLS_BTN_DISABLED",
")",
")",
"{",
"var",
"$btnWrapper",
"=",
"$target",
"var",
"selBtn",
"=",
"(",
"[",
"]",
".",
"concat",
"(",
"'.'",
"+",
"CLS_BTN",
",",
"BTN_ELEM_TAGS",
")",
")",
".",
"join",
"(",
"', '",
")",
"var",
"$btn",
"=",
"$btnWrapper",
".",
"find",
"(",
"selBtn",
")",
".",
"first",
"(",
")",
"if",
"(",
"!",
"$btn",
".",
"hasClass",
"(",
"CLS_BTN_DISABLED",
")",
")",
"{",
"$btn",
".",
"trigger",
"(",
"'click'",
")",
"}",
"}",
"}",
")",
"}"
] | util
if click on a btn wrapper, trigger `click` event on the btn inside of the wrapper
@private | [
"util",
"if",
"click",
"on",
"a",
"btn",
"wrapper",
"trigger",
"click",
"event",
"on",
"the",
"btn",
"inside",
"of",
"the",
"wrapper"
] | a0fd7f323bd2cf2f327ef6a5dc638e0b9e69a699 | https://github.com/CMUI/CMUI/blob/a0fd7f323bd2cf2f327ef6a5dc638e0b9e69a699/src/js/btn.js#L23-L36 |
22,949 | pimterry/server-components | src/index.js | renderNode | function renderNode(rootNode) {
let createdPromises = [];
var document = getDocument(rootNode);
recurseTree(rootNode, (foundNode) => {
if (foundNode.tagName) {
let nodeType = foundNode.tagName.toLowerCase();
let customElement = registeredElements[nodeType];
if (customElement) {
// TODO: Should probably clone node, not change prototype, for performance
Object.setPrototypeOf(foundNode, customElement);
if (customElement.createdCallback) {
createdPromises.push(new Promise((resolve) => {
resolve(customElement.createdCallback.call(foundNode, document));
}));
}
}
}
});
return Promise.all(createdPromises).then(() => rootNode);
} | javascript | function renderNode(rootNode) {
let createdPromises = [];
var document = getDocument(rootNode);
recurseTree(rootNode, (foundNode) => {
if (foundNode.tagName) {
let nodeType = foundNode.tagName.toLowerCase();
let customElement = registeredElements[nodeType];
if (customElement) {
// TODO: Should probably clone node, not change prototype, for performance
Object.setPrototypeOf(foundNode, customElement);
if (customElement.createdCallback) {
createdPromises.push(new Promise((resolve) => {
resolve(customElement.createdCallback.call(foundNode, document));
}));
}
}
}
});
return Promise.all(createdPromises).then(() => rootNode);
} | [
"function",
"renderNode",
"(",
"rootNode",
")",
"{",
"let",
"createdPromises",
"=",
"[",
"]",
";",
"var",
"document",
"=",
"getDocument",
"(",
"rootNode",
")",
";",
"recurseTree",
"(",
"rootNode",
",",
"(",
"foundNode",
")",
"=>",
"{",
"if",
"(",
"foundNode",
".",
"tagName",
")",
"{",
"let",
"nodeType",
"=",
"foundNode",
".",
"tagName",
".",
"toLowerCase",
"(",
")",
";",
"let",
"customElement",
"=",
"registeredElements",
"[",
"nodeType",
"]",
";",
"if",
"(",
"customElement",
")",
"{",
"// TODO: Should probably clone node, not change prototype, for performance",
"Object",
".",
"setPrototypeOf",
"(",
"foundNode",
",",
"customElement",
")",
";",
"if",
"(",
"customElement",
".",
"createdCallback",
")",
"{",
"createdPromises",
".",
"push",
"(",
"new",
"Promise",
"(",
"(",
"resolve",
")",
"=>",
"{",
"resolve",
"(",
"customElement",
".",
"createdCallback",
".",
"call",
"(",
"foundNode",
",",
"document",
")",
")",
";",
"}",
")",
")",
";",
"}",
"}",
"}",
"}",
")",
";",
"return",
"Promise",
".",
"all",
"(",
"createdPromises",
")",
".",
"then",
"(",
"(",
")",
"=>",
"rootNode",
")",
";",
"}"
] | Takes a full Domino node object. Traverses within it and renders all the custom elements found.
Returns a promise for the document object itself, resolved when every custom element has
resolved, and rejected if any of them are rejected. | [
"Takes",
"a",
"full",
"Domino",
"node",
"object",
".",
"Traverses",
"within",
"it",
"and",
"renders",
"all",
"the",
"custom",
"elements",
"found",
".",
"Returns",
"a",
"promise",
"for",
"the",
"document",
"object",
"itself",
"resolved",
"when",
"every",
"custom",
"element",
"has",
"resolved",
"and",
"rejected",
"if",
"any",
"of",
"them",
"are",
"rejected",
"."
] | c97a9f883db61490f35a1a9fc68316e3fa322e89 | https://github.com/pimterry/server-components/blob/c97a9f883db61490f35a1a9fc68316e3fa322e89/src/index.js#L88-L110 |
22,950 | MrMaxie/get-google-fonts | main.js | format | function format(template, values) {
return Object
.entries(values)
.filter(
([key]) => /^[a-z0-9_-]+$/gi.test(key)
)
.map(
([key, value]) =>
[new RegExp(`([^{]|^){${key}}([^}]|$)`,'g'), `$1${value}$2`]
)
.reduce(
(str, [regexp, replacement]) => {
return str.replace(regexp, replacement)
}, template
)
.replace(/({|}){2}/g, '$1')
} | javascript | function format(template, values) {
return Object
.entries(values)
.filter(
([key]) => /^[a-z0-9_-]+$/gi.test(key)
)
.map(
([key, value]) =>
[new RegExp(`([^{]|^){${key}}([^}]|$)`,'g'), `$1${value}$2`]
)
.reduce(
(str, [regexp, replacement]) => {
return str.replace(regexp, replacement)
}, template
)
.replace(/({|}){2}/g, '$1')
} | [
"function",
"format",
"(",
"template",
",",
"values",
")",
"{",
"return",
"Object",
".",
"entries",
"(",
"values",
")",
".",
"filter",
"(",
"(",
"[",
"key",
"]",
")",
"=>",
"/",
"^[a-z0-9_-]+$",
"/",
"gi",
".",
"test",
"(",
"key",
")",
")",
".",
"map",
"(",
"(",
"[",
"key",
",",
"value",
"]",
")",
"=>",
"[",
"new",
"RegExp",
"(",
"`",
"${",
"key",
"}",
"`",
",",
"'g'",
")",
",",
"`",
"${",
"value",
"}",
"`",
"]",
")",
".",
"reduce",
"(",
"(",
"str",
",",
"[",
"regexp",
",",
"replacement",
"]",
")",
"=>",
"{",
"return",
"str",
".",
"replace",
"(",
"regexp",
",",
"replacement",
")",
"}",
",",
"template",
")",
".",
"replace",
"(",
"/",
"({|}){2}",
"/",
"g",
",",
"'$1'",
")",
"}"
] | Replace in-string variables with their values from given object
@param {String} template
@param {Object} values
@return {String} | [
"Replace",
"in",
"-",
"string",
"variables",
"with",
"their",
"values",
"from",
"given",
"object"
] | 1f166b361773019d8b9145a8363b2089cfef905e | https://github.com/MrMaxie/get-google-fonts/blob/1f166b361773019d8b9145a8363b2089cfef905e/main.js#L41-L57 |
22,951 | MrMaxie/get-google-fonts | main.js | filterConfig | function filterConfig(config) {
return Object
.entries(config)
.filter(
([key, value]) =>
typeof value === typeof DEFAULT_CONFIG[key]
)
.reduce(
(obj, [key, value]) => {
obj[key] = value
return obj
}, {}
)
} | javascript | function filterConfig(config) {
return Object
.entries(config)
.filter(
([key, value]) =>
typeof value === typeof DEFAULT_CONFIG[key]
)
.reduce(
(obj, [key, value]) => {
obj[key] = value
return obj
}, {}
)
} | [
"function",
"filterConfig",
"(",
"config",
")",
"{",
"return",
"Object",
".",
"entries",
"(",
"config",
")",
".",
"filter",
"(",
"(",
"[",
"key",
",",
"value",
"]",
")",
"=>",
"typeof",
"value",
"===",
"typeof",
"DEFAULT_CONFIG",
"[",
"key",
"]",
")",
".",
"reduce",
"(",
"(",
"obj",
",",
"[",
"key",
",",
"value",
"]",
")",
"=>",
"{",
"obj",
"[",
"key",
"]",
"=",
"value",
"return",
"obj",
"}",
",",
"{",
"}",
")",
"}"
] | Allows to filter config object
@param {Object} config
@return {Object} | [
"Allows",
"to",
"filter",
"config",
"object"
] | 1f166b361773019d8b9145a8363b2089cfef905e | https://github.com/MrMaxie/get-google-fonts/blob/1f166b361773019d8b9145a8363b2089cfef905e/main.js#L63-L76 |
22,952 | MrMaxie/get-google-fonts | main.js | downloadString | function downloadString(url, {userAgent}) {
let deferred = Q.defer()
let startTime = Date.now()
let data = ''
request({
method: 'GET',
url: url,
headers: {
'User-Agent': userAgent
}
}, function(error, response, body) {
if(error) {
deferred.reject(new Error(error))
return;
}
deferred.resolve({
time: Date.now() - startTime,
result: body,
statusCode: response.statusCode
})
})
return deferred.promise
} | javascript | function downloadString(url, {userAgent}) {
let deferred = Q.defer()
let startTime = Date.now()
let data = ''
request({
method: 'GET',
url: url,
headers: {
'User-Agent': userAgent
}
}, function(error, response, body) {
if(error) {
deferred.reject(new Error(error))
return;
}
deferred.resolve({
time: Date.now() - startTime,
result: body,
statusCode: response.statusCode
})
})
return deferred.promise
} | [
"function",
"downloadString",
"(",
"url",
",",
"{",
"userAgent",
"}",
")",
"{",
"let",
"deferred",
"=",
"Q",
".",
"defer",
"(",
")",
"let",
"startTime",
"=",
"Date",
".",
"now",
"(",
")",
"let",
"data",
"=",
"''",
"request",
"(",
"{",
"method",
":",
"'GET'",
",",
"url",
":",
"url",
",",
"headers",
":",
"{",
"'User-Agent'",
":",
"userAgent",
"}",
"}",
",",
"function",
"(",
"error",
",",
"response",
",",
"body",
")",
"{",
"if",
"(",
"error",
")",
"{",
"deferred",
".",
"reject",
"(",
"new",
"Error",
"(",
"error",
")",
")",
"return",
";",
"}",
"deferred",
".",
"resolve",
"(",
"{",
"time",
":",
"Date",
".",
"now",
"(",
")",
"-",
"startTime",
",",
"result",
":",
"body",
",",
"statusCode",
":",
"response",
".",
"statusCode",
"}",
")",
"}",
")",
"return",
"deferred",
".",
"promise",
"}"
] | Download given url to string
@param {String} url
@return {Promise} | [
"Download",
"given",
"url",
"to",
"string"
] | 1f166b361773019d8b9145a8363b2089cfef905e | https://github.com/MrMaxie/get-google-fonts/blob/1f166b361773019d8b9145a8363b2089cfef905e/main.js#L82-L104 |
22,953 | MrMaxie/get-google-fonts | main.js | arrayFrom | function arrayFrom(arrayLike, delimiter=',') {
if(typeof arrayLike === 'string')
return arrayLike.split(delimiter)
return Array.from(arrayLike)
} | javascript | function arrayFrom(arrayLike, delimiter=',') {
if(typeof arrayLike === 'string')
return arrayLike.split(delimiter)
return Array.from(arrayLike)
} | [
"function",
"arrayFrom",
"(",
"arrayLike",
",",
"delimiter",
"=",
"','",
")",
"{",
"if",
"(",
"typeof",
"arrayLike",
"===",
"'string'",
")",
"return",
"arrayLike",
".",
"split",
"(",
"delimiter",
")",
"return",
"Array",
".",
"from",
"(",
"arrayLike",
")",
"}"
] | Array parser helper
@param {Mixed} arrayLike
@param {String} delimiter
@return {Array} | [
"Array",
"parser",
"helper"
] | 1f166b361773019d8b9145a8363b2089cfef905e | https://github.com/MrMaxie/get-google-fonts/blob/1f166b361773019d8b9145a8363b2089cfef905e/main.js#L111-L115 |
22,954 | MrMaxie/get-google-fonts | main.js | repairUrl | function repairUrl(url) {
return normalizeUrl(url
.replace(/&/gi, '&')
.replace(/</gi, '<')
.replace(/>/gi, '>')
.replace(/"/gi, '"')
.replace(/'/gi, '\'')
)
.trim()
.replace(/\s+/g,'+')
} | javascript | function repairUrl(url) {
return normalizeUrl(url
.replace(/&/gi, '&')
.replace(/</gi, '<')
.replace(/>/gi, '>')
.replace(/"/gi, '"')
.replace(/'/gi, '\'')
)
.trim()
.replace(/\s+/g,'+')
} | [
"function",
"repairUrl",
"(",
"url",
")",
"{",
"return",
"normalizeUrl",
"(",
"url",
".",
"replace",
"(",
"/",
"&",
"/",
"gi",
",",
"'&'",
")",
".",
"replace",
"(",
"/",
"<",
"/",
"gi",
",",
"'<'",
")",
".",
"replace",
"(",
"/",
">",
"/",
"gi",
",",
"'>'",
")",
".",
"replace",
"(",
"/",
""",
"/",
"gi",
",",
"'\"'",
")",
".",
"replace",
"(",
"/",
"'",
"/",
"gi",
",",
"'\\''",
")",
")",
".",
"trim",
"(",
")",
".",
"replace",
"(",
"/",
"\\s+",
"/",
"g",
",",
"'+'",
")",
"}"
] | Normalize given URL
@param {String} url
@return {String} | [
"Normalize",
"given",
"URL"
] | 1f166b361773019d8b9145a8363b2089cfef905e | https://github.com/MrMaxie/get-google-fonts/blob/1f166b361773019d8b9145a8363b2089cfef905e/main.js#L121-L131 |
22,955 | jonschlinkert/extend-shallow | benchmark/code/1-1-4.js | extend | function extend(o) {
if (typeOf(o) !== 'object') { return {}; }
var args = arguments;
var len = args.length - 1;
for (var i = 0; i < len; i++) {
var obj = args[i + 1];
if (typeOf(obj) === 'object' && typeOf(obj) !== 'regexp') {
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
o[key] = obj[key];
}
}
}
}
return o;
} | javascript | function extend(o) {
if (typeOf(o) !== 'object') { return {}; }
var args = arguments;
var len = args.length - 1;
for (var i = 0; i < len; i++) {
var obj = args[i + 1];
if (typeOf(obj) === 'object' && typeOf(obj) !== 'regexp') {
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
o[key] = obj[key];
}
}
}
}
return o;
} | [
"function",
"extend",
"(",
"o",
")",
"{",
"if",
"(",
"typeOf",
"(",
"o",
")",
"!==",
"'object'",
")",
"{",
"return",
"{",
"}",
";",
"}",
"var",
"args",
"=",
"arguments",
";",
"var",
"len",
"=",
"args",
".",
"length",
"-",
"1",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"var",
"obj",
"=",
"args",
"[",
"i",
"+",
"1",
"]",
";",
"if",
"(",
"typeOf",
"(",
"obj",
")",
"===",
"'object'",
"&&",
"typeOf",
"(",
"obj",
")",
"!==",
"'regexp'",
")",
"{",
"for",
"(",
"var",
"key",
"in",
"obj",
")",
"{",
"if",
"(",
"obj",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"o",
"[",
"key",
"]",
"=",
"obj",
"[",
"key",
"]",
";",
"}",
"}",
"}",
"}",
"return",
"o",
";",
"}"
] | Extend `o` with properties of other `objects`.
@param {Object} `o` The target object. Pass an empty object to shallow clone.
@param {Object} `objects`
@return {Object} | [
"Extend",
"o",
"with",
"properties",
"of",
"other",
"objects",
"."
] | 33698c3df7804f0d0e3ea98caa64d53f09c37bd4 | https://github.com/jonschlinkert/extend-shallow/blob/33698c3df7804f0d0e3ea98caa64d53f09c37bd4/benchmark/code/1-1-4.js#L19-L36 |
22,956 | andyearnshaw/rollup-plugin-bundle-worker | src/index.js | function (id) {
if (!paths.has(id)) {
return;
}
var code = [
`import shimWorker from 'rollup-plugin-bundle-worker';`,
`export default new shimWorker(${JSON.stringify(paths.get(id))}, function (window, document) {`,
`var self = this;`,
fs.readFileSync(id, 'utf-8'),
`\n});`
].join('\n');
return code;
} | javascript | function (id) {
if (!paths.has(id)) {
return;
}
var code = [
`import shimWorker from 'rollup-plugin-bundle-worker';`,
`export default new shimWorker(${JSON.stringify(paths.get(id))}, function (window, document) {`,
`var self = this;`,
fs.readFileSync(id, 'utf-8'),
`\n});`
].join('\n');
return code;
} | [
"function",
"(",
"id",
")",
"{",
"if",
"(",
"!",
"paths",
".",
"has",
"(",
"id",
")",
")",
"{",
"return",
";",
"}",
"var",
"code",
"=",
"[",
"`",
"`",
",",
"`",
"${",
"JSON",
".",
"stringify",
"(",
"paths",
".",
"get",
"(",
"id",
")",
")",
"}",
"`",
",",
"`",
"`",
",",
"fs",
".",
"readFileSync",
"(",
"id",
",",
"'utf-8'",
")",
",",
"`",
"\\n",
"`",
"]",
".",
"join",
"(",
"'\\n'",
")",
";",
"return",
"code",
";",
"}"
] | Do everything in load so that code loaded by the plugin can still be transformed by the
rollup configuration | [
"Do",
"everything",
"in",
"load",
"so",
"that",
"code",
"loaded",
"by",
"the",
"plugin",
"can",
"still",
"be",
"transformed",
"by",
"the",
"rollup",
"configuration"
] | 1c92add8aa3ebc590ebd258fc644ed147fab3d79 | https://github.com/andyearnshaw/rollup-plugin-bundle-worker/blob/1c92add8aa3ebc590ebd258fc644ed147fab3d79/src/index.js#L24-L38 | |
22,957 | zgreen/postcss-critical-css | lib/atRule.js | getCriticalFromAtRule | function getCriticalFromAtRule(args) {
var result = {};
var options = _extends({
defaultDest: 'critical.css',
css: _postcss2.default.root()
}, args);
options.css.walkAtRules('critical', function (atRule) {
var name = atRule.params ? atRule.params : options.defaultDest;
// If rule has no nodes, all the nodes of the parent will be critical.
var rule = atRule;
if (!atRule.nodes) {
rule = atRule.root();
}
rule.clone().each(function (node) {
if (node.name !== 'critical') {
result[name] = result[name] ? result[name].append(node) : _postcss2.default.root().append(node);
}
});
});
return result;
} | javascript | function getCriticalFromAtRule(args) {
var result = {};
var options = _extends({
defaultDest: 'critical.css',
css: _postcss2.default.root()
}, args);
options.css.walkAtRules('critical', function (atRule) {
var name = atRule.params ? atRule.params : options.defaultDest;
// If rule has no nodes, all the nodes of the parent will be critical.
var rule = atRule;
if (!atRule.nodes) {
rule = atRule.root();
}
rule.clone().each(function (node) {
if (node.name !== 'critical') {
result[name] = result[name] ? result[name].append(node) : _postcss2.default.root().append(node);
}
});
});
return result;
} | [
"function",
"getCriticalFromAtRule",
"(",
"args",
")",
"{",
"var",
"result",
"=",
"{",
"}",
";",
"var",
"options",
"=",
"_extends",
"(",
"{",
"defaultDest",
":",
"'critical.css'",
",",
"css",
":",
"_postcss2",
".",
"default",
".",
"root",
"(",
")",
"}",
",",
"args",
")",
";",
"options",
".",
"css",
".",
"walkAtRules",
"(",
"'critical'",
",",
"function",
"(",
"atRule",
")",
"{",
"var",
"name",
"=",
"atRule",
".",
"params",
"?",
"atRule",
".",
"params",
":",
"options",
".",
"defaultDest",
";",
"// If rule has no nodes, all the nodes of the parent will be critical.",
"var",
"rule",
"=",
"atRule",
";",
"if",
"(",
"!",
"atRule",
".",
"nodes",
")",
"{",
"rule",
"=",
"atRule",
".",
"root",
"(",
")",
";",
"}",
"rule",
".",
"clone",
"(",
")",
".",
"each",
"(",
"function",
"(",
"node",
")",
"{",
"if",
"(",
"node",
".",
"name",
"!==",
"'critical'",
")",
"{",
"result",
"[",
"name",
"]",
"=",
"result",
"[",
"name",
"]",
"?",
"result",
"[",
"name",
"]",
".",
"append",
"(",
"node",
")",
":",
"_postcss2",
".",
"default",
".",
"root",
"(",
")",
".",
"append",
"(",
"node",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"return",
"result",
";",
"}"
] | Get critical CSS from an at-rule.
@param {Object} args Function args. See flow type alias. | [
"Get",
"critical",
"CSS",
"from",
"an",
"at",
"-",
"rule",
"."
] | 33bed8bc678dd3f66b8b114414804dbe284ab672 | https://github.com/zgreen/postcss-critical-css/blob/33bed8bc678dd3f66b8b114414804dbe284ab672/lib/atRule.js#L22-L43 |
22,958 | zgreen/postcss-critical-css | lib/index.js | dryRunOrWriteFile | function dryRunOrWriteFile(dryRun, filePath, result) {
var css = result.css;
return new Promise(function (resolve) {
return resolve(dryRun ? doDryRun(css) : writeCriticalFile(filePath, css));
});
} | javascript | function dryRunOrWriteFile(dryRun, filePath, result) {
var css = result.css;
return new Promise(function (resolve) {
return resolve(dryRun ? doDryRun(css) : writeCriticalFile(filePath, css));
});
} | [
"function",
"dryRunOrWriteFile",
"(",
"dryRun",
",",
"filePath",
",",
"result",
")",
"{",
"var",
"css",
"=",
"result",
".",
"css",
";",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
")",
"{",
"return",
"resolve",
"(",
"dryRun",
"?",
"doDryRun",
"(",
"css",
")",
":",
"writeCriticalFile",
"(",
"filePath",
",",
"css",
")",
")",
";",
"}",
")",
";",
"}"
] | Do a dry run, or write a file.
@param {bool} dryRun Do a dry run?
@param {string} filePath Path to write file to.
@param {Object} result PostCSS root object.
@return {Promise} Resolves with writeCriticalFile or doDryRun function call. | [
"Do",
"a",
"dry",
"run",
"or",
"write",
"a",
"file",
"."
] | 33bed8bc678dd3f66b8b114414804dbe284ab672 | https://github.com/zgreen/postcss-critical-css/blob/33bed8bc678dd3f66b8b114414804dbe284ab672/lib/index.js#L106-L112 |
22,959 | zgreen/postcss-critical-css | lib/index.js | hasNoOtherChildNodes | function hasNoOtherChildNodes() {
var nodes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
var node = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _postcss2.default.root();
return nodes.filter(function (child) {
return child !== node;
}).length === 0;
} | javascript | function hasNoOtherChildNodes() {
var nodes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
var node = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _postcss2.default.root();
return nodes.filter(function (child) {
return child !== node;
}).length === 0;
} | [
"function",
"hasNoOtherChildNodes",
"(",
")",
"{",
"var",
"nodes",
"=",
"arguments",
".",
"length",
">",
"0",
"&&",
"arguments",
"[",
"0",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"0",
"]",
":",
"[",
"]",
";",
"var",
"node",
"=",
"arguments",
".",
"length",
">",
"1",
"&&",
"arguments",
"[",
"1",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"1",
"]",
":",
"_postcss2",
".",
"default",
".",
"root",
"(",
")",
";",
"return",
"nodes",
".",
"filter",
"(",
"function",
"(",
"child",
")",
"{",
"return",
"child",
"!==",
"node",
";",
"}",
")",
".",
"length",
"===",
"0",
";",
"}"
] | Confirm a node has no child nodes other than a specific node.
@param {array} nodes Nodes array to check.
@param {Object} node Node to check.
@return {boolean} Whether or not the node has no other children. | [
"Confirm",
"a",
"node",
"has",
"no",
"child",
"nodes",
"other",
"than",
"a",
"specific",
"node",
"."
] | 33bed8bc678dd3f66b8b114414804dbe284ab672 | https://github.com/zgreen/postcss-critical-css/blob/33bed8bc678dd3f66b8b114414804dbe284ab672/lib/index.js#L121-L128 |
22,960 | zgreen/postcss-critical-css | lib/index.js | writeCriticalFile | function writeCriticalFile(filePath, css) {
_fs2.default.writeFile(filePath, css, { flag: append ? 'a' : 'w' }, function (err) {
append = true;
if (err) {
console.error(err);
process.exit(1);
}
});
} | javascript | function writeCriticalFile(filePath, css) {
_fs2.default.writeFile(filePath, css, { flag: append ? 'a' : 'w' }, function (err) {
append = true;
if (err) {
console.error(err);
process.exit(1);
}
});
} | [
"function",
"writeCriticalFile",
"(",
"filePath",
",",
"css",
")",
"{",
"_fs2",
".",
"default",
".",
"writeFile",
"(",
"filePath",
",",
"css",
",",
"{",
"flag",
":",
"append",
"?",
"'a'",
":",
"'w'",
"}",
",",
"function",
"(",
"err",
")",
"{",
"append",
"=",
"true",
";",
"if",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"err",
")",
";",
"process",
".",
"exit",
"(",
"1",
")",
";",
"}",
"}",
")",
";",
"}"
] | Write a file containing critical CSS.
@param {string} filePath Path to write file to.
@param {string} css CSS to write to file. | [
"Write",
"a",
"file",
"containing",
"critical",
"CSS",
"."
] | 33bed8bc678dd3f66b8b114414804dbe284ab672 | https://github.com/zgreen/postcss-critical-css/blob/33bed8bc678dd3f66b8b114414804dbe284ab672/lib/index.js#L136-L144 |
22,961 | zgreen/postcss-critical-css | lib/index.js | buildCritical | function buildCritical() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var filteredOptions = Object.keys(options).reduce(function (acc, key) {
return typeof options[key] !== 'undefined' ? _extends({}, acc, _defineProperty({}, key, options[key])) : acc;
}, {});
var args = _extends({
outputPath: process.cwd(),
outputDest: 'critical.css',
preserve: true,
minify: true,
dryRun: false
}, filteredOptions);
append = false;
return function (css) {
var dryRun = args.dryRun,
preserve = args.preserve,
minify = args.minify,
outputPath = args.outputPath,
outputDest = args.outputDest;
var criticalOutput = (0, _getCriticalRules.getCriticalRules)(css, outputDest);
return Object.keys(criticalOutput).reduce(function (init, cur) {
var criticalCSS = _postcss2.default.root();
var filePath = _path2.default.join(outputPath, cur);
criticalOutput[cur].each(function (rule) {
return criticalCSS.append(rule.clone());
});
return (0, _postcss2.default)(minify ? [_cssnano2.default] : [])
// @TODO Use from/to correctly.
.process(criticalCSS, {
from: undefined
}).then(dryRunOrWriteFile.bind(null, dryRun, filePath)).then(clean.bind(null, css, preserve));
}, {});
};
} | javascript | function buildCritical() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var filteredOptions = Object.keys(options).reduce(function (acc, key) {
return typeof options[key] !== 'undefined' ? _extends({}, acc, _defineProperty({}, key, options[key])) : acc;
}, {});
var args = _extends({
outputPath: process.cwd(),
outputDest: 'critical.css',
preserve: true,
minify: true,
dryRun: false
}, filteredOptions);
append = false;
return function (css) {
var dryRun = args.dryRun,
preserve = args.preserve,
minify = args.minify,
outputPath = args.outputPath,
outputDest = args.outputDest;
var criticalOutput = (0, _getCriticalRules.getCriticalRules)(css, outputDest);
return Object.keys(criticalOutput).reduce(function (init, cur) {
var criticalCSS = _postcss2.default.root();
var filePath = _path2.default.join(outputPath, cur);
criticalOutput[cur].each(function (rule) {
return criticalCSS.append(rule.clone());
});
return (0, _postcss2.default)(minify ? [_cssnano2.default] : [])
// @TODO Use from/to correctly.
.process(criticalCSS, {
from: undefined
}).then(dryRunOrWriteFile.bind(null, dryRun, filePath)).then(clean.bind(null, css, preserve));
}, {});
};
} | [
"function",
"buildCritical",
"(",
")",
"{",
"var",
"options",
"=",
"arguments",
".",
"length",
">",
"0",
"&&",
"arguments",
"[",
"0",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"0",
"]",
":",
"{",
"}",
";",
"var",
"filteredOptions",
"=",
"Object",
".",
"keys",
"(",
"options",
")",
".",
"reduce",
"(",
"function",
"(",
"acc",
",",
"key",
")",
"{",
"return",
"typeof",
"options",
"[",
"key",
"]",
"!==",
"'undefined'",
"?",
"_extends",
"(",
"{",
"}",
",",
"acc",
",",
"_defineProperty",
"(",
"{",
"}",
",",
"key",
",",
"options",
"[",
"key",
"]",
")",
")",
":",
"acc",
";",
"}",
",",
"{",
"}",
")",
";",
"var",
"args",
"=",
"_extends",
"(",
"{",
"outputPath",
":",
"process",
".",
"cwd",
"(",
")",
",",
"outputDest",
":",
"'critical.css'",
",",
"preserve",
":",
"true",
",",
"minify",
":",
"true",
",",
"dryRun",
":",
"false",
"}",
",",
"filteredOptions",
")",
";",
"append",
"=",
"false",
";",
"return",
"function",
"(",
"css",
")",
"{",
"var",
"dryRun",
"=",
"args",
".",
"dryRun",
",",
"preserve",
"=",
"args",
".",
"preserve",
",",
"minify",
"=",
"args",
".",
"minify",
",",
"outputPath",
"=",
"args",
".",
"outputPath",
",",
"outputDest",
"=",
"args",
".",
"outputDest",
";",
"var",
"criticalOutput",
"=",
"(",
"0",
",",
"_getCriticalRules",
".",
"getCriticalRules",
")",
"(",
"css",
",",
"outputDest",
")",
";",
"return",
"Object",
".",
"keys",
"(",
"criticalOutput",
")",
".",
"reduce",
"(",
"function",
"(",
"init",
",",
"cur",
")",
"{",
"var",
"criticalCSS",
"=",
"_postcss2",
".",
"default",
".",
"root",
"(",
")",
";",
"var",
"filePath",
"=",
"_path2",
".",
"default",
".",
"join",
"(",
"outputPath",
",",
"cur",
")",
";",
"criticalOutput",
"[",
"cur",
"]",
".",
"each",
"(",
"function",
"(",
"rule",
")",
"{",
"return",
"criticalCSS",
".",
"append",
"(",
"rule",
".",
"clone",
"(",
")",
")",
";",
"}",
")",
";",
"return",
"(",
"0",
",",
"_postcss2",
".",
"default",
")",
"(",
"minify",
"?",
"[",
"_cssnano2",
".",
"default",
"]",
":",
"[",
"]",
")",
"// @TODO Use from/to correctly.",
".",
"process",
"(",
"criticalCSS",
",",
"{",
"from",
":",
"undefined",
"}",
")",
".",
"then",
"(",
"dryRunOrWriteFile",
".",
"bind",
"(",
"null",
",",
"dryRun",
",",
"filePath",
")",
")",
".",
"then",
"(",
"clean",
".",
"bind",
"(",
"null",
",",
"css",
",",
"preserve",
")",
")",
";",
"}",
",",
"{",
"}",
")",
";",
"}",
";",
"}"
] | Primary plugin function.
@param {object} options Object of function args.
@return {function} function for PostCSS plugin. | [
"Primary",
"plugin",
"function",
"."
] | 33bed8bc678dd3f66b8b114414804dbe284ab672 | https://github.com/zgreen/postcss-critical-css/blob/33bed8bc678dd3f66b8b114414804dbe284ab672/lib/index.js#L152-L187 |
22,962 | zgreen/postcss-critical-css | lib/getCriticalRules.js | clean | function clean(root) {
var test = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'critical-selector';
var clone = root.clone();
if (clone.type === 'decl') {
clone.remove();
} else {
clone.walkDecls(test, function (decl) {
decl.remove();
});
}
return clone;
} | javascript | function clean(root) {
var test = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'critical-selector';
var clone = root.clone();
if (clone.type === 'decl') {
clone.remove();
} else {
clone.walkDecls(test, function (decl) {
decl.remove();
});
}
return clone;
} | [
"function",
"clean",
"(",
"root",
")",
"{",
"var",
"test",
"=",
"arguments",
".",
"length",
">",
"1",
"&&",
"arguments",
"[",
"1",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"1",
"]",
":",
"'critical-selector'",
";",
"var",
"clone",
"=",
"root",
".",
"clone",
"(",
")",
";",
"if",
"(",
"clone",
".",
"type",
"===",
"'decl'",
")",
"{",
"clone",
".",
"remove",
"(",
")",
";",
"}",
"else",
"{",
"clone",
".",
"walkDecls",
"(",
"test",
",",
"function",
"(",
"decl",
")",
"{",
"decl",
".",
"remove",
"(",
")",
";",
"}",
")",
";",
"}",
"return",
"clone",
";",
"}"
] | Clean a root node of a declaration.
@param {Object} root PostCSS root node.
@param {string} test Declaration string. Default `critical-selector`
@return {Object} clone Cloned, cleaned root node. | [
"Clean",
"a",
"root",
"node",
"of",
"a",
"declaration",
"."
] | 33bed8bc678dd3f66b8b114414804dbe284ab672 | https://github.com/zgreen/postcss-critical-css/blob/33bed8bc678dd3f66b8b114414804dbe284ab672/lib/getCriticalRules.js#L27-L39 |
22,963 | zgreen/postcss-critical-css | lib/getCriticalRules.js | correctSourceOrder | function correctSourceOrder(root) {
var sortedRoot = _postcss2.default.root();
var clone = root.clone();
clone.walkRules(function (rule) {
var start = rule.source.start.line;
if (rule.parent.type === 'atrule') {
var child = rule;
rule = _postcss2.default.atRule({
name: rule.parent.name,
params: rule.parent.params
}).append(rule.clone());
rule.source = child.source;
start = child.source.start.line;
}
if (sortedRoot.nodes.length === 0 || sortedRoot.last && sortedRoot.last.source.start.line > start) {
sortedRoot.prepend(rule);
} else {
sortedRoot.append(rule);
}
});
return sortedRoot;
} | javascript | function correctSourceOrder(root) {
var sortedRoot = _postcss2.default.root();
var clone = root.clone();
clone.walkRules(function (rule) {
var start = rule.source.start.line;
if (rule.parent.type === 'atrule') {
var child = rule;
rule = _postcss2.default.atRule({
name: rule.parent.name,
params: rule.parent.params
}).append(rule.clone());
rule.source = child.source;
start = child.source.start.line;
}
if (sortedRoot.nodes.length === 0 || sortedRoot.last && sortedRoot.last.source.start.line > start) {
sortedRoot.prepend(rule);
} else {
sortedRoot.append(rule);
}
});
return sortedRoot;
} | [
"function",
"correctSourceOrder",
"(",
"root",
")",
"{",
"var",
"sortedRoot",
"=",
"_postcss2",
".",
"default",
".",
"root",
"(",
")",
";",
"var",
"clone",
"=",
"root",
".",
"clone",
"(",
")",
";",
"clone",
".",
"walkRules",
"(",
"function",
"(",
"rule",
")",
"{",
"var",
"start",
"=",
"rule",
".",
"source",
".",
"start",
".",
"line",
";",
"if",
"(",
"rule",
".",
"parent",
".",
"type",
"===",
"'atrule'",
")",
"{",
"var",
"child",
"=",
"rule",
";",
"rule",
"=",
"_postcss2",
".",
"default",
".",
"atRule",
"(",
"{",
"name",
":",
"rule",
".",
"parent",
".",
"name",
",",
"params",
":",
"rule",
".",
"parent",
".",
"params",
"}",
")",
".",
"append",
"(",
"rule",
".",
"clone",
"(",
")",
")",
";",
"rule",
".",
"source",
"=",
"child",
".",
"source",
";",
"start",
"=",
"child",
".",
"source",
".",
"start",
".",
"line",
";",
"}",
"if",
"(",
"sortedRoot",
".",
"nodes",
".",
"length",
"===",
"0",
"||",
"sortedRoot",
".",
"last",
"&&",
"sortedRoot",
".",
"last",
".",
"source",
".",
"start",
".",
"line",
">",
"start",
")",
"{",
"sortedRoot",
".",
"prepend",
"(",
"rule",
")",
";",
"}",
"else",
"{",
"sortedRoot",
".",
"append",
"(",
"rule",
")",
";",
"}",
"}",
")",
";",
"return",
"sortedRoot",
";",
"}"
] | Correct the source order of nodes in a root.
@param {Object} root PostCSS root node.
@return {Object} sortedRoot Root with nodes sorted by source order. | [
"Correct",
"the",
"source",
"order",
"of",
"nodes",
"in",
"a",
"root",
"."
] | 33bed8bc678dd3f66b8b114414804dbe284ab672 | https://github.com/zgreen/postcss-critical-css/blob/33bed8bc678dd3f66b8b114414804dbe284ab672/lib/getCriticalRules.js#L47-L68 |
22,964 | zgreen/postcss-critical-css | lib/getCriticalRules.js | establishContainer | function establishContainer(node) {
return node.parent.type === 'atrule' && node.parent.name !== 'critical' ? _postcss2.default.atRule({
name: node.parent.name,
type: node.parent.type,
params: node.parent.params,
nodes: [node]
}) : node.clone();
} | javascript | function establishContainer(node) {
return node.parent.type === 'atrule' && node.parent.name !== 'critical' ? _postcss2.default.atRule({
name: node.parent.name,
type: node.parent.type,
params: node.parent.params,
nodes: [node]
}) : node.clone();
} | [
"function",
"establishContainer",
"(",
"node",
")",
"{",
"return",
"node",
".",
"parent",
".",
"type",
"===",
"'atrule'",
"&&",
"node",
".",
"parent",
".",
"name",
"!==",
"'critical'",
"?",
"_postcss2",
".",
"default",
".",
"atRule",
"(",
"{",
"name",
":",
"node",
".",
"parent",
".",
"name",
",",
"type",
":",
"node",
".",
"parent",
".",
"type",
",",
"params",
":",
"node",
".",
"parent",
".",
"params",
",",
"nodes",
":",
"[",
"node",
"]",
"}",
")",
":",
"node",
".",
"clone",
"(",
")",
";",
"}"
] | Establish the container of a given node. Useful when preserving media queries
or other atrules.
@param {Object} node PostCSS node.
@return {Object} A new root node with an atrule at its base. | [
"Establish",
"the",
"container",
"of",
"a",
"given",
"node",
".",
"Useful",
"when",
"preserving",
"media",
"queries",
"or",
"other",
"atrules",
"."
] | 33bed8bc678dd3f66b8b114414804dbe284ab672 | https://github.com/zgreen/postcss-critical-css/blob/33bed8bc678dd3f66b8b114414804dbe284ab672/lib/getCriticalRules.js#L77-L84 |
22,965 | zgreen/postcss-critical-css | lib/getCriticalRules.js | updateCritical | function updateCritical(root, update) {
var clonedRoot = root.clone();
if (update.type === 'rule') {
clonedRoot.append(clean(update.clone()));
} else {
update.clone().each(function (rule) {
clonedRoot.append(clean(rule.root()));
});
}
return clonedRoot;
} | javascript | function updateCritical(root, update) {
var clonedRoot = root.clone();
if (update.type === 'rule') {
clonedRoot.append(clean(update.clone()));
} else {
update.clone().each(function (rule) {
clonedRoot.append(clean(rule.root()));
});
}
return clonedRoot;
} | [
"function",
"updateCritical",
"(",
"root",
",",
"update",
")",
"{",
"var",
"clonedRoot",
"=",
"root",
".",
"clone",
"(",
")",
";",
"if",
"(",
"update",
".",
"type",
"===",
"'rule'",
")",
"{",
"clonedRoot",
".",
"append",
"(",
"clean",
"(",
"update",
".",
"clone",
"(",
")",
")",
")",
";",
"}",
"else",
"{",
"update",
".",
"clone",
"(",
")",
".",
"each",
"(",
"function",
"(",
"rule",
")",
"{",
"clonedRoot",
".",
"append",
"(",
"clean",
"(",
"rule",
".",
"root",
"(",
")",
")",
")",
";",
"}",
")",
";",
"}",
"return",
"clonedRoot",
";",
"}"
] | Update a critical root.
@param {Object} root Root object to update.
@param {Object} update Update object.
@return {Object} clonedRoot Root object. | [
"Update",
"a",
"critical",
"root",
"."
] | 33bed8bc678dd3f66b8b114414804dbe284ab672 | https://github.com/zgreen/postcss-critical-css/blob/33bed8bc678dd3f66b8b114414804dbe284ab672/lib/getCriticalRules.js#L93-L103 |
22,966 | zgreen/postcss-critical-css | lib/getCriticalDestination.js | getCriticalDestination | function getCriticalDestination(rule, dest) {
rule.walkDecls('critical-filename', function (decl) {
dest = decl.value.replace(/['"]*/g, '');
decl.remove();
});
return dest;
} | javascript | function getCriticalDestination(rule, dest) {
rule.walkDecls('critical-filename', function (decl) {
dest = decl.value.replace(/['"]*/g, '');
decl.remove();
});
return dest;
} | [
"function",
"getCriticalDestination",
"(",
"rule",
",",
"dest",
")",
"{",
"rule",
".",
"walkDecls",
"(",
"'critical-filename'",
",",
"function",
"(",
"decl",
")",
"{",
"dest",
"=",
"decl",
".",
"value",
".",
"replace",
"(",
"/",
"['\"]*",
"/",
"g",
",",
"''",
")",
";",
"decl",
".",
"remove",
"(",
")",
";",
"}",
")",
";",
"return",
"dest",
";",
"}"
] | Identify critical CSS destinations.
@param {object} rule PostCSS rule.
@param {string} Default output CSS file name.
@return {string} String corresponding to output destination. | [
"Identify",
"critical",
"CSS",
"destinations",
"."
] | 33bed8bc678dd3f66b8b114414804dbe284ab672 | https://github.com/zgreen/postcss-critical-css/blob/33bed8bc678dd3f66b8b114414804dbe284ab672/lib/getCriticalDestination.js#L16-L22 |
22,967 | jridgewell/babel-plugin-transform-incremental-dom | src/helpers/runtime/spread-attribute.js | spreadAttributeAST | function spreadAttributeAST(plugin, ref, deps) {
const { hasOwn } = deps;
const spread = t.identifier("spread");
const prop = t.identifier("prop");
/**
* function _spreadAttribute(spread) {
* for (var prop in spread) {
* if (_hasOwn.call(spread, prop)) {
* attr(prop, spread[prop]);
* }
* }
* }
*/
return t.functionExpression(
ref,
[spread],
t.blockStatement([
t.forInStatement(
t.variableDeclaration("var", [t.variableDeclarator(prop)]),
spread,
t.ifStatement(
toFunctionCall(t.memberExpression(
hasOwn,
t.identifier("call")
), [spread, prop]),
t.expressionStatement(toFunctionCall(iDOMMethod("attr", plugin), [
prop,
t.memberExpression(spread, prop, true)
]))
)
)
])
);
} | javascript | function spreadAttributeAST(plugin, ref, deps) {
const { hasOwn } = deps;
const spread = t.identifier("spread");
const prop = t.identifier("prop");
/**
* function _spreadAttribute(spread) {
* for (var prop in spread) {
* if (_hasOwn.call(spread, prop)) {
* attr(prop, spread[prop]);
* }
* }
* }
*/
return t.functionExpression(
ref,
[spread],
t.blockStatement([
t.forInStatement(
t.variableDeclaration("var", [t.variableDeclarator(prop)]),
spread,
t.ifStatement(
toFunctionCall(t.memberExpression(
hasOwn,
t.identifier("call")
), [spread, prop]),
t.expressionStatement(toFunctionCall(iDOMMethod("attr", plugin), [
prop,
t.memberExpression(spread, prop, true)
]))
)
)
])
);
} | [
"function",
"spreadAttributeAST",
"(",
"plugin",
",",
"ref",
",",
"deps",
")",
"{",
"const",
"{",
"hasOwn",
"}",
"=",
"deps",
";",
"const",
"spread",
"=",
"t",
".",
"identifier",
"(",
"\"spread\"",
")",
";",
"const",
"prop",
"=",
"t",
".",
"identifier",
"(",
"\"prop\"",
")",
";",
"/**\n * function _spreadAttribute(spread) {\n * for (var prop in spread) {\n * if (_hasOwn.call(spread, prop)) {\n * attr(prop, spread[prop]);\n * }\n * }\n * }\n */",
"return",
"t",
".",
"functionExpression",
"(",
"ref",
",",
"[",
"spread",
"]",
",",
"t",
".",
"blockStatement",
"(",
"[",
"t",
".",
"forInStatement",
"(",
"t",
".",
"variableDeclaration",
"(",
"\"var\"",
",",
"[",
"t",
".",
"variableDeclarator",
"(",
"prop",
")",
"]",
")",
",",
"spread",
",",
"t",
".",
"ifStatement",
"(",
"toFunctionCall",
"(",
"t",
".",
"memberExpression",
"(",
"hasOwn",
",",
"t",
".",
"identifier",
"(",
"\"call\"",
")",
")",
",",
"[",
"spread",
",",
"prop",
"]",
")",
",",
"t",
".",
"expressionStatement",
"(",
"toFunctionCall",
"(",
"iDOMMethod",
"(",
"\"attr\"",
",",
"plugin",
")",
",",
"[",
"prop",
",",
"t",
".",
"memberExpression",
"(",
"spread",
",",
"prop",
",",
"true",
")",
"]",
")",
")",
")",
")",
"]",
")",
")",
";",
"}"
] | Iterates over a SpreadAttribute, assigning each property as an attribute on the element. | [
"Iterates",
"over",
"a",
"SpreadAttribute",
"assigning",
"each",
"property",
"as",
"an",
"attribute",
"on",
"the",
"element",
"."
] | 4ee2b244c0876338b6a7b6f2d6bae210712f8894 | https://github.com/jridgewell/babel-plugin-transform-incremental-dom/blob/4ee2b244c0876338b6a7b6f2d6bae210712f8894/src/helpers/runtime/spread-attribute.js#L9-L43 |
22,968 | jridgewell/babel-plugin-transform-incremental-dom | src/helpers/root-jsx.js | inPatchRoot | function inPatchRoot(path, plugin) {
const { opts } = plugin;
if (useFastRoot(path, opts)) {
return true;
}
const roots = patchRoots(plugin)
return !roots.length || path.findParent((parent) => {
return roots.indexOf(parent) > -1;
});
} | javascript | function inPatchRoot(path, plugin) {
const { opts } = plugin;
if (useFastRoot(path, opts)) {
return true;
}
const roots = patchRoots(plugin)
return !roots.length || path.findParent((parent) => {
return roots.indexOf(parent) > -1;
});
} | [
"function",
"inPatchRoot",
"(",
"path",
",",
"plugin",
")",
"{",
"const",
"{",
"opts",
"}",
"=",
"plugin",
";",
"if",
"(",
"useFastRoot",
"(",
"path",
",",
"opts",
")",
")",
"{",
"return",
"true",
";",
"}",
"const",
"roots",
"=",
"patchRoots",
"(",
"plugin",
")",
"return",
"!",
"roots",
".",
"length",
"||",
"path",
".",
"findParent",
"(",
"(",
"parent",
")",
"=>",
"{",
"return",
"roots",
".",
"indexOf",
"(",
"parent",
")",
">",
"-",
"1",
";",
"}",
")",
";",
"}"
] | Determines if the JSX element is nested inside a patch's rendering function. | [
"Determines",
"if",
"the",
"JSX",
"element",
"is",
"nested",
"inside",
"a",
"patch",
"s",
"rendering",
"function",
"."
] | 4ee2b244c0876338b6a7b6f2d6bae210712f8894 | https://github.com/jridgewell/babel-plugin-transform-incremental-dom/blob/4ee2b244c0876338b6a7b6f2d6bae210712f8894/src/helpers/root-jsx.js#L23-L33 |
22,969 | jridgewell/babel-plugin-transform-incremental-dom | src/helpers/runtime/render-arbitrary.js | isArray | function isArray(value) {
return toFunctionCall(
t.memberExpression(
t.identifier("Array"),
t.identifier("isArray")
),
[value]
);
} | javascript | function isArray(value) {
return toFunctionCall(
t.memberExpression(
t.identifier("Array"),
t.identifier("isArray")
),
[value]
);
} | [
"function",
"isArray",
"(",
"value",
")",
"{",
"return",
"toFunctionCall",
"(",
"t",
".",
"memberExpression",
"(",
"t",
".",
"identifier",
"(",
"\"Array\"",
")",
",",
"t",
".",
"identifier",
"(",
"\"isArray\"",
")",
")",
",",
"[",
"value",
"]",
")",
";",
"}"
] | Isolated AST code to determine if a value an Array. | [
"Isolated",
"AST",
"code",
"to",
"determine",
"if",
"a",
"value",
"an",
"Array",
"."
] | 4ee2b244c0876338b6a7b6f2d6bae210712f8894 | https://github.com/jridgewell/babel-plugin-transform-incremental-dom/blob/4ee2b244c0876338b6a7b6f2d6bae210712f8894/src/helpers/runtime/render-arbitrary.js#L26-L34 |
22,970 | jridgewell/babel-plugin-transform-incremental-dom | src/helpers/runtime/render-arbitrary.js | isPlainObject | function isPlainObject(value) {
return t.binaryExpression(
"===",
toFunctionCall(t.identifier("String"), [value]),
t.stringLiteral("[object Object]")
);
} | javascript | function isPlainObject(value) {
return t.binaryExpression(
"===",
toFunctionCall(t.identifier("String"), [value]),
t.stringLiteral("[object Object]")
);
} | [
"function",
"isPlainObject",
"(",
"value",
")",
"{",
"return",
"t",
".",
"binaryExpression",
"(",
"\"===\"",
",",
"toFunctionCall",
"(",
"t",
".",
"identifier",
"(",
"\"String\"",
")",
",",
"[",
"value",
"]",
")",
",",
"t",
".",
"stringLiteral",
"(",
"\"[object Object]\"",
")",
")",
";",
"}"
] | Isolated AST to determine if the value is a "plain" object. | [
"Isolated",
"AST",
"to",
"determine",
"if",
"the",
"value",
"is",
"a",
"plain",
"object",
"."
] | 4ee2b244c0876338b6a7b6f2d6bae210712f8894 | https://github.com/jridgewell/babel-plugin-transform-incremental-dom/blob/4ee2b244c0876338b6a7b6f2d6bae210712f8894/src/helpers/runtime/render-arbitrary.js#L51-L57 |
22,971 | jridgewell/babel-plugin-transform-incremental-dom | src/helpers/runtime/render-arbitrary.js | renderArbitraryAST | function renderArbitraryAST(plugin, ref, deps) {
const { hasOwn } = deps;
const child = t.identifier("child");
const type = t.identifier("type");
const func = t.identifier("func");
const args = t.identifier("args");
const i = t.identifier("i");
const prop = t.identifier("prop");
/**
* function _renderArbitrary(child) {
* var type = typeof child;
* if (type === "number" || (type === string || type === 'object' && child instanceof String)) {
* text(child);
* } else if (Array.isArray(child)) {
* for (var i = 0; i < child.length; i++) {
* _renderArbitrary(child[i]);
* }
* } else if (type === "object") {
* if (child.__jsxDOMWrapper) {
* var func = child.func, args = child.args;
* if (args) {
* func.apply(this, args);
* } else {
* func();
* }
* } else if (String(child) === "[object Object]") {
* for (var prop in child) {
* if (_hasOwn.call(child, prop)) {
* renderArbitrary(child[prop])
* }
* }
* }
* }
* }
*/
return t.functionExpression(
ref,
[child],
t.blockStatement([
t.variableDeclaration("var", [
t.variableDeclarator(
type,
t.unaryExpression("typeof", child)
)
]),
t.IfStatement(
isTextual(type, child),
t.blockStatement([
t.expressionStatement(toFunctionCall(iDOMMethod("text", plugin), [child]))
]),
t.ifStatement(
isArray(child),
t.blockStatement([
t.forStatement(
t.variableDeclaration("var", [t.variableDeclarator(i, t.numericLiteral(0))]),
t.binaryExpression("<", i, t.memberExpression(child, t.identifier("length"))),
t.updateExpression("++", i),
t.expressionStatement(toFunctionCall(ref, [
t.memberExpression(child, i, true)
]))
)
]),
t.ifStatement(
isObject(type),
t.blockStatement([
t.ifStatement(
isDOMWrapper(child),
t.blockStatement([
t.variableDeclaration("var", [
t.variableDeclarator(func, t.memberExpression(child, func)),
t.variableDeclarator(args, t.memberExpression(child, args))
]),
t.ifStatement(
args,
t.blockStatement([
t.expressionStatement(
toFunctionCall(t.memberExpression(func, t.identifier("apply")), [t.thisExpression(), args]),
)
]),
t.blockStatement([
t.expressionStatement(toFunctionCall(func, [])),
]),
)
]),
t.ifStatement(
isPlainObject(child),
t.blockStatement([
t.forInStatement(
t.variableDeclaration("var", [t.variableDeclarator(prop)]),
child,
t.ifStatement(
toFunctionCall(t.memberExpression(
hasOwn,
t.identifier("call")
), [child, i]),
t.expressionStatement(toFunctionCall(ref, [
t.memberExpression(child, i, true)
]))
)
)
])
)
)
])
)
)
)
])
);
} | javascript | function renderArbitraryAST(plugin, ref, deps) {
const { hasOwn } = deps;
const child = t.identifier("child");
const type = t.identifier("type");
const func = t.identifier("func");
const args = t.identifier("args");
const i = t.identifier("i");
const prop = t.identifier("prop");
/**
* function _renderArbitrary(child) {
* var type = typeof child;
* if (type === "number" || (type === string || type === 'object' && child instanceof String)) {
* text(child);
* } else if (Array.isArray(child)) {
* for (var i = 0; i < child.length; i++) {
* _renderArbitrary(child[i]);
* }
* } else if (type === "object") {
* if (child.__jsxDOMWrapper) {
* var func = child.func, args = child.args;
* if (args) {
* func.apply(this, args);
* } else {
* func();
* }
* } else if (String(child) === "[object Object]") {
* for (var prop in child) {
* if (_hasOwn.call(child, prop)) {
* renderArbitrary(child[prop])
* }
* }
* }
* }
* }
*/
return t.functionExpression(
ref,
[child],
t.blockStatement([
t.variableDeclaration("var", [
t.variableDeclarator(
type,
t.unaryExpression("typeof", child)
)
]),
t.IfStatement(
isTextual(type, child),
t.blockStatement([
t.expressionStatement(toFunctionCall(iDOMMethod("text", plugin), [child]))
]),
t.ifStatement(
isArray(child),
t.blockStatement([
t.forStatement(
t.variableDeclaration("var", [t.variableDeclarator(i, t.numericLiteral(0))]),
t.binaryExpression("<", i, t.memberExpression(child, t.identifier("length"))),
t.updateExpression("++", i),
t.expressionStatement(toFunctionCall(ref, [
t.memberExpression(child, i, true)
]))
)
]),
t.ifStatement(
isObject(type),
t.blockStatement([
t.ifStatement(
isDOMWrapper(child),
t.blockStatement([
t.variableDeclaration("var", [
t.variableDeclarator(func, t.memberExpression(child, func)),
t.variableDeclarator(args, t.memberExpression(child, args))
]),
t.ifStatement(
args,
t.blockStatement([
t.expressionStatement(
toFunctionCall(t.memberExpression(func, t.identifier("apply")), [t.thisExpression(), args]),
)
]),
t.blockStatement([
t.expressionStatement(toFunctionCall(func, [])),
]),
)
]),
t.ifStatement(
isPlainObject(child),
t.blockStatement([
t.forInStatement(
t.variableDeclaration("var", [t.variableDeclarator(prop)]),
child,
t.ifStatement(
toFunctionCall(t.memberExpression(
hasOwn,
t.identifier("call")
), [child, i]),
t.expressionStatement(toFunctionCall(ref, [
t.memberExpression(child, i, true)
]))
)
)
])
)
)
])
)
)
)
])
);
} | [
"function",
"renderArbitraryAST",
"(",
"plugin",
",",
"ref",
",",
"deps",
")",
"{",
"const",
"{",
"hasOwn",
"}",
"=",
"deps",
";",
"const",
"child",
"=",
"t",
".",
"identifier",
"(",
"\"child\"",
")",
";",
"const",
"type",
"=",
"t",
".",
"identifier",
"(",
"\"type\"",
")",
";",
"const",
"func",
"=",
"t",
".",
"identifier",
"(",
"\"func\"",
")",
";",
"const",
"args",
"=",
"t",
".",
"identifier",
"(",
"\"args\"",
")",
";",
"const",
"i",
"=",
"t",
".",
"identifier",
"(",
"\"i\"",
")",
";",
"const",
"prop",
"=",
"t",
".",
"identifier",
"(",
"\"prop\"",
")",
";",
"/**\n * function _renderArbitrary(child) {\n * var type = typeof child;\n * if (type === \"number\" || (type === string || type === 'object' && child instanceof String)) {\n * text(child);\n * } else if (Array.isArray(child)) {\n * for (var i = 0; i < child.length; i++) {\n * _renderArbitrary(child[i]);\n * }\n * } else if (type === \"object\") {\n * if (child.__jsxDOMWrapper) {\n * var func = child.func, args = child.args;\n * if (args) {\n * func.apply(this, args);\n * } else {\n * func();\n * }\n * } else if (String(child) === \"[object Object]\") {\n * for (var prop in child) {\n * if (_hasOwn.call(child, prop)) {\n * renderArbitrary(child[prop])\n * }\n * }\n * }\n * }\n * }\n */",
"return",
"t",
".",
"functionExpression",
"(",
"ref",
",",
"[",
"child",
"]",
",",
"t",
".",
"blockStatement",
"(",
"[",
"t",
".",
"variableDeclaration",
"(",
"\"var\"",
",",
"[",
"t",
".",
"variableDeclarator",
"(",
"type",
",",
"t",
".",
"unaryExpression",
"(",
"\"typeof\"",
",",
"child",
")",
")",
"]",
")",
",",
"t",
".",
"IfStatement",
"(",
"isTextual",
"(",
"type",
",",
"child",
")",
",",
"t",
".",
"blockStatement",
"(",
"[",
"t",
".",
"expressionStatement",
"(",
"toFunctionCall",
"(",
"iDOMMethod",
"(",
"\"text\"",
",",
"plugin",
")",
",",
"[",
"child",
"]",
")",
")",
"]",
")",
",",
"t",
".",
"ifStatement",
"(",
"isArray",
"(",
"child",
")",
",",
"t",
".",
"blockStatement",
"(",
"[",
"t",
".",
"forStatement",
"(",
"t",
".",
"variableDeclaration",
"(",
"\"var\"",
",",
"[",
"t",
".",
"variableDeclarator",
"(",
"i",
",",
"t",
".",
"numericLiteral",
"(",
"0",
")",
")",
"]",
")",
",",
"t",
".",
"binaryExpression",
"(",
"\"<\"",
",",
"i",
",",
"t",
".",
"memberExpression",
"(",
"child",
",",
"t",
".",
"identifier",
"(",
"\"length\"",
")",
")",
")",
",",
"t",
".",
"updateExpression",
"(",
"\"++\"",
",",
"i",
")",
",",
"t",
".",
"expressionStatement",
"(",
"toFunctionCall",
"(",
"ref",
",",
"[",
"t",
".",
"memberExpression",
"(",
"child",
",",
"i",
",",
"true",
")",
"]",
")",
")",
")",
"]",
")",
",",
"t",
".",
"ifStatement",
"(",
"isObject",
"(",
"type",
")",
",",
"t",
".",
"blockStatement",
"(",
"[",
"t",
".",
"ifStatement",
"(",
"isDOMWrapper",
"(",
"child",
")",
",",
"t",
".",
"blockStatement",
"(",
"[",
"t",
".",
"variableDeclaration",
"(",
"\"var\"",
",",
"[",
"t",
".",
"variableDeclarator",
"(",
"func",
",",
"t",
".",
"memberExpression",
"(",
"child",
",",
"func",
")",
")",
",",
"t",
".",
"variableDeclarator",
"(",
"args",
",",
"t",
".",
"memberExpression",
"(",
"child",
",",
"args",
")",
")",
"]",
")",
",",
"t",
".",
"ifStatement",
"(",
"args",
",",
"t",
".",
"blockStatement",
"(",
"[",
"t",
".",
"expressionStatement",
"(",
"toFunctionCall",
"(",
"t",
".",
"memberExpression",
"(",
"func",
",",
"t",
".",
"identifier",
"(",
"\"apply\"",
")",
")",
",",
"[",
"t",
".",
"thisExpression",
"(",
")",
",",
"args",
"]",
")",
",",
")",
"]",
")",
",",
"t",
".",
"blockStatement",
"(",
"[",
"t",
".",
"expressionStatement",
"(",
"toFunctionCall",
"(",
"func",
",",
"[",
"]",
")",
")",
",",
"]",
")",
",",
")",
"]",
")",
",",
"t",
".",
"ifStatement",
"(",
"isPlainObject",
"(",
"child",
")",
",",
"t",
".",
"blockStatement",
"(",
"[",
"t",
".",
"forInStatement",
"(",
"t",
".",
"variableDeclaration",
"(",
"\"var\"",
",",
"[",
"t",
".",
"variableDeclarator",
"(",
"prop",
")",
"]",
")",
",",
"child",
",",
"t",
".",
"ifStatement",
"(",
"toFunctionCall",
"(",
"t",
".",
"memberExpression",
"(",
"hasOwn",
",",
"t",
".",
"identifier",
"(",
"\"call\"",
")",
")",
",",
"[",
"child",
",",
"i",
"]",
")",
",",
"t",
".",
"expressionStatement",
"(",
"toFunctionCall",
"(",
"ref",
",",
"[",
"t",
".",
"memberExpression",
"(",
"child",
",",
"i",
",",
"true",
")",
"]",
")",
")",
")",
")",
"]",
")",
")",
")",
"]",
")",
")",
")",
")",
"]",
")",
")",
";",
"}"
] | Renders an arbitrary JSX Expression into the DOM. Valid types are strings, numbers, and JSX element closures. It may also be an Array or Object, which will be iterated recursively to find a valid type. | [
"Renders",
"an",
"arbitrary",
"JSX",
"Expression",
"into",
"the",
"DOM",
".",
"Valid",
"types",
"are",
"strings",
"numbers",
"and",
"JSX",
"element",
"closures",
".",
"It",
"may",
"also",
"be",
"an",
"Array",
"or",
"Object",
"which",
"will",
"be",
"iterated",
"recursively",
"to",
"find",
"a",
"valid",
"type",
"."
] | 4ee2b244c0876338b6a7b6f2d6bae210712f8894 | https://github.com/jridgewell/babel-plugin-transform-incremental-dom/blob/4ee2b244c0876338b6a7b6f2d6bae210712f8894/src/helpers/runtime/render-arbitrary.js#L64-L174 |
22,972 | jridgewell/babel-plugin-transform-incremental-dom | src/helpers/hoist.js | generateHoistNameBasedOn | function generateHoistNameBasedOn(path, suffix = "") {
const names = [];
if (suffix) {
names.push(suffix);
}
let current = path;
while (!(current.isIdentifier() || current.isJSXIdentifier())) {
names.push(current.node.property.name);
current = current.get("object");
}
names.push(current.node.name);
return path.scope.generateUidIdentifier(names.reverse().join("$"));
} | javascript | function generateHoistNameBasedOn(path, suffix = "") {
const names = [];
if (suffix) {
names.push(suffix);
}
let current = path;
while (!(current.isIdentifier() || current.isJSXIdentifier())) {
names.push(current.node.property.name);
current = current.get("object");
}
names.push(current.node.name);
return path.scope.generateUidIdentifier(names.reverse().join("$"));
} | [
"function",
"generateHoistNameBasedOn",
"(",
"path",
",",
"suffix",
"=",
"\"\"",
")",
"{",
"const",
"names",
"=",
"[",
"]",
";",
"if",
"(",
"suffix",
")",
"{",
"names",
".",
"push",
"(",
"suffix",
")",
";",
"}",
"let",
"current",
"=",
"path",
";",
"while",
"(",
"!",
"(",
"current",
".",
"isIdentifier",
"(",
")",
"||",
"current",
".",
"isJSXIdentifier",
"(",
")",
")",
")",
"{",
"names",
".",
"push",
"(",
"current",
".",
"node",
".",
"property",
".",
"name",
")",
";",
"current",
"=",
"current",
".",
"get",
"(",
"\"object\"",
")",
";",
"}",
"names",
".",
"push",
"(",
"current",
".",
"node",
".",
"name",
")",
";",
"return",
"path",
".",
"scope",
".",
"generateUidIdentifier",
"(",
"names",
".",
"reverse",
"(",
")",
".",
"join",
"(",
"\"$\"",
")",
")",
";",
"}"
] | Name Smartly Do Good. | [
"Name",
"Smartly",
"Do",
"Good",
"."
] | 4ee2b244c0876338b6a7b6f2d6bae210712f8894 | https://github.com/jridgewell/babel-plugin-transform-incremental-dom/blob/4ee2b244c0876338b6a7b6f2d6bae210712f8894/src/helpers/hoist.js#L49-L63 |
22,973 | jridgewell/babel-plugin-transform-incremental-dom | src/helpers/build-children.js | isStringConcatenation | function isStringConcatenation(path) {
if (!(path.isBinaryExpression() && path.node.operator === "+")) {
return false;
}
const left = path.get("left");
const right = path.get("right");
return left.isStringLiteral() ||
right.isStringLiteral() ||
isStringConcatenation(left) ||
isStringConcatenation(right);
} | javascript | function isStringConcatenation(path) {
if (!(path.isBinaryExpression() && path.node.operator === "+")) {
return false;
}
const left = path.get("left");
const right = path.get("right");
return left.isStringLiteral() ||
right.isStringLiteral() ||
isStringConcatenation(left) ||
isStringConcatenation(right);
} | [
"function",
"isStringConcatenation",
"(",
"path",
")",
"{",
"if",
"(",
"!",
"(",
"path",
".",
"isBinaryExpression",
"(",
")",
"&&",
"path",
".",
"node",
".",
"operator",
"===",
"\"+\"",
")",
")",
"{",
"return",
"false",
";",
"}",
"const",
"left",
"=",
"path",
".",
"get",
"(",
"\"left\"",
")",
";",
"const",
"right",
"=",
"path",
".",
"get",
"(",
"\"right\"",
")",
";",
"return",
"left",
".",
"isStringLiteral",
"(",
")",
"||",
"right",
".",
"isStringLiteral",
"(",
")",
"||",
"isStringConcatenation",
"(",
"left",
")",
"||",
"isStringConcatenation",
"(",
"right",
")",
";",
"}"
] | String concatenations are special cased, so template literals don't require a call to renderArbitrary. | [
"String",
"concatenations",
"are",
"special",
"cased",
"so",
"template",
"literals",
"don",
"t",
"require",
"a",
"call",
"to",
"renderArbitrary",
"."
] | 4ee2b244c0876338b6a7b6f2d6bae210712f8894 | https://github.com/jridgewell/babel-plugin-transform-incremental-dom/blob/4ee2b244c0876338b6a7b6f2d6bae210712f8894/src/helpers/build-children.js#L12-L23 |
22,974 | RedSeal-co/ts-tinkerpop | lib/tsJavaModule.js | beforeJvm | function beforeJvm() {
var moduleJars = ['target/ts-tinkerpop-3.0.1.GA.0.jar', 'target/dependency/commons-configuration-1.10.jar', 'target/dependency/commons-lang-2.6.jar', 'target/dependency/commons-lang3-3.3.1.jar', 'target/dependency/gremlin-core-3.0.1-incubating.jar', 'target/dependency/gremlin-groovy-3.0.1-incubating.jar', 'target/dependency/gremlin-shaded-3.0.1-incubating.jar', 'target/dependency/groovy-2.4.1-indy.jar', 'target/dependency/groovy-2.4.1.jar', 'target/dependency/groovy-console-2.4.1.jar', 'target/dependency/groovy-groovysh-2.4.1-indy.jar', 'target/dependency/groovy-json-2.4.1-indy.jar', 'target/dependency/groovy-jsr223-2.4.1-indy.jar', 'target/dependency/groovy-swing-2.4.1.jar', 'target/dependency/groovy-templates-2.4.1.jar', 'target/dependency/groovy-xml-2.4.1.jar', 'target/dependency/hamcrest-core-1.3.jar', 'target/dependency/hppc-0.7.1.jar', 'target/dependency/ivy-2.3.0.jar', 'target/dependency/jackson-annotations-2.5.0.jar', 'target/dependency/jackson-core-2.5.3.jar', 'target/dependency/jackson-databind-2.5.3.jar', 'target/dependency/javatuples-1.2.jar', 'target/dependency/jbcrypt-0.3m.jar', 'target/dependency/jcabi-log-0.14.jar', 'target/dependency/jcabi-manifests-1.1.jar', 'target/dependency/jcl-over-slf4j-1.7.12.jar', 'target/dependency/jline-2.12.jar', 'target/dependency/junit-4.11.jar', 'target/dependency/log4j-1.2.17.jar', 'target/dependency/slf4j-api-1.7.12.jar', 'target/dependency/slf4j-log4j12-1.7.12.jar', 'target/dependency/snakeyaml-1.15.jar', 'target/dependency/tinkergraph-gremlin-3.0.1-incubating.jar', 'target/ts-tinkerpop-3.0.1.GA.0.jar'];
moduleJars.forEach(function (jarPath) {
var fullJarPath = path.join(__dirname, '..', jarPath);
dlog('Adding to classpath:', fullJarPath);
_java.classpath.push(fullJarPath);
});
return BluePromise.resolve();
} | javascript | function beforeJvm() {
var moduleJars = ['target/ts-tinkerpop-3.0.1.GA.0.jar', 'target/dependency/commons-configuration-1.10.jar', 'target/dependency/commons-lang-2.6.jar', 'target/dependency/commons-lang3-3.3.1.jar', 'target/dependency/gremlin-core-3.0.1-incubating.jar', 'target/dependency/gremlin-groovy-3.0.1-incubating.jar', 'target/dependency/gremlin-shaded-3.0.1-incubating.jar', 'target/dependency/groovy-2.4.1-indy.jar', 'target/dependency/groovy-2.4.1.jar', 'target/dependency/groovy-console-2.4.1.jar', 'target/dependency/groovy-groovysh-2.4.1-indy.jar', 'target/dependency/groovy-json-2.4.1-indy.jar', 'target/dependency/groovy-jsr223-2.4.1-indy.jar', 'target/dependency/groovy-swing-2.4.1.jar', 'target/dependency/groovy-templates-2.4.1.jar', 'target/dependency/groovy-xml-2.4.1.jar', 'target/dependency/hamcrest-core-1.3.jar', 'target/dependency/hppc-0.7.1.jar', 'target/dependency/ivy-2.3.0.jar', 'target/dependency/jackson-annotations-2.5.0.jar', 'target/dependency/jackson-core-2.5.3.jar', 'target/dependency/jackson-databind-2.5.3.jar', 'target/dependency/javatuples-1.2.jar', 'target/dependency/jbcrypt-0.3m.jar', 'target/dependency/jcabi-log-0.14.jar', 'target/dependency/jcabi-manifests-1.1.jar', 'target/dependency/jcl-over-slf4j-1.7.12.jar', 'target/dependency/jline-2.12.jar', 'target/dependency/junit-4.11.jar', 'target/dependency/log4j-1.2.17.jar', 'target/dependency/slf4j-api-1.7.12.jar', 'target/dependency/slf4j-log4j12-1.7.12.jar', 'target/dependency/snakeyaml-1.15.jar', 'target/dependency/tinkergraph-gremlin-3.0.1-incubating.jar', 'target/ts-tinkerpop-3.0.1.GA.0.jar'];
moduleJars.forEach(function (jarPath) {
var fullJarPath = path.join(__dirname, '..', jarPath);
dlog('Adding to classpath:', fullJarPath);
_java.classpath.push(fullJarPath);
});
return BluePromise.resolve();
} | [
"function",
"beforeJvm",
"(",
")",
"{",
"var",
"moduleJars",
"=",
"[",
"'target/ts-tinkerpop-3.0.1.GA.0.jar'",
",",
"'target/dependency/commons-configuration-1.10.jar'",
",",
"'target/dependency/commons-lang-2.6.jar'",
",",
"'target/dependency/commons-lang3-3.3.1.jar'",
",",
"'target/dependency/gremlin-core-3.0.1-incubating.jar'",
",",
"'target/dependency/gremlin-groovy-3.0.1-incubating.jar'",
",",
"'target/dependency/gremlin-shaded-3.0.1-incubating.jar'",
",",
"'target/dependency/groovy-2.4.1-indy.jar'",
",",
"'target/dependency/groovy-2.4.1.jar'",
",",
"'target/dependency/groovy-console-2.4.1.jar'",
",",
"'target/dependency/groovy-groovysh-2.4.1-indy.jar'",
",",
"'target/dependency/groovy-json-2.4.1-indy.jar'",
",",
"'target/dependency/groovy-jsr223-2.4.1-indy.jar'",
",",
"'target/dependency/groovy-swing-2.4.1.jar'",
",",
"'target/dependency/groovy-templates-2.4.1.jar'",
",",
"'target/dependency/groovy-xml-2.4.1.jar'",
",",
"'target/dependency/hamcrest-core-1.3.jar'",
",",
"'target/dependency/hppc-0.7.1.jar'",
",",
"'target/dependency/ivy-2.3.0.jar'",
",",
"'target/dependency/jackson-annotations-2.5.0.jar'",
",",
"'target/dependency/jackson-core-2.5.3.jar'",
",",
"'target/dependency/jackson-databind-2.5.3.jar'",
",",
"'target/dependency/javatuples-1.2.jar'",
",",
"'target/dependency/jbcrypt-0.3m.jar'",
",",
"'target/dependency/jcabi-log-0.14.jar'",
",",
"'target/dependency/jcabi-manifests-1.1.jar'",
",",
"'target/dependency/jcl-over-slf4j-1.7.12.jar'",
",",
"'target/dependency/jline-2.12.jar'",
",",
"'target/dependency/junit-4.11.jar'",
",",
"'target/dependency/log4j-1.2.17.jar'",
",",
"'target/dependency/slf4j-api-1.7.12.jar'",
",",
"'target/dependency/slf4j-log4j12-1.7.12.jar'",
",",
"'target/dependency/snakeyaml-1.15.jar'",
",",
"'target/dependency/tinkergraph-gremlin-3.0.1-incubating.jar'",
",",
"'target/ts-tinkerpop-3.0.1.GA.0.jar'",
"]",
";",
"moduleJars",
".",
"forEach",
"(",
"function",
"(",
"jarPath",
")",
"{",
"var",
"fullJarPath",
"=",
"path",
".",
"join",
"(",
"__dirname",
",",
"'..'",
",",
"jarPath",
")",
";",
"dlog",
"(",
"'Adding to classpath:'",
",",
"fullJarPath",
")",
";",
"_java",
".",
"classpath",
".",
"push",
"(",
"fullJarPath",
")",
";",
"}",
")",
";",
"return",
"BluePromise",
".",
"resolve",
"(",
")",
";",
"}"
] | JVM initialization callback which adds tsjava.classpath to the JVM classpath. | [
"JVM",
"initialization",
"callback",
"which",
"adds",
"tsjava",
".",
"classpath",
"to",
"the",
"JVM",
"classpath",
"."
] | 5b1485194407864aaa71134409f4b83b7cdaee1e | https://github.com/RedSeal-co/ts-tinkerpop/blob/5b1485194407864aaa71134409f4b83b7cdaee1e/lib/tsJavaModule.js#L22-L30 |
22,975 | RedSeal-co/ts-tinkerpop | lib/tsJavaModule.js | instanceOf | function instanceOf(javaObject, className) {
var fullName = fullyQualifiedName(className) || className;
return smellsLikeJavaObject(javaObject) && _java.instanceOf(javaObject, fullName);
} | javascript | function instanceOf(javaObject, className) {
var fullName = fullyQualifiedName(className) || className;
return smellsLikeJavaObject(javaObject) && _java.instanceOf(javaObject, fullName);
} | [
"function",
"instanceOf",
"(",
"javaObject",
",",
"className",
")",
"{",
"var",
"fullName",
"=",
"fullyQualifiedName",
"(",
"className",
")",
"||",
"className",
";",
"return",
"smellsLikeJavaObject",
"(",
"javaObject",
")",
"&&",
"_java",
".",
"instanceOf",
"(",
"javaObject",
",",
"fullName",
")",
";",
"}"
] | Returns true if javaObject is an instance of the named class, which may be a short className. Returns false if javaObject is not an instance of the named class. Throws an exception if the named class does not exist, or is an ambiguous short name. | [
"Returns",
"true",
"if",
"javaObject",
"is",
"an",
"instance",
"of",
"the",
"named",
"class",
"which",
"may",
"be",
"a",
"short",
"className",
".",
"Returns",
"false",
"if",
"javaObject",
"is",
"not",
"an",
"instance",
"of",
"the",
"named",
"class",
".",
"Throws",
"an",
"exception",
"if",
"the",
"named",
"class",
"does",
"not",
"exist",
"or",
"is",
"an",
"ambiguous",
"short",
"name",
"."
] | 5b1485194407864aaa71134409f4b83b7cdaee1e | https://github.com/RedSeal-co/ts-tinkerpop/blob/5b1485194407864aaa71134409f4b83b7cdaee1e/lib/tsJavaModule.js#L488-L491 |
22,976 | HTMLElements/smarthtmlelements-core | demos/accordion/methods/index.js | function() {
if (insertCounter === 3) {
insertBtn.disabled = true;
}
else {
insertBtn.disabled = false;
}
if (insertCounter === -3) {
removeBtn.disabled = true;
}
else {
removeBtn.disabled = false;
}
} | javascript | function() {
if (insertCounter === 3) {
insertBtn.disabled = true;
}
else {
insertBtn.disabled = false;
}
if (insertCounter === -3) {
removeBtn.disabled = true;
}
else {
removeBtn.disabled = false;
}
} | [
"function",
"(",
")",
"{",
"if",
"(",
"insertCounter",
"===",
"3",
")",
"{",
"insertBtn",
".",
"disabled",
"=",
"true",
";",
"}",
"else",
"{",
"insertBtn",
".",
"disabled",
"=",
"false",
";",
"}",
"if",
"(",
"insertCounter",
"===",
"-",
"3",
")",
"{",
"removeBtn",
".",
"disabled",
"=",
"true",
";",
"}",
"else",
"{",
"removeBtn",
".",
"disabled",
"=",
"false",
";",
"}",
"}"
] | Insert, Update, Remove | [
"Insert",
"Update",
"Remove"
] | 80cc674fd954e3dba90644182479d67f0ffa1023 | https://github.com/HTMLElements/smarthtmlelements-core/blob/80cc674fd954e3dba90644182479d67f0ffa1023/demos/accordion/methods/index.js#L26-L40 | |
22,977 | mradionov/eslint-plugin-disable | src/settings.js | prepare | function prepare(config) {
config = config || {};
var settings = config.settings && config.settings[constants.PLUGIN_NAME] || {};
// Set paths, convert string values to array
settings.paths = objValuesToArray(settings.paths || {});
// Set allExceptPaths, convert string values to array
settings.allExceptPaths = objValuesToArray(settings.allExceptPaths || {});
// Set options for multimatch module
settings.pathsOptions = settings.pathsOptions || defaults.pathsOptions;
// Forward plugins from config or use custom ones, remove current plugin
settings.plugins = toArray(settings.plugins || config.plugins || []);
var index = settings.plugins.indexOf(constants.PLUGIN_NAME_SHORT);
if (index > -1) {
settings.plugins.splice(index, 1);
}
settings.cliArgs = settings.cliArgs || [];
return settings;
} | javascript | function prepare(config) {
config = config || {};
var settings = config.settings && config.settings[constants.PLUGIN_NAME] || {};
// Set paths, convert string values to array
settings.paths = objValuesToArray(settings.paths || {});
// Set allExceptPaths, convert string values to array
settings.allExceptPaths = objValuesToArray(settings.allExceptPaths || {});
// Set options for multimatch module
settings.pathsOptions = settings.pathsOptions || defaults.pathsOptions;
// Forward plugins from config or use custom ones, remove current plugin
settings.plugins = toArray(settings.plugins || config.plugins || []);
var index = settings.plugins.indexOf(constants.PLUGIN_NAME_SHORT);
if (index > -1) {
settings.plugins.splice(index, 1);
}
settings.cliArgs = settings.cliArgs || [];
return settings;
} | [
"function",
"prepare",
"(",
"config",
")",
"{",
"config",
"=",
"config",
"||",
"{",
"}",
";",
"var",
"settings",
"=",
"config",
".",
"settings",
"&&",
"config",
".",
"settings",
"[",
"constants",
".",
"PLUGIN_NAME",
"]",
"||",
"{",
"}",
";",
"// Set paths, convert string values to array",
"settings",
".",
"paths",
"=",
"objValuesToArray",
"(",
"settings",
".",
"paths",
"||",
"{",
"}",
")",
";",
"// Set allExceptPaths, convert string values to array",
"settings",
".",
"allExceptPaths",
"=",
"objValuesToArray",
"(",
"settings",
".",
"allExceptPaths",
"||",
"{",
"}",
")",
";",
"// Set options for multimatch module",
"settings",
".",
"pathsOptions",
"=",
"settings",
".",
"pathsOptions",
"||",
"defaults",
".",
"pathsOptions",
";",
"// Forward plugins from config or use custom ones, remove current plugin",
"settings",
".",
"plugins",
"=",
"toArray",
"(",
"settings",
".",
"plugins",
"||",
"config",
".",
"plugins",
"||",
"[",
"]",
")",
";",
"var",
"index",
"=",
"settings",
".",
"plugins",
".",
"indexOf",
"(",
"constants",
".",
"PLUGIN_NAME_SHORT",
")",
";",
"if",
"(",
"index",
">",
"-",
"1",
")",
"{",
"settings",
".",
"plugins",
".",
"splice",
"(",
"index",
",",
"1",
")",
";",
"}",
"settings",
".",
"cliArgs",
"=",
"settings",
".",
"cliArgs",
"||",
"[",
"]",
";",
"return",
"settings",
";",
"}"
] | Convert settings from config to use in plugin
@param {Object} config ESLint constructed config object
@return {Object} prettified settings object | [
"Convert",
"settings",
"from",
"config",
"to",
"use",
"in",
"plugin"
] | 19b4e341cc8769a9d20e8cbd50284a6a1b55efae | https://github.com/mradionov/eslint-plugin-disable/blob/19b4e341cc8769a9d20e8cbd50284a6a1b55efae/src/settings.js#L37-L60 |
22,978 | jbreckmckye/trkl | trkl.js | subscribe | function subscribe(subscriber, immediate) {
if (!~subscribers.indexOf(subscriber)) {
subscribers.push(subscriber);
}
if (immediate) {
subscriber(value);
}
} | javascript | function subscribe(subscriber, immediate) {
if (!~subscribers.indexOf(subscriber)) {
subscribers.push(subscriber);
}
if (immediate) {
subscriber(value);
}
} | [
"function",
"subscribe",
"(",
"subscriber",
",",
"immediate",
")",
"{",
"if",
"(",
"!",
"~",
"subscribers",
".",
"indexOf",
"(",
"subscriber",
")",
")",
"{",
"subscribers",
".",
"push",
"(",
"subscriber",
")",
";",
"}",
"if",
"(",
"immediate",
")",
"{",
"subscriber",
"(",
"value",
")",
";",
"}",
"}"
] | declaring as a private function means the minifier can scrub its name on internal references | [
"declaring",
"as",
"a",
"private",
"function",
"means",
"the",
"minifier",
"can",
"scrub",
"its",
"name",
"on",
"internal",
"references"
] | e2660c5fd8b8339f959e033c7d90a6860c3570d6 | https://github.com/jbreckmckye/trkl/blob/e2660c5fd8b8339f959e033c7d90a6860c3570d6/trkl.js#L23-L30 |
22,979 | zzarcon/gh-emoji | dist/gh-emoji.js | load | function load() {
return new Promise(function (resolve) {
if (emojis) return resolve(emojis);
return fetch(enpoint).then(function (r) {
return r.json();
}).then(function (response) {
emojis = response;
resolve(emojis);
});
});
} | javascript | function load() {
return new Promise(function (resolve) {
if (emojis) return resolve(emojis);
return fetch(enpoint).then(function (r) {
return r.json();
}).then(function (response) {
emojis = response;
resolve(emojis);
});
});
} | [
"function",
"load",
"(",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
")",
"{",
"if",
"(",
"emojis",
")",
"return",
"resolve",
"(",
"emojis",
")",
";",
"return",
"fetch",
"(",
"enpoint",
")",
".",
"then",
"(",
"function",
"(",
"r",
")",
"{",
"return",
"r",
".",
"json",
"(",
")",
";",
"}",
")",
".",
"then",
"(",
"function",
"(",
"response",
")",
"{",
"emojis",
"=",
"response",
";",
"resolve",
"(",
"emojis",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Fetch the emoji data from Github's api.
@example
import { load as loadEmojis } from 'gh-emoji';
loadEmojis().then((emojis) => {
console.log(emojis['+1']); // 👍
});
@returns {Promise<Object>} Promise which passes Object with emoji names
as keys and generated image tags as values to callback. | [
"Fetch",
"the",
"emoji",
"data",
"from",
"Github",
"s",
"api",
"."
] | ce3e1fa8ba8bf41c77a003cf6475e53456ff09f4 | https://github.com/zzarcon/gh-emoji/blob/ce3e1fa8ba8bf41c77a003cf6475e53456ff09f4/dist/gh-emoji.js#L126-L137 |
22,980 | zzarcon/gh-emoji | dist/gh-emoji.js | parse | function parse(text) {
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var output = '';
var customClassNames = options.classNames ? options.classNames.trim().split(/\s+/) : '';
output += text.replace(delimiterRegex, function (match) {
var name = match.replace(/:/g, '');
var classNames = ['gh-emoji', 'gh-emoji-' + name];
if (!exist(name)) {
return match;
}
if (customClassNames) {
classNames.push.apply(classNames, _toConsumableArray(customClassNames));
}
var imageSrc = getUrl(name);
var imageClass = classNames.join(' ');
var imageAlt = name;
return '<img src="' + imageSrc + '" class="' + imageClass + '" alt="' + imageAlt + '" />';
});
return output;
} | javascript | function parse(text) {
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var output = '';
var customClassNames = options.classNames ? options.classNames.trim().split(/\s+/) : '';
output += text.replace(delimiterRegex, function (match) {
var name = match.replace(/:/g, '');
var classNames = ['gh-emoji', 'gh-emoji-' + name];
if (!exist(name)) {
return match;
}
if (customClassNames) {
classNames.push.apply(classNames, _toConsumableArray(customClassNames));
}
var imageSrc = getUrl(name);
var imageClass = classNames.join(' ');
var imageAlt = name;
return '<img src="' + imageSrc + '" class="' + imageClass + '" alt="' + imageAlt + '" />';
});
return output;
} | [
"function",
"parse",
"(",
"text",
")",
"{",
"var",
"options",
"=",
"arguments",
".",
"length",
"<=",
"1",
"||",
"arguments",
"[",
"1",
"]",
"===",
"undefined",
"?",
"{",
"}",
":",
"arguments",
"[",
"1",
"]",
";",
"var",
"output",
"=",
"''",
";",
"var",
"customClassNames",
"=",
"options",
".",
"classNames",
"?",
"options",
".",
"classNames",
".",
"trim",
"(",
")",
".",
"split",
"(",
"/",
"\\s+",
"/",
")",
":",
"''",
";",
"output",
"+=",
"text",
".",
"replace",
"(",
"delimiterRegex",
",",
"function",
"(",
"match",
")",
"{",
"var",
"name",
"=",
"match",
".",
"replace",
"(",
"/",
":",
"/",
"g",
",",
"''",
")",
";",
"var",
"classNames",
"=",
"[",
"'gh-emoji'",
",",
"'gh-emoji-'",
"+",
"name",
"]",
";",
"if",
"(",
"!",
"exist",
"(",
"name",
")",
")",
"{",
"return",
"match",
";",
"}",
"if",
"(",
"customClassNames",
")",
"{",
"classNames",
".",
"push",
".",
"apply",
"(",
"classNames",
",",
"_toConsumableArray",
"(",
"customClassNames",
")",
")",
";",
"}",
"var",
"imageSrc",
"=",
"getUrl",
"(",
"name",
")",
";",
"var",
"imageClass",
"=",
"classNames",
".",
"join",
"(",
"' '",
")",
";",
"var",
"imageAlt",
"=",
"name",
";",
"return",
"'<img src=\"'",
"+",
"imageSrc",
"+",
"'\" class=\"'",
"+",
"imageClass",
"+",
"'\" alt=\"'",
"+",
"imageAlt",
"+",
"'\" />'",
";",
"}",
")",
";",
"return",
"output",
";",
"}"
] | Parse text and replace emoji tags with actual emoji symbols.
@example
import { load as loadEmojis, parse } from 'gh-emoji';
const text = 'Do you believe in :alien:...? :scream:';
loadEmojis().then(() => {
console.log(parse(text)) // 'Do you believe in 👽...? 😱';
});
@param {String} text Text to parse.
@param {Object} options Options with additional data for parser.
@param {String} options.classNames String with custom class names
added to each emoji, separated with whitespace.
@returns {String} Parsed text with emoji image tags in it. | [
"Parse",
"text",
"and",
"replace",
"emoji",
"tags",
"with",
"actual",
"emoji",
"symbols",
"."
] | ce3e1fa8ba8bf41c77a003cf6475e53456ff09f4 | https://github.com/zzarcon/gh-emoji/blob/ce3e1fa8ba8bf41c77a003cf6475e53456ff09f4/dist/gh-emoji.js#L224-L250 |
22,981 | weirdpattern/gatsby-remark-embed-gist | src/index.js | buildUrl | function buildUrl(value, options, file) {
const [gist] = value.split(/[?#]/);
const [inlineUsername, id] =
gist.indexOf("/") > 0 ? gist.split("/") : [null, gist];
// username can come from inline code or options
const username = inlineUsername || options.username;
// checks for a valid username
if (username == null || username.trim().length === 0) {
throw new Error("Missing username information");
}
// checks for a valid id
if (id == null || id.trim().length === 0) {
throw new Error("Missing gist id information");
}
// builds the url and completes it with the file if any
let url = `${baseUrl}/${username}/${id}.json`;
if (file != null) {
url += `?file=${file}`;
}
return url;
} | javascript | function buildUrl(value, options, file) {
const [gist] = value.split(/[?#]/);
const [inlineUsername, id] =
gist.indexOf("/") > 0 ? gist.split("/") : [null, gist];
// username can come from inline code or options
const username = inlineUsername || options.username;
// checks for a valid username
if (username == null || username.trim().length === 0) {
throw new Error("Missing username information");
}
// checks for a valid id
if (id == null || id.trim().length === 0) {
throw new Error("Missing gist id information");
}
// builds the url and completes it with the file if any
let url = `${baseUrl}/${username}/${id}.json`;
if (file != null) {
url += `?file=${file}`;
}
return url;
} | [
"function",
"buildUrl",
"(",
"value",
",",
"options",
",",
"file",
")",
"{",
"const",
"[",
"gist",
"]",
"=",
"value",
".",
"split",
"(",
"/",
"[?#]",
"/",
")",
";",
"const",
"[",
"inlineUsername",
",",
"id",
"]",
"=",
"gist",
".",
"indexOf",
"(",
"\"/\"",
")",
">",
"0",
"?",
"gist",
".",
"split",
"(",
"\"/\"",
")",
":",
"[",
"null",
",",
"gist",
"]",
";",
"// username can come from inline code or options",
"const",
"username",
"=",
"inlineUsername",
"||",
"options",
".",
"username",
";",
"// checks for a valid username",
"if",
"(",
"username",
"==",
"null",
"||",
"username",
".",
"trim",
"(",
")",
".",
"length",
"===",
"0",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Missing username information\"",
")",
";",
"}",
"// checks for a valid id",
"if",
"(",
"id",
"==",
"null",
"||",
"id",
".",
"trim",
"(",
")",
".",
"length",
"===",
"0",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Missing gist id information\"",
")",
";",
"}",
"// builds the url and completes it with the file if any",
"let",
"url",
"=",
"`",
"${",
"baseUrl",
"}",
"${",
"username",
"}",
"${",
"id",
"}",
"`",
";",
"if",
"(",
"file",
"!=",
"null",
")",
"{",
"url",
"+=",
"`",
"${",
"file",
"}",
"`",
";",
"}",
"return",
"url",
";",
"}"
] | Builds the gist url.
@param {string} value the value of the inlineCode block.
@param {PluginOptions} options the options of the plugin.
@param {string} file the file to be loaded.
@returns {string} the gist url. | [
"Builds",
"the",
"gist",
"url",
"."
] | c044ac165e1e37180743413d5614d749aee38349 | https://github.com/weirdpattern/gatsby-remark-embed-gist/blob/c044ac165e1e37180743413d5614d749aee38349/src/index.js#L79-L105 |
22,982 | MaiaVictor/lambda-calculus | lambda-calculus.js | fromNumber | function fromNumber(num){
return Lam(Lam((function go(n){return n===0?Var(0):App(Var(1),go(n-1))})(num)));
} | javascript | function fromNumber(num){
return Lam(Lam((function go(n){return n===0?Var(0):App(Var(1),go(n-1))})(num)));
} | [
"function",
"fromNumber",
"(",
"num",
")",
"{",
"return",
"Lam",
"(",
"Lam",
"(",
"(",
"function",
"go",
"(",
"n",
")",
"{",
"return",
"n",
"===",
"0",
"?",
"Var",
"(",
"0",
")",
":",
"App",
"(",
"Var",
"(",
"1",
")",
",",
"go",
"(",
"n",
"-",
"1",
")",
")",
"}",
")",
"(",
"num",
")",
")",
")",
";",
"}"
] | Number -> Term Converts a JS number to a church-encoded nat. | [
"Number",
"-",
">",
"Term",
"Converts",
"a",
"JS",
"number",
"to",
"a",
"church",
"-",
"encoded",
"nat",
"."
] | c0880087ddc46957e66a691d2d296d4c7c7c5cef | https://github.com/MaiaVictor/lambda-calculus/blob/c0880087ddc46957e66a691d2d296d4c7c7c5cef/lambda-calculus.js#L70-L72 |
22,983 | MaiaVictor/lambda-calculus | lambda-calculus.js | toFunction | function toFunction(term){
return eval(transmogrify(
function(varName, body){ return "(function("+varName+"){return "+body+"})"; },
function(fun, arg){ return fun+"("+arg+")"; })
(term));
} | javascript | function toFunction(term){
return eval(transmogrify(
function(varName, body){ return "(function("+varName+"){return "+body+"})"; },
function(fun, arg){ return fun+"("+arg+")"; })
(term));
} | [
"function",
"toFunction",
"(",
"term",
")",
"{",
"return",
"eval",
"(",
"transmogrify",
"(",
"function",
"(",
"varName",
",",
"body",
")",
"{",
"return",
"\"(function(\"",
"+",
"varName",
"+",
"\"){return \"",
"+",
"body",
"+",
"\"})\"",
";",
"}",
",",
"function",
"(",
"fun",
",",
"arg",
")",
"{",
"return",
"fun",
"+",
"\"(\"",
"+",
"arg",
"+",
"\")\"",
";",
"}",
")",
"(",
"term",
")",
")",
";",
"}"
] | Term -> String Converts a term to a native JS function. | [
"Term",
"-",
">",
"String",
"Converts",
"a",
"term",
"to",
"a",
"native",
"JS",
"function",
"."
] | c0880087ddc46957e66a691d2d296d4c7c7c5cef | https://github.com/MaiaVictor/lambda-calculus/blob/c0880087ddc46957e66a691d2d296d4c7c7c5cef/lambda-calculus.js#L113-L118 |
22,984 | MaiaVictor/lambda-calculus | lambda-calculus.js | fromBLC | function fromBLC(source){
var index = 0;
return (function go(){
if (source[index] === "0")
return source[index+1] === "0"
? (index+=2, Lam(go()))
: (index+=2, App(go(), go()));
for (var i=0; source[index]!=="0"; ++i)
++index;
return (++index, Var(i-1));
})();
} | javascript | function fromBLC(source){
var index = 0;
return (function go(){
if (source[index] === "0")
return source[index+1] === "0"
? (index+=2, Lam(go()))
: (index+=2, App(go(), go()));
for (var i=0; source[index]!=="0"; ++i)
++index;
return (++index, Var(i-1));
})();
} | [
"function",
"fromBLC",
"(",
"source",
")",
"{",
"var",
"index",
"=",
"0",
";",
"return",
"(",
"function",
"go",
"(",
")",
"{",
"if",
"(",
"source",
"[",
"index",
"]",
"===",
"\"0\"",
")",
"return",
"source",
"[",
"index",
"+",
"1",
"]",
"===",
"\"0\"",
"?",
"(",
"index",
"+=",
"2",
",",
"Lam",
"(",
"go",
"(",
")",
")",
")",
":",
"(",
"index",
"+=",
"2",
",",
"App",
"(",
"go",
"(",
")",
",",
"go",
"(",
")",
")",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"source",
"[",
"index",
"]",
"!==",
"\"0\"",
";",
"++",
"i",
")",
"++",
"index",
";",
"return",
"(",
"++",
"index",
",",
"Var",
"(",
"i",
"-",
"1",
")",
")",
";",
"}",
")",
"(",
")",
";",
"}"
] | String -> Term Converts a binary lambda calculus string to a term. | [
"String",
"-",
">",
"Term",
"Converts",
"a",
"binary",
"lambda",
"calculus",
"string",
"to",
"a",
"term",
"."
] | c0880087ddc46957e66a691d2d296d4c7c7c5cef | https://github.com/MaiaVictor/lambda-calculus/blob/c0880087ddc46957e66a691d2d296d4c7c7c5cef/lambda-calculus.js#L191-L202 |
22,985 | MaiaVictor/lambda-calculus | lambda-calculus.js | fromBLC64 | function fromBLC64(digits){
var blc = "";
for (var d=0, l=digits.length; d<l; ++d){
var bits = base64Table[digits[d]];
blc += d === 0 ? bits.slice(bits.indexOf("1")+1) : bits;
};
return fromBLC(blc);
} | javascript | function fromBLC64(digits){
var blc = "";
for (var d=0, l=digits.length; d<l; ++d){
var bits = base64Table[digits[d]];
blc += d === 0 ? bits.slice(bits.indexOf("1")+1) : bits;
};
return fromBLC(blc);
} | [
"function",
"fromBLC64",
"(",
"digits",
")",
"{",
"var",
"blc",
"=",
"\"\"",
";",
"for",
"(",
"var",
"d",
"=",
"0",
",",
"l",
"=",
"digits",
".",
"length",
";",
"d",
"<",
"l",
";",
"++",
"d",
")",
"{",
"var",
"bits",
"=",
"base64Table",
"[",
"digits",
"[",
"d",
"]",
"]",
";",
"blc",
"+=",
"d",
"===",
"0",
"?",
"bits",
".",
"slice",
"(",
"bits",
".",
"indexOf",
"(",
"\"1\"",
")",
"+",
"1",
")",
":",
"bits",
";",
"}",
";",
"return",
"fromBLC",
"(",
"blc",
")",
";",
"}"
] | String -> Term Converts a base64 binary lambda calculus string to a term. | [
"String",
"-",
">",
"Term",
"Converts",
"a",
"base64",
"binary",
"lambda",
"calculus",
"string",
"to",
"a",
"term",
"."
] | c0880087ddc46957e66a691d2d296d4c7c7c5cef | https://github.com/MaiaVictor/lambda-calculus/blob/c0880087ddc46957e66a691d2d296d4c7c7c5cef/lambda-calculus.js#L223-L230 |
22,986 | MaiaVictor/lambda-calculus | lambda-calculus.js | toBLC64 | function toBLC64(term){
var blc = toBLC(term);
var digits = "";
for (var d=0, l=blc.length; d<=l/6; ++d){
var i = l - d*6 - 6;
var bits = i < 0
? ("000001"+blc.slice(0, i+6)).slice(-6)
: blc.slice(i, i+6);
digits = base64Table[bits] + digits;
};
return digits;
} | javascript | function toBLC64(term){
var blc = toBLC(term);
var digits = "";
for (var d=0, l=blc.length; d<=l/6; ++d){
var i = l - d*6 - 6;
var bits = i < 0
? ("000001"+blc.slice(0, i+6)).slice(-6)
: blc.slice(i, i+6);
digits = base64Table[bits] + digits;
};
return digits;
} | [
"function",
"toBLC64",
"(",
"term",
")",
"{",
"var",
"blc",
"=",
"toBLC",
"(",
"term",
")",
";",
"var",
"digits",
"=",
"\"\"",
";",
"for",
"(",
"var",
"d",
"=",
"0",
",",
"l",
"=",
"blc",
".",
"length",
";",
"d",
"<=",
"l",
"/",
"6",
";",
"++",
"d",
")",
"{",
"var",
"i",
"=",
"l",
"-",
"d",
"*",
"6",
"-",
"6",
";",
"var",
"bits",
"=",
"i",
"<",
"0",
"?",
"(",
"\"000001\"",
"+",
"blc",
".",
"slice",
"(",
"0",
",",
"i",
"+",
"6",
")",
")",
".",
"slice",
"(",
"-",
"6",
")",
":",
"blc",
".",
"slice",
"(",
"i",
",",
"i",
"+",
"6",
")",
";",
"digits",
"=",
"base64Table",
"[",
"bits",
"]",
"+",
"digits",
";",
"}",
";",
"return",
"digits",
";",
"}"
] | Term -> String Converts a term to a base64 binary lambda calculus string. | [
"Term",
"-",
">",
"String",
"Converts",
"a",
"term",
"to",
"a",
"base64",
"binary",
"lambda",
"calculus",
"string",
"."
] | c0880087ddc46957e66a691d2d296d4c7c7c5cef | https://github.com/MaiaVictor/lambda-calculus/blob/c0880087ddc46957e66a691d2d296d4c7c7c5cef/lambda-calculus.js#L234-L245 |
22,987 | skerit/json-dry | lib/json-dry.js | createDryReplacer | function createDryReplacer(root, replacer) {
var value_paths = new WeakMap(),
seen_path,
flags = {is_root: true},
chain = [],
path = [],
temp,
last,
len;
return function dryReplacer(holder, key, value) {
// Process the value to a possible given replacer function
if (replacer != null) {
value = replacer.call(holder, key, value);
}
// All falsy values can be returned as-is
if (!value) {
return value;
}
let is_wrap;
// An explicitly false key means this dryReplaced was
// recursively called with a replacement object
if (key === false) {
key = '';
is_wrap = true;
// Wrappers get added to the object chain, but not the path
// We need to be able to identify them later on
holder.__is_wrap = true;
// See if the wrapped value is an object
if (holder[''] != null && typeof holder[''] === 'object') {
holder.__is_object = true;
}
}
switch (typeof value) {
case 'function':
// If no drier is created, return now.
// Else: fall through
if (!driers.Function) {
return;
}
case 'object':
value = replaceObject(dryReplacer, value, chain, flags, is_wrap, holder, path, value_paths, key);
break;
case 'string':
// Make sure regular strings don't start with the path delimiter
if (!flags.is_root && value[0] == '~') {
value = safe_special_char + value.slice(1);
}
break;
case 'number':
// Allow infinite values
if (value && !isFinite(value)) {
if (value > 0) {
value = {dry: '+Infinity'};
} else {
value = {dry: '-Infinity'};
}
}
break;
}
return value;
}
} | javascript | function createDryReplacer(root, replacer) {
var value_paths = new WeakMap(),
seen_path,
flags = {is_root: true},
chain = [],
path = [],
temp,
last,
len;
return function dryReplacer(holder, key, value) {
// Process the value to a possible given replacer function
if (replacer != null) {
value = replacer.call(holder, key, value);
}
// All falsy values can be returned as-is
if (!value) {
return value;
}
let is_wrap;
// An explicitly false key means this dryReplaced was
// recursively called with a replacement object
if (key === false) {
key = '';
is_wrap = true;
// Wrappers get added to the object chain, but not the path
// We need to be able to identify them later on
holder.__is_wrap = true;
// See if the wrapped value is an object
if (holder[''] != null && typeof holder[''] === 'object') {
holder.__is_object = true;
}
}
switch (typeof value) {
case 'function':
// If no drier is created, return now.
// Else: fall through
if (!driers.Function) {
return;
}
case 'object':
value = replaceObject(dryReplacer, value, chain, flags, is_wrap, holder, path, value_paths, key);
break;
case 'string':
// Make sure regular strings don't start with the path delimiter
if (!flags.is_root && value[0] == '~') {
value = safe_special_char + value.slice(1);
}
break;
case 'number':
// Allow infinite values
if (value && !isFinite(value)) {
if (value > 0) {
value = {dry: '+Infinity'};
} else {
value = {dry: '-Infinity'};
}
}
break;
}
return value;
}
} | [
"function",
"createDryReplacer",
"(",
"root",
",",
"replacer",
")",
"{",
"var",
"value_paths",
"=",
"new",
"WeakMap",
"(",
")",
",",
"seen_path",
",",
"flags",
"=",
"{",
"is_root",
":",
"true",
"}",
",",
"chain",
"=",
"[",
"]",
",",
"path",
"=",
"[",
"]",
",",
"temp",
",",
"last",
",",
"len",
";",
"return",
"function",
"dryReplacer",
"(",
"holder",
",",
"key",
",",
"value",
")",
"{",
"// Process the value to a possible given replacer function",
"if",
"(",
"replacer",
"!=",
"null",
")",
"{",
"value",
"=",
"replacer",
".",
"call",
"(",
"holder",
",",
"key",
",",
"value",
")",
";",
"}",
"// All falsy values can be returned as-is",
"if",
"(",
"!",
"value",
")",
"{",
"return",
"value",
";",
"}",
"let",
"is_wrap",
";",
"// An explicitly false key means this dryReplaced was",
"// recursively called with a replacement object",
"if",
"(",
"key",
"===",
"false",
")",
"{",
"key",
"=",
"''",
";",
"is_wrap",
"=",
"true",
";",
"// Wrappers get added to the object chain, but not the path",
"// We need to be able to identify them later on",
"holder",
".",
"__is_wrap",
"=",
"true",
";",
"// See if the wrapped value is an object",
"if",
"(",
"holder",
"[",
"''",
"]",
"!=",
"null",
"&&",
"typeof",
"holder",
"[",
"''",
"]",
"===",
"'object'",
")",
"{",
"holder",
".",
"__is_object",
"=",
"true",
";",
"}",
"}",
"switch",
"(",
"typeof",
"value",
")",
"{",
"case",
"'function'",
":",
"// If no drier is created, return now.",
"// Else: fall through",
"if",
"(",
"!",
"driers",
".",
"Function",
")",
"{",
"return",
";",
"}",
"case",
"'object'",
":",
"value",
"=",
"replaceObject",
"(",
"dryReplacer",
",",
"value",
",",
"chain",
",",
"flags",
",",
"is_wrap",
",",
"holder",
",",
"path",
",",
"value_paths",
",",
"key",
")",
";",
"break",
";",
"case",
"'string'",
":",
"// Make sure regular strings don't start with the path delimiter",
"if",
"(",
"!",
"flags",
".",
"is_root",
"&&",
"value",
"[",
"0",
"]",
"==",
"'~'",
")",
"{",
"value",
"=",
"safe_special_char",
"+",
"value",
".",
"slice",
"(",
"1",
")",
";",
"}",
"break",
";",
"case",
"'number'",
":",
"// Allow infinite values",
"if",
"(",
"value",
"&&",
"!",
"isFinite",
"(",
"value",
")",
")",
"{",
"if",
"(",
"value",
">",
"0",
")",
"{",
"value",
"=",
"{",
"dry",
":",
"'+Infinity'",
"}",
";",
"}",
"else",
"{",
"value",
"=",
"{",
"dry",
":",
"'-Infinity'",
"}",
";",
"}",
"}",
"break",
";",
"}",
"return",
"value",
";",
"}",
"}"
] | Generate a replacer function
@author Jelle De Loecker <jelle@develry.be>
@since 0.1.0
@version 1.0.1
@param {Object} root
@param {Function} replacer
@return {Function} | [
"Generate",
"a",
"replacer",
"function"
] | f20fd8e4aa3bcfe133f3c1a5b5b6ea3aa7060546 | https://github.com/skerit/json-dry/blob/f20fd8e4aa3bcfe133f3c1a5b5b6ea3aa7060546/lib/json-dry.js#L24-L100 |
22,988 | skerit/json-dry | lib/json-dry.js | recurseGeneralObject | function recurseGeneralObject(dryReplacer, value) {
var new_value = {},
keys = Object.keys(value),
key,
i;
for (i = 0; i < keys.length; i++) {
key = keys[i];
new_value[key] = dryReplacer(value, key, value[key]);
}
return new_value;
} | javascript | function recurseGeneralObject(dryReplacer, value) {
var new_value = {},
keys = Object.keys(value),
key,
i;
for (i = 0; i < keys.length; i++) {
key = keys[i];
new_value[key] = dryReplacer(value, key, value[key]);
}
return new_value;
} | [
"function",
"recurseGeneralObject",
"(",
"dryReplacer",
",",
"value",
")",
"{",
"var",
"new_value",
"=",
"{",
"}",
",",
"keys",
"=",
"Object",
".",
"keys",
"(",
"value",
")",
",",
"key",
",",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"keys",
".",
"length",
";",
"i",
"++",
")",
"{",
"key",
"=",
"keys",
"[",
"i",
"]",
";",
"new_value",
"[",
"key",
"]",
"=",
"dryReplacer",
"(",
"value",
",",
"key",
",",
"value",
"[",
"key",
"]",
")",
";",
"}",
"return",
"new_value",
";",
"}"
] | Recursively replace the given regular object
@author Jelle De Loecker <jelle@develry.be>
@since 1.0.11
@version 1.0.11
@param {Function} dryReplacer
@param {Object} value
@return {Object} | [
"Recursively",
"replace",
"the",
"given",
"regular",
"object"
] | f20fd8e4aa3bcfe133f3c1a5b5b6ea3aa7060546 | https://github.com/skerit/json-dry/blob/f20fd8e4aa3bcfe133f3c1a5b5b6ea3aa7060546/lib/json-dry.js#L313-L326 |
22,989 | skerit/json-dry | lib/json-dry.js | generateReviver | function generateReviver(reviver, undry_paths) {
return function dryReviver(key, value) {
var val_type = typeof value,
constructor,
temp;
if (val_type === 'string') {
if (value[0] === special_char) {
// This is actually a path that needs to be replaced.
// Put in a String object for now
return new String(value.slice(1));
} else if (value[0] == '\\' && value[1] == 'x' && value[2] == '7' && value[3] == 'e') {
value = special_char + value.slice(4);
}
} else if (value && value.dry != null) {
switch (value.dry) {
case 'date':
if (value.value) {
return new Date(value.value);
}
break;
case 'regexp':
if (value.value) {
return RegExp.apply(undefined, get_regex.exec(value.value).slice(1));
}
break;
case '+Infinity':
return Infinity;
case '-Infinity':
return -Infinity;
case 'toDry':
constructor = findClass(value);
// Undry this element, but don't put it in the parsed object yet
if (constructor && typeof constructor.unDry === 'function') {
value.unDryConstructor = constructor;
} else {
value.undried = value.value;
}
if (value.drypath) {
undry_paths.set(value.drypath.join(special_char), value);
} else {
return value.undried;
}
break;
default:
if (typeof value.value !== 'undefined') {
if (undriers[value.dry]) {
value.unDryFunction = undriers[value.dry].fnc;
if (!value.drypath) {
// No path given? Then do the undrying right now
value.undried = value.unDryFunction(this, key, value.value)
}
} else {
value.undried = value.value;
}
if (value.drypath) {
undry_paths.set(value.drypath.join(special_char), value);
} else {
return value.undried;
}
}
}
}
if (reviver == null) {
return value;
}
return reviver.call(this, key, value);
};
} | javascript | function generateReviver(reviver, undry_paths) {
return function dryReviver(key, value) {
var val_type = typeof value,
constructor,
temp;
if (val_type === 'string') {
if (value[0] === special_char) {
// This is actually a path that needs to be replaced.
// Put in a String object for now
return new String(value.slice(1));
} else if (value[0] == '\\' && value[1] == 'x' && value[2] == '7' && value[3] == 'e') {
value = special_char + value.slice(4);
}
} else if (value && value.dry != null) {
switch (value.dry) {
case 'date':
if (value.value) {
return new Date(value.value);
}
break;
case 'regexp':
if (value.value) {
return RegExp.apply(undefined, get_regex.exec(value.value).slice(1));
}
break;
case '+Infinity':
return Infinity;
case '-Infinity':
return -Infinity;
case 'toDry':
constructor = findClass(value);
// Undry this element, but don't put it in the parsed object yet
if (constructor && typeof constructor.unDry === 'function') {
value.unDryConstructor = constructor;
} else {
value.undried = value.value;
}
if (value.drypath) {
undry_paths.set(value.drypath.join(special_char), value);
} else {
return value.undried;
}
break;
default:
if (typeof value.value !== 'undefined') {
if (undriers[value.dry]) {
value.unDryFunction = undriers[value.dry].fnc;
if (!value.drypath) {
// No path given? Then do the undrying right now
value.undried = value.unDryFunction(this, key, value.value)
}
} else {
value.undried = value.value;
}
if (value.drypath) {
undry_paths.set(value.drypath.join(special_char), value);
} else {
return value.undried;
}
}
}
}
if (reviver == null) {
return value;
}
return reviver.call(this, key, value);
};
} | [
"function",
"generateReviver",
"(",
"reviver",
",",
"undry_paths",
")",
"{",
"return",
"function",
"dryReviver",
"(",
"key",
",",
"value",
")",
"{",
"var",
"val_type",
"=",
"typeof",
"value",
",",
"constructor",
",",
"temp",
";",
"if",
"(",
"val_type",
"===",
"'string'",
")",
"{",
"if",
"(",
"value",
"[",
"0",
"]",
"===",
"special_char",
")",
"{",
"// This is actually a path that needs to be replaced.",
"// Put in a String object for now",
"return",
"new",
"String",
"(",
"value",
".",
"slice",
"(",
"1",
")",
")",
";",
"}",
"else",
"if",
"(",
"value",
"[",
"0",
"]",
"==",
"'\\\\'",
"&&",
"value",
"[",
"1",
"]",
"==",
"'x'",
"&&",
"value",
"[",
"2",
"]",
"==",
"'7'",
"&&",
"value",
"[",
"3",
"]",
"==",
"'e'",
")",
"{",
"value",
"=",
"special_char",
"+",
"value",
".",
"slice",
"(",
"4",
")",
";",
"}",
"}",
"else",
"if",
"(",
"value",
"&&",
"value",
".",
"dry",
"!=",
"null",
")",
"{",
"switch",
"(",
"value",
".",
"dry",
")",
"{",
"case",
"'date'",
":",
"if",
"(",
"value",
".",
"value",
")",
"{",
"return",
"new",
"Date",
"(",
"value",
".",
"value",
")",
";",
"}",
"break",
";",
"case",
"'regexp'",
":",
"if",
"(",
"value",
".",
"value",
")",
"{",
"return",
"RegExp",
".",
"apply",
"(",
"undefined",
",",
"get_regex",
".",
"exec",
"(",
"value",
".",
"value",
")",
".",
"slice",
"(",
"1",
")",
")",
";",
"}",
"break",
";",
"case",
"'+Infinity'",
":",
"return",
"Infinity",
";",
"case",
"'-Infinity'",
":",
"return",
"-",
"Infinity",
";",
"case",
"'toDry'",
":",
"constructor",
"=",
"findClass",
"(",
"value",
")",
";",
"// Undry this element, but don't put it in the parsed object yet",
"if",
"(",
"constructor",
"&&",
"typeof",
"constructor",
".",
"unDry",
"===",
"'function'",
")",
"{",
"value",
".",
"unDryConstructor",
"=",
"constructor",
";",
"}",
"else",
"{",
"value",
".",
"undried",
"=",
"value",
".",
"value",
";",
"}",
"if",
"(",
"value",
".",
"drypath",
")",
"{",
"undry_paths",
".",
"set",
"(",
"value",
".",
"drypath",
".",
"join",
"(",
"special_char",
")",
",",
"value",
")",
";",
"}",
"else",
"{",
"return",
"value",
".",
"undried",
";",
"}",
"break",
";",
"default",
":",
"if",
"(",
"typeof",
"value",
".",
"value",
"!==",
"'undefined'",
")",
"{",
"if",
"(",
"undriers",
"[",
"value",
".",
"dry",
"]",
")",
"{",
"value",
".",
"unDryFunction",
"=",
"undriers",
"[",
"value",
".",
"dry",
"]",
".",
"fnc",
";",
"if",
"(",
"!",
"value",
".",
"drypath",
")",
"{",
"// No path given? Then do the undrying right now",
"value",
".",
"undried",
"=",
"value",
".",
"unDryFunction",
"(",
"this",
",",
"key",
",",
"value",
".",
"value",
")",
"}",
"}",
"else",
"{",
"value",
".",
"undried",
"=",
"value",
".",
"value",
";",
"}",
"if",
"(",
"value",
".",
"drypath",
")",
"{",
"undry_paths",
".",
"set",
"(",
"value",
".",
"drypath",
".",
"join",
"(",
"special_char",
")",
",",
"value",
")",
";",
"}",
"else",
"{",
"return",
"value",
".",
"undried",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"reviver",
"==",
"null",
")",
"{",
"return",
"value",
";",
"}",
"return",
"reviver",
".",
"call",
"(",
"this",
",",
"key",
",",
"value",
")",
";",
"}",
";",
"}"
] | Generate reviver function
@author Jelle De Loecker <jelle@develry.be>
@since 0.1.0
@version 1.0.2
@param {Function} reviver
@param {Map} undry_paths
@return {Function} | [
"Generate",
"reviver",
"function"
] | f20fd8e4aa3bcfe133f3c1a5b5b6ea3aa7060546 | https://github.com/skerit/json-dry/blob/f20fd8e4aa3bcfe133f3c1a5b5b6ea3aa7060546/lib/json-dry.js#L340-L424 |
22,990 | skerit/json-dry | lib/json-dry.js | registerDrier | function registerDrier(constructor, fnc, options) {
var path;
if (typeof constructor == 'function') {
path = constructor.name;
} else {
path = constructor;
}
driers[path] = {
fnc : fnc,
options : options || {}
};
} | javascript | function registerDrier(constructor, fnc, options) {
var path;
if (typeof constructor == 'function') {
path = constructor.name;
} else {
path = constructor;
}
driers[path] = {
fnc : fnc,
options : options || {}
};
} | [
"function",
"registerDrier",
"(",
"constructor",
",",
"fnc",
",",
"options",
")",
"{",
"var",
"path",
";",
"if",
"(",
"typeof",
"constructor",
"==",
"'function'",
")",
"{",
"path",
"=",
"constructor",
".",
"name",
";",
"}",
"else",
"{",
"path",
"=",
"constructor",
";",
"}",
"driers",
"[",
"path",
"]",
"=",
"{",
"fnc",
":",
"fnc",
",",
"options",
":",
"options",
"||",
"{",
"}",
"}",
";",
"}"
] | Register a drier
@author Jelle De Loecker <jelle@develry.be>
@since 1.0.0
@version 1.0.0
@param {Function|String} constructor What constructor to listen to
@param {Function} fnc
@param {Object} options | [
"Register",
"a",
"drier"
] | f20fd8e4aa3bcfe133f3c1a5b5b6ea3aa7060546 | https://github.com/skerit/json-dry/blob/f20fd8e4aa3bcfe133f3c1a5b5b6ea3aa7060546/lib/json-dry.js#L604-L618 |
22,991 | skerit/json-dry | lib/json-dry.js | registerUndrier | function registerUndrier(constructor, fnc, options) {
var path;
if (typeof constructor == 'function') {
path = constructor.name;
} else {
path = constructor;
}
undriers[path] = {
fnc : fnc,
options : options || {}
};
} | javascript | function registerUndrier(constructor, fnc, options) {
var path;
if (typeof constructor == 'function') {
path = constructor.name;
} else {
path = constructor;
}
undriers[path] = {
fnc : fnc,
options : options || {}
};
} | [
"function",
"registerUndrier",
"(",
"constructor",
",",
"fnc",
",",
"options",
")",
"{",
"var",
"path",
";",
"if",
"(",
"typeof",
"constructor",
"==",
"'function'",
")",
"{",
"path",
"=",
"constructor",
".",
"name",
";",
"}",
"else",
"{",
"path",
"=",
"constructor",
";",
"}",
"undriers",
"[",
"path",
"]",
"=",
"{",
"fnc",
":",
"fnc",
",",
"options",
":",
"options",
"||",
"{",
"}",
"}",
";",
"}"
] | Register an undrier
@author Jelle De Loecker <jelle@develry.be>
@since 1.0.0
@version 1.0.0
@param {Function|String} constructor What constructor to listen to
@param {Function} fnc
@param {Object} options | [
"Register",
"an",
"undrier"
] | f20fd8e4aa3bcfe133f3c1a5b5b6ea3aa7060546 | https://github.com/skerit/json-dry/blob/f20fd8e4aa3bcfe133f3c1a5b5b6ea3aa7060546/lib/json-dry.js#L631-L645 |
22,992 | skerit/json-dry | lib/json-dry.js | findClass | function findClass(value) {
var constructor,
ns;
// Return nothing for falsy values
if (!value) {
return null;
}
// Look for a regular class when it's just a string
if (typeof value == 'string') {
if (exports.Classes[value]) {
return exports.Classes[value];
}
return null;
}
if (value.path) {
return fromPath(exports.Classes, value.path);
} else {
if (value.namespace) {
ns = fromPath(exports.Classes, value.namespace);
} else {
ns = exports.Classes;
}
if (value.dry_class) {
constructor = fromPath(ns, value.dry_class);
} else if (value.name) {
constructor = ns[value.name];
}
if (!constructor && ns) {
if (ns.main_class) {
ns = ns.main_class;
}
if (ns && typeof ns.getClassForUndry == 'function') {
constructor = ns.getClassForUndry(value.dry_class || value.name);
}
}
}
if (!constructor) {
console.log('Could not find constructor for', value);
}
return constructor;
} | javascript | function findClass(value) {
var constructor,
ns;
// Return nothing for falsy values
if (!value) {
return null;
}
// Look for a regular class when it's just a string
if (typeof value == 'string') {
if (exports.Classes[value]) {
return exports.Classes[value];
}
return null;
}
if (value.path) {
return fromPath(exports.Classes, value.path);
} else {
if (value.namespace) {
ns = fromPath(exports.Classes, value.namespace);
} else {
ns = exports.Classes;
}
if (value.dry_class) {
constructor = fromPath(ns, value.dry_class);
} else if (value.name) {
constructor = ns[value.name];
}
if (!constructor && ns) {
if (ns.main_class) {
ns = ns.main_class;
}
if (ns && typeof ns.getClassForUndry == 'function') {
constructor = ns.getClassForUndry(value.dry_class || value.name);
}
}
}
if (!constructor) {
console.log('Could not find constructor for', value);
}
return constructor;
} | [
"function",
"findClass",
"(",
"value",
")",
"{",
"var",
"constructor",
",",
"ns",
";",
"// Return nothing for falsy values",
"if",
"(",
"!",
"value",
")",
"{",
"return",
"null",
";",
"}",
"// Look for a regular class when it's just a string",
"if",
"(",
"typeof",
"value",
"==",
"'string'",
")",
"{",
"if",
"(",
"exports",
".",
"Classes",
"[",
"value",
"]",
")",
"{",
"return",
"exports",
".",
"Classes",
"[",
"value",
"]",
";",
"}",
"return",
"null",
";",
"}",
"if",
"(",
"value",
".",
"path",
")",
"{",
"return",
"fromPath",
"(",
"exports",
".",
"Classes",
",",
"value",
".",
"path",
")",
";",
"}",
"else",
"{",
"if",
"(",
"value",
".",
"namespace",
")",
"{",
"ns",
"=",
"fromPath",
"(",
"exports",
".",
"Classes",
",",
"value",
".",
"namespace",
")",
";",
"}",
"else",
"{",
"ns",
"=",
"exports",
".",
"Classes",
";",
"}",
"if",
"(",
"value",
".",
"dry_class",
")",
"{",
"constructor",
"=",
"fromPath",
"(",
"ns",
",",
"value",
".",
"dry_class",
")",
";",
"}",
"else",
"if",
"(",
"value",
".",
"name",
")",
"{",
"constructor",
"=",
"ns",
"[",
"value",
".",
"name",
"]",
";",
"}",
"if",
"(",
"!",
"constructor",
"&&",
"ns",
")",
"{",
"if",
"(",
"ns",
".",
"main_class",
")",
"{",
"ns",
"=",
"ns",
".",
"main_class",
";",
"}",
"if",
"(",
"ns",
"&&",
"typeof",
"ns",
".",
"getClassForUndry",
"==",
"'function'",
")",
"{",
"constructor",
"=",
"ns",
".",
"getClassForUndry",
"(",
"value",
".",
"dry_class",
"||",
"value",
".",
"name",
")",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"constructor",
")",
"{",
"console",
".",
"log",
"(",
"'Could not find constructor for'",
",",
"value",
")",
";",
"}",
"return",
"constructor",
";",
"}"
] | Find a class
@author Jelle De Loecker <jelle@develry.be>
@since 1.0.0
@version 1.0.9
@param {String} value The name of the class | [
"Find",
"a",
"class"
] | f20fd8e4aa3bcfe133f3c1a5b5b6ea3aa7060546 | https://github.com/skerit/json-dry/blob/f20fd8e4aa3bcfe133f3c1a5b5b6ea3aa7060546/lib/json-dry.js#L687-L738 |
22,993 | skerit/json-dry | lib/json-dry.js | regenerateArray | function regenerateArray(root, holder, current, seen, retrieve, undry_paths, old, current_path) {
var length = current.length,
temp,
i;
for (i = 0; i < length; i++) {
// Only regenerate if it's not yet seen
if (!seen.get(current[i])) {
temp = current_path.slice(0);
temp.push(i);
current[i] = regenerate(root, current, current[i], seen, retrieve, undry_paths, old, temp);
}
}
return current;
} | javascript | function regenerateArray(root, holder, current, seen, retrieve, undry_paths, old, current_path) {
var length = current.length,
temp,
i;
for (i = 0; i < length; i++) {
// Only regenerate if it's not yet seen
if (!seen.get(current[i])) {
temp = current_path.slice(0);
temp.push(i);
current[i] = regenerate(root, current, current[i], seen, retrieve, undry_paths, old, temp);
}
}
return current;
} | [
"function",
"regenerateArray",
"(",
"root",
",",
"holder",
",",
"current",
",",
"seen",
",",
"retrieve",
",",
"undry_paths",
",",
"old",
",",
"current_path",
")",
"{",
"var",
"length",
"=",
"current",
".",
"length",
",",
"temp",
",",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"// Only regenerate if it's not yet seen",
"if",
"(",
"!",
"seen",
".",
"get",
"(",
"current",
"[",
"i",
"]",
")",
")",
"{",
"temp",
"=",
"current_path",
".",
"slice",
"(",
"0",
")",
";",
"temp",
".",
"push",
"(",
"i",
")",
";",
"current",
"[",
"i",
"]",
"=",
"regenerate",
"(",
"root",
",",
"current",
",",
"current",
"[",
"i",
"]",
",",
"seen",
",",
"retrieve",
",",
"undry_paths",
",",
"old",
",",
"temp",
")",
";",
"}",
"}",
"return",
"current",
";",
"}"
] | Regenerate an array
@author Jelle De Loecker <jelle@develry.be>
@since 0.1.4
@version 1.0.8
@return {Array} | [
"Regenerate",
"an",
"array"
] | f20fd8e4aa3bcfe133f3c1a5b5b6ea3aa7060546 | https://github.com/skerit/json-dry/blob/f20fd8e4aa3bcfe133f3c1a5b5b6ea3aa7060546/lib/json-dry.js#L749-L767 |
22,994 | skerit/json-dry | lib/json-dry.js | regenerateObject | function regenerateObject(root, holder, current, seen, retrieve, undry_paths, old, current_path) {
var path,
temp,
key;
for (key in current) {
if (current.hasOwnProperty(key)) {
// Only regenerate if it's not already seen
if (!seen.get(current[key])) {
path = current_path.slice(0);
path.push(key);
temp = regenerate(root, current, current[key], seen, retrieve, undry_paths, old, path);
// @TODO: Values returned by `unDry` methods also get regenerated,
// even though these could contain properties coming from somewhere else,
// like live HTMLCollections. Assigning anything to that will throw an error.
// This is a workaround to that proble: if the value is exactly the same,
// it's not needed to assign it again, so it won't throw an error,
// but it's not an ideal solution.
if (temp !== current[key]) {
current[key] = temp;
}
}
}
}
return current;
} | javascript | function regenerateObject(root, holder, current, seen, retrieve, undry_paths, old, current_path) {
var path,
temp,
key;
for (key in current) {
if (current.hasOwnProperty(key)) {
// Only regenerate if it's not already seen
if (!seen.get(current[key])) {
path = current_path.slice(0);
path.push(key);
temp = regenerate(root, current, current[key], seen, retrieve, undry_paths, old, path);
// @TODO: Values returned by `unDry` methods also get regenerated,
// even though these could contain properties coming from somewhere else,
// like live HTMLCollections. Assigning anything to that will throw an error.
// This is a workaround to that proble: if the value is exactly the same,
// it's not needed to assign it again, so it won't throw an error,
// but it's not an ideal solution.
if (temp !== current[key]) {
current[key] = temp;
}
}
}
}
return current;
} | [
"function",
"regenerateObject",
"(",
"root",
",",
"holder",
",",
"current",
",",
"seen",
",",
"retrieve",
",",
"undry_paths",
",",
"old",
",",
"current_path",
")",
"{",
"var",
"path",
",",
"temp",
",",
"key",
";",
"for",
"(",
"key",
"in",
"current",
")",
"{",
"if",
"(",
"current",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"// Only regenerate if it's not already seen",
"if",
"(",
"!",
"seen",
".",
"get",
"(",
"current",
"[",
"key",
"]",
")",
")",
"{",
"path",
"=",
"current_path",
".",
"slice",
"(",
"0",
")",
";",
"path",
".",
"push",
"(",
"key",
")",
";",
"temp",
"=",
"regenerate",
"(",
"root",
",",
"current",
",",
"current",
"[",
"key",
"]",
",",
"seen",
",",
"retrieve",
",",
"undry_paths",
",",
"old",
",",
"path",
")",
";",
"// @TODO: Values returned by `unDry` methods also get regenerated,",
"// even though these could contain properties coming from somewhere else,",
"// like live HTMLCollections. Assigning anything to that will throw an error.",
"// This is a workaround to that proble: if the value is exactly the same,",
"// it's not needed to assign it again, so it won't throw an error,",
"// but it's not an ideal solution.",
"if",
"(",
"temp",
"!==",
"current",
"[",
"key",
"]",
")",
"{",
"current",
"[",
"key",
"]",
"=",
"temp",
";",
"}",
"}",
"}",
"}",
"return",
"current",
";",
"}"
] | Regenerate an object
@author Jelle De Loecker <jelle@develry.be>
@since 0.1.4
@version 1.0.11
@return {Object} | [
"Regenerate",
"an",
"object"
] | f20fd8e4aa3bcfe133f3c1a5b5b6ea3aa7060546 | https://github.com/skerit/json-dry/blob/f20fd8e4aa3bcfe133f3c1a5b5b6ea3aa7060546/lib/json-dry.js#L778-L807 |
22,995 | skerit/json-dry | lib/json-dry.js | regenerate | function regenerate(root, holder, current, seen, retrieve, undry_paths, old, current_path) {
var temp;
if (current && typeof current == 'object') {
// Remember this object has been regenerated already
seen.set(current, true);
if (current instanceof Array) {
return regenerateArray(root, holder, current, seen, retrieve, undry_paths, old, current_path);
}
if (current instanceof String) {
if (current.length > -1) {
current = current.toString();
if (temp = undry_paths.get(current)) {
if (typeof temp.undried != 'undefined') {
return temp.undried;
}
if (!holder) {
throw new Error('Unable to resolve recursive reference');
}
undry_paths.extra_pass.push([holder, temp, current_path]);
return temp;
}
if (retrieve.hasOwnProperty(current)) {
temp = retrieve[current];
} else {
temp = retrieve[current] = retrieveFromPath(root, current.split(special_char));
if (typeof temp == 'undefined') {
temp = retrieve[current] = getFromOld(old, current.split(special_char));
}
}
// Because we always regenerate parsed objects first
// (JSON-dry parsing goes from string » object » regenerated object)
// keys of regular objects can appear out-of-order, so we need to parse them
if (temp && temp instanceof String) {
// Unset the String as a valid result
retrieve[current] = null;
// Regenerate the string again
// (We have to create a new instance, because it's already been "seen")
temp = retrieve[current] = regenerate(root, holder, new String(temp), seen, retrieve, undry_paths, old, current_path);
}
return temp;
} else {
return root;
}
}
return regenerateObject(root, holder, current, seen, retrieve, undry_paths, old, current_path);
}
return current;
} | javascript | function regenerate(root, holder, current, seen, retrieve, undry_paths, old, current_path) {
var temp;
if (current && typeof current == 'object') {
// Remember this object has been regenerated already
seen.set(current, true);
if (current instanceof Array) {
return regenerateArray(root, holder, current, seen, retrieve, undry_paths, old, current_path);
}
if (current instanceof String) {
if (current.length > -1) {
current = current.toString();
if (temp = undry_paths.get(current)) {
if (typeof temp.undried != 'undefined') {
return temp.undried;
}
if (!holder) {
throw new Error('Unable to resolve recursive reference');
}
undry_paths.extra_pass.push([holder, temp, current_path]);
return temp;
}
if (retrieve.hasOwnProperty(current)) {
temp = retrieve[current];
} else {
temp = retrieve[current] = retrieveFromPath(root, current.split(special_char));
if (typeof temp == 'undefined') {
temp = retrieve[current] = getFromOld(old, current.split(special_char));
}
}
// Because we always regenerate parsed objects first
// (JSON-dry parsing goes from string » object » regenerated object)
// keys of regular objects can appear out-of-order, so we need to parse them
if (temp && temp instanceof String) {
// Unset the String as a valid result
retrieve[current] = null;
// Regenerate the string again
// (We have to create a new instance, because it's already been "seen")
temp = retrieve[current] = regenerate(root, holder, new String(temp), seen, retrieve, undry_paths, old, current_path);
}
return temp;
} else {
return root;
}
}
return regenerateObject(root, holder, current, seen, retrieve, undry_paths, old, current_path);
}
return current;
} | [
"function",
"regenerate",
"(",
"root",
",",
"holder",
",",
"current",
",",
"seen",
",",
"retrieve",
",",
"undry_paths",
",",
"old",
",",
"current_path",
")",
"{",
"var",
"temp",
";",
"if",
"(",
"current",
"&&",
"typeof",
"current",
"==",
"'object'",
")",
"{",
"// Remember this object has been regenerated already",
"seen",
".",
"set",
"(",
"current",
",",
"true",
")",
";",
"if",
"(",
"current",
"instanceof",
"Array",
")",
"{",
"return",
"regenerateArray",
"(",
"root",
",",
"holder",
",",
"current",
",",
"seen",
",",
"retrieve",
",",
"undry_paths",
",",
"old",
",",
"current_path",
")",
";",
"}",
"if",
"(",
"current",
"instanceof",
"String",
")",
"{",
"if",
"(",
"current",
".",
"length",
">",
"-",
"1",
")",
"{",
"current",
"=",
"current",
".",
"toString",
"(",
")",
";",
"if",
"(",
"temp",
"=",
"undry_paths",
".",
"get",
"(",
"current",
")",
")",
"{",
"if",
"(",
"typeof",
"temp",
".",
"undried",
"!=",
"'undefined'",
")",
"{",
"return",
"temp",
".",
"undried",
";",
"}",
"if",
"(",
"!",
"holder",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Unable to resolve recursive reference'",
")",
";",
"}",
"undry_paths",
".",
"extra_pass",
".",
"push",
"(",
"[",
"holder",
",",
"temp",
",",
"current_path",
"]",
")",
";",
"return",
"temp",
";",
"}",
"if",
"(",
"retrieve",
".",
"hasOwnProperty",
"(",
"current",
")",
")",
"{",
"temp",
"=",
"retrieve",
"[",
"current",
"]",
";",
"}",
"else",
"{",
"temp",
"=",
"retrieve",
"[",
"current",
"]",
"=",
"retrieveFromPath",
"(",
"root",
",",
"current",
".",
"split",
"(",
"special_char",
")",
")",
";",
"if",
"(",
"typeof",
"temp",
"==",
"'undefined'",
")",
"{",
"temp",
"=",
"retrieve",
"[",
"current",
"]",
"=",
"getFromOld",
"(",
"old",
",",
"current",
".",
"split",
"(",
"special_char",
")",
")",
";",
"}",
"}",
"// Because we always regenerate parsed objects first",
"// (JSON-dry parsing goes from string » object » regenerated object)",
"// keys of regular objects can appear out-of-order, so we need to parse them",
"if",
"(",
"temp",
"&&",
"temp",
"instanceof",
"String",
")",
"{",
"// Unset the String as a valid result",
"retrieve",
"[",
"current",
"]",
"=",
"null",
";",
"// Regenerate the string again",
"// (We have to create a new instance, because it's already been \"seen\")",
"temp",
"=",
"retrieve",
"[",
"current",
"]",
"=",
"regenerate",
"(",
"root",
",",
"holder",
",",
"new",
"String",
"(",
"temp",
")",
",",
"seen",
",",
"retrieve",
",",
"undry_paths",
",",
"old",
",",
"current_path",
")",
";",
"}",
"return",
"temp",
";",
"}",
"else",
"{",
"return",
"root",
";",
"}",
"}",
"return",
"regenerateObject",
"(",
"root",
",",
"holder",
",",
"current",
",",
"seen",
",",
"retrieve",
",",
"undry_paths",
",",
"old",
",",
"current_path",
")",
";",
"}",
"return",
"current",
";",
"}"
] | Regenerate a value
@author Jelle De Loecker <jelle@develry.be>
@since 0.1.4
@version 1.0.8
@return {Mixed} | [
"Regenerate",
"a",
"value"
] | f20fd8e4aa3bcfe133f3c1a5b5b6ea3aa7060546 | https://github.com/skerit/json-dry/blob/f20fd8e4aa3bcfe133f3c1a5b5b6ea3aa7060546/lib/json-dry.js#L818-L881 |
22,996 | skerit/json-dry | lib/json-dry.js | getFromOld | function getFromOld(old, pieces) {
var length = pieces.length,
result,
path,
rest,
i;
for (i = 0; i < length; i++) {
path = pieces.slice(0, length - i).join('.');
result = old[path];
if (typeof result != 'undefined') {
if (i == 0) {
return result;
}
rest = pieces.slice(pieces.length - i);
result = retrieveFromPath(result, rest);
if (typeof result != 'undefined') {
return result;
}
}
}
} | javascript | function getFromOld(old, pieces) {
var length = pieces.length,
result,
path,
rest,
i;
for (i = 0; i < length; i++) {
path = pieces.slice(0, length - i).join('.');
result = old[path];
if (typeof result != 'undefined') {
if (i == 0) {
return result;
}
rest = pieces.slice(pieces.length - i);
result = retrieveFromPath(result, rest);
if (typeof result != 'undefined') {
return result;
}
}
}
} | [
"function",
"getFromOld",
"(",
"old",
",",
"pieces",
")",
"{",
"var",
"length",
"=",
"pieces",
".",
"length",
",",
"result",
",",
"path",
",",
"rest",
",",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"path",
"=",
"pieces",
".",
"slice",
"(",
"0",
",",
"length",
"-",
"i",
")",
".",
"join",
"(",
"'.'",
")",
";",
"result",
"=",
"old",
"[",
"path",
"]",
";",
"if",
"(",
"typeof",
"result",
"!=",
"'undefined'",
")",
"{",
"if",
"(",
"i",
"==",
"0",
")",
"{",
"return",
"result",
";",
"}",
"rest",
"=",
"pieces",
".",
"slice",
"(",
"pieces",
".",
"length",
"-",
"i",
")",
";",
"result",
"=",
"retrieveFromPath",
"(",
"result",
",",
"rest",
")",
";",
"if",
"(",
"typeof",
"result",
"!=",
"'undefined'",
")",
"{",
"return",
"result",
";",
"}",
"}",
"}",
"}"
] | Find path in an "old" object
@author Jelle De Loecker <jelle@develry.be>
@since 1.0.10
@version 1.0.10
@param {Object} old The object to look in
@param {Array} pieces The path to look for
@return {Mixed} | [
"Find",
"path",
"in",
"an",
"old",
"object"
] | f20fd8e4aa3bcfe133f3c1a5b5b6ea3aa7060546 | https://github.com/skerit/json-dry/blob/f20fd8e4aa3bcfe133f3c1a5b5b6ea3aa7060546/lib/json-dry.js#L895-L923 |
22,997 | skerit/json-dry | lib/json-dry.js | retrieveFromPath | function retrieveFromPath(current, keys) {
var length = keys.length,
prev,
key,
i;
// Keys [''] always means the root
if (length == 1 && keys[0] === '') {
return current;
}
for (i = 0; i < length; i++) {
key = keys[i];
// Normalize the key
if (typeof key == 'number') {
// Allow
} else if (key.indexOf(safe_special_char) > -1) {
key = key.replace(safe_special_char_rg, special_char);
}
prev = current;
if (current) {
if (current.hasOwnProperty(key)) {
current = current[key];
} else {
return undefined;
}
} else {
return undefined;
}
}
return current;
} | javascript | function retrieveFromPath(current, keys) {
var length = keys.length,
prev,
key,
i;
// Keys [''] always means the root
if (length == 1 && keys[0] === '') {
return current;
}
for (i = 0; i < length; i++) {
key = keys[i];
// Normalize the key
if (typeof key == 'number') {
// Allow
} else if (key.indexOf(safe_special_char) > -1) {
key = key.replace(safe_special_char_rg, special_char);
}
prev = current;
if (current) {
if (current.hasOwnProperty(key)) {
current = current[key];
} else {
return undefined;
}
} else {
return undefined;
}
}
return current;
} | [
"function",
"retrieveFromPath",
"(",
"current",
",",
"keys",
")",
"{",
"var",
"length",
"=",
"keys",
".",
"length",
",",
"prev",
",",
"key",
",",
"i",
";",
"// Keys [''] always means the root",
"if",
"(",
"length",
"==",
"1",
"&&",
"keys",
"[",
"0",
"]",
"===",
"''",
")",
"{",
"return",
"current",
";",
"}",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"key",
"=",
"keys",
"[",
"i",
"]",
";",
"// Normalize the key",
"if",
"(",
"typeof",
"key",
"==",
"'number'",
")",
"{",
"// Allow",
"}",
"else",
"if",
"(",
"key",
".",
"indexOf",
"(",
"safe_special_char",
")",
">",
"-",
"1",
")",
"{",
"key",
"=",
"key",
".",
"replace",
"(",
"safe_special_char_rg",
",",
"special_char",
")",
";",
"}",
"prev",
"=",
"current",
";",
"if",
"(",
"current",
")",
"{",
"if",
"(",
"current",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"current",
"=",
"current",
"[",
"key",
"]",
";",
"}",
"else",
"{",
"return",
"undefined",
";",
"}",
"}",
"else",
"{",
"return",
"undefined",
";",
"}",
"}",
"return",
"current",
";",
"}"
] | Retrieve from path.
Set the given value, but only if the containing object exists.
@author Jelle De Loecker <jelle@develry.be>
@since 0.1.4
@version 1.0.10
@param {Object} current The object to look in
@param {Array} keys The path to look for
@param {Mixed} value Optional value to set
@return {Mixed} | [
"Retrieve",
"from",
"path",
".",
"Set",
"the",
"given",
"value",
"but",
"only",
"if",
"the",
"containing",
"object",
"exists",
"."
] | f20fd8e4aa3bcfe133f3c1a5b5b6ea3aa7060546 | https://github.com/skerit/json-dry/blob/f20fd8e4aa3bcfe133f3c1a5b5b6ea3aa7060546/lib/json-dry.js#L939-L975 |
22,998 | skerit/json-dry | lib/json-dry.js | fromPath | function fromPath(obj, path) {
var pieces,
here,
len,
i;
if (typeof path == 'string') {
pieces = path.split('.');
} else {
pieces = path;
}
here = obj;
// Go over every piece in the path
for (i = 0; i < pieces.length; i++) {
if (here != null) {
if (here.hasOwnProperty(pieces[i])) {
here = here[pieces[i]];
} else {
return null;
}
} else {
break;
}
}
return here;
} | javascript | function fromPath(obj, path) {
var pieces,
here,
len,
i;
if (typeof path == 'string') {
pieces = path.split('.');
} else {
pieces = path;
}
here = obj;
// Go over every piece in the path
for (i = 0; i < pieces.length; i++) {
if (here != null) {
if (here.hasOwnProperty(pieces[i])) {
here = here[pieces[i]];
} else {
return null;
}
} else {
break;
}
}
return here;
} | [
"function",
"fromPath",
"(",
"obj",
",",
"path",
")",
"{",
"var",
"pieces",
",",
"here",
",",
"len",
",",
"i",
";",
"if",
"(",
"typeof",
"path",
"==",
"'string'",
")",
"{",
"pieces",
"=",
"path",
".",
"split",
"(",
"'.'",
")",
";",
"}",
"else",
"{",
"pieces",
"=",
"path",
";",
"}",
"here",
"=",
"obj",
";",
"// Go over every piece in the path",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"pieces",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"here",
"!=",
"null",
")",
"{",
"if",
"(",
"here",
".",
"hasOwnProperty",
"(",
"pieces",
"[",
"i",
"]",
")",
")",
"{",
"here",
"=",
"here",
"[",
"pieces",
"[",
"i",
"]",
"]",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}",
"else",
"{",
"break",
";",
"}",
"}",
"return",
"here",
";",
"}"
] | Extract something from an object by the path
@author Jelle De Loecker <jelle@develry.be>
@since 0.1.0
@version 1.0.0
@param {Object} obj
@param {String} path
@return {Mixed} | [
"Extract",
"something",
"from",
"an",
"object",
"by",
"the",
"path"
] | f20fd8e4aa3bcfe133f3c1a5b5b6ea3aa7060546 | https://github.com/skerit/json-dry/blob/f20fd8e4aa3bcfe133f3c1a5b5b6ea3aa7060546/lib/json-dry.js#L989-L1018 |
22,999 | skerit/json-dry | lib/json-dry.js | setPath | function setPath(obj, keys, value, force) {
var here,
i;
here = obj;
for (i = 0; i < keys.length - 1; i++) {
if (here != null) {
if (here.hasOwnProperty(keys[i])) {
here = here[keys[i]];
} else {
if (force && here[keys[i]] == null) {
here[keys[i]] = {};
here = here[keys[i]];
continue;
}
return null;
}
}
}
here[keys[keys.length - 1]] = value;
} | javascript | function setPath(obj, keys, value, force) {
var here,
i;
here = obj;
for (i = 0; i < keys.length - 1; i++) {
if (here != null) {
if (here.hasOwnProperty(keys[i])) {
here = here[keys[i]];
} else {
if (force && here[keys[i]] == null) {
here[keys[i]] = {};
here = here[keys[i]];
continue;
}
return null;
}
}
}
here[keys[keys.length - 1]] = value;
} | [
"function",
"setPath",
"(",
"obj",
",",
"keys",
",",
"value",
",",
"force",
")",
"{",
"var",
"here",
",",
"i",
";",
"here",
"=",
"obj",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"keys",
".",
"length",
"-",
"1",
";",
"i",
"++",
")",
"{",
"if",
"(",
"here",
"!=",
"null",
")",
"{",
"if",
"(",
"here",
".",
"hasOwnProperty",
"(",
"keys",
"[",
"i",
"]",
")",
")",
"{",
"here",
"=",
"here",
"[",
"keys",
"[",
"i",
"]",
"]",
";",
"}",
"else",
"{",
"if",
"(",
"force",
"&&",
"here",
"[",
"keys",
"[",
"i",
"]",
"]",
"==",
"null",
")",
"{",
"here",
"[",
"keys",
"[",
"i",
"]",
"]",
"=",
"{",
"}",
";",
"here",
"=",
"here",
"[",
"keys",
"[",
"i",
"]",
"]",
";",
"continue",
";",
"}",
"return",
"null",
";",
"}",
"}",
"}",
"here",
"[",
"keys",
"[",
"keys",
".",
"length",
"-",
"1",
"]",
"]",
"=",
"value",
";",
"}"
] | Set something on the given path
@author Jelle De Loecker <jelle@develry.be>
@since 1.0.0
@version 1.0.2
@param {Object} obj
@param {Array} path
@param {Boolean} force If a piece of the path doesn't exist, create it
@return {Mixed} | [
"Set",
"something",
"on",
"the",
"given",
"path"
] | f20fd8e4aa3bcfe133f3c1a5b5b6ea3aa7060546 | https://github.com/skerit/json-dry/blob/f20fd8e4aa3bcfe133f3c1a5b5b6ea3aa7060546/lib/json-dry.js#L1033-L1058 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.