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
|
---|---|---|---|---|---|---|---|---|---|---|---|
38,600 |
jpettersson/node-ordered-merge-stream
|
index.js
|
emitData
|
function emitData() {
for(var i=0;i<streamQueue.length;i++) {
var dataQueue = streamQueue[i].dataQueue;
if(streamQueue[i].pending) {
return;
}
for(var j=0;j<dataQueue.length;j++) {
var data = dataQueue[j];
if(!!data) {
_this.emit('data', data);
dataQueue[j] = null;
return emitData();
}
}
}
if(currentStream === streamQueue.length) {
_this.emit('end');
}
}
|
javascript
|
function emitData() {
for(var i=0;i<streamQueue.length;i++) {
var dataQueue = streamQueue[i].dataQueue;
if(streamQueue[i].pending) {
return;
}
for(var j=0;j<dataQueue.length;j++) {
var data = dataQueue[j];
if(!!data) {
_this.emit('data', data);
dataQueue[j] = null;
return emitData();
}
}
}
if(currentStream === streamQueue.length) {
_this.emit('end');
}
}
|
[
"function",
"emitData",
"(",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"streamQueue",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"dataQueue",
"=",
"streamQueue",
"[",
"i",
"]",
".",
"dataQueue",
";",
"if",
"(",
"streamQueue",
"[",
"i",
"]",
".",
"pending",
")",
"{",
"return",
";",
"}",
"for",
"(",
"var",
"j",
"=",
"0",
";",
"j",
"<",
"dataQueue",
".",
"length",
";",
"j",
"++",
")",
"{",
"var",
"data",
"=",
"dataQueue",
"[",
"j",
"]",
";",
"if",
"(",
"!",
"!",
"data",
")",
"{",
"_this",
".",
"emit",
"(",
"'data'",
",",
"data",
")",
";",
"dataQueue",
"[",
"j",
"]",
"=",
"null",
";",
"return",
"emitData",
"(",
")",
";",
"}",
"}",
"}",
"if",
"(",
"currentStream",
"===",
"streamQueue",
".",
"length",
")",
"{",
"_this",
".",
"emit",
"(",
"'end'",
")",
";",
"}",
"}"
] |
Emit everything available so far in the queue
|
[
"Emit",
"everything",
"available",
"so",
"far",
"in",
"the",
"queue"
] |
5e19cd3dae8ffbdce4a74a147edb7f6b1c97f3ab
|
https://github.com/jpettersson/node-ordered-merge-stream/blob/5e19cd3dae8ffbdce4a74a147edb7f6b1c97f3ab/index.js#L14-L36
|
38,601 |
sethvincent/store-emitter
|
index.js
|
store
|
function store (action) {
if (!action || !isPlainObject(action)) {
throw new Error('action parameter is required and must be a plain object')
}
if (!action.type || typeof action.type !== 'string') {
throw new Error('type property of action is required and must be a string')
}
if (isEmitting) {
throw new Error('modifiers may not emit actions')
}
isEmitting = true
var oldState = extend(state)
state = modifier(action, oldState)
var newState = extend(state)
emitter.emit(action.type, action, newState, oldState)
isEmitting = false
}
|
javascript
|
function store (action) {
if (!action || !isPlainObject(action)) {
throw new Error('action parameter is required and must be a plain object')
}
if (!action.type || typeof action.type !== 'string') {
throw new Error('type property of action is required and must be a string')
}
if (isEmitting) {
throw new Error('modifiers may not emit actions')
}
isEmitting = true
var oldState = extend(state)
state = modifier(action, oldState)
var newState = extend(state)
emitter.emit(action.type, action, newState, oldState)
isEmitting = false
}
|
[
"function",
"store",
"(",
"action",
")",
"{",
"if",
"(",
"!",
"action",
"||",
"!",
"isPlainObject",
"(",
"action",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'action parameter is required and must be a plain object'",
")",
"}",
"if",
"(",
"!",
"action",
".",
"type",
"||",
"typeof",
"action",
".",
"type",
"!==",
"'string'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'type property of action is required and must be a string'",
")",
"}",
"if",
"(",
"isEmitting",
")",
"{",
"throw",
"new",
"Error",
"(",
"'modifiers may not emit actions'",
")",
"}",
"isEmitting",
"=",
"true",
"var",
"oldState",
"=",
"extend",
"(",
"state",
")",
"state",
"=",
"modifier",
"(",
"action",
",",
"oldState",
")",
"var",
"newState",
"=",
"extend",
"(",
"state",
")",
"emitter",
".",
"emit",
"(",
"action",
".",
"type",
",",
"action",
",",
"newState",
",",
"oldState",
")",
"isEmitting",
"=",
"false",
"}"
] |
Send an action to the store. Takes a single object parameter. Object must include a `type` property with a string value, and can contain any other properties.
@name store
@param {object} action
@param {string} action.type
@example
store({
type: 'example'
exampleValue: 'anything'
})
|
[
"Send",
"an",
"action",
"to",
"the",
"store",
".",
"Takes",
"a",
"single",
"object",
"parameter",
".",
"Object",
"must",
"include",
"a",
"type",
"property",
"with",
"a",
"string",
"value",
"and",
"can",
"contain",
"any",
"other",
"properties",
"."
] |
a58d19390f1ef08477d795831738019993f074d5
|
https://github.com/sethvincent/store-emitter/blob/a58d19390f1ef08477d795831738019993f074d5/index.js#L46-L66
|
38,602 |
rootsdev/gedcomx-js
|
src/core/Qualifier.js
|
function(json){
// Protect against forgetting the new keyword when calling the constructor
if(!(this instanceof Qualifier)){
return new Qualifier(json);
}
// If the given object is already an instance then just return it. DON'T copy it.
if(Qualifier.isInstance(json)){
return json;
}
this.init(json);
}
|
javascript
|
function(json){
// Protect against forgetting the new keyword when calling the constructor
if(!(this instanceof Qualifier)){
return new Qualifier(json);
}
// If the given object is already an instance then just return it. DON'T copy it.
if(Qualifier.isInstance(json)){
return json;
}
this.init(json);
}
|
[
"function",
"(",
"json",
")",
"{",
"// Protect against forgetting the new keyword when calling the constructor",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Qualifier",
")",
")",
"{",
"return",
"new",
"Qualifier",
"(",
"json",
")",
";",
"}",
"// If the given object is already an instance then just return it. DON'T copy it.",
"if",
"(",
"Qualifier",
".",
"isInstance",
"(",
"json",
")",
")",
"{",
"return",
"json",
";",
"}",
"this",
".",
"init",
"(",
"json",
")",
";",
"}"
] |
Qualifiers are used to supply additional details about a piece of data.
@see {@link https://github.com/FamilySearch/gedcomx/blob/master/specifications/json-format-specification.md#qualifier|GEDCOM X JSON Spec}
@class
@extends Base
@param {Object} [json]
|
[
"Qualifiers",
"are",
"used",
"to",
"supply",
"additional",
"details",
"about",
"a",
"piece",
"of",
"data",
"."
] |
08b2fcde96f1e301c78561bfb7a8b0cac606e26e
|
https://github.com/rootsdev/gedcomx-js/blob/08b2fcde96f1e301c78561bfb7a8b0cac606e26e/src/core/Qualifier.js#L13-L26
|
|
38,603 |
fullcube/loopback-component-templates
|
lib/index.js
|
hasRemoteMethod
|
function hasRemoteMethod(model, methodName) {
return model.sharedClass
.methods({ includeDisabled: false })
.map(sharedMethod => sharedMethod.name)
.includes(methodName)
}
|
javascript
|
function hasRemoteMethod(model, methodName) {
return model.sharedClass
.methods({ includeDisabled: false })
.map(sharedMethod => sharedMethod.name)
.includes(methodName)
}
|
[
"function",
"hasRemoteMethod",
"(",
"model",
",",
"methodName",
")",
"{",
"return",
"model",
".",
"sharedClass",
".",
"methods",
"(",
"{",
"includeDisabled",
":",
"false",
"}",
")",
".",
"map",
"(",
"sharedMethod",
"=>",
"sharedMethod",
".",
"name",
")",
".",
"includes",
"(",
"methodName",
")",
"}"
] |
Helper method to check if a remote method exists on a model
@param model The LoopBack Model
@param methodName The name of the Remote Method
@returns {boolean}
|
[
"Helper",
"method",
"to",
"check",
"if",
"a",
"remote",
"method",
"exists",
"on",
"a",
"model"
] |
8fc81955d1ddae805bc6d66743d8e359d1cfac5f
|
https://github.com/fullcube/loopback-component-templates/blob/8fc81955d1ddae805bc6d66743d8e359d1cfac5f/lib/index.js#L13-L18
|
38,604 |
fullcube/loopback-component-templates
|
lib/index.js
|
addRemoteMethods
|
function addRemoteMethods(app) {
return Object.keys(app.models).forEach(modelName => {
const Model = app.models[modelName]
if (typeof Model._templates !== 'function') {
return null
}
return Object.keys(Model._templates()).forEach(templateName => {
const fnName = `_template_${templateName}`
const fnNameRemote = `_template_${templateName}_remote`
const path = `/${fnName}`
// Don't add the method if it already exists on the model
if (typeof Model[fnName] === 'function') {
debug('Method already exists: %s.%s', Model.modelName, fnName)
return null
}
// Don't add the remote method if it already exists on the model
if (hasRemoteMethod(Model, fnNameRemote)) {
debug('Remote method already exists: %s.%s', Model.modelName, fnName)
return null
}
debug('Create remote method for %s.%s', Model.modelName, fnName)
// The normal method does not need to be wrapped in a promise
Model[fnName] = (options, params) => {
// Get the random data
const template = Model._templates(params)[templateName]
// Overwrite the template with the passed in options
_.forEach(options, (value, key) => {
_.set(template, key, value)
})
return template
}
const fnSpecRemote = {
description: `Generate template ${templateName}`,
accepts: [
{ type: 'Object', arg: 'options', description: 'Overwrite values of template' },
{ type: 'Object', arg: 'params', description: 'Pass parameters into the template method' },
],
returns: [ { type: 'Object', arg: 'result', root: true } ],
http: { path, verb: 'get' },
}
// Support for loopback 2.x.
if (app.loopback.version.startsWith(2)) {
fnSpecRemote.isStatic = true
}
// Define the remote method on the model
Model.remoteMethod(fnNameRemote, fnSpecRemote)
// The remote method needs to be wrapped in a promise
Model[fnNameRemote] = (options, params) => new Promise(resolve => resolve(Model[fnName](options, params)))
// Send result as plain text if the content is a string
Model.afterRemote(fnNameRemote, (ctx, result, next) => {
if (typeof ctx.result !== 'string') {
return next()
}
ctx.res.setHeader('Content-Type', 'text/plain')
return ctx.res.end(ctx.result)
})
return true
})
})
}
|
javascript
|
function addRemoteMethods(app) {
return Object.keys(app.models).forEach(modelName => {
const Model = app.models[modelName]
if (typeof Model._templates !== 'function') {
return null
}
return Object.keys(Model._templates()).forEach(templateName => {
const fnName = `_template_${templateName}`
const fnNameRemote = `_template_${templateName}_remote`
const path = `/${fnName}`
// Don't add the method if it already exists on the model
if (typeof Model[fnName] === 'function') {
debug('Method already exists: %s.%s', Model.modelName, fnName)
return null
}
// Don't add the remote method if it already exists on the model
if (hasRemoteMethod(Model, fnNameRemote)) {
debug('Remote method already exists: %s.%s', Model.modelName, fnName)
return null
}
debug('Create remote method for %s.%s', Model.modelName, fnName)
// The normal method does not need to be wrapped in a promise
Model[fnName] = (options, params) => {
// Get the random data
const template = Model._templates(params)[templateName]
// Overwrite the template with the passed in options
_.forEach(options, (value, key) => {
_.set(template, key, value)
})
return template
}
const fnSpecRemote = {
description: `Generate template ${templateName}`,
accepts: [
{ type: 'Object', arg: 'options', description: 'Overwrite values of template' },
{ type: 'Object', arg: 'params', description: 'Pass parameters into the template method' },
],
returns: [ { type: 'Object', arg: 'result', root: true } ],
http: { path, verb: 'get' },
}
// Support for loopback 2.x.
if (app.loopback.version.startsWith(2)) {
fnSpecRemote.isStatic = true
}
// Define the remote method on the model
Model.remoteMethod(fnNameRemote, fnSpecRemote)
// The remote method needs to be wrapped in a promise
Model[fnNameRemote] = (options, params) => new Promise(resolve => resolve(Model[fnName](options, params)))
// Send result as plain text if the content is a string
Model.afterRemote(fnNameRemote, (ctx, result, next) => {
if (typeof ctx.result !== 'string') {
return next()
}
ctx.res.setHeader('Content-Type', 'text/plain')
return ctx.res.end(ctx.result)
})
return true
})
})
}
|
[
"function",
"addRemoteMethods",
"(",
"app",
")",
"{",
"return",
"Object",
".",
"keys",
"(",
"app",
".",
"models",
")",
".",
"forEach",
"(",
"modelName",
"=>",
"{",
"const",
"Model",
"=",
"app",
".",
"models",
"[",
"modelName",
"]",
"if",
"(",
"typeof",
"Model",
".",
"_templates",
"!==",
"'function'",
")",
"{",
"return",
"null",
"}",
"return",
"Object",
".",
"keys",
"(",
"Model",
".",
"_templates",
"(",
")",
")",
".",
"forEach",
"(",
"templateName",
"=>",
"{",
"const",
"fnName",
"=",
"`",
"${",
"templateName",
"}",
"`",
"const",
"fnNameRemote",
"=",
"`",
"${",
"templateName",
"}",
"`",
"const",
"path",
"=",
"`",
"${",
"fnName",
"}",
"`",
"// Don't add the method if it already exists on the model",
"if",
"(",
"typeof",
"Model",
"[",
"fnName",
"]",
"===",
"'function'",
")",
"{",
"debug",
"(",
"'Method already exists: %s.%s'",
",",
"Model",
".",
"modelName",
",",
"fnName",
")",
"return",
"null",
"}",
"// Don't add the remote method if it already exists on the model",
"if",
"(",
"hasRemoteMethod",
"(",
"Model",
",",
"fnNameRemote",
")",
")",
"{",
"debug",
"(",
"'Remote method already exists: %s.%s'",
",",
"Model",
".",
"modelName",
",",
"fnName",
")",
"return",
"null",
"}",
"debug",
"(",
"'Create remote method for %s.%s'",
",",
"Model",
".",
"modelName",
",",
"fnName",
")",
"// The normal method does not need to be wrapped in a promise",
"Model",
"[",
"fnName",
"]",
"=",
"(",
"options",
",",
"params",
")",
"=>",
"{",
"// Get the random data",
"const",
"template",
"=",
"Model",
".",
"_templates",
"(",
"params",
")",
"[",
"templateName",
"]",
"// Overwrite the template with the passed in options",
"_",
".",
"forEach",
"(",
"options",
",",
"(",
"value",
",",
"key",
")",
"=>",
"{",
"_",
".",
"set",
"(",
"template",
",",
"key",
",",
"value",
")",
"}",
")",
"return",
"template",
"}",
"const",
"fnSpecRemote",
"=",
"{",
"description",
":",
"`",
"${",
"templateName",
"}",
"`",
",",
"accepts",
":",
"[",
"{",
"type",
":",
"'Object'",
",",
"arg",
":",
"'options'",
",",
"description",
":",
"'Overwrite values of template'",
"}",
",",
"{",
"type",
":",
"'Object'",
",",
"arg",
":",
"'params'",
",",
"description",
":",
"'Pass parameters into the template method'",
"}",
",",
"]",
",",
"returns",
":",
"[",
"{",
"type",
":",
"'Object'",
",",
"arg",
":",
"'result'",
",",
"root",
":",
"true",
"}",
"]",
",",
"http",
":",
"{",
"path",
",",
"verb",
":",
"'get'",
"}",
",",
"}",
"// Support for loopback 2.x.",
"if",
"(",
"app",
".",
"loopback",
".",
"version",
".",
"startsWith",
"(",
"2",
")",
")",
"{",
"fnSpecRemote",
".",
"isStatic",
"=",
"true",
"}",
"// Define the remote method on the model",
"Model",
".",
"remoteMethod",
"(",
"fnNameRemote",
",",
"fnSpecRemote",
")",
"// The remote method needs to be wrapped in a promise",
"Model",
"[",
"fnNameRemote",
"]",
"=",
"(",
"options",
",",
"params",
")",
"=>",
"new",
"Promise",
"(",
"resolve",
"=>",
"resolve",
"(",
"Model",
"[",
"fnName",
"]",
"(",
"options",
",",
"params",
")",
")",
")",
"// Send result as plain text if the content is a string",
"Model",
".",
"afterRemote",
"(",
"fnNameRemote",
",",
"(",
"ctx",
",",
"result",
",",
"next",
")",
"=>",
"{",
"if",
"(",
"typeof",
"ctx",
".",
"result",
"!==",
"'string'",
")",
"{",
"return",
"next",
"(",
")",
"}",
"ctx",
".",
"res",
".",
"setHeader",
"(",
"'Content-Type'",
",",
"'text/plain'",
")",
"return",
"ctx",
".",
"res",
".",
"end",
"(",
"ctx",
".",
"result",
")",
"}",
")",
"return",
"true",
"}",
")",
"}",
")",
"}"
] |
Add remote methods for each template.
@param {Object} app loopback application
@param {Object} config component configuration
|
[
"Add",
"remote",
"methods",
"for",
"each",
"template",
"."
] |
8fc81955d1ddae805bc6d66743d8e359d1cfac5f
|
https://github.com/fullcube/loopback-component-templates/blob/8fc81955d1ddae805bc6d66743d8e359d1cfac5f/lib/index.js#L26-L98
|
38,605 |
fullcube/loopback-component-templates
|
lib/index.js
|
addAcls
|
function addAcls(app, config) {
config.acls = config.acls || []
return Promise.resolve(Object.keys(app.models)).mapSeries(modelName => {
const Model = app.models[modelName]
if (typeof Model._templates !== 'function') {
return null
}
return Promise.resolve(Object.keys(Model._templates()))
.mapSeries(templateName => {
const fnNameRemote = `_template_${templateName}_remote`
return Promise.resolve(config.acls).mapSeries(acl => {
const templateAcl = Object.assign({}, acl)
templateAcl.model = modelName
templateAcl.property = fnNameRemote
debug('Create ACL entry for %s.%s ', modelName, fnNameRemote)
return app.models.ACL.create(templateAcl)
})
})
})
}
|
javascript
|
function addAcls(app, config) {
config.acls = config.acls || []
return Promise.resolve(Object.keys(app.models)).mapSeries(modelName => {
const Model = app.models[modelName]
if (typeof Model._templates !== 'function') {
return null
}
return Promise.resolve(Object.keys(Model._templates()))
.mapSeries(templateName => {
const fnNameRemote = `_template_${templateName}_remote`
return Promise.resolve(config.acls).mapSeries(acl => {
const templateAcl = Object.assign({}, acl)
templateAcl.model = modelName
templateAcl.property = fnNameRemote
debug('Create ACL entry for %s.%s ', modelName, fnNameRemote)
return app.models.ACL.create(templateAcl)
})
})
})
}
|
[
"function",
"addAcls",
"(",
"app",
",",
"config",
")",
"{",
"config",
".",
"acls",
"=",
"config",
".",
"acls",
"||",
"[",
"]",
"return",
"Promise",
".",
"resolve",
"(",
"Object",
".",
"keys",
"(",
"app",
".",
"models",
")",
")",
".",
"mapSeries",
"(",
"modelName",
"=>",
"{",
"const",
"Model",
"=",
"app",
".",
"models",
"[",
"modelName",
"]",
"if",
"(",
"typeof",
"Model",
".",
"_templates",
"!==",
"'function'",
")",
"{",
"return",
"null",
"}",
"return",
"Promise",
".",
"resolve",
"(",
"Object",
".",
"keys",
"(",
"Model",
".",
"_templates",
"(",
")",
")",
")",
".",
"mapSeries",
"(",
"templateName",
"=>",
"{",
"const",
"fnNameRemote",
"=",
"`",
"${",
"templateName",
"}",
"`",
"return",
"Promise",
".",
"resolve",
"(",
"config",
".",
"acls",
")",
".",
"mapSeries",
"(",
"acl",
"=>",
"{",
"const",
"templateAcl",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"acl",
")",
"templateAcl",
".",
"model",
"=",
"modelName",
"templateAcl",
".",
"property",
"=",
"fnNameRemote",
"debug",
"(",
"'Create ACL entry for %s.%s '",
",",
"modelName",
",",
"fnNameRemote",
")",
"return",
"app",
".",
"models",
".",
"ACL",
".",
"create",
"(",
"templateAcl",
")",
"}",
")",
"}",
")",
"}",
")",
"}"
] |
Add ACLs for each template.
@param {Object} app loopback application
@param {Object} config component configuration
|
[
"Add",
"ACLs",
"for",
"each",
"template",
"."
] |
8fc81955d1ddae805bc6d66743d8e359d1cfac5f
|
https://github.com/fullcube/loopback-component-templates/blob/8fc81955d1ddae805bc6d66743d8e359d1cfac5f/lib/index.js#L106-L130
|
38,606 |
FormBucket/xander
|
src/router.js
|
match
|
function match(routes = [], path) {
for (var i = 0; i < routes.length; i++) {
var re = pathRegexps[routes[i].path] || pathToRegexp(routes[i].path);
pathRegexps[routes[i].path] = re;
if (re && re.test(path)) {
return { re, route: routes[i] };
}
}
return false;
}
|
javascript
|
function match(routes = [], path) {
for (var i = 0; i < routes.length; i++) {
var re = pathRegexps[routes[i].path] || pathToRegexp(routes[i].path);
pathRegexps[routes[i].path] = re;
if (re && re.test(path)) {
return { re, route: routes[i] };
}
}
return false;
}
|
[
"function",
"match",
"(",
"routes",
"=",
"[",
"]",
",",
"path",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"routes",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"re",
"=",
"pathRegexps",
"[",
"routes",
"[",
"i",
"]",
".",
"path",
"]",
"||",
"pathToRegexp",
"(",
"routes",
"[",
"i",
"]",
".",
"path",
")",
";",
"pathRegexps",
"[",
"routes",
"[",
"i",
"]",
".",
"path",
"]",
"=",
"re",
";",
"if",
"(",
"re",
"&&",
"re",
".",
"test",
"(",
"path",
")",
")",
"{",
"return",
"{",
"re",
",",
"route",
":",
"routes",
"[",
"i",
"]",
"}",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Return the first matching route.
|
[
"Return",
"the",
"first",
"matching",
"route",
"."
] |
6e63fdaa5cbacd125f661e87d703a4160d564e9f
|
https://github.com/FormBucket/xander/blob/6e63fdaa5cbacd125f661e87d703a4160d564e9f/src/router.js#L24-L35
|
38,607 |
rootsdev/gedcomx-js
|
src/rs/DisplayProperties.js
|
function(json){
// Protect against forgetting the new keyword when calling the constructor
if(!(this instanceof DisplayProperties)){
return new DisplayProperties(json);
}
// If the given object is already an instance then just return it. DON'T copy it.
if(DisplayProperties.isInstance(json)){
return json;
}
this.init(json);
}
|
javascript
|
function(json){
// Protect against forgetting the new keyword when calling the constructor
if(!(this instanceof DisplayProperties)){
return new DisplayProperties(json);
}
// If the given object is already an instance then just return it. DON'T copy it.
if(DisplayProperties.isInstance(json)){
return json;
}
this.init(json);
}
|
[
"function",
"(",
"json",
")",
"{",
"// Protect against forgetting the new keyword when calling the constructor",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"DisplayProperties",
")",
")",
"{",
"return",
"new",
"DisplayProperties",
"(",
"json",
")",
";",
"}",
"// If the given object is already an instance then just return it. DON'T copy it.",
"if",
"(",
"DisplayProperties",
".",
"isInstance",
"(",
"json",
")",
")",
"{",
"return",
"json",
";",
"}",
"this",
".",
"init",
"(",
"json",
")",
";",
"}"
] |
A set of properties for convenience in displaying a summary of a person to a user.
@see {@link https://github.com/FamilySearch/gedcomx-rs/blob/master/specifications/rs-specification.md#display-properties-data-type|GEDCOM X RS Spec}
@class DisplayProperties
@extends Base
@param {Object} [json]
|
[
"A",
"set",
"of",
"properties",
"for",
"convenience",
"in",
"displaying",
"a",
"summary",
"of",
"a",
"person",
"to",
"a",
"user",
"."
] |
08b2fcde96f1e301c78561bfb7a8b0cac606e26e
|
https://github.com/rootsdev/gedcomx-js/blob/08b2fcde96f1e301c78561bfb7a8b0cac606e26e/src/rs/DisplayProperties.js#L15-L28
|
|
38,608 |
rootsdev/gedcomx-js
|
src/atom/AtomEntry.js
|
function(json){
// Protect against forgetting the new keyword when calling the constructor
if(!(this instanceof AtomEntry)){
return new AtomEntry(json);
}
// If the given object is already an instance then just return it. DON'T copy it.
if(AtomEntry.isInstance(json)){
return json;
}
this.init(json);
}
|
javascript
|
function(json){
// Protect against forgetting the new keyword when calling the constructor
if(!(this instanceof AtomEntry)){
return new AtomEntry(json);
}
// If the given object is already an instance then just return it. DON'T copy it.
if(AtomEntry.isInstance(json)){
return json;
}
this.init(json);
}
|
[
"function",
"(",
"json",
")",
"{",
"// Protect against forgetting the new keyword when calling the constructor",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"AtomEntry",
")",
")",
"{",
"return",
"new",
"AtomEntry",
"(",
"json",
")",
";",
"}",
"// If the given object is already an instance then just return it. DON'T copy it.",
"if",
"(",
"AtomEntry",
".",
"isInstance",
"(",
"json",
")",
")",
"{",
"return",
"json",
";",
"}",
"this",
".",
"init",
"(",
"json",
")",
";",
"}"
] |
An individual atom feed entry.
@see {@link https://github.com/FamilySearch/gedcomx-rs/blob/master/specifications/atom-model-specification.md#atom-json-media-type|GEDCOM X Atom JSON Spec}
@see {@link https://tools.ietf.org/html/rfc4287#section-4.1.2|RFC 4287}
@class AtomEntry
@extends AtomCommon
@param {Object} [json]
|
[
"An",
"individual",
"atom",
"feed",
"entry",
"."
] |
08b2fcde96f1e301c78561bfb7a8b0cac606e26e
|
https://github.com/rootsdev/gedcomx-js/blob/08b2fcde96f1e301c78561bfb7a8b0cac606e26e/src/atom/AtomEntry.js#L16-L29
|
|
38,609 |
FormBucket/xander
|
src/store.js
|
Dispatcher
|
function Dispatcher() {
let lastId = 1;
let prefix = "ID_";
let callbacks = {};
let isPending = {};
let isHandled = {};
let isDispatching = false;
let pendingPayload = null;
function invokeCallback(id) {
isPending[id] = true;
callbacks[id](pendingPayload);
isHandled[id] = true;
}
this.register = callback => {
let id = prefix + lastId++;
callbacks[id] = callback;
return id;
};
this.unregister = id => {
if (!callbacks.hasOwnProperty(id))
return new Error("Cannot unregister unknown ID!");
delete callbacks[id];
return id;
};
this.waitFor = ids => {
for (var i = 0; i < ids.length; i++) {
var id = ids[id];
if (isPending[id]) {
return new Error("Circular dependency waiting for " + id);
}
if (!callbacks[id]) {
return new Error(`waitFor: ${id} is not a registered callback.`);
}
invokeCallback(id);
}
return undefined;
};
this.dispatch = payload => {
if (isDispatching) return new Error("Cannot dispatch while dispatching.");
// start
for (var id in callbacks) {
isPending[id] = false;
isHandled[id] = false;
}
pendingPayload = payload;
isDispatching = true;
// run each callback.
try {
for (var id in callbacks) {
if (isPending[id]) continue;
invokeCallback(id);
}
} finally {
pendingPayload = null;
isDispatching = false;
}
return payload;
};
}
|
javascript
|
function Dispatcher() {
let lastId = 1;
let prefix = "ID_";
let callbacks = {};
let isPending = {};
let isHandled = {};
let isDispatching = false;
let pendingPayload = null;
function invokeCallback(id) {
isPending[id] = true;
callbacks[id](pendingPayload);
isHandled[id] = true;
}
this.register = callback => {
let id = prefix + lastId++;
callbacks[id] = callback;
return id;
};
this.unregister = id => {
if (!callbacks.hasOwnProperty(id))
return new Error("Cannot unregister unknown ID!");
delete callbacks[id];
return id;
};
this.waitFor = ids => {
for (var i = 0; i < ids.length; i++) {
var id = ids[id];
if (isPending[id]) {
return new Error("Circular dependency waiting for " + id);
}
if (!callbacks[id]) {
return new Error(`waitFor: ${id} is not a registered callback.`);
}
invokeCallback(id);
}
return undefined;
};
this.dispatch = payload => {
if (isDispatching) return new Error("Cannot dispatch while dispatching.");
// start
for (var id in callbacks) {
isPending[id] = false;
isHandled[id] = false;
}
pendingPayload = payload;
isDispatching = true;
// run each callback.
try {
for (var id in callbacks) {
if (isPending[id]) continue;
invokeCallback(id);
}
} finally {
pendingPayload = null;
isDispatching = false;
}
return payload;
};
}
|
[
"function",
"Dispatcher",
"(",
")",
"{",
"let",
"lastId",
"=",
"1",
";",
"let",
"prefix",
"=",
"\"ID_\"",
";",
"let",
"callbacks",
"=",
"{",
"}",
";",
"let",
"isPending",
"=",
"{",
"}",
";",
"let",
"isHandled",
"=",
"{",
"}",
";",
"let",
"isDispatching",
"=",
"false",
";",
"let",
"pendingPayload",
"=",
"null",
";",
"function",
"invokeCallback",
"(",
"id",
")",
"{",
"isPending",
"[",
"id",
"]",
"=",
"true",
";",
"callbacks",
"[",
"id",
"]",
"(",
"pendingPayload",
")",
";",
"isHandled",
"[",
"id",
"]",
"=",
"true",
";",
"}",
"this",
".",
"register",
"=",
"callback",
"=>",
"{",
"let",
"id",
"=",
"prefix",
"+",
"lastId",
"++",
";",
"callbacks",
"[",
"id",
"]",
"=",
"callback",
";",
"return",
"id",
";",
"}",
";",
"this",
".",
"unregister",
"=",
"id",
"=>",
"{",
"if",
"(",
"!",
"callbacks",
".",
"hasOwnProperty",
"(",
"id",
")",
")",
"return",
"new",
"Error",
"(",
"\"Cannot unregister unknown ID!\"",
")",
";",
"delete",
"callbacks",
"[",
"id",
"]",
";",
"return",
"id",
";",
"}",
";",
"this",
".",
"waitFor",
"=",
"ids",
"=>",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"ids",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"id",
"=",
"ids",
"[",
"id",
"]",
";",
"if",
"(",
"isPending",
"[",
"id",
"]",
")",
"{",
"return",
"new",
"Error",
"(",
"\"Circular dependency waiting for \"",
"+",
"id",
")",
";",
"}",
"if",
"(",
"!",
"callbacks",
"[",
"id",
"]",
")",
"{",
"return",
"new",
"Error",
"(",
"`",
"${",
"id",
"}",
"`",
")",
";",
"}",
"invokeCallback",
"(",
"id",
")",
";",
"}",
"return",
"undefined",
";",
"}",
";",
"this",
".",
"dispatch",
"=",
"payload",
"=>",
"{",
"if",
"(",
"isDispatching",
")",
"return",
"new",
"Error",
"(",
"\"Cannot dispatch while dispatching.\"",
")",
";",
"// start",
"for",
"(",
"var",
"id",
"in",
"callbacks",
")",
"{",
"isPending",
"[",
"id",
"]",
"=",
"false",
";",
"isHandled",
"[",
"id",
"]",
"=",
"false",
";",
"}",
"pendingPayload",
"=",
"payload",
";",
"isDispatching",
"=",
"true",
";",
"// run each callback.",
"try",
"{",
"for",
"(",
"var",
"id",
"in",
"callbacks",
")",
"{",
"if",
"(",
"isPending",
"[",
"id",
"]",
")",
"continue",
";",
"invokeCallback",
"(",
"id",
")",
";",
"}",
"}",
"finally",
"{",
"pendingPayload",
"=",
"null",
";",
"isDispatching",
"=",
"false",
";",
"}",
"return",
"payload",
";",
"}",
";",
"}"
] |
Based on Facebook's Flux dispatcher class.
|
[
"Based",
"on",
"Facebook",
"s",
"Flux",
"dispatcher",
"class",
"."
] |
6e63fdaa5cbacd125f661e87d703a4160d564e9f
|
https://github.com/FormBucket/xander/blob/6e63fdaa5cbacd125f661e87d703a4160d564e9f/src/store.js#L5-L75
|
38,610 |
neagle/smartgamer
|
index.js
|
function () {
if (sequence) {
var localNodes = sequence.nodes;
var localIndex = (localNodes) ? localNodes.indexOf(node) : null;
if (localNodes) {
if (localIndex === (localNodes.length - 1)) {
return sequence.sequences || [];
} else {
return [];
}
}
}
}
|
javascript
|
function () {
if (sequence) {
var localNodes = sequence.nodes;
var localIndex = (localNodes) ? localNodes.indexOf(node) : null;
if (localNodes) {
if (localIndex === (localNodes.length - 1)) {
return sequence.sequences || [];
} else {
return [];
}
}
}
}
|
[
"function",
"(",
")",
"{",
"if",
"(",
"sequence",
")",
"{",
"var",
"localNodes",
"=",
"sequence",
".",
"nodes",
";",
"var",
"localIndex",
"=",
"(",
"localNodes",
")",
"?",
"localNodes",
".",
"indexOf",
"(",
"node",
")",
":",
"null",
";",
"if",
"(",
"localNodes",
")",
"{",
"if",
"(",
"localIndex",
"===",
"(",
"localNodes",
".",
"length",
"-",
"1",
")",
")",
"{",
"return",
"sequence",
".",
"sequences",
"||",
"[",
"]",
";",
"}",
"else",
"{",
"return",
"[",
"]",
";",
"}",
"}",
"}",
"}"
] |
Return any variations available at the current move
|
[
"Return",
"any",
"variations",
"available",
"at",
"the",
"current",
"move"
] |
83a4b47c476729a19f8d04c165c0c10b69095d62
|
https://github.com/neagle/smartgamer/blob/83a4b47c476729a19f8d04c165c0c10b69095d62/index.js#L65-L78
|
|
38,611 |
neagle/smartgamer
|
index.js
|
function (variation) {
variation = variation || 0;
var localNodes = sequence.nodes;
var localIndex = (localNodes) ? localNodes.indexOf(node) : null;
// If there are no additional nodes in this sequence,
// advance to the next one
if (localIndex === null || localIndex >= (localNodes.length - 1)) {
if (sequence.sequences) {
if (sequence.sequences[variation]) {
sequence = sequence.sequences[variation];
} else {
sequence = sequence.sequences[0];
}
node = sequence.nodes[0];
// Note the fork chosen for this variation in the path
this.path[this.path.m] = variation;
this.path.m += 1;
} else {
// End of sequence / game
return this;
}
} else {
node = localNodes[localIndex + 1];
this.path.m += 1;
}
return this;
}
|
javascript
|
function (variation) {
variation = variation || 0;
var localNodes = sequence.nodes;
var localIndex = (localNodes) ? localNodes.indexOf(node) : null;
// If there are no additional nodes in this sequence,
// advance to the next one
if (localIndex === null || localIndex >= (localNodes.length - 1)) {
if (sequence.sequences) {
if (sequence.sequences[variation]) {
sequence = sequence.sequences[variation];
} else {
sequence = sequence.sequences[0];
}
node = sequence.nodes[0];
// Note the fork chosen for this variation in the path
this.path[this.path.m] = variation;
this.path.m += 1;
} else {
// End of sequence / game
return this;
}
} else {
node = localNodes[localIndex + 1];
this.path.m += 1;
}
return this;
}
|
[
"function",
"(",
"variation",
")",
"{",
"variation",
"=",
"variation",
"||",
"0",
";",
"var",
"localNodes",
"=",
"sequence",
".",
"nodes",
";",
"var",
"localIndex",
"=",
"(",
"localNodes",
")",
"?",
"localNodes",
".",
"indexOf",
"(",
"node",
")",
":",
"null",
";",
"// If there are no additional nodes in this sequence,",
"// advance to the next one",
"if",
"(",
"localIndex",
"===",
"null",
"||",
"localIndex",
">=",
"(",
"localNodes",
".",
"length",
"-",
"1",
")",
")",
"{",
"if",
"(",
"sequence",
".",
"sequences",
")",
"{",
"if",
"(",
"sequence",
".",
"sequences",
"[",
"variation",
"]",
")",
"{",
"sequence",
"=",
"sequence",
".",
"sequences",
"[",
"variation",
"]",
";",
"}",
"else",
"{",
"sequence",
"=",
"sequence",
".",
"sequences",
"[",
"0",
"]",
";",
"}",
"node",
"=",
"sequence",
".",
"nodes",
"[",
"0",
"]",
";",
"// Note the fork chosen for this variation in the path",
"this",
".",
"path",
"[",
"this",
".",
"path",
".",
"m",
"]",
"=",
"variation",
";",
"this",
".",
"path",
".",
"m",
"+=",
"1",
";",
"}",
"else",
"{",
"// End of sequence / game",
"return",
"this",
";",
"}",
"}",
"else",
"{",
"node",
"=",
"localNodes",
"[",
"localIndex",
"+",
"1",
"]",
";",
"this",
".",
"path",
".",
"m",
"+=",
"1",
";",
"}",
"return",
"this",
";",
"}"
] |
Go to the next move
|
[
"Go",
"to",
"the",
"next",
"move"
] |
83a4b47c476729a19f8d04c165c0c10b69095d62
|
https://github.com/neagle/smartgamer/blob/83a4b47c476729a19f8d04c165c0c10b69095d62/index.js#L83-L114
|
|
38,612 |
neagle/smartgamer
|
index.js
|
function () {
var localNodes = sequence.nodes;
var localIndex = (localNodes) ? localNodes.indexOf(node) : null;
// Delete any variation forks at this point
// TODO: Make this configurable... we should keep this if we're
// remembering chosen paths
delete this.path[this.path.m];
if (!localIndex || localIndex === 0) {
if (sequence.parent && !sequence.parent.gameTrees) {
sequence = sequence.parent;
if (sequence.nodes) {
node = sequence.nodes[sequence.nodes.length - 1];
this.path.m -= 1;
} else {
node = null;
}
} else {
// Already at the beginning
return this;
}
} else {
node = localNodes[localIndex - 1];
this.path.m -= 1;
}
return this;
}
|
javascript
|
function () {
var localNodes = sequence.nodes;
var localIndex = (localNodes) ? localNodes.indexOf(node) : null;
// Delete any variation forks at this point
// TODO: Make this configurable... we should keep this if we're
// remembering chosen paths
delete this.path[this.path.m];
if (!localIndex || localIndex === 0) {
if (sequence.parent && !sequence.parent.gameTrees) {
sequence = sequence.parent;
if (sequence.nodes) {
node = sequence.nodes[sequence.nodes.length - 1];
this.path.m -= 1;
} else {
node = null;
}
} else {
// Already at the beginning
return this;
}
} else {
node = localNodes[localIndex - 1];
this.path.m -= 1;
}
return this;
}
|
[
"function",
"(",
")",
"{",
"var",
"localNodes",
"=",
"sequence",
".",
"nodes",
";",
"var",
"localIndex",
"=",
"(",
"localNodes",
")",
"?",
"localNodes",
".",
"indexOf",
"(",
"node",
")",
":",
"null",
";",
"// Delete any variation forks at this point",
"// TODO: Make this configurable... we should keep this if we're",
"// remembering chosen paths",
"delete",
"this",
".",
"path",
"[",
"this",
".",
"path",
".",
"m",
"]",
";",
"if",
"(",
"!",
"localIndex",
"||",
"localIndex",
"===",
"0",
")",
"{",
"if",
"(",
"sequence",
".",
"parent",
"&&",
"!",
"sequence",
".",
"parent",
".",
"gameTrees",
")",
"{",
"sequence",
"=",
"sequence",
".",
"parent",
";",
"if",
"(",
"sequence",
".",
"nodes",
")",
"{",
"node",
"=",
"sequence",
".",
"nodes",
"[",
"sequence",
".",
"nodes",
".",
"length",
"-",
"1",
"]",
";",
"this",
".",
"path",
".",
"m",
"-=",
"1",
";",
"}",
"else",
"{",
"node",
"=",
"null",
";",
"}",
"}",
"else",
"{",
"// Already at the beginning",
"return",
"this",
";",
"}",
"}",
"else",
"{",
"node",
"=",
"localNodes",
"[",
"localIndex",
"-",
"1",
"]",
";",
"this",
".",
"path",
".",
"m",
"-=",
"1",
";",
"}",
"return",
"this",
";",
"}"
] |
Go to the previous move
|
[
"Go",
"to",
"the",
"previous",
"move"
] |
83a4b47c476729a19f8d04c165c0c10b69095d62
|
https://github.com/neagle/smartgamer/blob/83a4b47c476729a19f8d04c165c0c10b69095d62/index.js#L119-L147
|
|
38,613 |
neagle/smartgamer
|
index.js
|
function (path) {
if (typeof path === 'string') {
path = this.pathTransform(path, 'object');
} else if (typeof path === 'number') {
path = { m: path };
}
this.reset();
var n = node;
for (var i = 0; i < path.m && n; i += 1) {
// Check for a variation in the path for the upcoming move
var variation = path[i + 1] || 0;
n = this.next(variation);
}
return this;
}
|
javascript
|
function (path) {
if (typeof path === 'string') {
path = this.pathTransform(path, 'object');
} else if (typeof path === 'number') {
path = { m: path };
}
this.reset();
var n = node;
for (var i = 0; i < path.m && n; i += 1) {
// Check for a variation in the path for the upcoming move
var variation = path[i + 1] || 0;
n = this.next(variation);
}
return this;
}
|
[
"function",
"(",
"path",
")",
"{",
"if",
"(",
"typeof",
"path",
"===",
"'string'",
")",
"{",
"path",
"=",
"this",
".",
"pathTransform",
"(",
"path",
",",
"'object'",
")",
";",
"}",
"else",
"if",
"(",
"typeof",
"path",
"===",
"'number'",
")",
"{",
"path",
"=",
"{",
"m",
":",
"path",
"}",
";",
"}",
"this",
".",
"reset",
"(",
")",
";",
"var",
"n",
"=",
"node",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"path",
".",
"m",
"&&",
"n",
";",
"i",
"+=",
"1",
")",
"{",
"// Check for a variation in the path for the upcoming move",
"var",
"variation",
"=",
"path",
"[",
"i",
"+",
"1",
"]",
"||",
"0",
";",
"n",
"=",
"this",
".",
"next",
"(",
"variation",
")",
";",
"}",
"return",
"this",
";",
"}"
] |
Go to a particular move, specified as a
a) number
b) path string
c) path object
|
[
"Go",
"to",
"a",
"particular",
"move",
"specified",
"as",
"a",
"a",
")",
"number",
"b",
")",
"path",
"string",
"c",
")",
"path",
"object"
] |
83a4b47c476729a19f8d04c165c0c10b69095d62
|
https://github.com/neagle/smartgamer/blob/83a4b47c476729a19f8d04c165c0c10b69095d62/index.js#L172-L190
|
|
38,614 |
neagle/smartgamer
|
index.js
|
function () {
var localSequence = this.game;
var moves = 0;
while(localSequence) {
moves += localSequence.nodes.length;
if (localSequence.sequences) {
localSequence = localSequence.sequences[0];
} else {
localSequence = null;
}
}
// TODO: Right now we're *assuming* that the root node doesn't have a
// move in it, which is *recommended* but not required practice.
// @see http://www.red-bean.com/sgf/sgf4.html
// "Note: it's bad style to have move properties in root nodes.
// (it isn't forbidden though)"
return moves - 1;
}
|
javascript
|
function () {
var localSequence = this.game;
var moves = 0;
while(localSequence) {
moves += localSequence.nodes.length;
if (localSequence.sequences) {
localSequence = localSequence.sequences[0];
} else {
localSequence = null;
}
}
// TODO: Right now we're *assuming* that the root node doesn't have a
// move in it, which is *recommended* but not required practice.
// @see http://www.red-bean.com/sgf/sgf4.html
// "Note: it's bad style to have move properties in root nodes.
// (it isn't forbidden though)"
return moves - 1;
}
|
[
"function",
"(",
")",
"{",
"var",
"localSequence",
"=",
"this",
".",
"game",
";",
"var",
"moves",
"=",
"0",
";",
"while",
"(",
"localSequence",
")",
"{",
"moves",
"+=",
"localSequence",
".",
"nodes",
".",
"length",
";",
"if",
"(",
"localSequence",
".",
"sequences",
")",
"{",
"localSequence",
"=",
"localSequence",
".",
"sequences",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"localSequence",
"=",
"null",
";",
"}",
"}",
"// TODO: Right now we're *assuming* that the root node doesn't have a",
"// move in it, which is *recommended* but not required practice.",
"// @see http://www.red-bean.com/sgf/sgf4.html",
"// \"Note: it's bad style to have move properties in root nodes.",
"// (it isn't forbidden though)\"",
"return",
"moves",
"-",
"1",
";",
"}"
] |
Get the total number of moves in a game
|
[
"Get",
"the",
"total",
"number",
"of",
"moves",
"in",
"a",
"game"
] |
83a4b47c476729a19f8d04c165c0c10b69095d62
|
https://github.com/neagle/smartgamer/blob/83a4b47c476729a19f8d04c165c0c10b69095d62/index.js#L202-L221
|
|
38,615 |
neagle/smartgamer
|
index.js
|
function (text) {
if (typeof text === 'undefined') {
// Unescape characters
if (node.C) {
return node.C.replace(/\\([\\:\]])/g, '$1');
} else {
return '';
}
} else {
// Escape characters
node.C = text.replace(/[\\:\]]/g, '\\$&');
}
}
|
javascript
|
function (text) {
if (typeof text === 'undefined') {
// Unescape characters
if (node.C) {
return node.C.replace(/\\([\\:\]])/g, '$1');
} else {
return '';
}
} else {
// Escape characters
node.C = text.replace(/[\\:\]]/g, '\\$&');
}
}
|
[
"function",
"(",
"text",
")",
"{",
"if",
"(",
"typeof",
"text",
"===",
"'undefined'",
")",
"{",
"// Unescape characters",
"if",
"(",
"node",
".",
"C",
")",
"{",
"return",
"node",
".",
"C",
".",
"replace",
"(",
"/",
"\\\\([\\\\:\\]])",
"/",
"g",
",",
"'$1'",
")",
";",
"}",
"else",
"{",
"return",
"''",
";",
"}",
"}",
"else",
"{",
"// Escape characters",
"node",
".",
"C",
"=",
"text",
".",
"replace",
"(",
"/",
"[\\\\:\\]]",
"/",
"g",
",",
"'\\\\$&'",
")",
";",
"}",
"}"
] |
Get or set a comment on the current node @see http://www.red-bean.com/sgf/sgf4.html#text
|
[
"Get",
"or",
"set",
"a",
"comment",
"on",
"the",
"current",
"node"
] |
83a4b47c476729a19f8d04c165c0c10b69095d62
|
https://github.com/neagle/smartgamer/blob/83a4b47c476729a19f8d04c165c0c10b69095d62/index.js#L225-L237
|
|
38,616 |
neagle/smartgamer
|
index.js
|
function (alphaCoordinates) {
var coordinateLabels = 'abcdefghijklmnopqrst';
var intersection = [];
intersection[0] = coordinateLabels.indexOf(alphaCoordinates.substring(0, 1));
intersection[1] = coordinateLabels.indexOf(alphaCoordinates.substring(1, 2));
return intersection;
}
|
javascript
|
function (alphaCoordinates) {
var coordinateLabels = 'abcdefghijklmnopqrst';
var intersection = [];
intersection[0] = coordinateLabels.indexOf(alphaCoordinates.substring(0, 1));
intersection[1] = coordinateLabels.indexOf(alphaCoordinates.substring(1, 2));
return intersection;
}
|
[
"function",
"(",
"alphaCoordinates",
")",
"{",
"var",
"coordinateLabels",
"=",
"'abcdefghijklmnopqrst'",
";",
"var",
"intersection",
"=",
"[",
"]",
";",
"intersection",
"[",
"0",
"]",
"=",
"coordinateLabels",
".",
"indexOf",
"(",
"alphaCoordinates",
".",
"substring",
"(",
"0",
",",
"1",
")",
")",
";",
"intersection",
"[",
"1",
"]",
"=",
"coordinateLabels",
".",
"indexOf",
"(",
"alphaCoordinates",
".",
"substring",
"(",
"1",
",",
"2",
")",
")",
";",
"return",
"intersection",
";",
"}"
] |
Translate alpha coordinates into an array
@param string alphaCoordinates
@return array [x, y]
|
[
"Translate",
"alpha",
"coordinates",
"into",
"an",
"array"
] |
83a4b47c476729a19f8d04c165c0c10b69095d62
|
https://github.com/neagle/smartgamer/blob/83a4b47c476729a19f8d04c165c0c10b69095d62/index.js#L244-L252
|
|
38,617 |
neagle/smartgamer
|
index.js
|
function (input, outputType, verbose) {
var output;
// If no output type has been specified, try to set it to the
// opposite of the input
if (typeof outputType === 'undefined') {
outputType = (typeof input === 'string') ? 'object' : 'string';
}
/**
* Turn a path object into a string.
*/
function stringify(input) {
if (typeof input === 'string') {
return input;
}
if (!input) {
return '';
}
output = input.m;
var variations = [];
for (var key in input) {
if (input.hasOwnProperty(key) && key !== 'm') {
// Only show variations that are not the primary one, since
// primary variations are chosen by default
if (input[key] > 0) {
if (verbose) {
variations.push(', variation ' + input[key] + ' at move ' + key);
} else {
variations.push('-' + key + ':' + input[key]);
}
}
}
}
output += variations.join('');
return output;
}
/**
* Turn a path string into an object.
*/
function parse(input) {
if (typeof input === 'object') {
input = stringify(input);
}
if (!input) {
return { m: 0 };
}
var path = input.split('-');
output = {
m: Number(path.shift())
};
if (path.length) {
path.forEach(function (variation, i) {
variation = variation.split(':');
output[Number(variation[0])] = parseInt(variation[1], 10);
});
}
return output;
}
if (outputType === 'string') {
output = stringify(input);
} else if (outputType === 'object') {
output = parse(input);
} else {
output = undefined;
}
return output;
}
|
javascript
|
function (input, outputType, verbose) {
var output;
// If no output type has been specified, try to set it to the
// opposite of the input
if (typeof outputType === 'undefined') {
outputType = (typeof input === 'string') ? 'object' : 'string';
}
/**
* Turn a path object into a string.
*/
function stringify(input) {
if (typeof input === 'string') {
return input;
}
if (!input) {
return '';
}
output = input.m;
var variations = [];
for (var key in input) {
if (input.hasOwnProperty(key) && key !== 'm') {
// Only show variations that are not the primary one, since
// primary variations are chosen by default
if (input[key] > 0) {
if (verbose) {
variations.push(', variation ' + input[key] + ' at move ' + key);
} else {
variations.push('-' + key + ':' + input[key]);
}
}
}
}
output += variations.join('');
return output;
}
/**
* Turn a path string into an object.
*/
function parse(input) {
if (typeof input === 'object') {
input = stringify(input);
}
if (!input) {
return { m: 0 };
}
var path = input.split('-');
output = {
m: Number(path.shift())
};
if (path.length) {
path.forEach(function (variation, i) {
variation = variation.split(':');
output[Number(variation[0])] = parseInt(variation[1], 10);
});
}
return output;
}
if (outputType === 'string') {
output = stringify(input);
} else if (outputType === 'object') {
output = parse(input);
} else {
output = undefined;
}
return output;
}
|
[
"function",
"(",
"input",
",",
"outputType",
",",
"verbose",
")",
"{",
"var",
"output",
";",
"// If no output type has been specified, try to set it to the",
"// opposite of the input",
"if",
"(",
"typeof",
"outputType",
"===",
"'undefined'",
")",
"{",
"outputType",
"=",
"(",
"typeof",
"input",
"===",
"'string'",
")",
"?",
"'object'",
":",
"'string'",
";",
"}",
"/**\n\t\t\t * Turn a path object into a string.\n\t\t\t */",
"function",
"stringify",
"(",
"input",
")",
"{",
"if",
"(",
"typeof",
"input",
"===",
"'string'",
")",
"{",
"return",
"input",
";",
"}",
"if",
"(",
"!",
"input",
")",
"{",
"return",
"''",
";",
"}",
"output",
"=",
"input",
".",
"m",
";",
"var",
"variations",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"key",
"in",
"input",
")",
"{",
"if",
"(",
"input",
".",
"hasOwnProperty",
"(",
"key",
")",
"&&",
"key",
"!==",
"'m'",
")",
"{",
"// Only show variations that are not the primary one, since",
"// primary variations are chosen by default",
"if",
"(",
"input",
"[",
"key",
"]",
">",
"0",
")",
"{",
"if",
"(",
"verbose",
")",
"{",
"variations",
".",
"push",
"(",
"', variation '",
"+",
"input",
"[",
"key",
"]",
"+",
"' at move '",
"+",
"key",
")",
";",
"}",
"else",
"{",
"variations",
".",
"push",
"(",
"'-'",
"+",
"key",
"+",
"':'",
"+",
"input",
"[",
"key",
"]",
")",
";",
"}",
"}",
"}",
"}",
"output",
"+=",
"variations",
".",
"join",
"(",
"''",
")",
";",
"return",
"output",
";",
"}",
"/**\n\t\t\t * Turn a path string into an object.\n\t\t\t */",
"function",
"parse",
"(",
"input",
")",
"{",
"if",
"(",
"typeof",
"input",
"===",
"'object'",
")",
"{",
"input",
"=",
"stringify",
"(",
"input",
")",
";",
"}",
"if",
"(",
"!",
"input",
")",
"{",
"return",
"{",
"m",
":",
"0",
"}",
";",
"}",
"var",
"path",
"=",
"input",
".",
"split",
"(",
"'-'",
")",
";",
"output",
"=",
"{",
"m",
":",
"Number",
"(",
"path",
".",
"shift",
"(",
")",
")",
"}",
";",
"if",
"(",
"path",
".",
"length",
")",
"{",
"path",
".",
"forEach",
"(",
"function",
"(",
"variation",
",",
"i",
")",
"{",
"variation",
"=",
"variation",
".",
"split",
"(",
"':'",
")",
";",
"output",
"[",
"Number",
"(",
"variation",
"[",
"0",
"]",
")",
"]",
"=",
"parseInt",
"(",
"variation",
"[",
"1",
"]",
",",
"10",
")",
";",
"}",
")",
";",
"}",
"return",
"output",
";",
"}",
"if",
"(",
"outputType",
"===",
"'string'",
")",
"{",
"output",
"=",
"stringify",
"(",
"input",
")",
";",
"}",
"else",
"if",
"(",
"outputType",
"===",
"'object'",
")",
"{",
"output",
"=",
"parse",
"(",
"input",
")",
";",
"}",
"else",
"{",
"output",
"=",
"undefined",
";",
"}",
"return",
"output",
";",
"}"
] |
Convert path objects to strings and path strings to objects
|
[
"Convert",
"path",
"objects",
"to",
"strings",
"and",
"path",
"strings",
"to",
"objects"
] |
83a4b47c476729a19f8d04c165c0c10b69095d62
|
https://github.com/neagle/smartgamer/blob/83a4b47c476729a19f8d04c165c0c10b69095d62/index.js#L257-L335
|
|
38,618 |
neagle/smartgamer
|
index.js
|
stringify
|
function stringify(input) {
if (typeof input === 'string') {
return input;
}
if (!input) {
return '';
}
output = input.m;
var variations = [];
for (var key in input) {
if (input.hasOwnProperty(key) && key !== 'm') {
// Only show variations that are not the primary one, since
// primary variations are chosen by default
if (input[key] > 0) {
if (verbose) {
variations.push(', variation ' + input[key] + ' at move ' + key);
} else {
variations.push('-' + key + ':' + input[key]);
}
}
}
}
output += variations.join('');
return output;
}
|
javascript
|
function stringify(input) {
if (typeof input === 'string') {
return input;
}
if (!input) {
return '';
}
output = input.m;
var variations = [];
for (var key in input) {
if (input.hasOwnProperty(key) && key !== 'm') {
// Only show variations that are not the primary one, since
// primary variations are chosen by default
if (input[key] > 0) {
if (verbose) {
variations.push(', variation ' + input[key] + ' at move ' + key);
} else {
variations.push('-' + key + ':' + input[key]);
}
}
}
}
output += variations.join('');
return output;
}
|
[
"function",
"stringify",
"(",
"input",
")",
"{",
"if",
"(",
"typeof",
"input",
"===",
"'string'",
")",
"{",
"return",
"input",
";",
"}",
"if",
"(",
"!",
"input",
")",
"{",
"return",
"''",
";",
"}",
"output",
"=",
"input",
".",
"m",
";",
"var",
"variations",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"key",
"in",
"input",
")",
"{",
"if",
"(",
"input",
".",
"hasOwnProperty",
"(",
"key",
")",
"&&",
"key",
"!==",
"'m'",
")",
"{",
"// Only show variations that are not the primary one, since",
"// primary variations are chosen by default",
"if",
"(",
"input",
"[",
"key",
"]",
">",
"0",
")",
"{",
"if",
"(",
"verbose",
")",
"{",
"variations",
".",
"push",
"(",
"', variation '",
"+",
"input",
"[",
"key",
"]",
"+",
"' at move '",
"+",
"key",
")",
";",
"}",
"else",
"{",
"variations",
".",
"push",
"(",
"'-'",
"+",
"key",
"+",
"':'",
"+",
"input",
"[",
"key",
"]",
")",
";",
"}",
"}",
"}",
"}",
"output",
"+=",
"variations",
".",
"join",
"(",
"''",
")",
";",
"return",
"output",
";",
"}"
] |
Turn a path object into a string.
|
[
"Turn",
"a",
"path",
"object",
"into",
"a",
"string",
"."
] |
83a4b47c476729a19f8d04c165c0c10b69095d62
|
https://github.com/neagle/smartgamer/blob/83a4b47c476729a19f8d04c165c0c10b69095d62/index.js#L269-L297
|
38,619 |
neagle/smartgamer
|
index.js
|
parse
|
function parse(input) {
if (typeof input === 'object') {
input = stringify(input);
}
if (!input) {
return { m: 0 };
}
var path = input.split('-');
output = {
m: Number(path.shift())
};
if (path.length) {
path.forEach(function (variation, i) {
variation = variation.split(':');
output[Number(variation[0])] = parseInt(variation[1], 10);
});
}
return output;
}
|
javascript
|
function parse(input) {
if (typeof input === 'object') {
input = stringify(input);
}
if (!input) {
return { m: 0 };
}
var path = input.split('-');
output = {
m: Number(path.shift())
};
if (path.length) {
path.forEach(function (variation, i) {
variation = variation.split(':');
output[Number(variation[0])] = parseInt(variation[1], 10);
});
}
return output;
}
|
[
"function",
"parse",
"(",
"input",
")",
"{",
"if",
"(",
"typeof",
"input",
"===",
"'object'",
")",
"{",
"input",
"=",
"stringify",
"(",
"input",
")",
";",
"}",
"if",
"(",
"!",
"input",
")",
"{",
"return",
"{",
"m",
":",
"0",
"}",
";",
"}",
"var",
"path",
"=",
"input",
".",
"split",
"(",
"'-'",
")",
";",
"output",
"=",
"{",
"m",
":",
"Number",
"(",
"path",
".",
"shift",
"(",
")",
")",
"}",
";",
"if",
"(",
"path",
".",
"length",
")",
"{",
"path",
".",
"forEach",
"(",
"function",
"(",
"variation",
",",
"i",
")",
"{",
"variation",
"=",
"variation",
".",
"split",
"(",
"':'",
")",
";",
"output",
"[",
"Number",
"(",
"variation",
"[",
"0",
"]",
")",
"]",
"=",
"parseInt",
"(",
"variation",
"[",
"1",
"]",
",",
"10",
")",
";",
"}",
")",
";",
"}",
"return",
"output",
";",
"}"
] |
Turn a path string into an object.
|
[
"Turn",
"a",
"path",
"string",
"into",
"an",
"object",
"."
] |
83a4b47c476729a19f8d04c165c0c10b69095d62
|
https://github.com/neagle/smartgamer/blob/83a4b47c476729a19f8d04c165c0c10b69095d62/index.js#L302-L324
|
38,620 |
AckerApple/ack-node
|
js/modules/reqres/req.js
|
processArray
|
function processArray(req, res, nextarray) {
if (!nextarray || !nextarray.length)
return;
var proc = nextarray.shift();
proc(req, res, function () {
processArray(req, res, nextarray);
});
}
|
javascript
|
function processArray(req, res, nextarray) {
if (!nextarray || !nextarray.length)
return;
var proc = nextarray.shift();
proc(req, res, function () {
processArray(req, res, nextarray);
});
}
|
[
"function",
"processArray",
"(",
"req",
",",
"res",
",",
"nextarray",
")",
"{",
"if",
"(",
"!",
"nextarray",
"||",
"!",
"nextarray",
".",
"length",
")",
"return",
";",
"var",
"proc",
"=",
"nextarray",
".",
"shift",
"(",
")",
";",
"proc",
"(",
"req",
",",
"res",
",",
"function",
"(",
")",
"{",
"processArray",
"(",
"req",
",",
"res",
",",
"nextarray",
")",
";",
"}",
")",
";",
"}"
] |
!!!Non-prototypes below express request handler with array shifting
|
[
"!!!Non",
"-",
"prototypes",
"below",
"express",
"request",
"handler",
"with",
"array",
"shifting"
] |
c123d3fcbdd0195630fece6dc9ddee8910c9e115
|
https://github.com/AckerApple/ack-node/blob/c123d3fcbdd0195630fece6dc9ddee8910c9e115/js/modules/reqres/req.js#L210-L217
|
38,621 |
AckerApple/ack-node
|
js/modules/reqres/req.js
|
path
|
function path(req) {
var oUrl = req.originalUrl || req.url;
this.string = oUrl.split('?')[0];
this.relative = req.url.split('?')[0];
}
|
javascript
|
function path(req) {
var oUrl = req.originalUrl || req.url;
this.string = oUrl.split('?')[0];
this.relative = req.url.split('?')[0];
}
|
[
"function",
"path",
"(",
"req",
")",
"{",
"var",
"oUrl",
"=",
"req",
".",
"originalUrl",
"||",
"req",
".",
"url",
";",
"this",
".",
"string",
"=",
"oUrl",
".",
"split",
"(",
"'?'",
")",
"[",
"0",
"]",
";",
"this",
".",
"relative",
"=",
"req",
".",
"url",
".",
"split",
"(",
"'?'",
")",
"[",
"0",
"]",
";",
"}"
] |
path component to aid in reading the request path
|
[
"path",
"component",
"to",
"aid",
"in",
"reading",
"the",
"request",
"path"
] |
c123d3fcbdd0195630fece6dc9ddee8910c9e115
|
https://github.com/AckerApple/ack-node/blob/c123d3fcbdd0195630fece6dc9ddee8910c9e115/js/modules/reqres/req.js#L219-L223
|
38,622 |
rootsdev/gedcomx-js
|
src/atom/AtomCommon.js
|
function(json){
// Protect against forgetting the new keyword when calling the constructor
if(!(this instanceof AtomCommon)){
return new AtomCommon(json);
}
// If the given object is already an instance then just return it. DON'T copy it.
if(AtomCommon.isInstance(json)){
return json;
}
this.init(json);
}
|
javascript
|
function(json){
// Protect against forgetting the new keyword when calling the constructor
if(!(this instanceof AtomCommon)){
return new AtomCommon(json);
}
// If the given object is already an instance then just return it. DON'T copy it.
if(AtomCommon.isInstance(json)){
return json;
}
this.init(json);
}
|
[
"function",
"(",
"json",
")",
"{",
"// Protect against forgetting the new keyword when calling the constructor",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"AtomCommon",
")",
")",
"{",
"return",
"new",
"AtomCommon",
"(",
"json",
")",
";",
"}",
"// If the given object is already an instance then just return it. DON'T copy it.",
"if",
"(",
"AtomCommon",
".",
"isInstance",
"(",
"json",
")",
")",
"{",
"return",
"json",
";",
"}",
"this",
".",
"init",
"(",
"json",
")",
";",
"}"
] |
Common attributes for all Atom entities
@see {@link https://tools.ietf.org/html/rfc4287#page-7|RFC 4287}
@class AtomCommon
@extends Base
@param {Object} [json]
|
[
"Common",
"attributes",
"for",
"all",
"Atom",
"entities"
] |
08b2fcde96f1e301c78561bfb7a8b0cac606e26e
|
https://github.com/rootsdev/gedcomx-js/blob/08b2fcde96f1e301c78561bfb7a8b0cac606e26e/src/atom/AtomCommon.js#L13-L26
|
|
38,623 |
amrdraz/java-code-runner
|
node/server.js
|
findPort
|
function findPort(cb) {
var port = tryPort;
tryPort += 1;
var server = net.createServer();
server.listen(port, function(err) {
server.once('close', function() {
cb(port);
});
server.close();
});
server.on('error', function(err) {
log("port " + tryPort + " is occupied");
findPort(cb);
});
}
|
javascript
|
function findPort(cb) {
var port = tryPort;
tryPort += 1;
var server = net.createServer();
server.listen(port, function(err) {
server.once('close', function() {
cb(port);
});
server.close();
});
server.on('error', function(err) {
log("port " + tryPort + " is occupied");
findPort(cb);
});
}
|
[
"function",
"findPort",
"(",
"cb",
")",
"{",
"var",
"port",
"=",
"tryPort",
";",
"tryPort",
"+=",
"1",
";",
"var",
"server",
"=",
"net",
".",
"createServer",
"(",
")",
";",
"server",
".",
"listen",
"(",
"port",
",",
"function",
"(",
"err",
")",
"{",
"server",
".",
"once",
"(",
"'close'",
",",
"function",
"(",
")",
"{",
"cb",
"(",
"port",
")",
";",
"}",
")",
";",
"server",
".",
"close",
"(",
")",
";",
"}",
")",
";",
"server",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"err",
")",
"{",
"log",
"(",
"\"port \"",
"+",
"tryPort",
"+",
"\" is occupied\"",
")",
";",
"findPort",
"(",
"cb",
")",
";",
"}",
")",
";",
"}"
] |
get an empty port for the java server
|
[
"get",
"an",
"empty",
"port",
"for",
"the",
"java",
"server"
] |
b5d87b503076bf76a01d111b85c18a639e6f80c8
|
https://github.com/amrdraz/java-code-runner/blob/b5d87b503076bf76a01d111b85c18a639e6f80c8/node/server.js#L41-L56
|
38,624 |
amrdraz/java-code-runner
|
node/server.js
|
startServlet
|
function startServlet(cb) {
startingServer = true;
servletReady = false;
debugger;
findPort(function(port) {
servletPort = global._servletPort = '' + port;
servlet = global._servlet = cp.spawn('java', ['-cp', '.:../lib/servlet-api-2.5.jar:../lib/jetty-all-7.0.2.v20100331.jar', 'RunnerServlet', servletPort], {
cwd: config.rootDir + '/bin'
});
servlet.stdout.on('data', function(data) {
console.log('OUT:' + data);
});
servlet.stderr.on('data', function(data) {
console.log("" + data);
if (~data.toString().indexOf(servletPort)) {
servletReady = true;
startingServer = false;
// queue.checkQueues();
observer.emit("server.running", port);
if (cb) cb(port);
}
});
servlet.on('exit', function(code, signal) {
resetFlags();
if (code === null || signal === null) {
serverExit = true;
}
log('servlet exist with code ' + code + 'signal ' + signal);
observer.emit('server.exit',code);
});
// make sure to close server after node process ends
process.on('exit', function() {
stopServer(true);
});
});
}
|
javascript
|
function startServlet(cb) {
startingServer = true;
servletReady = false;
debugger;
findPort(function(port) {
servletPort = global._servletPort = '' + port;
servlet = global._servlet = cp.spawn('java', ['-cp', '.:../lib/servlet-api-2.5.jar:../lib/jetty-all-7.0.2.v20100331.jar', 'RunnerServlet', servletPort], {
cwd: config.rootDir + '/bin'
});
servlet.stdout.on('data', function(data) {
console.log('OUT:' + data);
});
servlet.stderr.on('data', function(data) {
console.log("" + data);
if (~data.toString().indexOf(servletPort)) {
servletReady = true;
startingServer = false;
// queue.checkQueues();
observer.emit("server.running", port);
if (cb) cb(port);
}
});
servlet.on('exit', function(code, signal) {
resetFlags();
if (code === null || signal === null) {
serverExit = true;
}
log('servlet exist with code ' + code + 'signal ' + signal);
observer.emit('server.exit',code);
});
// make sure to close server after node process ends
process.on('exit', function() {
stopServer(true);
});
});
}
|
[
"function",
"startServlet",
"(",
"cb",
")",
"{",
"startingServer",
"=",
"true",
";",
"servletReady",
"=",
"false",
";",
"debugger",
";",
"findPort",
"(",
"function",
"(",
"port",
")",
"{",
"servletPort",
"=",
"global",
".",
"_servletPort",
"=",
"''",
"+",
"port",
";",
"servlet",
"=",
"global",
".",
"_servlet",
"=",
"cp",
".",
"spawn",
"(",
"'java'",
",",
"[",
"'-cp'",
",",
"'.:../lib/servlet-api-2.5.jar:../lib/jetty-all-7.0.2.v20100331.jar'",
",",
"'RunnerServlet'",
",",
"servletPort",
"]",
",",
"{",
"cwd",
":",
"config",
".",
"rootDir",
"+",
"'/bin'",
"}",
")",
";",
"servlet",
".",
"stdout",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"data",
")",
"{",
"console",
".",
"log",
"(",
"'OUT:'",
"+",
"data",
")",
";",
"}",
")",
";",
"servlet",
".",
"stderr",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"data",
")",
"{",
"console",
".",
"log",
"(",
"\"\"",
"+",
"data",
")",
";",
"if",
"(",
"~",
"data",
".",
"toString",
"(",
")",
".",
"indexOf",
"(",
"servletPort",
")",
")",
"{",
"servletReady",
"=",
"true",
";",
"startingServer",
"=",
"false",
";",
"// queue.checkQueues();",
"observer",
".",
"emit",
"(",
"\"server.running\"",
",",
"port",
")",
";",
"if",
"(",
"cb",
")",
"cb",
"(",
"port",
")",
";",
"}",
"}",
")",
";",
"servlet",
".",
"on",
"(",
"'exit'",
",",
"function",
"(",
"code",
",",
"signal",
")",
"{",
"resetFlags",
"(",
")",
";",
"if",
"(",
"code",
"===",
"null",
"||",
"signal",
"===",
"null",
")",
"{",
"serverExit",
"=",
"true",
";",
"}",
"log",
"(",
"'servlet exist with code '",
"+",
"code",
"+",
"'signal '",
"+",
"signal",
")",
";",
"observer",
".",
"emit",
"(",
"'server.exit'",
",",
"code",
")",
";",
"}",
")",
";",
"// make sure to close server after node process ends",
"process",
".",
"on",
"(",
"'exit'",
",",
"function",
"(",
")",
"{",
"stopServer",
"(",
"true",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Starts the servlet on an empty port default is 3678
|
[
"Starts",
"the",
"servlet",
"on",
"an",
"empty",
"port",
"default",
"is",
"3678"
] |
b5d87b503076bf76a01d111b85c18a639e6f80c8
|
https://github.com/amrdraz/java-code-runner/blob/b5d87b503076bf76a01d111b85c18a639e6f80c8/node/server.js#L144-L182
|
38,625 |
DeviaVir/node-partyflock
|
partyflock.js
|
Partyflock
|
function Partyflock(consumerKey, consumerSecret, endpoint, debug) {
this.endpoint = 'partyflock.nl';
// Check instance arguments
this.endpoint = (endpoint ? endpoint : this.endpoint);
this.consumerKey = (consumerKey ? consumerKey : false);
this.consumerSecret = (consumerSecret ? consumerSecret : false);
this.debug = (typeof debug !== 'undefined' ? debug : false);
// Check config options
if(config.partyflock) {
this.consumerKey = (this.consumerKey === false ? config.partyflock.consumerKey : false);
this.consumerSecret = (this.consumerSecret === false ? config.partyflock.consumerSecret : false);
this.endpoint = (this.endpoint !== config.partyflock.endpoint ? config.partyflock.endpoint : this.endpoint);
this.debug = (this.debug === false && config.partyflock.debug !== 'undefined' ? config.partyflock.debug : this.debug);
}
// CI integration
if(process.env['CONSUMER_KEY'] && process.env['CONSUMER_SECRET']) {
this.consumerKey = process.env['CONSUMER_KEY'];
this.consumerSecret = process.env['CONSUMER_SECRET'];
}
this.type = 'json';
this.date = new date(this);
this.location = new location(this);
this.artist = new artist(this);
this.user = new user(this);
this.party = new party(this);
this.oauth = new OAuth.OAuth(
'https://' + this.endpoint + '/request_token',
'', // no need for an oauth_token request
this.consumerKey,
this.consumerSecret,
'1.0A',
null,
'HMAC-SHA1'
);
}
|
javascript
|
function Partyflock(consumerKey, consumerSecret, endpoint, debug) {
this.endpoint = 'partyflock.nl';
// Check instance arguments
this.endpoint = (endpoint ? endpoint : this.endpoint);
this.consumerKey = (consumerKey ? consumerKey : false);
this.consumerSecret = (consumerSecret ? consumerSecret : false);
this.debug = (typeof debug !== 'undefined' ? debug : false);
// Check config options
if(config.partyflock) {
this.consumerKey = (this.consumerKey === false ? config.partyflock.consumerKey : false);
this.consumerSecret = (this.consumerSecret === false ? config.partyflock.consumerSecret : false);
this.endpoint = (this.endpoint !== config.partyflock.endpoint ? config.partyflock.endpoint : this.endpoint);
this.debug = (this.debug === false && config.partyflock.debug !== 'undefined' ? config.partyflock.debug : this.debug);
}
// CI integration
if(process.env['CONSUMER_KEY'] && process.env['CONSUMER_SECRET']) {
this.consumerKey = process.env['CONSUMER_KEY'];
this.consumerSecret = process.env['CONSUMER_SECRET'];
}
this.type = 'json';
this.date = new date(this);
this.location = new location(this);
this.artist = new artist(this);
this.user = new user(this);
this.party = new party(this);
this.oauth = new OAuth.OAuth(
'https://' + this.endpoint + '/request_token',
'', // no need for an oauth_token request
this.consumerKey,
this.consumerSecret,
'1.0A',
null,
'HMAC-SHA1'
);
}
|
[
"function",
"Partyflock",
"(",
"consumerKey",
",",
"consumerSecret",
",",
"endpoint",
",",
"debug",
")",
"{",
"this",
".",
"endpoint",
"=",
"'partyflock.nl'",
";",
"// Check instance arguments",
"this",
".",
"endpoint",
"=",
"(",
"endpoint",
"?",
"endpoint",
":",
"this",
".",
"endpoint",
")",
";",
"this",
".",
"consumerKey",
"=",
"(",
"consumerKey",
"?",
"consumerKey",
":",
"false",
")",
";",
"this",
".",
"consumerSecret",
"=",
"(",
"consumerSecret",
"?",
"consumerSecret",
":",
"false",
")",
";",
"this",
".",
"debug",
"=",
"(",
"typeof",
"debug",
"!==",
"'undefined'",
"?",
"debug",
":",
"false",
")",
";",
"// Check config options",
"if",
"(",
"config",
".",
"partyflock",
")",
"{",
"this",
".",
"consumerKey",
"=",
"(",
"this",
".",
"consumerKey",
"===",
"false",
"?",
"config",
".",
"partyflock",
".",
"consumerKey",
":",
"false",
")",
";",
"this",
".",
"consumerSecret",
"=",
"(",
"this",
".",
"consumerSecret",
"===",
"false",
"?",
"config",
".",
"partyflock",
".",
"consumerSecret",
":",
"false",
")",
";",
"this",
".",
"endpoint",
"=",
"(",
"this",
".",
"endpoint",
"!==",
"config",
".",
"partyflock",
".",
"endpoint",
"?",
"config",
".",
"partyflock",
".",
"endpoint",
":",
"this",
".",
"endpoint",
")",
";",
"this",
".",
"debug",
"=",
"(",
"this",
".",
"debug",
"===",
"false",
"&&",
"config",
".",
"partyflock",
".",
"debug",
"!==",
"'undefined'",
"?",
"config",
".",
"partyflock",
".",
"debug",
":",
"this",
".",
"debug",
")",
";",
"}",
"// CI integration",
"if",
"(",
"process",
".",
"env",
"[",
"'CONSUMER_KEY'",
"]",
"&&",
"process",
".",
"env",
"[",
"'CONSUMER_SECRET'",
"]",
")",
"{",
"this",
".",
"consumerKey",
"=",
"process",
".",
"env",
"[",
"'CONSUMER_KEY'",
"]",
";",
"this",
".",
"consumerSecret",
"=",
"process",
".",
"env",
"[",
"'CONSUMER_SECRET'",
"]",
";",
"}",
"this",
".",
"type",
"=",
"'json'",
";",
"this",
".",
"date",
"=",
"new",
"date",
"(",
"this",
")",
";",
"this",
".",
"location",
"=",
"new",
"location",
"(",
"this",
")",
";",
"this",
".",
"artist",
"=",
"new",
"artist",
"(",
"this",
")",
";",
"this",
".",
"user",
"=",
"new",
"user",
"(",
"this",
")",
";",
"this",
".",
"party",
"=",
"new",
"party",
"(",
"this",
")",
";",
"this",
".",
"oauth",
"=",
"new",
"OAuth",
".",
"OAuth",
"(",
"'https://'",
"+",
"this",
".",
"endpoint",
"+",
"'/request_token'",
",",
"''",
",",
"// no need for an oauth_token request",
"this",
".",
"consumerKey",
",",
"this",
".",
"consumerSecret",
",",
"'1.0A'",
",",
"null",
",",
"'HMAC-SHA1'",
")",
";",
"}"
] |
Partyflock instance constructor
@prototype
@class Partyflock
|
[
"Partyflock",
"instance",
"constructor"
] |
dafad1cc1f466d1373637f9748121f0acb7c3499
|
https://github.com/DeviaVir/node-partyflock/blob/dafad1cc1f466d1373637f9748121f0acb7c3499/partyflock.js#L21-L58
|
38,626 |
rootsdev/gedcomx-js
|
src/core/Coverage.js
|
function(json){
// Protect against forgetting the new keyword when calling the constructor
if(!(this instanceof Coverage)){
return new Coverage(json);
}
// If the given object is already an instance then just return it. DON'T copy it.
if(Coverage.isInstance(json)){
return json;
}
this.init(json);
}
|
javascript
|
function(json){
// Protect against forgetting the new keyword when calling the constructor
if(!(this instanceof Coverage)){
return new Coverage(json);
}
// If the given object is already an instance then just return it. DON'T copy it.
if(Coverage.isInstance(json)){
return json;
}
this.init(json);
}
|
[
"function",
"(",
"json",
")",
"{",
"// Protect against forgetting the new keyword when calling the constructor",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Coverage",
")",
")",
"{",
"return",
"new",
"Coverage",
"(",
"json",
")",
";",
"}",
"// If the given object is already an instance then just return it. DON'T copy it.",
"if",
"(",
"Coverage",
".",
"isInstance",
"(",
"json",
")",
")",
"{",
"return",
"json",
";",
"}",
"this",
".",
"init",
"(",
"json",
")",
";",
"}"
] |
A description of the spatial and temporal coverage of a resource.
@see {@link https://github.com/FamilySearch/gedcomx/blob/master/specifications/json-format-specification.md#coverage|GEDCOM X JSON Spec}
@class
@extends ExtensibleData
@apram {Object} [json]
|
[
"A",
"description",
"of",
"the",
"spatial",
"and",
"temporal",
"coverage",
"of",
"a",
"resource",
"."
] |
08b2fcde96f1e301c78561bfb7a8b0cac606e26e
|
https://github.com/rootsdev/gedcomx-js/blob/08b2fcde96f1e301c78561bfb7a8b0cac606e26e/src/core/Coverage.js#L13-L26
|
|
38,627 |
WildDogTeam/lib-js-wildgeo
|
src/geoDogUtils.js
|
function(resolution, latitude) {
var degs = metersToLongitudeDegrees(resolution, latitude);
return (Math.abs(degs) > 0.000001) ? Math.max(1, Math.log2(360/degs)) : 1;
}
|
javascript
|
function(resolution, latitude) {
var degs = metersToLongitudeDegrees(resolution, latitude);
return (Math.abs(degs) > 0.000001) ? Math.max(1, Math.log2(360/degs)) : 1;
}
|
[
"function",
"(",
"resolution",
",",
"latitude",
")",
"{",
"var",
"degs",
"=",
"metersToLongitudeDegrees",
"(",
"resolution",
",",
"latitude",
")",
";",
"return",
"(",
"Math",
".",
"abs",
"(",
"degs",
")",
">",
"0.000001",
")",
"?",
"Math",
".",
"max",
"(",
"1",
",",
"Math",
".",
"log2",
"(",
"360",
"/",
"degs",
")",
")",
":",
"1",
";",
"}"
] |
Calculates the bits necessary to reach a given resolution, in meters, for the longitude at a
given latitude.
@param {number} resolution The desired resolution.
@param {number} latitude The latitude used in the conversion.
@return {number} The bits necessary to reach a given resolution, in meters.
|
[
"Calculates",
"the",
"bits",
"necessary",
"to",
"reach",
"a",
"given",
"resolution",
"in",
"meters",
"for",
"the",
"longitude",
"at",
"a",
"given",
"latitude",
"."
] |
225c8949e814ec7b39d1457f3aa3c63808a79470
|
https://github.com/WildDogTeam/lib-js-wildgeo/blob/225c8949e814ec7b39d1457f3aa3c63808a79470/src/geoDogUtils.js#L281-L284
|
|
38,628 |
WildDogTeam/lib-js-wildgeo
|
src/geoDogUtils.js
|
function(coordinate,size) {
var latDeltaDegrees = size/g_METERS_PER_DEGREE_LATITUDE;
var latitudeNorth = Math.min(90, coordinate[0] + latDeltaDegrees);
var latitudeSouth = Math.max(-90, coordinate[0] - latDeltaDegrees);
var bitsLat = Math.floor(latitudeBitsForResolution(size))*2;
var bitsLongNorth = Math.floor(longitudeBitsForResolution(size, latitudeNorth))*2-1;
var bitsLongSouth = Math.floor(longitudeBitsForResolution(size, latitudeSouth))*2-1;
return Math.min(bitsLat, bitsLongNorth, bitsLongSouth, g_MAXIMUM_BITS_PRECISION);
}
|
javascript
|
function(coordinate,size) {
var latDeltaDegrees = size/g_METERS_PER_DEGREE_LATITUDE;
var latitudeNorth = Math.min(90, coordinate[0] + latDeltaDegrees);
var latitudeSouth = Math.max(-90, coordinate[0] - latDeltaDegrees);
var bitsLat = Math.floor(latitudeBitsForResolution(size))*2;
var bitsLongNorth = Math.floor(longitudeBitsForResolution(size, latitudeNorth))*2-1;
var bitsLongSouth = Math.floor(longitudeBitsForResolution(size, latitudeSouth))*2-1;
return Math.min(bitsLat, bitsLongNorth, bitsLongSouth, g_MAXIMUM_BITS_PRECISION);
}
|
[
"function",
"(",
"coordinate",
",",
"size",
")",
"{",
"var",
"latDeltaDegrees",
"=",
"size",
"/",
"g_METERS_PER_DEGREE_LATITUDE",
";",
"var",
"latitudeNorth",
"=",
"Math",
".",
"min",
"(",
"90",
",",
"coordinate",
"[",
"0",
"]",
"+",
"latDeltaDegrees",
")",
";",
"var",
"latitudeSouth",
"=",
"Math",
".",
"max",
"(",
"-",
"90",
",",
"coordinate",
"[",
"0",
"]",
"-",
"latDeltaDegrees",
")",
";",
"var",
"bitsLat",
"=",
"Math",
".",
"floor",
"(",
"latitudeBitsForResolution",
"(",
"size",
")",
")",
"*",
"2",
";",
"var",
"bitsLongNorth",
"=",
"Math",
".",
"floor",
"(",
"longitudeBitsForResolution",
"(",
"size",
",",
"latitudeNorth",
")",
")",
"*",
"2",
"-",
"1",
";",
"var",
"bitsLongSouth",
"=",
"Math",
".",
"floor",
"(",
"longitudeBitsForResolution",
"(",
"size",
",",
"latitudeSouth",
")",
")",
"*",
"2",
"-",
"1",
";",
"return",
"Math",
".",
"min",
"(",
"bitsLat",
",",
"bitsLongNorth",
",",
"bitsLongSouth",
",",
"g_MAXIMUM_BITS_PRECISION",
")",
";",
"}"
] |
Calculates the maximum number of bits of a geohash to get a bounding box that is larger than a
given size at the given coordinate.
@param {Array.<number>} coordinate The coordinate as a [latitude, longitude] pair.
@param {number} size The size of the bounding box.
@return {number} The number of bits necessary for the geohash.
|
[
"Calculates",
"the",
"maximum",
"number",
"of",
"bits",
"of",
"a",
"geohash",
"to",
"get",
"a",
"bounding",
"box",
"that",
"is",
"larger",
"than",
"a",
"given",
"size",
"at",
"the",
"given",
"coordinate",
"."
] |
225c8949e814ec7b39d1457f3aa3c63808a79470
|
https://github.com/WildDogTeam/lib-js-wildgeo/blob/225c8949e814ec7b39d1457f3aa3c63808a79470/src/geoDogUtils.js#L322-L330
|
|
38,629 |
WildDogTeam/lib-js-wildgeo
|
src/geoDogUtils.js
|
function(center, radius) {
var latDegrees = radius/g_METERS_PER_DEGREE_LATITUDE;
var latitudeNorth = Math.min(90, center[0] + latDegrees);
var latitudeSouth = Math.max(-90, center[0] - latDegrees);
var longDegsNorth = metersToLongitudeDegrees(radius, latitudeNorth);
var longDegsSouth = metersToLongitudeDegrees(radius, latitudeSouth);
var longDegs = Math.max(longDegsNorth, longDegsSouth);
return [
[center[0], center[1]],
[center[0], wrapLongitude(center[1] - longDegs)],
[center[0], wrapLongitude(center[1] + longDegs)],
[latitudeNorth, center[1]],
[latitudeNorth, wrapLongitude(center[1] - longDegs)],
[latitudeNorth, wrapLongitude(center[1] + longDegs)],
[latitudeSouth, center[1]],
[latitudeSouth, wrapLongitude(center[1] - longDegs)],
[latitudeSouth, wrapLongitude(center[1] + longDegs)]
];
}
|
javascript
|
function(center, radius) {
var latDegrees = radius/g_METERS_PER_DEGREE_LATITUDE;
var latitudeNorth = Math.min(90, center[0] + latDegrees);
var latitudeSouth = Math.max(-90, center[0] - latDegrees);
var longDegsNorth = metersToLongitudeDegrees(radius, latitudeNorth);
var longDegsSouth = metersToLongitudeDegrees(radius, latitudeSouth);
var longDegs = Math.max(longDegsNorth, longDegsSouth);
return [
[center[0], center[1]],
[center[0], wrapLongitude(center[1] - longDegs)],
[center[0], wrapLongitude(center[1] + longDegs)],
[latitudeNorth, center[1]],
[latitudeNorth, wrapLongitude(center[1] - longDegs)],
[latitudeNorth, wrapLongitude(center[1] + longDegs)],
[latitudeSouth, center[1]],
[latitudeSouth, wrapLongitude(center[1] - longDegs)],
[latitudeSouth, wrapLongitude(center[1] + longDegs)]
];
}
|
[
"function",
"(",
"center",
",",
"radius",
")",
"{",
"var",
"latDegrees",
"=",
"radius",
"/",
"g_METERS_PER_DEGREE_LATITUDE",
";",
"var",
"latitudeNorth",
"=",
"Math",
".",
"min",
"(",
"90",
",",
"center",
"[",
"0",
"]",
"+",
"latDegrees",
")",
";",
"var",
"latitudeSouth",
"=",
"Math",
".",
"max",
"(",
"-",
"90",
",",
"center",
"[",
"0",
"]",
"-",
"latDegrees",
")",
";",
"var",
"longDegsNorth",
"=",
"metersToLongitudeDegrees",
"(",
"radius",
",",
"latitudeNorth",
")",
";",
"var",
"longDegsSouth",
"=",
"metersToLongitudeDegrees",
"(",
"radius",
",",
"latitudeSouth",
")",
";",
"var",
"longDegs",
"=",
"Math",
".",
"max",
"(",
"longDegsNorth",
",",
"longDegsSouth",
")",
";",
"return",
"[",
"[",
"center",
"[",
"0",
"]",
",",
"center",
"[",
"1",
"]",
"]",
",",
"[",
"center",
"[",
"0",
"]",
",",
"wrapLongitude",
"(",
"center",
"[",
"1",
"]",
"-",
"longDegs",
")",
"]",
",",
"[",
"center",
"[",
"0",
"]",
",",
"wrapLongitude",
"(",
"center",
"[",
"1",
"]",
"+",
"longDegs",
")",
"]",
",",
"[",
"latitudeNorth",
",",
"center",
"[",
"1",
"]",
"]",
",",
"[",
"latitudeNorth",
",",
"wrapLongitude",
"(",
"center",
"[",
"1",
"]",
"-",
"longDegs",
")",
"]",
",",
"[",
"latitudeNorth",
",",
"wrapLongitude",
"(",
"center",
"[",
"1",
"]",
"+",
"longDegs",
")",
"]",
",",
"[",
"latitudeSouth",
",",
"center",
"[",
"1",
"]",
"]",
",",
"[",
"latitudeSouth",
",",
"wrapLongitude",
"(",
"center",
"[",
"1",
"]",
"-",
"longDegs",
")",
"]",
",",
"[",
"latitudeSouth",
",",
"wrapLongitude",
"(",
"center",
"[",
"1",
"]",
"+",
"longDegs",
")",
"]",
"]",
";",
"}"
] |
Calculates eight points on the bounding box and the center of a given circle. At least one
geohash of these nine coordinates, truncated to a precision of at most radius, are guaranteed
to be prefixes of any geohash that lies within the circle.
@param {Array.<number>} center The center given as [latitude, longitude].
@param {number} radius The radius of the circle.
@return {Array.<Array.<number>>} The eight bounding box points.
|
[
"Calculates",
"eight",
"points",
"on",
"the",
"bounding",
"box",
"and",
"the",
"center",
"of",
"a",
"given",
"circle",
".",
"At",
"least",
"one",
"geohash",
"of",
"these",
"nine",
"coordinates",
"truncated",
"to",
"a",
"precision",
"of",
"at",
"most",
"radius",
"are",
"guaranteed",
"to",
"be",
"prefixes",
"of",
"any",
"geohash",
"that",
"lies",
"within",
"the",
"circle",
"."
] |
225c8949e814ec7b39d1457f3aa3c63808a79470
|
https://github.com/WildDogTeam/lib-js-wildgeo/blob/225c8949e814ec7b39d1457f3aa3c63808a79470/src/geoDogUtils.js#L341-L359
|
|
38,630 |
WildDogTeam/lib-js-wildgeo
|
src/geoDogUtils.js
|
function(geohash, bits) {
validateGeohash(geohash);
var precision = Math.ceil(bits/g_BITS_PER_CHAR);
if (geohash.length < precision) {
return [geohash, geohash+"~"];
}
geohash = geohash.substring(0, precision);
var base = geohash.substring(0, geohash.length - 1);
var lastValue = g_BASE32.indexOf(geohash.charAt(geohash.length - 1));
var significantBits = bits - (base.length*g_BITS_PER_CHAR);
var unusedBits = (g_BITS_PER_CHAR - significantBits);
/*jshint bitwise: false*/
// delete unused bits
var startValue = (lastValue >> unusedBits) << unusedBits;
var endValue = startValue + (1 << unusedBits);
/*jshint bitwise: true*/
if (endValue > 31) {
return [base+g_BASE32[startValue], base+"~"];
}
else {
return [base+g_BASE32[startValue], base+g_BASE32[endValue]];
}
}
|
javascript
|
function(geohash, bits) {
validateGeohash(geohash);
var precision = Math.ceil(bits/g_BITS_PER_CHAR);
if (geohash.length < precision) {
return [geohash, geohash+"~"];
}
geohash = geohash.substring(0, precision);
var base = geohash.substring(0, geohash.length - 1);
var lastValue = g_BASE32.indexOf(geohash.charAt(geohash.length - 1));
var significantBits = bits - (base.length*g_BITS_PER_CHAR);
var unusedBits = (g_BITS_PER_CHAR - significantBits);
/*jshint bitwise: false*/
// delete unused bits
var startValue = (lastValue >> unusedBits) << unusedBits;
var endValue = startValue + (1 << unusedBits);
/*jshint bitwise: true*/
if (endValue > 31) {
return [base+g_BASE32[startValue], base+"~"];
}
else {
return [base+g_BASE32[startValue], base+g_BASE32[endValue]];
}
}
|
[
"function",
"(",
"geohash",
",",
"bits",
")",
"{",
"validateGeohash",
"(",
"geohash",
")",
";",
"var",
"precision",
"=",
"Math",
".",
"ceil",
"(",
"bits",
"/",
"g_BITS_PER_CHAR",
")",
";",
"if",
"(",
"geohash",
".",
"length",
"<",
"precision",
")",
"{",
"return",
"[",
"geohash",
",",
"geohash",
"+",
"\"~\"",
"]",
";",
"}",
"geohash",
"=",
"geohash",
".",
"substring",
"(",
"0",
",",
"precision",
")",
";",
"var",
"base",
"=",
"geohash",
".",
"substring",
"(",
"0",
",",
"geohash",
".",
"length",
"-",
"1",
")",
";",
"var",
"lastValue",
"=",
"g_BASE32",
".",
"indexOf",
"(",
"geohash",
".",
"charAt",
"(",
"geohash",
".",
"length",
"-",
"1",
")",
")",
";",
"var",
"significantBits",
"=",
"bits",
"-",
"(",
"base",
".",
"length",
"*",
"g_BITS_PER_CHAR",
")",
";",
"var",
"unusedBits",
"=",
"(",
"g_BITS_PER_CHAR",
"-",
"significantBits",
")",
";",
"/*jshint bitwise: false*/",
"// delete unused bits",
"var",
"startValue",
"=",
"(",
"lastValue",
">>",
"unusedBits",
")",
"<<",
"unusedBits",
";",
"var",
"endValue",
"=",
"startValue",
"+",
"(",
"1",
"<<",
"unusedBits",
")",
";",
"/*jshint bitwise: true*/",
"if",
"(",
"endValue",
">",
"31",
")",
"{",
"return",
"[",
"base",
"+",
"g_BASE32",
"[",
"startValue",
"]",
",",
"base",
"+",
"\"~\"",
"]",
";",
"}",
"else",
"{",
"return",
"[",
"base",
"+",
"g_BASE32",
"[",
"startValue",
"]",
",",
"base",
"+",
"g_BASE32",
"[",
"endValue",
"]",
"]",
";",
"}",
"}"
] |
Calculates the bounding box query for a geohash with x bits precision.
@param {string} geohash The geohash whose bounding box query to generate.
@param {number} bits The number of bits of precision.
@return {Array.<string>} A [start, end] pair of geohashes.
|
[
"Calculates",
"the",
"bounding",
"box",
"query",
"for",
"a",
"geohash",
"with",
"x",
"bits",
"precision",
"."
] |
225c8949e814ec7b39d1457f3aa3c63808a79470
|
https://github.com/WildDogTeam/lib-js-wildgeo/blob/225c8949e814ec7b39d1457f3aa3c63808a79470/src/geoDogUtils.js#L368-L390
|
|
38,631 |
PlatziDev/react-markdown
|
index.js
|
reducer
|
function reducer(props, map, key) {
return Object.assign({}, map, {
[key]: props[key],
});
}
|
javascript
|
function reducer(props, map, key) {
return Object.assign({}, map, {
[key]: props[key],
});
}
|
[
"function",
"reducer",
"(",
"props",
",",
"map",
",",
"key",
")",
"{",
"return",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"map",
",",
"{",
"[",
"key",
"]",
":",
"props",
"[",
"key",
"]",
",",
"}",
")",
";",
"}"
] |
Merge props into a new map
@param {Object} props The original prop map
@param {Object} map The new prop map to fill
@param {string} key Each key name that have passed the filter
@return {Object} The new prop map with the setted prop
|
[
"Merge",
"props",
"into",
"a",
"new",
"map"
] |
f3f186627231bad7a4422df17191a68ff8c130df
|
https://github.com/PlatziDev/react-markdown/blob/f3f186627231bad7a4422df17191a68ff8c130df/index.js#L21-L25
|
38,632 |
PlatziDev/react-markdown
|
index.js
|
Markdown
|
function Markdown(props) {
const tagProps = Object.keys(props).filter(filter).reduce(reducer.bind(null, props), {});
const parser = createParser(props.parser);
return React.createElement(
props.tagName,
Object.assign(tagProps, {
dangerouslySetInnerHTML: {
__html: parser(props.content),
},
}),
);
}
|
javascript
|
function Markdown(props) {
const tagProps = Object.keys(props).filter(filter).reduce(reducer.bind(null, props), {});
const parser = createParser(props.parser);
return React.createElement(
props.tagName,
Object.assign(tagProps, {
dangerouslySetInnerHTML: {
__html: parser(props.content),
},
}),
);
}
|
[
"function",
"Markdown",
"(",
"props",
")",
"{",
"const",
"tagProps",
"=",
"Object",
".",
"keys",
"(",
"props",
")",
".",
"filter",
"(",
"filter",
")",
".",
"reduce",
"(",
"reducer",
".",
"bind",
"(",
"null",
",",
"props",
")",
",",
"{",
"}",
")",
";",
"const",
"parser",
"=",
"createParser",
"(",
"props",
".",
"parser",
")",
";",
"return",
"React",
".",
"createElement",
"(",
"props",
".",
"tagName",
",",
"Object",
".",
"assign",
"(",
"tagProps",
",",
"{",
"dangerouslySetInnerHTML",
":",
"{",
"__html",
":",
"parser",
"(",
"props",
".",
"content",
")",
",",
"}",
",",
"}",
")",
",",
")",
";",
"}"
] |
Render Platzi Flavored Markdown inside a React application.
@param {string} [props.tagName='div'] The HTML tag used as wrapper
@param {string} props.content The Markdown content to parse and render
@param {Object} [props.parser={}] The parser options
|
[
"Render",
"Platzi",
"Flavored",
"Markdown",
"inside",
"a",
"React",
"application",
"."
] |
f3f186627231bad7a4422df17191a68ff8c130df
|
https://github.com/PlatziDev/react-markdown/blob/f3f186627231bad7a4422df17191a68ff8c130df/index.js#L33-L46
|
38,633 |
Schoonology/discovery
|
lib/managers/http.js
|
HttpManager
|
function HttpManager(options) {
if (!(this instanceof HttpManager)) {
return new HttpManager(options);
}
options = options || {};
Manager.call(this, options);
debug('New HttpManager: %j', options);
this.hostname = options.hostname || null;
this.port = options.port || Defaults.PORT;
this.interval = options.interval || Defaults.INTERVAL;
this._announceTimerId = null;
this._startAnnouncements();
}
|
javascript
|
function HttpManager(options) {
if (!(this instanceof HttpManager)) {
return new HttpManager(options);
}
options = options || {};
Manager.call(this, options);
debug('New HttpManager: %j', options);
this.hostname = options.hostname || null;
this.port = options.port || Defaults.PORT;
this.interval = options.interval || Defaults.INTERVAL;
this._announceTimerId = null;
this._startAnnouncements();
}
|
[
"function",
"HttpManager",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"HttpManager",
")",
")",
"{",
"return",
"new",
"HttpManager",
"(",
"options",
")",
";",
"}",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"Manager",
".",
"call",
"(",
"this",
",",
"options",
")",
";",
"debug",
"(",
"'New HttpManager: %j'",
",",
"options",
")",
";",
"this",
".",
"hostname",
"=",
"options",
".",
"hostname",
"||",
"null",
";",
"this",
".",
"port",
"=",
"options",
".",
"port",
"||",
"Defaults",
".",
"PORT",
";",
"this",
".",
"interval",
"=",
"options",
".",
"interval",
"||",
"Defaults",
".",
"INTERVAL",
";",
"this",
".",
"_announceTimerId",
"=",
"null",
";",
"this",
".",
"_startAnnouncements",
"(",
")",
";",
"}"
] |
Creates a new instance of HttpManager with the provided `options`.
The HttpManager provides a client connection to the HTTP-based, Tracker
discovery system.
For more information, see the README.
@param {Object} options
|
[
"Creates",
"a",
"new",
"instance",
"of",
"HttpManager",
"with",
"the",
"provided",
"options",
"."
] |
9d123d74c13f8c9b6904e409f8933b09ab22e175
|
https://github.com/Schoonology/discovery/blob/9d123d74c13f8c9b6904e409f8933b09ab22e175/lib/managers/http.js#L23-L42
|
38,634 |
AmpersandJS/ampersand-filtered-subcollection
|
ampersand-filtered-subcollection.js
|
function (newFilters, oldFilters) {
var self = this;
if (!oldFilters) {
oldFilters = this._filters;
} else if (!isArray(oldFilters)) {
oldFilters = [oldFilters];
}
if (!newFilters) {
newFilters = [];
} else if (!isArray(newFilters)) {
newFilters = [newFilters];
}
oldFilters.forEach(function (filter) {
self._removeFilter(filter);
});
newFilters.forEach(function (filter) {
self._addFilter(filter);
});
this._runFilters();
}
|
javascript
|
function (newFilters, oldFilters) {
var self = this;
if (!oldFilters) {
oldFilters = this._filters;
} else if (!isArray(oldFilters)) {
oldFilters = [oldFilters];
}
if (!newFilters) {
newFilters = [];
} else if (!isArray(newFilters)) {
newFilters = [newFilters];
}
oldFilters.forEach(function (filter) {
self._removeFilter(filter);
});
newFilters.forEach(function (filter) {
self._addFilter(filter);
});
this._runFilters();
}
|
[
"function",
"(",
"newFilters",
",",
"oldFilters",
")",
"{",
"var",
"self",
"=",
"this",
";",
"if",
"(",
"!",
"oldFilters",
")",
"{",
"oldFilters",
"=",
"this",
".",
"_filters",
";",
"}",
"else",
"if",
"(",
"!",
"isArray",
"(",
"oldFilters",
")",
")",
"{",
"oldFilters",
"=",
"[",
"oldFilters",
"]",
";",
"}",
"if",
"(",
"!",
"newFilters",
")",
"{",
"newFilters",
"=",
"[",
"]",
";",
"}",
"else",
"if",
"(",
"!",
"isArray",
"(",
"newFilters",
")",
")",
"{",
"newFilters",
"=",
"[",
"newFilters",
"]",
";",
"}",
"oldFilters",
".",
"forEach",
"(",
"function",
"(",
"filter",
")",
"{",
"self",
".",
"_removeFilter",
"(",
"filter",
")",
";",
"}",
")",
";",
"newFilters",
".",
"forEach",
"(",
"function",
"(",
"filter",
")",
"{",
"self",
".",
"_addFilter",
"(",
"filter",
")",
";",
"}",
")",
";",
"this",
".",
"_runFilters",
"(",
")",
";",
"}"
] |
Swap out a set of old filters with a set of new filters
|
[
"Swap",
"out",
"a",
"set",
"of",
"old",
"filters",
"with",
"a",
"set",
"of",
"new",
"filters"
] |
50fe385c658faff62e5c610217c949ad0e2c3ce2
|
https://github.com/AmpersandJS/ampersand-filtered-subcollection/blob/50fe385c658faff62e5c610217c949ad0e2c3ce2/ampersand-filtered-subcollection.js#L53-L77
|
|
38,635 |
AmpersandJS/ampersand-filtered-subcollection
|
ampersand-filtered-subcollection.js
|
function (query, indexName) {
var model = this.collection.get(query, indexName);
if (model && includes(this.models, model)) return model;
}
|
javascript
|
function (query, indexName) {
var model = this.collection.get(query, indexName);
if (model && includes(this.models, model)) return model;
}
|
[
"function",
"(",
"query",
",",
"indexName",
")",
"{",
"var",
"model",
"=",
"this",
".",
"collection",
".",
"get",
"(",
"query",
",",
"indexName",
")",
";",
"if",
"(",
"model",
"&&",
"includes",
"(",
"this",
".",
"models",
",",
"model",
")",
")",
"return",
"model",
";",
"}"
] |
proxy `get` method to the underlying collection
|
[
"proxy",
"get",
"method",
"to",
"the",
"underlying",
"collection"
] |
50fe385c658faff62e5c610217c949ad0e2c3ce2
|
https://github.com/AmpersandJS/ampersand-filtered-subcollection/blob/50fe385c658faff62e5c610217c949ad0e2c3ce2/ampersand-filtered-subcollection.js#L92-L95
|
|
38,636 |
AmpersandJS/ampersand-filtered-subcollection
|
ampersand-filtered-subcollection.js
|
function (query, indexName) {
if (!query) return;
var index = this._indexes[indexName || this.mainIndex];
return index[query] || index[query[this.mainIndex]] || this._indexes.cid[query] || this._indexes.cid[query.cid];
}
|
javascript
|
function (query, indexName) {
if (!query) return;
var index = this._indexes[indexName || this.mainIndex];
return index[query] || index[query[this.mainIndex]] || this._indexes.cid[query] || this._indexes.cid[query.cid];
}
|
[
"function",
"(",
"query",
",",
"indexName",
")",
"{",
"if",
"(",
"!",
"query",
")",
"return",
";",
"var",
"index",
"=",
"this",
".",
"_indexes",
"[",
"indexName",
"||",
"this",
".",
"mainIndex",
"]",
";",
"return",
"index",
"[",
"query",
"]",
"||",
"index",
"[",
"query",
"[",
"this",
".",
"mainIndex",
"]",
"]",
"||",
"this",
".",
"_indexes",
".",
"cid",
"[",
"query",
"]",
"||",
"this",
".",
"_indexes",
".",
"cid",
"[",
"query",
".",
"cid",
"]",
";",
"}"
] |
Internal API try to get a model by index
|
[
"Internal",
"API",
"try",
"to",
"get",
"a",
"model",
"by",
"index"
] |
50fe385c658faff62e5c610217c949ad0e2c3ce2
|
https://github.com/AmpersandJS/ampersand-filtered-subcollection/blob/50fe385c658faff62e5c610217c949ad0e2c3ce2/ampersand-filtered-subcollection.js#L105-L109
|
|
38,637 |
AmpersandJS/ampersand-filtered-subcollection
|
ampersand-filtered-subcollection.js
|
function (model, options, eventName) {
var newModels = slice.call(this.models);
var comparator = this.comparator || this.collection.comparator;
//Whether or not we are to expect a sort event from our collection later
var sortable = eventName === 'add' && this.collection.comparator && (options.at == null) && options.sort !== false;
if (!sortable) {
var index = sortedIndexBy(newModels, model, comparator);
newModels.splice(index, 0, model);
} else {
newModels.push(model);
if (options.at) newModels = this._sortModels(newModels);
}
this.models = newModels;
this._addIndex(this._indexes, model);
if (this.comparator && !sortable) {
this.trigger('sort', this);
}
}
|
javascript
|
function (model, options, eventName) {
var newModels = slice.call(this.models);
var comparator = this.comparator || this.collection.comparator;
//Whether or not we are to expect a sort event from our collection later
var sortable = eventName === 'add' && this.collection.comparator && (options.at == null) && options.sort !== false;
if (!sortable) {
var index = sortedIndexBy(newModels, model, comparator);
newModels.splice(index, 0, model);
} else {
newModels.push(model);
if (options.at) newModels = this._sortModels(newModels);
}
this.models = newModels;
this._addIndex(this._indexes, model);
if (this.comparator && !sortable) {
this.trigger('sort', this);
}
}
|
[
"function",
"(",
"model",
",",
"options",
",",
"eventName",
")",
"{",
"var",
"newModels",
"=",
"slice",
".",
"call",
"(",
"this",
".",
"models",
")",
";",
"var",
"comparator",
"=",
"this",
".",
"comparator",
"||",
"this",
".",
"collection",
".",
"comparator",
";",
"//Whether or not we are to expect a sort event from our collection later",
"var",
"sortable",
"=",
"eventName",
"===",
"'add'",
"&&",
"this",
".",
"collection",
".",
"comparator",
"&&",
"(",
"options",
".",
"at",
"==",
"null",
")",
"&&",
"options",
".",
"sort",
"!==",
"false",
";",
"if",
"(",
"!",
"sortable",
")",
"{",
"var",
"index",
"=",
"sortedIndexBy",
"(",
"newModels",
",",
"model",
",",
"comparator",
")",
";",
"newModels",
".",
"splice",
"(",
"index",
",",
"0",
",",
"model",
")",
";",
"}",
"else",
"{",
"newModels",
".",
"push",
"(",
"model",
")",
";",
"if",
"(",
"options",
".",
"at",
")",
"newModels",
"=",
"this",
".",
"_sortModels",
"(",
"newModels",
")",
";",
"}",
"this",
".",
"models",
"=",
"newModels",
";",
"this",
".",
"_addIndex",
"(",
"this",
".",
"_indexes",
",",
"model",
")",
";",
"if",
"(",
"this",
".",
"comparator",
"&&",
"!",
"sortable",
")",
"{",
"this",
".",
"trigger",
"(",
"'sort'",
",",
"this",
")",
";",
"}",
"}"
] |
Add a model to this filtered collection that has already passed the filters
|
[
"Add",
"a",
"model",
"to",
"this",
"filtered",
"collection",
"that",
"has",
"already",
"passed",
"the",
"filters"
] |
50fe385c658faff62e5c610217c949ad0e2c3ce2
|
https://github.com/AmpersandJS/ampersand-filtered-subcollection/blob/50fe385c658faff62e5c610217c949ad0e2c3ce2/ampersand-filtered-subcollection.js#L178-L196
|
|
38,638 |
AmpersandJS/ampersand-filtered-subcollection
|
ampersand-filtered-subcollection.js
|
function (model) {
var newModels = slice.call(this.models);
var modelIndex = newModels.indexOf(model);
if (modelIndex > -1) {
newModels.splice(modelIndex, 1);
this.models = newModels;
this._removeIndex(this._indexes, model);
return true;
}
return false;
}
|
javascript
|
function (model) {
var newModels = slice.call(this.models);
var modelIndex = newModels.indexOf(model);
if (modelIndex > -1) {
newModels.splice(modelIndex, 1);
this.models = newModels;
this._removeIndex(this._indexes, model);
return true;
}
return false;
}
|
[
"function",
"(",
"model",
")",
"{",
"var",
"newModels",
"=",
"slice",
".",
"call",
"(",
"this",
".",
"models",
")",
";",
"var",
"modelIndex",
"=",
"newModels",
".",
"indexOf",
"(",
"model",
")",
";",
"if",
"(",
"modelIndex",
">",
"-",
"1",
")",
"{",
"newModels",
".",
"splice",
"(",
"modelIndex",
",",
"1",
")",
";",
"this",
".",
"models",
"=",
"newModels",
";",
"this",
".",
"_removeIndex",
"(",
"this",
".",
"_indexes",
",",
"model",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Remove a model if it's in this filtered collection
|
[
"Remove",
"a",
"model",
"if",
"it",
"s",
"in",
"this",
"filtered",
"collection"
] |
50fe385c658faff62e5c610217c949ad0e2c3ce2
|
https://github.com/AmpersandJS/ampersand-filtered-subcollection/blob/50fe385c658faff62e5c610217c949ad0e2c3ce2/ampersand-filtered-subcollection.js#L199-L209
|
|
38,639 |
AmpersandJS/ampersand-filtered-subcollection
|
ampersand-filtered-subcollection.js
|
function () {
// make a copy of the array for comparisons
var existingModels = slice.call(this.models);
var rootModels = slice.call(this.collection.models);
var newIndexes = {};
var newModels, toAdd, toRemove;
this._resetIndexes(newIndexes);
// reduce base model set by applying filters
if (this._filters.length) {
newModels = reduce(this._filters, function (startingArray, filterFunc) {
return startingArray.filter(filterFunc);
}, rootModels);
} else {
newModels = slice.call(rootModels);
}
// sort it
if (this.comparator) newModels = this._sortModels(newModels, this.comparator);
newModels.forEach(function (model) {
this._addIndex(newIndexes, model);
}, this);
// Cache a reference to the full filtered set to allow this._filtered.length. Ref: #6
if (rootModels.length) {
this._filtered = newModels;
this._indexes = newIndexes;
} else {
this._filtered = [];
this._resetIndexes(this._indexes);
}
// now we've got our new models time to compare
toAdd = difference(newModels, existingModels);
toRemove = difference(existingModels, newModels);
// save 'em
this.models = newModels;
forEach(toRemove, bind(function (model) {
this.trigger('remove', model, this);
}, this));
forEach(toAdd, bind(function (model) {
this.trigger('add', model, this);
}, this));
// unless we have the same models in same order trigger `sort`
if (!isEqual(existingModels, newModels) && this.comparator) {
this.trigger('sort', this);
}
}
|
javascript
|
function () {
// make a copy of the array for comparisons
var existingModels = slice.call(this.models);
var rootModels = slice.call(this.collection.models);
var newIndexes = {};
var newModels, toAdd, toRemove;
this._resetIndexes(newIndexes);
// reduce base model set by applying filters
if (this._filters.length) {
newModels = reduce(this._filters, function (startingArray, filterFunc) {
return startingArray.filter(filterFunc);
}, rootModels);
} else {
newModels = slice.call(rootModels);
}
// sort it
if (this.comparator) newModels = this._sortModels(newModels, this.comparator);
newModels.forEach(function (model) {
this._addIndex(newIndexes, model);
}, this);
// Cache a reference to the full filtered set to allow this._filtered.length. Ref: #6
if (rootModels.length) {
this._filtered = newModels;
this._indexes = newIndexes;
} else {
this._filtered = [];
this._resetIndexes(this._indexes);
}
// now we've got our new models time to compare
toAdd = difference(newModels, existingModels);
toRemove = difference(existingModels, newModels);
// save 'em
this.models = newModels;
forEach(toRemove, bind(function (model) {
this.trigger('remove', model, this);
}, this));
forEach(toAdd, bind(function (model) {
this.trigger('add', model, this);
}, this));
// unless we have the same models in same order trigger `sort`
if (!isEqual(existingModels, newModels) && this.comparator) {
this.trigger('sort', this);
}
}
|
[
"function",
"(",
")",
"{",
"// make a copy of the array for comparisons",
"var",
"existingModels",
"=",
"slice",
".",
"call",
"(",
"this",
".",
"models",
")",
";",
"var",
"rootModels",
"=",
"slice",
".",
"call",
"(",
"this",
".",
"collection",
".",
"models",
")",
";",
"var",
"newIndexes",
"=",
"{",
"}",
";",
"var",
"newModels",
",",
"toAdd",
",",
"toRemove",
";",
"this",
".",
"_resetIndexes",
"(",
"newIndexes",
")",
";",
"// reduce base model set by applying filters",
"if",
"(",
"this",
".",
"_filters",
".",
"length",
")",
"{",
"newModels",
"=",
"reduce",
"(",
"this",
".",
"_filters",
",",
"function",
"(",
"startingArray",
",",
"filterFunc",
")",
"{",
"return",
"startingArray",
".",
"filter",
"(",
"filterFunc",
")",
";",
"}",
",",
"rootModels",
")",
";",
"}",
"else",
"{",
"newModels",
"=",
"slice",
".",
"call",
"(",
"rootModels",
")",
";",
"}",
"// sort it",
"if",
"(",
"this",
".",
"comparator",
")",
"newModels",
"=",
"this",
".",
"_sortModels",
"(",
"newModels",
",",
"this",
".",
"comparator",
")",
";",
"newModels",
".",
"forEach",
"(",
"function",
"(",
"model",
")",
"{",
"this",
".",
"_addIndex",
"(",
"newIndexes",
",",
"model",
")",
";",
"}",
",",
"this",
")",
";",
"// Cache a reference to the full filtered set to allow this._filtered.length. Ref: #6",
"if",
"(",
"rootModels",
".",
"length",
")",
"{",
"this",
".",
"_filtered",
"=",
"newModels",
";",
"this",
".",
"_indexes",
"=",
"newIndexes",
";",
"}",
"else",
"{",
"this",
".",
"_filtered",
"=",
"[",
"]",
";",
"this",
".",
"_resetIndexes",
"(",
"this",
".",
"_indexes",
")",
";",
"}",
"// now we've got our new models time to compare",
"toAdd",
"=",
"difference",
"(",
"newModels",
",",
"existingModels",
")",
";",
"toRemove",
"=",
"difference",
"(",
"existingModels",
",",
"newModels",
")",
";",
"// save 'em",
"this",
".",
"models",
"=",
"newModels",
";",
"forEach",
"(",
"toRemove",
",",
"bind",
"(",
"function",
"(",
"model",
")",
"{",
"this",
".",
"trigger",
"(",
"'remove'",
",",
"model",
",",
"this",
")",
";",
"}",
",",
"this",
")",
")",
";",
"forEach",
"(",
"toAdd",
",",
"bind",
"(",
"function",
"(",
"model",
")",
"{",
"this",
".",
"trigger",
"(",
"'add'",
",",
"model",
",",
"this",
")",
";",
"}",
",",
"this",
")",
")",
";",
"// unless we have the same models in same order trigger `sort`",
"if",
"(",
"!",
"isEqual",
"(",
"existingModels",
",",
"newModels",
")",
"&&",
"this",
".",
"comparator",
")",
"{",
"this",
".",
"trigger",
"(",
"'sort'",
",",
"this",
")",
";",
"}",
"}"
] |
Re-run the filters on all our parent's models
|
[
"Re",
"-",
"run",
"the",
"filters",
"on",
"all",
"our",
"parent",
"s",
"models"
] |
50fe385c658faff62e5c610217c949ad0e2c3ce2
|
https://github.com/AmpersandJS/ampersand-filtered-subcollection/blob/50fe385c658faff62e5c610217c949ad0e2c3ce2/ampersand-filtered-subcollection.js#L245-L298
|
|
38,640 |
rootsdev/gedcomx-js
|
src/core/NameForm.js
|
function(json){
// Protect against forgetting the new keyword when calling the constructor
if(!(this instanceof NameForm)){
return new NameForm(json);
}
// If the given object is already an instance then just return it. DON'T copy it.
if(NameForm.isInstance(json)){
return json;
}
this.init(json);
}
|
javascript
|
function(json){
// Protect against forgetting the new keyword when calling the constructor
if(!(this instanceof NameForm)){
return new NameForm(json);
}
// If the given object is already an instance then just return it. DON'T copy it.
if(NameForm.isInstance(json)){
return json;
}
this.init(json);
}
|
[
"function",
"(",
"json",
")",
"{",
"// Protect against forgetting the new keyword when calling the constructor",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"NameForm",
")",
")",
"{",
"return",
"new",
"NameForm",
"(",
"json",
")",
";",
"}",
"// If the given object is already an instance then just return it. DON'T copy it.",
"if",
"(",
"NameForm",
".",
"isInstance",
"(",
"json",
")",
")",
"{",
"return",
"json",
";",
"}",
"this",
".",
"init",
"(",
"json",
")",
";",
"}"
] |
A form of a name.
@see {@link https://github.com/FamilySearch/gedcomx/blob/master/specifications/json-format-specification.md#name-form|GEDCOM X JSON Spec}
@class
@extends ExtensibleData
@param {Object} [json]
|
[
"A",
"form",
"of",
"a",
"name",
"."
] |
08b2fcde96f1e301c78561bfb7a8b0cac606e26e
|
https://github.com/rootsdev/gedcomx-js/blob/08b2fcde96f1e301c78561bfb7a8b0cac606e26e/src/core/NameForm.js#L13-L26
|
|
38,641 |
Ubudu/uBeacon-uart-lib
|
node/examples/mesh-sender.js
|
function(callback){
ubeacon.getMeshSettingsRegisterObject( function(data, error){
if( error === null ){
meshSettings.setFrom( data );
console.log( 'meshSettings: ', meshSettings );
if( meshSettings.enabled !== true && program.enableMesh !== true ){
return callback(new Error('Mesh is disabled on device. Enable it by adding `--enable-mesh` parameter.'));
}
return callback(null);
}else{
return callback(error);
}
});
}
|
javascript
|
function(callback){
ubeacon.getMeshSettingsRegisterObject( function(data, error){
if( error === null ){
meshSettings.setFrom( data );
console.log( 'meshSettings: ', meshSettings );
if( meshSettings.enabled !== true && program.enableMesh !== true ){
return callback(new Error('Mesh is disabled on device. Enable it by adding `--enable-mesh` parameter.'));
}
return callback(null);
}else{
return callback(error);
}
});
}
|
[
"function",
"(",
"callback",
")",
"{",
"ubeacon",
".",
"getMeshSettingsRegisterObject",
"(",
"function",
"(",
"data",
",",
"error",
")",
"{",
"if",
"(",
"error",
"===",
"null",
")",
"{",
"meshSettings",
".",
"setFrom",
"(",
"data",
")",
";",
"console",
".",
"log",
"(",
"'meshSettings: '",
",",
"meshSettings",
")",
";",
"if",
"(",
"meshSettings",
".",
"enabled",
"!==",
"true",
"&&",
"program",
".",
"enableMesh",
"!==",
"true",
")",
"{",
"return",
"callback",
"(",
"new",
"Error",
"(",
"'Mesh is disabled on device. Enable it by adding `--enable-mesh` parameter.'",
")",
")",
";",
"}",
"return",
"callback",
"(",
"null",
")",
";",
"}",
"else",
"{",
"return",
"callback",
"(",
"error",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Check if mesh is enabled
|
[
"Check",
"if",
"mesh",
"is",
"enabled"
] |
a7436f3491f61ffabb34e2bc3b2441cc048f5dfa
|
https://github.com/Ubudu/uBeacon-uart-lib/blob/a7436f3491f61ffabb34e2bc3b2441cc048f5dfa/node/examples/mesh-sender.js#L35-L49
|
|
38,642 |
Ubudu/uBeacon-uart-lib
|
node/examples/mesh-sender.js
|
function(callback){
ubeacon.getMeshDeviceId( function( deviceAddress ){
console.log( '[ubeacon] Device address is: ' + deviceAddress + ' (0x' + deviceAddress.toString(16) + ')' );
callback(null);
});
}
|
javascript
|
function(callback){
ubeacon.getMeshDeviceId( function( deviceAddress ){
console.log( '[ubeacon] Device address is: ' + deviceAddress + ' (0x' + deviceAddress.toString(16) + ')' );
callback(null);
});
}
|
[
"function",
"(",
"callback",
")",
"{",
"ubeacon",
".",
"getMeshDeviceId",
"(",
"function",
"(",
"deviceAddress",
")",
"{",
"console",
".",
"log",
"(",
"'[ubeacon] Device address is: '",
"+",
"deviceAddress",
"+",
"' (0x'",
"+",
"deviceAddress",
".",
"toString",
"(",
"16",
")",
"+",
"')'",
")",
";",
"callback",
"(",
"null",
")",
";",
"}",
")",
";",
"}"
] |
Get device address and print it
|
[
"Get",
"device",
"address",
"and",
"print",
"it"
] |
a7436f3491f61ffabb34e2bc3b2441cc048f5dfa
|
https://github.com/Ubudu/uBeacon-uart-lib/blob/a7436f3491f61ffabb34e2bc3b2441cc048f5dfa/node/examples/mesh-sender.js#L68-L73
|
|
38,643 |
Ubudu/uBeacon-uart-lib
|
node/examples/mesh-sender.js
|
function(callback){
console.log( 'Start sending messages... ');
setInterval(function(){
var msg = '';
if( program.message != null ){
msg = program.message;
}else{
msgCounter++;
msg = 'Hello #' + msgCounter + ' from node.js';
}
console.log( '[ubeacon] Sending "' +msg+ '" to device: ' + program.destinationAddress );
ubeacon.sendMeshGenericMessage( program.destinationAddress, msg, function( response ){
console.log( '[ubeacon] Mesh message #' + msgCounter + ' sent. Response: ' + response );
});
}, interval);
}
|
javascript
|
function(callback){
console.log( 'Start sending messages... ');
setInterval(function(){
var msg = '';
if( program.message != null ){
msg = program.message;
}else{
msgCounter++;
msg = 'Hello #' + msgCounter + ' from node.js';
}
console.log( '[ubeacon] Sending "' +msg+ '" to device: ' + program.destinationAddress );
ubeacon.sendMeshGenericMessage( program.destinationAddress, msg, function( response ){
console.log( '[ubeacon] Mesh message #' + msgCounter + ' sent. Response: ' + response );
});
}, interval);
}
|
[
"function",
"(",
"callback",
")",
"{",
"console",
".",
"log",
"(",
"'Start sending messages... '",
")",
";",
"setInterval",
"(",
"function",
"(",
")",
"{",
"var",
"msg",
"=",
"''",
";",
"if",
"(",
"program",
".",
"message",
"!=",
"null",
")",
"{",
"msg",
"=",
"program",
".",
"message",
";",
"}",
"else",
"{",
"msgCounter",
"++",
";",
"msg",
"=",
"'Hello #'",
"+",
"msgCounter",
"+",
"' from node.js'",
";",
"}",
"console",
".",
"log",
"(",
"'[ubeacon] Sending \"'",
"+",
"msg",
"+",
"'\" to device: '",
"+",
"program",
".",
"destinationAddress",
")",
";",
"ubeacon",
".",
"sendMeshGenericMessage",
"(",
"program",
".",
"destinationAddress",
",",
"msg",
",",
"function",
"(",
"response",
")",
"{",
"console",
".",
"log",
"(",
"'[ubeacon] Mesh message #'",
"+",
"msgCounter",
"+",
"' sent. Response: '",
"+",
"response",
")",
";",
"}",
")",
";",
"}",
",",
"interval",
")",
";",
"}"
] |
Send message - works until script is terminated
|
[
"Send",
"message",
"-",
"works",
"until",
"script",
"is",
"terminated"
] |
a7436f3491f61ffabb34e2bc3b2441cc048f5dfa
|
https://github.com/Ubudu/uBeacon-uart-lib/blob/a7436f3491f61ffabb34e2bc3b2441cc048f5dfa/node/examples/mesh-sender.js#L76-L91
|
|
38,644 |
AppGeo/cartodb
|
lib/builder.js
|
columns
|
function columns(column) {
if (!column) {
return this;
}
this._statements.push({
grouping: 'columns',
value: normalizeArr.apply(null, arguments)
});
return this;
}
|
javascript
|
function columns(column) {
if (!column) {
return this;
}
this._statements.push({
grouping: 'columns',
value: normalizeArr.apply(null, arguments)
});
return this;
}
|
[
"function",
"columns",
"(",
"column",
")",
"{",
"if",
"(",
"!",
"column",
")",
"{",
"return",
"this",
";",
"}",
"this",
".",
"_statements",
".",
"push",
"(",
"{",
"grouping",
":",
"'columns'",
",",
"value",
":",
"normalizeArr",
".",
"apply",
"(",
"null",
",",
"arguments",
")",
"}",
")",
";",
"return",
"this",
";",
"}"
] |
Adds a column or columns to the list of "columns" being selected on the query.
|
[
"Adds",
"a",
"column",
"or",
"columns",
"to",
"the",
"list",
"of",
"columns",
"being",
"selected",
"on",
"the",
"query",
"."
] |
4cc624975d359800961bf34cb74de97488d2efb5
|
https://github.com/AppGeo/cartodb/blob/4cc624975d359800961bf34cb74de97488d2efb5/lib/builder.js#L59-L68
|
38,645 |
AppGeo/cartodb
|
lib/builder.js
|
distinct
|
function distinct() {
this._statements.push({
grouping: 'columns',
value: normalizeArr.apply(null, arguments),
distinct: true
});
return this;
}
|
javascript
|
function distinct() {
this._statements.push({
grouping: 'columns',
value: normalizeArr.apply(null, arguments),
distinct: true
});
return this;
}
|
[
"function",
"distinct",
"(",
")",
"{",
"this",
".",
"_statements",
".",
"push",
"(",
"{",
"grouping",
":",
"'columns'",
",",
"value",
":",
"normalizeArr",
".",
"apply",
"(",
"null",
",",
"arguments",
")",
",",
"distinct",
":",
"true",
"}",
")",
";",
"return",
"this",
";",
"}"
] |
Adds a `distinct` clause to the query.
|
[
"Adds",
"a",
"distinct",
"clause",
"to",
"the",
"query",
"."
] |
4cc624975d359800961bf34cb74de97488d2efb5
|
https://github.com/AppGeo/cartodb/blob/4cc624975d359800961bf34cb74de97488d2efb5/lib/builder.js#L86-L93
|
38,646 |
AppGeo/cartodb
|
lib/builder.js
|
_objectWhere
|
function _objectWhere(obj) {
var boolVal = this._bool();
var notVal = this._not() ? 'Not' : '';
for (var key in obj) {
this[boolVal + 'Where' + notVal](key, obj[key]);
}
return this;
}
|
javascript
|
function _objectWhere(obj) {
var boolVal = this._bool();
var notVal = this._not() ? 'Not' : '';
for (var key in obj) {
this[boolVal + 'Where' + notVal](key, obj[key]);
}
return this;
}
|
[
"function",
"_objectWhere",
"(",
"obj",
")",
"{",
"var",
"boolVal",
"=",
"this",
".",
"_bool",
"(",
")",
";",
"var",
"notVal",
"=",
"this",
".",
"_not",
"(",
")",
"?",
"'Not'",
":",
"''",
";",
"for",
"(",
"var",
"key",
"in",
"obj",
")",
"{",
"this",
"[",
"boolVal",
"+",
"'Where'",
"+",
"notVal",
"]",
"(",
"key",
",",
"obj",
"[",
"key",
"]",
")",
";",
"}",
"return",
"this",
";",
"}"
] |
Processes an object literal provided in a "where" clause.
|
[
"Processes",
"an",
"object",
"literal",
"provided",
"in",
"a",
"where",
"clause",
"."
] |
4cc624975d359800961bf34cb74de97488d2efb5
|
https://github.com/AppGeo/cartodb/blob/4cc624975d359800961bf34cb74de97488d2efb5/lib/builder.js#L241-L248
|
38,647 |
AppGeo/cartodb
|
lib/builder.js
|
havingWrapped
|
function havingWrapped(callback) {
this._statements.push({
grouping: 'having',
type: 'whereWrapped',
value: callback,
bool: this._bool()
});
return this;
}
|
javascript
|
function havingWrapped(callback) {
this._statements.push({
grouping: 'having',
type: 'whereWrapped',
value: callback,
bool: this._bool()
});
return this;
}
|
[
"function",
"havingWrapped",
"(",
"callback",
")",
"{",
"this",
".",
"_statements",
".",
"push",
"(",
"{",
"grouping",
":",
"'having'",
",",
"type",
":",
"'whereWrapped'",
",",
"value",
":",
"callback",
",",
"bool",
":",
"this",
".",
"_bool",
"(",
")",
"}",
")",
";",
"return",
"this",
";",
"}"
] |
Helper for compiling any advanced `having` queries.
|
[
"Helper",
"for",
"compiling",
"any",
"advanced",
"having",
"queries",
"."
] |
4cc624975d359800961bf34cb74de97488d2efb5
|
https://github.com/AppGeo/cartodb/blob/4cc624975d359800961bf34cb74de97488d2efb5/lib/builder.js#L279-L287
|
38,648 |
AppGeo/cartodb
|
lib/builder.js
|
whereExists
|
function whereExists(callback) {
this._statements.push({
grouping: 'where',
type: 'whereExists',
value: callback,
not: this._not(),
bool: this._bool() });
return this;
}
|
javascript
|
function whereExists(callback) {
this._statements.push({
grouping: 'where',
type: 'whereExists',
value: callback,
not: this._not(),
bool: this._bool() });
return this;
}
|
[
"function",
"whereExists",
"(",
"callback",
")",
"{",
"this",
".",
"_statements",
".",
"push",
"(",
"{",
"grouping",
":",
"'where'",
",",
"type",
":",
"'whereExists'",
",",
"value",
":",
"callback",
",",
"not",
":",
"this",
".",
"_not",
"(",
")",
",",
"bool",
":",
"this",
".",
"_bool",
"(",
")",
"}",
")",
";",
"return",
"this",
";",
"}"
] |
Adds a `where exists` clause to the query.
|
[
"Adds",
"a",
"where",
"exists",
"clause",
"to",
"the",
"query",
"."
] |
4cc624975d359800961bf34cb74de97488d2efb5
|
https://github.com/AppGeo/cartodb/blob/4cc624975d359800961bf34cb74de97488d2efb5/lib/builder.js#L290-L298
|
38,649 |
AppGeo/cartodb
|
lib/builder.js
|
whereIn
|
function whereIn(column, values) {
if (Array.isArray(values) && isEmpty(values)) {
return this.where(this._not());
}
this._statements.push({
grouping: 'where',
type: 'whereIn',
column: column,
value: values,
not: this._not(),
bool: this._bool()
});
return this;
}
|
javascript
|
function whereIn(column, values) {
if (Array.isArray(values) && isEmpty(values)) {
return this.where(this._not());
}
this._statements.push({
grouping: 'where',
type: 'whereIn',
column: column,
value: values,
not: this._not(),
bool: this._bool()
});
return this;
}
|
[
"function",
"whereIn",
"(",
"column",
",",
"values",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"values",
")",
"&&",
"isEmpty",
"(",
"values",
")",
")",
"{",
"return",
"this",
".",
"where",
"(",
"this",
".",
"_not",
"(",
")",
")",
";",
"}",
"this",
".",
"_statements",
".",
"push",
"(",
"{",
"grouping",
":",
"'where'",
",",
"type",
":",
"'whereIn'",
",",
"column",
":",
"column",
",",
"value",
":",
"values",
",",
"not",
":",
"this",
".",
"_not",
"(",
")",
",",
"bool",
":",
"this",
".",
"_bool",
"(",
")",
"}",
")",
";",
"return",
"this",
";",
"}"
] |
Adds a `where in` clause to the query.
|
[
"Adds",
"a",
"where",
"in",
"clause",
"to",
"the",
"query",
"."
] |
4cc624975d359800961bf34cb74de97488d2efb5
|
https://github.com/AppGeo/cartodb/blob/4cc624975d359800961bf34cb74de97488d2efb5/lib/builder.js#L316-L329
|
38,650 |
AppGeo/cartodb
|
lib/builder.js
|
whereNull
|
function whereNull(column) {
this._statements.push({
grouping: 'where',
type: 'whereNull',
column: column,
not: this._not(),
bool: this._bool()
});
return this;
}
|
javascript
|
function whereNull(column) {
this._statements.push({
grouping: 'where',
type: 'whereNull',
column: column,
not: this._not(),
bool: this._bool()
});
return this;
}
|
[
"function",
"whereNull",
"(",
"column",
")",
"{",
"this",
".",
"_statements",
".",
"push",
"(",
"{",
"grouping",
":",
"'where'",
",",
"type",
":",
"'whereNull'",
",",
"column",
":",
"column",
",",
"not",
":",
"this",
".",
"_not",
"(",
")",
",",
"bool",
":",
"this",
".",
"_bool",
"(",
")",
"}",
")",
";",
"return",
"this",
";",
"}"
] |
Adds a `where null` clause to the query.
|
[
"Adds",
"a",
"where",
"null",
"clause",
"to",
"the",
"query",
"."
] |
4cc624975d359800961bf34cb74de97488d2efb5
|
https://github.com/AppGeo/cartodb/blob/4cc624975d359800961bf34cb74de97488d2efb5/lib/builder.js#L347-L356
|
38,651 |
AppGeo/cartodb
|
lib/builder.js
|
whereBetween
|
function whereBetween(column, values) {
assert(Array.isArray(values), 'The second argument to whereBetween must be an array.');
assert(values.length === 2, 'You must specify 2 values for the whereBetween clause');
this._statements.push({
grouping: 'where',
type: 'whereBetween',
column: column,
value: values,
not: this._not(),
bool: this._bool()
});
return this;
}
|
javascript
|
function whereBetween(column, values) {
assert(Array.isArray(values), 'The second argument to whereBetween must be an array.');
assert(values.length === 2, 'You must specify 2 values for the whereBetween clause');
this._statements.push({
grouping: 'where',
type: 'whereBetween',
column: column,
value: values,
not: this._not(),
bool: this._bool()
});
return this;
}
|
[
"function",
"whereBetween",
"(",
"column",
",",
"values",
")",
"{",
"assert",
"(",
"Array",
".",
"isArray",
"(",
"values",
")",
",",
"'The second argument to whereBetween must be an array.'",
")",
";",
"assert",
"(",
"values",
".",
"length",
"===",
"2",
",",
"'You must specify 2 values for the whereBetween clause'",
")",
";",
"this",
".",
"_statements",
".",
"push",
"(",
"{",
"grouping",
":",
"'where'",
",",
"type",
":",
"'whereBetween'",
",",
"column",
":",
"column",
",",
"value",
":",
"values",
",",
"not",
":",
"this",
".",
"_not",
"(",
")",
",",
"bool",
":",
"this",
".",
"_bool",
"(",
")",
"}",
")",
";",
"return",
"this",
";",
"}"
] |
Adds a `where between` clause to the query.
|
[
"Adds",
"a",
"where",
"between",
"clause",
"to",
"the",
"query",
"."
] |
4cc624975d359800961bf34cb74de97488d2efb5
|
https://github.com/AppGeo/cartodb/blob/4cc624975d359800961bf34cb74de97488d2efb5/lib/builder.js#L374-L386
|
38,652 |
AppGeo/cartodb
|
lib/builder.js
|
groupBy
|
function groupBy(item) {
if (item instanceof Raw) {
return this.groupByRaw.apply(this, arguments);
}
this._statements.push({
grouping: 'group',
type: 'groupByBasic',
value: normalizeArr.apply(null, arguments)
});
return this;
}
|
javascript
|
function groupBy(item) {
if (item instanceof Raw) {
return this.groupByRaw.apply(this, arguments);
}
this._statements.push({
grouping: 'group',
type: 'groupByBasic',
value: normalizeArr.apply(null, arguments)
});
return this;
}
|
[
"function",
"groupBy",
"(",
"item",
")",
"{",
"if",
"(",
"item",
"instanceof",
"Raw",
")",
"{",
"return",
"this",
".",
"groupByRaw",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"}",
"this",
".",
"_statements",
".",
"push",
"(",
"{",
"grouping",
":",
"'group'",
",",
"type",
":",
"'groupByBasic'",
",",
"value",
":",
"normalizeArr",
".",
"apply",
"(",
"null",
",",
"arguments",
")",
"}",
")",
";",
"return",
"this",
";",
"}"
] |
Adds a `group by` clause to the query.
|
[
"Adds",
"a",
"group",
"by",
"clause",
"to",
"the",
"query",
"."
] |
4cc624975d359800961bf34cb74de97488d2efb5
|
https://github.com/AppGeo/cartodb/blob/4cc624975d359800961bf34cb74de97488d2efb5/lib/builder.js#L404-L414
|
38,653 |
AppGeo/cartodb
|
lib/builder.js
|
groupByRaw
|
function groupByRaw(sql, bindings) {
var raw = sql instanceof Raw ? sql : this.client.raw(sql, bindings);
this._statements.push({
grouping: 'group',
type: 'groupByRaw',
value: raw
});
return this;
}
|
javascript
|
function groupByRaw(sql, bindings) {
var raw = sql instanceof Raw ? sql : this.client.raw(sql, bindings);
this._statements.push({
grouping: 'group',
type: 'groupByRaw',
value: raw
});
return this;
}
|
[
"function",
"groupByRaw",
"(",
"sql",
",",
"bindings",
")",
"{",
"var",
"raw",
"=",
"sql",
"instanceof",
"Raw",
"?",
"sql",
":",
"this",
".",
"client",
".",
"raw",
"(",
"sql",
",",
"bindings",
")",
";",
"this",
".",
"_statements",
".",
"push",
"(",
"{",
"grouping",
":",
"'group'",
",",
"type",
":",
"'groupByRaw'",
",",
"value",
":",
"raw",
"}",
")",
";",
"return",
"this",
";",
"}"
] |
Adds a raw `group by` clause to the query.
|
[
"Adds",
"a",
"raw",
"group",
"by",
"clause",
"to",
"the",
"query",
"."
] |
4cc624975d359800961bf34cb74de97488d2efb5
|
https://github.com/AppGeo/cartodb/blob/4cc624975d359800961bf34cb74de97488d2efb5/lib/builder.js#L417-L425
|
38,654 |
AppGeo/cartodb
|
lib/builder.js
|
orderBy
|
function orderBy(column, direction) {
this._statements.push({
grouping: 'order',
type: 'orderByBasic',
value: column,
direction: direction
});
return this;
}
|
javascript
|
function orderBy(column, direction) {
this._statements.push({
grouping: 'order',
type: 'orderByBasic',
value: column,
direction: direction
});
return this;
}
|
[
"function",
"orderBy",
"(",
"column",
",",
"direction",
")",
"{",
"this",
".",
"_statements",
".",
"push",
"(",
"{",
"grouping",
":",
"'order'",
",",
"type",
":",
"'orderByBasic'",
",",
"value",
":",
"column",
",",
"direction",
":",
"direction",
"}",
")",
";",
"return",
"this",
";",
"}"
] |
Adds a `order by` clause to the query.
|
[
"Adds",
"a",
"order",
"by",
"clause",
"to",
"the",
"query",
"."
] |
4cc624975d359800961bf34cb74de97488d2efb5
|
https://github.com/AppGeo/cartodb/blob/4cc624975d359800961bf34cb74de97488d2efb5/lib/builder.js#L428-L436
|
38,655 |
AppGeo/cartodb
|
lib/builder.js
|
union
|
function union(callbacks, wrap) {
if (arguments.length === 1 || arguments.length === 2 && typeof wrap === 'boolean') {
if (!Array.isArray(callbacks)) {
callbacks = [callbacks];
}
for (var i = 0, l = callbacks.length; i < l; i++) {
this._statements.push({
grouping: 'union',
clause: 'union',
value: callbacks[i],
wrap: wrap || false
});
}
} else {
callbacks = normalizeArr.apply(null, arguments).slice(0, arguments.length - 1);
wrap = arguments[arguments.length - 1];
if (typeof wrap !== 'boolean') {
callbacks.push(wrap);
wrap = false;
}
this.union(callbacks, wrap);
}
return this;
}
|
javascript
|
function union(callbacks, wrap) {
if (arguments.length === 1 || arguments.length === 2 && typeof wrap === 'boolean') {
if (!Array.isArray(callbacks)) {
callbacks = [callbacks];
}
for (var i = 0, l = callbacks.length; i < l; i++) {
this._statements.push({
grouping: 'union',
clause: 'union',
value: callbacks[i],
wrap: wrap || false
});
}
} else {
callbacks = normalizeArr.apply(null, arguments).slice(0, arguments.length - 1);
wrap = arguments[arguments.length - 1];
if (typeof wrap !== 'boolean') {
callbacks.push(wrap);
wrap = false;
}
this.union(callbacks, wrap);
}
return this;
}
|
[
"function",
"union",
"(",
"callbacks",
",",
"wrap",
")",
"{",
"if",
"(",
"arguments",
".",
"length",
"===",
"1",
"||",
"arguments",
".",
"length",
"===",
"2",
"&&",
"typeof",
"wrap",
"===",
"'boolean'",
")",
"{",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"callbacks",
")",
")",
"{",
"callbacks",
"=",
"[",
"callbacks",
"]",
";",
"}",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"l",
"=",
"callbacks",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"this",
".",
"_statements",
".",
"push",
"(",
"{",
"grouping",
":",
"'union'",
",",
"clause",
":",
"'union'",
",",
"value",
":",
"callbacks",
"[",
"i",
"]",
",",
"wrap",
":",
"wrap",
"||",
"false",
"}",
")",
";",
"}",
"}",
"else",
"{",
"callbacks",
"=",
"normalizeArr",
".",
"apply",
"(",
"null",
",",
"arguments",
")",
".",
"slice",
"(",
"0",
",",
"arguments",
".",
"length",
"-",
"1",
")",
";",
"wrap",
"=",
"arguments",
"[",
"arguments",
".",
"length",
"-",
"1",
"]",
";",
"if",
"(",
"typeof",
"wrap",
"!==",
"'boolean'",
")",
"{",
"callbacks",
".",
"push",
"(",
"wrap",
")",
";",
"wrap",
"=",
"false",
";",
"}",
"this",
".",
"union",
"(",
"callbacks",
",",
"wrap",
")",
";",
"}",
"return",
"this",
";",
"}"
] |
Add a union statement to the query.
|
[
"Add",
"a",
"union",
"statement",
"to",
"the",
"query",
"."
] |
4cc624975d359800961bf34cb74de97488d2efb5
|
https://github.com/AppGeo/cartodb/blob/4cc624975d359800961bf34cb74de97488d2efb5/lib/builder.js#L450-L473
|
38,656 |
AppGeo/cartodb
|
lib/builder.js
|
unionAll
|
function unionAll(callback, wrap) {
this._statements.push({
grouping: 'union',
clause: 'union all',
value: callback,
wrap: wrap || false
});
return this;
}
|
javascript
|
function unionAll(callback, wrap) {
this._statements.push({
grouping: 'union',
clause: 'union all',
value: callback,
wrap: wrap || false
});
return this;
}
|
[
"function",
"unionAll",
"(",
"callback",
",",
"wrap",
")",
"{",
"this",
".",
"_statements",
".",
"push",
"(",
"{",
"grouping",
":",
"'union'",
",",
"clause",
":",
"'union all'",
",",
"value",
":",
"callback",
",",
"wrap",
":",
"wrap",
"||",
"false",
"}",
")",
";",
"return",
"this",
";",
"}"
] |
Adds a union all statement to the query.
|
[
"Adds",
"a",
"union",
"all",
"statement",
"to",
"the",
"query",
"."
] |
4cc624975d359800961bf34cb74de97488d2efb5
|
https://github.com/AppGeo/cartodb/blob/4cc624975d359800961bf34cb74de97488d2efb5/lib/builder.js#L476-L484
|
38,657 |
AppGeo/cartodb
|
lib/builder.js
|
having
|
function having(column, operator, value) {
if (column instanceof Raw && arguments.length === 1) {
return this._havingRaw(column);
}
// Check if the column is a function, in which case it's
// a having statement wrapped in parens.
if (typeof column === 'function') {
return this.havingWrapped(column);
}
this._statements.push({
grouping: 'having',
type: 'havingBasic',
column: column,
operator: operator,
value: value,
bool: this._bool()
});
return this;
}
|
javascript
|
function having(column, operator, value) {
if (column instanceof Raw && arguments.length === 1) {
return this._havingRaw(column);
}
// Check if the column is a function, in which case it's
// a having statement wrapped in parens.
if (typeof column === 'function') {
return this.havingWrapped(column);
}
this._statements.push({
grouping: 'having',
type: 'havingBasic',
column: column,
operator: operator,
value: value,
bool: this._bool()
});
return this;
}
|
[
"function",
"having",
"(",
"column",
",",
"operator",
",",
"value",
")",
"{",
"if",
"(",
"column",
"instanceof",
"Raw",
"&&",
"arguments",
".",
"length",
"===",
"1",
")",
"{",
"return",
"this",
".",
"_havingRaw",
"(",
"column",
")",
";",
"}",
"// Check if the column is a function, in which case it's",
"// a having statement wrapped in parens.",
"if",
"(",
"typeof",
"column",
"===",
"'function'",
")",
"{",
"return",
"this",
".",
"havingWrapped",
"(",
"column",
")",
";",
"}",
"this",
".",
"_statements",
".",
"push",
"(",
"{",
"grouping",
":",
"'having'",
",",
"type",
":",
"'havingBasic'",
",",
"column",
":",
"column",
",",
"operator",
":",
"operator",
",",
"value",
":",
"value",
",",
"bool",
":",
"this",
".",
"_bool",
"(",
")",
"}",
")",
";",
"return",
"this",
";",
"}"
] |
Adds a `having` clause to the query.
|
[
"Adds",
"a",
"having",
"clause",
"to",
"the",
"query",
"."
] |
4cc624975d359800961bf34cb74de97488d2efb5
|
https://github.com/AppGeo/cartodb/blob/4cc624975d359800961bf34cb74de97488d2efb5/lib/builder.js#L487-L507
|
38,658 |
AppGeo/cartodb
|
lib/builder.js
|
_havingRaw
|
function _havingRaw(sql, bindings) {
var raw = sql instanceof Raw ? sql : this.client.raw(sql, bindings);
this._statements.push({
grouping: 'having',
type: 'havingRaw',
value: raw,
bool: this._bool()
});
return this;
}
|
javascript
|
function _havingRaw(sql, bindings) {
var raw = sql instanceof Raw ? sql : this.client.raw(sql, bindings);
this._statements.push({
grouping: 'having',
type: 'havingRaw',
value: raw,
bool: this._bool()
});
return this;
}
|
[
"function",
"_havingRaw",
"(",
"sql",
",",
"bindings",
")",
"{",
"var",
"raw",
"=",
"sql",
"instanceof",
"Raw",
"?",
"sql",
":",
"this",
".",
"client",
".",
"raw",
"(",
"sql",
",",
"bindings",
")",
";",
"this",
".",
"_statements",
".",
"push",
"(",
"{",
"grouping",
":",
"'having'",
",",
"type",
":",
"'havingRaw'",
",",
"value",
":",
"raw",
",",
"bool",
":",
"this",
".",
"_bool",
"(",
")",
"}",
")",
";",
"return",
"this",
";",
"}"
] |
Adds a raw `having` clause to the query.
|
[
"Adds",
"a",
"raw",
"having",
"clause",
"to",
"the",
"query",
"."
] |
4cc624975d359800961bf34cb74de97488d2efb5
|
https://github.com/AppGeo/cartodb/blob/4cc624975d359800961bf34cb74de97488d2efb5/lib/builder.js#L519-L528
|
38,659 |
AppGeo/cartodb
|
lib/builder.js
|
limit
|
function limit(value) {
var val = parseInt(value, 10);
if (isNaN(val)) {
debug('A valid integer must be provided to limit');
} else {
this._single.limit = val;
}
return this;
}
|
javascript
|
function limit(value) {
var val = parseInt(value, 10);
if (isNaN(val)) {
debug('A valid integer must be provided to limit');
} else {
this._single.limit = val;
}
return this;
}
|
[
"function",
"limit",
"(",
"value",
")",
"{",
"var",
"val",
"=",
"parseInt",
"(",
"value",
",",
"10",
")",
";",
"if",
"(",
"isNaN",
"(",
"val",
")",
")",
"{",
"debug",
"(",
"'A valid integer must be provided to limit'",
")",
";",
"}",
"else",
"{",
"this",
".",
"_single",
".",
"limit",
"=",
"val",
";",
"}",
"return",
"this",
";",
"}"
] |
Only allow a single "limit" to be set for the current query.
|
[
"Only",
"allow",
"a",
"single",
"limit",
"to",
"be",
"set",
"for",
"the",
"current",
"query",
"."
] |
4cc624975d359800961bf34cb74de97488d2efb5
|
https://github.com/AppGeo/cartodb/blob/4cc624975d359800961bf34cb74de97488d2efb5/lib/builder.js#L537-L545
|
38,660 |
AppGeo/cartodb
|
lib/builder.js
|
pluck
|
function pluck(column) {
this._method = 'pluck';
this._single.pluck = column;
this._statements.push({
grouping: 'columns',
type: 'pluck',
value: column
});
return this;
}
|
javascript
|
function pluck(column) {
this._method = 'pluck';
this._single.pluck = column;
this._statements.push({
grouping: 'columns',
type: 'pluck',
value: column
});
return this;
}
|
[
"function",
"pluck",
"(",
"column",
")",
"{",
"this",
".",
"_method",
"=",
"'pluck'",
";",
"this",
".",
"_single",
".",
"pluck",
"=",
"column",
";",
"this",
".",
"_statements",
".",
"push",
"(",
"{",
"grouping",
":",
"'columns'",
",",
"type",
":",
"'pluck'",
",",
"value",
":",
"column",
"}",
")",
";",
"return",
"this",
";",
"}"
] |
Pluck a column from a query.
|
[
"Pluck",
"a",
"column",
"from",
"a",
"query",
"."
] |
4cc624975d359800961bf34cb74de97488d2efb5
|
https://github.com/AppGeo/cartodb/blob/4cc624975d359800961bf34cb74de97488d2efb5/lib/builder.js#L597-L606
|
38,661 |
AppGeo/cartodb
|
lib/builder.js
|
fromJS
|
function fromJS(obj) {
Object.keys(obj).forEach(function (key) {
var val = obj[key];
if (typeof this[key] !== 'function') {
debug('Knex Error: unknown key ' + key);
}
if (Array.isArray(val)) {
this[key].apply(this, val);
} else {
this[key](val);
}
}, this);
return this;
}
|
javascript
|
function fromJS(obj) {
Object.keys(obj).forEach(function (key) {
var val = obj[key];
if (typeof this[key] !== 'function') {
debug('Knex Error: unknown key ' + key);
}
if (Array.isArray(val)) {
this[key].apply(this, val);
} else {
this[key](val);
}
}, this);
return this;
}
|
[
"function",
"fromJS",
"(",
"obj",
")",
"{",
"Object",
".",
"keys",
"(",
"obj",
")",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"var",
"val",
"=",
"obj",
"[",
"key",
"]",
";",
"if",
"(",
"typeof",
"this",
"[",
"key",
"]",
"!==",
"'function'",
")",
"{",
"debug",
"(",
"'Knex Error: unknown key '",
"+",
"key",
")",
";",
"}",
"if",
"(",
"Array",
".",
"isArray",
"(",
"val",
")",
")",
"{",
"this",
"[",
"key",
"]",
".",
"apply",
"(",
"this",
",",
"val",
")",
";",
"}",
"else",
"{",
"this",
"[",
"key",
"]",
"(",
"val",
")",
";",
"}",
"}",
",",
"this",
")",
";",
"return",
"this",
";",
"}"
] |
Takes a JS object of methods to call and calls them
|
[
"Takes",
"a",
"JS",
"object",
"of",
"methods",
"to",
"call",
"and",
"calls",
"them"
] |
4cc624975d359800961bf34cb74de97488d2efb5
|
https://github.com/AppGeo/cartodb/blob/4cc624975d359800961bf34cb74de97488d2efb5/lib/builder.js#L697-L710
|
38,662 |
AppGeo/cartodb
|
lib/builder.js
|
_bool
|
function _bool(val) {
if (arguments.length === 1) {
this._boolFlag = val;
return this;
}
var ret = this._boolFlag;
this._boolFlag = 'and';
return ret;
}
|
javascript
|
function _bool(val) {
if (arguments.length === 1) {
this._boolFlag = val;
return this;
}
var ret = this._boolFlag;
this._boolFlag = 'and';
return ret;
}
|
[
"function",
"_bool",
"(",
"val",
")",
"{",
"if",
"(",
"arguments",
".",
"length",
"===",
"1",
")",
"{",
"this",
".",
"_boolFlag",
"=",
"val",
";",
"return",
"this",
";",
"}",
"var",
"ret",
"=",
"this",
".",
"_boolFlag",
";",
"this",
".",
"_boolFlag",
"=",
"'and'",
";",
"return",
"ret",
";",
"}"
] |
Helper to get or set the "boolFlag" value.
|
[
"Helper",
"to",
"get",
"or",
"set",
"the",
"boolFlag",
"value",
"."
] |
4cc624975d359800961bf34cb74de97488d2efb5
|
https://github.com/AppGeo/cartodb/blob/4cc624975d359800961bf34cb74de97488d2efb5/lib/builder.js#L730-L738
|
38,663 |
AppGeo/cartodb
|
lib/builder.js
|
_not
|
function _not(val) {
if (arguments.length === 1) {
this._notFlag = val;
return this;
}
var ret = this._notFlag;
this._notFlag = false;
return ret;
}
|
javascript
|
function _not(val) {
if (arguments.length === 1) {
this._notFlag = val;
return this;
}
var ret = this._notFlag;
this._notFlag = false;
return ret;
}
|
[
"function",
"_not",
"(",
"val",
")",
"{",
"if",
"(",
"arguments",
".",
"length",
"===",
"1",
")",
"{",
"this",
".",
"_notFlag",
"=",
"val",
";",
"return",
"this",
";",
"}",
"var",
"ret",
"=",
"this",
".",
"_notFlag",
";",
"this",
".",
"_notFlag",
"=",
"false",
";",
"return",
"ret",
";",
"}"
] |
Helper to get or set the "notFlag" value.
|
[
"Helper",
"to",
"get",
"or",
"set",
"the",
"notFlag",
"value",
"."
] |
4cc624975d359800961bf34cb74de97488d2efb5
|
https://github.com/AppGeo/cartodb/blob/4cc624975d359800961bf34cb74de97488d2efb5/lib/builder.js#L741-L749
|
38,664 |
AppGeo/cartodb
|
lib/builder.js
|
_joinType
|
function _joinType(val) {
if (arguments.length === 1) {
this._joinFlag = val;
return this;
}
var ret = this._joinFlag || 'inner';
this._joinFlag = 'inner';
return ret;
}
|
javascript
|
function _joinType(val) {
if (arguments.length === 1) {
this._joinFlag = val;
return this;
}
var ret = this._joinFlag || 'inner';
this._joinFlag = 'inner';
return ret;
}
|
[
"function",
"_joinType",
"(",
"val",
")",
"{",
"if",
"(",
"arguments",
".",
"length",
"===",
"1",
")",
"{",
"this",
".",
"_joinFlag",
"=",
"val",
";",
"return",
"this",
";",
"}",
"var",
"ret",
"=",
"this",
".",
"_joinFlag",
"||",
"'inner'",
";",
"this",
".",
"_joinFlag",
"=",
"'inner'",
";",
"return",
"ret",
";",
"}"
] |
Helper to get or set the "joinFlag" value.
|
[
"Helper",
"to",
"get",
"or",
"set",
"the",
"joinFlag",
"value",
"."
] |
4cc624975d359800961bf34cb74de97488d2efb5
|
https://github.com/AppGeo/cartodb/blob/4cc624975d359800961bf34cb74de97488d2efb5/lib/builder.js#L752-L760
|
38,665 |
AppGeo/cartodb
|
lib/builder.js
|
_aggregate
|
function _aggregate(method, column) {
this._statements.push({
grouping: 'columns',
type: 'aggregate',
method: method,
value: column
});
return this;
}
|
javascript
|
function _aggregate(method, column) {
this._statements.push({
grouping: 'columns',
type: 'aggregate',
method: method,
value: column
});
return this;
}
|
[
"function",
"_aggregate",
"(",
"method",
",",
"column",
")",
"{",
"this",
".",
"_statements",
".",
"push",
"(",
"{",
"grouping",
":",
"'columns'",
",",
"type",
":",
"'aggregate'",
",",
"method",
":",
"method",
",",
"value",
":",
"column",
"}",
")",
";",
"return",
"this",
";",
"}"
] |
Helper for compiling any aggregate queries.
|
[
"Helper",
"for",
"compiling",
"any",
"aggregate",
"queries",
"."
] |
4cc624975d359800961bf34cb74de97488d2efb5
|
https://github.com/AppGeo/cartodb/blob/4cc624975d359800961bf34cb74de97488d2efb5/lib/builder.js#L763-L771
|
38,666 |
rootsdev/gedcomx-js
|
src/core/ExtensibleData.js
|
function(json){
// Protect against forgetting the new keyword when calling the constructor
if(!(this instanceof ExtensibleData)){
return new ExtensibleData(json);
}
// If the given object is already an instance then just return it. DON'T copy it.
if(ExtensibleData.isInstance(json)){
return json;
}
this.init(json);
}
|
javascript
|
function(json){
// Protect against forgetting the new keyword when calling the constructor
if(!(this instanceof ExtensibleData)){
return new ExtensibleData(json);
}
// If the given object is already an instance then just return it. DON'T copy it.
if(ExtensibleData.isInstance(json)){
return json;
}
this.init(json);
}
|
[
"function",
"(",
"json",
")",
"{",
"// Protect against forgetting the new keyword when calling the constructor",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"ExtensibleData",
")",
")",
"{",
"return",
"new",
"ExtensibleData",
"(",
"json",
")",
";",
"}",
"// If the given object is already an instance then just return it. DON'T copy it.",
"if",
"(",
"ExtensibleData",
".",
"isInstance",
"(",
"json",
")",
")",
"{",
"return",
"json",
";",
"}",
"this",
".",
"init",
"(",
"json",
")",
";",
"}"
] |
A set of data that supports extension elements.
@class
@extends Base
@param {Object} [json]
|
[
"A",
"set",
"of",
"data",
"that",
"supports",
"extension",
"elements",
"."
] |
08b2fcde96f1e301c78561bfb7a8b0cac606e26e
|
https://github.com/rootsdev/gedcomx-js/blob/08b2fcde96f1e301c78561bfb7a8b0cac606e26e/src/core/ExtensibleData.js#L11-L24
|
|
38,667 |
anvilresearch/connect-keys
|
index.js
|
generateKeyPairs
|
function generateKeyPairs () {
AnvilConnectKeys.generateKeyPair(this.sig.pub, this.sig.prv)
AnvilConnectKeys.generateKeyPair(this.enc.pub, this.enc.prv)
}
|
javascript
|
function generateKeyPairs () {
AnvilConnectKeys.generateKeyPair(this.sig.pub, this.sig.prv)
AnvilConnectKeys.generateKeyPair(this.enc.pub, this.enc.prv)
}
|
[
"function",
"generateKeyPairs",
"(",
")",
"{",
"AnvilConnectKeys",
".",
"generateKeyPair",
"(",
"this",
".",
"sig",
".",
"pub",
",",
"this",
".",
"sig",
".",
"prv",
")",
"AnvilConnectKeys",
".",
"generateKeyPair",
"(",
"this",
".",
"enc",
".",
"pub",
",",
"this",
".",
"enc",
".",
"prv",
")",
"}"
] |
Generate key pairs
|
[
"Generate",
"key",
"pairs"
] |
45c7b4c7092cd37e92300add6951a8b1d74f3033
|
https://github.com/anvilresearch/connect-keys/blob/45c7b4c7092cd37e92300add6951a8b1d74f3033/index.js#L42-L45
|
38,668 |
anvilresearch/connect-keys
|
index.js
|
generateKeyPair
|
function generateKeyPair (pub, prv) {
try {
mkdirp.sync(path.dirname(pub))
mkdirp.sync(path.dirname(prv))
childProcess.execFileSync('openssl', [
'genrsa',
'-out',
prv,
'4096'
], {
stdio: 'ignore'
})
childProcess.execFileSync('openssl', [
'rsa',
'-pubout',
'-in',
prv,
'-out',
pub
], {
stdio: 'ignore'
})
} catch (e) {
throw new Error(
'Failed to generate keys using OpenSSL. Please ensure you have OpenSSL ' +
'installed and configured on your system.'
)
}
}
|
javascript
|
function generateKeyPair (pub, prv) {
try {
mkdirp.sync(path.dirname(pub))
mkdirp.sync(path.dirname(prv))
childProcess.execFileSync('openssl', [
'genrsa',
'-out',
prv,
'4096'
], {
stdio: 'ignore'
})
childProcess.execFileSync('openssl', [
'rsa',
'-pubout',
'-in',
prv,
'-out',
pub
], {
stdio: 'ignore'
})
} catch (e) {
throw new Error(
'Failed to generate keys using OpenSSL. Please ensure you have OpenSSL ' +
'installed and configured on your system.'
)
}
}
|
[
"function",
"generateKeyPair",
"(",
"pub",
",",
"prv",
")",
"{",
"try",
"{",
"mkdirp",
".",
"sync",
"(",
"path",
".",
"dirname",
"(",
"pub",
")",
")",
"mkdirp",
".",
"sync",
"(",
"path",
".",
"dirname",
"(",
"prv",
")",
")",
"childProcess",
".",
"execFileSync",
"(",
"'openssl'",
",",
"[",
"'genrsa'",
",",
"'-out'",
",",
"prv",
",",
"'4096'",
"]",
",",
"{",
"stdio",
":",
"'ignore'",
"}",
")",
"childProcess",
".",
"execFileSync",
"(",
"'openssl'",
",",
"[",
"'rsa'",
",",
"'-pubout'",
",",
"'-in'",
",",
"prv",
",",
"'-out'",
",",
"pub",
"]",
",",
"{",
"stdio",
":",
"'ignore'",
"}",
")",
"}",
"catch",
"(",
"e",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Failed to generate keys using OpenSSL. Please ensure you have OpenSSL '",
"+",
"'installed and configured on your system.'",
")",
"}",
"}"
] |
Generate single key pair
|
[
"Generate",
"single",
"key",
"pair"
] |
45c7b4c7092cd37e92300add6951a8b1d74f3033
|
https://github.com/anvilresearch/connect-keys/blob/45c7b4c7092cd37e92300add6951a8b1d74f3033/index.js#L53-L83
|
38,669 |
anvilresearch/connect-keys
|
index.js
|
loadKeyPairs
|
function loadKeyPairs () {
var sig = AnvilConnectKeys.loadKeyPair(this.sig.pub, this.sig.prv, 'sig')
var enc = AnvilConnectKeys.loadKeyPair(this.enc.pub, this.enc.prv, 'enc')
var jwkKeys = []
jwkKeys.push(sig.jwk.pub, enc.jwk.pub)
return {
sig: sig.pem,
enc: enc.pem,
jwks: {
keys: jwkKeys
}
}
}
|
javascript
|
function loadKeyPairs () {
var sig = AnvilConnectKeys.loadKeyPair(this.sig.pub, this.sig.prv, 'sig')
var enc = AnvilConnectKeys.loadKeyPair(this.enc.pub, this.enc.prv, 'enc')
var jwkKeys = []
jwkKeys.push(sig.jwk.pub, enc.jwk.pub)
return {
sig: sig.pem,
enc: enc.pem,
jwks: {
keys: jwkKeys
}
}
}
|
[
"function",
"loadKeyPairs",
"(",
")",
"{",
"var",
"sig",
"=",
"AnvilConnectKeys",
".",
"loadKeyPair",
"(",
"this",
".",
"sig",
".",
"pub",
",",
"this",
".",
"sig",
".",
"prv",
",",
"'sig'",
")",
"var",
"enc",
"=",
"AnvilConnectKeys",
".",
"loadKeyPair",
"(",
"this",
".",
"enc",
".",
"pub",
",",
"this",
".",
"enc",
".",
"prv",
",",
"'enc'",
")",
"var",
"jwkKeys",
"=",
"[",
"]",
"jwkKeys",
".",
"push",
"(",
"sig",
".",
"jwk",
".",
"pub",
",",
"enc",
".",
"jwk",
".",
"pub",
")",
"return",
"{",
"sig",
":",
"sig",
".",
"pem",
",",
"enc",
":",
"enc",
".",
"pem",
",",
"jwks",
":",
"{",
"keys",
":",
"jwkKeys",
"}",
"}",
"}"
] |
Load key pairs
|
[
"Load",
"key",
"pairs"
] |
45c7b4c7092cd37e92300add6951a8b1d74f3033
|
https://github.com/anvilresearch/connect-keys/blob/45c7b4c7092cd37e92300add6951a8b1d74f3033/index.js#L91-L105
|
38,670 |
anvilresearch/connect-keys
|
index.js
|
loadKeyPair
|
function loadKeyPair (pub, prv, use) {
var pubPEM, prvPEM, pubJWK
try {
pubPEM = fs.readFileSync(pub).toString('ascii')
} catch (e) {
throw new Error('Unable to read the public key from ' + pub)
}
try {
prvPEM = fs.readFileSync(prv).toString('ascii')
} catch (e) {
throw new Error('Unable to read the private key from ' + pub)
}
try {
pubJWK = pemjwk.pem2jwk(pubPEM)
} catch (e) {
throw new Error('Unable to convert the public key ' + pub + ' to a JWK')
}
return {
pem: {
pub: pubPEM,
prv: prvPEM
},
jwk: {
pub: {
kty: pubJWK.kty,
use: use,
alg: 'RS256',
n: pubJWK.n,
e: pubJWK.e
}
}
}
}
|
javascript
|
function loadKeyPair (pub, prv, use) {
var pubPEM, prvPEM, pubJWK
try {
pubPEM = fs.readFileSync(pub).toString('ascii')
} catch (e) {
throw new Error('Unable to read the public key from ' + pub)
}
try {
prvPEM = fs.readFileSync(prv).toString('ascii')
} catch (e) {
throw new Error('Unable to read the private key from ' + pub)
}
try {
pubJWK = pemjwk.pem2jwk(pubPEM)
} catch (e) {
throw new Error('Unable to convert the public key ' + pub + ' to a JWK')
}
return {
pem: {
pub: pubPEM,
prv: prvPEM
},
jwk: {
pub: {
kty: pubJWK.kty,
use: use,
alg: 'RS256',
n: pubJWK.n,
e: pubJWK.e
}
}
}
}
|
[
"function",
"loadKeyPair",
"(",
"pub",
",",
"prv",
",",
"use",
")",
"{",
"var",
"pubPEM",
",",
"prvPEM",
",",
"pubJWK",
"try",
"{",
"pubPEM",
"=",
"fs",
".",
"readFileSync",
"(",
"pub",
")",
".",
"toString",
"(",
"'ascii'",
")",
"}",
"catch",
"(",
"e",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Unable to read the public key from '",
"+",
"pub",
")",
"}",
"try",
"{",
"prvPEM",
"=",
"fs",
".",
"readFileSync",
"(",
"prv",
")",
".",
"toString",
"(",
"'ascii'",
")",
"}",
"catch",
"(",
"e",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Unable to read the private key from '",
"+",
"pub",
")",
"}",
"try",
"{",
"pubJWK",
"=",
"pemjwk",
".",
"pem2jwk",
"(",
"pubPEM",
")",
"}",
"catch",
"(",
"e",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Unable to convert the public key '",
"+",
"pub",
"+",
"' to a JWK'",
")",
"}",
"return",
"{",
"pem",
":",
"{",
"pub",
":",
"pubPEM",
",",
"prv",
":",
"prvPEM",
"}",
",",
"jwk",
":",
"{",
"pub",
":",
"{",
"kty",
":",
"pubJWK",
".",
"kty",
",",
"use",
":",
"use",
",",
"alg",
":",
"'RS256'",
",",
"n",
":",
"pubJWK",
".",
"n",
",",
"e",
":",
"pubJWK",
".",
"e",
"}",
"}",
"}",
"}"
] |
Load single key pair
|
[
"Load",
"single",
"key",
"pair"
] |
45c7b4c7092cd37e92300add6951a8b1d74f3033
|
https://github.com/anvilresearch/connect-keys/blob/45c7b4c7092cd37e92300add6951a8b1d74f3033/index.js#L113-L149
|
38,671 |
anvilresearch/connect-keys
|
index.js
|
generateSetupToken
|
function generateSetupToken (tokenPath) {
mkdirp.sync(path.dirname(tokenPath))
var token = crypto.randomBytes(256).toString('hex')
try {
fs.writeFileSync(tokenPath, token, 'utf8')
} catch (e) {
throw new Error('Unable to save setup token to ' + tokenPath)
}
return token
}
|
javascript
|
function generateSetupToken (tokenPath) {
mkdirp.sync(path.dirname(tokenPath))
var token = crypto.randomBytes(256).toString('hex')
try {
fs.writeFileSync(tokenPath, token, 'utf8')
} catch (e) {
throw new Error('Unable to save setup token to ' + tokenPath)
}
return token
}
|
[
"function",
"generateSetupToken",
"(",
"tokenPath",
")",
"{",
"mkdirp",
".",
"sync",
"(",
"path",
".",
"dirname",
"(",
"tokenPath",
")",
")",
"var",
"token",
"=",
"crypto",
".",
"randomBytes",
"(",
"256",
")",
".",
"toString",
"(",
"'hex'",
")",
"try",
"{",
"fs",
".",
"writeFileSync",
"(",
"tokenPath",
",",
"token",
",",
"'utf8'",
")",
"}",
"catch",
"(",
"e",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Unable to save setup token to '",
"+",
"tokenPath",
")",
"}",
"return",
"token",
"}"
] |
Generate setup token
|
[
"Generate",
"setup",
"token"
] |
45c7b4c7092cd37e92300add6951a8b1d74f3033
|
https://github.com/anvilresearch/connect-keys/blob/45c7b4c7092cd37e92300add6951a8b1d74f3033/index.js#L157-L167
|
38,672 |
benderjs/benderjs-coverage
|
lib/middleware.js
|
Transformer
|
function Transformer( file, res ) {
stream.Transform.call( this );
this.file = file;
this.res = res;
this.chunks = [];
}
|
javascript
|
function Transformer( file, res ) {
stream.Transform.call( this );
this.file = file;
this.res = res;
this.chunks = [];
}
|
[
"function",
"Transformer",
"(",
"file",
",",
"res",
")",
"{",
"stream",
".",
"Transform",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"file",
"=",
"file",
";",
"this",
".",
"res",
"=",
"res",
";",
"this",
".",
"chunks",
"=",
"[",
"]",
";",
"}"
] |
Transofrms the code from an incomming stream and outputs the code instrumented by Istanbul
@param {String} file File name used by Istanbul
@param {Object} res HTTP response
|
[
"Transofrms",
"the",
"code",
"from",
"an",
"incomming",
"stream",
"and",
"outputs",
"the",
"code",
"instrumented",
"by",
"Istanbul"
] |
37099604257d7acf6dae57c425095cd884205a1f
|
https://github.com/benderjs/benderjs-coverage/blob/37099604257d7acf6dae57c425095cd884205a1f/lib/middleware.js#L27-L33
|
38,673 |
nomocas/kroked
|
lib/utils.js
|
function(src, skipBlanck) {
var tokens = [],
cells, cap;
while (src) {
cells = [];
while (cap = cellDelimitter.exec(src)) {
src = src.substring(cap[0].length);
cells.push(cap[1]);
}
if (cells.length || !skipBlanck)
tokens.push(cells);
// src should start now with \n or \r
src = src.substring(1);
}
return tokens;
}
|
javascript
|
function(src, skipBlanck) {
var tokens = [],
cells, cap;
while (src) {
cells = [];
while (cap = cellDelimitter.exec(src)) {
src = src.substring(cap[0].length);
cells.push(cap[1]);
}
if (cells.length || !skipBlanck)
tokens.push(cells);
// src should start now with \n or \r
src = src.substring(1);
}
return tokens;
}
|
[
"function",
"(",
"src",
",",
"skipBlanck",
")",
"{",
"var",
"tokens",
"=",
"[",
"]",
",",
"cells",
",",
"cap",
";",
"while",
"(",
"src",
")",
"{",
"cells",
"=",
"[",
"]",
";",
"while",
"(",
"cap",
"=",
"cellDelimitter",
".",
"exec",
"(",
"src",
")",
")",
"{",
"src",
"=",
"src",
".",
"substring",
"(",
"cap",
"[",
"0",
"]",
".",
"length",
")",
";",
"cells",
".",
"push",
"(",
"cap",
"[",
"1",
"]",
")",
";",
"}",
"if",
"(",
"cells",
".",
"length",
"||",
"!",
"skipBlanck",
")",
"tokens",
".",
"push",
"(",
"cells",
")",
";",
"// src should start now with \\n or \\r",
"src",
"=",
"src",
".",
"substring",
"(",
"1",
")",
";",
"}",
"return",
"tokens",
";",
"}"
] |
Parse tab delimitted lines from string. usefull for raw macros and table like widgets rendering.
@param {String} src the content block to parse until the end.
@param {Boolean} skipBlanck optional. if true, skip blank lines.
@return {Array} Parsed lines. Array of cells array. i.e. lines[2][3] gives you third cell of second line.
|
[
"Parse",
"tab",
"delimitted",
"lines",
"from",
"string",
".",
"usefull",
"for",
"raw",
"macros",
"and",
"table",
"like",
"widgets",
"rendering",
"."
] |
1d6baf62df437c0b4ab242be7b8915fa66c2cdb8
|
https://github.com/nomocas/kroked/blob/1d6baf62df437c0b4ab242be7b8915fa66c2cdb8/lib/utils.js#L33-L48
|
|
38,674 |
lionel-rigoux/pandemic
|
lib/load-instructions.js
|
defaultInstructions
|
function defaultInstructions (format) {
// start with empty instructions
let instructions = emptyInstructions('_defaults', format);
// extend with the default recipe, if it exists for the target extension
const recipeFilePath = path.join(
__dirname,
'..',
'_defaults',
`recipe.${format}.json`
);
if (fs.existsSync(recipeFilePath)) {
instructions = Object.assign(
instructions,
JSON.parse(fs.readFileSync(recipeFilePath, 'utf8'))
);
}
return instructions;
}
|
javascript
|
function defaultInstructions (format) {
// start with empty instructions
let instructions = emptyInstructions('_defaults', format);
// extend with the default recipe, if it exists for the target extension
const recipeFilePath = path.join(
__dirname,
'..',
'_defaults',
`recipe.${format}.json`
);
if (fs.existsSync(recipeFilePath)) {
instructions = Object.assign(
instructions,
JSON.parse(fs.readFileSync(recipeFilePath, 'utf8'))
);
}
return instructions;
}
|
[
"function",
"defaultInstructions",
"(",
"format",
")",
"{",
"// start with empty instructions",
"let",
"instructions",
"=",
"emptyInstructions",
"(",
"'_defaults'",
",",
"format",
")",
";",
"// extend with the default recipe, if it exists for the target extension",
"const",
"recipeFilePath",
"=",
"path",
".",
"join",
"(",
"__dirname",
",",
"'..'",
",",
"'_defaults'",
",",
"`",
"${",
"format",
"}",
"`",
")",
";",
"if",
"(",
"fs",
".",
"existsSync",
"(",
"recipeFilePath",
")",
")",
"{",
"instructions",
"=",
"Object",
".",
"assign",
"(",
"instructions",
",",
"JSON",
".",
"parse",
"(",
"fs",
".",
"readFileSync",
"(",
"recipeFilePath",
",",
"'utf8'",
")",
")",
")",
";",
"}",
"return",
"instructions",
";",
"}"
] |
default recipe instruction
|
[
"default",
"recipe",
"instruction"
] |
133b2445ea4981f64012f6af4e6210a18981d46e
|
https://github.com/lionel-rigoux/pandemic/blob/133b2445ea4981f64012f6af4e6210a18981d46e/lib/load-instructions.js#L28-L46
|
38,675 |
lionel-rigoux/pandemic
|
lib/load-instructions.js
|
isTemplate
|
function isTemplate (file, format) {
const { prefix, ext } = splitFormat(format);
return formatMap[ext]
.map(e => (prefix.length ? '.' : '') + prefix + e)
.some(e => file.endsWith(e));
}
|
javascript
|
function isTemplate (file, format) {
const { prefix, ext } = splitFormat(format);
return formatMap[ext]
.map(e => (prefix.length ? '.' : '') + prefix + e)
.some(e => file.endsWith(e));
}
|
[
"function",
"isTemplate",
"(",
"file",
",",
"format",
")",
"{",
"const",
"{",
"prefix",
",",
"ext",
"}",
"=",
"splitFormat",
"(",
"format",
")",
";",
"return",
"formatMap",
"[",
"ext",
"]",
".",
"map",
"(",
"e",
"=>",
"(",
"prefix",
".",
"length",
"?",
"'.'",
":",
"''",
")",
"+",
"prefix",
"+",
"e",
")",
".",
"some",
"(",
"e",
"=>",
"file",
".",
"endsWith",
"(",
"e",
")",
")",
";",
"}"
] |
test if a given file could serve as a template for the format
|
[
"test",
"if",
"a",
"given",
"file",
"could",
"serve",
"as",
"a",
"template",
"for",
"the",
"format"
] |
133b2445ea4981f64012f6af4e6210a18981d46e
|
https://github.com/lionel-rigoux/pandemic/blob/133b2445ea4981f64012f6af4e6210a18981d46e/lib/load-instructions.js#L49-L54
|
38,676 |
ningsuhen/passport-linkedin-token
|
lib/passport-linkedin-token/strategy.js
|
LinkedInTokenStrategy
|
function LinkedInTokenStrategy(options, verify) {
options = options || {};
options.requestTokenURL = options.requestTokenURL || 'https://api.linkedin.com/uas/oauth/requestToken';
options.accessTokenURL = options.accessTokenURL || 'https://api.linkedin.com/uas/oauth/accessToken';
options.userAuthorizationURL = options.userAuthorizationURL || 'https://www.linkedin.com/uas/oauth/authenticate';
options.sessionKey = options.sessionKey || 'oauth:linkedin';
OAuthStrategy.call(this, options, verify);
this.name = 'linkedin-token';
this._profileFields = options.profileFields;
this._skipExtendedUserProfile = (options.skipExtendedUserProfile === undefined) ? false : options.skipExtendedUserProfile;
}
|
javascript
|
function LinkedInTokenStrategy(options, verify) {
options = options || {};
options.requestTokenURL = options.requestTokenURL || 'https://api.linkedin.com/uas/oauth/requestToken';
options.accessTokenURL = options.accessTokenURL || 'https://api.linkedin.com/uas/oauth/accessToken';
options.userAuthorizationURL = options.userAuthorizationURL || 'https://www.linkedin.com/uas/oauth/authenticate';
options.sessionKey = options.sessionKey || 'oauth:linkedin';
OAuthStrategy.call(this, options, verify);
this.name = 'linkedin-token';
this._profileFields = options.profileFields;
this._skipExtendedUserProfile = (options.skipExtendedUserProfile === undefined) ? false : options.skipExtendedUserProfile;
}
|
[
"function",
"LinkedInTokenStrategy",
"(",
"options",
",",
"verify",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"options",
".",
"requestTokenURL",
"=",
"options",
".",
"requestTokenURL",
"||",
"'https://api.linkedin.com/uas/oauth/requestToken'",
";",
"options",
".",
"accessTokenURL",
"=",
"options",
".",
"accessTokenURL",
"||",
"'https://api.linkedin.com/uas/oauth/accessToken'",
";",
"options",
".",
"userAuthorizationURL",
"=",
"options",
".",
"userAuthorizationURL",
"||",
"'https://www.linkedin.com/uas/oauth/authenticate'",
";",
"options",
".",
"sessionKey",
"=",
"options",
".",
"sessionKey",
"||",
"'oauth:linkedin'",
";",
"OAuthStrategy",
".",
"call",
"(",
"this",
",",
"options",
",",
"verify",
")",
";",
"this",
".",
"name",
"=",
"'linkedin-token'",
";",
"this",
".",
"_profileFields",
"=",
"options",
".",
"profileFields",
";",
"this",
".",
"_skipExtendedUserProfile",
"=",
"(",
"options",
".",
"skipExtendedUserProfile",
"===",
"undefined",
")",
"?",
"false",
":",
"options",
".",
"skipExtendedUserProfile",
";",
"}"
] |
`LinkedInTokenStrategy` constructor.
The LinkedIn authentication strategy authenticates requests by delegating to
LinkedIn using the OAuth protocol.
Applications must supply a `verify` callback which accepts a `token`,
`tokenSecret` and service-specific `profile`, and then calls the `done`
callback supplying a `user`, which should be set to `false` if the
credentials are not valid. If an exception occured, `err` should be set.
Options:
- `consumerKey` identifies client to LinkedIn
- `consumerSecret` secret used to establish ownership of the consumer key
Examples:
passport.use(new LinkedInTokenStrategy({
consumerKey: '123-456-789',
consumerSecret: 'shhh-its-a-secret'
},
function(token, tokenSecret, profile, done) {
User.findOrCreate(..., function (err, user) {
done(err, user);
});
}
));
@param {Object} options
@param {Function} verify
@api public
|
[
"LinkedInTokenStrategy",
"constructor",
"."
] |
da9e364abcaafca674d1a605101912844d46bde3
|
https://github.com/ningsuhen/passport-linkedin-token/blob/da9e364abcaafca674d1a605101912844d46bde3/lib/passport-linkedin-token/strategy.js#L41-L53
|
38,677 |
rootsdev/gedcomx-js
|
src/core/PlaceDescription.js
|
function(json){
// Protect against forgetting the new keyword when calling the constructor
if(!(this instanceof PlaceDescription)){
return new PlaceDescription(json);
}
// If the given object is already an instance then just return it. DON'T copy it.
if(PlaceDescription.isInstance(json)){
return json;
}
this.init(json);
}
|
javascript
|
function(json){
// Protect against forgetting the new keyword when calling the constructor
if(!(this instanceof PlaceDescription)){
return new PlaceDescription(json);
}
// If the given object is already an instance then just return it. DON'T copy it.
if(PlaceDescription.isInstance(json)){
return json;
}
this.init(json);
}
|
[
"function",
"(",
"json",
")",
"{",
"// Protect against forgetting the new keyword when calling the constructor",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"PlaceDescription",
")",
")",
"{",
"return",
"new",
"PlaceDescription",
"(",
"json",
")",
";",
"}",
"// If the given object is already an instance then just return it. DON'T copy it.",
"if",
"(",
"PlaceDescription",
".",
"isInstance",
"(",
"json",
")",
")",
"{",
"return",
"json",
";",
"}",
"this",
".",
"init",
"(",
"json",
")",
";",
"}"
] |
A description of a place
@see {@link https://github.com/FamilySearch/gedcomx/blob/master/specifications/json-format-specification.md#place-description|GEDCOM X JSON Spec}
@class
@extends Subject
@param {Object} [json]
|
[
"A",
"description",
"of",
"a",
"place"
] |
08b2fcde96f1e301c78561bfb7a8b0cac606e26e
|
https://github.com/rootsdev/gedcomx-js/blob/08b2fcde96f1e301c78561bfb7a8b0cac606e26e/src/core/PlaceDescription.js#L13-L26
|
|
38,678 |
reworkcss/rework-import
|
index.js
|
createImportError
|
function createImportError(rule) {
var url = rule.import ? rule.import.replace(/\r?\n/g, '\\n') : '<no url>';
var err = ['Bad import url: @import ' + url];
if (rule.position) {
err.push(' starting at line ' + rule.position.start.line + ' column ' + rule.position.start.column);
err.push(' ending at line ' + rule.position.end.line + ' column ' + rule.position.end.column);
if (rule.position.source) {
err.push(' in ' + rule.position.source);
}
}
return err.join('\n');
}
|
javascript
|
function createImportError(rule) {
var url = rule.import ? rule.import.replace(/\r?\n/g, '\\n') : '<no url>';
var err = ['Bad import url: @import ' + url];
if (rule.position) {
err.push(' starting at line ' + rule.position.start.line + ' column ' + rule.position.start.column);
err.push(' ending at line ' + rule.position.end.line + ' column ' + rule.position.end.column);
if (rule.position.source) {
err.push(' in ' + rule.position.source);
}
}
return err.join('\n');
}
|
[
"function",
"createImportError",
"(",
"rule",
")",
"{",
"var",
"url",
"=",
"rule",
".",
"import",
"?",
"rule",
".",
"import",
".",
"replace",
"(",
"/",
"\\r?\\n",
"/",
"g",
",",
"'\\\\n'",
")",
":",
"'<no url>'",
";",
"var",
"err",
"=",
"[",
"'Bad import url: @import '",
"+",
"url",
"]",
";",
"if",
"(",
"rule",
".",
"position",
")",
"{",
"err",
".",
"push",
"(",
"' starting at line '",
"+",
"rule",
".",
"position",
".",
"start",
".",
"line",
"+",
"' column '",
"+",
"rule",
".",
"position",
".",
"start",
".",
"column",
")",
";",
"err",
".",
"push",
"(",
"' ending at line '",
"+",
"rule",
".",
"position",
".",
"end",
".",
"line",
"+",
"' column '",
"+",
"rule",
".",
"position",
".",
"end",
".",
"column",
")",
";",
"if",
"(",
"rule",
".",
"position",
".",
"source",
")",
"{",
"err",
".",
"push",
"(",
"' in '",
"+",
"rule",
".",
"position",
".",
"source",
")",
";",
"}",
"}",
"return",
"err",
".",
"join",
"(",
"'\\n'",
")",
";",
"}"
] |
Create bad import rule error
@param {String} rule
@api private
|
[
"Create",
"bad",
"import",
"rule",
"error"
] |
071a715124c7b10eeb1c298a72b7fc106a4bb8f0
|
https://github.com/reworkcss/rework-import/blob/071a715124c7b10eeb1c298a72b7fc106a4bb8f0/index.js#L76-L90
|
38,679 |
reworkcss/rework-import
|
index.js
|
read
|
function read(file, opts) {
var encoding = opts.encoding || 'utf8';
var data = opts.transform(fs.readFileSync(file, encoding));
return css.parse(data, {source: file}).stylesheet;
}
|
javascript
|
function read(file, opts) {
var encoding = opts.encoding || 'utf8';
var data = opts.transform(fs.readFileSync(file, encoding));
return css.parse(data, {source: file}).stylesheet;
}
|
[
"function",
"read",
"(",
"file",
",",
"opts",
")",
"{",
"var",
"encoding",
"=",
"opts",
".",
"encoding",
"||",
"'utf8'",
";",
"var",
"data",
"=",
"opts",
".",
"transform",
"(",
"fs",
".",
"readFileSync",
"(",
"file",
",",
"encoding",
")",
")",
";",
"return",
"css",
".",
"parse",
"(",
"data",
",",
"{",
"source",
":",
"file",
"}",
")",
".",
"stylesheet",
";",
"}"
] |
Read the contents of a file
@param {String} file
@param {Object} opts
@api private
|
[
"Read",
"the",
"contents",
"of",
"a",
"file"
] |
071a715124c7b10eeb1c298a72b7fc106a4bb8f0
|
https://github.com/reworkcss/rework-import/blob/071a715124c7b10eeb1c298a72b7fc106a4bb8f0/index.js#L123-L127
|
38,680 |
WRidder/backgrid-advanced-filter
|
src/filter-collection.js
|
function (attributes, options) {
var AttrCollection = Backgrid.Extension.AdvancedFilter.AttributeFilterCollection;
if (attributes.attributeFilters !== undefined && !(attributes.attributeFilters instanceof AttrCollection)) {
attributes.attributeFilters = new AttrCollection(attributes.attributeFilters);
}
return Backbone.Model.prototype.set.call(this, attributes, options);
}
|
javascript
|
function (attributes, options) {
var AttrCollection = Backgrid.Extension.AdvancedFilter.AttributeFilterCollection;
if (attributes.attributeFilters !== undefined && !(attributes.attributeFilters instanceof AttrCollection)) {
attributes.attributeFilters = new AttrCollection(attributes.attributeFilters);
}
return Backbone.Model.prototype.set.call(this, attributes, options);
}
|
[
"function",
"(",
"attributes",
",",
"options",
")",
"{",
"var",
"AttrCollection",
"=",
"Backgrid",
".",
"Extension",
".",
"AdvancedFilter",
".",
"AttributeFilterCollection",
";",
"if",
"(",
"attributes",
".",
"attributeFilters",
"!==",
"undefined",
"&&",
"!",
"(",
"attributes",
".",
"attributeFilters",
"instanceof",
"AttrCollection",
")",
")",
"{",
"attributes",
".",
"attributeFilters",
"=",
"new",
"AttrCollection",
"(",
"attributes",
".",
"attributeFilters",
")",
";",
"}",
"return",
"Backbone",
".",
"Model",
".",
"prototype",
".",
"set",
".",
"call",
"(",
"this",
",",
"attributes",
",",
"options",
")",
";",
"}"
] |
Set override
Makes sure the attributeFilters are set as a collection.
@method set
@param {Object} attributes
@param {Object} options
@return {*}
|
[
"Set",
"override",
"Makes",
"sure",
"the",
"attributeFilters",
"are",
"set",
"as",
"a",
"collection",
"."
] |
5b10216f091d0e4bad418398fb4ec4c4588f4475
|
https://github.com/WRidder/backgrid-advanced-filter/blob/5b10216f091d0e4bad418398fb4ec4c4588f4475/src/filter-collection.js#L238-L244
|
|
38,681 |
WRidder/backgrid-advanced-filter
|
src/filter-collection.js
|
function (style, exportAsString) {
var self = this;
var result;
switch (style) {
case "mongo":
case "mongodb":
default:
var mongoParser = new Backgrid.Extension.AdvancedFilter.FilterParsers.MongoParser();
result = mongoParser.parse(self);
if (exportAsString) {
result = self.stringifyFilterJson(result);
}
}
return result;
}
|
javascript
|
function (style, exportAsString) {
var self = this;
var result;
switch (style) {
case "mongo":
case "mongodb":
default:
var mongoParser = new Backgrid.Extension.AdvancedFilter.FilterParsers.MongoParser();
result = mongoParser.parse(self);
if (exportAsString) {
result = self.stringifyFilterJson(result);
}
}
return result;
}
|
[
"function",
"(",
"style",
",",
"exportAsString",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"result",
";",
"switch",
"(",
"style",
")",
"{",
"case",
"\"mongo\"",
":",
"case",
"\"mongodb\"",
":",
"default",
":",
"var",
"mongoParser",
"=",
"new",
"Backgrid",
".",
"Extension",
".",
"AdvancedFilter",
".",
"FilterParsers",
".",
"MongoParser",
"(",
")",
";",
"result",
"=",
"mongoParser",
".",
"parse",
"(",
"self",
")",
";",
"if",
"(",
"exportAsString",
")",
"{",
"result",
"=",
"self",
".",
"stringifyFilterJson",
"(",
"result",
")",
";",
"}",
"}",
"return",
"result",
";",
"}"
] |
Export the filter for a given style
@method exportFilter
@param {String} style. Values: "(mongo|mongodb), ..."
@param {boolean} exportAsString exports as a string if true.
@return {Object}
|
[
"Export",
"the",
"filter",
"for",
"a",
"given",
"style"
] |
5b10216f091d0e4bad418398fb4ec4c4588f4475
|
https://github.com/WRidder/backgrid-advanced-filter/blob/5b10216f091d0e4bad418398fb4ec4c4588f4475/src/filter-collection.js#L253-L269
|
|
38,682 |
WRidder/backgrid-advanced-filter
|
src/filter-collection.js
|
function() {
var self = this;
self.newFilterCount += 1;
if (self.length === 0) {
return self.newFilterCount;
}
else {
var newFilterName = self.newFilterName.replace(self.filterNamePartial, "");
var results = self.filter(function(fm) {
return fm.get("name").indexOf(newFilterName) === 0;
}).map(function(fm) {
return fm.get("name");
});
if (_.isArray(results) && results.length > 0) {
// Sort results
results.sort();
// Get highest count
var highestCount = parseInt(results[results.length - 1].replace(newFilterName, ""));
if (_.isNaN(highestCount)) {
highestCount = self.newFilterCount;
}
else {
highestCount += 1;
}
}
else {
highestCount = self.newFilterCount;
}
return highestCount;
}
}
|
javascript
|
function() {
var self = this;
self.newFilterCount += 1;
if (self.length === 0) {
return self.newFilterCount;
}
else {
var newFilterName = self.newFilterName.replace(self.filterNamePartial, "");
var results = self.filter(function(fm) {
return fm.get("name").indexOf(newFilterName) === 0;
}).map(function(fm) {
return fm.get("name");
});
if (_.isArray(results) && results.length > 0) {
// Sort results
results.sort();
// Get highest count
var highestCount = parseInt(results[results.length - 1].replace(newFilterName, ""));
if (_.isNaN(highestCount)) {
highestCount = self.newFilterCount;
}
else {
highestCount += 1;
}
}
else {
highestCount = self.newFilterCount;
}
return highestCount;
}
}
|
[
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"self",
".",
"newFilterCount",
"+=",
"1",
";",
"if",
"(",
"self",
".",
"length",
"===",
"0",
")",
"{",
"return",
"self",
".",
"newFilterCount",
";",
"}",
"else",
"{",
"var",
"newFilterName",
"=",
"self",
".",
"newFilterName",
".",
"replace",
"(",
"self",
".",
"filterNamePartial",
",",
"\"\"",
")",
";",
"var",
"results",
"=",
"self",
".",
"filter",
"(",
"function",
"(",
"fm",
")",
"{",
"return",
"fm",
".",
"get",
"(",
"\"name\"",
")",
".",
"indexOf",
"(",
"newFilterName",
")",
"===",
"0",
";",
"}",
")",
".",
"map",
"(",
"function",
"(",
"fm",
")",
"{",
"return",
"fm",
".",
"get",
"(",
"\"name\"",
")",
";",
"}",
")",
";",
"if",
"(",
"_",
".",
"isArray",
"(",
"results",
")",
"&&",
"results",
".",
"length",
">",
"0",
")",
"{",
"// Sort results",
"results",
".",
"sort",
"(",
")",
";",
"// Get highest count",
"var",
"highestCount",
"=",
"parseInt",
"(",
"results",
"[",
"results",
".",
"length",
"-",
"1",
"]",
".",
"replace",
"(",
"newFilterName",
",",
"\"\"",
")",
")",
";",
"if",
"(",
"_",
".",
"isNaN",
"(",
"highestCount",
")",
")",
"{",
"highestCount",
"=",
"self",
".",
"newFilterCount",
";",
"}",
"else",
"{",
"highestCount",
"+=",
"1",
";",
"}",
"}",
"else",
"{",
"highestCount",
"=",
"self",
".",
"newFilterCount",
";",
"}",
"return",
"highestCount",
";",
"}",
"}"
] |
Retrieves a new filter number.
@method getNewFilterNumber
@return {int}
@private
|
[
"Retrieves",
"a",
"new",
"filter",
"number",
"."
] |
5b10216f091d0e4bad418398fb4ec4c4588f4475
|
https://github.com/WRidder/backgrid-advanced-filter/blob/5b10216f091d0e4bad418398fb4ec4c4588f4475/src/filter-collection.js#L332-L366
|
|
38,683 |
furf/vineapple
|
lib/vineapple.js
|
function (username, password, callback) {
var request;
var promise;
// Preemptively validate username and password
if (!username) {
throw new Error('Invalid credentials. Missing username.');
}
if (!password) {
throw new Error('Invalid credentials. Missing password.');
}
// Execute the API request for authentication
request = this.request({
method: 'post',
url: 'users/authenticate',
form: {
deviceToken: Vineapple.DEVICE_TOKEN || createDeviceToken([
Vineapple.DEVICE_TOKEN_SEED,
username,
password
].join(':')),
username: username,
password: password
}
});
promise = request.then(this.authorize.bind(this));
if (callback) {
promise.then(callback.bind(null, null)).fail(callback);
}
return promise;
}
|
javascript
|
function (username, password, callback) {
var request;
var promise;
// Preemptively validate username and password
if (!username) {
throw new Error('Invalid credentials. Missing username.');
}
if (!password) {
throw new Error('Invalid credentials. Missing password.');
}
// Execute the API request for authentication
request = this.request({
method: 'post',
url: 'users/authenticate',
form: {
deviceToken: Vineapple.DEVICE_TOKEN || createDeviceToken([
Vineapple.DEVICE_TOKEN_SEED,
username,
password
].join(':')),
username: username,
password: password
}
});
promise = request.then(this.authorize.bind(this));
if (callback) {
promise.then(callback.bind(null, null)).fail(callback);
}
return promise;
}
|
[
"function",
"(",
"username",
",",
"password",
",",
"callback",
")",
"{",
"var",
"request",
";",
"var",
"promise",
";",
"// Preemptively validate username and password",
"if",
"(",
"!",
"username",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Invalid credentials. Missing username.'",
")",
";",
"}",
"if",
"(",
"!",
"password",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Invalid credentials. Missing password.'",
")",
";",
"}",
"// Execute the API request for authentication",
"request",
"=",
"this",
".",
"request",
"(",
"{",
"method",
":",
"'post'",
",",
"url",
":",
"'users/authenticate'",
",",
"form",
":",
"{",
"deviceToken",
":",
"Vineapple",
".",
"DEVICE_TOKEN",
"||",
"createDeviceToken",
"(",
"[",
"Vineapple",
".",
"DEVICE_TOKEN_SEED",
",",
"username",
",",
"password",
"]",
".",
"join",
"(",
"':'",
")",
")",
",",
"username",
":",
"username",
",",
"password",
":",
"password",
"}",
"}",
")",
";",
"promise",
"=",
"request",
".",
"then",
"(",
"this",
".",
"authorize",
".",
"bind",
"(",
"this",
")",
")",
";",
"if",
"(",
"callback",
")",
"{",
"promise",
".",
"then",
"(",
"callback",
".",
"bind",
"(",
"null",
",",
"null",
")",
")",
".",
"fail",
"(",
"callback",
")",
";",
"}",
"return",
"promise",
";",
"}"
] |
Authenticate the Vine API client
@param username {String}
@param password {String}
@param callback {Function} [optional]
@return {Object} request API promise
|
[
"Authenticate",
"the",
"Vine",
"API",
"client"
] |
9c71f2e45f306a517b6cfcfb3ef8e804918e3f81
|
https://github.com/furf/vineapple/blob/9c71f2e45f306a517b6cfcfb3ef8e804918e3f81/lib/vineapple.js#L155-L191
|
|
38,684 |
furf/vineapple
|
lib/vineapple.js
|
function (callback) {
var promise = this.request({
method: 'delete',
url: 'users/authenticate'
}).then(this.authorize.bind(this));
if (callback) {
promise.then(callback.bind(null, null)).fail(callback);
}
return promise;
}
|
javascript
|
function (callback) {
var promise = this.request({
method: 'delete',
url: 'users/authenticate'
}).then(this.authorize.bind(this));
if (callback) {
promise.then(callback.bind(null, null)).fail(callback);
}
return promise;
}
|
[
"function",
"(",
"callback",
")",
"{",
"var",
"promise",
"=",
"this",
".",
"request",
"(",
"{",
"method",
":",
"'delete'",
",",
"url",
":",
"'users/authenticate'",
"}",
")",
".",
"then",
"(",
"this",
".",
"authorize",
".",
"bind",
"(",
"this",
")",
")",
";",
"if",
"(",
"callback",
")",
"{",
"promise",
".",
"then",
"(",
"callback",
".",
"bind",
"(",
"null",
",",
"null",
")",
")",
".",
"fail",
"(",
"callback",
")",
";",
"}",
"return",
"promise",
";",
"}"
] |
De-authenticate the Vine API client
@param username {String}
@param password {String}
@param callback {Function} [optional]
@return {Object} request API promise
|
[
"De",
"-",
"authenticate",
"the",
"Vine",
"API",
"client"
] |
9c71f2e45f306a517b6cfcfb3ef8e804918e3f81
|
https://github.com/furf/vineapple/blob/9c71f2e45f306a517b6cfcfb3ef8e804918e3f81/lib/vineapple.js#L200-L212
|
|
38,685 |
furf/vineapple
|
lib/vineapple.js
|
function (settings) {
this.key = settings && settings.key;
this.userId = settings && settings.userId;
this.username = settings && settings.username;
return this;
}
|
javascript
|
function (settings) {
this.key = settings && settings.key;
this.userId = settings && settings.userId;
this.username = settings && settings.username;
return this;
}
|
[
"function",
"(",
"settings",
")",
"{",
"this",
".",
"key",
"=",
"settings",
"&&",
"settings",
".",
"key",
";",
"this",
".",
"userId",
"=",
"settings",
"&&",
"settings",
".",
"userId",
";",
"this",
".",
"username",
"=",
"settings",
"&&",
"settings",
".",
"username",
";",
"return",
"this",
";",
"}"
] |
Authorize the current client
@param settings {Object}
@return {Object} self
|
[
"Authorize",
"the",
"current",
"client"
] |
9c71f2e45f306a517b6cfcfb3ef8e804918e3f81
|
https://github.com/furf/vineapple/blob/9c71f2e45f306a517b6cfcfb3ef8e804918e3f81/lib/vineapple.js#L219-L224
|
|
38,686 |
kozervar/napi-js
|
dist/download.js
|
generateFileHashes
|
function generateFileHashes(options, files) {
if (options.verbose) {
_utils.logger.info('Generating files hash...');
}
if (files.length === 0) _utils.logger.info('No files found!');else if (options.verbose) {
_utils.logger.info('Files found: ');
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = files[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var file = _step.value;
_utils.logger.info(file);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}
var promises = [];
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = files[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var file = _step2.value;
promises.push((0, _utils.hash)(file));
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
return Promise.all(promises);
}
|
javascript
|
function generateFileHashes(options, files) {
if (options.verbose) {
_utils.logger.info('Generating files hash...');
}
if (files.length === 0) _utils.logger.info('No files found!');else if (options.verbose) {
_utils.logger.info('Files found: ');
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = files[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var file = _step.value;
_utils.logger.info(file);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}
var promises = [];
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = files[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var file = _step2.value;
promises.push((0, _utils.hash)(file));
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
return Promise.all(promises);
}
|
[
"function",
"generateFileHashes",
"(",
"options",
",",
"files",
")",
"{",
"if",
"(",
"options",
".",
"verbose",
")",
"{",
"_utils",
".",
"logger",
".",
"info",
"(",
"'Generating files hash...'",
")",
";",
"}",
"if",
"(",
"files",
".",
"length",
"===",
"0",
")",
"_utils",
".",
"logger",
".",
"info",
"(",
"'No files found!'",
")",
";",
"else",
"if",
"(",
"options",
".",
"verbose",
")",
"{",
"_utils",
".",
"logger",
".",
"info",
"(",
"'Files found: '",
")",
";",
"var",
"_iteratorNormalCompletion",
"=",
"true",
";",
"var",
"_didIteratorError",
"=",
"false",
";",
"var",
"_iteratorError",
"=",
"undefined",
";",
"try",
"{",
"for",
"(",
"var",
"_iterator",
"=",
"files",
"[",
"Symbol",
".",
"iterator",
"]",
"(",
")",
",",
"_step",
";",
"!",
"(",
"_iteratorNormalCompletion",
"=",
"(",
"_step",
"=",
"_iterator",
".",
"next",
"(",
")",
")",
".",
"done",
")",
";",
"_iteratorNormalCompletion",
"=",
"true",
")",
"{",
"var",
"file",
"=",
"_step",
".",
"value",
";",
"_utils",
".",
"logger",
".",
"info",
"(",
"file",
")",
";",
"}",
"}",
"catch",
"(",
"err",
")",
"{",
"_didIteratorError",
"=",
"true",
";",
"_iteratorError",
"=",
"err",
";",
"}",
"finally",
"{",
"try",
"{",
"if",
"(",
"!",
"_iteratorNormalCompletion",
"&&",
"_iterator",
".",
"return",
")",
"{",
"_iterator",
".",
"return",
"(",
")",
";",
"}",
"}",
"finally",
"{",
"if",
"(",
"_didIteratorError",
")",
"{",
"throw",
"_iteratorError",
";",
"}",
"}",
"}",
"}",
"var",
"promises",
"=",
"[",
"]",
";",
"var",
"_iteratorNormalCompletion2",
"=",
"true",
";",
"var",
"_didIteratorError2",
"=",
"false",
";",
"var",
"_iteratorError2",
"=",
"undefined",
";",
"try",
"{",
"for",
"(",
"var",
"_iterator2",
"=",
"files",
"[",
"Symbol",
".",
"iterator",
"]",
"(",
")",
",",
"_step2",
";",
"!",
"(",
"_iteratorNormalCompletion2",
"=",
"(",
"_step2",
"=",
"_iterator2",
".",
"next",
"(",
")",
")",
".",
"done",
")",
";",
"_iteratorNormalCompletion2",
"=",
"true",
")",
"{",
"var",
"file",
"=",
"_step2",
".",
"value",
";",
"promises",
".",
"push",
"(",
"(",
"0",
",",
"_utils",
".",
"hash",
")",
"(",
"file",
")",
")",
";",
"}",
"}",
"catch",
"(",
"err",
")",
"{",
"_didIteratorError2",
"=",
"true",
";",
"_iteratorError2",
"=",
"err",
";",
"}",
"finally",
"{",
"try",
"{",
"if",
"(",
"!",
"_iteratorNormalCompletion2",
"&&",
"_iterator2",
".",
"return",
")",
"{",
"_iterator2",
".",
"return",
"(",
")",
";",
"}",
"}",
"finally",
"{",
"if",
"(",
"_didIteratorError2",
")",
"{",
"throw",
"_iteratorError2",
";",
"}",
"}",
"}",
"return",
"Promise",
".",
"all",
"(",
"promises",
")",
";",
"}"
] |
Generate MD5 partial hash for provided files
@param {NapijsOptions} options
@param files
@returns {Promise}
|
[
"Generate",
"MD5",
"partial",
"hash",
"for",
"provided",
"files"
] |
f54809fdd20ad293c46ce1fbed0b4c1e12d4977c
|
https://github.com/kozervar/napi-js/blob/f54809fdd20ad293c46ce1fbed0b4c1e12d4977c/dist/download.js#L18-L77
|
38,687 |
kozervar/napi-js
|
dist/download.js
|
makeHttpRequests
|
function makeHttpRequests(options, fileHashes) {
if (options.verbose) {
_utils.logger.info('Performing HTTP requests...');
}
var promises = [];
var _iteratorNormalCompletion4 = true;
var _didIteratorError4 = false;
var _iteratorError4 = undefined;
try {
for (var _iterator4 = fileHashes[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
var fileWithHash = _step4.value;
if (fileWithHash.subtitlesPresent) continue;
if (options.verbose) {
_utils.logger.info('Downloading subtitles for file [%s] with hash [%s]', fileWithHash.file, fileWithHash.hash);
}
var httpRequest = new _utils.HttpRequest(options, fileWithHash);
promises.push(httpRequest.request());
}
} catch (err) {
_didIteratorError4 = true;
_iteratorError4 = err;
} finally {
try {
if (!_iteratorNormalCompletion4 && _iterator4.return) {
_iterator4.return();
}
} finally {
if (_didIteratorError4) {
throw _iteratorError4;
}
}
}
return Promise.all(promises);
}
|
javascript
|
function makeHttpRequests(options, fileHashes) {
if (options.verbose) {
_utils.logger.info('Performing HTTP requests...');
}
var promises = [];
var _iteratorNormalCompletion4 = true;
var _didIteratorError4 = false;
var _iteratorError4 = undefined;
try {
for (var _iterator4 = fileHashes[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
var fileWithHash = _step4.value;
if (fileWithHash.subtitlesPresent) continue;
if (options.verbose) {
_utils.logger.info('Downloading subtitles for file [%s] with hash [%s]', fileWithHash.file, fileWithHash.hash);
}
var httpRequest = new _utils.HttpRequest(options, fileWithHash);
promises.push(httpRequest.request());
}
} catch (err) {
_didIteratorError4 = true;
_iteratorError4 = err;
} finally {
try {
if (!_iteratorNormalCompletion4 && _iterator4.return) {
_iterator4.return();
}
} finally {
if (_didIteratorError4) {
throw _iteratorError4;
}
}
}
return Promise.all(promises);
}
|
[
"function",
"makeHttpRequests",
"(",
"options",
",",
"fileHashes",
")",
"{",
"if",
"(",
"options",
".",
"verbose",
")",
"{",
"_utils",
".",
"logger",
".",
"info",
"(",
"'Performing HTTP requests...'",
")",
";",
"}",
"var",
"promises",
"=",
"[",
"]",
";",
"var",
"_iteratorNormalCompletion4",
"=",
"true",
";",
"var",
"_didIteratorError4",
"=",
"false",
";",
"var",
"_iteratorError4",
"=",
"undefined",
";",
"try",
"{",
"for",
"(",
"var",
"_iterator4",
"=",
"fileHashes",
"[",
"Symbol",
".",
"iterator",
"]",
"(",
")",
",",
"_step4",
";",
"!",
"(",
"_iteratorNormalCompletion4",
"=",
"(",
"_step4",
"=",
"_iterator4",
".",
"next",
"(",
")",
")",
".",
"done",
")",
";",
"_iteratorNormalCompletion4",
"=",
"true",
")",
"{",
"var",
"fileWithHash",
"=",
"_step4",
".",
"value",
";",
"if",
"(",
"fileWithHash",
".",
"subtitlesPresent",
")",
"continue",
";",
"if",
"(",
"options",
".",
"verbose",
")",
"{",
"_utils",
".",
"logger",
".",
"info",
"(",
"'Downloading subtitles for file [%s] with hash [%s]'",
",",
"fileWithHash",
".",
"file",
",",
"fileWithHash",
".",
"hash",
")",
";",
"}",
"var",
"httpRequest",
"=",
"new",
"_utils",
".",
"HttpRequest",
"(",
"options",
",",
"fileWithHash",
")",
";",
"promises",
".",
"push",
"(",
"httpRequest",
".",
"request",
"(",
")",
")",
";",
"}",
"}",
"catch",
"(",
"err",
")",
"{",
"_didIteratorError4",
"=",
"true",
";",
"_iteratorError4",
"=",
"err",
";",
"}",
"finally",
"{",
"try",
"{",
"if",
"(",
"!",
"_iteratorNormalCompletion4",
"&&",
"_iterator4",
".",
"return",
")",
"{",
"_iterator4",
".",
"return",
"(",
")",
";",
"}",
"}",
"finally",
"{",
"if",
"(",
"_didIteratorError4",
")",
"{",
"throw",
"_iteratorError4",
";",
"}",
"}",
"}",
"return",
"Promise",
".",
"all",
"(",
"promises",
")",
";",
"}"
] |
Perform HTTP request to Napiprojekt server
@param {NapijsOptions} options
@param fileHashes
@returns {Promise}
|
[
"Perform",
"HTTP",
"request",
"to",
"Napiprojekt",
"server"
] |
f54809fdd20ad293c46ce1fbed0b4c1e12d4977c
|
https://github.com/kozervar/napi-js/blob/f54809fdd20ad293c46ce1fbed0b4c1e12d4977c/dist/download.js#L123-L159
|
38,688 |
kozervar/napi-js
|
dist/download.js
|
parseHttpResponse
|
function parseHttpResponse(options, filesWithHash) {
if (options.verbose) {
_utils.logger.info('Parsing HTTP responses...');
}
var promises = [];
var _iteratorNormalCompletion5 = true;
var _didIteratorError5 = false;
var _iteratorError5 = undefined;
try {
for (var _iterator5 = filesWithHash[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
var fileWithHash = _step5.value;
if (fileWithHash.subtitlesPresent) continue;
var p = (0, _utils.XML2JSON)(options, fileWithHash).catch(function (err) {
if (options.verbose) {
_utils.logger.info('Error in HTTP response: ', err.err);
}
return err.fileWithHash;
});
promises.push(p);
}
} catch (err) {
_didIteratorError5 = true;
_iteratorError5 = err;
} finally {
try {
if (!_iteratorNormalCompletion5 && _iterator5.return) {
_iterator5.return();
}
} finally {
if (_didIteratorError5) {
throw _iteratorError5;
}
}
}
return Promise.all(promises);
}
|
javascript
|
function parseHttpResponse(options, filesWithHash) {
if (options.verbose) {
_utils.logger.info('Parsing HTTP responses...');
}
var promises = [];
var _iteratorNormalCompletion5 = true;
var _didIteratorError5 = false;
var _iteratorError5 = undefined;
try {
for (var _iterator5 = filesWithHash[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
var fileWithHash = _step5.value;
if (fileWithHash.subtitlesPresent) continue;
var p = (0, _utils.XML2JSON)(options, fileWithHash).catch(function (err) {
if (options.verbose) {
_utils.logger.info('Error in HTTP response: ', err.err);
}
return err.fileWithHash;
});
promises.push(p);
}
} catch (err) {
_didIteratorError5 = true;
_iteratorError5 = err;
} finally {
try {
if (!_iteratorNormalCompletion5 && _iterator5.return) {
_iterator5.return();
}
} finally {
if (_didIteratorError5) {
throw _iteratorError5;
}
}
}
return Promise.all(promises);
}
|
[
"function",
"parseHttpResponse",
"(",
"options",
",",
"filesWithHash",
")",
"{",
"if",
"(",
"options",
".",
"verbose",
")",
"{",
"_utils",
".",
"logger",
".",
"info",
"(",
"'Parsing HTTP responses...'",
")",
";",
"}",
"var",
"promises",
"=",
"[",
"]",
";",
"var",
"_iteratorNormalCompletion5",
"=",
"true",
";",
"var",
"_didIteratorError5",
"=",
"false",
";",
"var",
"_iteratorError5",
"=",
"undefined",
";",
"try",
"{",
"for",
"(",
"var",
"_iterator5",
"=",
"filesWithHash",
"[",
"Symbol",
".",
"iterator",
"]",
"(",
")",
",",
"_step5",
";",
"!",
"(",
"_iteratorNormalCompletion5",
"=",
"(",
"_step5",
"=",
"_iterator5",
".",
"next",
"(",
")",
")",
".",
"done",
")",
";",
"_iteratorNormalCompletion5",
"=",
"true",
")",
"{",
"var",
"fileWithHash",
"=",
"_step5",
".",
"value",
";",
"if",
"(",
"fileWithHash",
".",
"subtitlesPresent",
")",
"continue",
";",
"var",
"p",
"=",
"(",
"0",
",",
"_utils",
".",
"XML2JSON",
")",
"(",
"options",
",",
"fileWithHash",
")",
".",
"catch",
"(",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"options",
".",
"verbose",
")",
"{",
"_utils",
".",
"logger",
".",
"info",
"(",
"'Error in HTTP response: '",
",",
"err",
".",
"err",
")",
";",
"}",
"return",
"err",
".",
"fileWithHash",
";",
"}",
")",
";",
"promises",
".",
"push",
"(",
"p",
")",
";",
"}",
"}",
"catch",
"(",
"err",
")",
"{",
"_didIteratorError5",
"=",
"true",
";",
"_iteratorError5",
"=",
"err",
";",
"}",
"finally",
"{",
"try",
"{",
"if",
"(",
"!",
"_iteratorNormalCompletion5",
"&&",
"_iterator5",
".",
"return",
")",
"{",
"_iterator5",
".",
"return",
"(",
")",
";",
"}",
"}",
"finally",
"{",
"if",
"(",
"_didIteratorError5",
")",
"{",
"throw",
"_iteratorError5",
";",
"}",
"}",
"}",
"return",
"Promise",
".",
"all",
"(",
"promises",
")",
";",
"}"
] |
Parse HTTP response from Napiprojekt server. Format XML response to JSON and save subtitles to file.
@param {NapijsOptions} options
@param filesWithHash
@returns {Promise}
|
[
"Parse",
"HTTP",
"response",
"from",
"Napiprojekt",
"server",
".",
"Format",
"XML",
"response",
"to",
"JSON",
"and",
"save",
"subtitles",
"to",
"file",
"."
] |
f54809fdd20ad293c46ce1fbed0b4c1e12d4977c
|
https://github.com/kozervar/napi-js/blob/f54809fdd20ad293c46ce1fbed0b4c1e12d4977c/dist/download.js#L167-L205
|
38,689 |
ipanli/xlsxtojson
|
lib/xlsx-to-json.js
|
parseObjectArrayField
|
function parseObjectArrayField(row, key, value) {
var obj_array = [];
if (value) {
if (value.indexOf(',') !== -1) {
obj_array = value.split(',');
} else {
obj_array.push(value.toString());
};
};
// if (typeof(value) === 'string' && value.indexOf(',') !== -1) {
// obj_array = value.split(',');
// } else {
// obj_array.push(value.toString());
// };
var result = [];
obj_array.forEach(function(e) {
if (e) {
result.push(array2object(e.split(';')));
}
});
row[key] = result;
}
|
javascript
|
function parseObjectArrayField(row, key, value) {
var obj_array = [];
if (value) {
if (value.indexOf(',') !== -1) {
obj_array = value.split(',');
} else {
obj_array.push(value.toString());
};
};
// if (typeof(value) === 'string' && value.indexOf(',') !== -1) {
// obj_array = value.split(',');
// } else {
// obj_array.push(value.toString());
// };
var result = [];
obj_array.forEach(function(e) {
if (e) {
result.push(array2object(e.split(';')));
}
});
row[key] = result;
}
|
[
"function",
"parseObjectArrayField",
"(",
"row",
",",
"key",
",",
"value",
")",
"{",
"var",
"obj_array",
"=",
"[",
"]",
";",
"if",
"(",
"value",
")",
"{",
"if",
"(",
"value",
".",
"indexOf",
"(",
"','",
")",
"!==",
"-",
"1",
")",
"{",
"obj_array",
"=",
"value",
".",
"split",
"(",
"','",
")",
";",
"}",
"else",
"{",
"obj_array",
".",
"push",
"(",
"value",
".",
"toString",
"(",
")",
")",
";",
"}",
";",
"}",
";",
"// if (typeof(value) === 'string' && value.indexOf(',') !== -1) {",
"// obj_array = value.split(',');",
"// } else {",
"// obj_array.push(value.toString());",
"// };",
"var",
"result",
"=",
"[",
"]",
";",
"obj_array",
".",
"forEach",
"(",
"function",
"(",
"e",
")",
"{",
"if",
"(",
"e",
")",
"{",
"result",
".",
"push",
"(",
"array2object",
"(",
"e",
".",
"split",
"(",
"';'",
")",
")",
")",
";",
"}",
"}",
")",
";",
"row",
"[",
"key",
"]",
"=",
"result",
";",
"}"
] |
parse object array.
|
[
"parse",
"object",
"array",
"."
] |
7432f133d584d6f32eb2bf722de084e2416bc468
|
https://github.com/ipanli/xlsxtojson/blob/7432f133d584d6f32eb2bf722de084e2416bc468/lib/xlsx-to-json.js#L205-L232
|
38,690 |
ipanli/xlsxtojson
|
lib/xlsx-to-json.js
|
parseBasicArrayField
|
function parseBasicArrayField(field, key, array) {
var basic_array;
if (typeof array === "string") {
basic_array = array.split(arraySeparator);
} else {
basic_array = [];
basic_array.push(array);
};
var result = [];
if (isNumberArray(basic_array)) {
basic_array.forEach(function(element) {
result.push(Number(element));
});
} else if (isBooleanArray(basic_array)) {
basic_array.forEach(function(element) {
result.push(toBoolean(element));
});
} else { //string array
result = basic_array;
};
// console.log("basic_array", result + "|||" + cell.value);
field[key] = result;
}
|
javascript
|
function parseBasicArrayField(field, key, array) {
var basic_array;
if (typeof array === "string") {
basic_array = array.split(arraySeparator);
} else {
basic_array = [];
basic_array.push(array);
};
var result = [];
if (isNumberArray(basic_array)) {
basic_array.forEach(function(element) {
result.push(Number(element));
});
} else if (isBooleanArray(basic_array)) {
basic_array.forEach(function(element) {
result.push(toBoolean(element));
});
} else { //string array
result = basic_array;
};
// console.log("basic_array", result + "|||" + cell.value);
field[key] = result;
}
|
[
"function",
"parseBasicArrayField",
"(",
"field",
",",
"key",
",",
"array",
")",
"{",
"var",
"basic_array",
";",
"if",
"(",
"typeof",
"array",
"===",
"\"string\"",
")",
"{",
"basic_array",
"=",
"array",
".",
"split",
"(",
"arraySeparator",
")",
";",
"}",
"else",
"{",
"basic_array",
"=",
"[",
"]",
";",
"basic_array",
".",
"push",
"(",
"array",
")",
";",
"}",
";",
"var",
"result",
"=",
"[",
"]",
";",
"if",
"(",
"isNumberArray",
"(",
"basic_array",
")",
")",
"{",
"basic_array",
".",
"forEach",
"(",
"function",
"(",
"element",
")",
"{",
"result",
".",
"push",
"(",
"Number",
"(",
"element",
")",
")",
";",
"}",
")",
";",
"}",
"else",
"if",
"(",
"isBooleanArray",
"(",
"basic_array",
")",
")",
"{",
"basic_array",
".",
"forEach",
"(",
"function",
"(",
"element",
")",
"{",
"result",
".",
"push",
"(",
"toBoolean",
"(",
"element",
")",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"//string array",
"result",
"=",
"basic_array",
";",
"}",
";",
"// console.log(\"basic_array\", result + \"|||\" + cell.value);",
"field",
"[",
"key",
"]",
"=",
"result",
";",
"}"
] |
parse simple array.
|
[
"parse",
"simple",
"array",
"."
] |
7432f133d584d6f32eb2bf722de084e2416bc468
|
https://github.com/ipanli/xlsxtojson/blob/7432f133d584d6f32eb2bf722de084e2416bc468/lib/xlsx-to-json.js#L267-L291
|
38,691 |
ipanli/xlsxtojson
|
lib/xlsx-to-json.js
|
isBoolean
|
function isBoolean(value) {
if (typeof(value) == "undefined") {
return false;
}
if (typeof value === 'boolean') {
return true;
};
var b = value.toString().trim().toLowerCase();
return b === 'true' || b === 'false';
}
|
javascript
|
function isBoolean(value) {
if (typeof(value) == "undefined") {
return false;
}
if (typeof value === 'boolean') {
return true;
};
var b = value.toString().trim().toLowerCase();
return b === 'true' || b === 'false';
}
|
[
"function",
"isBoolean",
"(",
"value",
")",
"{",
"if",
"(",
"typeof",
"(",
"value",
")",
"==",
"\"undefined\"",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"typeof",
"value",
"===",
"'boolean'",
")",
"{",
"return",
"true",
";",
"}",
";",
"var",
"b",
"=",
"value",
".",
"toString",
"(",
")",
".",
"trim",
"(",
")",
".",
"toLowerCase",
"(",
")",
";",
"return",
"b",
"===",
"'true'",
"||",
"b",
"===",
"'false'",
";",
"}"
] |
boolean type check.
|
[
"boolean",
"type",
"check",
"."
] |
7432f133d584d6f32eb2bf722de084e2416bc468
|
https://github.com/ipanli/xlsxtojson/blob/7432f133d584d6f32eb2bf722de084e2416bc468/lib/xlsx-to-json.js#L336-L349
|
38,692 |
ipanli/xlsxtojson
|
lib/xlsx-to-json.js
|
isDateType
|
function isDateType(value) {
if (value) {
var str = value.toString();
return moment(new Date(value), "YYYY-M-D", true).isValid() || moment(value, "YYYY-M-D H:m:s", true).isValid() || moment(value, "YYYY/M/D H:m:s", true).isValid() || moment(value, "YYYY/M/D", true).isValid();
};
return false;
}
|
javascript
|
function isDateType(value) {
if (value) {
var str = value.toString();
return moment(new Date(value), "YYYY-M-D", true).isValid() || moment(value, "YYYY-M-D H:m:s", true).isValid() || moment(value, "YYYY/M/D H:m:s", true).isValid() || moment(value, "YYYY/M/D", true).isValid();
};
return false;
}
|
[
"function",
"isDateType",
"(",
"value",
")",
"{",
"if",
"(",
"value",
")",
"{",
"var",
"str",
"=",
"value",
".",
"toString",
"(",
")",
";",
"return",
"moment",
"(",
"new",
"Date",
"(",
"value",
")",
",",
"\"YYYY-M-D\"",
",",
"true",
")",
".",
"isValid",
"(",
")",
"||",
"moment",
"(",
"value",
",",
"\"YYYY-M-D H:m:s\"",
",",
"true",
")",
".",
"isValid",
"(",
")",
"||",
"moment",
"(",
"value",
",",
"\"YYYY/M/D H:m:s\"",
",",
"true",
")",
".",
"isValid",
"(",
")",
"||",
"moment",
"(",
"value",
",",
"\"YYYY/M/D\"",
",",
"true",
")",
".",
"isValid",
"(",
")",
";",
"}",
";",
"return",
"false",
";",
"}"
] |
date type check.
|
[
"date",
"type",
"check",
"."
] |
7432f133d584d6f32eb2bf722de084e2416bc468
|
https://github.com/ipanli/xlsxtojson/blob/7432f133d584d6f32eb2bf722de084e2416bc468/lib/xlsx-to-json.js#L359-L365
|
38,693 |
mjlescano/domator
|
domator.js
|
domator
|
function domator() {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return render(parse(args));
}
|
javascript
|
function domator() {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return render(parse(args));
}
|
[
"function",
"domator",
"(",
")",
"{",
"for",
"(",
"var",
"_len",
"=",
"arguments",
".",
"length",
",",
"args",
"=",
"Array",
"(",
"_len",
")",
",",
"_key",
"=",
"0",
";",
"_key",
"<",
"_len",
";",
"_key",
"++",
")",
"{",
"args",
"[",
"_key",
"]",
"=",
"arguments",
"[",
"_key",
"]",
";",
"}",
"return",
"render",
"(",
"parse",
"(",
"args",
")",
")",
";",
"}"
] |
Default domator export
|
[
"Default",
"domator",
"export"
] |
8307bee6172f4830d40df61ba277ac2b2b4c0fc2
|
https://github.com/mjlescano/domator/blob/8307bee6172f4830d40df61ba277ac2b2b4c0fc2/domator.js#L175-L181
|
38,694 |
rootsdev/gedcomx-js
|
src/core/Subject.js
|
function(json){
// Protect against forgetting the new keyword when calling the constructor
if(!(this instanceof Subject)){
return new Subject(json);
}
// If the given object is already an instance then just return it. DON'T copy it.
if(Subject.isInstance(json)){
return json;
}
this.init(json);
}
|
javascript
|
function(json){
// Protect against forgetting the new keyword when calling the constructor
if(!(this instanceof Subject)){
return new Subject(json);
}
// If the given object is already an instance then just return it. DON'T copy it.
if(Subject.isInstance(json)){
return json;
}
this.init(json);
}
|
[
"function",
"(",
"json",
")",
"{",
"// Protect against forgetting the new keyword when calling the constructor",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Subject",
")",
")",
"{",
"return",
"new",
"Subject",
"(",
"json",
")",
";",
"}",
"// If the given object is already an instance then just return it. DON'T copy it.",
"if",
"(",
"Subject",
".",
"isInstance",
"(",
"json",
")",
")",
"{",
"return",
"json",
";",
"}",
"this",
".",
"init",
"(",
"json",
")",
";",
"}"
] |
An object identified in time and space by various conclusions.
@see {@link https://github.com/FamilySearch/gedcomx/blob/master/specifications/json-format-specification.md#subject|GEDCOM X JSON Spec}
@class
@extends Conclusion
@param {Object} [json]
|
[
"An",
"object",
"identified",
"in",
"time",
"and",
"space",
"by",
"various",
"conclusions",
"."
] |
08b2fcde96f1e301c78561bfb7a8b0cac606e26e
|
https://github.com/rootsdev/gedcomx-js/blob/08b2fcde96f1e301c78561bfb7a8b0cac606e26e/src/core/Subject.js#L13-L26
|
|
38,695 |
rootsdev/gedcomx-js
|
src/core/Document.js
|
function(json){
// Protect against forgetting the new keyword when calling the constructor
if(!(this instanceof Document)){
return new Document(json);
}
// If the given object is already an instance then just return it. DON'T copy it.
if(Document.isInstance(json)){
return json;
}
this.init(json);
}
|
javascript
|
function(json){
// Protect against forgetting the new keyword when calling the constructor
if(!(this instanceof Document)){
return new Document(json);
}
// If the given object is already an instance then just return it. DON'T copy it.
if(Document.isInstance(json)){
return json;
}
this.init(json);
}
|
[
"function",
"(",
"json",
")",
"{",
"// Protect against forgetting the new keyword when calling the constructor",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Document",
")",
")",
"{",
"return",
"new",
"Document",
"(",
"json",
")",
";",
"}",
"// If the given object is already an instance then just return it. DON'T copy it.",
"if",
"(",
"Document",
".",
"isInstance",
"(",
"json",
")",
")",
"{",
"return",
"json",
";",
"}",
"this",
".",
"init",
"(",
"json",
")",
";",
"}"
] |
A textual document
@see {@link https://github.com/FamilySearch/gedcomx/blob/master/specifications/json-format-specification.md#document|GEDCOM X JSON Spec}
@class
@extends Conclusion
@param {Object} [json]
|
[
"A",
"textual",
"document"
] |
08b2fcde96f1e301c78561bfb7a8b0cac606e26e
|
https://github.com/rootsdev/gedcomx-js/blob/08b2fcde96f1e301c78561bfb7a8b0cac606e26e/src/core/Document.js#L13-L26
|
|
38,696 |
rootsdev/gedcomx-js
|
src/records/FieldValue.js
|
function(json){
// Protect against forgetting the new keyword when calling the constructor
if(!(this instanceof FieldValue)){
return new FieldValue(json);
}
// If the given object is already an instance then just return it. DON'T copy it.
if(FieldValue.isInstance(json)){
return json;
}
this.init(json);
}
|
javascript
|
function(json){
// Protect against forgetting the new keyword when calling the constructor
if(!(this instanceof FieldValue)){
return new FieldValue(json);
}
// If the given object is already an instance then just return it. DON'T copy it.
if(FieldValue.isInstance(json)){
return json;
}
this.init(json);
}
|
[
"function",
"(",
"json",
")",
"{",
"// Protect against forgetting the new keyword when calling the constructor",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"FieldValue",
")",
")",
"{",
"return",
"new",
"FieldValue",
"(",
"json",
")",
";",
"}",
"// If the given object is already an instance then just return it. DON'T copy it.",
"if",
"(",
"FieldValue",
".",
"isInstance",
"(",
"json",
")",
")",
"{",
"return",
"json",
";",
"}",
"this",
".",
"init",
"(",
"json",
")",
";",
"}"
] |
Information about the value of a field.
@see {@link https://github.com/FamilySearch/gedcomx-record/blob/master/specifications/record-specification.md#field-value-data-type|GEDCOM X Records Spec}
@class FieldValue
@extends Conclusion
@param {Object} [json]
|
[
"Information",
"about",
"the",
"value",
"of",
"a",
"field",
"."
] |
08b2fcde96f1e301c78561bfb7a8b0cac606e26e
|
https://github.com/rootsdev/gedcomx-js/blob/08b2fcde96f1e301c78561bfb7a8b0cac606e26e/src/records/FieldValue.js#L14-L27
|
|
38,697 |
rootsdev/gedcomx-js
|
src/core/Name.js
|
function(json){
// Protect against forgetting the new keyword when calling the constructor
if(!(this instanceof Name)){
return new Name(json);
}
// If the given object is already an instance then just return it. DON'T copy it.
if(Name.isInstance(json)){
return json;
}
this.init(json);
}
|
javascript
|
function(json){
// Protect against forgetting the new keyword when calling the constructor
if(!(this instanceof Name)){
return new Name(json);
}
// If the given object is already an instance then just return it. DON'T copy it.
if(Name.isInstance(json)){
return json;
}
this.init(json);
}
|
[
"function",
"(",
"json",
")",
"{",
"// Protect against forgetting the new keyword when calling the constructor",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Name",
")",
")",
"{",
"return",
"new",
"Name",
"(",
"json",
")",
";",
"}",
"// If the given object is already an instance then just return it. DON'T copy it.",
"if",
"(",
"Name",
".",
"isInstance",
"(",
"json",
")",
")",
"{",
"return",
"json",
";",
"}",
"this",
".",
"init",
"(",
"json",
")",
";",
"}"
] |
A name.
@see {@link https://github.com/FamilySearch/gedcomx/blob/master/specifications/json-format-specification.md#name-conclusion|GEDCOM X JSON Spec}
@class
@extends Conclusion
@param {Object} [json]
|
[
"A",
"name",
"."
] |
08b2fcde96f1e301c78561bfb7a8b0cac606e26e
|
https://github.com/rootsdev/gedcomx-js/blob/08b2fcde96f1e301c78561bfb7a8b0cac606e26e/src/core/Name.js#L13-L26
|
|
38,698 |
Adeptive/Smappee-NodeJS
|
smappee-api.js
|
function(handler) {
if (typeof accessToken == 'undefined') {
var body = {
client_id: clientId,
client_secret: clientSecret,
username: username,
password: password,
grant_type: 'password'
};
if (thisObject.debug) {
console.log("Making oAuth call...");
}
var options = {
url: 'https://app1pub.smappee.net/dev/v1/oauth2/token',
headers: {
'Host': 'app1pub.smappee.net'
},
form: body
};
request.post(options, function (err, httpResponse, body) {
if (err) {
return console.error('Request failed:', err);
}
if (thisObject.debug) {
console.log('Server responded with:', body);
}
accessToken = JSON.parse(body);
handler(accessToken);
});
} else {
handler(accessToken)
}
}
|
javascript
|
function(handler) {
if (typeof accessToken == 'undefined') {
var body = {
client_id: clientId,
client_secret: clientSecret,
username: username,
password: password,
grant_type: 'password'
};
if (thisObject.debug) {
console.log("Making oAuth call...");
}
var options = {
url: 'https://app1pub.smappee.net/dev/v1/oauth2/token',
headers: {
'Host': 'app1pub.smappee.net'
},
form: body
};
request.post(options, function (err, httpResponse, body) {
if (err) {
return console.error('Request failed:', err);
}
if (thisObject.debug) {
console.log('Server responded with:', body);
}
accessToken = JSON.parse(body);
handler(accessToken);
});
} else {
handler(accessToken)
}
}
|
[
"function",
"(",
"handler",
")",
"{",
"if",
"(",
"typeof",
"accessToken",
"==",
"'undefined'",
")",
"{",
"var",
"body",
"=",
"{",
"client_id",
":",
"clientId",
",",
"client_secret",
":",
"clientSecret",
",",
"username",
":",
"username",
",",
"password",
":",
"password",
",",
"grant_type",
":",
"'password'",
"}",
";",
"if",
"(",
"thisObject",
".",
"debug",
")",
"{",
"console",
".",
"log",
"(",
"\"Making oAuth call...\"",
")",
";",
"}",
"var",
"options",
"=",
"{",
"url",
":",
"'https://app1pub.smappee.net/dev/v1/oauth2/token'",
",",
"headers",
":",
"{",
"'Host'",
":",
"'app1pub.smappee.net'",
"}",
",",
"form",
":",
"body",
"}",
";",
"request",
".",
"post",
"(",
"options",
",",
"function",
"(",
"err",
",",
"httpResponse",
",",
"body",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"console",
".",
"error",
"(",
"'Request failed:'",
",",
"err",
")",
";",
"}",
"if",
"(",
"thisObject",
".",
"debug",
")",
"{",
"console",
".",
"log",
"(",
"'Server responded with:'",
",",
"body",
")",
";",
"}",
"accessToken",
"=",
"JSON",
".",
"parse",
"(",
"body",
")",
";",
"handler",
"(",
"accessToken",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"handler",
"(",
"accessToken",
")",
"}",
"}"
] |
HELPER METHODS ++++++++++++++++++++++++++++++++++++++++
|
[
"HELPER",
"METHODS",
"++++++++++++++++++++++++++++++++++++++++"
] |
02de2f6f8fcc1d48a39b1b36d36535ea24435395
|
https://github.com/Adeptive/Smappee-NodeJS/blob/02de2f6f8fcc1d48a39b1b36d36535ea24435395/smappee-api.js#L125-L161
|
|
38,699 |
gabrieleds/node-argv
|
index.js
|
parse
|
function parse (argv, opts, target) {
if ('string' === typeof argv) argv = argv.split(rSplit).filter(ignore);
if (!opts) opts = {};
opts[don] = true;
var parsed = parseArray(argv, opts);
opts[don] = false;
var through = parsed[don].length ? parseArray(parsed[don], opts) : null;
if (!target) target = {};
target.options = parsed;
target.commands = parsed[din];
target.input = argv;
if (through) {
target.through = {
options: through,
commands: through[din]
};
delete through[din];
}
delete parsed[din];
delete parsed[don];
return target;
function ignore (s) {
return s && '' !== s;
}
}
|
javascript
|
function parse (argv, opts, target) {
if ('string' === typeof argv) argv = argv.split(rSplit).filter(ignore);
if (!opts) opts = {};
opts[don] = true;
var parsed = parseArray(argv, opts);
opts[don] = false;
var through = parsed[don].length ? parseArray(parsed[don], opts) : null;
if (!target) target = {};
target.options = parsed;
target.commands = parsed[din];
target.input = argv;
if (through) {
target.through = {
options: through,
commands: through[din]
};
delete through[din];
}
delete parsed[din];
delete parsed[don];
return target;
function ignore (s) {
return s && '' !== s;
}
}
|
[
"function",
"parse",
"(",
"argv",
",",
"opts",
",",
"target",
")",
"{",
"if",
"(",
"'string'",
"===",
"typeof",
"argv",
")",
"argv",
"=",
"argv",
".",
"split",
"(",
"rSplit",
")",
".",
"filter",
"(",
"ignore",
")",
";",
"if",
"(",
"!",
"opts",
")",
"opts",
"=",
"{",
"}",
";",
"opts",
"[",
"don",
"]",
"=",
"true",
";",
"var",
"parsed",
"=",
"parseArray",
"(",
"argv",
",",
"opts",
")",
";",
"opts",
"[",
"don",
"]",
"=",
"false",
";",
"var",
"through",
"=",
"parsed",
"[",
"don",
"]",
".",
"length",
"?",
"parseArray",
"(",
"parsed",
"[",
"don",
"]",
",",
"opts",
")",
":",
"null",
";",
"if",
"(",
"!",
"target",
")",
"target",
"=",
"{",
"}",
";",
"target",
".",
"options",
"=",
"parsed",
";",
"target",
".",
"commands",
"=",
"parsed",
"[",
"din",
"]",
";",
"target",
".",
"input",
"=",
"argv",
";",
"if",
"(",
"through",
")",
"{",
"target",
".",
"through",
"=",
"{",
"options",
":",
"through",
",",
"commands",
":",
"through",
"[",
"din",
"]",
"}",
";",
"delete",
"through",
"[",
"din",
"]",
";",
"}",
"delete",
"parsed",
"[",
"din",
"]",
";",
"delete",
"parsed",
"[",
"don",
"]",
";",
"return",
"target",
";",
"function",
"ignore",
"(",
"s",
")",
"{",
"return",
"s",
"&&",
"''",
"!==",
"s",
";",
"}",
"}"
] |
Parse arguments.
@param {argv} String/Array to parse
@param {opts} Object of properties
@param {target} Object
@return {target|Object}
@api public
|
[
"Parse",
"arguments",
"."
] |
c970e90d0a812fc93435051a89ee1cc9c87a80d5
|
https://github.com/gabrieleds/node-argv/blob/c970e90d0a812fc93435051a89ee1cc9c87a80d5/index.js#L38-L62
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.