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
|
---|---|---|---|---|---|---|---|---|---|---|---|
41,700 | bootprint/customize-write-files | lib/changed.js | compareBuffer | async function compareBuffer (filename, expectedContents) {
try {
const actualContents = await fs.readFile(filename)
return !expectedContents.equals(actualContents)
} catch (err) {
return handleError(err)
}
} | javascript | async function compareBuffer (filename, expectedContents) {
try {
const actualContents = await fs.readFile(filename)
return !expectedContents.equals(actualContents)
} catch (err) {
return handleError(err)
}
} | [
"async",
"function",
"compareBuffer",
"(",
"filename",
",",
"expectedContents",
")",
"{",
"try",
"{",
"const",
"actualContents",
"=",
"await",
"fs",
".",
"readFile",
"(",
"filename",
")",
"return",
"!",
"expectedContents",
".",
"equals",
"(",
"actualContents",
")",
"}",
"catch",
"(",
"err",
")",
"{",
"return",
"handleError",
"(",
"err",
")",
"}",
"}"
]
| Compares a buffer with a file contents. Returns true, if they differ or the file does not exist.
@param {string} filename the file name
@param {Buffer} expectedContents the file contents
@returns {Promise<boolean>|boolean}
@private | [
"Compares",
"a",
"buffer",
"with",
"a",
"file",
"contents",
".",
"Returns",
"true",
"if",
"they",
"differ",
"or",
"the",
"file",
"does",
"not",
"exist",
"."
]
| af77ce78b5196f40ce90670bfdb6e1e7e496a415 | https://github.com/bootprint/customize-write-files/blob/af77ce78b5196f40ce90670bfdb6e1e7e496a415/lib/changed.js#L68-L75 |
41,701 | bootprint/customize-write-files | lib/changed.js | compareStream | async function compareStream (filename, expectedContents) {
try {
const actualStream = fs.createReadStream(filename)
const result = await streamCompare(expectedContents, actualStream, {
abortOnError: true,
compare: (a, b) => {
return Buffer.compare(a.data, b.data) !== 0
}
})
return result
} catch (err) {
return handleError(err)
}
} | javascript | async function compareStream (filename, expectedContents) {
try {
const actualStream = fs.createReadStream(filename)
const result = await streamCompare(expectedContents, actualStream, {
abortOnError: true,
compare: (a, b) => {
return Buffer.compare(a.data, b.data) !== 0
}
})
return result
} catch (err) {
return handleError(err)
}
} | [
"async",
"function",
"compareStream",
"(",
"filename",
",",
"expectedContents",
")",
"{",
"try",
"{",
"const",
"actualStream",
"=",
"fs",
".",
"createReadStream",
"(",
"filename",
")",
"const",
"result",
"=",
"await",
"streamCompare",
"(",
"expectedContents",
",",
"actualStream",
",",
"{",
"abortOnError",
":",
"true",
",",
"compare",
":",
"(",
"a",
",",
"b",
")",
"=>",
"{",
"return",
"Buffer",
".",
"compare",
"(",
"a",
".",
"data",
",",
"b",
".",
"data",
")",
"!==",
"0",
"}",
"}",
")",
"return",
"result",
"}",
"catch",
"(",
"err",
")",
"{",
"return",
"handleError",
"(",
"err",
")",
"}",
"}"
]
| Compares a readable stream with a file contents. Returns true, if they differ or the file does not exist.
@param {string} filename the file name
@param {Stream} expectedContents the file contents
@returns {Promise<boolean>|boolean}
@private | [
"Compares",
"a",
"readable",
"stream",
"with",
"a",
"file",
"contents",
".",
"Returns",
"true",
"if",
"they",
"differ",
"or",
"the",
"file",
"does",
"not",
"exist",
"."
]
| af77ce78b5196f40ce90670bfdb6e1e7e496a415 | https://github.com/bootprint/customize-write-files/blob/af77ce78b5196f40ce90670bfdb6e1e7e496a415/lib/changed.js#L84-L97 |
41,702 | unfoldingWord-dev/node-door43-client | lib/main.js | function(project) {
if(project.slug.toLowerCase() === 'obs'
|| project.slug.toLowerCase() === 'bible-obs'
|| project.slug.toLowerCase() === 'bible'
|| !project.chunks_url) return Promise.resolve();
return request.read(project.chunks_url)
.then(function(response) {
// consume chunk data
if(response.status !== 200) return Promise.reject(response);
let data;
try {
data = JSON.parse(response.data);
} catch(err) {
console.log(project);
return Promise.reject(err);
}
try {
let language_id = library.addSourceLanguage({
slug: 'en',
name: 'English',
direction: 'ltr'
});
// TODO: retrieve the correct versification name(s) from the source language
let versification_id = library.addVersification({
slug: 'en-US',
name: 'American English'
}, language_id);
if (versification_id > 0) {
for (let chunk of data) {
library.addChunkMarker({
chapter: padSlug(chunk.chp, 2),
verse: padSlug(chunk.firstvs, 2)
}, project.slug, versification_id);
}
}
} catch (err) {
return Promise.reject(err);
}
});
} | javascript | function(project) {
if(project.slug.toLowerCase() === 'obs'
|| project.slug.toLowerCase() === 'bible-obs'
|| project.slug.toLowerCase() === 'bible'
|| !project.chunks_url) return Promise.resolve();
return request.read(project.chunks_url)
.then(function(response) {
// consume chunk data
if(response.status !== 200) return Promise.reject(response);
let data;
try {
data = JSON.parse(response.data);
} catch(err) {
console.log(project);
return Promise.reject(err);
}
try {
let language_id = library.addSourceLanguage({
slug: 'en',
name: 'English',
direction: 'ltr'
});
// TODO: retrieve the correct versification name(s) from the source language
let versification_id = library.addVersification({
slug: 'en-US',
name: 'American English'
}, language_id);
if (versification_id > 0) {
for (let chunk of data) {
library.addChunkMarker({
chapter: padSlug(chunk.chp, 2),
verse: padSlug(chunk.firstvs, 2)
}, project.slug, versification_id);
}
}
} catch (err) {
return Promise.reject(err);
}
});
} | [
"function",
"(",
"project",
")",
"{",
"if",
"(",
"project",
".",
"slug",
".",
"toLowerCase",
"(",
")",
"===",
"'obs'",
"||",
"project",
".",
"slug",
".",
"toLowerCase",
"(",
")",
"===",
"'bible-obs'",
"||",
"project",
".",
"slug",
".",
"toLowerCase",
"(",
")",
"===",
"'bible'",
"||",
"!",
"project",
".",
"chunks_url",
")",
"return",
"Promise",
".",
"resolve",
"(",
")",
";",
"return",
"request",
".",
"read",
"(",
"project",
".",
"chunks_url",
")",
".",
"then",
"(",
"function",
"(",
"response",
")",
"{",
"// consume chunk data",
"if",
"(",
"response",
".",
"status",
"!==",
"200",
")",
"return",
"Promise",
".",
"reject",
"(",
"response",
")",
";",
"let",
"data",
";",
"try",
"{",
"data",
"=",
"JSON",
".",
"parse",
"(",
"response",
".",
"data",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"console",
".",
"log",
"(",
"project",
")",
";",
"return",
"Promise",
".",
"reject",
"(",
"err",
")",
";",
"}",
"try",
"{",
"let",
"language_id",
"=",
"library",
".",
"addSourceLanguage",
"(",
"{",
"slug",
":",
"'en'",
",",
"name",
":",
"'English'",
",",
"direction",
":",
"'ltr'",
"}",
")",
";",
"// TODO: retrieve the correct versification name(s) from the source language",
"let",
"versification_id",
"=",
"library",
".",
"addVersification",
"(",
"{",
"slug",
":",
"'en-US'",
",",
"name",
":",
"'American English'",
"}",
",",
"language_id",
")",
";",
"if",
"(",
"versification_id",
">",
"0",
")",
"{",
"for",
"(",
"let",
"chunk",
"of",
"data",
")",
"{",
"library",
".",
"addChunkMarker",
"(",
"{",
"chapter",
":",
"padSlug",
"(",
"chunk",
".",
"chp",
",",
"2",
")",
",",
"verse",
":",
"padSlug",
"(",
"chunk",
".",
"firstvs",
",",
"2",
")",
"}",
",",
"project",
".",
"slug",
",",
"versification_id",
")",
";",
"}",
"}",
"}",
"catch",
"(",
"err",
")",
"{",
"return",
"Promise",
".",
"reject",
"(",
"err",
")",
";",
"}",
"}",
")",
";",
"}"
]
| Downloads the chunks for a project
@param project {{}} | [
"Downloads",
"the",
"chunks",
"for",
"a",
"project"
]
| 18f518368ee89f4baf8943500a1c53ef5efcfb3e | https://github.com/unfoldingWord-dev/node-door43-client/blob/18f518368ee89f4baf8943500a1c53ef5efcfb3e/lib/main.js#L59-L105 |
|
41,703 | unfoldingWord-dev/node-door43-client | lib/main.js | function(project) {
return request.read(project.lang_catalog)
.then(function(response) {
// consume language data
if(response.status !== 200) return Promise.reject(response);
let data;
try {
data = JSON.parse(response.data);
} catch(err) {
return Promise.reject(err);
}
let projects = [];
for(let language of data) {
try {
let language_id = library.addSourceLanguage({
slug: language.language.slug,
name: language.language.name,
direction: language.language.direction
});
project.categories = _.map(project.meta, function (names, slug, index) {
return {name: names[index], slug: slug};
}.bind(this, language.project.meta));
if (project.slug.toLowerCase() !== 'obs') {
project.chunks_url = 'https://api.unfoldingword.org/bible/txt/1/' + project.slug + '/chunks.json';
}
let projectId = library.addProject({
slug: project.slug,
name: language.project.name,
desc: language.project.desc,
icon: project.icon,
sort: project.sort,
chunks_url: project.chunks_url,
categories: project.categories,
}, language_id);
projects.push({
id: projectId,
chunks_url: project.chunks_url,
slug: project.slug,
resourceUrl: language.res_catalog,
source_language_slug: language.language.slug,
source_language_id: language_id
});
} catch (err) {
return Promise.reject(err);
}
}
// TRICKY: we just flipped the data hierarchy from project->lang to lang->project for future compatibility
return projects;
});
} | javascript | function(project) {
return request.read(project.lang_catalog)
.then(function(response) {
// consume language data
if(response.status !== 200) return Promise.reject(response);
let data;
try {
data = JSON.parse(response.data);
} catch(err) {
return Promise.reject(err);
}
let projects = [];
for(let language of data) {
try {
let language_id = library.addSourceLanguage({
slug: language.language.slug,
name: language.language.name,
direction: language.language.direction
});
project.categories = _.map(project.meta, function (names, slug, index) {
return {name: names[index], slug: slug};
}.bind(this, language.project.meta));
if (project.slug.toLowerCase() !== 'obs') {
project.chunks_url = 'https://api.unfoldingword.org/bible/txt/1/' + project.slug + '/chunks.json';
}
let projectId = library.addProject({
slug: project.slug,
name: language.project.name,
desc: language.project.desc,
icon: project.icon,
sort: project.sort,
chunks_url: project.chunks_url,
categories: project.categories,
}, language_id);
projects.push({
id: projectId,
chunks_url: project.chunks_url,
slug: project.slug,
resourceUrl: language.res_catalog,
source_language_slug: language.language.slug,
source_language_id: language_id
});
} catch (err) {
return Promise.reject(err);
}
}
// TRICKY: we just flipped the data hierarchy from project->lang to lang->project for future compatibility
return projects;
});
} | [
"function",
"(",
"project",
")",
"{",
"return",
"request",
".",
"read",
"(",
"project",
".",
"lang_catalog",
")",
".",
"then",
"(",
"function",
"(",
"response",
")",
"{",
"// consume language data",
"if",
"(",
"response",
".",
"status",
"!==",
"200",
")",
"return",
"Promise",
".",
"reject",
"(",
"response",
")",
";",
"let",
"data",
";",
"try",
"{",
"data",
"=",
"JSON",
".",
"parse",
"(",
"response",
".",
"data",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"return",
"Promise",
".",
"reject",
"(",
"err",
")",
";",
"}",
"let",
"projects",
"=",
"[",
"]",
";",
"for",
"(",
"let",
"language",
"of",
"data",
")",
"{",
"try",
"{",
"let",
"language_id",
"=",
"library",
".",
"addSourceLanguage",
"(",
"{",
"slug",
":",
"language",
".",
"language",
".",
"slug",
",",
"name",
":",
"language",
".",
"language",
".",
"name",
",",
"direction",
":",
"language",
".",
"language",
".",
"direction",
"}",
")",
";",
"project",
".",
"categories",
"=",
"_",
".",
"map",
"(",
"project",
".",
"meta",
",",
"function",
"(",
"names",
",",
"slug",
",",
"index",
")",
"{",
"return",
"{",
"name",
":",
"names",
"[",
"index",
"]",
",",
"slug",
":",
"slug",
"}",
";",
"}",
".",
"bind",
"(",
"this",
",",
"language",
".",
"project",
".",
"meta",
")",
")",
";",
"if",
"(",
"project",
".",
"slug",
".",
"toLowerCase",
"(",
")",
"!==",
"'obs'",
")",
"{",
"project",
".",
"chunks_url",
"=",
"'https://api.unfoldingword.org/bible/txt/1/'",
"+",
"project",
".",
"slug",
"+",
"'/chunks.json'",
";",
"}",
"let",
"projectId",
"=",
"library",
".",
"addProject",
"(",
"{",
"slug",
":",
"project",
".",
"slug",
",",
"name",
":",
"language",
".",
"project",
".",
"name",
",",
"desc",
":",
"language",
".",
"project",
".",
"desc",
",",
"icon",
":",
"project",
".",
"icon",
",",
"sort",
":",
"project",
".",
"sort",
",",
"chunks_url",
":",
"project",
".",
"chunks_url",
",",
"categories",
":",
"project",
".",
"categories",
",",
"}",
",",
"language_id",
")",
";",
"projects",
".",
"push",
"(",
"{",
"id",
":",
"projectId",
",",
"chunks_url",
":",
"project",
".",
"chunks_url",
",",
"slug",
":",
"project",
".",
"slug",
",",
"resourceUrl",
":",
"language",
".",
"res_catalog",
",",
"source_language_slug",
":",
"language",
".",
"language",
".",
"slug",
",",
"source_language_id",
":",
"language_id",
"}",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"return",
"Promise",
".",
"reject",
"(",
"err",
")",
";",
"}",
"}",
"// TRICKY: we just flipped the data hierarchy from project->lang to lang->project for future compatibility",
"return",
"projects",
";",
"}",
")",
";",
"}"
]
| Downloads the source languages for a project
@param project {{}}
@returns {Promise} | [
"Downloads",
"the",
"source",
"languages",
"for",
"a",
"project"
]
| 18f518368ee89f4baf8943500a1c53ef5efcfb3e | https://github.com/unfoldingWord-dev/node-door43-client/blob/18f518368ee89f4baf8943500a1c53ef5efcfb3e/lib/main.js#L112-L168 |
|
41,704 | unfoldingWord-dev/node-door43-client | lib/main.js | function() {
library.addCatalog({
slug: 'langnames',
url: 'https://td.unfoldingword.org/exports/langnames.json',
modified_at: 0
});
library.addCatalog({
slug: 'new-language-questions',
url: 'https://td.unfoldingword.org/api/questionnaire/',
modified_at: 0
});
library.addCatalog({
slug: 'temp-langnames',
url: 'https://td.unfoldingword.org/api/templanguages/',
modified_at: 0
});
// TRICKY: this catalog should always be indexed after langnames and temp-langnames otherwise the linking will fail!
library.addCatalog({
slug: 'approved-temp-langnames',
url: 'https://td.unfoldingword.org/api/templanguages/assignment/changed/',
modified_at: 0
});
return Promise.resolve();
} | javascript | function() {
library.addCatalog({
slug: 'langnames',
url: 'https://td.unfoldingword.org/exports/langnames.json',
modified_at: 0
});
library.addCatalog({
slug: 'new-language-questions',
url: 'https://td.unfoldingword.org/api/questionnaire/',
modified_at: 0
});
library.addCatalog({
slug: 'temp-langnames',
url: 'https://td.unfoldingword.org/api/templanguages/',
modified_at: 0
});
// TRICKY: this catalog should always be indexed after langnames and temp-langnames otherwise the linking will fail!
library.addCatalog({
slug: 'approved-temp-langnames',
url: 'https://td.unfoldingword.org/api/templanguages/assignment/changed/',
modified_at: 0
});
return Promise.resolve();
} | [
"function",
"(",
")",
"{",
"library",
".",
"addCatalog",
"(",
"{",
"slug",
":",
"'langnames'",
",",
"url",
":",
"'https://td.unfoldingword.org/exports/langnames.json'",
",",
"modified_at",
":",
"0",
"}",
")",
";",
"library",
".",
"addCatalog",
"(",
"{",
"slug",
":",
"'new-language-questions'",
",",
"url",
":",
"'https://td.unfoldingword.org/api/questionnaire/'",
",",
"modified_at",
":",
"0",
"}",
")",
";",
"library",
".",
"addCatalog",
"(",
"{",
"slug",
":",
"'temp-langnames'",
",",
"url",
":",
"'https://td.unfoldingword.org/api/templanguages/'",
",",
"modified_at",
":",
"0",
"}",
")",
";",
"// TRICKY: this catalog should always be indexed after langnames and temp-langnames otherwise the linking will fail!",
"library",
".",
"addCatalog",
"(",
"{",
"slug",
":",
"'approved-temp-langnames'",
",",
"url",
":",
"'https://td.unfoldingword.org/api/templanguages/assignment/changed/'",
",",
"modified_at",
":",
"0",
"}",
")",
";",
"return",
"Promise",
".",
"resolve",
"(",
")",
";",
"}"
]
| Injects the global catalogs since they are missing from api v2.
@returns {Promise} | [
"Injects",
"the",
"global",
"catalogs",
"since",
"they",
"are",
"missing",
"from",
"api",
"v2",
"."
]
| 18f518368ee89f4baf8943500a1c53ef5efcfb3e | https://github.com/unfoldingWord-dev/node-door43-client/blob/18f518368ee89f4baf8943500a1c53ef5efcfb3e/lib/main.js#L300-L323 |
|
41,705 | unfoldingWord-dev/node-door43-client | lib/main.js | function(url, onProgress) {
onProgress = onProgress || function(){};
return injectGlobalCatalogs()
.then(function() {
library.commit();
return request.read(url);
})
.then(function(response) {
// disable saves for better performance
library.autosave(false);
// index projects and source languages
if (response.status !== 200) return Promise.reject(response);
let projects;
try {
projects = JSON.parse(response.data);
} catch (err) {
return Promise.reject(err);
}
return promiseUtils.chain(downloadSourceLanguages, function(err, data) {
if(err instanceof Error) return Promise.reject(err);
console.log(err);
return false;
}, {compact: true, onProgress: onProgress.bind(null, 'projects')})(projects);
})
.then(function(projects) {
// index resources
library.commit();
if(!projects) return Promise.reject('No projects found');
let list = [];
for(let project of projects) {
for(let localizedProject of project) {
list.push({
id: localizedProject.id,
slug: localizedProject.slug,
source_language_id: localizedProject.source_language_id,
resourceUrl: localizedProject.resourceUrl
});
}
}
return promiseUtils.chain(downloadSourceResources, function(err, data) {
if(err instanceof Error) return Promise.reject(err);
console.log(err);
return false;
}, {compact: true, onProgress: onProgress.bind(null, 'resources')})(list);
}).then(function() {
// keep the promise args clean
library.commit();
library.autosave(true);
return Promise.resolve();
}).catch(function(err) {
library.autosave(true);
return Promise.reject(err);
});
} | javascript | function(url, onProgress) {
onProgress = onProgress || function(){};
return injectGlobalCatalogs()
.then(function() {
library.commit();
return request.read(url);
})
.then(function(response) {
// disable saves for better performance
library.autosave(false);
// index projects and source languages
if (response.status !== 200) return Promise.reject(response);
let projects;
try {
projects = JSON.parse(response.data);
} catch (err) {
return Promise.reject(err);
}
return promiseUtils.chain(downloadSourceLanguages, function(err, data) {
if(err instanceof Error) return Promise.reject(err);
console.log(err);
return false;
}, {compact: true, onProgress: onProgress.bind(null, 'projects')})(projects);
})
.then(function(projects) {
// index resources
library.commit();
if(!projects) return Promise.reject('No projects found');
let list = [];
for(let project of projects) {
for(let localizedProject of project) {
list.push({
id: localizedProject.id,
slug: localizedProject.slug,
source_language_id: localizedProject.source_language_id,
resourceUrl: localizedProject.resourceUrl
});
}
}
return promiseUtils.chain(downloadSourceResources, function(err, data) {
if(err instanceof Error) return Promise.reject(err);
console.log(err);
return false;
}, {compact: true, onProgress: onProgress.bind(null, 'resources')})(list);
}).then(function() {
// keep the promise args clean
library.commit();
library.autosave(true);
return Promise.resolve();
}).catch(function(err) {
library.autosave(true);
return Promise.reject(err);
});
} | [
"function",
"(",
"url",
",",
"onProgress",
")",
"{",
"onProgress",
"=",
"onProgress",
"||",
"function",
"(",
")",
"{",
"}",
";",
"return",
"injectGlobalCatalogs",
"(",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"library",
".",
"commit",
"(",
")",
";",
"return",
"request",
".",
"read",
"(",
"url",
")",
";",
"}",
")",
".",
"then",
"(",
"function",
"(",
"response",
")",
"{",
"// disable saves for better performance",
"library",
".",
"autosave",
"(",
"false",
")",
";",
"// index projects and source languages",
"if",
"(",
"response",
".",
"status",
"!==",
"200",
")",
"return",
"Promise",
".",
"reject",
"(",
"response",
")",
";",
"let",
"projects",
";",
"try",
"{",
"projects",
"=",
"JSON",
".",
"parse",
"(",
"response",
".",
"data",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"return",
"Promise",
".",
"reject",
"(",
"err",
")",
";",
"}",
"return",
"promiseUtils",
".",
"chain",
"(",
"downloadSourceLanguages",
",",
"function",
"(",
"err",
",",
"data",
")",
"{",
"if",
"(",
"err",
"instanceof",
"Error",
")",
"return",
"Promise",
".",
"reject",
"(",
"err",
")",
";",
"console",
".",
"log",
"(",
"err",
")",
";",
"return",
"false",
";",
"}",
",",
"{",
"compact",
":",
"true",
",",
"onProgress",
":",
"onProgress",
".",
"bind",
"(",
"null",
",",
"'projects'",
")",
"}",
")",
"(",
"projects",
")",
";",
"}",
")",
".",
"then",
"(",
"function",
"(",
"projects",
")",
"{",
"// index resources",
"library",
".",
"commit",
"(",
")",
";",
"if",
"(",
"!",
"projects",
")",
"return",
"Promise",
".",
"reject",
"(",
"'No projects found'",
")",
";",
"let",
"list",
"=",
"[",
"]",
";",
"for",
"(",
"let",
"project",
"of",
"projects",
")",
"{",
"for",
"(",
"let",
"localizedProject",
"of",
"project",
")",
"{",
"list",
".",
"push",
"(",
"{",
"id",
":",
"localizedProject",
".",
"id",
",",
"slug",
":",
"localizedProject",
".",
"slug",
",",
"source_language_id",
":",
"localizedProject",
".",
"source_language_id",
",",
"resourceUrl",
":",
"localizedProject",
".",
"resourceUrl",
"}",
")",
";",
"}",
"}",
"return",
"promiseUtils",
".",
"chain",
"(",
"downloadSourceResources",
",",
"function",
"(",
"err",
",",
"data",
")",
"{",
"if",
"(",
"err",
"instanceof",
"Error",
")",
"return",
"Promise",
".",
"reject",
"(",
"err",
")",
";",
"console",
".",
"log",
"(",
"err",
")",
";",
"return",
"false",
";",
"}",
",",
"{",
"compact",
":",
"true",
",",
"onProgress",
":",
"onProgress",
".",
"bind",
"(",
"null",
",",
"'resources'",
")",
"}",
")",
"(",
"list",
")",
";",
"}",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"// keep the promise args clean",
"library",
".",
"commit",
"(",
")",
";",
"library",
".",
"autosave",
"(",
"true",
")",
";",
"return",
"Promise",
".",
"resolve",
"(",
")",
";",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"err",
")",
"{",
"library",
".",
"autosave",
"(",
"true",
")",
";",
"return",
"Promise",
".",
"reject",
"(",
"err",
")",
";",
"}",
")",
";",
"}"
]
| Indexes the languages, projects, and resources from the api
@param url {string} the entry resource api catalog
@param onProgress {function} an optional progress listener. This should receive progress id, total, completed
@returns {Promise} | [
"Indexes",
"the",
"languages",
"projects",
"and",
"resources",
"from",
"the",
"api"
]
| 18f518368ee89f4baf8943500a1c53ef5efcfb3e | https://github.com/unfoldingWord-dev/node-door43-client/blob/18f518368ee89f4baf8943500a1c53ef5efcfb3e/lib/main.js#L346-L402 |
|
41,706 | unfoldingWord-dev/node-door43-client | lib/main.js | function(onProgress) {
onProgress = onProgress || function() {};
let projects = library.public_getters.getProjects();
library.autosave(false);
return promiseUtils.chain(downloadChunks, function(err, data) {
if(err instanceof Error) return Promise.reject(err);
console.log(err);
return false;
}, {compact: true, onProgress: onProgress.bind(null, 'chunks')})(projects)
.then(function() {
library.commit();
library.autosave(true);
return Promise.resolve();
})
.catch(function(err) {
library.autosave(true);
return Promise.reject(err);
});
} | javascript | function(onProgress) {
onProgress = onProgress || function() {};
let projects = library.public_getters.getProjects();
library.autosave(false);
return promiseUtils.chain(downloadChunks, function(err, data) {
if(err instanceof Error) return Promise.reject(err);
console.log(err);
return false;
}, {compact: true, onProgress: onProgress.bind(null, 'chunks')})(projects)
.then(function() {
library.commit();
library.autosave(true);
return Promise.resolve();
})
.catch(function(err) {
library.autosave(true);
return Promise.reject(err);
});
} | [
"function",
"(",
"onProgress",
")",
"{",
"onProgress",
"=",
"onProgress",
"||",
"function",
"(",
")",
"{",
"}",
";",
"let",
"projects",
"=",
"library",
".",
"public_getters",
".",
"getProjects",
"(",
")",
";",
"library",
".",
"autosave",
"(",
"false",
")",
";",
"return",
"promiseUtils",
".",
"chain",
"(",
"downloadChunks",
",",
"function",
"(",
"err",
",",
"data",
")",
"{",
"if",
"(",
"err",
"instanceof",
"Error",
")",
"return",
"Promise",
".",
"reject",
"(",
"err",
")",
";",
"console",
".",
"log",
"(",
"err",
")",
";",
"return",
"false",
";",
"}",
",",
"{",
"compact",
":",
"true",
",",
"onProgress",
":",
"onProgress",
".",
"bind",
"(",
"null",
",",
"'chunks'",
")",
"}",
")",
"(",
"projects",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"library",
".",
"commit",
"(",
")",
";",
"library",
".",
"autosave",
"(",
"true",
")",
";",
"return",
"Promise",
".",
"resolve",
"(",
")",
";",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"err",
")",
"{",
"library",
".",
"autosave",
"(",
"true",
")",
";",
"return",
"Promise",
".",
"reject",
"(",
"err",
")",
";",
"}",
")",
";",
"}"
]
| Downloads the chunks for all projects
@param onProgress
@returns {Promise.<>} | [
"Downloads",
"the",
"chunks",
"for",
"all",
"projects"
]
| 18f518368ee89f4baf8943500a1c53ef5efcfb3e | https://github.com/unfoldingWord-dev/node-door43-client/blob/18f518368ee89f4baf8943500a1c53ef5efcfb3e/lib/main.js#L409-L427 |
|
41,707 | unfoldingWord-dev/node-door43-client | lib/main.js | function(onProgress) {
onProgress = onProgress || function() {};
library.autosave(false);
let modules_urls = [
'https://api.unfoldingword.org/ta/txt/1/en/audio_2.json',
'https://api.unfoldingword.org/ta/txt/1/en/checking_1.json',
'https://api.unfoldingword.org/ta/txt/1/en/checking_2.json',
'https://api.unfoldingword.org/ta/txt/1/en/gateway_3.json',
'https://api.unfoldingword.org/ta/txt/1/en/intro_1.json',
'https://api.unfoldingword.org/ta/txt/1/en/process_1.json',
'https://api.unfoldingword.org/ta/txt/1/en/translate_1.json',
'https://api.unfoldingword.org/ta/txt/1/en/translate_2.json'
];
return promiseUtils.chain(downloadTA, function(err, data) {
if(err instanceof Error) return Promise.reject(err);
console.log(err);
return false;
}, {compact: true, onProgress: onProgress.bind(null, 'ta')})(modules_urls)
.then(function() {
library.commit();
library.autosave(true);
return Promise.resolve();
})
.catch(function(err) {
library.autosave(true);
return Promise.reject(err);
});
} | javascript | function(onProgress) {
onProgress = onProgress || function() {};
library.autosave(false);
let modules_urls = [
'https://api.unfoldingword.org/ta/txt/1/en/audio_2.json',
'https://api.unfoldingword.org/ta/txt/1/en/checking_1.json',
'https://api.unfoldingword.org/ta/txt/1/en/checking_2.json',
'https://api.unfoldingword.org/ta/txt/1/en/gateway_3.json',
'https://api.unfoldingword.org/ta/txt/1/en/intro_1.json',
'https://api.unfoldingword.org/ta/txt/1/en/process_1.json',
'https://api.unfoldingword.org/ta/txt/1/en/translate_1.json',
'https://api.unfoldingword.org/ta/txt/1/en/translate_2.json'
];
return promiseUtils.chain(downloadTA, function(err, data) {
if(err instanceof Error) return Promise.reject(err);
console.log(err);
return false;
}, {compact: true, onProgress: onProgress.bind(null, 'ta')})(modules_urls)
.then(function() {
library.commit();
library.autosave(true);
return Promise.resolve();
})
.catch(function(err) {
library.autosave(true);
return Promise.reject(err);
});
} | [
"function",
"(",
"onProgress",
")",
"{",
"onProgress",
"=",
"onProgress",
"||",
"function",
"(",
")",
"{",
"}",
";",
"library",
".",
"autosave",
"(",
"false",
")",
";",
"let",
"modules_urls",
"=",
"[",
"'https://api.unfoldingword.org/ta/txt/1/en/audio_2.json'",
",",
"'https://api.unfoldingword.org/ta/txt/1/en/checking_1.json'",
",",
"'https://api.unfoldingword.org/ta/txt/1/en/checking_2.json'",
",",
"'https://api.unfoldingword.org/ta/txt/1/en/gateway_3.json'",
",",
"'https://api.unfoldingword.org/ta/txt/1/en/intro_1.json'",
",",
"'https://api.unfoldingword.org/ta/txt/1/en/process_1.json'",
",",
"'https://api.unfoldingword.org/ta/txt/1/en/translate_1.json'",
",",
"'https://api.unfoldingword.org/ta/txt/1/en/translate_2.json'",
"]",
";",
"return",
"promiseUtils",
".",
"chain",
"(",
"downloadTA",
",",
"function",
"(",
"err",
",",
"data",
")",
"{",
"if",
"(",
"err",
"instanceof",
"Error",
")",
"return",
"Promise",
".",
"reject",
"(",
"err",
")",
";",
"console",
".",
"log",
"(",
"err",
")",
";",
"return",
"false",
";",
"}",
",",
"{",
"compact",
":",
"true",
",",
"onProgress",
":",
"onProgress",
".",
"bind",
"(",
"null",
",",
"'ta'",
")",
"}",
")",
"(",
"modules_urls",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"library",
".",
"commit",
"(",
")",
";",
"library",
".",
"autosave",
"(",
"true",
")",
";",
"return",
"Promise",
".",
"resolve",
"(",
")",
";",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"err",
")",
"{",
"library",
".",
"autosave",
"(",
"true",
")",
";",
"return",
"Promise",
".",
"reject",
"(",
"err",
")",
";",
"}",
")",
";",
"}"
]
| Downloads the tA projects
@param onProgress
@returns {Promise.<>} | [
"Downloads",
"the",
"tA",
"projects"
]
| 18f518368ee89f4baf8943500a1c53ef5efcfb3e | https://github.com/unfoldingWord-dev/node-door43-client/blob/18f518368ee89f4baf8943500a1c53ef5efcfb3e/lib/main.js#L434-L461 |
|
41,708 | unfoldingWord-dev/node-door43-client | lib/main.js | function(onProgress) {
const errorHandler = function(err) {
if(err instanceof Error) {
return Promise.reject(err);
} else {
return Promise.resolve();
}
};
// TRICKY: the language catalogs are dependent so we must run them in order
return updateCatalog('langnames', onProgress)
.catch(errorHandler)
.then(function(response) {
return updateCatalog('temp-langnames', onProgress);
})
.catch(errorHandler)
.then(function(response) {
return updateCatalog('approved-temp-langnames', onProgress);
})
.catch(errorHandler)
.then(function(response) {
return updateCatalog('new-language-questions', onProgress)
})
.catch(errorHandler)
.then(function() {
return Promise.resolve();
});
} | javascript | function(onProgress) {
const errorHandler = function(err) {
if(err instanceof Error) {
return Promise.reject(err);
} else {
return Promise.resolve();
}
};
// TRICKY: the language catalogs are dependent so we must run them in order
return updateCatalog('langnames', onProgress)
.catch(errorHandler)
.then(function(response) {
return updateCatalog('temp-langnames', onProgress);
})
.catch(errorHandler)
.then(function(response) {
return updateCatalog('approved-temp-langnames', onProgress);
})
.catch(errorHandler)
.then(function(response) {
return updateCatalog('new-language-questions', onProgress)
})
.catch(errorHandler)
.then(function() {
return Promise.resolve();
});
} | [
"function",
"(",
"onProgress",
")",
"{",
"const",
"errorHandler",
"=",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
"instanceof",
"Error",
")",
"{",
"return",
"Promise",
".",
"reject",
"(",
"err",
")",
";",
"}",
"else",
"{",
"return",
"Promise",
".",
"resolve",
"(",
")",
";",
"}",
"}",
";",
"// TRICKY: the language catalogs are dependent so we must run them in order",
"return",
"updateCatalog",
"(",
"'langnames'",
",",
"onProgress",
")",
".",
"catch",
"(",
"errorHandler",
")",
".",
"then",
"(",
"function",
"(",
"response",
")",
"{",
"return",
"updateCatalog",
"(",
"'temp-langnames'",
",",
"onProgress",
")",
";",
"}",
")",
".",
"catch",
"(",
"errorHandler",
")",
".",
"then",
"(",
"function",
"(",
"response",
")",
"{",
"return",
"updateCatalog",
"(",
"'approved-temp-langnames'",
",",
"onProgress",
")",
";",
"}",
")",
".",
"catch",
"(",
"errorHandler",
")",
".",
"then",
"(",
"function",
"(",
"response",
")",
"{",
"return",
"updateCatalog",
"(",
"'new-language-questions'",
",",
"onProgress",
")",
"}",
")",
".",
"catch",
"(",
"errorHandler",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"return",
"Promise",
".",
"resolve",
"(",
")",
";",
"}",
")",
";",
"}"
]
| Updates all of the global catalogs
@param onProgress
@returns {Promise.<>} | [
"Updates",
"all",
"of",
"the",
"global",
"catalogs"
]
| 18f518368ee89f4baf8943500a1c53ef5efcfb3e | https://github.com/unfoldingWord-dev/node-door43-client/blob/18f518368ee89f4baf8943500a1c53ef5efcfb3e/lib/main.js#L521-L548 |
|
41,709 | unfoldingWord-dev/node-door43-client | lib/main.js | function(data, onProgress) {
onProgress = onProgress || function() {};
return new Promise(function(resolve, reject) {
try {
let languages = JSON.parse(data);
_.forEach(languages, function (language, index) {
language.slug = language.lc;
language.name = language.ln;
language.anglicized_name = language.ang;
language.direction = language.ld;
language.region = language.lr;
language.country_codes = language.cc || [];
language.aliases = language.alt || [];
language.is_gateway_language = language.gl ? language.gl : false;
try {
library.addTargetLanguage(language);
} catch (err) {
console.error('Failed to add target language', language);
reject(err);
return;
}
onProgress(languages.length, index + 1);
});
resolve();
} catch(err) {
reject(err);
}
});
} | javascript | function(data, onProgress) {
onProgress = onProgress || function() {};
return new Promise(function(resolve, reject) {
try {
let languages = JSON.parse(data);
_.forEach(languages, function (language, index) {
language.slug = language.lc;
language.name = language.ln;
language.anglicized_name = language.ang;
language.direction = language.ld;
language.region = language.lr;
language.country_codes = language.cc || [];
language.aliases = language.alt || [];
language.is_gateway_language = language.gl ? language.gl : false;
try {
library.addTargetLanguage(language);
} catch (err) {
console.error('Failed to add target language', language);
reject(err);
return;
}
onProgress(languages.length, index + 1);
});
resolve();
} catch(err) {
reject(err);
}
});
} | [
"function",
"(",
"data",
",",
"onProgress",
")",
"{",
"onProgress",
"=",
"onProgress",
"||",
"function",
"(",
")",
"{",
"}",
";",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"try",
"{",
"let",
"languages",
"=",
"JSON",
".",
"parse",
"(",
"data",
")",
";",
"_",
".",
"forEach",
"(",
"languages",
",",
"function",
"(",
"language",
",",
"index",
")",
"{",
"language",
".",
"slug",
"=",
"language",
".",
"lc",
";",
"language",
".",
"name",
"=",
"language",
".",
"ln",
";",
"language",
".",
"anglicized_name",
"=",
"language",
".",
"ang",
";",
"language",
".",
"direction",
"=",
"language",
".",
"ld",
";",
"language",
".",
"region",
"=",
"language",
".",
"lr",
";",
"language",
".",
"country_codes",
"=",
"language",
".",
"cc",
"||",
"[",
"]",
";",
"language",
".",
"aliases",
"=",
"language",
".",
"alt",
"||",
"[",
"]",
";",
"language",
".",
"is_gateway_language",
"=",
"language",
".",
"gl",
"?",
"language",
".",
"gl",
":",
"false",
";",
"try",
"{",
"library",
".",
"addTargetLanguage",
"(",
"language",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"'Failed to add target language'",
",",
"language",
")",
";",
"reject",
"(",
"err",
")",
";",
"return",
";",
"}",
"onProgress",
"(",
"languages",
".",
"length",
",",
"index",
"+",
"1",
")",
";",
"}",
")",
";",
"resolve",
"(",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"reject",
"(",
"err",
")",
";",
"}",
"}",
")",
";",
"}"
]
| Parses the target language catalog and indexes it.
@param data {string}
@param onProgress {function} an optional progress listener. This should receive progress id, total, completed
@returns {Promise} | [
"Parses",
"the",
"target",
"language",
"catalog",
"and",
"indexes",
"it",
"."
]
| 18f518368ee89f4baf8943500a1c53ef5efcfb3e | https://github.com/unfoldingWord-dev/node-door43-client/blob/18f518368ee89f4baf8943500a1c53ef5efcfb3e/lib/main.js#L622-L651 |
|
41,710 | unfoldingWord-dev/node-door43-client | lib/main.js | function(data, onProgress) {
onProgress = onProgress || function() {};
return new Promise(function(resolve, reject) {
try {
let obj = JSON.parse(data);
_.forEach(obj.languages, function (questionnaire, index) {
// format
questionnaire.language_slug = questionnaire.slug;
questionnaire.language_name = questionnaire.name;
questionnaire.td_id = questionnaire.questionnaire_id;
questionnaire.language_direction = questionnaire.dir.toLowerCase() === 'rtl' ? 'rtl' : 'ltr';
try {
let id = library.addQuestionnaire(questionnaire);
if (id > 0) {
// add questions
_.forEach(questionnaire.questions, function (question, n) {
// format question
question.is_required = question.required ? 1 : 0;
question.depends_on = question.depends_on === null ? -1 : question.depends_on;
question.td_id = question.id;
try {
library.addQuestion(question, id);
} catch (err) {
console.error('Failed to add question', question);
reject(err);
return;
}
// broadcast itemized progress if there is only one questionnaire
if (obj.languages.length == 1) {
onProgress(questionnaire.questions.length, n + 1);
}
});
} else {
console.error('Failed to add questionnaire', questionnaire);
}
} catch (err) {
console.error('Failed to add questionnaire', questionnaire);
reject(err);
return;
}
// broadcast overall progress if there are multiple questionnaires.
if (obj.languages.length > 1) {
onProgress(obj.languages.length, index + 1);
}
});
resolve();
} catch (err) {
reject(err);
}
});
} | javascript | function(data, onProgress) {
onProgress = onProgress || function() {};
return new Promise(function(resolve, reject) {
try {
let obj = JSON.parse(data);
_.forEach(obj.languages, function (questionnaire, index) {
// format
questionnaire.language_slug = questionnaire.slug;
questionnaire.language_name = questionnaire.name;
questionnaire.td_id = questionnaire.questionnaire_id;
questionnaire.language_direction = questionnaire.dir.toLowerCase() === 'rtl' ? 'rtl' : 'ltr';
try {
let id = library.addQuestionnaire(questionnaire);
if (id > 0) {
// add questions
_.forEach(questionnaire.questions, function (question, n) {
// format question
question.is_required = question.required ? 1 : 0;
question.depends_on = question.depends_on === null ? -1 : question.depends_on;
question.td_id = question.id;
try {
library.addQuestion(question, id);
} catch (err) {
console.error('Failed to add question', question);
reject(err);
return;
}
// broadcast itemized progress if there is only one questionnaire
if (obj.languages.length == 1) {
onProgress(questionnaire.questions.length, n + 1);
}
});
} else {
console.error('Failed to add questionnaire', questionnaire);
}
} catch (err) {
console.error('Failed to add questionnaire', questionnaire);
reject(err);
return;
}
// broadcast overall progress if there are multiple questionnaires.
if (obj.languages.length > 1) {
onProgress(obj.languages.length, index + 1);
}
});
resolve();
} catch (err) {
reject(err);
}
});
} | [
"function",
"(",
"data",
",",
"onProgress",
")",
"{",
"onProgress",
"=",
"onProgress",
"||",
"function",
"(",
")",
"{",
"}",
";",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"try",
"{",
"let",
"obj",
"=",
"JSON",
".",
"parse",
"(",
"data",
")",
";",
"_",
".",
"forEach",
"(",
"obj",
".",
"languages",
",",
"function",
"(",
"questionnaire",
",",
"index",
")",
"{",
"// format",
"questionnaire",
".",
"language_slug",
"=",
"questionnaire",
".",
"slug",
";",
"questionnaire",
".",
"language_name",
"=",
"questionnaire",
".",
"name",
";",
"questionnaire",
".",
"td_id",
"=",
"questionnaire",
".",
"questionnaire_id",
";",
"questionnaire",
".",
"language_direction",
"=",
"questionnaire",
".",
"dir",
".",
"toLowerCase",
"(",
")",
"===",
"'rtl'",
"?",
"'rtl'",
":",
"'ltr'",
";",
"try",
"{",
"let",
"id",
"=",
"library",
".",
"addQuestionnaire",
"(",
"questionnaire",
")",
";",
"if",
"(",
"id",
">",
"0",
")",
"{",
"// add questions",
"_",
".",
"forEach",
"(",
"questionnaire",
".",
"questions",
",",
"function",
"(",
"question",
",",
"n",
")",
"{",
"// format question",
"question",
".",
"is_required",
"=",
"question",
".",
"required",
"?",
"1",
":",
"0",
";",
"question",
".",
"depends_on",
"=",
"question",
".",
"depends_on",
"===",
"null",
"?",
"-",
"1",
":",
"question",
".",
"depends_on",
";",
"question",
".",
"td_id",
"=",
"question",
".",
"id",
";",
"try",
"{",
"library",
".",
"addQuestion",
"(",
"question",
",",
"id",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"'Failed to add question'",
",",
"question",
")",
";",
"reject",
"(",
"err",
")",
";",
"return",
";",
"}",
"// broadcast itemized progress if there is only one questionnaire",
"if",
"(",
"obj",
".",
"languages",
".",
"length",
"==",
"1",
")",
"{",
"onProgress",
"(",
"questionnaire",
".",
"questions",
".",
"length",
",",
"n",
"+",
"1",
")",
";",
"}",
"}",
")",
";",
"}",
"else",
"{",
"console",
".",
"error",
"(",
"'Failed to add questionnaire'",
",",
"questionnaire",
")",
";",
"}",
"}",
"catch",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"'Failed to add questionnaire'",
",",
"questionnaire",
")",
";",
"reject",
"(",
"err",
")",
";",
"return",
";",
"}",
"// broadcast overall progress if there are multiple questionnaires.",
"if",
"(",
"obj",
".",
"languages",
".",
"length",
">",
"1",
")",
"{",
"onProgress",
"(",
"obj",
".",
"languages",
".",
"length",
",",
"index",
"+",
"1",
")",
";",
"}",
"}",
")",
";",
"resolve",
"(",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"reject",
"(",
"err",
")",
";",
"}",
"}",
")",
";",
"}"
]
| Parses the new language questions catalog and indexes it.
@param data {string}
@param onProgress {function} an optional progress listener. This should receive progress id, total, completed
@returns {Promise} | [
"Parses",
"the",
"new",
"language",
"questions",
"catalog",
"and",
"indexes",
"it",
"."
]
| 18f518368ee89f4baf8943500a1c53ef5efcfb3e | https://github.com/unfoldingWord-dev/node-door43-client/blob/18f518368ee89f4baf8943500a1c53ef5efcfb3e/lib/main.js#L660-L712 |
|
41,711 | unfoldingWord-dev/node-door43-client | lib/main.js | function(formats) {
for(let format of formats) {
// TODO: rather than hard coding the mime type use library.spec.base_mime_type
if(format.mime_type.match(/application\/tsrc\+.+/)) {
return format;
}
}
return null;
} | javascript | function(formats) {
for(let format of formats) {
// TODO: rather than hard coding the mime type use library.spec.base_mime_type
if(format.mime_type.match(/application\/tsrc\+.+/)) {
return format;
}
}
return null;
} | [
"function",
"(",
"formats",
")",
"{",
"for",
"(",
"let",
"format",
"of",
"formats",
")",
"{",
"// TODO: rather than hard coding the mime type use library.spec.base_mime_type",
"if",
"(",
"format",
".",
"mime_type",
".",
"match",
"(",
"/",
"application\\/tsrc\\+.+",
"/",
")",
")",
"{",
"return",
"format",
";",
"}",
"}",
"return",
"null",
";",
"}"
]
| Returns the first resource container format found in the list.
E.g. the array may contain binary formats such as pdf, mp3, etc. This basically filters those.
@param formats {[]} an array of resource formats
@returns {{}} the resource container format | [
"Returns",
"the",
"first",
"resource",
"container",
"format",
"found",
"in",
"the",
"list",
".",
"E",
".",
"g",
".",
"the",
"array",
"may",
"contain",
"binary",
"formats",
"such",
"as",
"pdf",
"mp3",
"etc",
".",
"This",
"basically",
"filters",
"those",
"."
]
| 18f518368ee89f4baf8943500a1c53ef5efcfb3e | https://github.com/unfoldingWord-dev/node-door43-client/blob/18f518368ee89f4baf8943500a1c53ef5efcfb3e/lib/main.js#L788-L796 |
|
41,712 | unfoldingWord-dev/node-door43-client | lib/main.js | function(languageSlug, projectSlug, resourceSlug, progressCallback) {
// support passing args as an object
if(languageSlug != null && typeof languageSlug == 'object') {
resourceSlug = languageSlug.resourceSlug;
projectSlug = languageSlug.projectSlug;
languageSlug = languageSlug.languageSlug;
}
let destFile;
let tempFile;
let containerDir;
return new Promise(function(resolve, reject) {
try {
resolve(library.public_getters.getResource(languageSlug, projectSlug, resourceSlug));
} catch(err) {
reject(err);
}
})
.then(function(resource) {
if(!resource) return Promise.reject(new Error('Unknown resource'));
let containerFormat = getResourceContainerFormat(resource.formats);
if(!containerFormat) return Promise.reject(new Error('Missing resource container format'));
let containerSlug = rc.tools.makeSlug(languageSlug, projectSlug, resourceSlug);
containerDir = path.join(resourceDir, containerSlug);
destFile = containerDir + '.' + rc.tools.spec.file_ext;
tempFile = containerDir + '.download';
rimraf.sync(tempFile);
mkdirp(path.dirname(containerDir));
if(!containerFormat.url) return Promise.reject('Missing resource format url');
return request.download(containerFormat.url, tempFile, progressCallback);
})
.then(function(response) {
if(response.status !== 200) {
rimraf.sync(tempFile);
return Promise.reject(response);
}
// replace old files
rimraf.sync(containerDir);
return new Promise(function(resolve, reject) {
mv(tempFile, destFile, {clobber: true}, function(err) {
if(err) {
reject(err);
} else {
resolve(destFile);
}
});
});
});
} | javascript | function(languageSlug, projectSlug, resourceSlug, progressCallback) {
// support passing args as an object
if(languageSlug != null && typeof languageSlug == 'object') {
resourceSlug = languageSlug.resourceSlug;
projectSlug = languageSlug.projectSlug;
languageSlug = languageSlug.languageSlug;
}
let destFile;
let tempFile;
let containerDir;
return new Promise(function(resolve, reject) {
try {
resolve(library.public_getters.getResource(languageSlug, projectSlug, resourceSlug));
} catch(err) {
reject(err);
}
})
.then(function(resource) {
if(!resource) return Promise.reject(new Error('Unknown resource'));
let containerFormat = getResourceContainerFormat(resource.formats);
if(!containerFormat) return Promise.reject(new Error('Missing resource container format'));
let containerSlug = rc.tools.makeSlug(languageSlug, projectSlug, resourceSlug);
containerDir = path.join(resourceDir, containerSlug);
destFile = containerDir + '.' + rc.tools.spec.file_ext;
tempFile = containerDir + '.download';
rimraf.sync(tempFile);
mkdirp(path.dirname(containerDir));
if(!containerFormat.url) return Promise.reject('Missing resource format url');
return request.download(containerFormat.url, tempFile, progressCallback);
})
.then(function(response) {
if(response.status !== 200) {
rimraf.sync(tempFile);
return Promise.reject(response);
}
// replace old files
rimraf.sync(containerDir);
return new Promise(function(resolve, reject) {
mv(tempFile, destFile, {clobber: true}, function(err) {
if(err) {
reject(err);
} else {
resolve(destFile);
}
});
});
});
} | [
"function",
"(",
"languageSlug",
",",
"projectSlug",
",",
"resourceSlug",
",",
"progressCallback",
")",
"{",
"// support passing args as an object",
"if",
"(",
"languageSlug",
"!=",
"null",
"&&",
"typeof",
"languageSlug",
"==",
"'object'",
")",
"{",
"resourceSlug",
"=",
"languageSlug",
".",
"resourceSlug",
";",
"projectSlug",
"=",
"languageSlug",
".",
"projectSlug",
";",
"languageSlug",
"=",
"languageSlug",
".",
"languageSlug",
";",
"}",
"let",
"destFile",
";",
"let",
"tempFile",
";",
"let",
"containerDir",
";",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"try",
"{",
"resolve",
"(",
"library",
".",
"public_getters",
".",
"getResource",
"(",
"languageSlug",
",",
"projectSlug",
",",
"resourceSlug",
")",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"reject",
"(",
"err",
")",
";",
"}",
"}",
")",
".",
"then",
"(",
"function",
"(",
"resource",
")",
"{",
"if",
"(",
"!",
"resource",
")",
"return",
"Promise",
".",
"reject",
"(",
"new",
"Error",
"(",
"'Unknown resource'",
")",
")",
";",
"let",
"containerFormat",
"=",
"getResourceContainerFormat",
"(",
"resource",
".",
"formats",
")",
";",
"if",
"(",
"!",
"containerFormat",
")",
"return",
"Promise",
".",
"reject",
"(",
"new",
"Error",
"(",
"'Missing resource container format'",
")",
")",
";",
"let",
"containerSlug",
"=",
"rc",
".",
"tools",
".",
"makeSlug",
"(",
"languageSlug",
",",
"projectSlug",
",",
"resourceSlug",
")",
";",
"containerDir",
"=",
"path",
".",
"join",
"(",
"resourceDir",
",",
"containerSlug",
")",
";",
"destFile",
"=",
"containerDir",
"+",
"'.'",
"+",
"rc",
".",
"tools",
".",
"spec",
".",
"file_ext",
";",
"tempFile",
"=",
"containerDir",
"+",
"'.download'",
";",
"rimraf",
".",
"sync",
"(",
"tempFile",
")",
";",
"mkdirp",
"(",
"path",
".",
"dirname",
"(",
"containerDir",
")",
")",
";",
"if",
"(",
"!",
"containerFormat",
".",
"url",
")",
"return",
"Promise",
".",
"reject",
"(",
"'Missing resource format url'",
")",
";",
"return",
"request",
".",
"download",
"(",
"containerFormat",
".",
"url",
",",
"tempFile",
",",
"progressCallback",
")",
";",
"}",
")",
".",
"then",
"(",
"function",
"(",
"response",
")",
"{",
"if",
"(",
"response",
".",
"status",
"!==",
"200",
")",
"{",
"rimraf",
".",
"sync",
"(",
"tempFile",
")",
";",
"return",
"Promise",
".",
"reject",
"(",
"response",
")",
";",
"}",
"// replace old files",
"rimraf",
".",
"sync",
"(",
"containerDir",
")",
";",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"mv",
"(",
"tempFile",
",",
"destFile",
",",
"{",
"clobber",
":",
"true",
"}",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"reject",
"(",
"err",
")",
";",
"}",
"else",
"{",
"resolve",
"(",
"destFile",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| Downloads a resource container.
This expects a correctly formatted resource container
and will download it directly to the disk
Note: You may provide a single object parameter if you prefer
once the api can deliver proper resource containers this method
should be renamed to downloadContainer
@param languageSlug {string}
@param projectSlug {string}
@param resourceSlug {string}
@param progressCallback {function} receives download progress updates
@returns {Promise.<String>} the path to the downloaded resource container | [
"Downloads",
"a",
"resource",
"container",
".",
"This",
"expects",
"a",
"correctly",
"formatted",
"resource",
"container",
"and",
"will",
"download",
"it",
"directly",
"to",
"the",
"disk"
]
| 18f518368ee89f4baf8943500a1c53ef5efcfb3e | https://github.com/unfoldingWord-dev/node-door43-client/blob/18f518368ee89f4baf8943500a1c53ef5efcfb3e/lib/main.js#L871-L921 |
|
41,713 | unfoldingWord-dev/node-door43-client | lib/main.js | function(languageSlug, projectSlug, resourceSlug) {
return new Promise(function(resolve, reject) {
try {
resolve(library.public_getters.getResource(languageSlug, projectSlug, resourceSlug));
} catch(err) {
reject(err);
}
})
.then(function(resource) {
if(!resource) return Promise.reject(new Error('Unknown resource'));
let containerSlug = rc.tools.makeSlug(languageSlug, projectSlug, resourceSlug);
let directory = path.join(resourceDir, containerSlug);
let archive = directory + '.' + rc.tools.spec.file_ext;
return rc.open(archive, directory, opts);
});
} | javascript | function(languageSlug, projectSlug, resourceSlug) {
return new Promise(function(resolve, reject) {
try {
resolve(library.public_getters.getResource(languageSlug, projectSlug, resourceSlug));
} catch(err) {
reject(err);
}
})
.then(function(resource) {
if(!resource) return Promise.reject(new Error('Unknown resource'));
let containerSlug = rc.tools.makeSlug(languageSlug, projectSlug, resourceSlug);
let directory = path.join(resourceDir, containerSlug);
let archive = directory + '.' + rc.tools.spec.file_ext;
return rc.open(archive, directory, opts);
});
} | [
"function",
"(",
"languageSlug",
",",
"projectSlug",
",",
"resourceSlug",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"try",
"{",
"resolve",
"(",
"library",
".",
"public_getters",
".",
"getResource",
"(",
"languageSlug",
",",
"projectSlug",
",",
"resourceSlug",
")",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"reject",
"(",
"err",
")",
";",
"}",
"}",
")",
".",
"then",
"(",
"function",
"(",
"resource",
")",
"{",
"if",
"(",
"!",
"resource",
")",
"return",
"Promise",
".",
"reject",
"(",
"new",
"Error",
"(",
"'Unknown resource'",
")",
")",
";",
"let",
"containerSlug",
"=",
"rc",
".",
"tools",
".",
"makeSlug",
"(",
"languageSlug",
",",
"projectSlug",
",",
"resourceSlug",
")",
";",
"let",
"directory",
"=",
"path",
".",
"join",
"(",
"resourceDir",
",",
"containerSlug",
")",
";",
"let",
"archive",
"=",
"directory",
"+",
"'.'",
"+",
"rc",
".",
"tools",
".",
"spec",
".",
"file_ext",
";",
"return",
"rc",
".",
"open",
"(",
"archive",
",",
"directory",
",",
"opts",
")",
";",
"}",
")",
";",
"}"
]
| Opens a resource container archive so it's contents can be read.
The index will be referenced to validate the resource and retrieve the container type.
@param languageSlug {string}
@param projectSlug {string}
@param resourceSlug {string}
@returns {Promise.<Container>} | [
"Opens",
"a",
"resource",
"container",
"archive",
"so",
"it",
"s",
"contents",
"can",
"be",
"read",
".",
"The",
"index",
"will",
"be",
"referenced",
"to",
"validate",
"the",
"resource",
"and",
"retrieve",
"the",
"container",
"type",
"."
]
| 18f518368ee89f4baf8943500a1c53ef5efcfb3e | https://github.com/unfoldingWord-dev/node-door43-client/blob/18f518368ee89f4baf8943500a1c53ef5efcfb3e/lib/main.js#L1114-L1129 |
|
41,714 | unfoldingWord-dev/node-door43-client | lib/main.js | function(languageSlug, projectSlug, resourceSlug) {
return new Promise(function(resolve, reject) {
try {
resolve(library.public_getters.getResource(languageSlug, projectSlug, resourceSlug));
} catch(err) {
reject(err);
}
})
.then(function(resource) {
if(!resource) return Promise.reject(new Error('Unknown resource'));
let containerSlug = rc.tools.makeSlug(languageSlug, projectSlug, resourceSlug);
let directory = path.join(resourceDir, containerSlug);
opts.clean = true; // remove the directory once closed.
return rc.close(directory, opts);
});
} | javascript | function(languageSlug, projectSlug, resourceSlug) {
return new Promise(function(resolve, reject) {
try {
resolve(library.public_getters.getResource(languageSlug, projectSlug, resourceSlug));
} catch(err) {
reject(err);
}
})
.then(function(resource) {
if(!resource) return Promise.reject(new Error('Unknown resource'));
let containerSlug = rc.tools.makeSlug(languageSlug, projectSlug, resourceSlug);
let directory = path.join(resourceDir, containerSlug);
opts.clean = true; // remove the directory once closed.
return rc.close(directory, opts);
});
} | [
"function",
"(",
"languageSlug",
",",
"projectSlug",
",",
"resourceSlug",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"try",
"{",
"resolve",
"(",
"library",
".",
"public_getters",
".",
"getResource",
"(",
"languageSlug",
",",
"projectSlug",
",",
"resourceSlug",
")",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"reject",
"(",
"err",
")",
";",
"}",
"}",
")",
".",
"then",
"(",
"function",
"(",
"resource",
")",
"{",
"if",
"(",
"!",
"resource",
")",
"return",
"Promise",
".",
"reject",
"(",
"new",
"Error",
"(",
"'Unknown resource'",
")",
")",
";",
"let",
"containerSlug",
"=",
"rc",
".",
"tools",
".",
"makeSlug",
"(",
"languageSlug",
",",
"projectSlug",
",",
"resourceSlug",
")",
";",
"let",
"directory",
"=",
"path",
".",
"join",
"(",
"resourceDir",
",",
"containerSlug",
")",
";",
"opts",
".",
"clean",
"=",
"true",
";",
"// remove the directory once closed.",
"return",
"rc",
".",
"close",
"(",
"directory",
",",
"opts",
")",
";",
"}",
")",
";",
"}"
]
| Closes a resource container archive.
@param languageSlug {string}
@param projectSlug {string}
@param resourceSlug {string}
@returns {Promise.<string>} the path to the closed container | [
"Closes",
"a",
"resource",
"container",
"archive",
"."
]
| 18f518368ee89f4baf8943500a1c53ef5efcfb3e | https://github.com/unfoldingWord-dev/node-door43-client/blob/18f518368ee89f4baf8943500a1c53ef5efcfb3e/lib/main.js#L1139-L1154 |
|
41,715 | unfoldingWord-dev/node-door43-client | lib/main.js | function() {
return new Promise(function(resolve, reject) {
try {
let files;
if(fileUtils.fileExists(resourceDir)) {
files = fs.readdirSync(resourceDir);
files = _.uniqBy(files, function (f) {
return path.basename(f, '.' + rc.tools.spec.file_ext);
}).map(function(f) { return path.join(resourceDir, f);});
}
if(!files) files = [];
resolve(files);
} catch (err) {
reject(err);
}
}).then(function(files) {
return promiseUtils.chain(rc.tools.inspect, function(err) {
console.error(err);
return false;
})(files);
});
} | javascript | function() {
return new Promise(function(resolve, reject) {
try {
let files;
if(fileUtils.fileExists(resourceDir)) {
files = fs.readdirSync(resourceDir);
files = _.uniqBy(files, function (f) {
return path.basename(f, '.' + rc.tools.spec.file_ext);
}).map(function(f) { return path.join(resourceDir, f);});
}
if(!files) files = [];
resolve(files);
} catch (err) {
reject(err);
}
}).then(function(files) {
return promiseUtils.chain(rc.tools.inspect, function(err) {
console.error(err);
return false;
})(files);
});
} | [
"function",
"(",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"try",
"{",
"let",
"files",
";",
"if",
"(",
"fileUtils",
".",
"fileExists",
"(",
"resourceDir",
")",
")",
"{",
"files",
"=",
"fs",
".",
"readdirSync",
"(",
"resourceDir",
")",
";",
"files",
"=",
"_",
".",
"uniqBy",
"(",
"files",
",",
"function",
"(",
"f",
")",
"{",
"return",
"path",
".",
"basename",
"(",
"f",
",",
"'.'",
"+",
"rc",
".",
"tools",
".",
"spec",
".",
"file_ext",
")",
";",
"}",
")",
".",
"map",
"(",
"function",
"(",
"f",
")",
"{",
"return",
"path",
".",
"join",
"(",
"resourceDir",
",",
"f",
")",
";",
"}",
")",
";",
"}",
"if",
"(",
"!",
"files",
")",
"files",
"=",
"[",
"]",
";",
"resolve",
"(",
"files",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"reject",
"(",
"err",
")",
";",
"}",
"}",
")",
".",
"then",
"(",
"function",
"(",
"files",
")",
"{",
"return",
"promiseUtils",
".",
"chain",
"(",
"rc",
".",
"tools",
".",
"inspect",
",",
"function",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"err",
")",
";",
"return",
"false",
";",
"}",
")",
"(",
"files",
")",
";",
"}",
")",
";",
"}"
]
| Returns a list of resource containers that have been downloaded
@returns {Promise.<[{}]>} an array of resource container info objects (package.json). | [
"Returns",
"a",
"list",
"of",
"resource",
"containers",
"that",
"have",
"been",
"downloaded"
]
| 18f518368ee89f4baf8943500a1c53ef5efcfb3e | https://github.com/unfoldingWord-dev/node-door43-client/blob/18f518368ee89f4baf8943500a1c53ef5efcfb3e/lib/main.js#L1160-L1181 |
|
41,716 | unfoldingWord-dev/node-door43-client | lib/main.js | function() {
return new Promise(function(resolve, reject) {
try{
resolve(library.listSourceLanguagesLastModified());
} catch (err) {
reject(err);
}
}).then(function(languages) {
return listResourceContainers()
.then(function(results) {
// flatten modified_at
let local = {};
for(let info of results) {
try {
if(!local[info.language.slug]) local[info.language.slug] = -1;
let old = local[info.language.slug];
local[info.language.slug] = info.modified_at > old ? info.modified_at : old;
} catch (err) {
console.error(err);
}
}
return inferUpdates(local, languages);
});
});
} | javascript | function() {
return new Promise(function(resolve, reject) {
try{
resolve(library.listSourceLanguagesLastModified());
} catch (err) {
reject(err);
}
}).then(function(languages) {
return listResourceContainers()
.then(function(results) {
// flatten modified_at
let local = {};
for(let info of results) {
try {
if(!local[info.language.slug]) local[info.language.slug] = -1;
let old = local[info.language.slug];
local[info.language.slug] = info.modified_at > old ? info.modified_at : old;
} catch (err) {
console.error(err);
}
}
return inferUpdates(local, languages);
});
});
} | [
"function",
"(",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"try",
"{",
"resolve",
"(",
"library",
".",
"listSourceLanguagesLastModified",
"(",
")",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"reject",
"(",
"err",
")",
";",
"}",
"}",
")",
".",
"then",
"(",
"function",
"(",
"languages",
")",
"{",
"return",
"listResourceContainers",
"(",
")",
".",
"then",
"(",
"function",
"(",
"results",
")",
"{",
"// flatten modified_at",
"let",
"local",
"=",
"{",
"}",
";",
"for",
"(",
"let",
"info",
"of",
"results",
")",
"{",
"try",
"{",
"if",
"(",
"!",
"local",
"[",
"info",
".",
"language",
".",
"slug",
"]",
")",
"local",
"[",
"info",
".",
"language",
".",
"slug",
"]",
"=",
"-",
"1",
";",
"let",
"old",
"=",
"local",
"[",
"info",
".",
"language",
".",
"slug",
"]",
";",
"local",
"[",
"info",
".",
"language",
".",
"slug",
"]",
"=",
"info",
".",
"modified_at",
">",
"old",
"?",
"info",
".",
"modified_at",
":",
"old",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"err",
")",
";",
"}",
"}",
"return",
"inferUpdates",
"(",
"local",
",",
"languages",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| Returns a list of source languages that are eligible for updates.
@returns {Promise.<Array>} An array of slugs | [
"Returns",
"a",
"list",
"of",
"source",
"languages",
"that",
"are",
"eligible",
"for",
"updates",
"."
]
| 18f518368ee89f4baf8943500a1c53ef5efcfb3e | https://github.com/unfoldingWord-dev/node-door43-client/blob/18f518368ee89f4baf8943500a1c53ef5efcfb3e/lib/main.js#L1213-L1237 |
|
41,717 | unfoldingWord-dev/node-door43-client | lib/main.js | function(languageSlug) {
return new Promise(function(resolve, reject) {
try{
resolve(library.listProjectsLastModified(languageSlug));
} catch (err) {
reject(err);
}
}).then(function(projects) {
return listResourceContainers()
.then(function(results) {
// flatten modified_at
let local = {};
for(let info of results) {
try {
if(languageSlug && info.language.slug !== languageSlug) continue;
if(!local[info.project.slug]) local[info.project.slug] = -1;
let old = local[info.project.slug];
local[info.project.slug] = info.modified_at > old ? info.modified_at : old;
} catch (err) {
console.error(err);
}
}
return inferUpdates(local, projects);
});
});
} | javascript | function(languageSlug) {
return new Promise(function(resolve, reject) {
try{
resolve(library.listProjectsLastModified(languageSlug));
} catch (err) {
reject(err);
}
}).then(function(projects) {
return listResourceContainers()
.then(function(results) {
// flatten modified_at
let local = {};
for(let info of results) {
try {
if(languageSlug && info.language.slug !== languageSlug) continue;
if(!local[info.project.slug]) local[info.project.slug] = -1;
let old = local[info.project.slug];
local[info.project.slug] = info.modified_at > old ? info.modified_at : old;
} catch (err) {
console.error(err);
}
}
return inferUpdates(local, projects);
});
});
} | [
"function",
"(",
"languageSlug",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"try",
"{",
"resolve",
"(",
"library",
".",
"listProjectsLastModified",
"(",
"languageSlug",
")",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"reject",
"(",
"err",
")",
";",
"}",
"}",
")",
".",
"then",
"(",
"function",
"(",
"projects",
")",
"{",
"return",
"listResourceContainers",
"(",
")",
".",
"then",
"(",
"function",
"(",
"results",
")",
"{",
"// flatten modified_at",
"let",
"local",
"=",
"{",
"}",
";",
"for",
"(",
"let",
"info",
"of",
"results",
")",
"{",
"try",
"{",
"if",
"(",
"languageSlug",
"&&",
"info",
".",
"language",
".",
"slug",
"!==",
"languageSlug",
")",
"continue",
";",
"if",
"(",
"!",
"local",
"[",
"info",
".",
"project",
".",
"slug",
"]",
")",
"local",
"[",
"info",
".",
"project",
".",
"slug",
"]",
"=",
"-",
"1",
";",
"let",
"old",
"=",
"local",
"[",
"info",
".",
"project",
".",
"slug",
"]",
";",
"local",
"[",
"info",
".",
"project",
".",
"slug",
"]",
"=",
"info",
".",
"modified_at",
">",
"old",
"?",
"info",
".",
"modified_at",
":",
"old",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"err",
")",
";",
"}",
"}",
"return",
"inferUpdates",
"(",
"local",
",",
"projects",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| Returns a list of projects that are eligible for updates.
If no language is given the results will include all projects in all languages. This is helpful if you need to view updates based on project first rather than source language first.
@param languageSlug {string|null} the slug of a source language who's projects will be checked.
@returns {Promise.<Array>} An array of slugs | [
"Returns",
"a",
"list",
"of",
"projects",
"that",
"are",
"eligible",
"for",
"updates",
".",
"If",
"no",
"language",
"is",
"given",
"the",
"results",
"will",
"include",
"all",
"projects",
"in",
"all",
"languages",
".",
"This",
"is",
"helpful",
"if",
"you",
"need",
"to",
"view",
"updates",
"based",
"on",
"project",
"first",
"rather",
"than",
"source",
"language",
"first",
"."
]
| 18f518368ee89f4baf8943500a1c53ef5efcfb3e | https://github.com/unfoldingWord-dev/node-door43-client/blob/18f518368ee89f4baf8943500a1c53ef5efcfb3e/lib/main.js#L1246-L1271 |
|
41,718 | DFFR-NT/dffrnt.confs | lib/utils.js | FREEZE | function FREEZE(obj, all = false) {
if (UoN(obj)) return obj;
// ----------------------------------------------------------
let iss = ISS(obj), iEN = OoA.has(iss), dfl, res;
// ----------------------------------------------------------
if (!iEN||iss=='function') return obj;
if (!!obj.toJS) obj = obj.toJS();
if (ISCONFIG(obj)||ISPTYPE(obj)) return obj;
// ----------------------------------------------------------
dfl = [{},[]][-(-(iss==OoA[1]))];
res = Assign(dfl, obj);
// ----------------------------------------------------------
if (!!all) res = FromJS(res).map((v)=>(
FREEZE(v, all)
)).toJS();
// ----------------------------------------------------------
return Object.freeze(res);
} | javascript | function FREEZE(obj, all = false) {
if (UoN(obj)) return obj;
// ----------------------------------------------------------
let iss = ISS(obj), iEN = OoA.has(iss), dfl, res;
// ----------------------------------------------------------
if (!iEN||iss=='function') return obj;
if (!!obj.toJS) obj = obj.toJS();
if (ISCONFIG(obj)||ISPTYPE(obj)) return obj;
// ----------------------------------------------------------
dfl = [{},[]][-(-(iss==OoA[1]))];
res = Assign(dfl, obj);
// ----------------------------------------------------------
if (!!all) res = FromJS(res).map((v)=>(
FREEZE(v, all)
)).toJS();
// ----------------------------------------------------------
return Object.freeze(res);
} | [
"function",
"FREEZE",
"(",
"obj",
",",
"all",
"=",
"false",
")",
"{",
"if",
"(",
"UoN",
"(",
"obj",
")",
")",
"return",
"obj",
";",
"// ----------------------------------------------------------",
"let",
"iss",
"=",
"ISS",
"(",
"obj",
")",
",",
"iEN",
"=",
"OoA",
".",
"has",
"(",
"iss",
")",
",",
"dfl",
",",
"res",
";",
"// ----------------------------------------------------------",
"if",
"(",
"!",
"iEN",
"||",
"iss",
"==",
"'function'",
")",
"return",
"obj",
";",
"if",
"(",
"!",
"!",
"obj",
".",
"toJS",
")",
"obj",
"=",
"obj",
".",
"toJS",
"(",
")",
";",
"if",
"(",
"ISCONFIG",
"(",
"obj",
")",
"||",
"ISPTYPE",
"(",
"obj",
")",
")",
"return",
"obj",
";",
"// ----------------------------------------------------------",
"dfl",
"=",
"[",
"{",
"}",
",",
"[",
"]",
"]",
"[",
"-",
"(",
"-",
"(",
"iss",
"==",
"OoA",
"[",
"1",
"]",
")",
")",
"]",
";",
"res",
"=",
"Assign",
"(",
"dfl",
",",
"obj",
")",
";",
"// ----------------------------------------------------------",
"if",
"(",
"!",
"!",
"all",
")",
"res",
"=",
"FromJS",
"(",
"res",
")",
".",
"map",
"(",
"(",
"v",
")",
"=>",
"(",
"FREEZE",
"(",
"v",
",",
"all",
")",
")",
")",
".",
"toJS",
"(",
")",
";",
"// ----------------------------------------------------------",
"return",
"Object",
".",
"freeze",
"(",
"res",
")",
";",
"}"
]
| Freeze an Object, if needed.
@param {*} obj The Object to Freeze
@param {Boolean} [all=false] `true`, if Freezing should be recursive
@returns {Object} The frozen Object
@private | [
"Freeze",
"an",
"Object",
"if",
"needed",
"."
]
| 2175e20c0ed3405e8956dd9b59cd71e79bef6d16 | https://github.com/DFFR-NT/dffrnt.confs/blob/2175e20c0ed3405e8956dd9b59cd71e79bef6d16/lib/utils.js#L265-L282 |
41,719 | DFFR-NT/dffrnt.confs | lib/utils.js | IDPTYPE | function IDPTYPE() {
let make = ()=>(Math.random().toString(36).slice(2)), rslt = make();
while (global.__PTYPES__.has(rslt)) { rslt = make(); }
return rslt;
} | javascript | function IDPTYPE() {
let make = ()=>(Math.random().toString(36).slice(2)), rslt = make();
while (global.__PTYPES__.has(rslt)) { rslt = make(); }
return rslt;
} | [
"function",
"IDPTYPE",
"(",
")",
"{",
"let",
"make",
"=",
"(",
")",
"=>",
"(",
"Math",
".",
"random",
"(",
")",
".",
"toString",
"(",
"36",
")",
".",
"slice",
"(",
"2",
")",
")",
",",
"rslt",
"=",
"make",
"(",
")",
";",
"while",
"(",
"global",
".",
"__PTYPES__",
".",
"has",
"(",
"rslt",
")",
")",
"{",
"rslt",
"=",
"make",
"(",
")",
";",
"}",
"return",
"rslt",
";",
"}"
]
| Creates a unique ID for `PTypes`
@returns {string} A unique identifier
@private | [
"Creates",
"a",
"unique",
"ID",
"for",
"PTypes"
]
| 2175e20c0ed3405e8956dd9b59cd71e79bef6d16 | https://github.com/DFFR-NT/dffrnt.confs/blob/2175e20c0ed3405e8956dd9b59cd71e79bef6d16/lib/utils.js#L312-L316 |
41,720 | DFFR-NT/dffrnt.confs | lib/utils.js | GETCONFIG | function GETCONFIG(name) {
return {
GNConfig: GNConfig,
RouteGN: RouteGN,
RouteAU: RouteAU,
RouteDB: RouteDB,
GNHeaders: GNHeaders,
GNParam: GNParam,
GNDescr: GNDescr,
}[name];
} | javascript | function GETCONFIG(name) {
return {
GNConfig: GNConfig,
RouteGN: RouteGN,
RouteAU: RouteAU,
RouteDB: RouteDB,
GNHeaders: GNHeaders,
GNParam: GNParam,
GNDescr: GNDescr,
}[name];
} | [
"function",
"GETCONFIG",
"(",
"name",
")",
"{",
"return",
"{",
"GNConfig",
":",
"GNConfig",
",",
"RouteGN",
":",
"RouteGN",
",",
"RouteAU",
":",
"RouteAU",
",",
"RouteDB",
":",
"RouteDB",
",",
"GNHeaders",
":",
"GNHeaders",
",",
"GNParam",
":",
"GNParam",
",",
"GNDescr",
":",
"GNDescr",
",",
"}",
"[",
"name",
"]",
";",
"}"
]
| Grabs a Config-Type Class
@param {string} name The name of the Config-Type Class
@returns {GNConfig|RouteGN|RouteAU|RouteDB|GNHeaders|GNParam|GNDescr}
@private | [
"Grabs",
"a",
"Config",
"-",
"Type",
"Class"
]
| 2175e20c0ed3405e8956dd9b59cd71e79bef6d16 | https://github.com/DFFR-NT/dffrnt.confs/blob/2175e20c0ed3405e8956dd9b59cd71e79bef6d16/lib/utils.js#L325-L335 |
41,721 | DFFR-NT/dffrnt.confs | lib/utils.js | MERGER | function MERGER(oldVal, newVal) {
let onme = CNAME(oldVal), ocon = ISCONFIG(oldVal), otyp = ISPTYPE(oldVal),
nnme = CNAME(newVal), ncon = ISCONFIG(newVal), ntyp = ISPTYPE(newVal);
if (otyp || ntyp) { return newVal; };
if (ocon && ncon && onme==nnme) {
return new GETCONFIG(onme)(Assign(oldVal, newVal));
};
if (ocon && onme=='GNParam') {
if (nnme=='array') return oldVal.AddVersion(newVal[0], newVal[1]);
if (nnme=='List' ) return oldVal.AddVersion(newVal.get(0), newVal.get(1).toJS());
};
return newVal;
} | javascript | function MERGER(oldVal, newVal) {
let onme = CNAME(oldVal), ocon = ISCONFIG(oldVal), otyp = ISPTYPE(oldVal),
nnme = CNAME(newVal), ncon = ISCONFIG(newVal), ntyp = ISPTYPE(newVal);
if (otyp || ntyp) { return newVal; };
if (ocon && ncon && onme==nnme) {
return new GETCONFIG(onme)(Assign(oldVal, newVal));
};
if (ocon && onme=='GNParam') {
if (nnme=='array') return oldVal.AddVersion(newVal[0], newVal[1]);
if (nnme=='List' ) return oldVal.AddVersion(newVal.get(0), newVal.get(1).toJS());
};
return newVal;
} | [
"function",
"MERGER",
"(",
"oldVal",
",",
"newVal",
")",
"{",
"let",
"onme",
"=",
"CNAME",
"(",
"oldVal",
")",
",",
"ocon",
"=",
"ISCONFIG",
"(",
"oldVal",
")",
",",
"otyp",
"=",
"ISPTYPE",
"(",
"oldVal",
")",
",",
"nnme",
"=",
"CNAME",
"(",
"newVal",
")",
",",
"ncon",
"=",
"ISCONFIG",
"(",
"newVal",
")",
",",
"ntyp",
"=",
"ISPTYPE",
"(",
"newVal",
")",
";",
"if",
"(",
"otyp",
"||",
"ntyp",
")",
"{",
"return",
"newVal",
";",
"}",
";",
"if",
"(",
"ocon",
"&&",
"ncon",
"&&",
"onme",
"==",
"nnme",
")",
"{",
"return",
"new",
"GETCONFIG",
"(",
"onme",
")",
"(",
"Assign",
"(",
"oldVal",
",",
"newVal",
")",
")",
";",
"}",
";",
"if",
"(",
"ocon",
"&&",
"onme",
"==",
"'GNParam'",
")",
"{",
"if",
"(",
"nnme",
"==",
"'array'",
")",
"return",
"oldVal",
".",
"AddVersion",
"(",
"newVal",
"[",
"0",
"]",
",",
"newVal",
"[",
"1",
"]",
")",
";",
"if",
"(",
"nnme",
"==",
"'List'",
")",
"return",
"oldVal",
".",
"AddVersion",
"(",
"newVal",
".",
"get",
"(",
"0",
")",
",",
"newVal",
".",
"get",
"(",
"1",
")",
".",
"toJS",
"(",
")",
")",
";",
"}",
";",
"return",
"newVal",
";",
"}"
]
| A `callback` used in `Immutable`.`mergeWith`
@param {*} oldVal The value of the original Object
@param {*} newVal The value of the merging Object
@returns {*} | [
"A",
"callback",
"used",
"in",
"Immutable",
".",
"mergeWith"
]
| 2175e20c0ed3405e8956dd9b59cd71e79bef6d16 | https://github.com/DFFR-NT/dffrnt.confs/blob/2175e20c0ed3405e8956dd9b59cd71e79bef6d16/lib/utils.js#L344-L356 |
41,722 | DFFR-NT/dffrnt.confs | lib/utils.js | ThrowType | function ThrowType(name, type, value, actual) {
console.log('THIS:', this)
let THS = this, pfx = (!!THS ? THS.Name||THS.Scheme : '');
throw new TypeError(
`${pfx} property, [${name}], must be one of the following, <${
type.join('> or <').toTitleCase()
}>. Got <${actual.toTitleCase()}> (${value}) instead.`
);
} | javascript | function ThrowType(name, type, value, actual) {
console.log('THIS:', this)
let THS = this, pfx = (!!THS ? THS.Name||THS.Scheme : '');
throw new TypeError(
`${pfx} property, [${name}], must be one of the following, <${
type.join('> or <').toTitleCase()
}>. Got <${actual.toTitleCase()}> (${value}) instead.`
);
} | [
"function",
"ThrowType",
"(",
"name",
",",
"type",
",",
"value",
",",
"actual",
")",
"{",
"console",
".",
"log",
"(",
"'THIS:'",
",",
"this",
")",
"let",
"THS",
"=",
"this",
",",
"pfx",
"=",
"(",
"!",
"!",
"THS",
"?",
"THS",
".",
"Name",
"||",
"THS",
".",
"Scheme",
":",
"''",
")",
";",
"throw",
"new",
"TypeError",
"(",
"`",
"${",
"pfx",
"}",
"${",
"name",
"}",
"${",
"type",
".",
"join",
"(",
"'> or <'",
")",
".",
"toTitleCase",
"(",
")",
"}",
"${",
"actual",
".",
"toTitleCase",
"(",
")",
"}",
"${",
"value",
"}",
"`",
")",
";",
"}"
]
| Throws a `TypeError` when a `type` requirement is not met
@param {String} name The `name` of the Property
@param {String} type The `type` the Property should have been
@param {any} value The failed `value`
@param {String} actual The `type` the Value actual is
@private | [
"Throws",
"a",
"TypeError",
"when",
"a",
"type",
"requirement",
"is",
"not",
"met"
]
| 2175e20c0ed3405e8956dd9b59cd71e79bef6d16 | https://github.com/DFFR-NT/dffrnt.confs/blob/2175e20c0ed3405e8956dd9b59cd71e79bef6d16/lib/utils.js#L409-L417 |
41,723 | bigpipe/predefine | index.js | descriptor | function descriptor(obj) {
if (!obj || 'object' !== typeof obj || Array.isArray(obj)) return false;
var keys = Object.keys(obj);
//
// A descriptor can only be a data or accessor descriptor, never both.
// An data descriptor can only specify:
//
// - configurable
// - enumerable
// - (optional) value
// - (optional) writable
//
// And an accessor descriptor can only specify;
//
// - configurable
// - enumerable
// - (optional) get
// - (optional) set
//
if (
('value' in obj || 'writable' in obj)
&& ('function' === typeof obj.set || 'function' === typeof obj.get)
) return false;
return !!keys.length && keys.every(function allowed(key) {
var type = description[key]
, valid = type === undefined || is(obj[key], type);
return key in description && valid;
});
} | javascript | function descriptor(obj) {
if (!obj || 'object' !== typeof obj || Array.isArray(obj)) return false;
var keys = Object.keys(obj);
//
// A descriptor can only be a data or accessor descriptor, never both.
// An data descriptor can only specify:
//
// - configurable
// - enumerable
// - (optional) value
// - (optional) writable
//
// And an accessor descriptor can only specify;
//
// - configurable
// - enumerable
// - (optional) get
// - (optional) set
//
if (
('value' in obj || 'writable' in obj)
&& ('function' === typeof obj.set || 'function' === typeof obj.get)
) return false;
return !!keys.length && keys.every(function allowed(key) {
var type = description[key]
, valid = type === undefined || is(obj[key], type);
return key in description && valid;
});
} | [
"function",
"descriptor",
"(",
"obj",
")",
"{",
"if",
"(",
"!",
"obj",
"||",
"'object'",
"!==",
"typeof",
"obj",
"||",
"Array",
".",
"isArray",
"(",
"obj",
")",
")",
"return",
"false",
";",
"var",
"keys",
"=",
"Object",
".",
"keys",
"(",
"obj",
")",
";",
"//",
"// A descriptor can only be a data or accessor descriptor, never both.",
"// An data descriptor can only specify:",
"//",
"// - configurable",
"// - enumerable",
"// - (optional) value",
"// - (optional) writable",
"//",
"// And an accessor descriptor can only specify;",
"//",
"// - configurable",
"// - enumerable",
"// - (optional) get",
"// - (optional) set",
"//",
"if",
"(",
"(",
"'value'",
"in",
"obj",
"||",
"'writable'",
"in",
"obj",
")",
"&&",
"(",
"'function'",
"===",
"typeof",
"obj",
".",
"set",
"||",
"'function'",
"===",
"typeof",
"obj",
".",
"get",
")",
")",
"return",
"false",
";",
"return",
"!",
"!",
"keys",
".",
"length",
"&&",
"keys",
".",
"every",
"(",
"function",
"allowed",
"(",
"key",
")",
"{",
"var",
"type",
"=",
"description",
"[",
"key",
"]",
",",
"valid",
"=",
"type",
"===",
"undefined",
"||",
"is",
"(",
"obj",
"[",
"key",
"]",
",",
"type",
")",
";",
"return",
"key",
"in",
"description",
"&&",
"valid",
";",
"}",
")",
";",
"}"
]
| Check if a given object is valid as an descriptor.
@param {Object} obj The object with a possible description.
@returns {Boolean}
@api public | [
"Check",
"if",
"a",
"given",
"object",
"is",
"valid",
"as",
"an",
"descriptor",
"."
]
| 238137e3d1b8288ff5d7529c3cbcdd371888c26b | https://github.com/bigpipe/predefine/blob/238137e3d1b8288ff5d7529c3cbcdd371888c26b/index.js#L28-L60 |
41,724 | bigpipe/predefine | index.js | predefine | function predefine(obj, pattern) {
pattern = pattern || predefine.READABLE;
return function predefined(method, description, clean) {
//
// If we are given a description compatible Object, use that instead of
// setting it as value. This allows easy creation of getters and setters.
//
if (
!predefine.descriptor(description)
|| is(description, 'object')
&& !clean
&& !predefine.descriptor(predefine.mixin({}, pattern, description))
) { description = {
value: description
};
}
//
// Prevent thrown errors when we attempt to override a readonly
// property
//
var described = Object.getOwnPropertyDescriptor(obj, method);
if (described && !described.configurable) {
return predefined;
}
Object.defineProperty(obj, method, !clean
? predefine.mixin({}, pattern, description)
: description
);
return predefined;
};
} | javascript | function predefine(obj, pattern) {
pattern = pattern || predefine.READABLE;
return function predefined(method, description, clean) {
//
// If we are given a description compatible Object, use that instead of
// setting it as value. This allows easy creation of getters and setters.
//
if (
!predefine.descriptor(description)
|| is(description, 'object')
&& !clean
&& !predefine.descriptor(predefine.mixin({}, pattern, description))
) { description = {
value: description
};
}
//
// Prevent thrown errors when we attempt to override a readonly
// property
//
var described = Object.getOwnPropertyDescriptor(obj, method);
if (described && !described.configurable) {
return predefined;
}
Object.defineProperty(obj, method, !clean
? predefine.mixin({}, pattern, description)
: description
);
return predefined;
};
} | [
"function",
"predefine",
"(",
"obj",
",",
"pattern",
")",
"{",
"pattern",
"=",
"pattern",
"||",
"predefine",
".",
"READABLE",
";",
"return",
"function",
"predefined",
"(",
"method",
",",
"description",
",",
"clean",
")",
"{",
"//",
"// If we are given a description compatible Object, use that instead of",
"// setting it as value. This allows easy creation of getters and setters.",
"//",
"if",
"(",
"!",
"predefine",
".",
"descriptor",
"(",
"description",
")",
"||",
"is",
"(",
"description",
",",
"'object'",
")",
"&&",
"!",
"clean",
"&&",
"!",
"predefine",
".",
"descriptor",
"(",
"predefine",
".",
"mixin",
"(",
"{",
"}",
",",
"pattern",
",",
"description",
")",
")",
")",
"{",
"description",
"=",
"{",
"value",
":",
"description",
"}",
";",
"}",
"//",
"// Prevent thrown errors when we attempt to override a readonly",
"// property",
"//",
"var",
"described",
"=",
"Object",
".",
"getOwnPropertyDescriptor",
"(",
"obj",
",",
"method",
")",
";",
"if",
"(",
"described",
"&&",
"!",
"described",
".",
"configurable",
")",
"{",
"return",
"predefined",
";",
"}",
"Object",
".",
"defineProperty",
"(",
"obj",
",",
"method",
",",
"!",
"clean",
"?",
"predefine",
".",
"mixin",
"(",
"{",
"}",
",",
"pattern",
",",
"description",
")",
":",
"description",
")",
";",
"return",
"predefined",
";",
"}",
";",
"}"
]
| Predefine, preconfigure an Object.defineProperty.
@param {Object} obj The context, prototype or object we define on.
@param {Object} pattern The default description.
@param {Boolean} override Override the pattern.
@returns {Function} The function definition.
@api public | [
"Predefine",
"preconfigure",
"an",
"Object",
".",
"defineProperty",
"."
]
| 238137e3d1b8288ff5d7529c3cbcdd371888c26b | https://github.com/bigpipe/predefine/blob/238137e3d1b8288ff5d7529c3cbcdd371888c26b/index.js#L83-L117 |
41,725 | bigpipe/predefine | index.js | lazy | function lazy(obj, prop, fn) {
Object.defineProperty(obj, prop, {
configurable: true,
get: function get() {
return Object.defineProperty(this, prop, {
value: fn.call(this)
})[prop];
},
set: function set(value) {
return Object.defineProperty(this, prop, {
value: value
})[prop];
}
});
} | javascript | function lazy(obj, prop, fn) {
Object.defineProperty(obj, prop, {
configurable: true,
get: function get() {
return Object.defineProperty(this, prop, {
value: fn.call(this)
})[prop];
},
set: function set(value) {
return Object.defineProperty(this, prop, {
value: value
})[prop];
}
});
} | [
"function",
"lazy",
"(",
"obj",
",",
"prop",
",",
"fn",
")",
"{",
"Object",
".",
"defineProperty",
"(",
"obj",
",",
"prop",
",",
"{",
"configurable",
":",
"true",
",",
"get",
":",
"function",
"get",
"(",
")",
"{",
"return",
"Object",
".",
"defineProperty",
"(",
"this",
",",
"prop",
",",
"{",
"value",
":",
"fn",
".",
"call",
"(",
"this",
")",
"}",
")",
"[",
"prop",
"]",
";",
"}",
",",
"set",
":",
"function",
"set",
"(",
"value",
")",
"{",
"return",
"Object",
".",
"defineProperty",
"(",
"this",
",",
"prop",
",",
"{",
"value",
":",
"value",
"}",
")",
"[",
"prop",
"]",
";",
"}",
"}",
")",
";",
"}"
]
| Lazy initialization pattern.
@param {Object} obj The object where we need to add lazy loading prop.
@param {String} prop The name of the property that should lazy load.
@param {Function} fn The function that returns the lazy laoded value.
@api public | [
"Lazy",
"initialization",
"pattern",
"."
]
| 238137e3d1b8288ff5d7529c3cbcdd371888c26b | https://github.com/bigpipe/predefine/blob/238137e3d1b8288ff5d7529c3cbcdd371888c26b/index.js#L127-L143 |
41,726 | bigpipe/predefine | index.js | remove | function remove(obj, keep) {
if (!obj) return false;
keep = keep || [];
for (var prop in obj) {
if (has.call(obj, prop) && !~keep.indexOf(prop)) {
delete obj[prop];
}
}
return true;
} | javascript | function remove(obj, keep) {
if (!obj) return false;
keep = keep || [];
for (var prop in obj) {
if (has.call(obj, prop) && !~keep.indexOf(prop)) {
delete obj[prop];
}
}
return true;
} | [
"function",
"remove",
"(",
"obj",
",",
"keep",
")",
"{",
"if",
"(",
"!",
"obj",
")",
"return",
"false",
";",
"keep",
"=",
"keep",
"||",
"[",
"]",
";",
"for",
"(",
"var",
"prop",
"in",
"obj",
")",
"{",
"if",
"(",
"has",
".",
"call",
"(",
"obj",
",",
"prop",
")",
"&&",
"!",
"~",
"keep",
".",
"indexOf",
"(",
"prop",
")",
")",
"{",
"delete",
"obj",
"[",
"prop",
"]",
";",
"}",
"}",
"return",
"true",
";",
"}"
]
| Remove all enumerable properties from an given object.
@param {Object} obj The object that needs cleaning.
@param {Array} keep Properties that should be kept.
@api public | [
"Remove",
"all",
"enumerable",
"properties",
"from",
"an",
"given",
"object",
"."
]
| 238137e3d1b8288ff5d7529c3cbcdd371888c26b | https://github.com/bigpipe/predefine/blob/238137e3d1b8288ff5d7529c3cbcdd371888c26b/index.js#L162-L173 |
41,727 | bigpipe/predefine | index.js | mixin | function mixin(target) {
Array.prototype.slice.call(arguments, 1).forEach(function forEach(o) {
Object.getOwnPropertyNames(o).forEach(function eachAttr(attr) {
Object.defineProperty(target, attr, Object.getOwnPropertyDescriptor(o, attr));
});
});
return target;
} | javascript | function mixin(target) {
Array.prototype.slice.call(arguments, 1).forEach(function forEach(o) {
Object.getOwnPropertyNames(o).forEach(function eachAttr(attr) {
Object.defineProperty(target, attr, Object.getOwnPropertyDescriptor(o, attr));
});
});
return target;
} | [
"function",
"mixin",
"(",
"target",
")",
"{",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"1",
")",
".",
"forEach",
"(",
"function",
"forEach",
"(",
"o",
")",
"{",
"Object",
".",
"getOwnPropertyNames",
"(",
"o",
")",
".",
"forEach",
"(",
"function",
"eachAttr",
"(",
"attr",
")",
"{",
"Object",
".",
"defineProperty",
"(",
"target",
",",
"attr",
",",
"Object",
".",
"getOwnPropertyDescriptor",
"(",
"o",
",",
"attr",
")",
")",
";",
"}",
")",
";",
"}",
")",
";",
"return",
"target",
";",
"}"
]
| Mix multiple objects in to one single object that contains the properties of
all given objects. This assumes objects that are not nested deeply and it
correctly transfers objects that were created using `Object.defineProperty`.
@returns {Object} target
@api public | [
"Mix",
"multiple",
"objects",
"in",
"to",
"one",
"single",
"object",
"that",
"contains",
"the",
"properties",
"of",
"all",
"given",
"objects",
".",
"This",
"assumes",
"objects",
"that",
"are",
"not",
"nested",
"deeply",
"and",
"it",
"correctly",
"transfers",
"objects",
"that",
"were",
"created",
"using",
"Object",
".",
"defineProperty",
"."
]
| 238137e3d1b8288ff5d7529c3cbcdd371888c26b | https://github.com/bigpipe/predefine/blob/238137e3d1b8288ff5d7529c3cbcdd371888c26b/index.js#L206-L214 |
41,728 | bigpipe/predefine | index.js | each | function each(collection, iterator, context) {
if (arguments.length === 1) {
iterator = collection;
collection = this;
}
var isArray = Array.isArray(collection || this)
, length = collection.length
, i = 0
, value;
if (context) {
if (isArray) {
for (; i < length; i++) {
value = iterator.apply(collection[ i ], context);
if (value === false) break;
}
} else {
for (i in collection) {
value = iterator.apply(collection[ i ], context);
if (value === false) break;
}
}
} else {
if (isArray) {
for (; i < length; i++) {
value = iterator.call(collection[i], i, collection[i]);
if (value === false) break;
}
} else {
for (i in collection) {
value = iterator.call(collection[i], i, collection[i]);
if (value === false) break;
}
}
}
return this;
} | javascript | function each(collection, iterator, context) {
if (arguments.length === 1) {
iterator = collection;
collection = this;
}
var isArray = Array.isArray(collection || this)
, length = collection.length
, i = 0
, value;
if (context) {
if (isArray) {
for (; i < length; i++) {
value = iterator.apply(collection[ i ], context);
if (value === false) break;
}
} else {
for (i in collection) {
value = iterator.apply(collection[ i ], context);
if (value === false) break;
}
}
} else {
if (isArray) {
for (; i < length; i++) {
value = iterator.call(collection[i], i, collection[i]);
if (value === false) break;
}
} else {
for (i in collection) {
value = iterator.call(collection[i], i, collection[i]);
if (value === false) break;
}
}
}
return this;
} | [
"function",
"each",
"(",
"collection",
",",
"iterator",
",",
"context",
")",
"{",
"if",
"(",
"arguments",
".",
"length",
"===",
"1",
")",
"{",
"iterator",
"=",
"collection",
";",
"collection",
"=",
"this",
";",
"}",
"var",
"isArray",
"=",
"Array",
".",
"isArray",
"(",
"collection",
"||",
"this",
")",
",",
"length",
"=",
"collection",
".",
"length",
",",
"i",
"=",
"0",
",",
"value",
";",
"if",
"(",
"context",
")",
"{",
"if",
"(",
"isArray",
")",
"{",
"for",
"(",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"value",
"=",
"iterator",
".",
"apply",
"(",
"collection",
"[",
"i",
"]",
",",
"context",
")",
";",
"if",
"(",
"value",
"===",
"false",
")",
"break",
";",
"}",
"}",
"else",
"{",
"for",
"(",
"i",
"in",
"collection",
")",
"{",
"value",
"=",
"iterator",
".",
"apply",
"(",
"collection",
"[",
"i",
"]",
",",
"context",
")",
";",
"if",
"(",
"value",
"===",
"false",
")",
"break",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"isArray",
")",
"{",
"for",
"(",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"value",
"=",
"iterator",
".",
"call",
"(",
"collection",
"[",
"i",
"]",
",",
"i",
",",
"collection",
"[",
"i",
"]",
")",
";",
"if",
"(",
"value",
"===",
"false",
")",
"break",
";",
"}",
"}",
"else",
"{",
"for",
"(",
"i",
"in",
"collection",
")",
"{",
"value",
"=",
"iterator",
".",
"call",
"(",
"collection",
"[",
"i",
"]",
",",
"i",
",",
"collection",
"[",
"i",
"]",
")",
";",
"if",
"(",
"value",
"===",
"false",
")",
"break",
";",
"}",
"}",
"}",
"return",
"this",
";",
"}"
]
| Iterate over a collection. When you return false, it will stop the iteration.
@param {Mixed} collection Either an Array or Object.
@param {Function} iterator Function to be called for each item.
@param {Mixed} context The context for the iterator.
@api public | [
"Iterate",
"over",
"a",
"collection",
".",
"When",
"you",
"return",
"false",
"it",
"will",
"stop",
"the",
"iteration",
"."
]
| 238137e3d1b8288ff5d7529c3cbcdd371888c26b | https://github.com/bigpipe/predefine/blob/238137e3d1b8288ff5d7529c3cbcdd371888c26b/index.js#L223-L261 |
41,729 | vigour-io/postcssify | lib/index.js | init | function init (file) {
if (!postcssify.entry) {
if (dest) {
log.info('output: %s', dest)
process.on('beforeExit', () => {
if (!postcssify.complete) {
postcssify.complete = true
bundle()
}
})
postcssify.entry = file
} else {
return
}
}
return true
} | javascript | function init (file) {
if (!postcssify.entry) {
if (dest) {
log.info('output: %s', dest)
process.on('beforeExit', () => {
if (!postcssify.complete) {
postcssify.complete = true
bundle()
}
})
postcssify.entry = file
} else {
return
}
}
return true
} | [
"function",
"init",
"(",
"file",
")",
"{",
"if",
"(",
"!",
"postcssify",
".",
"entry",
")",
"{",
"if",
"(",
"dest",
")",
"{",
"log",
".",
"info",
"(",
"'output: %s'",
",",
"dest",
")",
"process",
".",
"on",
"(",
"'beforeExit'",
",",
"(",
")",
"=>",
"{",
"if",
"(",
"!",
"postcssify",
".",
"complete",
")",
"{",
"postcssify",
".",
"complete",
"=",
"true",
"bundle",
"(",
")",
"}",
"}",
")",
"postcssify",
".",
"entry",
"=",
"file",
"}",
"else",
"{",
"return",
"}",
"}",
"return",
"true",
"}"
]
| init => returns false if no dest is defined | [
"init",
"=",
">",
"returns",
"false",
"if",
"no",
"dest",
"is",
"defined"
]
| f7b1c7fc31bba4d0bc9c59eba0caf6eccabc1a66 | https://github.com/vigour-io/postcssify/blob/f7b1c7fc31bba4d0bc9c59eba0caf6eccabc1a66/lib/index.js#L68-L84 |
41,730 | vigour-io/postcssify | lib/index.js | bundle | function bundle () {
const ordered = order(deps[postcssify.entry], [], {})
const l = ordered.length
let ast
for (let i = 0; i < l; i++) {
const file = ordered[i]
const style = styles[file]
if (style === void 0) {
return
} else {
if (!ast) {
ast = style.clone()
} else {
ast.append(style)
}
}
}
if (ast) {
postcss(processors).process(ast.toResult(), { to: dest, map: true }).then((result) => {
fs.writeFile(dest, result.css, (err) => {
if (err) {
throw err
} else {
log.info('updated: %s', dest)
}
})
}).catch((err) => log.error(err))
}
} | javascript | function bundle () {
const ordered = order(deps[postcssify.entry], [], {})
const l = ordered.length
let ast
for (let i = 0; i < l; i++) {
const file = ordered[i]
const style = styles[file]
if (style === void 0) {
return
} else {
if (!ast) {
ast = style.clone()
} else {
ast.append(style)
}
}
}
if (ast) {
postcss(processors).process(ast.toResult(), { to: dest, map: true }).then((result) => {
fs.writeFile(dest, result.css, (err) => {
if (err) {
throw err
} else {
log.info('updated: %s', dest)
}
})
}).catch((err) => log.error(err))
}
} | [
"function",
"bundle",
"(",
")",
"{",
"const",
"ordered",
"=",
"order",
"(",
"deps",
"[",
"postcssify",
".",
"entry",
"]",
",",
"[",
"]",
",",
"{",
"}",
")",
"const",
"l",
"=",
"ordered",
".",
"length",
"let",
"ast",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"const",
"file",
"=",
"ordered",
"[",
"i",
"]",
"const",
"style",
"=",
"styles",
"[",
"file",
"]",
"if",
"(",
"style",
"===",
"void",
"0",
")",
"{",
"return",
"}",
"else",
"{",
"if",
"(",
"!",
"ast",
")",
"{",
"ast",
"=",
"style",
".",
"clone",
"(",
")",
"}",
"else",
"{",
"ast",
".",
"append",
"(",
"style",
")",
"}",
"}",
"}",
"if",
"(",
"ast",
")",
"{",
"postcss",
"(",
"processors",
")",
".",
"process",
"(",
"ast",
".",
"toResult",
"(",
")",
",",
"{",
"to",
":",
"dest",
",",
"map",
":",
"true",
"}",
")",
".",
"then",
"(",
"(",
"result",
")",
"=>",
"{",
"fs",
".",
"writeFile",
"(",
"dest",
",",
"result",
".",
"css",
",",
"(",
"err",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"throw",
"err",
"}",
"else",
"{",
"log",
".",
"info",
"(",
"'updated: %s'",
",",
"dest",
")",
"}",
"}",
")",
"}",
")",
".",
"catch",
"(",
"(",
"err",
")",
"=>",
"log",
".",
"error",
"(",
"err",
")",
")",
"}",
"}"
]
| concat and bundle css | [
"concat",
"and",
"bundle",
"css"
]
| f7b1c7fc31bba4d0bc9c59eba0caf6eccabc1a66 | https://github.com/vigour-io/postcssify/blob/f7b1c7fc31bba4d0bc9c59eba0caf6eccabc1a66/lib/index.js#L301-L329 |
41,731 | vigour-io/postcssify | lib/index.js | order | function order (d, arr, visited) {
for (let i in d) {
if (!visited[i]) {
let obj = d[i]
visited[i] = true
arr = arr.concat(order(obj, [], visited))
if (css(i)) {
arr.push(i)
}
}
}
return arr
} | javascript | function order (d, arr, visited) {
for (let i in d) {
if (!visited[i]) {
let obj = d[i]
visited[i] = true
arr = arr.concat(order(obj, [], visited))
if (css(i)) {
arr.push(i)
}
}
}
return arr
} | [
"function",
"order",
"(",
"d",
",",
"arr",
",",
"visited",
")",
"{",
"for",
"(",
"let",
"i",
"in",
"d",
")",
"{",
"if",
"(",
"!",
"visited",
"[",
"i",
"]",
")",
"{",
"let",
"obj",
"=",
"d",
"[",
"i",
"]",
"visited",
"[",
"i",
"]",
"=",
"true",
"arr",
"=",
"arr",
".",
"concat",
"(",
"order",
"(",
"obj",
",",
"[",
"]",
",",
"visited",
")",
")",
"if",
"(",
"css",
"(",
"i",
")",
")",
"{",
"arr",
".",
"push",
"(",
"i",
")",
"}",
"}",
"}",
"return",
"arr",
"}"
]
| walk deps and return ordered array | [
"walk",
"deps",
"and",
"return",
"ordered",
"array"
]
| f7b1c7fc31bba4d0bc9c59eba0caf6eccabc1a66 | https://github.com/vigour-io/postcssify/blob/f7b1c7fc31bba4d0bc9c59eba0caf6eccabc1a66/lib/index.js#L352-L364 |
41,732 | MarkGriffiths/string | src/index.js | pad | function pad(str, length, char) {
return new BespokeString(str).pad(length, char).toString()
} | javascript | function pad(str, length, char) {
return new BespokeString(str).pad(length, char).toString()
} | [
"function",
"pad",
"(",
"str",
",",
"length",
",",
"char",
")",
"{",
"return",
"new",
"BespokeString",
"(",
"str",
")",
".",
"pad",
"(",
"length",
",",
"char",
")",
".",
"toString",
"(",
")",
"}"
]
| Helper method for padding a string.
@param {String} str The string to pad.
@param {Number} length Target length.
@param {String} char Character to use for pad.
@return {String} The padded string. | [
"Helper",
"method",
"for",
"padding",
"a",
"string",
"."
]
| 699a4404d53501c719c34e649a34376a66ff8c62 | https://github.com/MarkGriffiths/string/blob/699a4404d53501c719c34e649a34376a66ff8c62/src/index.js#L133-L135 |
41,733 | LeisureLink/magicbus | lib/queue-machine.js | function(callback, options) {
return new Promise((resolve, reject) => {
let op = () => {
return this.channel.subscribe(callback, options)
.then(resolve, reject);
};
this.on('failed', function(err) {
reject(err);
}).once();
this.handle('subscribe', op);
});
} | javascript | function(callback, options) {
return new Promise((resolve, reject) => {
let op = () => {
return this.channel.subscribe(callback, options)
.then(resolve, reject);
};
this.on('failed', function(err) {
reject(err);
}).once();
this.handle('subscribe', op);
});
} | [
"function",
"(",
"callback",
",",
"options",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"let",
"op",
"=",
"(",
")",
"=>",
"{",
"return",
"this",
".",
"channel",
".",
"subscribe",
"(",
"callback",
",",
"options",
")",
".",
"then",
"(",
"resolve",
",",
"reject",
")",
";",
"}",
";",
"this",
".",
"on",
"(",
"'failed'",
",",
"function",
"(",
"err",
")",
"{",
"reject",
"(",
"err",
")",
";",
"}",
")",
".",
"once",
"(",
")",
";",
"this",
".",
"handle",
"(",
"'subscribe'",
",",
"op",
")",
";",
"}",
")",
";",
"}"
]
| Subscribe to the queue
@public
@memberOf QueueMachine.prototype
@param {Function} callback - the function to be called with each message
@param {Object} options - details in consuming from the queue
@param {Number} options.limit - the channel prefetch limit
@param {bool} options.noBatch - if true, ack/nack/reject operations will execute immediately and not be batched
@param {bool} options.noAck - if true, the broker won't expect an acknowledgement of messages delivered to this consumer; i.e., it will dequeue messages as soon as they've been sent down the wire. Defaults to false (i.e., you will be expected to acknowledge messages).
@param {String} options.consumerTag - a name which the server will use to distinguish message deliveries for the consumer; mustn't be already in use on the channel. It's usually easier to omit this, in which case the server will create a random name and supply it in the reply.
@param {bool} options.exclusive - if true, the broker won't let anyone else consume from this queue; if there already is a consumer, there goes your channel (so usually only useful if you've made a 'private' queue by letting the server choose its name).
@param {Number} options.priority - gives a priority to the consumer; higher priority consumers get messages in preference to lower priority consumers. See this RabbitMQ extension's documentation
@param {Object} options.arguments - arbitrary arguments. Go to town.
@returns {Promise} a promise that is fulfilled when the subscription is active | [
"Subscribe",
"to",
"the",
"queue"
]
| 0370c38ebb8c7917cfd3894263d734aefc2d3d29 | https://github.com/LeisureLink/magicbus/blob/0370c38ebb8c7917cfd3894263d734aefc2d3d29/lib/queue-machine.js#L92-L103 |
|
41,734 | cronvel/kung-fig-expression | lib/Expression.js | parseFnKeyConst | function parseFnKeyConst( str_ , runtime ) {
var separatorIndex = nextSeparator( str_ , runtime ) ;
var str = str_.slice( runtime.i , separatorIndex ) ;
//console.log( 'str before:' , str_ ) ;
//console.log( 'str after:' , str ) ;
//var indexOf ;
//str = str.slice( runtime.i , runtime.iEndOfLine ) ;
//if ( ( indexOf = str.indexOf( ' ' ) ) !== -1 ) { str = str.slice( 0 , indexOf ) ; }
runtime.i += str.length ;
if (
str_[ separatorIndex ] === ':' ||
( str_[ separatorIndex ] === ' ' && afterSpacesChar( str_ , runtime , separatorIndex ) === ':' )
) {
// This is a key, return the unquoted string
return str ;
}
else if ( str in common.constants ) {
return common.constants[ str ] ;
}
else if ( fnOperators[ str ] ) {
return fnOperators[ str ] ;
}
else if ( str in expressionConstants ) {
return expressionConstants[ str ] ;
}
else if ( runtime.operators[ str ] ) {
return runtime.operators[ str ] ;
}
else if ( str in runtime.constants ) {
return runtime.constants[ str ] ;
}
throw new SyntaxError( "Unexpected '" + str + "' in expression" ) ;
} | javascript | function parseFnKeyConst( str_ , runtime ) {
var separatorIndex = nextSeparator( str_ , runtime ) ;
var str = str_.slice( runtime.i , separatorIndex ) ;
//console.log( 'str before:' , str_ ) ;
//console.log( 'str after:' , str ) ;
//var indexOf ;
//str = str.slice( runtime.i , runtime.iEndOfLine ) ;
//if ( ( indexOf = str.indexOf( ' ' ) ) !== -1 ) { str = str.slice( 0 , indexOf ) ; }
runtime.i += str.length ;
if (
str_[ separatorIndex ] === ':' ||
( str_[ separatorIndex ] === ' ' && afterSpacesChar( str_ , runtime , separatorIndex ) === ':' )
) {
// This is a key, return the unquoted string
return str ;
}
else if ( str in common.constants ) {
return common.constants[ str ] ;
}
else if ( fnOperators[ str ] ) {
return fnOperators[ str ] ;
}
else if ( str in expressionConstants ) {
return expressionConstants[ str ] ;
}
else if ( runtime.operators[ str ] ) {
return runtime.operators[ str ] ;
}
else if ( str in runtime.constants ) {
return runtime.constants[ str ] ;
}
throw new SyntaxError( "Unexpected '" + str + "' in expression" ) ;
} | [
"function",
"parseFnKeyConst",
"(",
"str_",
",",
"runtime",
")",
"{",
"var",
"separatorIndex",
"=",
"nextSeparator",
"(",
"str_",
",",
"runtime",
")",
";",
"var",
"str",
"=",
"str_",
".",
"slice",
"(",
"runtime",
".",
"i",
",",
"separatorIndex",
")",
";",
"//console.log( 'str before:' , str_ ) ;",
"//console.log( 'str after:' , str ) ;",
"//var indexOf ;",
"//str = str.slice( runtime.i , runtime.iEndOfLine ) ;",
"//if ( ( indexOf = str.indexOf( ' ' ) ) !== -1 ) { str = str.slice( 0 , indexOf ) ; }",
"runtime",
".",
"i",
"+=",
"str",
".",
"length",
";",
"if",
"(",
"str_",
"[",
"separatorIndex",
"]",
"===",
"':'",
"||",
"(",
"str_",
"[",
"separatorIndex",
"]",
"===",
"' '",
"&&",
"afterSpacesChar",
"(",
"str_",
",",
"runtime",
",",
"separatorIndex",
")",
"===",
"':'",
")",
")",
"{",
"// This is a key, return the unquoted string",
"return",
"str",
";",
"}",
"else",
"if",
"(",
"str",
"in",
"common",
".",
"constants",
")",
"{",
"return",
"common",
".",
"constants",
"[",
"str",
"]",
";",
"}",
"else",
"if",
"(",
"fnOperators",
"[",
"str",
"]",
")",
"{",
"return",
"fnOperators",
"[",
"str",
"]",
";",
"}",
"else",
"if",
"(",
"str",
"in",
"expressionConstants",
")",
"{",
"return",
"expressionConstants",
"[",
"str",
"]",
";",
"}",
"else",
"if",
"(",
"runtime",
".",
"operators",
"[",
"str",
"]",
")",
"{",
"return",
"runtime",
".",
"operators",
"[",
"str",
"]",
";",
"}",
"else",
"if",
"(",
"str",
"in",
"runtime",
".",
"constants",
")",
"{",
"return",
"runtime",
".",
"constants",
"[",
"str",
"]",
";",
"}",
"throw",
"new",
"SyntaxError",
"(",
"\"Unexpected '\"",
"+",
"str",
"+",
"\"' in expression\"",
")",
";",
"}"
]
| An identifier that is a function, a key or a constant | [
"An",
"identifier",
"that",
"is",
"a",
"function",
"a",
"key",
"or",
"a",
"constant"
]
| b9aae3aa2e3a5fdfc13fb6c76794526764485c5b | https://github.com/cronvel/kung-fig-expression/blob/b9aae3aa2e3a5fdfc13fb6c76794526764485c5b/lib/Expression.js#L668-L705 |
41,735 | vamship/config | src/config.js | function(scope) {
if (!_argValidator.checkString(scope)) {
scope = _applicationScope;
}
let config = _configCache[scope];
if (!config) {
const data = _deepDefaults(
_deepDefaults({}, _config[scope]),
_config.default
);
config = new AppConfig(data);
if (_isInitialized) {
_configCache[scope] = config;
}
}
return config;
} | javascript | function(scope) {
if (!_argValidator.checkString(scope)) {
scope = _applicationScope;
}
let config = _configCache[scope];
if (!config) {
const data = _deepDefaults(
_deepDefaults({}, _config[scope]),
_config.default
);
config = new AppConfig(data);
if (_isInitialized) {
_configCache[scope] = config;
}
}
return config;
} | [
"function",
"(",
"scope",
")",
"{",
"if",
"(",
"!",
"_argValidator",
".",
"checkString",
"(",
"scope",
")",
")",
"{",
"scope",
"=",
"_applicationScope",
";",
"}",
"let",
"config",
"=",
"_configCache",
"[",
"scope",
"]",
";",
"if",
"(",
"!",
"config",
")",
"{",
"const",
"data",
"=",
"_deepDefaults",
"(",
"_deepDefaults",
"(",
"{",
"}",
",",
"_config",
"[",
"scope",
"]",
")",
",",
"_config",
".",
"default",
")",
";",
"config",
"=",
"new",
"AppConfig",
"(",
"data",
")",
";",
"if",
"(",
"_isInitialized",
")",
"{",
"_configCache",
"[",
"scope",
"]",
"=",
"config",
";",
"}",
"}",
"return",
"config",
";",
"}"
]
| Returns a configuration object that is scoped to a specific environment.
This configuration object will return default application configuration
properties, overridden by environment speicific values.
@param {String} [scope=<default scope>] The name of the environment for
which the application configuration object will be returned. If
omitted, this value will be defaulted to the environment
set by invoking
[setAppScope()]{@link module:config.setAppScope}. If this
method was never invoked, the default scope is "default".
@return {AppConfig} A configuration object that can be used to query for
configuration parameters. | [
"Returns",
"a",
"configuration",
"object",
"that",
"is",
"scoped",
"to",
"a",
"specific",
"environment",
".",
"This",
"configuration",
"object",
"will",
"return",
"default",
"application",
"configuration",
"properties",
"overridden",
"by",
"environment",
"speicific",
"values",
"."
]
| 4678290c4c272efcbc629c91031f867a85d92781 | https://github.com/vamship/config/blob/4678290c4c272efcbc629c91031f867a85d92781/src/config.js#L155-L173 |
|
41,736 | veo-labs/openveo-api | lib/multipart/MultipartParser.js | MultipartParser | function MultipartParser(request, fileFields, limits) {
Object.defineProperties(this, {
/**
* The HTTP request containing a multipart body.
*
* @property request
* @type Request
* @final
*/
request: {value: request},
/**
* The list of file field descriptors.
*
* @property fileFields
* @type Array
* @final
*/
fileFields: {value: fileFields || []},
/**
* Multipart limits configuration.
*
* @property limits
* @type Object
* @final
*/
limits: {value: limits},
/**
* Final paths of files detected in multipart body.
*
* @property detectedFilesPaths
* @type Array
* @final
*/
detectedFilesPaths: {value: []}
});
if (!this.request)
throw new TypeError('A MultipartParser needs a request');
} | javascript | function MultipartParser(request, fileFields, limits) {
Object.defineProperties(this, {
/**
* The HTTP request containing a multipart body.
*
* @property request
* @type Request
* @final
*/
request: {value: request},
/**
* The list of file field descriptors.
*
* @property fileFields
* @type Array
* @final
*/
fileFields: {value: fileFields || []},
/**
* Multipart limits configuration.
*
* @property limits
* @type Object
* @final
*/
limits: {value: limits},
/**
* Final paths of files detected in multipart body.
*
* @property detectedFilesPaths
* @type Array
* @final
*/
detectedFilesPaths: {value: []}
});
if (!this.request)
throw new TypeError('A MultipartParser needs a request');
} | [
"function",
"MultipartParser",
"(",
"request",
",",
"fileFields",
",",
"limits",
")",
"{",
"Object",
".",
"defineProperties",
"(",
"this",
",",
"{",
"/**\n * The HTTP request containing a multipart body.\n *\n * @property request\n * @type Request\n * @final\n */",
"request",
":",
"{",
"value",
":",
"request",
"}",
",",
"/**\n * The list of file field descriptors.\n *\n * @property fileFields\n * @type Array\n * @final\n */",
"fileFields",
":",
"{",
"value",
":",
"fileFields",
"||",
"[",
"]",
"}",
",",
"/**\n * Multipart limits configuration.\n *\n * @property limits\n * @type Object\n * @final\n */",
"limits",
":",
"{",
"value",
":",
"limits",
"}",
",",
"/**\n * Final paths of files detected in multipart body.\n *\n * @property detectedFilesPaths\n * @type Array\n * @final\n */",
"detectedFilesPaths",
":",
"{",
"value",
":",
"[",
"]",
"}",
"}",
")",
";",
"if",
"(",
"!",
"this",
".",
"request",
")",
"throw",
"new",
"TypeError",
"(",
"'A MultipartParser needs a request'",
")",
";",
"}"
]
| Defines a multipart parser to parse multipart requests.
Use MultipartParser to get fields from multipart requests (including files).
@example
// Get multipart parser
var MultipartParser = require('@openveo/api').multipart.MultipartParser;
// Create a request parser expecting several files: files in photos "field" and a file in "videos" field
var parser = new MultipartParser(request, [
{
name: 'photos',
destinationPath: '/tmp/photos',
maxCount: 2,
unique: true
},
{
name: 'videos',
destinationPath: '/tmp/videos',
maxCount: 1,
unique: false
}
], {
fieldNameSize: 100,
fieldSize: 1024,
fields: Infinity,
fileSize: Infinity,
files: Infinity,
parts: Infinity,
headerPairs: 2000
});
parser.parse(function(error) {
if (error)
console.log('Something went wrong when uploading');
else
console.log(request.files);
});
@class MultipartParser
@constructor
@param {Request} request HTTP Request containing a multipart body, it will be altered with parsing properties
@param {Array} fileFields A list of file field descriptors with:
- {String} name The field name which contains the file
- {String} destinationPath The destination directory where the file will be uploaded
- {Number} [maxCount] The maximum number of files allowed for this field
- {Boolean} [unique] true to generate unique file names for files corresponding to this field, false to generate a
unique id only if a file with the same name already exists in the destination folder
@param {Object} [limits] Multipart limits configuration, for more information about
available limits see Multer documentation (https://www.npmjs.com/package/multer#limits).
@throws {TypeError} If request is not as expected | [
"Defines",
"a",
"multipart",
"parser",
"to",
"parse",
"multipart",
"requests",
"."
]
| 493a811e9a5ba4d3e14910facaa7452caba1ab38 | https://github.com/veo-labs/openveo-api/blob/493a811e9a5ba4d3e14910facaa7452caba1ab38/lib/multipart/MultipartParser.js#L67-L110 |
41,737 | Bartvds/ministyle | lib/common.js | plain | function plain() {
var mw = core.base();
mw.plain = function (str) {
return String(str);
};
mw.error = function (str) {
return mw.plain(str);
};
mw.warning = function (str) {
return mw.plain(str);
};
mw.success = function (str) {
return mw.plain(str);
};
mw.accent = function (str) {
return mw.plain(str);
};
mw.muted = function (str) {
return mw.plain(str);
};
mw.toString = function () {
return '<ministyle-plain>';
};
return mw;
} | javascript | function plain() {
var mw = core.base();
mw.plain = function (str) {
return String(str);
};
mw.error = function (str) {
return mw.plain(str);
};
mw.warning = function (str) {
return mw.plain(str);
};
mw.success = function (str) {
return mw.plain(str);
};
mw.accent = function (str) {
return mw.plain(str);
};
mw.muted = function (str) {
return mw.plain(str);
};
mw.toString = function () {
return '<ministyle-plain>';
};
return mw;
} | [
"function",
"plain",
"(",
")",
"{",
"var",
"mw",
"=",
"core",
".",
"base",
"(",
")",
";",
"mw",
".",
"plain",
"=",
"function",
"(",
"str",
")",
"{",
"return",
"String",
"(",
"str",
")",
";",
"}",
";",
"mw",
".",
"error",
"=",
"function",
"(",
"str",
")",
"{",
"return",
"mw",
".",
"plain",
"(",
"str",
")",
";",
"}",
";",
"mw",
".",
"warning",
"=",
"function",
"(",
"str",
")",
"{",
"return",
"mw",
".",
"plain",
"(",
"str",
")",
";",
"}",
";",
"mw",
".",
"success",
"=",
"function",
"(",
"str",
")",
"{",
"return",
"mw",
".",
"plain",
"(",
"str",
")",
";",
"}",
";",
"mw",
".",
"accent",
"=",
"function",
"(",
"str",
")",
"{",
"return",
"mw",
".",
"plain",
"(",
"str",
")",
";",
"}",
";",
"mw",
".",
"muted",
"=",
"function",
"(",
"str",
")",
"{",
"return",
"mw",
".",
"plain",
"(",
"str",
")",
";",
"}",
";",
"mw",
".",
"toString",
"=",
"function",
"(",
")",
"{",
"return",
"'<ministyle-plain>'",
";",
"}",
";",
"return",
"mw",
";",
"}"
]
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - plain text | [
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"plain",
"text"
]
| 92681e81d4c93faddd4e5d1d6edf44990b3a9e68 | https://github.com/Bartvds/ministyle/blob/92681e81d4c93faddd4e5d1d6edf44990b3a9e68/lib/common.js#L50-L75 |
41,738 | Bartvds/ministyle | lib/common.js | empty | function empty() {
var mw = plain();
mw.plain = function (str) {
str = String(str);
var ret = '';
for (var i = 0; i < str.length; i++) {
ret += ' ';
}
return ret;
};
mw.toString = function () {
return '<ministyle-empty>';
};
return mw;
} | javascript | function empty() {
var mw = plain();
mw.plain = function (str) {
str = String(str);
var ret = '';
for (var i = 0; i < str.length; i++) {
ret += ' ';
}
return ret;
};
mw.toString = function () {
return '<ministyle-empty>';
};
return mw;
} | [
"function",
"empty",
"(",
")",
"{",
"var",
"mw",
"=",
"plain",
"(",
")",
";",
"mw",
".",
"plain",
"=",
"function",
"(",
"str",
")",
"{",
"str",
"=",
"String",
"(",
"str",
")",
";",
"var",
"ret",
"=",
"''",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"str",
".",
"length",
";",
"i",
"++",
")",
"{",
"ret",
"+=",
"' '",
";",
"}",
"return",
"ret",
";",
"}",
";",
"mw",
".",
"toString",
"=",
"function",
"(",
")",
"{",
"return",
"'<ministyle-empty>'",
";",
"}",
";",
"return",
"mw",
";",
"}"
]
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - return empty spaces | [
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"return",
"empty",
"spaces"
]
| 92681e81d4c93faddd4e5d1d6edf44990b3a9e68 | https://github.com/Bartvds/ministyle/blob/92681e81d4c93faddd4e5d1d6edf44990b3a9e68/lib/common.js#L114-L129 |
41,739 | feedhenry/fh-component-metrics | lib/clients/influxdb.js | influxUdp | function influxUdp(opts) {
BaseClient.apply(this, arguments);
opts = opts || {};
this.host = opts.host || '127.0.0.1';
this.port = opts.port || 4444;
this.socket = dgram.createSocket('udp4');
} | javascript | function influxUdp(opts) {
BaseClient.apply(this, arguments);
opts = opts || {};
this.host = opts.host || '127.0.0.1';
this.port = opts.port || 4444;
this.socket = dgram.createSocket('udp4');
} | [
"function",
"influxUdp",
"(",
"opts",
")",
"{",
"BaseClient",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"opts",
"=",
"opts",
"||",
"{",
"}",
";",
"this",
".",
"host",
"=",
"opts",
".",
"host",
"||",
"'127.0.0.1'",
";",
"this",
".",
"port",
"=",
"opts",
".",
"port",
"||",
"4444",
";",
"this",
".",
"socket",
"=",
"dgram",
".",
"createSocket",
"(",
"'udp4'",
")",
";",
"}"
]
| A client that can send data to Influxdb backend via UDP
@param {Object} opts options about the influxdb backend
@param {String} opts.host the host of the influxdb. Default is 127.0.0.1
@param {Number} opts.port the port of the UDP port of influxdb. Default is 4444.
@param {Number} opts.sendQueueConcurrency specify the concurrency when send data to influxdb. Default is 10. | [
"A",
"client",
"that",
"can",
"send",
"data",
"to",
"Influxdb",
"backend",
"via",
"UDP"
]
| c97a1a82ff0144f2a7c2abecbc22084fade1cbc8 | https://github.com/feedhenry/fh-component-metrics/blob/c97a1a82ff0144f2a7c2abecbc22084fade1cbc8/lib/clients/influxdb.js#L13-L19 |
41,740 | Mammut-FE/nejm | src/util/dispatcher/dispatcher.js | function(_url,_href){
if (!_url) return;
var _info = location.parse(_url);
this._$dispatchEvent('onbeforechange',_info);
var _umi = this.__doRewriteUMI(
_info.path,_href||_info.href
);
return this.__groups[this.__pbseed]._$hasUMI(_umi);
} | javascript | function(_url,_href){
if (!_url) return;
var _info = location.parse(_url);
this._$dispatchEvent('onbeforechange',_info);
var _umi = this.__doRewriteUMI(
_info.path,_href||_info.href
);
return this.__groups[this.__pbseed]._$hasUMI(_umi);
} | [
"function",
"(",
"_url",
",",
"_href",
")",
"{",
"if",
"(",
"!",
"_url",
")",
"return",
";",
"var",
"_info",
"=",
"location",
".",
"parse",
"(",
"_url",
")",
";",
"this",
".",
"_$dispatchEvent",
"(",
"'onbeforechange'",
",",
"_info",
")",
";",
"var",
"_umi",
"=",
"this",
".",
"__doRewriteUMI",
"(",
"_info",
".",
"path",
",",
"_href",
"||",
"_info",
".",
"href",
")",
";",
"return",
"this",
".",
"__groups",
"[",
"this",
".",
"__pbseed",
"]",
".",
"_$hasUMI",
"(",
"_umi",
")",
";",
"}"
]
| check event need delegated | [
"check",
"event",
"need",
"delegated"
]
| dfc09ac66a8d67620a7aea65e34d8a179976b3fb | https://github.com/Mammut-FE/nejm/blob/dfc09ac66a8d67620a7aea65e34d8a179976b3fb/src/util/dispatcher/dispatcher.js#L538-L546 |
|
41,741 | Mammut-FE/nejm | src/util/dispatcher/dispatcher.js | function(_target,_message){
var _from = _message.from;
while(!!_target){
if (_target._$getPath()!=_from){
_doSendMessage(_target,_message);
}
_target = _target._$getParent();
}
} | javascript | function(_target,_message){
var _from = _message.from;
while(!!_target){
if (_target._$getPath()!=_from){
_doSendMessage(_target,_message);
}
_target = _target._$getParent();
}
} | [
"function",
"(",
"_target",
",",
"_message",
")",
"{",
"var",
"_from",
"=",
"_message",
".",
"from",
";",
"while",
"(",
"!",
"!",
"_target",
")",
"{",
"if",
"(",
"_target",
".",
"_$getPath",
"(",
")",
"!=",
"_from",
")",
"{",
"_doSendMessage",
"(",
"_target",
",",
"_message",
")",
";",
"}",
"_target",
"=",
"_target",
".",
"_$getParent",
"(",
")",
";",
"}",
"}"
]
| send message to every node in target path | [
"send",
"message",
"to",
"every",
"node",
"in",
"target",
"path"
]
| dfc09ac66a8d67620a7aea65e34d8a179976b3fb | https://github.com/Mammut-FE/nejm/blob/dfc09ac66a8d67620a7aea65e34d8a179976b3fb/src/util/dispatcher/dispatcher.js#L983-L991 |
|
41,742 | Mammut-FE/nejm | src/util/dispatcher/dispatcher.js | function(_target,_message){
var _from = _message.from;
_t3._$breadthFirstSearch(
_target,function(_node){
if (_node._$getPath()!=_from){
_doSendMessage(_node,_message);
}
}
);
} | javascript | function(_target,_message){
var _from = _message.from;
_t3._$breadthFirstSearch(
_target,function(_node){
if (_node._$getPath()!=_from){
_doSendMessage(_node,_message);
}
}
);
} | [
"function",
"(",
"_target",
",",
"_message",
")",
"{",
"var",
"_from",
"=",
"_message",
".",
"from",
";",
"_t3",
".",
"_$breadthFirstSearch",
"(",
"_target",
",",
"function",
"(",
"_node",
")",
"{",
"if",
"(",
"_node",
".",
"_$getPath",
"(",
")",
"!=",
"_from",
")",
"{",
"_doSendMessage",
"(",
"_node",
",",
"_message",
")",
";",
"}",
"}",
")",
";",
"}"
]
| broadcast to all target descendants | [
"broadcast",
"to",
"all",
"target",
"descendants"
]
| dfc09ac66a8d67620a7aea65e34d8a179976b3fb | https://github.com/Mammut-FE/nejm/blob/dfc09ac66a8d67620a7aea65e34d8a179976b3fb/src/util/dispatcher/dispatcher.js#L993-L1002 |
|
41,743 | ibm-bluemix-mobile-services/bms-mca-token-validation-strategy | lib/util/token-decoder.js | doTokenValidation | function doTokenValidation(token,publicKey,appId) {
var parts = token.split('.');
if (parts.length < 3) {
ibmlogger.getLogger().debug("The token decode failure details:", token);
return Q.reject(RejectionMessage("The token is malformed.", token,RejectionMessage.INVALID_TOKEN_ERROR));
}
if (parts[2].trim() === '' && publicKey) {
return Q.reject(RejectionMessage("The token missing the signature.", token,RejectionMessage.INVALID_TOKEN_ERROR));
}
var valid;
if (publicKey) {
try {
valid = jws.verify(token, publicKey);
if (!valid) {
return Q.reject(RejectionMessage("The token was verified failed with the public key.", token,RejectionMessage.INVALID_TOKEN_ERROR));
}
}
catch (e) {
return Q.reject(RejectionMessage("An error occurred when verifying the token"+e.message, token, RejectionMessage.INVALID_TOKEN_ERROR));
}
}
var decodedToken = jws.decode(token,{json:true});
if (!decodedToken) {
return Q.reject(RejectionMessage("The token was decoded failed", token, RejectionMessage.INVALID_TOKEN_ERROR));
}
var payload = decodedToken.payload;
if (payload.exp) {
if (Math.round(Date.now()) / 1000 >= payload.exp) {
return Q.reject(RejectionMessage("The token has been expired.", token, RejectionMessage.INVALID_TOKEN_ERROR));
}
}
if (payload.aud) {
if (payload.aud != appId) {
return Q.reject(RejectionMessage("The aud in token is inconsistent with the given application id."+payload.aud+","+appId, token, RejectionMessage.INVALID_TOKEN_ERROR));
}
}
/*
if (options.audience) {
if (payload.aud !== options.audience) {
return Q.reject(RejectionMessage("The audience is different from the expected aud:"+options.audience, token, RejectionMessage.INVALID_TOKEN_ERROR));
}
}
if (options.issuer) {
if (payload.iss !== options.issuer) {
return Q.reject(RejectionMessage("The issuer is different from the expected iss:"+options.issuer, token, RejectionMessage.INVALID_TOKEN_ERROR));
}
}
*/
return Q.resolve(payload);
} | javascript | function doTokenValidation(token,publicKey,appId) {
var parts = token.split('.');
if (parts.length < 3) {
ibmlogger.getLogger().debug("The token decode failure details:", token);
return Q.reject(RejectionMessage("The token is malformed.", token,RejectionMessage.INVALID_TOKEN_ERROR));
}
if (parts[2].trim() === '' && publicKey) {
return Q.reject(RejectionMessage("The token missing the signature.", token,RejectionMessage.INVALID_TOKEN_ERROR));
}
var valid;
if (publicKey) {
try {
valid = jws.verify(token, publicKey);
if (!valid) {
return Q.reject(RejectionMessage("The token was verified failed with the public key.", token,RejectionMessage.INVALID_TOKEN_ERROR));
}
}
catch (e) {
return Q.reject(RejectionMessage("An error occurred when verifying the token"+e.message, token, RejectionMessage.INVALID_TOKEN_ERROR));
}
}
var decodedToken = jws.decode(token,{json:true});
if (!decodedToken) {
return Q.reject(RejectionMessage("The token was decoded failed", token, RejectionMessage.INVALID_TOKEN_ERROR));
}
var payload = decodedToken.payload;
if (payload.exp) {
if (Math.round(Date.now()) / 1000 >= payload.exp) {
return Q.reject(RejectionMessage("The token has been expired.", token, RejectionMessage.INVALID_TOKEN_ERROR));
}
}
if (payload.aud) {
if (payload.aud != appId) {
return Q.reject(RejectionMessage("The aud in token is inconsistent with the given application id."+payload.aud+","+appId, token, RejectionMessage.INVALID_TOKEN_ERROR));
}
}
/*
if (options.audience) {
if (payload.aud !== options.audience) {
return Q.reject(RejectionMessage("The audience is different from the expected aud:"+options.audience, token, RejectionMessage.INVALID_TOKEN_ERROR));
}
}
if (options.issuer) {
if (payload.iss !== options.issuer) {
return Q.reject(RejectionMessage("The issuer is different from the expected iss:"+options.issuer, token, RejectionMessage.INVALID_TOKEN_ERROR));
}
}
*/
return Q.resolve(payload);
} | [
"function",
"doTokenValidation",
"(",
"token",
",",
"publicKey",
",",
"appId",
")",
"{",
"var",
"parts",
"=",
"token",
".",
"split",
"(",
"'.'",
")",
";",
"if",
"(",
"parts",
".",
"length",
"<",
"3",
")",
"{",
"ibmlogger",
".",
"getLogger",
"(",
")",
".",
"debug",
"(",
"\"The token decode failure details:\"",
",",
"token",
")",
";",
"return",
"Q",
".",
"reject",
"(",
"RejectionMessage",
"(",
"\"The token is malformed.\"",
",",
"token",
",",
"RejectionMessage",
".",
"INVALID_TOKEN_ERROR",
")",
")",
";",
"}",
"if",
"(",
"parts",
"[",
"2",
"]",
".",
"trim",
"(",
")",
"===",
"''",
"&&",
"publicKey",
")",
"{",
"return",
"Q",
".",
"reject",
"(",
"RejectionMessage",
"(",
"\"The token missing the signature.\"",
",",
"token",
",",
"RejectionMessage",
".",
"INVALID_TOKEN_ERROR",
")",
")",
";",
"}",
"var",
"valid",
";",
"if",
"(",
"publicKey",
")",
"{",
"try",
"{",
"valid",
"=",
"jws",
".",
"verify",
"(",
"token",
",",
"publicKey",
")",
";",
"if",
"(",
"!",
"valid",
")",
"{",
"return",
"Q",
".",
"reject",
"(",
"RejectionMessage",
"(",
"\"The token was verified failed with the public key.\"",
",",
"token",
",",
"RejectionMessage",
".",
"INVALID_TOKEN_ERROR",
")",
")",
";",
"}",
"}",
"catch",
"(",
"e",
")",
"{",
"return",
"Q",
".",
"reject",
"(",
"RejectionMessage",
"(",
"\"An error occurred when verifying the token\"",
"+",
"e",
".",
"message",
",",
"token",
",",
"RejectionMessage",
".",
"INVALID_TOKEN_ERROR",
")",
")",
";",
"}",
"}",
"var",
"decodedToken",
"=",
"jws",
".",
"decode",
"(",
"token",
",",
"{",
"json",
":",
"true",
"}",
")",
";",
"if",
"(",
"!",
"decodedToken",
")",
"{",
"return",
"Q",
".",
"reject",
"(",
"RejectionMessage",
"(",
"\"The token was decoded failed\"",
",",
"token",
",",
"RejectionMessage",
".",
"INVALID_TOKEN_ERROR",
")",
")",
";",
"}",
"var",
"payload",
"=",
"decodedToken",
".",
"payload",
";",
"if",
"(",
"payload",
".",
"exp",
")",
"{",
"if",
"(",
"Math",
".",
"round",
"(",
"Date",
".",
"now",
"(",
")",
")",
"/",
"1000",
">=",
"payload",
".",
"exp",
")",
"{",
"return",
"Q",
".",
"reject",
"(",
"RejectionMessage",
"(",
"\"The token has been expired.\"",
",",
"token",
",",
"RejectionMessage",
".",
"INVALID_TOKEN_ERROR",
")",
")",
";",
"}",
"}",
"if",
"(",
"payload",
".",
"aud",
")",
"{",
"if",
"(",
"payload",
".",
"aud",
"!=",
"appId",
")",
"{",
"return",
"Q",
".",
"reject",
"(",
"RejectionMessage",
"(",
"\"The aud in token is inconsistent with the given application id.\"",
"+",
"payload",
".",
"aud",
"+",
"\",\"",
"+",
"appId",
",",
"token",
",",
"RejectionMessage",
".",
"INVALID_TOKEN_ERROR",
")",
")",
";",
"}",
"}",
"/*\n\t if (options.audience) {\n\t\t if (payload.aud !== options.audience) {\n\t\t\t return Q.reject(RejectionMessage(\"The audience is different from the expected aud:\"+options.audience, token, RejectionMessage.INVALID_TOKEN_ERROR));\n\t\t }\n\t }\n\n\t if (options.issuer) {\n\t\t if (payload.iss !== options.issuer) {\n\t\t \treturn Q.reject(RejectionMessage(\"The issuer is different from the expected iss:\"+options.issuer, token, RejectionMessage.INVALID_TOKEN_ERROR));\n\t\t }\n\t }\n\t */",
"return",
"Q",
".",
"resolve",
"(",
"payload",
")",
";",
"}"
]
| Verify the token with the public key.
And validate the exp, iss and aud with the decoded token. | [
"Verify",
"the",
"token",
"with",
"the",
"public",
"key",
".",
"And",
"validate",
"the",
"exp",
"iss",
"and",
"aud",
"with",
"the",
"decoded",
"token",
"."
]
| 56c2a7a6cb5a55b75eee3b4da6c5ac801b793a0f | https://github.com/ibm-bluemix-mobile-services/bms-mca-token-validation-strategy/blob/56c2a7a6cb5a55b75eee3b4da6c5ac801b793a0f/lib/util/token-decoder.js#L76-L132 |
41,744 | Everyplay/serverbone | lib/errors/validation_error.js | getErrorMessage | function getErrorMessage(errors) {
if (_.isArray(errors)) {
return _.uniq(_.pluck(errors, 'stack')).join().replace(/instance./g, '');
} else if (errors) {
return errors.message;
}
} | javascript | function getErrorMessage(errors) {
if (_.isArray(errors)) {
return _.uniq(_.pluck(errors, 'stack')).join().replace(/instance./g, '');
} else if (errors) {
return errors.message;
}
} | [
"function",
"getErrorMessage",
"(",
"errors",
")",
"{",
"if",
"(",
"_",
".",
"isArray",
"(",
"errors",
")",
")",
"{",
"return",
"_",
".",
"uniq",
"(",
"_",
".",
"pluck",
"(",
"errors",
",",
"'stack'",
")",
")",
".",
"join",
"(",
")",
".",
"replace",
"(",
"/",
"instance.",
"/",
"g",
",",
"''",
")",
";",
"}",
"else",
"if",
"(",
"errors",
")",
"{",
"return",
"errors",
".",
"message",
";",
"}",
"}"
]
| convert errors given by jsonschema | [
"convert",
"errors",
"given",
"by",
"jsonschema"
]
| 214cf2a5b003c99d8c353f3a750f36309f0f19a2 | https://github.com/Everyplay/serverbone/blob/214cf2a5b003c99d8c353f3a750f36309f0f19a2/lib/errors/validation_error.js#L6-L12 |
41,745 | cronvel/logfella | lib/messageFormatter.js | message | function message( data , color ) {
var k , messageString = '' ;
if ( data.mon ) {
messageString = '\n' ;
if ( color ) {
for ( k in data.mon ) {
messageString += string.ansi.green + k + string.ansi.reset + ': ' +
string.ansi.cyan + data.mon[ k ] + string.ansi.reset + '\n' ;
}
}
else {
for ( k in data.mon ) { messageString += k + ': ' + data.mon[ k ] + '\n' ; }
}
}
else if ( Array.isArray( data.messageData ) && data.isFormat ) {
//if ( color ) { messageString = string.ansi.italic + string.formatMethod.apply( { color: true } , data.messageData ) ; }
//else { messageString = string.formatMethod.apply( { color: false } , data.messageData ) ; }
messageString = string.formatMethod.apply( color ? formatColor : format , data.messageData ) ;
}
else if ( data.messageData instanceof Error ) {
messageString = string.inspectError( { style: color ? 'color' : 'none' } , data.messageData ) ;
}
else if ( typeof data.messageData !== 'string' ) {
messageString = string.inspect( { style: color ? 'color' : 'none' } , data.messageData ) ;
}
else {
// Even if messageData is not an array, it may contains markup, so it should be formated anyway
//messageString = data.messageData ;
messageString = string.formatMethod.call( color ? formatColor : format , data.messageData ) ;
}
return messageString ;
} | javascript | function message( data , color ) {
var k , messageString = '' ;
if ( data.mon ) {
messageString = '\n' ;
if ( color ) {
for ( k in data.mon ) {
messageString += string.ansi.green + k + string.ansi.reset + ': ' +
string.ansi.cyan + data.mon[ k ] + string.ansi.reset + '\n' ;
}
}
else {
for ( k in data.mon ) { messageString += k + ': ' + data.mon[ k ] + '\n' ; }
}
}
else if ( Array.isArray( data.messageData ) && data.isFormat ) {
//if ( color ) { messageString = string.ansi.italic + string.formatMethod.apply( { color: true } , data.messageData ) ; }
//else { messageString = string.formatMethod.apply( { color: false } , data.messageData ) ; }
messageString = string.formatMethod.apply( color ? formatColor : format , data.messageData ) ;
}
else if ( data.messageData instanceof Error ) {
messageString = string.inspectError( { style: color ? 'color' : 'none' } , data.messageData ) ;
}
else if ( typeof data.messageData !== 'string' ) {
messageString = string.inspect( { style: color ? 'color' : 'none' } , data.messageData ) ;
}
else {
// Even if messageData is not an array, it may contains markup, so it should be formated anyway
//messageString = data.messageData ;
messageString = string.formatMethod.call( color ? formatColor : format , data.messageData ) ;
}
return messageString ;
} | [
"function",
"message",
"(",
"data",
",",
"color",
")",
"{",
"var",
"k",
",",
"messageString",
"=",
"''",
";",
"if",
"(",
"data",
".",
"mon",
")",
"{",
"messageString",
"=",
"'\\n'",
";",
"if",
"(",
"color",
")",
"{",
"for",
"(",
"k",
"in",
"data",
".",
"mon",
")",
"{",
"messageString",
"+=",
"string",
".",
"ansi",
".",
"green",
"+",
"k",
"+",
"string",
".",
"ansi",
".",
"reset",
"+",
"': '",
"+",
"string",
".",
"ansi",
".",
"cyan",
"+",
"data",
".",
"mon",
"[",
"k",
"]",
"+",
"string",
".",
"ansi",
".",
"reset",
"+",
"'\\n'",
";",
"}",
"}",
"else",
"{",
"for",
"(",
"k",
"in",
"data",
".",
"mon",
")",
"{",
"messageString",
"+=",
"k",
"+",
"': '",
"+",
"data",
".",
"mon",
"[",
"k",
"]",
"+",
"'\\n'",
";",
"}",
"}",
"}",
"else",
"if",
"(",
"Array",
".",
"isArray",
"(",
"data",
".",
"messageData",
")",
"&&",
"data",
".",
"isFormat",
")",
"{",
"//if ( color ) { messageString = string.ansi.italic + string.formatMethod.apply( { color: true } , data.messageData ) ; }",
"//else { messageString = string.formatMethod.apply( { color: false } , data.messageData ) ; }",
"messageString",
"=",
"string",
".",
"formatMethod",
".",
"apply",
"(",
"color",
"?",
"formatColor",
":",
"format",
",",
"data",
".",
"messageData",
")",
";",
"}",
"else",
"if",
"(",
"data",
".",
"messageData",
"instanceof",
"Error",
")",
"{",
"messageString",
"=",
"string",
".",
"inspectError",
"(",
"{",
"style",
":",
"color",
"?",
"'color'",
":",
"'none'",
"}",
",",
"data",
".",
"messageData",
")",
";",
"}",
"else",
"if",
"(",
"typeof",
"data",
".",
"messageData",
"!==",
"'string'",
")",
"{",
"messageString",
"=",
"string",
".",
"inspect",
"(",
"{",
"style",
":",
"color",
"?",
"'color'",
":",
"'none'",
"}",
",",
"data",
".",
"messageData",
")",
";",
"}",
"else",
"{",
"// Even if messageData is not an array, it may contains markup, so it should be formated anyway",
"//messageString = data.messageData ;",
"messageString",
"=",
"string",
".",
"formatMethod",
".",
"call",
"(",
"color",
"?",
"formatColor",
":",
"format",
",",
"data",
".",
"messageData",
")",
";",
"}",
"return",
"messageString",
";",
"}"
]
| Turn style markup off | [
"Turn",
"style",
"markup",
"off"
]
| 1b46d80a108d6ad51f9f1732619232de8ff0af53 | https://github.com/cronvel/logfella/blob/1b46d80a108d6ad51f9f1732619232de8ff0af53/lib/messageFormatter.js#L43-L78 |
41,746 | cronvel/logfella | lib/messageFormatter.js | hashSymbol | function hashSymbol( value ) {
var i , iMax , hash = 0 , output , offset ;
value = '' + value ;
// At least 3 passes
offset = 3 * 16 / value.length ;
for ( i = 0 , iMax = value.length ; i < iMax ; i ++ ) {
hash ^= value.charCodeAt( i ) << ( ( i * offset ) % 16 ) ;
//hash += value.charCodeAt( i ) ;
//hash += value.charCodeAt( i ) * ( i + 1 ) ;
}
output = symbols[ hash % symbols.length ] ;
hash = Math.floor( hash / symbols.length ) ;
output = string.ansi[ fgColors[ hash % fgColors.length ] ] + output ;
hash = Math.floor( hash / fgColors.length ) ;
output = string.ansi[ bgColors[ hash % bgColors.length ] ] + output ;
hash = Math.floor( hash / bgColors.length ) ;
output += string.ansi.reset ;
return output ;
} | javascript | function hashSymbol( value ) {
var i , iMax , hash = 0 , output , offset ;
value = '' + value ;
// At least 3 passes
offset = 3 * 16 / value.length ;
for ( i = 0 , iMax = value.length ; i < iMax ; i ++ ) {
hash ^= value.charCodeAt( i ) << ( ( i * offset ) % 16 ) ;
//hash += value.charCodeAt( i ) ;
//hash += value.charCodeAt( i ) * ( i + 1 ) ;
}
output = symbols[ hash % symbols.length ] ;
hash = Math.floor( hash / symbols.length ) ;
output = string.ansi[ fgColors[ hash % fgColors.length ] ] + output ;
hash = Math.floor( hash / fgColors.length ) ;
output = string.ansi[ bgColors[ hash % bgColors.length ] ] + output ;
hash = Math.floor( hash / bgColors.length ) ;
output += string.ansi.reset ;
return output ;
} | [
"function",
"hashSymbol",
"(",
"value",
")",
"{",
"var",
"i",
",",
"iMax",
",",
"hash",
"=",
"0",
",",
"output",
",",
"offset",
";",
"value",
"=",
"''",
"+",
"value",
";",
"// At least 3 passes",
"offset",
"=",
"3",
"*",
"16",
"/",
"value",
".",
"length",
";",
"for",
"(",
"i",
"=",
"0",
",",
"iMax",
"=",
"value",
".",
"length",
";",
"i",
"<",
"iMax",
";",
"i",
"++",
")",
"{",
"hash",
"^=",
"value",
".",
"charCodeAt",
"(",
"i",
")",
"<<",
"(",
"(",
"i",
"*",
"offset",
")",
"%",
"16",
")",
";",
"//hash += value.charCodeAt( i ) ;",
"//hash += value.charCodeAt( i ) * ( i + 1 ) ;",
"}",
"output",
"=",
"symbols",
"[",
"hash",
"%",
"symbols",
".",
"length",
"]",
";",
"hash",
"=",
"Math",
".",
"floor",
"(",
"hash",
"/",
"symbols",
".",
"length",
")",
";",
"output",
"=",
"string",
".",
"ansi",
"[",
"fgColors",
"[",
"hash",
"%",
"fgColors",
".",
"length",
"]",
"]",
"+",
"output",
";",
"hash",
"=",
"Math",
".",
"floor",
"(",
"hash",
"/",
"fgColors",
".",
"length",
")",
";",
"output",
"=",
"string",
".",
"ansi",
"[",
"bgColors",
"[",
"hash",
"%",
"bgColors",
".",
"length",
"]",
"]",
"+",
"output",
";",
"hash",
"=",
"Math",
".",
"floor",
"(",
"hash",
"/",
"bgColors",
".",
"length",
")",
";",
"output",
"+=",
"string",
".",
"ansi",
".",
"reset",
";",
"return",
"output",
";",
"}"
]
| Naive CRC-like algorithm | [
"Naive",
"CRC",
"-",
"like",
"algorithm"
]
| 1b46d80a108d6ad51f9f1732619232de8ff0af53 | https://github.com/cronvel/logfella/blob/1b46d80a108d6ad51f9f1732619232de8ff0af53/lib/messageFormatter.js#L95-L121 |
41,747 | andrewscwei/gulp-prismic-mpa-builder | helpers/task-helpers.js | globExts | function globExts() {
let exts = _.flattenDeep(_.concat.apply(null, arguments));
return (exts.length <= 1) ? (exts[0] && `.${exts[0]}` || ``) : `.{${exts.join(`,`)}}`;
} | javascript | function globExts() {
let exts = _.flattenDeep(_.concat.apply(null, arguments));
return (exts.length <= 1) ? (exts[0] && `.${exts[0]}` || ``) : `.{${exts.join(`,`)}}`;
} | [
"function",
"globExts",
"(",
")",
"{",
"let",
"exts",
"=",
"_",
".",
"flattenDeep",
"(",
"_",
".",
"concat",
".",
"apply",
"(",
"null",
",",
"arguments",
")",
")",
";",
"return",
"(",
"exts",
".",
"length",
"<=",
"1",
")",
"?",
"(",
"exts",
"[",
"0",
"]",
"&&",
"`",
"${",
"exts",
"[",
"0",
"]",
"}",
"`",
"||",
"`",
"`",
")",
":",
"`",
"${",
"exts",
".",
"join",
"(",
"`",
"`",
")",
"}",
"`",
";",
"}"
]
| Returns a wildcard glob pattern of the specified file extensions.
@param {...(string|string[])} extensions - Extensions to be included in the
wildcard pattern.
@return {string} - Wildcard glob pattern consisting of all specified
extensions. | [
"Returns",
"a",
"wildcard",
"glob",
"pattern",
"of",
"the",
"specified",
"file",
"extensions",
"."
]
| c7fb9180de2aeca2657f0318c0befbd166a9bff5 | https://github.com/andrewscwei/gulp-prismic-mpa-builder/blob/c7fb9180de2aeca2657f0318c0befbd166a9bff5/helpers/task-helpers.js#L121-L124 |
41,748 | LeisureLink/magicbus | lib/amqp/machine-factory.js | function() {
this.emit('acquiring');
const onAcquisitionError = (err) => {
logger.debug('Resource acquisition failed with error', err);
this.emit('failed', err);
this.handle('failed');
};
const onAcquired = (o) => {
this.item = o;
this.waitInterval = 0;
if (this.item.on) {
this.disposeHandle = this.item.once(disposalEvent || 'close', (err) => {
logger.info('Resource lost, releasing', err);
this.emit('lost');
this.transition('released');
});
this.item.once('error', (err) => {
logger.info('Resource error', err);
this.transition('failed');
});
this.item.on('drain', () => {
this.emit('drain');
});
}
this.transition('acquired');
};
const onException = (ex) => {
logger.debug('Resource acquisition failed with exception', ex);
this.emit('failed', ex);
this.handle('failed');
};
factory()
.then(onAcquired, onAcquisitionError)
.catch(onException);
} | javascript | function() {
this.emit('acquiring');
const onAcquisitionError = (err) => {
logger.debug('Resource acquisition failed with error', err);
this.emit('failed', err);
this.handle('failed');
};
const onAcquired = (o) => {
this.item = o;
this.waitInterval = 0;
if (this.item.on) {
this.disposeHandle = this.item.once(disposalEvent || 'close', (err) => {
logger.info('Resource lost, releasing', err);
this.emit('lost');
this.transition('released');
});
this.item.once('error', (err) => {
logger.info('Resource error', err);
this.transition('failed');
});
this.item.on('drain', () => {
this.emit('drain');
});
}
this.transition('acquired');
};
const onException = (ex) => {
logger.debug('Resource acquisition failed with exception', ex);
this.emit('failed', ex);
this.handle('failed');
};
factory()
.then(onAcquired, onAcquisitionError)
.catch(onException);
} | [
"function",
"(",
")",
"{",
"this",
".",
"emit",
"(",
"'acquiring'",
")",
";",
"const",
"onAcquisitionError",
"=",
"(",
"err",
")",
"=>",
"{",
"logger",
".",
"debug",
"(",
"'Resource acquisition failed with error'",
",",
"err",
")",
";",
"this",
".",
"emit",
"(",
"'failed'",
",",
"err",
")",
";",
"this",
".",
"handle",
"(",
"'failed'",
")",
";",
"}",
";",
"const",
"onAcquired",
"=",
"(",
"o",
")",
"=>",
"{",
"this",
".",
"item",
"=",
"o",
";",
"this",
".",
"waitInterval",
"=",
"0",
";",
"if",
"(",
"this",
".",
"item",
".",
"on",
")",
"{",
"this",
".",
"disposeHandle",
"=",
"this",
".",
"item",
".",
"once",
"(",
"disposalEvent",
"||",
"'close'",
",",
"(",
"err",
")",
"=>",
"{",
"logger",
".",
"info",
"(",
"'Resource lost, releasing'",
",",
"err",
")",
";",
"this",
".",
"emit",
"(",
"'lost'",
")",
";",
"this",
".",
"transition",
"(",
"'released'",
")",
";",
"}",
")",
";",
"this",
".",
"item",
".",
"once",
"(",
"'error'",
",",
"(",
"err",
")",
"=>",
"{",
"logger",
".",
"info",
"(",
"'Resource error'",
",",
"err",
")",
";",
"this",
".",
"transition",
"(",
"'failed'",
")",
";",
"}",
")",
";",
"this",
".",
"item",
".",
"on",
"(",
"'drain'",
",",
"(",
")",
"=>",
"{",
"this",
".",
"emit",
"(",
"'drain'",
")",
";",
"}",
")",
";",
"}",
"this",
".",
"transition",
"(",
"'acquired'",
")",
";",
"}",
";",
"const",
"onException",
"=",
"(",
"ex",
")",
"=>",
"{",
"logger",
".",
"debug",
"(",
"'Resource acquisition failed with exception'",
",",
"ex",
")",
";",
"this",
".",
"emit",
"(",
"'failed'",
",",
"ex",
")",
";",
"this",
".",
"handle",
"(",
"'failed'",
")",
";",
"}",
";",
"factory",
"(",
")",
".",
"then",
"(",
"onAcquired",
",",
"onAcquisitionError",
")",
".",
"catch",
"(",
"onException",
")",
";",
"}"
]
| Does the work in acquiring a resource and sets up events for state transitions.
@private
@memberOf PromiseMachine.prototype | [
"Does",
"the",
"work",
"in",
"acquiring",
"a",
"resource",
"and",
"sets",
"up",
"events",
"for",
"state",
"transitions",
"."
]
| 0370c38ebb8c7917cfd3894263d734aefc2d3d29 | https://github.com/LeisureLink/magicbus/blob/0370c38ebb8c7917cfd3894263d734aefc2d3d29/lib/amqp/machine-factory.js#L40-L74 |
|
41,749 | 1stdibs/backbone-base-and-form-view | backbone-baseview.js | function (str) {
var arr = str.split('.');
var obj = root[arr.shift()];
while (arr.length && obj) {
obj = obj[arr.shift()];
}
return obj;
} | javascript | function (str) {
var arr = str.split('.');
var obj = root[arr.shift()];
while (arr.length && obj) {
obj = obj[arr.shift()];
}
return obj;
} | [
"function",
"(",
"str",
")",
"{",
"var",
"arr",
"=",
"str",
".",
"split",
"(",
"'.'",
")",
";",
"var",
"obj",
"=",
"root",
"[",
"arr",
".",
"shift",
"(",
")",
"]",
";",
"while",
"(",
"arr",
".",
"length",
"&&",
"obj",
")",
"{",
"obj",
"=",
"obj",
"[",
"arr",
".",
"shift",
"(",
")",
"]",
";",
"}",
"return",
"obj",
";",
"}"
]
| Finds globally dot noted namespaced objects from a string | [
"Finds",
"globally",
"dot",
"noted",
"namespaced",
"objects",
"from",
"a",
"string"
]
| 9c49f9ac059ba3177b61f7395151de78b506e8f7 | https://github.com/1stdibs/backbone-base-and-form-view/blob/9c49f9ac059ba3177b61f7395151de78b506e8f7/backbone-baseview.js#L22-L30 |
|
41,750 | 1stdibs/backbone-base-and-form-view | backbone-baseview.js | function (name, instance, singleton) {
var arr = (isArray(name)) ? name : (isArray(instance)) ? instance : undefined; // If its a simple array of subviews or configs
var map = (!arr && isObject(name) && name instanceof View === false) ? name : undefined; // If its a mapping of subviews
var viewOptions = (!arr && instance instanceof View === false) ? instance : undefined;
var key;
var i;
var len;
if (map) {
singleton = (typeof instance === 'boolean') ? instance : undefined;
for (key in map) {
if (map.hasOwnProperty(key)) {
map[key] = (isArray(map[key])) ? map[key] : [map[key]];
len = map[key].length;
if (len && map[key][0] instanceof View) {
this._addInstance(key, map[key], singleton);
} else {
i = -1;
while (++i < len) {
this._init(key, map[key][i], singleton);
}
}
}
}
return this;
}
instance = (name instanceof View) ? name : instance;
name = (typeof name === 'string' || typeof name === "number") ? name : undefined;
singleton = (typeof singleton === 'boolean') ? singleton :
(!name && typeof instance === 'boolean') ? instance : undefined;
if (viewOptions) {
this._init(name, viewOptions, singleton);
return this;
}
if (arr && (len = arr.length)) { //eslint-disable-line no-cond-assign
if (arr[0] instanceof View) {
this._addInstance(name, arr, singleton);
} else {
i = -1;
while (++i < len) {
this._init(name, arr[i], singleton);
}
}
return this;
}
if (instance) {
this._addInstance(name, instance, singleton);
} else if (name) {
this._init(name, singleton);
}
return this;
} | javascript | function (name, instance, singleton) {
var arr = (isArray(name)) ? name : (isArray(instance)) ? instance : undefined; // If its a simple array of subviews or configs
var map = (!arr && isObject(name) && name instanceof View === false) ? name : undefined; // If its a mapping of subviews
var viewOptions = (!arr && instance instanceof View === false) ? instance : undefined;
var key;
var i;
var len;
if (map) {
singleton = (typeof instance === 'boolean') ? instance : undefined;
for (key in map) {
if (map.hasOwnProperty(key)) {
map[key] = (isArray(map[key])) ? map[key] : [map[key]];
len = map[key].length;
if (len && map[key][0] instanceof View) {
this._addInstance(key, map[key], singleton);
} else {
i = -1;
while (++i < len) {
this._init(key, map[key][i], singleton);
}
}
}
}
return this;
}
instance = (name instanceof View) ? name : instance;
name = (typeof name === 'string' || typeof name === "number") ? name : undefined;
singleton = (typeof singleton === 'boolean') ? singleton :
(!name && typeof instance === 'boolean') ? instance : undefined;
if (viewOptions) {
this._init(name, viewOptions, singleton);
return this;
}
if (arr && (len = arr.length)) { //eslint-disable-line no-cond-assign
if (arr[0] instanceof View) {
this._addInstance(name, arr, singleton);
} else {
i = -1;
while (++i < len) {
this._init(name, arr[i], singleton);
}
}
return this;
}
if (instance) {
this._addInstance(name, instance, singleton);
} else if (name) {
this._init(name, singleton);
}
return this;
} | [
"function",
"(",
"name",
",",
"instance",
",",
"singleton",
")",
"{",
"var",
"arr",
"=",
"(",
"isArray",
"(",
"name",
")",
")",
"?",
"name",
":",
"(",
"isArray",
"(",
"instance",
")",
")",
"?",
"instance",
":",
"undefined",
";",
"// If its a simple array of subviews or configs",
"var",
"map",
"=",
"(",
"!",
"arr",
"&&",
"isObject",
"(",
"name",
")",
"&&",
"name",
"instanceof",
"View",
"===",
"false",
")",
"?",
"name",
":",
"undefined",
";",
"// If its a mapping of subviews",
"var",
"viewOptions",
"=",
"(",
"!",
"arr",
"&&",
"instance",
"instanceof",
"View",
"===",
"false",
")",
"?",
"instance",
":",
"undefined",
";",
"var",
"key",
";",
"var",
"i",
";",
"var",
"len",
";",
"if",
"(",
"map",
")",
"{",
"singleton",
"=",
"(",
"typeof",
"instance",
"===",
"'boolean'",
")",
"?",
"instance",
":",
"undefined",
";",
"for",
"(",
"key",
"in",
"map",
")",
"{",
"if",
"(",
"map",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"map",
"[",
"key",
"]",
"=",
"(",
"isArray",
"(",
"map",
"[",
"key",
"]",
")",
")",
"?",
"map",
"[",
"key",
"]",
":",
"[",
"map",
"[",
"key",
"]",
"]",
";",
"len",
"=",
"map",
"[",
"key",
"]",
".",
"length",
";",
"if",
"(",
"len",
"&&",
"map",
"[",
"key",
"]",
"[",
"0",
"]",
"instanceof",
"View",
")",
"{",
"this",
".",
"_addInstance",
"(",
"key",
",",
"map",
"[",
"key",
"]",
",",
"singleton",
")",
";",
"}",
"else",
"{",
"i",
"=",
"-",
"1",
";",
"while",
"(",
"++",
"i",
"<",
"len",
")",
"{",
"this",
".",
"_init",
"(",
"key",
",",
"map",
"[",
"key",
"]",
"[",
"i",
"]",
",",
"singleton",
")",
";",
"}",
"}",
"}",
"}",
"return",
"this",
";",
"}",
"instance",
"=",
"(",
"name",
"instanceof",
"View",
")",
"?",
"name",
":",
"instance",
";",
"name",
"=",
"(",
"typeof",
"name",
"===",
"'string'",
"||",
"typeof",
"name",
"===",
"\"number\"",
")",
"?",
"name",
":",
"undefined",
";",
"singleton",
"=",
"(",
"typeof",
"singleton",
"===",
"'boolean'",
")",
"?",
"singleton",
":",
"(",
"!",
"name",
"&&",
"typeof",
"instance",
"===",
"'boolean'",
")",
"?",
"instance",
":",
"undefined",
";",
"if",
"(",
"viewOptions",
")",
"{",
"this",
".",
"_init",
"(",
"name",
",",
"viewOptions",
",",
"singleton",
")",
";",
"return",
"this",
";",
"}",
"if",
"(",
"arr",
"&&",
"(",
"len",
"=",
"arr",
".",
"length",
")",
")",
"{",
"//eslint-disable-line no-cond-assign",
"if",
"(",
"arr",
"[",
"0",
"]",
"instanceof",
"View",
")",
"{",
"this",
".",
"_addInstance",
"(",
"name",
",",
"arr",
",",
"singleton",
")",
";",
"}",
"else",
"{",
"i",
"=",
"-",
"1",
";",
"while",
"(",
"++",
"i",
"<",
"len",
")",
"{",
"this",
".",
"_init",
"(",
"name",
",",
"arr",
"[",
"i",
"]",
",",
"singleton",
")",
";",
"}",
"}",
"return",
"this",
";",
"}",
"if",
"(",
"instance",
")",
"{",
"this",
".",
"_addInstance",
"(",
"name",
",",
"instance",
",",
"singleton",
")",
";",
"}",
"else",
"if",
"(",
"name",
")",
"{",
"this",
".",
"_init",
"(",
"name",
",",
"singleton",
")",
";",
"}",
"return",
"this",
";",
"}"
]
| Adds a subView or subViews to the View's list of subViews. Calling
function must provide instances of views or configurations.
@memberOf SubViewManager#
@class SubViewManager
@type {SubViewManager}
@method add
@param {Object} map
An object with key's to refer to subViews and values that
are View instances, options to pass to the constructor, or
an array of either the previous two to add multiple subViews.
If you pass options or an array of options, the SubViewManager
will look for a configuration matching the key for these options
and will initialize subviews based on the config, passing options
to the constructor.
@param {Boolean} [singleton]
True if the instances mapped to the keys should be singletons.
If you pass options, the singleton param will be ignored.
@return {SubViewManager}
Adds a subView or subViews to the View's list of subViews. Calling
function must provide instances of views or configurations.
@memberOf SubViewManager#
@type {SubViewManager}
@method add
@param {String} name
A string key to refer to the subViews with. Should match
a key in the subView configuration. If not, a configuration
will be set up with default values based on the instance
passed.
@param {Backbone.View[]|object[]} arr
An array of View instances or options. Instances will be
appropriately associated with the key, options will be
used to instantiate a subView based on the configuration
matching the key
@param {Boolean} [singleton]
True if the added views should be singletons
@return {SubViewManager}
Adds a subView or subViews to the View's list of subViews. Calling
function must provide instances of views or configurations.
@memberOf SubViewManager#
@type {SubViewManager}
@method add
@param {Backbone.View[]} arr
An array of View instances. These will not be accessible
by a type or key
@return {SubViewManager}
Adds a subView or subViews to the View's list of subViews. Calling
function must provide instances of views or configurations.
@memberOf SubViewManager#
@type {SubViewManager}
@method add
@param {String} name
A string key to refer to the subView with
@param {Backbone.View} instance
A View instance
@param {Object} [singleton]
If you want the view matching this key to be a singleton
@return {SubViewManager}
Adds a subView or subViews to the View's list of subViews. Calling
function must provide instances of views or configurations.
@memberOf SubViewManager#
@type {SubViewManager}
@method add
@param {String} name
A string key to refer to the subView with. Without an instance
as the second param, this variant requires that a configuration
to have been specified matching the 'name' with a constructor to
initialize.
@param {Object} [options]
An object that will be passed as the options parameter to the
view on initialization.
@return {SubViewManager}
Adds a subView or subViews to the View's list of subViews. Calling
function must provide instances of views or configurations.
@memberOf SubViewManager#
@type {SubViewManager}
@method add
@param {Backbone.View} instance
A Backbone.View instance to add as the subview
@return {SubViewManager} | [
"Adds",
"a",
"subView",
"or",
"subViews",
"to",
"the",
"View",
"s",
"list",
"of",
"subViews",
".",
"Calling",
"function",
"must",
"provide",
"instances",
"of",
"views",
"or",
"configurations",
"."
]
| 9c49f9ac059ba3177b61f7395151de78b506e8f7 | https://github.com/1stdibs/backbone-base-and-form-view/blob/9c49f9ac059ba3177b61f7395151de78b506e8f7/backbone-baseview.js#L162-L218 |
|
41,751 | 1stdibs/backbone-base-and-form-view | backbone-baseview.js | function (key, instance) {
if (key instanceof View) {
instance = key;
key = undefined;
}
this._addInstance(key, instance);
return this;
} | javascript | function (key, instance) {
if (key instanceof View) {
instance = key;
key = undefined;
}
this._addInstance(key, instance);
return this;
} | [
"function",
"(",
"key",
",",
"instance",
")",
"{",
"if",
"(",
"key",
"instanceof",
"View",
")",
"{",
"instance",
"=",
"key",
";",
"key",
"=",
"undefined",
";",
"}",
"this",
".",
"_addInstance",
"(",
"key",
",",
"instance",
")",
";",
"return",
"this",
";",
"}"
]
| Add a subview instance. If is has a config,
the instance will be associated with that
config. If the config specifies that the
view is a singleton an a view for that
key already exists, it will not be added.
@param {string|number} key
@param {Backbone.View} instance
Add a subview instance, without a key.
Since it doesn't have a key, it will
simply be added to the subViews array.
@param {Backbone.View} instance | [
"Add",
"a",
"subview",
"instance",
".",
"If",
"is",
"has",
"a",
"config",
"the",
"instance",
"will",
"be",
"associated",
"with",
"that",
"config",
".",
"If",
"the",
"config",
"specifies",
"that",
"the",
"view",
"is",
"a",
"singleton",
"an",
"a",
"view",
"for",
"that",
"key",
"already",
"exists",
"it",
"will",
"not",
"be",
"added",
"."
]
| 9c49f9ac059ba3177b61f7395151de78b506e8f7 | https://github.com/1stdibs/backbone-base-and-form-view/blob/9c49f9ac059ba3177b61f7395151de78b506e8f7/backbone-baseview.js#L234-L241 |
|
41,752 | 1stdibs/backbone-base-and-form-view | backbone-baseview.js | function (key, instances) {
if (isArray(key)) {
instances = key;
key = undefined;
}
var i = -1;
var len = instances.length;
while (++i < len) {
this._addInstance(key, instances[i]);
}
return this;
} | javascript | function (key, instances) {
if (isArray(key)) {
instances = key;
key = undefined;
}
var i = -1;
var len = instances.length;
while (++i < len) {
this._addInstance(key, instances[i]);
}
return this;
} | [
"function",
"(",
"key",
",",
"instances",
")",
"{",
"if",
"(",
"isArray",
"(",
"key",
")",
")",
"{",
"instances",
"=",
"key",
";",
"key",
"=",
"undefined",
";",
"}",
"var",
"i",
"=",
"-",
"1",
";",
"var",
"len",
"=",
"instances",
".",
"length",
";",
"while",
"(",
"++",
"i",
"<",
"len",
")",
"{",
"this",
".",
"_addInstance",
"(",
"key",
",",
"instances",
"[",
"i",
"]",
")",
";",
"}",
"return",
"this",
";",
"}"
]
| Add a subview for each view instance in
an array for a particular key
@memberOf SubViewManager#
@param {string} key
@param {Backbone.View[]} instances
@return {SubViewManager}
Add a subview for each view instance in
an array. They will not be associated
with a key and will be only accessible
through the subViews array.
@memberOf SubViewManager#
@param {Backbone.View[]} instances
@return {SubViewManager} | [
"Add",
"a",
"subview",
"for",
"each",
"view",
"instance",
"in",
"an",
"array",
"for",
"a",
"particular",
"key"
]
| 9c49f9ac059ba3177b61f7395151de78b506e8f7 | https://github.com/1stdibs/backbone-base-and-form-view/blob/9c49f9ac059ba3177b61f7395151de78b506e8f7/backbone-baseview.js#L259-L270 |
|
41,753 | 1stdibs/backbone-base-and-form-view | backbone-baseview.js | function (map) {
var key;
for (key in map) {
if (map.hasOwnProperty(key)) {
this.addInstance(key, map[key]);
}
}
return this;
} | javascript | function (map) {
var key;
for (key in map) {
if (map.hasOwnProperty(key)) {
this.addInstance(key, map[key]);
}
}
return this;
} | [
"function",
"(",
"map",
")",
"{",
"var",
"key",
";",
"for",
"(",
"key",
"in",
"map",
")",
"{",
"if",
"(",
"map",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"this",
".",
"addInstance",
"(",
"key",
",",
"map",
"[",
"key",
"]",
")",
";",
"}",
"}",
"return",
"this",
";",
"}"
]
| Add instances using an object that
maps subview keys to the instances
@param {object} map
@return {SubViewManager} | [
"Add",
"instances",
"using",
"an",
"object",
"that",
"maps",
"subview",
"keys",
"to",
"the",
"instances"
]
| 9c49f9ac059ba3177b61f7395151de78b506e8f7 | https://github.com/1stdibs/backbone-base-and-form-view/blob/9c49f9ac059ba3177b61f7395151de78b506e8f7/backbone-baseview.js#L277-L285 |
|
41,754 | 1stdibs/backbone-base-and-form-view | backbone-baseview.js | function (keys, options) {
var views = [];
var len = keys.length;
var i = -1;
while (++i < len) {
views.push(this._init(keys[i], options));
}
return views;
} | javascript | function (keys, options) {
var views = [];
var len = keys.length;
var i = -1;
while (++i < len) {
views.push(this._init(keys[i], options));
}
return views;
} | [
"function",
"(",
"keys",
",",
"options",
")",
"{",
"var",
"views",
"=",
"[",
"]",
";",
"var",
"len",
"=",
"keys",
".",
"length",
";",
"var",
"i",
"=",
"-",
"1",
";",
"while",
"(",
"++",
"i",
"<",
"len",
")",
"{",
"views",
".",
"push",
"(",
"this",
".",
"_init",
"(",
"keys",
"[",
"i",
"]",
",",
"options",
")",
")",
";",
"}",
"return",
"views",
";",
"}"
]
| Given an array of keys, a subview
will be instantiated for each key
based on the configuration for that
key. The options param will be
passed to each view on instantiation
as additional options.
@memberOf SubViewManager#
@param {String[]} keys
@param {Object} options
Additional options to pass
to each view on init
@return {Backbone.View[]}
Array of newly created subviews | [
"Given",
"an",
"array",
"of",
"keys",
"a",
"subview",
"will",
"be",
"instantiated",
"for",
"each",
"key",
"based",
"on",
"the",
"configuration",
"for",
"that",
"key",
".",
"The",
"options",
"param",
"will",
"be",
"passed",
"to",
"each",
"view",
"on",
"instantiation",
"as",
"additional",
"options",
"."
]
| 9c49f9ac059ba3177b61f7395151de78b506e8f7 | https://github.com/1stdibs/backbone-base-and-form-view/blob/9c49f9ac059ba3177b61f7395151de78b506e8f7/backbone-baseview.js#L314-L322 |
|
41,755 | 1stdibs/backbone-base-and-form-view | backbone-baseview.js | function (options) {
var key;
for (key in this.config) {
if (this.config.hasOwnProperty(key) && this.config[key].singleton) {
this._init(key, options);
}
}
return this;
} | javascript | function (options) {
var key;
for (key in this.config) {
if (this.config.hasOwnProperty(key) && this.config[key].singleton) {
this._init(key, options);
}
}
return this;
} | [
"function",
"(",
"options",
")",
"{",
"var",
"key",
";",
"for",
"(",
"key",
"in",
"this",
".",
"config",
")",
"{",
"if",
"(",
"this",
".",
"config",
".",
"hasOwnProperty",
"(",
"key",
")",
"&&",
"this",
".",
"config",
"[",
"key",
"]",
".",
"singleton",
")",
"{",
"this",
".",
"_init",
"(",
"key",
",",
"options",
")",
";",
"}",
"}",
"return",
"this",
";",
"}"
]
| Instantiate all singletons defined in the
config.
@param {object} options Additional options
@return {SubViewManager} | [
"Instantiate",
"all",
"singletons",
"defined",
"in",
"the",
"config",
"."
]
| 9c49f9ac059ba3177b61f7395151de78b506e8f7 | https://github.com/1stdibs/backbone-base-and-form-view/blob/9c49f9ac059ba3177b61f7395151de78b506e8f7/backbone-baseview.js#L329-L337 |
|
41,756 | 1stdibs/backbone-base-and-form-view | backbone-baseview.js | function (map) {
var key;
for (key in map) {
if (map.hasOwnProperty(key)) {
this._init(key, map[key]);
}
}
return this;
} | javascript | function (map) {
var key;
for (key in map) {
if (map.hasOwnProperty(key)) {
this._init(key, map[key]);
}
}
return this;
} | [
"function",
"(",
"map",
")",
"{",
"var",
"key",
";",
"for",
"(",
"key",
"in",
"map",
")",
"{",
"if",
"(",
"map",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"this",
".",
"_init",
"(",
"key",
",",
"map",
"[",
"key",
"]",
")",
";",
"}",
"}",
"return",
"this",
";",
"}"
]
| Create subviews with a map of configured
subview keys to additional options.
@param {object} map
@return {SubViewManager} | [
"Create",
"subviews",
"with",
"a",
"map",
"of",
"configured",
"subview",
"keys",
"to",
"additional",
"options",
"."
]
| 9c49f9ac059ba3177b61f7395151de78b506e8f7 | https://github.com/1stdibs/backbone-base-and-form-view/blob/9c49f9ac059ba3177b61f7395151de78b506e8f7/backbone-baseview.js#L344-L352 |
|
41,757 | 1stdibs/backbone-base-and-form-view | backbone-baseview.js | function (name, config) {
var map = (isObject(name) && !isArray(name)) ? name : false;
if (map) {
each(map, this._addConfig, this);
return this;
}
return this._addConfig(config, name);
} | javascript | function (name, config) {
var map = (isObject(name) && !isArray(name)) ? name : false;
if (map) {
each(map, this._addConfig, this);
return this;
}
return this._addConfig(config, name);
} | [
"function",
"(",
"name",
",",
"config",
")",
"{",
"var",
"map",
"=",
"(",
"isObject",
"(",
"name",
")",
"&&",
"!",
"isArray",
"(",
"name",
")",
")",
"?",
"name",
":",
"false",
";",
"if",
"(",
"map",
")",
"{",
"each",
"(",
"map",
",",
"this",
".",
"_addConfig",
",",
"this",
")",
";",
"return",
"this",
";",
"}",
"return",
"this",
".",
"_addConfig",
"(",
"config",
",",
"name",
")",
";",
"}"
]
| Add an configuration for a subview to the SubViewManager.
It can be instantiated later with the add function.
@memberOf SubViewManager#
@type {SubViewManager}
@class
@method addConfig
@param {String} name
The name or type that you would like use to refer to subViews
created with this config
@param {String|Function} construct
The constructor function for this subView. If its a string, the
string must resolve to a global name-spaced function in dot notation.
(e.g. 'Backbone.imageUpload.View')
@param {String} [options]
The options or base options you would like to pass to the constructor
whenever it is initialized.
@param {String|HTMLElement} [location]
If you want to be able to automatically place a subView's DOM element
somewhere in the parent view, pass a selector or DOM element or $ instance
here that can be used by jquery as a wrapper to append the subView $el
@param {Boolean} [singleton]
If you want this view to be a singleton subView. A singleton subView
will only allow one instance of it to be created.
@return {SubViewManager}
Add an configuration for a subview to the SubViewManager.
It can be instantiated later with the add function.
@memberOf SubViewManager#
@type {SubViewManager}
@method addConfig
@param {Object} map
A object of key names/types to config objects, so you can add multiple configs
@example
// A config object should have the following format:
{
construct: // Constructor function or string version (i.e. "Backbone.BaseView")
options: // Any options you want to pass to the initialize function
singleton: // if the object should be configured as a singleton or not
location: // A string or jQuery instance in the parent view element. Or
// a function that returns one of these. The subview el will
// be appended to that location
}
@return {SubViewManager}
Add an configuration for a subview to the SubViewManager.
It can be instantiated later with the add function.
@memberOf SubViewManager#
@type {SubViewManager}
@method addConfig
@param {String} name
The name or type that you would like use to refer to subViews
created with this config
@param {Object} config
The configuration object (uses the format described above)
@return {SubViewManager} | [
"Add",
"an",
"configuration",
"for",
"a",
"subview",
"to",
"the",
"SubViewManager",
".",
"It",
"can",
"be",
"instantiated",
"later",
"with",
"the",
"add",
"function",
"."
]
| 9c49f9ac059ba3177b61f7395151de78b506e8f7 | https://github.com/1stdibs/backbone-base-and-form-view/blob/9c49f9ac059ba3177b61f7395151de78b506e8f7/backbone-baseview.js#L436-L444 |
|
41,758 | 1stdibs/backbone-base-and-form-view | backbone-baseview.js | function (key) {
var i = -1;
var len;
var subViews;
var subMgr = new SubViewManager(null, this.parent, this.options);
subMgr.config = this.config;
subViews = (isArray(key)) ? key : (isFunction(key)) ? this.filter(key) : this.getByType(key);
len = subViews.length;
while (++i < len) {
subMgr.add(subViews[i]._subviewtype, subViews[i]);
}
return subMgr;
} | javascript | function (key) {
var i = -1;
var len;
var subViews;
var subMgr = new SubViewManager(null, this.parent, this.options);
subMgr.config = this.config;
subViews = (isArray(key)) ? key : (isFunction(key)) ? this.filter(key) : this.getByType(key);
len = subViews.length;
while (++i < len) {
subMgr.add(subViews[i]._subviewtype, subViews[i]);
}
return subMgr;
} | [
"function",
"(",
"key",
")",
"{",
"var",
"i",
"=",
"-",
"1",
";",
"var",
"len",
";",
"var",
"subViews",
";",
"var",
"subMgr",
"=",
"new",
"SubViewManager",
"(",
"null",
",",
"this",
".",
"parent",
",",
"this",
".",
"options",
")",
";",
"subMgr",
".",
"config",
"=",
"this",
".",
"config",
";",
"subViews",
"=",
"(",
"isArray",
"(",
"key",
")",
")",
"?",
"key",
":",
"(",
"isFunction",
"(",
"key",
")",
")",
"?",
"this",
".",
"filter",
"(",
"key",
")",
":",
"this",
".",
"getByType",
"(",
"key",
")",
";",
"len",
"=",
"subViews",
".",
"length",
";",
"while",
"(",
"++",
"i",
"<",
"len",
")",
"{",
"subMgr",
".",
"add",
"(",
"subViews",
"[",
"i",
"]",
".",
"_subviewtype",
",",
"subViews",
"[",
"i",
"]",
")",
";",
"}",
"return",
"subMgr",
";",
"}"
]
| Returns a new SubViewManager instance with filtered list of subviews.
@memberOf SubViewManager#
@type {SubViewManager}
@param {string|Backbone.View[]|function} key
The key or type used to refer to a subview or subviews, or a list
of subViews with a type found in this SubViewManager config, or a function
that will iterate over the subviews and return true if a subview
should be included in the filtered SubViewManager instance.
@return {SubViewManager} | [
"Returns",
"a",
"new",
"SubViewManager",
"instance",
"with",
"filtered",
"list",
"of",
"subviews",
"."
]
| 9c49f9ac059ba3177b61f7395151de78b506e8f7 | https://github.com/1stdibs/backbone-base-and-form-view/blob/9c49f9ac059ba3177b61f7395151de78b506e8f7/backbone-baseview.js#L521-L533 |
|
41,759 | 1stdibs/backbone-base-and-form-view | backbone-baseview.js | function (preserveElems, clearConfigs) {
if (!preserveElems) {
this.removeElems();
}
this.subViews = [];
if (this.parent && this.parent.subViews) {
this.parent.subViews = this.subViews;
}
this._subViewsByType = {};
this._subViewSingletons = {};
this._subViewsByCid = {};
this._subViewsByModelCid = {};
if (clearConfigs) {
this.config = {};
}
return this;
} | javascript | function (preserveElems, clearConfigs) {
if (!preserveElems) {
this.removeElems();
}
this.subViews = [];
if (this.parent && this.parent.subViews) {
this.parent.subViews = this.subViews;
}
this._subViewsByType = {};
this._subViewSingletons = {};
this._subViewsByCid = {};
this._subViewsByModelCid = {};
if (clearConfigs) {
this.config = {};
}
return this;
} | [
"function",
"(",
"preserveElems",
",",
"clearConfigs",
")",
"{",
"if",
"(",
"!",
"preserveElems",
")",
"{",
"this",
".",
"removeElems",
"(",
")",
";",
"}",
"this",
".",
"subViews",
"=",
"[",
"]",
";",
"if",
"(",
"this",
".",
"parent",
"&&",
"this",
".",
"parent",
".",
"subViews",
")",
"{",
"this",
".",
"parent",
".",
"subViews",
"=",
"this",
".",
"subViews",
";",
"}",
"this",
".",
"_subViewsByType",
"=",
"{",
"}",
";",
"this",
".",
"_subViewSingletons",
"=",
"{",
"}",
";",
"this",
".",
"_subViewsByCid",
"=",
"{",
"}",
";",
"this",
".",
"_subViewsByModelCid",
"=",
"{",
"}",
";",
"if",
"(",
"clearConfigs",
")",
"{",
"this",
".",
"config",
"=",
"{",
"}",
";",
"}",
"return",
"this",
";",
"}"
]
| Clears all subViews and subView data off of the SubViewManager instance
@memberOf SubViewManager#
@type {SubViewManager}
@param {Boolean} [preserveElems] If true, view $els are left on the DOM
@param {Boolean} [clearConfigs] If true, resets the subView configs as well
@return {SubViewManager} | [
"Clears",
"all",
"subViews",
"and",
"subView",
"data",
"off",
"of",
"the",
"SubViewManager",
"instance"
]
| 9c49f9ac059ba3177b61f7395151de78b506e8f7 | https://github.com/1stdibs/backbone-base-and-form-view/blob/9c49f9ac059ba3177b61f7395151de78b506e8f7/backbone-baseview.js#L577-L593 |
|
41,760 | 1stdibs/backbone-base-and-form-view | backbone-baseview.js | function (key, preserveElems) {
var subViews = (key && (typeof key === "string" || key.cid)) ? this.get(key) : key;
var len;
if (!subViews) { return this; }
if (!isArray(subViews)) {
subViews = [subViews];
}
len = subViews ? subViews.length : 0;
if (!preserveElems) {
this.removeElems(subViews);
}
if (len) {
this.trigger('remove', subViews);
}
while (subViews && subViews.length) {
this._remove(subViews.shift());
}
return this;
} | javascript | function (key, preserveElems) {
var subViews = (key && (typeof key === "string" || key.cid)) ? this.get(key) : key;
var len;
if (!subViews) { return this; }
if (!isArray(subViews)) {
subViews = [subViews];
}
len = subViews ? subViews.length : 0;
if (!preserveElems) {
this.removeElems(subViews);
}
if (len) {
this.trigger('remove', subViews);
}
while (subViews && subViews.length) {
this._remove(subViews.shift());
}
return this;
} | [
"function",
"(",
"key",
",",
"preserveElems",
")",
"{",
"var",
"subViews",
"=",
"(",
"key",
"&&",
"(",
"typeof",
"key",
"===",
"\"string\"",
"||",
"key",
".",
"cid",
")",
")",
"?",
"this",
".",
"get",
"(",
"key",
")",
":",
"key",
";",
"var",
"len",
";",
"if",
"(",
"!",
"subViews",
")",
"{",
"return",
"this",
";",
"}",
"if",
"(",
"!",
"isArray",
"(",
"subViews",
")",
")",
"{",
"subViews",
"=",
"[",
"subViews",
"]",
";",
"}",
"len",
"=",
"subViews",
"?",
"subViews",
".",
"length",
":",
"0",
";",
"if",
"(",
"!",
"preserveElems",
")",
"{",
"this",
".",
"removeElems",
"(",
"subViews",
")",
";",
"}",
"if",
"(",
"len",
")",
"{",
"this",
".",
"trigger",
"(",
"'remove'",
",",
"subViews",
")",
";",
"}",
"while",
"(",
"subViews",
"&&",
"subViews",
".",
"length",
")",
"{",
"this",
".",
"_remove",
"(",
"subViews",
".",
"shift",
"(",
")",
")",
";",
"}",
"return",
"this",
";",
"}"
]
| Remove a subView
@memberOf SubViewManager#
@type {SubViewManager}
@param {String|Backbone.View|Backbone.Model} key
@param {Boolean} [preserveElems] If true, the View's element will not be removed from the DOM
@return {SubViewManager} | [
"Remove",
"a",
"subView"
]
| 9c49f9ac059ba3177b61f7395151de78b506e8f7 | https://github.com/1stdibs/backbone-base-and-form-view/blob/9c49f9ac059ba3177b61f7395151de78b506e8f7/backbone-baseview.js#L602-L620 |
|
41,761 | 1stdibs/backbone-base-and-form-view | backbone-baseview.js | function (keys, preserveElems) {
var i = 0;
var len = keys ? keys.length : 0;
for (i; i < len; i++) {
this.remove(keys[i], preserveElems);
}
return this;
} | javascript | function (keys, preserveElems) {
var i = 0;
var len = keys ? keys.length : 0;
for (i; i < len; i++) {
this.remove(keys[i], preserveElems);
}
return this;
} | [
"function",
"(",
"keys",
",",
"preserveElems",
")",
"{",
"var",
"i",
"=",
"0",
";",
"var",
"len",
"=",
"keys",
"?",
"keys",
".",
"length",
":",
"0",
";",
"for",
"(",
"i",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"this",
".",
"remove",
"(",
"keys",
"[",
"i",
"]",
",",
"preserveElems",
")",
";",
"}",
"return",
"this",
";",
"}"
]
| Remove's all subviews matching any
key in a list of keys
@memberOf SubViewManager#
@param {String[]} keys
@param {Boolean} [preserveElems=false]
If true, the views' elements will not
be removed from the DOM
@return {SubViewManager} | [
"Remove",
"s",
"all",
"subviews",
"matching",
"any",
"key",
"in",
"a",
"list",
"of",
"keys"
]
| 9c49f9ac059ba3177b61f7395151de78b506e8f7 | https://github.com/1stdibs/backbone-base-and-form-view/blob/9c49f9ac059ba3177b61f7395151de78b506e8f7/backbone-baseview.js#L631-L638 |
|
41,762 | 1stdibs/backbone-base-and-form-view | backbone-baseview.js | function (subViews) {
subViews = subViews || this.subViews;
var i = -1;
var len = subViews.length;
while (++i < len) {
subViews[i].remove();
}
return this;
} | javascript | function (subViews) {
subViews = subViews || this.subViews;
var i = -1;
var len = subViews.length;
while (++i < len) {
subViews[i].remove();
}
return this;
} | [
"function",
"(",
"subViews",
")",
"{",
"subViews",
"=",
"subViews",
"||",
"this",
".",
"subViews",
";",
"var",
"i",
"=",
"-",
"1",
";",
"var",
"len",
"=",
"subViews",
".",
"length",
";",
"while",
"(",
"++",
"i",
"<",
"len",
")",
"{",
"subViews",
"[",
"i",
"]",
".",
"remove",
"(",
")",
";",
"}",
"return",
"this",
";",
"}"
]
| Removes all subView '.el' element from the dom, or if passed a
list of subViews, removes only the elements in those.
@memberOf SubViewManager#
@type {SubViewManager}
@param {Backbone.View[]} subViews
@return {SubViewManager} | [
"Removes",
"all",
"subView",
".",
"el",
"element",
"from",
"the",
"dom",
"or",
"if",
"passed",
"a",
"list",
"of",
"subViews",
"removes",
"only",
"the",
"elements",
"in",
"those",
"."
]
| 9c49f9ac059ba3177b61f7395151de78b506e8f7 | https://github.com/1stdibs/backbone-base-and-form-view/blob/9c49f9ac059ba3177b61f7395151de78b506e8f7/backbone-baseview.js#L647-L656 |
|
41,763 | 1stdibs/backbone-base-and-form-view | backbone-baseview.js | function (key) {
if (key.cid) {
return this._subViewsByCid[key.cid] || this._subViewsByModelCid[key.cid];
}
if (key.indexOf('.') > -1 && this.dotNotation) {
var segs = key.split('.');
var view = this.parent;
while (segs.length && view) { view = view.subs.get(segs.shift()); }
return view;
}
return this._subViewSingletons[key] || this._subViewsByCid[key] ||
this._subViewsByModelCid[key] || this._subViewsByType[key];
} | javascript | function (key) {
if (key.cid) {
return this._subViewsByCid[key.cid] || this._subViewsByModelCid[key.cid];
}
if (key.indexOf('.') > -1 && this.dotNotation) {
var segs = key.split('.');
var view = this.parent;
while (segs.length && view) { view = view.subs.get(segs.shift()); }
return view;
}
return this._subViewSingletons[key] || this._subViewsByCid[key] ||
this._subViewsByModelCid[key] || this._subViewsByType[key];
} | [
"function",
"(",
"key",
")",
"{",
"if",
"(",
"key",
".",
"cid",
")",
"{",
"return",
"this",
".",
"_subViewsByCid",
"[",
"key",
".",
"cid",
"]",
"||",
"this",
".",
"_subViewsByModelCid",
"[",
"key",
".",
"cid",
"]",
";",
"}",
"if",
"(",
"key",
".",
"indexOf",
"(",
"'.'",
")",
">",
"-",
"1",
"&&",
"this",
".",
"dotNotation",
")",
"{",
"var",
"segs",
"=",
"key",
".",
"split",
"(",
"'.'",
")",
";",
"var",
"view",
"=",
"this",
".",
"parent",
";",
"while",
"(",
"segs",
".",
"length",
"&&",
"view",
")",
"{",
"view",
"=",
"view",
".",
"subs",
".",
"get",
"(",
"segs",
".",
"shift",
"(",
")",
")",
";",
"}",
"return",
"view",
";",
"}",
"return",
"this",
".",
"_subViewSingletons",
"[",
"key",
"]",
"||",
"this",
".",
"_subViewsByCid",
"[",
"key",
"]",
"||",
"this",
".",
"_subViewsByModelCid",
"[",
"key",
"]",
"||",
"this",
".",
"_subViewsByType",
"[",
"key",
"]",
";",
"}"
]
| Get a subView instance or an array if multiple instances
match your key.
@memberOf SubViewManager#
@type {SubViewManager}
@param {Object|String} [key]
The key to a subView singleton, the view's cid
the associated model cid, the associated model itself,
or the associated view itself. If your key is a
string, you can use
@return {Backbone.View|Backbone.View[]} | [
"Get",
"a",
"subView",
"instance",
"or",
"an",
"array",
"if",
"multiple",
"instances",
"match",
"your",
"key",
"."
]
| 9c49f9ac059ba3177b61f7395151de78b506e8f7 | https://github.com/1stdibs/backbone-base-and-form-view/blob/9c49f9ac059ba3177b61f7395151de78b506e8f7/backbone-baseview.js#L692-L705 |
|
41,764 | 1stdibs/backbone-base-and-form-view | backbone-baseview.js | function (subview) {
subview = (subview instanceof View === true) ? subview : this.get(subview);
return subview._subviewtype;
} | javascript | function (subview) {
subview = (subview instanceof View === true) ? subview : this.get(subview);
return subview._subviewtype;
} | [
"function",
"(",
"subview",
")",
"{",
"subview",
"=",
"(",
"subview",
"instanceof",
"View",
"===",
"true",
")",
"?",
"subview",
":",
"this",
".",
"get",
"(",
"subview",
")",
";",
"return",
"subview",
".",
"_subviewtype",
";",
"}"
]
| Get the subviews type or key
@memberOf SubViewManager#
@type {SubViewManager}
@param subview
@return {String|Number} | [
"Get",
"the",
"subviews",
"type",
"or",
"key"
]
| 9c49f9ac059ba3177b61f7395151de78b506e8f7 | https://github.com/1stdibs/backbone-base-and-form-view/blob/9c49f9ac059ba3177b61f7395151de78b506e8f7/backbone-baseview.js#L726-L729 |
|
41,765 | 1stdibs/backbone-base-and-form-view | backbone-baseview.js | function (type) {
var confs = type ? _.pick(this.config, type) : this.config;
each(confs, function (config) {
this.parent.$(config.location).html('');
}, this);
return this;
} | javascript | function (type) {
var confs = type ? _.pick(this.config, type) : this.config;
each(confs, function (config) {
this.parent.$(config.location).html('');
}, this);
return this;
} | [
"function",
"(",
"type",
")",
"{",
"var",
"confs",
"=",
"type",
"?",
"_",
".",
"pick",
"(",
"this",
".",
"config",
",",
"type",
")",
":",
"this",
".",
"config",
";",
"each",
"(",
"confs",
",",
"function",
"(",
"config",
")",
"{",
"this",
".",
"parent",
".",
"$",
"(",
"config",
".",
"location",
")",
".",
"html",
"(",
"''",
")",
";",
"}",
",",
"this",
")",
";",
"return",
"this",
";",
"}"
]
| Clears the html in all locations specified in the subview configs
@memberOf SubViewManager#
@type {SubViewManager}
@return {SubViewManager} | [
"Clears",
"the",
"html",
"in",
"all",
"locations",
"specified",
"in",
"the",
"subview",
"configs"
]
| 9c49f9ac059ba3177b61f7395151de78b506e8f7 | https://github.com/1stdibs/backbone-base-and-form-view/blob/9c49f9ac059ba3177b61f7395151de78b506e8f7/backbone-baseview.js#L747-L753 |
|
41,766 | 1stdibs/backbone-base-and-form-view | backbone-baseview.js | function () {
var html = '';
var template = this.template;
if (isFunction(template)) {
html = template(result(this, 'templateVars')) || '';
}
this.$el.html(html);
this.subs.renderAppend();
return this;
} | javascript | function () {
var html = '';
var template = this.template;
if (isFunction(template)) {
html = template(result(this, 'templateVars')) || '';
}
this.$el.html(html);
this.subs.renderAppend();
return this;
} | [
"function",
"(",
")",
"{",
"var",
"html",
"=",
"''",
";",
"var",
"template",
"=",
"this",
".",
"template",
";",
"if",
"(",
"isFunction",
"(",
"template",
")",
")",
"{",
"html",
"=",
"template",
"(",
"result",
"(",
"this",
",",
"'templateVars'",
")",
")",
"||",
"''",
";",
"}",
"this",
".",
"$el",
".",
"html",
"(",
"html",
")",
";",
"this",
".",
"subs",
".",
"renderAppend",
"(",
")",
";",
"return",
"this",
";",
"}"
]
| A basic render function that looks for a template
function, calls the template with the result of
the 'templateVars' property, and then set the html
to the result. Then, subviews are rendered and then
appended to their locations.
@memberOf Backbone.BaseView#
@return {Backbone.BaseView} | [
"A",
"basic",
"render",
"function",
"that",
"looks",
"for",
"a",
"template",
"function",
"calls",
"the",
"template",
"with",
"the",
"result",
"of",
"the",
"templateVars",
"property",
"and",
"then",
"set",
"the",
"html",
"to",
"the",
"result",
".",
"Then",
"subviews",
"are",
"rendered",
"and",
"then",
"appended",
"to",
"their",
"locations",
"."
]
| 9c49f9ac059ba3177b61f7395151de78b506e8f7 | https://github.com/1stdibs/backbone-base-and-form-view/blob/9c49f9ac059ba3177b61f7395151de78b506e8f7/backbone-baseview.js#L1105-L1114 |
|
41,767 | 1stdibs/backbone-base-and-form-view | backbone-baseview.js | function (event) {
var args = slice.call(arguments, 1);
var stopPropogation;
var anscestor;
args.unshift(event);
args.push(this);
anscestor = this;
while (anscestor) {
anscestor.trigger.apply(anscestor, args);
stopPropogation = anscestor._stopPropogation;
if (stopPropogation && stopPropogation[event]) {
stopPropogation[event] = false;
return this;
}
anscestor = anscestor.parentView;
}
return this;
} | javascript | function (event) {
var args = slice.call(arguments, 1);
var stopPropogation;
var anscestor;
args.unshift(event);
args.push(this);
anscestor = this;
while (anscestor) {
anscestor.trigger.apply(anscestor, args);
stopPropogation = anscestor._stopPropogation;
if (stopPropogation && stopPropogation[event]) {
stopPropogation[event] = false;
return this;
}
anscestor = anscestor.parentView;
}
return this;
} | [
"function",
"(",
"event",
")",
"{",
"var",
"args",
"=",
"slice",
".",
"call",
"(",
"arguments",
",",
"1",
")",
";",
"var",
"stopPropogation",
";",
"var",
"anscestor",
";",
"args",
".",
"unshift",
"(",
"event",
")",
";",
"args",
".",
"push",
"(",
"this",
")",
";",
"anscestor",
"=",
"this",
";",
"while",
"(",
"anscestor",
")",
"{",
"anscestor",
".",
"trigger",
".",
"apply",
"(",
"anscestor",
",",
"args",
")",
";",
"stopPropogation",
"=",
"anscestor",
".",
"_stopPropogation",
";",
"if",
"(",
"stopPropogation",
"&&",
"stopPropogation",
"[",
"event",
"]",
")",
"{",
"stopPropogation",
"[",
"event",
"]",
"=",
"false",
";",
"return",
"this",
";",
"}",
"anscestor",
"=",
"anscestor",
".",
"parentView",
";",
"}",
"return",
"this",
";",
"}"
]
| Like Backbone.trigger, except that this will not only use trigger
on the instance this method is invoked on, but also the instance's
'parentView', and the parentView's parentView, and so on.
Additional arguments beyond the event name will be passed
as arguments to the event handler functions. The view that
originated the bubbling event will automatically be tacked
on to the end of the arguments, so you can access it if needed.
@memberOf Backbone.BaseView#
@param {String} event The name of the event
@param {...Mixed} [arg] Argument be passed to event callbacks
@return {Backbone.BaseView} | [
"Like",
"Backbone",
".",
"trigger",
"except",
"that",
"this",
"will",
"not",
"only",
"use",
"trigger",
"on",
"the",
"instance",
"this",
"method",
"is",
"invoked",
"on",
"but",
"also",
"the",
"instance",
"s",
"parentView",
"and",
"the",
"parentView",
"s",
"parentView",
"and",
"so",
"on",
".",
"Additional",
"arguments",
"beyond",
"the",
"event",
"name",
"will",
"be",
"passed",
"as",
"arguments",
"to",
"the",
"event",
"handler",
"functions",
".",
"The",
"view",
"that",
"originated",
"the",
"bubbling",
"event",
"will",
"automatically",
"be",
"tacked",
"on",
"to",
"the",
"end",
"of",
"the",
"arguments",
"so",
"you",
"can",
"access",
"it",
"if",
"needed",
"."
]
| 9c49f9ac059ba3177b61f7395151de78b506e8f7 | https://github.com/1stdibs/backbone-base-and-form-view/blob/9c49f9ac059ba3177b61f7395151de78b506e8f7/backbone-baseview.js#L1177-L1194 |
|
41,768 | 1stdibs/backbone-base-and-form-view | backbone-baseview.js | function (event) {
var args = slice.call(arguments, 1);
var _trigger = function (subViews) {
var i = -1;
var len = subViews.length;
var subSubs;
var stopPropogation;
var descend;
while (++i < len) {
descend = true;
subViews[i].trigger.apply(subViews[i], args);
stopPropogation = subViews[i]._stopPropogation;
if (stopPropogation && stopPropogation[event]) {
stopPropogation[event] = false;
descend = false;
}
subSubs = subViews[i].subViews;
if (descend && subSubs && subSubs.length) {
_trigger(subSubs);
}
}
};
args.unshift(event);
args.push(this);
_trigger([this]);
return this;
} | javascript | function (event) {
var args = slice.call(arguments, 1);
var _trigger = function (subViews) {
var i = -1;
var len = subViews.length;
var subSubs;
var stopPropogation;
var descend;
while (++i < len) {
descend = true;
subViews[i].trigger.apply(subViews[i], args);
stopPropogation = subViews[i]._stopPropogation;
if (stopPropogation && stopPropogation[event]) {
stopPropogation[event] = false;
descend = false;
}
subSubs = subViews[i].subViews;
if (descend && subSubs && subSubs.length) {
_trigger(subSubs);
}
}
};
args.unshift(event);
args.push(this);
_trigger([this]);
return this;
} | [
"function",
"(",
"event",
")",
"{",
"var",
"args",
"=",
"slice",
".",
"call",
"(",
"arguments",
",",
"1",
")",
";",
"var",
"_trigger",
"=",
"function",
"(",
"subViews",
")",
"{",
"var",
"i",
"=",
"-",
"1",
";",
"var",
"len",
"=",
"subViews",
".",
"length",
";",
"var",
"subSubs",
";",
"var",
"stopPropogation",
";",
"var",
"descend",
";",
"while",
"(",
"++",
"i",
"<",
"len",
")",
"{",
"descend",
"=",
"true",
";",
"subViews",
"[",
"i",
"]",
".",
"trigger",
".",
"apply",
"(",
"subViews",
"[",
"i",
"]",
",",
"args",
")",
";",
"stopPropogation",
"=",
"subViews",
"[",
"i",
"]",
".",
"_stopPropogation",
";",
"if",
"(",
"stopPropogation",
"&&",
"stopPropogation",
"[",
"event",
"]",
")",
"{",
"stopPropogation",
"[",
"event",
"]",
"=",
"false",
";",
"descend",
"=",
"false",
";",
"}",
"subSubs",
"=",
"subViews",
"[",
"i",
"]",
".",
"subViews",
";",
"if",
"(",
"descend",
"&&",
"subSubs",
"&&",
"subSubs",
".",
"length",
")",
"{",
"_trigger",
"(",
"subSubs",
")",
";",
"}",
"}",
"}",
";",
"args",
".",
"unshift",
"(",
"event",
")",
";",
"args",
".",
"push",
"(",
"this",
")",
";",
"_trigger",
"(",
"[",
"this",
"]",
")",
";",
"return",
"this",
";",
"}"
]
| Triggers an event that will trigger on each of the instances
subViews, and then if a subView has subViews, will trigger the
event on that subViews' subViews, and so on. If a subView
calls stopEvent and passes the event name, then the event
will not trigger on that subViews' subViews. Arguments
work in the same manner as they do with triggerBubble.
@memberOf Backbone.BaseView#
@param {String} event The event name
@param {...Mixed} [arg] Argument be passed to event callbacks
@return {Backbone.BaseView} | [
"Triggers",
"an",
"event",
"that",
"will",
"trigger",
"on",
"each",
"of",
"the",
"instances",
"subViews",
"and",
"then",
"if",
"a",
"subView",
"has",
"subViews",
"will",
"trigger",
"the",
"event",
"on",
"that",
"subViews",
"subViews",
"and",
"so",
"on",
".",
"If",
"a",
"subView",
"calls",
"stopEvent",
"and",
"passes",
"the",
"event",
"name",
"then",
"the",
"event",
"will",
"not",
"trigger",
"on",
"that",
"subViews",
"subViews",
".",
"Arguments",
"work",
"in",
"the",
"same",
"manner",
"as",
"they",
"do",
"with",
"triggerBubble",
"."
]
| 9c49f9ac059ba3177b61f7395151de78b506e8f7 | https://github.com/1stdibs/backbone-base-and-form-view/blob/9c49f9ac059ba3177b61f7395151de78b506e8f7/backbone-baseview.js#L1207-L1233 |
|
41,769 | 1stdibs/backbone-base-and-form-view | backbone-baseview.js | function (fnName, args) {
var func;
var ancestor = this;
var isFunc = isFunction(fnName);
while (ancestor.parentView) {
ancestor = ancestor.parentView;
if (ancestor) {
func = isFunc ? fnName : ancestor[fnName];
func.apply(ancestor, args);
}
}
return this;
} | javascript | function (fnName, args) {
var func;
var ancestor = this;
var isFunc = isFunction(fnName);
while (ancestor.parentView) {
ancestor = ancestor.parentView;
if (ancestor) {
func = isFunc ? fnName : ancestor[fnName];
func.apply(ancestor, args);
}
}
return this;
} | [
"function",
"(",
"fnName",
",",
"args",
")",
"{",
"var",
"func",
";",
"var",
"ancestor",
"=",
"this",
";",
"var",
"isFunc",
"=",
"isFunction",
"(",
"fnName",
")",
";",
"while",
"(",
"ancestor",
".",
"parentView",
")",
"{",
"ancestor",
"=",
"ancestor",
".",
"parentView",
";",
"if",
"(",
"ancestor",
")",
"{",
"func",
"=",
"isFunc",
"?",
"fnName",
":",
"ancestor",
"[",
"fnName",
"]",
";",
"func",
".",
"apply",
"(",
"ancestor",
",",
"args",
")",
";",
"}",
"}",
"return",
"this",
";",
"}"
]
| Invoke a function or method on ancestors
@memberOf Backbone.BaseView#
@param {Function|String} fnName
@param {mixed[]} [args]
An array of arguments to pass to
the invocation
@return {Backbone.BaseView} | [
"Invoke",
"a",
"function",
"or",
"method",
"on",
"ancestors"
]
| 9c49f9ac059ba3177b61f7395151de78b506e8f7 | https://github.com/1stdibs/backbone-base-and-form-view/blob/9c49f9ac059ba3177b61f7395151de78b506e8f7/backbone-baseview.js#L1243-L1255 |
|
41,770 | 1stdibs/backbone-base-and-form-view | backbone-baseview.js | function (testFn) {
var ancestor = this;
while (ancestor.parentView) {
ancestor = ancestor.parentView;
if (ancestor && testFn(ancestor)) {
return ancestor;
}
}
return null;
} | javascript | function (testFn) {
var ancestor = this;
while (ancestor.parentView) {
ancestor = ancestor.parentView;
if (ancestor && testFn(ancestor)) {
return ancestor;
}
}
return null;
} | [
"function",
"(",
"testFn",
")",
"{",
"var",
"ancestor",
"=",
"this",
";",
"while",
"(",
"ancestor",
".",
"parentView",
")",
"{",
"ancestor",
"=",
"ancestor",
".",
"parentView",
";",
"if",
"(",
"ancestor",
"&&",
"testFn",
"(",
"ancestor",
")",
")",
"{",
"return",
"ancestor",
";",
"}",
"}",
"return",
"null",
";",
"}"
]
| Ascends up the ancestor line until an
a test function returns true
@param {Function} testFn
A function that returns a truthy
value if the current ancestor should be
returned
@return {Backbone.BaseView|null} | [
"Ascends",
"up",
"the",
"ancestor",
"line",
"until",
"an",
"a",
"test",
"function",
"returns",
"true"
]
| 9c49f9ac059ba3177b61f7395151de78b506e8f7 | https://github.com/1stdibs/backbone-base-and-form-view/blob/9c49f9ac059ba3177b61f7395151de78b506e8f7/backbone-baseview.js#L1265-L1274 |
|
41,771 | 1stdibs/backbone-base-and-form-view | backbone-baseview.js | function (events) {
events = events || result(this, 'viewEvents');
each(events, function (func, event) {
var segs = event.split(' ');
var listenTo = (segs.length > 1) ? this[segs[1]] : this;
func = isFunction(func) ? func : this[func];
if (listenTo) {
this.stopListening(listenTo, segs[0], func);
this.listenTo(listenTo, segs[0], func);
}
}, this);
return this;
} | javascript | function (events) {
events = events || result(this, 'viewEvents');
each(events, function (func, event) {
var segs = event.split(' ');
var listenTo = (segs.length > 1) ? this[segs[1]] : this;
func = isFunction(func) ? func : this[func];
if (listenTo) {
this.stopListening(listenTo, segs[0], func);
this.listenTo(listenTo, segs[0], func);
}
}, this);
return this;
} | [
"function",
"(",
"events",
")",
"{",
"events",
"=",
"events",
"||",
"result",
"(",
"this",
",",
"'viewEvents'",
")",
";",
"each",
"(",
"events",
",",
"function",
"(",
"func",
",",
"event",
")",
"{",
"var",
"segs",
"=",
"event",
".",
"split",
"(",
"' '",
")",
";",
"var",
"listenTo",
"=",
"(",
"segs",
".",
"length",
">",
"1",
")",
"?",
"this",
"[",
"segs",
"[",
"1",
"]",
"]",
":",
"this",
";",
"func",
"=",
"isFunction",
"(",
"func",
")",
"?",
"func",
":",
"this",
"[",
"func",
"]",
";",
"if",
"(",
"listenTo",
")",
"{",
"this",
".",
"stopListening",
"(",
"listenTo",
",",
"segs",
"[",
"0",
"]",
",",
"func",
")",
";",
"this",
".",
"listenTo",
"(",
"listenTo",
",",
"segs",
"[",
"0",
"]",
",",
"func",
")",
";",
"}",
"}",
",",
"this",
")",
";",
"return",
"this",
";",
"}"
]
| Like delegateEvents, except that instead of events being bound to el, the
events are backbone events bound to the view object itself. You can create
a 'viewEvents' object literal property on a View's prototype, and when it's
instantiated, the view will listen for events on a Backone object based on
the key.
For example { 'change model': 'render' } would listen for a 'change'
event on the view's model property and then call view's render method.
If you only specify an event name and leave the property out of the key,
then the event will be bound to the view instance directly. For example,
{ 'submit' : 'render' } would call the render method of the view when
a 'submit' event occurs on the view.
@memberOf Backbone.BaseView#
return {Backbone.BaseView} | [
"Like",
"delegateEvents",
"except",
"that",
"instead",
"of",
"events",
"being",
"bound",
"to",
"el",
"the",
"events",
"are",
"backbone",
"events",
"bound",
"to",
"the",
"view",
"object",
"itself",
".",
"You",
"can",
"create",
"a",
"viewEvents",
"object",
"literal",
"property",
"on",
"a",
"View",
"s",
"prototype",
"and",
"when",
"it",
"s",
"instantiated",
"the",
"view",
"will",
"listen",
"for",
"events",
"on",
"a",
"Backone",
"object",
"based",
"on",
"the",
"key",
"."
]
| 9c49f9ac059ba3177b61f7395151de78b506e8f7 | https://github.com/1stdibs/backbone-base-and-form-view/blob/9c49f9ac059ba3177b61f7395151de78b506e8f7/backbone-baseview.js#L1345-L1357 |
|
41,772 | 1stdibs/backbone-base-and-form-view | backbone-baseview.js | function (viewInstance) {
console.assert(viewInstance instanceof Backbone.BaseView, 'viewInstance must be an instance of Backbone.BaseView');
var mixins = slice.call(arguments, 1);
_marinate(viewInstance, mixins);
} | javascript | function (viewInstance) {
console.assert(viewInstance instanceof Backbone.BaseView, 'viewInstance must be an instance of Backbone.BaseView');
var mixins = slice.call(arguments, 1);
_marinate(viewInstance, mixins);
} | [
"function",
"(",
"viewInstance",
")",
"{",
"console",
".",
"assert",
"(",
"viewInstance",
"instanceof",
"Backbone",
".",
"BaseView",
",",
"'viewInstance must be an instance of Backbone.BaseView'",
")",
";",
"var",
"mixins",
"=",
"slice",
".",
"call",
"(",
"arguments",
",",
"1",
")",
";",
"_marinate",
"(",
"viewInstance",
",",
"mixins",
")",
";",
"}"
]
| Marinate only an instance of a view
@memberOf module:marinate
@param {Backbone.BaseView} viewInstance
@param {...object} mixins | [
"Marinate",
"only",
"an",
"instance",
"of",
"a",
"view"
]
| 9c49f9ac059ba3177b61f7395151de78b506e8f7 | https://github.com/1stdibs/backbone-base-and-form-view/blob/9c49f9ac059ba3177b61f7395151de78b506e8f7/backbone-baseview.js#L1460-L1464 |
|
41,773 | 1stdibs/backbone-base-and-form-view | backbone-baseview.js | function (View, name, eventsObj) { //eslint-disable-line no-shadow
console.assert(View.prototype instanceof Backbone.BaseView, 'View must a Backbone.BaseView constructor');
_addEvents(View.prototype, name, eventsObj);
} | javascript | function (View, name, eventsObj) { //eslint-disable-line no-shadow
console.assert(View.prototype instanceof Backbone.BaseView, 'View must a Backbone.BaseView constructor');
_addEvents(View.prototype, name, eventsObj);
} | [
"function",
"(",
"View",
",",
"name",
",",
"eventsObj",
")",
"{",
"//eslint-disable-line no-shadow",
"console",
".",
"assert",
"(",
"View",
".",
"prototype",
"instanceof",
"Backbone",
".",
"BaseView",
",",
"'View must a Backbone.BaseView constructor'",
")",
";",
"_addEvents",
"(",
"View",
".",
"prototype",
",",
"name",
",",
"eventsObj",
")",
";",
"}"
]
| Add DOM events to a BaseView pseudoclass
@memberOf module:marinate
@param {function} View Constructor for Backbone.BaseView
@param {string} name Namespace for your added events
@param {object} eventsObj Backbone DOM events hash | [
"Add",
"DOM",
"events",
"to",
"a",
"BaseView",
"pseudoclass"
]
| 9c49f9ac059ba3177b61f7395151de78b506e8f7 | https://github.com/1stdibs/backbone-base-and-form-view/blob/9c49f9ac059ba3177b61f7395151de78b506e8f7/backbone-baseview.js#L1472-L1475 |
|
41,774 | 1stdibs/backbone-base-and-form-view | backbone-baseview.js | function (viewInstance, name, eventsObj) {
console.assert(viewInstance instanceof Backbone.BaseView, 'viewInstance must be an instance of Backbone.BaseView');
_addEvents(viewInstance, name, eventsObj);
} | javascript | function (viewInstance, name, eventsObj) {
console.assert(viewInstance instanceof Backbone.BaseView, 'viewInstance must be an instance of Backbone.BaseView');
_addEvents(viewInstance, name, eventsObj);
} | [
"function",
"(",
"viewInstance",
",",
"name",
",",
"eventsObj",
")",
"{",
"console",
".",
"assert",
"(",
"viewInstance",
"instanceof",
"Backbone",
".",
"BaseView",
",",
"'viewInstance must be an instance of Backbone.BaseView'",
")",
";",
"_addEvents",
"(",
"viewInstance",
",",
"name",
",",
"eventsObj",
")",
";",
"}"
]
| Add DOM events to a BaseView instance
@memberOf module:marinate
@param {Backbone.BaseView} viewInstance
@param {string} name Namespace for your added events
@param {object} eventsObj Backbone DOM events hash | [
"Add",
"DOM",
"events",
"to",
"a",
"BaseView",
"instance"
]
| 9c49f9ac059ba3177b61f7395151de78b506e8f7 | https://github.com/1stdibs/backbone-base-and-form-view/blob/9c49f9ac059ba3177b61f7395151de78b506e8f7/backbone-baseview.js#L1483-L1486 |
|
41,775 | chip-js/observations-js | src/observations.js | function(context, expression, onChange, callbackContext) {
var observer = this.createObserver(expression, onChange, callbackContext || context);
observer.bind(context);
return observer;
} | javascript | function(context, expression, onChange, callbackContext) {
var observer = this.createObserver(expression, onChange, callbackContext || context);
observer.bind(context);
return observer;
} | [
"function",
"(",
"context",
",",
"expression",
",",
"onChange",
",",
"callbackContext",
")",
"{",
"var",
"observer",
"=",
"this",
".",
"createObserver",
"(",
"expression",
",",
"onChange",
",",
"callbackContext",
"||",
"context",
")",
";",
"observer",
".",
"bind",
"(",
"context",
")",
";",
"return",
"observer",
";",
"}"
]
| Observes any changes to the result of the expression on the context object and calls the callback.
@param {Object} context The context to bind the expression against
@param {String} expression The expression to observe
@param {Function} onChange The function which will be called when the expression value changes
@return {Observer} The observer created | [
"Observes",
"any",
"changes",
"to",
"the",
"result",
"of",
"the",
"expression",
"on",
"the",
"context",
"object",
"and",
"calls",
"the",
"callback",
"."
]
| a48b32a648089bc86b502712d78cd0b3f8317d50 | https://github.com/chip-js/observations-js/blob/a48b32a648089bc86b502712d78cd0b3f8317d50/src/observations.js#L56-L60 |
|
41,776 | chip-js/observations-js | src/observations.js | function(expression, options) {
if (options && options.isSetter) {
return expressions.parseSetter(expression, this.globals, this.formatters, options.extraArgs);
} else if (options && options.extraArgs) {
var allArgs = [expression, this.globals, this.formatters].concat(options.extraArgs);
return expressions.parse.apply(expressions, allArgs);
} else {
return expressions.parse(expression, this.globals, this.formatters);
}
} | javascript | function(expression, options) {
if (options && options.isSetter) {
return expressions.parseSetter(expression, this.globals, this.formatters, options.extraArgs);
} else if (options && options.extraArgs) {
var allArgs = [expression, this.globals, this.formatters].concat(options.extraArgs);
return expressions.parse.apply(expressions, allArgs);
} else {
return expressions.parse(expression, this.globals, this.formatters);
}
} | [
"function",
"(",
"expression",
",",
"options",
")",
"{",
"if",
"(",
"options",
"&&",
"options",
".",
"isSetter",
")",
"{",
"return",
"expressions",
".",
"parseSetter",
"(",
"expression",
",",
"this",
".",
"globals",
",",
"this",
".",
"formatters",
",",
"options",
".",
"extraArgs",
")",
";",
"}",
"else",
"if",
"(",
"options",
"&&",
"options",
".",
"extraArgs",
")",
"{",
"var",
"allArgs",
"=",
"[",
"expression",
",",
"this",
".",
"globals",
",",
"this",
".",
"formatters",
"]",
".",
"concat",
"(",
"options",
".",
"extraArgs",
")",
";",
"return",
"expressions",
".",
"parse",
".",
"apply",
"(",
"expressions",
",",
"allArgs",
")",
";",
"}",
"else",
"{",
"return",
"expressions",
".",
"parse",
"(",
"expression",
",",
"this",
".",
"globals",
",",
"this",
".",
"formatters",
")",
";",
"}",
"}"
]
| Parses an expression into a function using the globals and formatters objects associated with this instance of
observations.
@param {String} expression The expression string to parse into a function
@param {Object} options Additional options to pass to the parser.
`{ isSetter: true }` will make this expression a setter that accepts a value.
`{ extraArgs: [ 'argName' ]` will make extra arguments to pass in to the function.
@return {Function} A function that may be called to execute the expression (call it against a context using=
`func.call(context)` in order to get the data from the context correct) | [
"Parses",
"an",
"expression",
"into",
"a",
"function",
"using",
"the",
"globals",
"and",
"formatters",
"objects",
"associated",
"with",
"this",
"instance",
"of",
"observations",
"."
]
| a48b32a648089bc86b502712d78cd0b3f8317d50 | https://github.com/chip-js/observations-js/blob/a48b32a648089bc86b502712d78cd0b3f8317d50/src/observations.js#L181-L190 |
|
41,777 | chip-js/observations-js | src/observations.js | function(source, expression, value) {
return this.getExpression(expression, { isSetter: true }).call(source, value);
} | javascript | function(source, expression, value) {
return this.getExpression(expression, { isSetter: true }).call(source, value);
} | [
"function",
"(",
"source",
",",
"expression",
",",
"value",
")",
"{",
"return",
"this",
".",
"getExpression",
"(",
"expression",
",",
"{",
"isSetter",
":",
"true",
"}",
")",
".",
"call",
"(",
"source",
",",
"value",
")",
";",
"}"
]
| Sets the value on the expression in the given context object
@param {Object} context The context object the expression will be evaluated against
@param {String} expression The expression to set a value with
@param {mixed} value The value to set on the expression
@return {mixed} The result of the expression against the context | [
"Sets",
"the",
"value",
"on",
"the",
"expression",
"in",
"the",
"given",
"context",
"object"
]
| a48b32a648089bc86b502712d78cd0b3f8317d50 | https://github.com/chip-js/observations-js/blob/a48b32a648089bc86b502712d78cd0b3f8317d50/src/observations.js#L211-L213 |
|
41,778 | chip-js/observations-js | src/observations.js | function(callback) {
if (typeof callback === 'function') {
this.afterSync(callback);
}
if (this.pendingSync) {
return false;
}
var fallback = setTimeout(this.syncNow, 500);
this.windows = this.windows.filter(this.removeClosed);
this.pendingSync = this.windows.map(this.queueSync).concat(fallback);
return true;
} | javascript | function(callback) {
if (typeof callback === 'function') {
this.afterSync(callback);
}
if (this.pendingSync) {
return false;
}
var fallback = setTimeout(this.syncNow, 500);
this.windows = this.windows.filter(this.removeClosed);
this.pendingSync = this.windows.map(this.queueSync).concat(fallback);
return true;
} | [
"function",
"(",
"callback",
")",
"{",
"if",
"(",
"typeof",
"callback",
"===",
"'function'",
")",
"{",
"this",
".",
"afterSync",
"(",
"callback",
")",
";",
"}",
"if",
"(",
"this",
".",
"pendingSync",
")",
"{",
"return",
"false",
";",
"}",
"var",
"fallback",
"=",
"setTimeout",
"(",
"this",
".",
"syncNow",
",",
"500",
")",
";",
"this",
".",
"windows",
"=",
"this",
".",
"windows",
".",
"filter",
"(",
"this",
".",
"removeClosed",
")",
";",
"this",
".",
"pendingSync",
"=",
"this",
".",
"windows",
".",
"map",
"(",
"this",
".",
"queueSync",
")",
".",
"concat",
"(",
"fallback",
")",
";",
"return",
"true",
";",
"}"
]
| Schedules an observer sync cycle which checks all the observers to see if they've changed. | [
"Schedules",
"an",
"observer",
"sync",
"cycle",
"which",
"checks",
"all",
"the",
"observers",
"to",
"see",
"if",
"they",
"ve",
"changed",
"."
]
| a48b32a648089bc86b502712d78cd0b3f8317d50 | https://github.com/chip-js/observations-js/blob/a48b32a648089bc86b502712d78cd0b3f8317d50/src/observations.js#L217-L230 |
|
41,779 | chip-js/observations-js | src/observations.js | function(callback) {
if (typeof callback === 'function') {
this.afterSync(callback);
}
if (this.pendingSync) {
clearTimeout(this.pendingSync.pop());
this.pendingSync.forEach(this.cancelQueue);
this.pendingSync = null;
}
if (this.syncing) {
this.rerun = true;
return false;
}
this.runSync();
return true;
} | javascript | function(callback) {
if (typeof callback === 'function') {
this.afterSync(callback);
}
if (this.pendingSync) {
clearTimeout(this.pendingSync.pop());
this.pendingSync.forEach(this.cancelQueue);
this.pendingSync = null;
}
if (this.syncing) {
this.rerun = true;
return false;
}
this.runSync();
return true;
} | [
"function",
"(",
"callback",
")",
"{",
"if",
"(",
"typeof",
"callback",
"===",
"'function'",
")",
"{",
"this",
".",
"afterSync",
"(",
"callback",
")",
";",
"}",
"if",
"(",
"this",
".",
"pendingSync",
")",
"{",
"clearTimeout",
"(",
"this",
".",
"pendingSync",
".",
"pop",
"(",
")",
")",
";",
"this",
".",
"pendingSync",
".",
"forEach",
"(",
"this",
".",
"cancelQueue",
")",
";",
"this",
".",
"pendingSync",
"=",
"null",
";",
"}",
"if",
"(",
"this",
".",
"syncing",
")",
"{",
"this",
".",
"rerun",
"=",
"true",
";",
"return",
"false",
";",
"}",
"this",
".",
"runSync",
"(",
")",
";",
"return",
"true",
";",
"}"
]
| Runs the observer sync cycle which checks all the observers to see if they've changed. | [
"Runs",
"the",
"observer",
"sync",
"cycle",
"which",
"checks",
"all",
"the",
"observers",
"to",
"see",
"if",
"they",
"ve",
"changed",
"."
]
| a48b32a648089bc86b502712d78cd0b3f8317d50 | https://github.com/chip-js/observations-js/blob/a48b32a648089bc86b502712d78cd0b3f8317d50/src/observations.js#L234-L252 |
|
41,780 | chip-js/observations-js | src/observations.js | function(observer, skipUpdate) {
this.observers.add(observer);
if (!skipUpdate) {
observer.forceUpdateNextSync = true;
observer.sync();
}
} | javascript | function(observer, skipUpdate) {
this.observers.add(observer);
if (!skipUpdate) {
observer.forceUpdateNextSync = true;
observer.sync();
}
} | [
"function",
"(",
"observer",
",",
"skipUpdate",
")",
"{",
"this",
".",
"observers",
".",
"add",
"(",
"observer",
")",
";",
"if",
"(",
"!",
"skipUpdate",
")",
"{",
"observer",
".",
"forceUpdateNextSync",
"=",
"true",
";",
"observer",
".",
"sync",
"(",
")",
";",
"}",
"}"
]
| Adds a new observer to be synced with changes. If `skipUpdate` is true then the callback will only be called when a change is made, not initially. | [
"Adds",
"a",
"new",
"observer",
"to",
"be",
"synced",
"with",
"changes",
".",
"If",
"skipUpdate",
"is",
"true",
"then",
"the",
"callback",
"will",
"only",
"be",
"called",
"when",
"a",
"change",
"is",
"made",
"not",
"initially",
"."
]
| a48b32a648089bc86b502712d78cd0b3f8317d50 | https://github.com/chip-js/observations-js/blob/a48b32a648089bc86b502712d78cd0b3f8317d50/src/observations.js#L329-L335 |
|
41,781 | inadarei/nodebootstrap-server | app.js | configure_logging | function configure_logging() {
if ('log' in CONF) {
if ('plugin' in CONF.log) { process.env.NODE_LOGGER_PLUGIN = CONF.log.plugin; }
if ('level' in CONF.log) { process.env.NODE_LOGGER_LEVEL = CONF.log.level; }
if ('customlevels' in CONF.log) {
for (var key in CONF.log.customlevels) {
process.env['NODE_LOGGER_LEVEL_' + key] = CONF.log.customlevels[key];
}
}
}
} | javascript | function configure_logging() {
if ('log' in CONF) {
if ('plugin' in CONF.log) { process.env.NODE_LOGGER_PLUGIN = CONF.log.plugin; }
if ('level' in CONF.log) { process.env.NODE_LOGGER_LEVEL = CONF.log.level; }
if ('customlevels' in CONF.log) {
for (var key in CONF.log.customlevels) {
process.env['NODE_LOGGER_LEVEL_' + key] = CONF.log.customlevels[key];
}
}
}
} | [
"function",
"configure_logging",
"(",
")",
"{",
"if",
"(",
"'log'",
"in",
"CONF",
")",
"{",
"if",
"(",
"'plugin'",
"in",
"CONF",
".",
"log",
")",
"{",
"process",
".",
"env",
".",
"NODE_LOGGER_PLUGIN",
"=",
"CONF",
".",
"log",
".",
"plugin",
";",
"}",
"if",
"(",
"'level'",
"in",
"CONF",
".",
"log",
")",
"{",
"process",
".",
"env",
".",
"NODE_LOGGER_LEVEL",
"=",
"CONF",
".",
"log",
".",
"level",
";",
"}",
"if",
"(",
"'customlevels'",
"in",
"CONF",
".",
"log",
")",
"{",
"for",
"(",
"var",
"key",
"in",
"CONF",
".",
"log",
".",
"customlevels",
")",
"{",
"process",
".",
"env",
"[",
"'NODE_LOGGER_LEVEL_'",
"+",
"key",
"]",
"=",
"CONF",
".",
"log",
".",
"customlevels",
"[",
"key",
"]",
";",
"}",
"}",
"}",
"}"
]
| Default configuration of logging | [
"Default",
"configuration",
"of",
"logging"
]
| 250b5affd440b6030e7fb7eb435c5d952abf91af | https://github.com/inadarei/nodebootstrap-server/blob/250b5affd440b6030e7fb7eb435c5d952abf91af/app.js#L117-L129 |
41,782 | ofidj/fidj | .todo/miapp.tools.storage.js | errorMessage | function errorMessage(fileError) {
var msg = '';
switch (fileError.code) {
case FileError.NOT_FOUND_ERR:
msg = 'File not found';
break;
case FileError.SECURITY_ERR:
// You may need the --allow-file-access-from-files flag
// if you're debugging your app from file://.
msg = 'Security error';
break;
case FileError.ABORT_ERR:
msg = 'Aborted';
break;
case FileError.NOT_READABLE_ERR:
msg = 'File not readable';
break;
case FileError.ENCODING_ERR:
msg = 'Encoding error';
break;
case FileError.NO_MODIFICATION_ALLOWED_ERR:
msg = 'File not modifiable';
break;
case FileError.INVALID_STATE_ERR:
msg = 'Invalid state';
break;
case FileError.SYNTAX_ERR:
msg = 'Syntax error';
break;
case FileError.INVALID_MODIFICATION_ERR:
msg = 'Invalid modification';
break;
case FileError.QUOTA_EXCEEDED_ERR:
// You may need the --allow-file-access-from-files flag
// if you're debugging your app from file://.
msg = 'Quota exceeded';
break;
case FileError.TYPE_MISMATCH_ERR:
msg = 'Type mismatch';
break;
case FileError.PATH_EXISTS_ERR:
msg = 'File already exists';
break;
default:
msg = 'Unknown FileError code (code= ' + fileError.code + ', type=' + typeof(fileError) + ')';
break;
}
return msg;
} | javascript | function errorMessage(fileError) {
var msg = '';
switch (fileError.code) {
case FileError.NOT_FOUND_ERR:
msg = 'File not found';
break;
case FileError.SECURITY_ERR:
// You may need the --allow-file-access-from-files flag
// if you're debugging your app from file://.
msg = 'Security error';
break;
case FileError.ABORT_ERR:
msg = 'Aborted';
break;
case FileError.NOT_READABLE_ERR:
msg = 'File not readable';
break;
case FileError.ENCODING_ERR:
msg = 'Encoding error';
break;
case FileError.NO_MODIFICATION_ALLOWED_ERR:
msg = 'File not modifiable';
break;
case FileError.INVALID_STATE_ERR:
msg = 'Invalid state';
break;
case FileError.SYNTAX_ERR:
msg = 'Syntax error';
break;
case FileError.INVALID_MODIFICATION_ERR:
msg = 'Invalid modification';
break;
case FileError.QUOTA_EXCEEDED_ERR:
// You may need the --allow-file-access-from-files flag
// if you're debugging your app from file://.
msg = 'Quota exceeded';
break;
case FileError.TYPE_MISMATCH_ERR:
msg = 'Type mismatch';
break;
case FileError.PATH_EXISTS_ERR:
msg = 'File already exists';
break;
default:
msg = 'Unknown FileError code (code= ' + fileError.code + ', type=' + typeof(fileError) + ')';
break;
}
return msg;
} | [
"function",
"errorMessage",
"(",
"fileError",
")",
"{",
"var",
"msg",
"=",
"''",
";",
"switch",
"(",
"fileError",
".",
"code",
")",
"{",
"case",
"FileError",
".",
"NOT_FOUND_ERR",
":",
"msg",
"=",
"'File not found'",
";",
"break",
";",
"case",
"FileError",
".",
"SECURITY_ERR",
":",
"// You may need the --allow-file-access-from-files flag",
"// if you're debugging your app from file://.",
"msg",
"=",
"'Security error'",
";",
"break",
";",
"case",
"FileError",
".",
"ABORT_ERR",
":",
"msg",
"=",
"'Aborted'",
";",
"break",
";",
"case",
"FileError",
".",
"NOT_READABLE_ERR",
":",
"msg",
"=",
"'File not readable'",
";",
"break",
";",
"case",
"FileError",
".",
"ENCODING_ERR",
":",
"msg",
"=",
"'Encoding error'",
";",
"break",
";",
"case",
"FileError",
".",
"NO_MODIFICATION_ALLOWED_ERR",
":",
"msg",
"=",
"'File not modifiable'",
";",
"break",
";",
"case",
"FileError",
".",
"INVALID_STATE_ERR",
":",
"msg",
"=",
"'Invalid state'",
";",
"break",
";",
"case",
"FileError",
".",
"SYNTAX_ERR",
":",
"msg",
"=",
"'Syntax error'",
";",
"break",
";",
"case",
"FileError",
".",
"INVALID_MODIFICATION_ERR",
":",
"msg",
"=",
"'Invalid modification'",
";",
"break",
";",
"case",
"FileError",
".",
"QUOTA_EXCEEDED_ERR",
":",
"// You may need the --allow-file-access-from-files flag",
"// if you're debugging your app from file://.",
"msg",
"=",
"'Quota exceeded'",
";",
"break",
";",
"case",
"FileError",
".",
"TYPE_MISMATCH_ERR",
":",
"msg",
"=",
"'Type mismatch'",
";",
"break",
";",
"case",
"FileError",
".",
"PATH_EXISTS_ERR",
":",
"msg",
"=",
"'File already exists'",
";",
"break",
";",
"default",
":",
"msg",
"=",
"'Unknown FileError code (code= '",
"+",
"fileError",
".",
"code",
"+",
"', type='",
"+",
"typeof",
"(",
"fileError",
")",
"+",
"')'",
";",
"break",
";",
"}",
"return",
"msg",
";",
"}"
]
| Private API helper functions and variables hidden within this function scope | [
"Private",
"API",
"helper",
"functions",
"and",
"variables",
"hidden",
"within",
"this",
"function",
"scope"
]
| e57ebece54ee68211d43802a8e0feeef098d3e36 | https://github.com/ofidj/fidj/blob/e57ebece54ee68211d43802a8e0feeef098d3e36/.todo/miapp.tools.storage.js#L1356-L1404 |
41,783 | cafjs/caf_components | lib/templateUtils.js | function(template, delta) {
assert.ok(Array.isArray(template), "'template' is not an array");
assert.ok(Array.isArray(delta), "'delta' is not an array");
/*
* This merge step is inefficient O(n*m) but we are assuming small arrays
* and 'delta' typically smaller than 'template'.
*
* A 'delta' operation could merge with another component in 'template'
* with the same name, it could delete an existing entry if the 'module'
* key is null, or it could insert a new entry in the array.
* The insertion point of a new entry is just after the previous
* operation target. If the first operation in 'delta' is a new entry it
* becomes the first element.
*
* Note that 'delta' is not sorted and it could contain duplicates. This
* allow us to change the order in the original list. For example,
* if template is [A|B|...], and we want to swap B and A, we can add these
* three operations in delta:
*
* Remove A (assign null to A's module)
* Touch B (just have an entry with B's name that won't change B)
* Add A with the original A's values (inserted after B)
*
*/
var findEntry = function(result, name, lastOp) {
return result.some(function(x, i) {
if (x.name === name) {
lastOp.index = i;
return true;
} else {
return false;
}
});
};
var deleteEntry = function(result, name, lastOp) {
if (findEntry(result, name, lastOp)) {
result.splice(lastOp.index, 1);
lastOp.index = lastOp.index -1;
}
};
var insertEntry = function(result, entry, lastOp) {
// splice prepends, and we want after
lastOp.index = lastOp.index + 1;
result.splice(lastOp.index, 0, entry);
};
var result = myUtils.deepClone(template);
var lastOp = {index: -1};
delta.forEach(function(x) {
if (x.module === null) {
deleteEntry(result, x.name, lastOp);
} else if (findEntry(result, x.name, lastOp)) {
result[lastOp.index] = mergeObj(result[lastOp.index], x, false);
} else {
insertEntry(result, myUtils.deepClone(x), lastOp);
}
});
return result;
} | javascript | function(template, delta) {
assert.ok(Array.isArray(template), "'template' is not an array");
assert.ok(Array.isArray(delta), "'delta' is not an array");
/*
* This merge step is inefficient O(n*m) but we are assuming small arrays
* and 'delta' typically smaller than 'template'.
*
* A 'delta' operation could merge with another component in 'template'
* with the same name, it could delete an existing entry if the 'module'
* key is null, or it could insert a new entry in the array.
* The insertion point of a new entry is just after the previous
* operation target. If the first operation in 'delta' is a new entry it
* becomes the first element.
*
* Note that 'delta' is not sorted and it could contain duplicates. This
* allow us to change the order in the original list. For example,
* if template is [A|B|...], and we want to swap B and A, we can add these
* three operations in delta:
*
* Remove A (assign null to A's module)
* Touch B (just have an entry with B's name that won't change B)
* Add A with the original A's values (inserted after B)
*
*/
var findEntry = function(result, name, lastOp) {
return result.some(function(x, i) {
if (x.name === name) {
lastOp.index = i;
return true;
} else {
return false;
}
});
};
var deleteEntry = function(result, name, lastOp) {
if (findEntry(result, name, lastOp)) {
result.splice(lastOp.index, 1);
lastOp.index = lastOp.index -1;
}
};
var insertEntry = function(result, entry, lastOp) {
// splice prepends, and we want after
lastOp.index = lastOp.index + 1;
result.splice(lastOp.index, 0, entry);
};
var result = myUtils.deepClone(template);
var lastOp = {index: -1};
delta.forEach(function(x) {
if (x.module === null) {
deleteEntry(result, x.name, lastOp);
} else if (findEntry(result, x.name, lastOp)) {
result[lastOp.index] = mergeObj(result[lastOp.index], x, false);
} else {
insertEntry(result, myUtils.deepClone(x), lastOp);
}
});
return result;
} | [
"function",
"(",
"template",
",",
"delta",
")",
"{",
"assert",
".",
"ok",
"(",
"Array",
".",
"isArray",
"(",
"template",
")",
",",
"\"'template' is not an array\"",
")",
";",
"assert",
".",
"ok",
"(",
"Array",
".",
"isArray",
"(",
"delta",
")",
",",
"\"'delta' is not an array\"",
")",
";",
"/*\n * This merge step is inefficient O(n*m) but we are assuming small arrays\n * and 'delta' typically smaller than 'template'.\n *\n * A 'delta' operation could merge with another component in 'template'\n * with the same name, it could delete an existing entry if the 'module'\n * key is null, or it could insert a new entry in the array.\n * The insertion point of a new entry is just after the previous\n * operation target. If the first operation in 'delta' is a new entry it\n * becomes the first element.\n *\n * Note that 'delta' is not sorted and it could contain duplicates. This\n * allow us to change the order in the original list. For example,\n * if template is [A|B|...], and we want to swap B and A, we can add these\n * three operations in delta:\n *\n * Remove A (assign null to A's module)\n * Touch B (just have an entry with B's name that won't change B)\n * Add A with the original A's values (inserted after B)\n *\n */",
"var",
"findEntry",
"=",
"function",
"(",
"result",
",",
"name",
",",
"lastOp",
")",
"{",
"return",
"result",
".",
"some",
"(",
"function",
"(",
"x",
",",
"i",
")",
"{",
"if",
"(",
"x",
".",
"name",
"===",
"name",
")",
"{",
"lastOp",
".",
"index",
"=",
"i",
";",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
")",
";",
"}",
";",
"var",
"deleteEntry",
"=",
"function",
"(",
"result",
",",
"name",
",",
"lastOp",
")",
"{",
"if",
"(",
"findEntry",
"(",
"result",
",",
"name",
",",
"lastOp",
")",
")",
"{",
"result",
".",
"splice",
"(",
"lastOp",
".",
"index",
",",
"1",
")",
";",
"lastOp",
".",
"index",
"=",
"lastOp",
".",
"index",
"-",
"1",
";",
"}",
"}",
";",
"var",
"insertEntry",
"=",
"function",
"(",
"result",
",",
"entry",
",",
"lastOp",
")",
"{",
"// splice prepends, and we want after",
"lastOp",
".",
"index",
"=",
"lastOp",
".",
"index",
"+",
"1",
";",
"result",
".",
"splice",
"(",
"lastOp",
".",
"index",
",",
"0",
",",
"entry",
")",
";",
"}",
";",
"var",
"result",
"=",
"myUtils",
".",
"deepClone",
"(",
"template",
")",
";",
"var",
"lastOp",
"=",
"{",
"index",
":",
"-",
"1",
"}",
";",
"delta",
".",
"forEach",
"(",
"function",
"(",
"x",
")",
"{",
"if",
"(",
"x",
".",
"module",
"===",
"null",
")",
"{",
"deleteEntry",
"(",
"result",
",",
"x",
".",
"name",
",",
"lastOp",
")",
";",
"}",
"else",
"if",
"(",
"findEntry",
"(",
"result",
",",
"x",
".",
"name",
",",
"lastOp",
")",
")",
"{",
"result",
"[",
"lastOp",
".",
"index",
"]",
"=",
"mergeObj",
"(",
"result",
"[",
"lastOp",
".",
"index",
"]",
",",
"x",
",",
"false",
")",
";",
"}",
"else",
"{",
"insertEntry",
"(",
"result",
",",
"myUtils",
".",
"deepClone",
"(",
"x",
")",
",",
"lastOp",
")",
";",
"}",
"}",
")",
";",
"return",
"result",
";",
"}"
]
| Merge two component arrays of matching components.
@param {Array.<specType>} template
@param {Array.<specDeltaType>} delta
@return {Array.<specType>} result | [
"Merge",
"two",
"component",
"arrays",
"of",
"matching",
"components",
"."
]
| dca28007d6618066df8ed058362f0d4a0745c2cf | https://github.com/cafjs/caf_components/blob/dca28007d6618066df8ed058362f0d4a0745c2cf/lib/templateUtils.js#L63-L126 |
|
41,784 | cafjs/caf_components | lib/templateUtils.js | function(template, delta) {
assert.equal(typeof(template), 'object', "'template' is not an object");
assert.equal(typeof(delta), 'object', "'delta' is not an object");
var result = myUtils.deepClone(template);
Object.keys(delta).forEach(function(x) {
result[x] = myUtils.deepClone(delta[x]);
});
return result;
} | javascript | function(template, delta) {
assert.equal(typeof(template), 'object', "'template' is not an object");
assert.equal(typeof(delta), 'object', "'delta' is not an object");
var result = myUtils.deepClone(template);
Object.keys(delta).forEach(function(x) {
result[x] = myUtils.deepClone(delta[x]);
});
return result;
} | [
"function",
"(",
"template",
",",
"delta",
")",
"{",
"assert",
".",
"equal",
"(",
"typeof",
"(",
"template",
")",
",",
"'object'",
",",
"\"'template' is not an object\"",
")",
";",
"assert",
".",
"equal",
"(",
"typeof",
"(",
"delta",
")",
",",
"'object'",
",",
"\"'delta' is not an object\"",
")",
";",
"var",
"result",
"=",
"myUtils",
".",
"deepClone",
"(",
"template",
")",
";",
"Object",
".",
"keys",
"(",
"delta",
")",
".",
"forEach",
"(",
"function",
"(",
"x",
")",
"{",
"result",
"[",
"x",
"]",
"=",
"myUtils",
".",
"deepClone",
"(",
"delta",
"[",
"x",
"]",
")",
";",
"}",
")",
";",
"return",
"result",
";",
"}"
]
| Merge two environments of matching components.
@param {Object} template
@param {Object} delta
@return {Object} result | [
"Merge",
"two",
"environments",
"of",
"matching",
"components",
"."
]
| dca28007d6618066df8ed058362f0d4a0745c2cf | https://github.com/cafjs/caf_components/blob/dca28007d6618066df8ed058362f0d4a0745c2cf/lib/templateUtils.js#L135-L144 |
|
41,785 | cafjs/caf_components | lib/templateUtils.js | function(template, delta, overrideName) {
if (template.name !== delta.name) {
if (!overrideName) {
var err = new Error('mergeObj: description names do not match');
err['template'] = template;
err['delta'] = delta;
throw err;
}
}
/** @type specType*/
var result = {
name: delta.name || template.name,
module: (delta.module ? delta.module : template.module),
description: (delta.description ? delta.description :
template.description),
env: mergeEnv(template.env, delta.env || {})
};
if (template.components || delta.components) {
result.components = mergeComponents(template.components || [],
delta.components || []);
}
return result;
} | javascript | function(template, delta, overrideName) {
if (template.name !== delta.name) {
if (!overrideName) {
var err = new Error('mergeObj: description names do not match');
err['template'] = template;
err['delta'] = delta;
throw err;
}
}
/** @type specType*/
var result = {
name: delta.name || template.name,
module: (delta.module ? delta.module : template.module),
description: (delta.description ? delta.description :
template.description),
env: mergeEnv(template.env, delta.env || {})
};
if (template.components || delta.components) {
result.components = mergeComponents(template.components || [],
delta.components || []);
}
return result;
} | [
"function",
"(",
"template",
",",
"delta",
",",
"overrideName",
")",
"{",
"if",
"(",
"template",
".",
"name",
"!==",
"delta",
".",
"name",
")",
"{",
"if",
"(",
"!",
"overrideName",
")",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'mergeObj: description names do not match'",
")",
";",
"err",
"[",
"'template'",
"]",
"=",
"template",
";",
"err",
"[",
"'delta'",
"]",
"=",
"delta",
";",
"throw",
"err",
";",
"}",
"}",
"/** @type specType*/",
"var",
"result",
"=",
"{",
"name",
":",
"delta",
".",
"name",
"||",
"template",
".",
"name",
",",
"module",
":",
"(",
"delta",
".",
"module",
"?",
"delta",
".",
"module",
":",
"template",
".",
"module",
")",
",",
"description",
":",
"(",
"delta",
".",
"description",
"?",
"delta",
".",
"description",
":",
"template",
".",
"description",
")",
",",
"env",
":",
"mergeEnv",
"(",
"template",
".",
"env",
",",
"delta",
".",
"env",
"||",
"{",
"}",
")",
"}",
";",
"if",
"(",
"template",
".",
"components",
"||",
"delta",
".",
"components",
")",
"{",
"result",
".",
"components",
"=",
"mergeComponents",
"(",
"template",
".",
"components",
"||",
"[",
"]",
",",
"delta",
".",
"components",
"||",
"[",
"]",
")",
";",
"}",
"return",
"result",
";",
"}"
]
| Merge two descriptions with the same name.
@param {specType} template
@param {specDeltaType} delta
@param {boolean} overrideName
@return {specType} result | [
"Merge",
"two",
"descriptions",
"with",
"the",
"same",
"name",
"."
]
| dca28007d6618066df8ed058362f0d4a0745c2cf | https://github.com/cafjs/caf_components/blob/dca28007d6618066df8ed058362f0d4a0745c2cf/lib/templateUtils.js#L156-L180 |
|
41,786 | cafjs/caf_components | lib/templateUtils.js | function(desc, f) {
if (typeof desc === 'object') {
f(desc.env);
if (Array.isArray(desc.components)) {
desc.components.forEach(function(x) { patchEnv(x, f);});
}
} else {
var err = new Error('patchEnv: not an object');
err['desc'] = desc;
throw err;
}
} | javascript | function(desc, f) {
if (typeof desc === 'object') {
f(desc.env);
if (Array.isArray(desc.components)) {
desc.components.forEach(function(x) { patchEnv(x, f);});
}
} else {
var err = new Error('patchEnv: not an object');
err['desc'] = desc;
throw err;
}
} | [
"function",
"(",
"desc",
",",
"f",
")",
"{",
"if",
"(",
"typeof",
"desc",
"===",
"'object'",
")",
"{",
"f",
"(",
"desc",
".",
"env",
")",
";",
"if",
"(",
"Array",
".",
"isArray",
"(",
"desc",
".",
"components",
")",
")",
"{",
"desc",
".",
"components",
".",
"forEach",
"(",
"function",
"(",
"x",
")",
"{",
"patchEnv",
"(",
"x",
",",
"f",
")",
";",
"}",
")",
";",
"}",
"}",
"else",
"{",
"var",
"err",
"=",
"new",
"Error",
"(",
"'patchEnv: not an object'",
")",
";",
"err",
"[",
"'desc'",
"]",
"=",
"desc",
";",
"throw",
"err",
";",
"}",
"}"
]
| Patches every environment in a description.
@param {specType} desc A description to patch.
@param {function(Object)} f A function to patch an environment. | [
"Patches",
"every",
"environment",
"in",
"a",
"description",
"."
]
| dca28007d6618066df8ed058362f0d4a0745c2cf | https://github.com/cafjs/caf_components/blob/dca28007d6618066df8ed058362f0d4a0745c2cf/lib/templateUtils.js#L215-L226 |
|
41,787 | cafjs/caf_components | lib/templateUtils.js | function(prefix, f) {
var retF = function(env) {
Object.keys(env)
.forEach(function(x) {
var val = env[x];
if ((typeof val === 'string') &&
(val.indexOf(prefix) === 0)) {
var propName = val.substring(prefix.length,
val.length);
env[x] = f(propName);
} else if (Array.isArray(val)) {
retF(val);
} else if (val && (typeof val === 'object')) {
retF(val);
}
});
};
return retF;
} | javascript | function(prefix, f) {
var retF = function(env) {
Object.keys(env)
.forEach(function(x) {
var val = env[x];
if ((typeof val === 'string') &&
(val.indexOf(prefix) === 0)) {
var propName = val.substring(prefix.length,
val.length);
env[x] = f(propName);
} else if (Array.isArray(val)) {
retF(val);
} else if (val && (typeof val === 'object')) {
retF(val);
}
});
};
return retF;
} | [
"function",
"(",
"prefix",
",",
"f",
")",
"{",
"var",
"retF",
"=",
"function",
"(",
"env",
")",
"{",
"Object",
".",
"keys",
"(",
"env",
")",
".",
"forEach",
"(",
"function",
"(",
"x",
")",
"{",
"var",
"val",
"=",
"env",
"[",
"x",
"]",
";",
"if",
"(",
"(",
"typeof",
"val",
"===",
"'string'",
")",
"&&",
"(",
"val",
".",
"indexOf",
"(",
"prefix",
")",
"===",
"0",
")",
")",
"{",
"var",
"propName",
"=",
"val",
".",
"substring",
"(",
"prefix",
".",
"length",
",",
"val",
".",
"length",
")",
";",
"env",
"[",
"x",
"]",
"=",
"f",
"(",
"propName",
")",
";",
"}",
"else",
"if",
"(",
"Array",
".",
"isArray",
"(",
"val",
")",
")",
"{",
"retF",
"(",
"val",
")",
";",
"}",
"else",
"if",
"(",
"val",
"&&",
"(",
"typeof",
"val",
"===",
"'object'",
")",
")",
"{",
"retF",
"(",
"val",
")",
";",
"}",
"}",
")",
";",
"}",
";",
"return",
"retF",
";",
"}"
]
| Returns a function that filters relevant values in an environment and
applies a transform to them.
@param {string} prefix A matching prefix for selected values.
@param {function(string): Object} f A function that transforms matching
values. | [
"Returns",
"a",
"function",
"that",
"filters",
"relevant",
"values",
"in",
"an",
"environment",
"and",
"applies",
"a",
"transform",
"to",
"them",
"."
]
| dca28007d6618066df8ed058362f0d4a0745c2cf | https://github.com/cafjs/caf_components/blob/dca28007d6618066df8ed058362f0d4a0745c2cf/lib/templateUtils.js#L237-L255 |
|
41,788 | repetere/periodicjs.core.mailer | lib/getTransport.js | getTransport | function getTransport(options = {}) {
return new Promise((resolve, reject) => {
try {
const defaultTransport = {
type: 'direct',
transportOptions: { debug: true }
};
const { transportObject = defaultTransport, } = options;
const nodemailerTransporter = nodemailer.createTransport(transportMap[transportObject.type](transportObject.transportoptions));
if (transportObject.type === 'stub') {
const originalSendmail = nodemailerTransporter.sendMail;
nodemailerTransporter.sendMail = (data, callback) => {
(function(maildata, mailcallback, fn) {
return fn.call(nodemailerTransporter, maildata, function(err, email_status) {
email_status.response = email_status.response.toString();
mailcallback(err, email_status);
});
})(data, callback, originalSendmail);
};
}
nodemailerTransporter.use('compile', htmlToText());
resolve(nodemailerTransporter);
} catch (e) {
reject(e);
}
});
} | javascript | function getTransport(options = {}) {
return new Promise((resolve, reject) => {
try {
const defaultTransport = {
type: 'direct',
transportOptions: { debug: true }
};
const { transportObject = defaultTransport, } = options;
const nodemailerTransporter = nodemailer.createTransport(transportMap[transportObject.type](transportObject.transportoptions));
if (transportObject.type === 'stub') {
const originalSendmail = nodemailerTransporter.sendMail;
nodemailerTransporter.sendMail = (data, callback) => {
(function(maildata, mailcallback, fn) {
return fn.call(nodemailerTransporter, maildata, function(err, email_status) {
email_status.response = email_status.response.toString();
mailcallback(err, email_status);
});
})(data, callback, originalSendmail);
};
}
nodemailerTransporter.use('compile', htmlToText());
resolve(nodemailerTransporter);
} catch (e) {
reject(e);
}
});
} | [
"function",
"getTransport",
"(",
"options",
"=",
"{",
"}",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"try",
"{",
"const",
"defaultTransport",
"=",
"{",
"type",
":",
"'direct'",
",",
"transportOptions",
":",
"{",
"debug",
":",
"true",
"}",
"}",
";",
"const",
"{",
"transportObject",
"=",
"defaultTransport",
",",
"}",
"=",
"options",
";",
"const",
"nodemailerTransporter",
"=",
"nodemailer",
".",
"createTransport",
"(",
"transportMap",
"[",
"transportObject",
".",
"type",
"]",
"(",
"transportObject",
".",
"transportoptions",
")",
")",
";",
"if",
"(",
"transportObject",
".",
"type",
"===",
"'stub'",
")",
"{",
"const",
"originalSendmail",
"=",
"nodemailerTransporter",
".",
"sendMail",
";",
"nodemailerTransporter",
".",
"sendMail",
"=",
"(",
"data",
",",
"callback",
")",
"=>",
"{",
"(",
"function",
"(",
"maildata",
",",
"mailcallback",
",",
"fn",
")",
"{",
"return",
"fn",
".",
"call",
"(",
"nodemailerTransporter",
",",
"maildata",
",",
"function",
"(",
"err",
",",
"email_status",
")",
"{",
"email_status",
".",
"response",
"=",
"email_status",
".",
"response",
".",
"toString",
"(",
")",
";",
"mailcallback",
"(",
"err",
",",
"email_status",
")",
";",
"}",
")",
";",
"}",
")",
"(",
"data",
",",
"callback",
",",
"originalSendmail",
")",
";",
"}",
";",
"}",
"nodemailerTransporter",
".",
"use",
"(",
"'compile'",
",",
"htmlToText",
"(",
")",
")",
";",
"resolve",
"(",
"nodemailerTransporter",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"reject",
"(",
"e",
")",
";",
"}",
"}",
")",
";",
"}"
]
| returns a node mailer transport based off of a json configuration
@param {any} [options={}]
@param {object} options.transportObject the json configuration for a node mailer transport
@param {string} options.transportObject.transportType [ses|direct|sendmail|smtp-pool|sendgrid|sendgridapi|mailgun|stub]
@param {object} options.transportObject.transportOptions options for a node mailer transport
@returns {promise} resolves a node mailer transport | [
"returns",
"a",
"node",
"mailer",
"transport",
"based",
"off",
"of",
"a",
"json",
"configuration"
]
| f544584cb1520015adac0326f8b02c38fbbd3417 | https://github.com/repetere/periodicjs.core.mailer/blob/f544584cb1520015adac0326f8b02c38fbbd3417/lib/getTransport.js#L38-L64 |
41,789 | typhonjs-node-escomplex/escomplex-plugin-syntax-babylon | src/PluginSyntaxBabylon.js | s_SAFE_COMPUTED_OPERANDS | function s_SAFE_COMPUTED_OPERANDS(node)
{
const operands = [];
if (typeof node.computed === 'boolean' && node.computed)
{
// The following will pick up a single literal computed value (string).
if (node.key.type === 'StringLiteral')
{
operands.push(TraitUtil.safeValue(node.key));
}
else // Fully evaluate AST node and children for computed operands.
{
operands.push(...ASTGenerator.parse(node.key).operands);
}
}
else // Parent is not computed and `parent.key` is an `Identifier` node.
{
operands.push(TraitUtil.safeName(node.key));
}
return operands;
} | javascript | function s_SAFE_COMPUTED_OPERANDS(node)
{
const operands = [];
if (typeof node.computed === 'boolean' && node.computed)
{
// The following will pick up a single literal computed value (string).
if (node.key.type === 'StringLiteral')
{
operands.push(TraitUtil.safeValue(node.key));
}
else // Fully evaluate AST node and children for computed operands.
{
operands.push(...ASTGenerator.parse(node.key).operands);
}
}
else // Parent is not computed and `parent.key` is an `Identifier` node.
{
operands.push(TraitUtil.safeName(node.key));
}
return operands;
} | [
"function",
"s_SAFE_COMPUTED_OPERANDS",
"(",
"node",
")",
"{",
"const",
"operands",
"=",
"[",
"]",
";",
"if",
"(",
"typeof",
"node",
".",
"computed",
"===",
"'boolean'",
"&&",
"node",
".",
"computed",
")",
"{",
"// The following will pick up a single literal computed value (string).",
"if",
"(",
"node",
".",
"key",
".",
"type",
"===",
"'StringLiteral'",
")",
"{",
"operands",
".",
"push",
"(",
"TraitUtil",
".",
"safeValue",
"(",
"node",
".",
"key",
")",
")",
";",
"}",
"else",
"// Fully evaluate AST node and children for computed operands.",
"{",
"operands",
".",
"push",
"(",
"...",
"ASTGenerator",
".",
"parse",
"(",
"node",
".",
"key",
")",
".",
"operands",
")",
";",
"}",
"}",
"else",
"// Parent is not computed and `parent.key` is an `Identifier` node.",
"{",
"operands",
".",
"push",
"(",
"TraitUtil",
".",
"safeName",
"(",
"node",
".",
"key",
")",
")",
";",
"}",
"return",
"operands",
";",
"}"
]
| Provides a utility method that determines the operands of a method for Babylon AST nodes. If the name is a computed
value and not a string literal then `ASTGenerator` is invoked to determine the computed operands.
@param {object} node - The current AST node.
@returns {Array<*>} | [
"Provides",
"a",
"utility",
"method",
"that",
"determines",
"the",
"operands",
"of",
"a",
"method",
"for",
"Babylon",
"AST",
"nodes",
".",
"If",
"the",
"name",
"is",
"a",
"computed",
"value",
"and",
"not",
"a",
"string",
"literal",
"then",
"ASTGenerator",
"is",
"invoked",
"to",
"determine",
"the",
"computed",
"operands",
"."
]
| d0ce535ccebb2f8afc4bc991db6611fcd7e01ce5 | https://github.com/typhonjs-node-escomplex/escomplex-plugin-syntax-babylon/blob/d0ce535ccebb2f8afc4bc991db6611fcd7e01ce5/src/PluginSyntaxBabylon.js#L269-L291 |
41,790 | Mammut-FE/nejm | src/base/element.js | function(_list){
var _result = 0;
_u._$forEach(
_list,function(_size){
if (!_size) return;
if (!_result){
_result = _size;
}else{
_result = Math.min(_result,_size);
}
}
);
return _result;
} | javascript | function(_list){
var _result = 0;
_u._$forEach(
_list,function(_size){
if (!_size) return;
if (!_result){
_result = _size;
}else{
_result = Math.min(_result,_size);
}
}
);
return _result;
} | [
"function",
"(",
"_list",
")",
"{",
"var",
"_result",
"=",
"0",
";",
"_u",
".",
"_$forEach",
"(",
"_list",
",",
"function",
"(",
"_size",
")",
"{",
"if",
"(",
"!",
"_size",
")",
"return",
";",
"if",
"(",
"!",
"_result",
")",
"{",
"_result",
"=",
"_size",
";",
"}",
"else",
"{",
"_result",
"=",
"Math",
".",
"min",
"(",
"_result",
",",
"_size",
")",
";",
"}",
"}",
")",
";",
"return",
"_result",
";",
"}"
]
| get min value but not zero | [
"get",
"min",
"value",
"but",
"not",
"zero"
]
| dfc09ac66a8d67620a7aea65e34d8a179976b3fb | https://github.com/Mammut-FE/nejm/blob/dfc09ac66a8d67620a7aea65e34d8a179976b3fb/src/base/element.js#L463-L476 |
|
41,791 | jldec/pub-resolve-opts | resolve-opts.js | injectPaths | function injectPaths(paths) {
u.each(paths, function(path) {
if (path.inject) {
// injected css and js sources are always rooted paths
var src = mkSrc(path);
if (/\.css$/i.test(src.path)) return opts.injectCss.push(src);
if (/\.js$|\.es6$|\.jsx$/i.test(src.path)) return opts.injectJs.push(src);
return opts.log('Don\'t know how to inject', path.path);
}
});
} | javascript | function injectPaths(paths) {
u.each(paths, function(path) {
if (path.inject) {
// injected css and js sources are always rooted paths
var src = mkSrc(path);
if (/\.css$/i.test(src.path)) return opts.injectCss.push(src);
if (/\.js$|\.es6$|\.jsx$/i.test(src.path)) return opts.injectJs.push(src);
return opts.log('Don\'t know how to inject', path.path);
}
});
} | [
"function",
"injectPaths",
"(",
"paths",
")",
"{",
"u",
".",
"each",
"(",
"paths",
",",
"function",
"(",
"path",
")",
"{",
"if",
"(",
"path",
".",
"inject",
")",
"{",
"// injected css and js sources are always rooted paths",
"var",
"src",
"=",
"mkSrc",
"(",
"path",
")",
";",
"if",
"(",
"/",
"\\.css$",
"/",
"i",
".",
"test",
"(",
"src",
".",
"path",
")",
")",
"return",
"opts",
".",
"injectCss",
".",
"push",
"(",
"src",
")",
";",
"if",
"(",
"/",
"\\.js$|\\.es6$|\\.jsx$",
"/",
"i",
".",
"test",
"(",
"src",
".",
"path",
")",
")",
"return",
"opts",
".",
"injectJs",
".",
"push",
"(",
"src",
")",
";",
"return",
"opts",
".",
"log",
"(",
"'Don\\'t know how to inject'",
",",
"path",
".",
"path",
")",
";",
"}",
"}",
")",
";",
"}"
]
| add injectable staticPaths to opts.injectCss or opts.injectJs | [
"add",
"injectable",
"staticPaths",
"to",
"opts",
".",
"injectCss",
"or",
"opts",
".",
"injectJs"
]
| 432dce8a638e1a909256179957a4ec25ac9542b7 | https://github.com/jldec/pub-resolve-opts/blob/432dce8a638e1a909256179957a4ec25ac9542b7/resolve-opts.js#L214-L224 |
41,792 | jldec/pub-resolve-opts | resolve-opts.js | watchOpts | function watchOpts(src) {
if ((src._pkg && !opts.watchPkgs) || ('watch' in src && !src.watch)) return false;
return (typeof src.watch === 'object') ? src.watch : {};
} | javascript | function watchOpts(src) {
if ((src._pkg && !opts.watchPkgs) || ('watch' in src && !src.watch)) return false;
return (typeof src.watch === 'object') ? src.watch : {};
} | [
"function",
"watchOpts",
"(",
"src",
")",
"{",
"if",
"(",
"(",
"src",
".",
"_pkg",
"&&",
"!",
"opts",
".",
"watchPkgs",
")",
"||",
"(",
"'watch'",
"in",
"src",
"&&",
"!",
"src",
".",
"watch",
")",
")",
"return",
"false",
";",
"return",
"(",
"typeof",
"src",
".",
"watch",
"===",
"'object'",
")",
"?",
"src",
".",
"watch",
":",
"{",
"}",
";",
"}"
]
| don't watch inside packages unless opts.watchPkgs don't watch if src.watch = falsy | [
"don",
"t",
"watch",
"inside",
"packages",
"unless",
"opts",
".",
"watchPkgs",
"don",
"t",
"watch",
"if",
"src",
".",
"watch",
"=",
"falsy"
]
| 432dce8a638e1a909256179957a4ec25ac9542b7 | https://github.com/jldec/pub-resolve-opts/blob/432dce8a638e1a909256179957a4ec25ac9542b7/resolve-opts.js#L334-L337 |
41,793 | jldec/pub-resolve-opts | resolve-opts.js | normalizeOptsKey | function normalizeOptsKey(aval, basedir, pkg) {
aval = aval || [];
if (!u.isArray(aval)) {
aval = [ aval ];
}
return u.map(u.compact(aval), function(val) {
return normalize(val, basedir, pkg);
});
} | javascript | function normalizeOptsKey(aval, basedir, pkg) {
aval = aval || [];
if (!u.isArray(aval)) {
aval = [ aval ];
}
return u.map(u.compact(aval), function(val) {
return normalize(val, basedir, pkg);
});
} | [
"function",
"normalizeOptsKey",
"(",
"aval",
",",
"basedir",
",",
"pkg",
")",
"{",
"aval",
"=",
"aval",
"||",
"[",
"]",
";",
"if",
"(",
"!",
"u",
".",
"isArray",
"(",
"aval",
")",
")",
"{",
"aval",
"=",
"[",
"aval",
"]",
";",
"}",
"return",
"u",
".",
"map",
"(",
"u",
".",
"compact",
"(",
"aval",
")",
",",
"function",
"(",
"val",
")",
"{",
"return",
"normalize",
"(",
"val",
",",
"basedir",
",",
"pkg",
")",
";",
"}",
")",
";",
"}"
]
| normalize a single opts key | [
"normalize",
"a",
"single",
"opts",
"key"
]
| 432dce8a638e1a909256179957a4ec25ac9542b7 | https://github.com/jldec/pub-resolve-opts/blob/432dce8a638e1a909256179957a4ec25ac9542b7/resolve-opts.js#L362-L374 |
41,794 | jldec/pub-resolve-opts | resolve-opts.js | normalize | function normalize(val, basedir, pkg) {
if (typeof val === 'string') {
val = { path: val };
}
var originalPath = val.path;
// npm3 treatment of sub-package paths starting with ./node_modules/
var subPkgName = val.path.replace(/^\.\/node_modules\/([^/]+).*/,'$1');
if (subPkgName != originalPath) {
var subPkg = resolvePkg({ path:subPkgName }, basedir, true);
val.path = subPkg.dir + val.path.slice(15 + subPkgName.length);
}
// join with basedir if relative directory path
else if (/^\.$|^\.\.$|^\.\/|^\.\.\//.test(val.path)) {
val.path = fspath.join(basedir || opts.basedir, val.path);
}
// for brevity on console output
val.inspect = function() {
return (originalPath) +
(pkg ? ' in ' + pkg : '') +
(val.cache ? ' (cached)' : '');
};
if (pkg) {
val._pkg = pkg;
}
return val;
} | javascript | function normalize(val, basedir, pkg) {
if (typeof val === 'string') {
val = { path: val };
}
var originalPath = val.path;
// npm3 treatment of sub-package paths starting with ./node_modules/
var subPkgName = val.path.replace(/^\.\/node_modules\/([^/]+).*/,'$1');
if (subPkgName != originalPath) {
var subPkg = resolvePkg({ path:subPkgName }, basedir, true);
val.path = subPkg.dir + val.path.slice(15 + subPkgName.length);
}
// join with basedir if relative directory path
else if (/^\.$|^\.\.$|^\.\/|^\.\.\//.test(val.path)) {
val.path = fspath.join(basedir || opts.basedir, val.path);
}
// for brevity on console output
val.inspect = function() {
return (originalPath) +
(pkg ? ' in ' + pkg : '') +
(val.cache ? ' (cached)' : '');
};
if (pkg) {
val._pkg = pkg;
}
return val;
} | [
"function",
"normalize",
"(",
"val",
",",
"basedir",
",",
"pkg",
")",
"{",
"if",
"(",
"typeof",
"val",
"===",
"'string'",
")",
"{",
"val",
"=",
"{",
"path",
":",
"val",
"}",
";",
"}",
"var",
"originalPath",
"=",
"val",
".",
"path",
";",
"// npm3 treatment of sub-package paths starting with ./node_modules/",
"var",
"subPkgName",
"=",
"val",
".",
"path",
".",
"replace",
"(",
"/",
"^\\.\\/node_modules\\/([^/]+).*",
"/",
",",
"'$1'",
")",
";",
"if",
"(",
"subPkgName",
"!=",
"originalPath",
")",
"{",
"var",
"subPkg",
"=",
"resolvePkg",
"(",
"{",
"path",
":",
"subPkgName",
"}",
",",
"basedir",
",",
"true",
")",
";",
"val",
".",
"path",
"=",
"subPkg",
".",
"dir",
"+",
"val",
".",
"path",
".",
"slice",
"(",
"15",
"+",
"subPkgName",
".",
"length",
")",
";",
"}",
"// join with basedir if relative directory path",
"else",
"if",
"(",
"/",
"^\\.$|^\\.\\.$|^\\.\\/|^\\.\\.\\/",
"/",
".",
"test",
"(",
"val",
".",
"path",
")",
")",
"{",
"val",
".",
"path",
"=",
"fspath",
".",
"join",
"(",
"basedir",
"||",
"opts",
".",
"basedir",
",",
"val",
".",
"path",
")",
";",
"}",
"// for brevity on console output",
"val",
".",
"inspect",
"=",
"function",
"(",
")",
"{",
"return",
"(",
"originalPath",
")",
"+",
"(",
"pkg",
"?",
"' in '",
"+",
"pkg",
":",
"''",
")",
"+",
"(",
"val",
".",
"cache",
"?",
"' (cached)'",
":",
"''",
")",
";",
"}",
";",
"if",
"(",
"pkg",
")",
"{",
"val",
".",
"_pkg",
"=",
"pkg",
";",
"}",
"return",
"val",
";",
"}"
]
| normalize a single opts key value | [
"normalize",
"a",
"single",
"opts",
"key",
"value"
]
| 432dce8a638e1a909256179957a4ec25ac9542b7 | https://github.com/jldec/pub-resolve-opts/blob/432dce8a638e1a909256179957a4ec25ac9542b7/resolve-opts.js#L377-L408 |
41,795 | vesln/hydro | lib/timeout-error.js | TimeoutError | function TimeoutError(message) {
this.message = message;
this.timeout = true;
Error.captureStackTrace(this, arguments.callee);
} | javascript | function TimeoutError(message) {
this.message = message;
this.timeout = true;
Error.captureStackTrace(this, arguments.callee);
} | [
"function",
"TimeoutError",
"(",
"message",
")",
"{",
"this",
".",
"message",
"=",
"message",
";",
"this",
".",
"timeout",
"=",
"true",
";",
"Error",
".",
"captureStackTrace",
"(",
"this",
",",
"arguments",
".",
"callee",
")",
";",
"}"
]
| Timeout Error.
@param {String} message
@constructor | [
"Timeout",
"Error",
"."
]
| 3f4d2e4926f913976187376e82f1496514c39890 | https://github.com/vesln/hydro/blob/3f4d2e4926f913976187376e82f1496514c39890/lib/timeout-error.js#L8-L13 |
41,796 | arokor/pararr.js | lib/paworker.js | onFunction | function onFunction(data, op, iterStr, context) {
var iter,
data;
// Check task
if(!op || !data || !iterStr || !context) {
throw Error('Worker received invalid task');
}
// parse the serialized function
// eval() may be evil but here we don't have much choice
eval('var iter = ' + iterStr);
switch(op) {
case 'map':
data = data.map(iter);
break;
case 'filter':
data = data.filter(iter);
break;
default:
data = null;
break;
}
process.send({
result: data,
context: context
});
} | javascript | function onFunction(data, op, iterStr, context) {
var iter,
data;
// Check task
if(!op || !data || !iterStr || !context) {
throw Error('Worker received invalid task');
}
// parse the serialized function
// eval() may be evil but here we don't have much choice
eval('var iter = ' + iterStr);
switch(op) {
case 'map':
data = data.map(iter);
break;
case 'filter':
data = data.filter(iter);
break;
default:
data = null;
break;
}
process.send({
result: data,
context: context
});
} | [
"function",
"onFunction",
"(",
"data",
",",
"op",
",",
"iterStr",
",",
"context",
")",
"{",
"var",
"iter",
",",
"data",
";",
"// Check task",
"if",
"(",
"!",
"op",
"||",
"!",
"data",
"||",
"!",
"iterStr",
"||",
"!",
"context",
")",
"{",
"throw",
"Error",
"(",
"'Worker received invalid task'",
")",
";",
"}",
"// parse the serialized function",
"// eval() may be evil but here we don't have much choice",
"eval",
"(",
"'var iter = '",
"+",
"iterStr",
")",
";",
"switch",
"(",
"op",
")",
"{",
"case",
"'map'",
":",
"data",
"=",
"data",
".",
"map",
"(",
"iter",
")",
";",
"break",
";",
"case",
"'filter'",
":",
"data",
"=",
"data",
".",
"filter",
"(",
"iter",
")",
";",
"break",
";",
"default",
":",
"data",
"=",
"null",
";",
"break",
";",
"}",
"process",
".",
"send",
"(",
"{",
"result",
":",
"data",
",",
"context",
":",
"context",
"}",
")",
";",
"}"
]
| Handle functional requests | [
"Handle",
"functional",
"requests"
]
| 215ddc452e24fd239b42de3997738510d1888135 | https://github.com/arokor/pararr.js/blob/215ddc452e24fd239b42de3997738510d1888135/lib/paworker.js#L2-L31 |
41,797 | arokor/pararr.js | lib/paworker.js | onExec | function onExec(funcStr, parStr, context) {
var func,
par,
data,
err = null;
try {
// Check task
if(!funcStr || !context) {
throw Error('Worker received invalid task');
}
par = parStr ? JSON.parse(parStr) : null;
// parse the serialized function
// eval() may be evil but here we don't have much choice
eval('var func = ' + funcStr);
data = func(par);
// console.log(' - '+data);
} catch(e) {
data = null;
err = e;
}
process.send({
result: data,
err: err,
context: context
});
} | javascript | function onExec(funcStr, parStr, context) {
var func,
par,
data,
err = null;
try {
// Check task
if(!funcStr || !context) {
throw Error('Worker received invalid task');
}
par = parStr ? JSON.parse(parStr) : null;
// parse the serialized function
// eval() may be evil but here we don't have much choice
eval('var func = ' + funcStr);
data = func(par);
// console.log(' - '+data);
} catch(e) {
data = null;
err = e;
}
process.send({
result: data,
err: err,
context: context
});
} | [
"function",
"onExec",
"(",
"funcStr",
",",
"parStr",
",",
"context",
")",
"{",
"var",
"func",
",",
"par",
",",
"data",
",",
"err",
"=",
"null",
";",
"try",
"{",
"// Check task",
"if",
"(",
"!",
"funcStr",
"||",
"!",
"context",
")",
"{",
"throw",
"Error",
"(",
"'Worker received invalid task'",
")",
";",
"}",
"par",
"=",
"parStr",
"?",
"JSON",
".",
"parse",
"(",
"parStr",
")",
":",
"null",
";",
"// parse the serialized function",
"// eval() may be evil but here we don't have much choice",
"eval",
"(",
"'var func = '",
"+",
"funcStr",
")",
";",
"data",
"=",
"func",
"(",
"par",
")",
";",
"//\t\tconsole.log(' - '+data);",
"}",
"catch",
"(",
"e",
")",
"{",
"data",
"=",
"null",
";",
"err",
"=",
"e",
";",
"}",
"process",
".",
"send",
"(",
"{",
"result",
":",
"data",
",",
"err",
":",
"err",
",",
"context",
":",
"context",
"}",
")",
";",
"}"
]
| Handle exec requests | [
"Handle",
"exec",
"requests"
]
| 215ddc452e24fd239b42de3997738510d1888135 | https://github.com/arokor/pararr.js/blob/215ddc452e24fd239b42de3997738510d1888135/lib/paworker.js#L34-L62 |
41,798 | veo-labs/openveo-api | lib/controllers/ContentController.js | getUserGroups | function getUserGroups(user) {
var groups = {};
if (user && user.permissions) {
user.permissions.forEach(function(permission) {
var reg = new RegExp('^(get|update|delete)-group-(.+)$');
var permissionChunks = reg.exec(permission);
if (permissionChunks) {
var operation = permissionChunks[1];
var groupId = permissionChunks[2];
if (!groups[groupId])
groups[groupId] = [];
groups[groupId].push(operation);
}
});
}
return groups;
} | javascript | function getUserGroups(user) {
var groups = {};
if (user && user.permissions) {
user.permissions.forEach(function(permission) {
var reg = new RegExp('^(get|update|delete)-group-(.+)$');
var permissionChunks = reg.exec(permission);
if (permissionChunks) {
var operation = permissionChunks[1];
var groupId = permissionChunks[2];
if (!groups[groupId])
groups[groupId] = [];
groups[groupId].push(operation);
}
});
}
return groups;
} | [
"function",
"getUserGroups",
"(",
"user",
")",
"{",
"var",
"groups",
"=",
"{",
"}",
";",
"if",
"(",
"user",
"&&",
"user",
".",
"permissions",
")",
"{",
"user",
".",
"permissions",
".",
"forEach",
"(",
"function",
"(",
"permission",
")",
"{",
"var",
"reg",
"=",
"new",
"RegExp",
"(",
"'^(get|update|delete)-group-(.+)$'",
")",
";",
"var",
"permissionChunks",
"=",
"reg",
".",
"exec",
"(",
"permission",
")",
";",
"if",
"(",
"permissionChunks",
")",
"{",
"var",
"operation",
"=",
"permissionChunks",
"[",
"1",
"]",
";",
"var",
"groupId",
"=",
"permissionChunks",
"[",
"2",
"]",
";",
"if",
"(",
"!",
"groups",
"[",
"groupId",
"]",
")",
"groups",
"[",
"groupId",
"]",
"=",
"[",
"]",
";",
"groups",
"[",
"groupId",
"]",
".",
"push",
"(",
"operation",
")",
";",
"}",
"}",
")",
";",
"}",
"return",
"groups",
";",
"}"
]
| Gets user permissions by groups.
@example
// Example of user permissions
['get-group-Jekrn20Rl', 'update-group-Jekrn20Rl', 'delete-group-YldO3Jie3']
// Example of returned groups
{
'Jekrn20Rl': ['get', 'update'], // User only has get / update permissions on group 'Jekrn20Rl'
'YldO3Jie3': ['delete'], // User only has delete permission on group 'YldO3Jie3'
...
}
@method getUserGroups
@private
@param {Object} user The user to extract groups from
@return {Object} Groups organized by ids | [
"Gets",
"user",
"permissions",
"by",
"groups",
"."
]
| 493a811e9a5ba4d3e14910facaa7452caba1ab38 | https://github.com/veo-labs/openveo-api/blob/493a811e9a5ba4d3e14910facaa7452caba1ab38/lib/controllers/ContentController.js#L80-L100 |
41,799 | veo-labs/openveo-api | lib/controllers/ContentController.js | getUserAuthorizedGroups | function getUserAuthorizedGroups(user, operation) {
var userGroups = getUserGroups(user);
var groups = [];
for (var groupId in userGroups) {
if (userGroups[groupId].indexOf(operation) >= 0)
groups.push(groupId);
}
return groups;
} | javascript | function getUserAuthorizedGroups(user, operation) {
var userGroups = getUserGroups(user);
var groups = [];
for (var groupId in userGroups) {
if (userGroups[groupId].indexOf(operation) >= 0)
groups.push(groupId);
}
return groups;
} | [
"function",
"getUserAuthorizedGroups",
"(",
"user",
",",
"operation",
")",
"{",
"var",
"userGroups",
"=",
"getUserGroups",
"(",
"user",
")",
";",
"var",
"groups",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"groupId",
"in",
"userGroups",
")",
"{",
"if",
"(",
"userGroups",
"[",
"groupId",
"]",
".",
"indexOf",
"(",
"operation",
")",
">=",
"0",
")",
"groups",
".",
"push",
"(",
"groupId",
")",
";",
"}",
"return",
"groups",
";",
"}"
]
| Gets the list of groups of a user, with authorization on a certain operation.
All user groups with authorization on the operation are returned.
@method getUserAuthorizedGroups
@private
@param {Object} user The user
@param {String} operation The operation (get, update or delete)
@return {Array} The list of user groups which have authorization on the given operation | [
"Gets",
"the",
"list",
"of",
"groups",
"of",
"a",
"user",
"with",
"authorization",
"on",
"a",
"certain",
"operation",
"."
]
| 493a811e9a5ba4d3e14910facaa7452caba1ab38 | https://github.com/veo-labs/openveo-api/blob/493a811e9a5ba4d3e14910facaa7452caba1ab38/lib/controllers/ContentController.js#L113-L123 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.