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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
15,500
|
bbc/waveform-data.js
|
lib/core.js
|
setSegment
|
function setSegment(start, end, identifier) {
if (identifier === undefined || identifier === null || identifier.length === 0) {
identifier = "default";
}
this.segments[identifier] = new WaveformDataSegment(this, start, end);
return this.segments[identifier];
}
|
javascript
|
function setSegment(start, end, identifier) {
if (identifier === undefined || identifier === null || identifier.length === 0) {
identifier = "default";
}
this.segments[identifier] = new WaveformDataSegment(this, start, end);
return this.segments[identifier];
}
|
[
"function",
"setSegment",
"(",
"start",
",",
"end",
",",
"identifier",
")",
"{",
"if",
"(",
"identifier",
"===",
"undefined",
"||",
"identifier",
"===",
"null",
"||",
"identifier",
".",
"length",
"===",
"0",
")",
"{",
"identifier",
"=",
"\"default\"",
";",
"}",
"this",
".",
"segments",
"[",
"identifier",
"]",
"=",
"new",
"WaveformDataSegment",
"(",
"this",
",",
"start",
",",
"end",
")",
";",
"return",
"this",
".",
"segments",
"[",
"identifier",
"]",
";",
"}"
] |
Creates a new segment of data.
Pretty handy if you need to bookmark a duration and display it according
to the current offset.
```javascript
var waveform = WaveformData.create({ ... });
console.log(Object.keys(waveform.segments)); // -> []
waveform.set_segment(10, 120);
waveform.set_segment(30, 90, "speakerA");
console.log(Object.keys(waveform.segments)); // -> ['default', 'speakerA']
console.log(waveform.segments.default.min.length); // -> 110
console.log(waveform.segments.speakerA.min.length); // -> 60
```
@param {Integer} start Beginning of the segment (inclusive)
@param {Integer} end Ending of the segment (exclusive)
@param {String*} identifier Unique identifier. If nothing is specified,
*default* will be used as a value.
@return {WaveformDataSegment}
|
[
"Creates",
"a",
"new",
"segment",
"of",
"data",
".",
"Pretty",
"handy",
"if",
"you",
"need",
"to",
"bookmark",
"a",
"duration",
"and",
"display",
"it",
"according",
"to",
"the",
"current",
"offset",
"."
] |
64967ad58aac527642be193eee916698df521efa
|
https://github.com/bbc/waveform-data.js/blob/64967ad58aac527642be193eee916698df521efa/lib/core.js#L210-L218
|
15,501
|
bbc/waveform-data.js
|
lib/core.js
|
setPoint
|
function setPoint(timeStamp, identifier) {
if (identifier === undefined || identifier === null || identifier.length === 0) {
identifier = "default";
}
this.points[identifier] = new WaveformDataPoint(this, timeStamp);
return this.points[identifier];
}
|
javascript
|
function setPoint(timeStamp, identifier) {
if (identifier === undefined || identifier === null || identifier.length === 0) {
identifier = "default";
}
this.points[identifier] = new WaveformDataPoint(this, timeStamp);
return this.points[identifier];
}
|
[
"function",
"setPoint",
"(",
"timeStamp",
",",
"identifier",
")",
"{",
"if",
"(",
"identifier",
"===",
"undefined",
"||",
"identifier",
"===",
"null",
"||",
"identifier",
".",
"length",
"===",
"0",
")",
"{",
"identifier",
"=",
"\"default\"",
";",
"}",
"this",
".",
"points",
"[",
"identifier",
"]",
"=",
"new",
"WaveformDataPoint",
"(",
"this",
",",
"timeStamp",
")",
";",
"return",
"this",
".",
"points",
"[",
"identifier",
"]",
";",
"}"
] |
Creates a new point of data.
Pretty handy if you need to bookmark a specific point and display it
according to the current offset.
```javascript
var waveform = WaveformData.create({ ... });
console.log(Object.keys(waveform.points)); // -> []
waveform.set_point(10);
waveform.set_point(30, "speakerA");
console.log(Object.keys(waveform.points)); // -> ['default', 'speakerA']
```
@param {Integer} timeStamp the time to place the bookmark
@param {String*} identifier Unique identifier. If nothing is specified,
*default* will be used as a value.
@return {WaveformDataPoint}
|
[
"Creates",
"a",
"new",
"point",
"of",
"data",
".",
"Pretty",
"handy",
"if",
"you",
"need",
"to",
"bookmark",
"a",
"specific",
"point",
"and",
"display",
"it",
"according",
"to",
"the",
"current",
"offset",
"."
] |
64967ad58aac527642be193eee916698df521efa
|
https://github.com/bbc/waveform-data.js/blob/64967ad58aac527642be193eee916698df521efa/lib/core.js#L242-L250
|
15,502
|
bbc/waveform-data.js
|
lib/core.js
|
getOffsetValues
|
function getOffsetValues(start, length, correction) {
var adapter = this.adapter;
var values = [];
correction += (start * 2); // offset the positioning query
for (var i = 0; i < length; i++) {
values.push(adapter.at((i * 2) + correction));
}
return values;
}
|
javascript
|
function getOffsetValues(start, length, correction) {
var adapter = this.adapter;
var values = [];
correction += (start * 2); // offset the positioning query
for (var i = 0; i < length; i++) {
values.push(adapter.at((i * 2) + correction));
}
return values;
}
|
[
"function",
"getOffsetValues",
"(",
"start",
",",
"length",
",",
"correction",
")",
"{",
"var",
"adapter",
"=",
"this",
".",
"adapter",
";",
"var",
"values",
"=",
"[",
"]",
";",
"correction",
"+=",
"(",
"start",
"*",
"2",
")",
";",
"// offset the positioning query",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"values",
".",
"push",
"(",
"adapter",
".",
"at",
"(",
"(",
"i",
"*",
"2",
")",
"+",
"correction",
")",
")",
";",
"}",
"return",
"values",
";",
"}"
] |
Return the unpacked values for a particular offset.
@param {Integer} start
@param {Integer} length
@param {Integer} correction The step to skip for each iteration
(as the response body is [min, max, min, max...])
@return {Array.<Integer>}
|
[
"Return",
"the",
"unpacked",
"values",
"for",
"a",
"particular",
"offset",
"."
] |
64967ad58aac527642be193eee916698df521efa
|
https://github.com/bbc/waveform-data.js/blob/64967ad58aac527642be193eee916698df521efa/lib/core.js#L502-L513
|
15,503
|
bbc/waveform-data.js
|
lib/builders/webaudio.js
|
fromAudioObjectBuilder
|
function fromAudioObjectBuilder(audio_context, raw_response, options, callback) {
var audioContext = window.AudioContext || window.webkitAudioContext;
if (!(audio_context instanceof audioContext)) {
throw new TypeError("First argument should be an AudioContext instance");
}
var opts = getOptions(options, callback);
callback = opts.callback;
options = opts.options;
// The following function is a workaround for a Webkit bug where decodeAudioData
// invokes the errorCallback with null instead of a DOMException.
// See https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-decodeaudiodata
// and http://stackoverflow.com/q/10365335/103396
function errorCallback(error) {
if (!error) {
error = new DOMException("EncodingError");
}
callback(error);
}
return audio_context.decodeAudioData(
raw_response,
getAudioDecoder(options, callback),
errorCallback
);
}
|
javascript
|
function fromAudioObjectBuilder(audio_context, raw_response, options, callback) {
var audioContext = window.AudioContext || window.webkitAudioContext;
if (!(audio_context instanceof audioContext)) {
throw new TypeError("First argument should be an AudioContext instance");
}
var opts = getOptions(options, callback);
callback = opts.callback;
options = opts.options;
// The following function is a workaround for a Webkit bug where decodeAudioData
// invokes the errorCallback with null instead of a DOMException.
// See https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-decodeaudiodata
// and http://stackoverflow.com/q/10365335/103396
function errorCallback(error) {
if (!error) {
error = new DOMException("EncodingError");
}
callback(error);
}
return audio_context.decodeAudioData(
raw_response,
getAudioDecoder(options, callback),
errorCallback
);
}
|
[
"function",
"fromAudioObjectBuilder",
"(",
"audio_context",
",",
"raw_response",
",",
"options",
",",
"callback",
")",
"{",
"var",
"audioContext",
"=",
"window",
".",
"AudioContext",
"||",
"window",
".",
"webkitAudioContext",
";",
"if",
"(",
"!",
"(",
"audio_context",
"instanceof",
"audioContext",
")",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"\"First argument should be an AudioContext instance\"",
")",
";",
"}",
"var",
"opts",
"=",
"getOptions",
"(",
"options",
",",
"callback",
")",
";",
"callback",
"=",
"opts",
".",
"callback",
";",
"options",
"=",
"opts",
".",
"options",
";",
"// The following function is a workaround for a Webkit bug where decodeAudioData",
"// invokes the errorCallback with null instead of a DOMException.",
"// See https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-decodeaudiodata",
"// and http://stackoverflow.com/q/10365335/103396",
"function",
"errorCallback",
"(",
"error",
")",
"{",
"if",
"(",
"!",
"error",
")",
"{",
"error",
"=",
"new",
"DOMException",
"(",
"\"EncodingError\"",
")",
";",
"}",
"callback",
"(",
"error",
")",
";",
"}",
"return",
"audio_context",
".",
"decodeAudioData",
"(",
"raw_response",
",",
"getAudioDecoder",
"(",
"options",
",",
"callback",
")",
",",
"errorCallback",
")",
";",
"}"
] |
Creates a working WaveformData based on binary audio data.
This is still quite experimental and the result will mostly depend on the
level of browser support.
```javascript
const xhr = new XMLHttpRequest();
const audioContext = new AudioContext();
// URL of a CORS MP3/Ogg file
xhr.open('GET', 'https://example.com/audio/track.ogg');
xhr.responseType = 'arraybuffer';
xhr.addEventListener('load', function(progressEvent) {
WaveformData.builders.webaudio(audioContext, progressEvent.target.response,
function(err, waveform) {
if (err) {
console.error(err);
return;
}
console.log(waveform.duration);
});
});
xhr.send();
```
@todo use a Web Worker to offload processing of the binary data
@todo or use `SourceBuffer.appendBuffer` and `ProgressEvent` to stream the decoding
@todo abstract the number of channels, because it is assumed the audio file is stereo
@param {AudioContext|webkitAudioContext} audio_context
@param {ArrayBuffer} raw_response
@param {callback} what to do once the decoding is done
@constructor
|
[
"Creates",
"a",
"working",
"WaveformData",
"based",
"on",
"binary",
"audio",
"data",
"."
] |
64967ad58aac527642be193eee916698df521efa
|
https://github.com/bbc/waveform-data.js/blob/64967ad58aac527642be193eee916698df521efa/lib/builders/webaudio.js#L44-L73
|
15,504
|
dkfbasel/vuex-i18n
|
dist/vuex-i18n.es.js
|
ADD_LOCALE
|
function ADD_LOCALE(state, payload) {
// reduce the given translations to a single-depth tree
var translations = flattenTranslations(payload.translations);
if (state.translations.hasOwnProperty(payload.locale)) {
// get the existing translations
var existingTranslations = state.translations[payload.locale]; // merge the translations
state.translations[payload.locale] = Object.assign({}, existingTranslations, translations);
} else {
// just set the locale if it does not yet exist
state.translations[payload.locale] = translations;
} // make sure to notify vue of changes (this might break with new vue versions)
try {
if (state.translations.__ob__) {
state.translations.__ob__.dep.notify();
}
} catch (ex) {}
}
|
javascript
|
function ADD_LOCALE(state, payload) {
// reduce the given translations to a single-depth tree
var translations = flattenTranslations(payload.translations);
if (state.translations.hasOwnProperty(payload.locale)) {
// get the existing translations
var existingTranslations = state.translations[payload.locale]; // merge the translations
state.translations[payload.locale] = Object.assign({}, existingTranslations, translations);
} else {
// just set the locale if it does not yet exist
state.translations[payload.locale] = translations;
} // make sure to notify vue of changes (this might break with new vue versions)
try {
if (state.translations.__ob__) {
state.translations.__ob__.dep.notify();
}
} catch (ex) {}
}
|
[
"function",
"ADD_LOCALE",
"(",
"state",
",",
"payload",
")",
"{",
"// reduce the given translations to a single-depth tree",
"var",
"translations",
"=",
"flattenTranslations",
"(",
"payload",
".",
"translations",
")",
";",
"if",
"(",
"state",
".",
"translations",
".",
"hasOwnProperty",
"(",
"payload",
".",
"locale",
")",
")",
"{",
"// get the existing translations",
"var",
"existingTranslations",
"=",
"state",
".",
"translations",
"[",
"payload",
".",
"locale",
"]",
";",
"// merge the translations",
"state",
".",
"translations",
"[",
"payload",
".",
"locale",
"]",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"existingTranslations",
",",
"translations",
")",
";",
"}",
"else",
"{",
"// just set the locale if it does not yet exist",
"state",
".",
"translations",
"[",
"payload",
".",
"locale",
"]",
"=",
"translations",
";",
"}",
"// make sure to notify vue of changes (this might break with new vue versions)",
"try",
"{",
"if",
"(",
"state",
".",
"translations",
".",
"__ob__",
")",
"{",
"state",
".",
"translations",
".",
"__ob__",
".",
"dep",
".",
"notify",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"ex",
")",
"{",
"}",
"}"
] |
add a new locale
|
[
"add",
"a",
"new",
"locale"
] |
41b589e05546986f9e7768cd1ca4982b90ebde95
|
https://github.com/dkfbasel/vuex-i18n/blob/41b589e05546986f9e7768cd1ca4982b90ebde95/dist/vuex-i18n.es.js#L33-L53
|
15,505
|
dkfbasel/vuex-i18n
|
dist/vuex-i18n.es.js
|
REPLACE_LOCALE
|
function REPLACE_LOCALE(state, payload) {
// reduce the given translations to a single-depth tree
var translations = flattenTranslations(payload.translations); // replace the translations entirely
state.translations[payload.locale] = translations; // make sure to notify vue of changes (this might break with new vue versions)
try {
if (state.translations.__ob__) {
state.translations.__ob__.dep.notify();
}
} catch (ex) {}
}
|
javascript
|
function REPLACE_LOCALE(state, payload) {
// reduce the given translations to a single-depth tree
var translations = flattenTranslations(payload.translations); // replace the translations entirely
state.translations[payload.locale] = translations; // make sure to notify vue of changes (this might break with new vue versions)
try {
if (state.translations.__ob__) {
state.translations.__ob__.dep.notify();
}
} catch (ex) {}
}
|
[
"function",
"REPLACE_LOCALE",
"(",
"state",
",",
"payload",
")",
"{",
"// reduce the given translations to a single-depth tree",
"var",
"translations",
"=",
"flattenTranslations",
"(",
"payload",
".",
"translations",
")",
";",
"// replace the translations entirely",
"state",
".",
"translations",
"[",
"payload",
".",
"locale",
"]",
"=",
"translations",
";",
"// make sure to notify vue of changes (this might break with new vue versions)",
"try",
"{",
"if",
"(",
"state",
".",
"translations",
".",
"__ob__",
")",
"{",
"state",
".",
"translations",
".",
"__ob__",
".",
"dep",
".",
"notify",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"ex",
")",
"{",
"}",
"}"
] |
replace existing locale information with new translations
|
[
"replace",
"existing",
"locale",
"information",
"with",
"new",
"translations"
] |
41b589e05546986f9e7768cd1ca4982b90ebde95
|
https://github.com/dkfbasel/vuex-i18n/blob/41b589e05546986f9e7768cd1ca4982b90ebde95/dist/vuex-i18n.es.js#L55-L66
|
15,506
|
dkfbasel/vuex-i18n
|
dist/vuex-i18n.es.js
|
REMOVE_LOCALE
|
function REMOVE_LOCALE(state, payload) {
// check if the given locale is present in the state
if (state.translations.hasOwnProperty(payload.locale)) {
// check if the current locale is the given locale to remvoe
if (state.locale === payload.locale) {
// reset the current locale
state.locale = null;
} // create a copy of the translations object
var translationCopy = Object.assign({}, state.translations); // remove the given locale
delete translationCopy[payload.locale]; // set the state to the new object
state.translations = translationCopy;
}
}
|
javascript
|
function REMOVE_LOCALE(state, payload) {
// check if the given locale is present in the state
if (state.translations.hasOwnProperty(payload.locale)) {
// check if the current locale is the given locale to remvoe
if (state.locale === payload.locale) {
// reset the current locale
state.locale = null;
} // create a copy of the translations object
var translationCopy = Object.assign({}, state.translations); // remove the given locale
delete translationCopy[payload.locale]; // set the state to the new object
state.translations = translationCopy;
}
}
|
[
"function",
"REMOVE_LOCALE",
"(",
"state",
",",
"payload",
")",
"{",
"// check if the given locale is present in the state",
"if",
"(",
"state",
".",
"translations",
".",
"hasOwnProperty",
"(",
"payload",
".",
"locale",
")",
")",
"{",
"// check if the current locale is the given locale to remvoe",
"if",
"(",
"state",
".",
"locale",
"===",
"payload",
".",
"locale",
")",
"{",
"// reset the current locale",
"state",
".",
"locale",
"=",
"null",
";",
"}",
"// create a copy of the translations object",
"var",
"translationCopy",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"state",
".",
"translations",
")",
";",
"// remove the given locale",
"delete",
"translationCopy",
"[",
"payload",
".",
"locale",
"]",
";",
"// set the state to the new object",
"state",
".",
"translations",
"=",
"translationCopy",
";",
"}",
"}"
] |
remove a locale from the store
|
[
"remove",
"a",
"locale",
"from",
"the",
"store"
] |
41b589e05546986f9e7768cd1ca4982b90ebde95
|
https://github.com/dkfbasel/vuex-i18n/blob/41b589e05546986f9e7768cd1ca4982b90ebde95/dist/vuex-i18n.es.js#L68-L84
|
15,507
|
dkfbasel/vuex-i18n
|
dist/vuex-i18n.es.js
|
addLocale
|
function addLocale(context, payload) {
context.commit({
type: 'ADD_LOCALE',
locale: payload.locale,
translations: payload.translations
});
}
|
javascript
|
function addLocale(context, payload) {
context.commit({
type: 'ADD_LOCALE',
locale: payload.locale,
translations: payload.translations
});
}
|
[
"function",
"addLocale",
"(",
"context",
",",
"payload",
")",
"{",
"context",
".",
"commit",
"(",
"{",
"type",
":",
"'ADD_LOCALE'",
",",
"locale",
":",
"payload",
".",
"locale",
",",
"translations",
":",
"payload",
".",
"translations",
"}",
")",
";",
"}"
] |
add or extend a locale with translations
|
[
"add",
"or",
"extend",
"a",
"locale",
"with",
"translations"
] |
41b589e05546986f9e7768cd1ca4982b90ebde95
|
https://github.com/dkfbasel/vuex-i18n/blob/41b589e05546986f9e7768cd1ca4982b90ebde95/dist/vuex-i18n.es.js#L98-L104
|
15,508
|
dkfbasel/vuex-i18n
|
dist/vuex-i18n.es.js
|
replaceLocale
|
function replaceLocale(context, payload) {
context.commit({
type: 'REPLACE_LOCALE',
locale: payload.locale,
translations: payload.translations
});
}
|
javascript
|
function replaceLocale(context, payload) {
context.commit({
type: 'REPLACE_LOCALE',
locale: payload.locale,
translations: payload.translations
});
}
|
[
"function",
"replaceLocale",
"(",
"context",
",",
"payload",
")",
"{",
"context",
".",
"commit",
"(",
"{",
"type",
":",
"'REPLACE_LOCALE'",
",",
"locale",
":",
"payload",
".",
"locale",
",",
"translations",
":",
"payload",
".",
"translations",
"}",
")",
";",
"}"
] |
replace locale information
|
[
"replace",
"locale",
"information"
] |
41b589e05546986f9e7768cd1ca4982b90ebde95
|
https://github.com/dkfbasel/vuex-i18n/blob/41b589e05546986f9e7768cd1ca4982b90ebde95/dist/vuex-i18n.es.js#L106-L112
|
15,509
|
dkfbasel/vuex-i18n
|
dist/vuex-i18n.es.js
|
removeLocale
|
function removeLocale(context, payload) {
context.commit({
type: 'REMOVE_LOCALE',
locale: payload.locale,
translations: payload.translations
});
}
|
javascript
|
function removeLocale(context, payload) {
context.commit({
type: 'REMOVE_LOCALE',
locale: payload.locale,
translations: payload.translations
});
}
|
[
"function",
"removeLocale",
"(",
"context",
",",
"payload",
")",
"{",
"context",
".",
"commit",
"(",
"{",
"type",
":",
"'REMOVE_LOCALE'",
",",
"locale",
":",
"payload",
".",
"locale",
",",
"translations",
":",
"payload",
".",
"translations",
"}",
")",
";",
"}"
] |
remove the given locale translations
|
[
"remove",
"the",
"given",
"locale",
"translations"
] |
41b589e05546986f9e7768cd1ca4982b90ebde95
|
https://github.com/dkfbasel/vuex-i18n/blob/41b589e05546986f9e7768cd1ca4982b90ebde95/dist/vuex-i18n.es.js#L114-L120
|
15,510
|
dkfbasel/vuex-i18n
|
dist/vuex-i18n.es.js
|
flattenTranslations
|
function flattenTranslations(translations) {
var toReturn = {};
for (var i in translations) {
// check if the property is present
if (!translations.hasOwnProperty(i)) {
continue;
} // get the type of the property
var objType = _typeof(translations[i]); // allow unflattened array of strings
if (isArray(translations[i])) {
var count = translations[i].length;
for (var index = 0; index < count; index++) {
var itemType = _typeof(translations[i][index]);
if (itemType !== 'string') {
console.warn('i18n:', 'currently only arrays of strings are fully supported', translations[i]);
break;
}
}
toReturn[i] = translations[i];
} else if (objType == 'object' && objType !== null) {
var flatObject = flattenTranslations(translations[i]);
for (var x in flatObject) {
if (!flatObject.hasOwnProperty(x)) continue;
toReturn[i + '.' + x] = flatObject[x];
}
} else {
toReturn[i] = translations[i];
}
}
return toReturn;
}
|
javascript
|
function flattenTranslations(translations) {
var toReturn = {};
for (var i in translations) {
// check if the property is present
if (!translations.hasOwnProperty(i)) {
continue;
} // get the type of the property
var objType = _typeof(translations[i]); // allow unflattened array of strings
if (isArray(translations[i])) {
var count = translations[i].length;
for (var index = 0; index < count; index++) {
var itemType = _typeof(translations[i][index]);
if (itemType !== 'string') {
console.warn('i18n:', 'currently only arrays of strings are fully supported', translations[i]);
break;
}
}
toReturn[i] = translations[i];
} else if (objType == 'object' && objType !== null) {
var flatObject = flattenTranslations(translations[i]);
for (var x in flatObject) {
if (!flatObject.hasOwnProperty(x)) continue;
toReturn[i + '.' + x] = flatObject[x];
}
} else {
toReturn[i] = translations[i];
}
}
return toReturn;
}
|
[
"function",
"flattenTranslations",
"(",
"translations",
")",
"{",
"var",
"toReturn",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"i",
"in",
"translations",
")",
"{",
"// check if the property is present",
"if",
"(",
"!",
"translations",
".",
"hasOwnProperty",
"(",
"i",
")",
")",
"{",
"continue",
";",
"}",
"// get the type of the property",
"var",
"objType",
"=",
"_typeof",
"(",
"translations",
"[",
"i",
"]",
")",
";",
"// allow unflattened array of strings",
"if",
"(",
"isArray",
"(",
"translations",
"[",
"i",
"]",
")",
")",
"{",
"var",
"count",
"=",
"translations",
"[",
"i",
"]",
".",
"length",
";",
"for",
"(",
"var",
"index",
"=",
"0",
";",
"index",
"<",
"count",
";",
"index",
"++",
")",
"{",
"var",
"itemType",
"=",
"_typeof",
"(",
"translations",
"[",
"i",
"]",
"[",
"index",
"]",
")",
";",
"if",
"(",
"itemType",
"!==",
"'string'",
")",
"{",
"console",
".",
"warn",
"(",
"'i18n:'",
",",
"'currently only arrays of strings are fully supported'",
",",
"translations",
"[",
"i",
"]",
")",
";",
"break",
";",
"}",
"}",
"toReturn",
"[",
"i",
"]",
"=",
"translations",
"[",
"i",
"]",
";",
"}",
"else",
"if",
"(",
"objType",
"==",
"'object'",
"&&",
"objType",
"!==",
"null",
")",
"{",
"var",
"flatObject",
"=",
"flattenTranslations",
"(",
"translations",
"[",
"i",
"]",
")",
";",
"for",
"(",
"var",
"x",
"in",
"flatObject",
")",
"{",
"if",
"(",
"!",
"flatObject",
".",
"hasOwnProperty",
"(",
"x",
")",
")",
"continue",
";",
"toReturn",
"[",
"i",
"+",
"'.'",
"+",
"x",
"]",
"=",
"flatObject",
"[",
"x",
"]",
";",
"}",
"}",
"else",
"{",
"toReturn",
"[",
"i",
"]",
"=",
"translations",
"[",
"i",
"]",
";",
"}",
"}",
"return",
"toReturn",
";",
"}"
] |
flattenTranslations will convert object trees for translations into a single-depth object tree
|
[
"flattenTranslations",
"will",
"convert",
"object",
"trees",
"for",
"translations",
"into",
"a",
"single",
"-",
"depth",
"object",
"tree"
] |
41b589e05546986f9e7768cd1ca4982b90ebde95
|
https://github.com/dkfbasel/vuex-i18n/blob/41b589e05546986f9e7768cd1ca4982b90ebde95/dist/vuex-i18n.es.js#L131-L170
|
15,511
|
dkfbasel/vuex-i18n
|
dist/vuex-i18n.es.js
|
$t
|
function $t() {
// get the current language from the store
var locale = store.state[moduleName].locale;
return translateInLanguage.apply(void 0, [locale].concat(Array.prototype.slice.call(arguments)));
}
|
javascript
|
function $t() {
// get the current language from the store
var locale = store.state[moduleName].locale;
return translateInLanguage.apply(void 0, [locale].concat(Array.prototype.slice.call(arguments)));
}
|
[
"function",
"$t",
"(",
")",
"{",
"// get the current language from the store",
"var",
"locale",
"=",
"store",
".",
"state",
"[",
"moduleName",
"]",
".",
"locale",
";",
"return",
"translateInLanguage",
".",
"apply",
"(",
"void",
"0",
",",
"[",
"locale",
"]",
".",
"concat",
"(",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
")",
")",
";",
"}"
] |
get localized string from store. note that we pass the arguments passed to the function directly to the translateInLanguage function
|
[
"get",
"localized",
"string",
"from",
"store",
".",
"note",
"that",
"we",
"pass",
"the",
"arguments",
"passed",
"to",
"the",
"function",
"directly",
"to",
"the",
"translateInLanguage",
"function"
] |
41b589e05546986f9e7768cd1ca4982b90ebde95
|
https://github.com/dkfbasel/vuex-i18n/blob/41b589e05546986f9e7768cd1ca4982b90ebde95/dist/vuex-i18n.es.js#L453-L457
|
15,512
|
dkfbasel/vuex-i18n
|
dist/vuex-i18n.es.js
|
checkKeyExists
|
function checkKeyExists(key) {
var scope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'fallback';
// get the current language from the store
var locale = store.state[moduleName].locale;
var fallback = store.state[moduleName].fallback;
var translations = store.state[moduleName].translations; // check the current translation
if (translations.hasOwnProperty(locale) && translations[locale].hasOwnProperty(key)) {
return true;
}
if (scope == 'strict') {
return false;
} // check any localized translations
var localeRegional = locale.split('-');
if (localeRegional.length > 1 && translations.hasOwnProperty(localeRegional[0]) && translations[localeRegional[0]].hasOwnProperty(key)) {
return true;
}
if (scope == 'locale') {
return false;
} // check if a fallback locale exists
if (translations.hasOwnProperty(fallback) && translations[fallback].hasOwnProperty(key)) {
return true;
} // key does not exist in the store
return false;
}
|
javascript
|
function checkKeyExists(key) {
var scope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'fallback';
// get the current language from the store
var locale = store.state[moduleName].locale;
var fallback = store.state[moduleName].fallback;
var translations = store.state[moduleName].translations; // check the current translation
if (translations.hasOwnProperty(locale) && translations[locale].hasOwnProperty(key)) {
return true;
}
if (scope == 'strict') {
return false;
} // check any localized translations
var localeRegional = locale.split('-');
if (localeRegional.length > 1 && translations.hasOwnProperty(localeRegional[0]) && translations[localeRegional[0]].hasOwnProperty(key)) {
return true;
}
if (scope == 'locale') {
return false;
} // check if a fallback locale exists
if (translations.hasOwnProperty(fallback) && translations[fallback].hasOwnProperty(key)) {
return true;
} // key does not exist in the store
return false;
}
|
[
"function",
"checkKeyExists",
"(",
"key",
")",
"{",
"var",
"scope",
"=",
"arguments",
".",
"length",
">",
"1",
"&&",
"arguments",
"[",
"1",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"1",
"]",
":",
"'fallback'",
";",
"// get the current language from the store",
"var",
"locale",
"=",
"store",
".",
"state",
"[",
"moduleName",
"]",
".",
"locale",
";",
"var",
"fallback",
"=",
"store",
".",
"state",
"[",
"moduleName",
"]",
".",
"fallback",
";",
"var",
"translations",
"=",
"store",
".",
"state",
"[",
"moduleName",
"]",
".",
"translations",
";",
"// check the current translation",
"if",
"(",
"translations",
".",
"hasOwnProperty",
"(",
"locale",
")",
"&&",
"translations",
"[",
"locale",
"]",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"scope",
"==",
"'strict'",
")",
"{",
"return",
"false",
";",
"}",
"// check any localized translations",
"var",
"localeRegional",
"=",
"locale",
".",
"split",
"(",
"'-'",
")",
";",
"if",
"(",
"localeRegional",
".",
"length",
">",
"1",
"&&",
"translations",
".",
"hasOwnProperty",
"(",
"localeRegional",
"[",
"0",
"]",
")",
"&&",
"translations",
"[",
"localeRegional",
"[",
"0",
"]",
"]",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"scope",
"==",
"'locale'",
")",
"{",
"return",
"false",
";",
"}",
"// check if a fallback locale exists",
"if",
"(",
"translations",
".",
"hasOwnProperty",
"(",
"fallback",
")",
"&&",
"translations",
"[",
"fallback",
"]",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"return",
"true",
";",
"}",
"// key does not exist in the store",
"return",
"false",
";",
"}"
] |
check if the given key exists in the current locale
|
[
"check",
"if",
"the",
"given",
"key",
"exists",
"in",
"the",
"current",
"locale"
] |
41b589e05546986f9e7768cd1ca4982b90ebde95
|
https://github.com/dkfbasel/vuex-i18n/blob/41b589e05546986f9e7768cd1ca4982b90ebde95/dist/vuex-i18n.es.js#L568-L601
|
15,513
|
dkfbasel/vuex-i18n
|
dist/vuex-i18n.es.js
|
replaceLocale
|
function replaceLocale(locale, translations) {
return store.dispatch({
type: "".concat(moduleName, "/replaceLocale"),
locale: locale,
translations: translations
});
}
|
javascript
|
function replaceLocale(locale, translations) {
return store.dispatch({
type: "".concat(moduleName, "/replaceLocale"),
locale: locale,
translations: translations
});
}
|
[
"function",
"replaceLocale",
"(",
"locale",
",",
"translations",
")",
"{",
"return",
"store",
".",
"dispatch",
"(",
"{",
"type",
":",
"\"\"",
".",
"concat",
"(",
"moduleName",
",",
"\"/replaceLocale\"",
")",
",",
"locale",
":",
"locale",
",",
"translations",
":",
"translations",
"}",
")",
";",
"}"
] |
replace all locale information in the store
|
[
"replace",
"all",
"locale",
"information",
"in",
"the",
"store"
] |
41b589e05546986f9e7768cd1ca4982b90ebde95
|
https://github.com/dkfbasel/vuex-i18n/blob/41b589e05546986f9e7768cd1ca4982b90ebde95/dist/vuex-i18n.es.js#L639-L645
|
15,514
|
dkfbasel/vuex-i18n
|
dist/vuex-i18n.es.js
|
removeLocale
|
function removeLocale(locale) {
if (store.state[moduleName].translations.hasOwnProperty(locale)) {
store.dispatch({
type: "".concat(moduleName, "/removeLocale"),
locale: locale
});
}
}
|
javascript
|
function removeLocale(locale) {
if (store.state[moduleName].translations.hasOwnProperty(locale)) {
store.dispatch({
type: "".concat(moduleName, "/removeLocale"),
locale: locale
});
}
}
|
[
"function",
"removeLocale",
"(",
"locale",
")",
"{",
"if",
"(",
"store",
".",
"state",
"[",
"moduleName",
"]",
".",
"translations",
".",
"hasOwnProperty",
"(",
"locale",
")",
")",
"{",
"store",
".",
"dispatch",
"(",
"{",
"type",
":",
"\"\"",
".",
"concat",
"(",
"moduleName",
",",
"\"/removeLocale\"",
")",
",",
"locale",
":",
"locale",
"}",
")",
";",
"}",
"}"
] |
remove the givne locale from the store
|
[
"remove",
"the",
"givne",
"locale",
"from",
"the",
"store"
] |
41b589e05546986f9e7768cd1ca4982b90ebde95
|
https://github.com/dkfbasel/vuex-i18n/blob/41b589e05546986f9e7768cd1ca4982b90ebde95/dist/vuex-i18n.es.js#L648-L655
|
15,515
|
dkfbasel/vuex-i18n
|
dist/vuex-i18n.es.js
|
replace
|
function replace(translation, replacements) {
// check if the object has a replace property
if (!translation.replace) {
return translation;
}
return translation.replace(matcher, function (placeholder) {
// remove the identifiers (can be set on the module level)
var key = placeholder.replace(identifiers[0], '').replace(identifiers[1], '');
if (replacements[key] !== undefined) {
return replacements[key];
} // warn user that the placeholder has not been found
if (warnings) {
console.group ? console.group('i18n: Not all placeholders found') : console.warn('i18n: Not all placeholders found');
console.warn('Text:', translation);
console.warn('Placeholder:', placeholder);
if (console.groupEnd) {
console.groupEnd();
}
} // return the original placeholder
return placeholder;
});
}
|
javascript
|
function replace(translation, replacements) {
// check if the object has a replace property
if (!translation.replace) {
return translation;
}
return translation.replace(matcher, function (placeholder) {
// remove the identifiers (can be set on the module level)
var key = placeholder.replace(identifiers[0], '').replace(identifiers[1], '');
if (replacements[key] !== undefined) {
return replacements[key];
} // warn user that the placeholder has not been found
if (warnings) {
console.group ? console.group('i18n: Not all placeholders found') : console.warn('i18n: Not all placeholders found');
console.warn('Text:', translation);
console.warn('Placeholder:', placeholder);
if (console.groupEnd) {
console.groupEnd();
}
} // return the original placeholder
return placeholder;
});
}
|
[
"function",
"replace",
"(",
"translation",
",",
"replacements",
")",
"{",
"// check if the object has a replace property",
"if",
"(",
"!",
"translation",
".",
"replace",
")",
"{",
"return",
"translation",
";",
"}",
"return",
"translation",
".",
"replace",
"(",
"matcher",
",",
"function",
"(",
"placeholder",
")",
"{",
"// remove the identifiers (can be set on the module level)",
"var",
"key",
"=",
"placeholder",
".",
"replace",
"(",
"identifiers",
"[",
"0",
"]",
",",
"''",
")",
".",
"replace",
"(",
"identifiers",
"[",
"1",
"]",
",",
"''",
")",
";",
"if",
"(",
"replacements",
"[",
"key",
"]",
"!==",
"undefined",
")",
"{",
"return",
"replacements",
"[",
"key",
"]",
";",
"}",
"// warn user that the placeholder has not been found",
"if",
"(",
"warnings",
")",
"{",
"console",
".",
"group",
"?",
"console",
".",
"group",
"(",
"'i18n: Not all placeholders found'",
")",
":",
"console",
".",
"warn",
"(",
"'i18n: Not all placeholders found'",
")",
";",
"console",
".",
"warn",
"(",
"'Text:'",
",",
"translation",
")",
";",
"console",
".",
"warn",
"(",
"'Placeholder:'",
",",
"placeholder",
")",
";",
"if",
"(",
"console",
".",
"groupEnd",
")",
"{",
"console",
".",
"groupEnd",
"(",
")",
";",
"}",
"}",
"// return the original placeholder",
"return",
"placeholder",
";",
"}",
")",
";",
"}"
] |
define the replacement function
|
[
"define",
"the",
"replacement",
"function"
] |
41b589e05546986f9e7768cd1ca4982b90ebde95
|
https://github.com/dkfbasel/vuex-i18n/blob/41b589e05546986f9e7768cd1ca4982b90ebde95/dist/vuex-i18n.es.js#L722-L750
|
15,516
|
dkfbasel/vuex-i18n
|
dist/vuex-i18n.es.js
|
render
|
function render(locale, translation) {
var replacements = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var pluralization = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
// get the type of the property
var objType = _typeof(translation);
var pluralizationType = _typeof(pluralization);
var resolvePlaceholders = function resolvePlaceholders() {
if (isArray$1(translation)) {
// replace the placeholder elements in all sub-items
return translation.map(function (item) {
return replace(item, replacements, false);
});
} else if (objType === 'string') {
return replace(translation, replacements, true);
}
}; // return translation item directly
if (pluralization === null) {
return resolvePlaceholders();
} // check if pluralization value is countable
if (pluralizationType !== 'number') {
if (warnings) console.warn('i18n: pluralization is not a number');
return resolvePlaceholders();
} // --- handle pluralizations ---
// replace all placeholders
var resolvedTranslation = resolvePlaceholders(); // initialize pluralizations
var pluralizations = null; // if translations are already an array and have more than one entry,
// we will not perform a split operation on :::
if (isArray$1(resolvedTranslation) && resolvedTranslation.length > 0) {
pluralizations = resolvedTranslation;
} else {
// split translation strings by ::: to find create the pluralization array
pluralizations = resolvedTranslation.split(':::');
} // determine the pluralization version to use by locale
var index = plurals.getTranslationIndex(locale, pluralization); // check if the specified index is present in the pluralization
if (typeof pluralizations[index] === 'undefined') {
if (warnings) {
console.warn('i18n: pluralization not provided in locale', translation, locale, index);
} // return the first element of the pluralization by default
return pluralizations[0].trim();
} // return the requested item from the pluralizations
return pluralizations[index].trim();
}
|
javascript
|
function render(locale, translation) {
var replacements = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var pluralization = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
// get the type of the property
var objType = _typeof(translation);
var pluralizationType = _typeof(pluralization);
var resolvePlaceholders = function resolvePlaceholders() {
if (isArray$1(translation)) {
// replace the placeholder elements in all sub-items
return translation.map(function (item) {
return replace(item, replacements, false);
});
} else if (objType === 'string') {
return replace(translation, replacements, true);
}
}; // return translation item directly
if (pluralization === null) {
return resolvePlaceholders();
} // check if pluralization value is countable
if (pluralizationType !== 'number') {
if (warnings) console.warn('i18n: pluralization is not a number');
return resolvePlaceholders();
} // --- handle pluralizations ---
// replace all placeholders
var resolvedTranslation = resolvePlaceholders(); // initialize pluralizations
var pluralizations = null; // if translations are already an array and have more than one entry,
// we will not perform a split operation on :::
if (isArray$1(resolvedTranslation) && resolvedTranslation.length > 0) {
pluralizations = resolvedTranslation;
} else {
// split translation strings by ::: to find create the pluralization array
pluralizations = resolvedTranslation.split(':::');
} // determine the pluralization version to use by locale
var index = plurals.getTranslationIndex(locale, pluralization); // check if the specified index is present in the pluralization
if (typeof pluralizations[index] === 'undefined') {
if (warnings) {
console.warn('i18n: pluralization not provided in locale', translation, locale, index);
} // return the first element of the pluralization by default
return pluralizations[0].trim();
} // return the requested item from the pluralizations
return pluralizations[index].trim();
}
|
[
"function",
"render",
"(",
"locale",
",",
"translation",
")",
"{",
"var",
"replacements",
"=",
"arguments",
".",
"length",
">",
"2",
"&&",
"arguments",
"[",
"2",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"2",
"]",
":",
"{",
"}",
";",
"var",
"pluralization",
"=",
"arguments",
".",
"length",
">",
"3",
"&&",
"arguments",
"[",
"3",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"3",
"]",
":",
"null",
";",
"// get the type of the property",
"var",
"objType",
"=",
"_typeof",
"(",
"translation",
")",
";",
"var",
"pluralizationType",
"=",
"_typeof",
"(",
"pluralization",
")",
";",
"var",
"resolvePlaceholders",
"=",
"function",
"resolvePlaceholders",
"(",
")",
"{",
"if",
"(",
"isArray$1",
"(",
"translation",
")",
")",
"{",
"// replace the placeholder elements in all sub-items",
"return",
"translation",
".",
"map",
"(",
"function",
"(",
"item",
")",
"{",
"return",
"replace",
"(",
"item",
",",
"replacements",
",",
"false",
")",
";",
"}",
")",
";",
"}",
"else",
"if",
"(",
"objType",
"===",
"'string'",
")",
"{",
"return",
"replace",
"(",
"translation",
",",
"replacements",
",",
"true",
")",
";",
"}",
"}",
";",
"// return translation item directly",
"if",
"(",
"pluralization",
"===",
"null",
")",
"{",
"return",
"resolvePlaceholders",
"(",
")",
";",
"}",
"// check if pluralization value is countable",
"if",
"(",
"pluralizationType",
"!==",
"'number'",
")",
"{",
"if",
"(",
"warnings",
")",
"console",
".",
"warn",
"(",
"'i18n: pluralization is not a number'",
")",
";",
"return",
"resolvePlaceholders",
"(",
")",
";",
"}",
"// --- handle pluralizations ---",
"// replace all placeholders",
"var",
"resolvedTranslation",
"=",
"resolvePlaceholders",
"(",
")",
";",
"// initialize pluralizations",
"var",
"pluralizations",
"=",
"null",
";",
"// if translations are already an array and have more than one entry,",
"// we will not perform a split operation on :::",
"if",
"(",
"isArray$1",
"(",
"resolvedTranslation",
")",
"&&",
"resolvedTranslation",
".",
"length",
">",
"0",
")",
"{",
"pluralizations",
"=",
"resolvedTranslation",
";",
"}",
"else",
"{",
"// split translation strings by ::: to find create the pluralization array",
"pluralizations",
"=",
"resolvedTranslation",
".",
"split",
"(",
"':::'",
")",
";",
"}",
"// determine the pluralization version to use by locale",
"var",
"index",
"=",
"plurals",
".",
"getTranslationIndex",
"(",
"locale",
",",
"pluralization",
")",
";",
"// check if the specified index is present in the pluralization",
"if",
"(",
"typeof",
"pluralizations",
"[",
"index",
"]",
"===",
"'undefined'",
")",
"{",
"if",
"(",
"warnings",
")",
"{",
"console",
".",
"warn",
"(",
"'i18n: pluralization not provided in locale'",
",",
"translation",
",",
"locale",
",",
"index",
")",
";",
"}",
"// return the first element of the pluralization by default",
"return",
"pluralizations",
"[",
"0",
"]",
".",
"trim",
"(",
")",
";",
"}",
"// return the requested item from the pluralizations",
"return",
"pluralizations",
"[",
"index",
"]",
".",
"trim",
"(",
")",
";",
"}"
] |
the render function will replace variable substitutions and prepare the translations for rendering
|
[
"the",
"render",
"function",
"will",
"replace",
"variable",
"substitutions",
"and",
"prepare",
"the",
"translations",
"for",
"rendering"
] |
41b589e05546986f9e7768cd1ca4982b90ebde95
|
https://github.com/dkfbasel/vuex-i18n/blob/41b589e05546986f9e7768cd1ca4982b90ebde95/dist/vuex-i18n.es.js#L754-L813
|
15,517
|
rdkmaster/jigsaw
|
build/scripts/doc-generator/json-parser.js
|
findInheritedProperties
|
function findInheritedProperties(ci, properties) {
while (ci && ci.extends) {
ci = findTypeMetaInfo(ci.extends);
if (!ci) {
console.warn('no meta info for: ' + ci.extends);
continue;
}
mergeProperties(ci).forEach(p => {
if (properties.find(pp => pp.name === p.name)) {
return;
}
if (p.inheritance) {
return;
}
// deep copy
p = JSON.parse(JSON.stringify(p));
delete p.inheritance;
p.inheritInfo = {from: ci.name, type: ci.type || ci.subtype};
properties.push(p);
});
}
}
|
javascript
|
function findInheritedProperties(ci, properties) {
while (ci && ci.extends) {
ci = findTypeMetaInfo(ci.extends);
if (!ci) {
console.warn('no meta info for: ' + ci.extends);
continue;
}
mergeProperties(ci).forEach(p => {
if (properties.find(pp => pp.name === p.name)) {
return;
}
if (p.inheritance) {
return;
}
// deep copy
p = JSON.parse(JSON.stringify(p));
delete p.inheritance;
p.inheritInfo = {from: ci.name, type: ci.type || ci.subtype};
properties.push(p);
});
}
}
|
[
"function",
"findInheritedProperties",
"(",
"ci",
",",
"properties",
")",
"{",
"while",
"(",
"ci",
"&&",
"ci",
".",
"extends",
")",
"{",
"ci",
"=",
"findTypeMetaInfo",
"(",
"ci",
".",
"extends",
")",
";",
"if",
"(",
"!",
"ci",
")",
"{",
"console",
".",
"warn",
"(",
"'no meta info for: '",
"+",
"ci",
".",
"extends",
")",
";",
"continue",
";",
"}",
"mergeProperties",
"(",
"ci",
")",
".",
"forEach",
"(",
"p",
"=>",
"{",
"if",
"(",
"properties",
".",
"find",
"(",
"pp",
"=>",
"pp",
".",
"name",
"===",
"p",
".",
"name",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"p",
".",
"inheritance",
")",
"{",
"return",
";",
"}",
"// deep copy\r",
"p",
"=",
"JSON",
".",
"parse",
"(",
"JSON",
".",
"stringify",
"(",
"p",
")",
")",
";",
"delete",
"p",
".",
"inheritance",
";",
"p",
".",
"inheritInfo",
"=",
"{",
"from",
":",
"ci",
".",
"name",
",",
"type",
":",
"ci",
".",
"type",
"||",
"ci",
".",
"subtype",
"}",
";",
"properties",
".",
"push",
"(",
"p",
")",
";",
"}",
")",
";",
"}",
"}"
] |
not including the current class's properties
|
[
"not",
"including",
"the",
"current",
"class",
"s",
"properties"
] |
c378116a62913f3d43ac3e1064f6f41b9e1b4333
|
https://github.com/rdkmaster/jigsaw/blob/c378116a62913f3d43ac3e1064f6f41b9e1b4333/build/scripts/doc-generator/json-parser.js#L244-L265
|
15,518
|
rdkmaster/jigsaw
|
build/scripts/doc-generator/json-parser.js
|
findInheritedMethods
|
function findInheritedMethods(ci, methods) {
while (ci && ci.extends) {
ci = findTypeMetaInfo(ci.extends);
if (!ci) {
console.warn('no meta info for: ' + ci.extends);
continue;
}
(ci.methodsClass || ci.methods).forEach(m => {
if (methods.find(mm => mm.name === m.name && getArgumentsString(mm) == getArgumentsString(m))) {
return;
}
if (m.inheritance || isAngularLifeCircle(m.name)) {
return;
}
// deep copy
m = JSON.parse(JSON.stringify(m));
delete m.inheritance;
m.inheritInfo = {from: ci.name, type: ci.type || ci.subtype};
methods.push(m);
});
}
}
|
javascript
|
function findInheritedMethods(ci, methods) {
while (ci && ci.extends) {
ci = findTypeMetaInfo(ci.extends);
if (!ci) {
console.warn('no meta info for: ' + ci.extends);
continue;
}
(ci.methodsClass || ci.methods).forEach(m => {
if (methods.find(mm => mm.name === m.name && getArgumentsString(mm) == getArgumentsString(m))) {
return;
}
if (m.inheritance || isAngularLifeCircle(m.name)) {
return;
}
// deep copy
m = JSON.parse(JSON.stringify(m));
delete m.inheritance;
m.inheritInfo = {from: ci.name, type: ci.type || ci.subtype};
methods.push(m);
});
}
}
|
[
"function",
"findInheritedMethods",
"(",
"ci",
",",
"methods",
")",
"{",
"while",
"(",
"ci",
"&&",
"ci",
".",
"extends",
")",
"{",
"ci",
"=",
"findTypeMetaInfo",
"(",
"ci",
".",
"extends",
")",
";",
"if",
"(",
"!",
"ci",
")",
"{",
"console",
".",
"warn",
"(",
"'no meta info for: '",
"+",
"ci",
".",
"extends",
")",
";",
"continue",
";",
"}",
"(",
"ci",
".",
"methodsClass",
"||",
"ci",
".",
"methods",
")",
".",
"forEach",
"(",
"m",
"=>",
"{",
"if",
"(",
"methods",
".",
"find",
"(",
"mm",
"=>",
"mm",
".",
"name",
"===",
"m",
".",
"name",
"&&",
"getArgumentsString",
"(",
"mm",
")",
"==",
"getArgumentsString",
"(",
"m",
")",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"m",
".",
"inheritance",
"||",
"isAngularLifeCircle",
"(",
"m",
".",
"name",
")",
")",
"{",
"return",
";",
"}",
"// deep copy\r",
"m",
"=",
"JSON",
".",
"parse",
"(",
"JSON",
".",
"stringify",
"(",
"m",
")",
")",
";",
"delete",
"m",
".",
"inheritance",
";",
"m",
".",
"inheritInfo",
"=",
"{",
"from",
":",
"ci",
".",
"name",
",",
"type",
":",
"ci",
".",
"type",
"||",
"ci",
".",
"subtype",
"}",
";",
"methods",
".",
"push",
"(",
"m",
")",
";",
"}",
")",
";",
"}",
"}"
] |
not including the current class's methods
|
[
"not",
"including",
"the",
"current",
"class",
"s",
"methods"
] |
c378116a62913f3d43ac3e1064f6f41b9e1b4333
|
https://github.com/rdkmaster/jigsaw/blob/c378116a62913f3d43ac3e1064f6f41b9e1b4333/build/scripts/doc-generator/json-parser.js#L366-L387
|
15,519
|
adonisjs/ace
|
src/Question/index.js
|
multipleFilterFn
|
function multipleFilterFn () {
return this.choices.choices
.filter((choice) => choice.checked)
.map((choice) => choice.key)
}
|
javascript
|
function multipleFilterFn () {
return this.choices.choices
.filter((choice) => choice.checked)
.map((choice) => choice.key)
}
|
[
"function",
"multipleFilterFn",
"(",
")",
"{",
"return",
"this",
".",
"choices",
".",
"choices",
".",
"filter",
"(",
"(",
"choice",
")",
"=>",
"choice",
".",
"checked",
")",
".",
"map",
"(",
"(",
"choice",
")",
"=>",
"choice",
".",
"key",
")",
"}"
] |
The enquirer has a bug where it returns
the name over the key, which is wrong.
This method overrides that behavior
@method multipleFilterFn
@return {Array}
|
[
"The",
"enquirer",
"has",
"a",
"bug",
"where",
"it",
"returns",
"the",
"name",
"over",
"the",
"key",
"which",
"is",
"wrong",
"."
] |
1d9df4a75740da5fa8098efab5f08da2bcc30b7f
|
https://github.com/adonisjs/ace/blob/1d9df4a75740da5fa8098efab5f08da2bcc30b7f/src/Question/index.js#L25-L29
|
15,520
|
detro/ghostdriver
|
src/third_party/console++.js
|
function(msg, levelMsg) {
if (console.isTimestamped()) {
return "[" + levelMsg + " - " + new Date().toJSON() + "] " + msg;
} else {
return "[" + levelMsg + "] " + msg;
}
}
|
javascript
|
function(msg, levelMsg) {
if (console.isTimestamped()) {
return "[" + levelMsg + " - " + new Date().toJSON() + "] " + msg;
} else {
return "[" + levelMsg + "] " + msg;
}
}
|
[
"function",
"(",
"msg",
",",
"levelMsg",
")",
"{",
"if",
"(",
"console",
".",
"isTimestamped",
"(",
")",
")",
"{",
"return",
"\"[\"",
"+",
"levelMsg",
"+",
"\" - \"",
"+",
"new",
"Date",
"(",
")",
".",
"toJSON",
"(",
")",
"+",
"\"] \"",
"+",
"msg",
";",
"}",
"else",
"{",
"return",
"\"[\"",
"+",
"levelMsg",
"+",
"\"] \"",
"+",
"msg",
";",
"}",
"}"
] |
Formats the Message content.
@param msg The message itself
@param levelMsg The portion of message that contains the Level (maybe colored)
@retuns The formatted message
|
[
"Formats",
"the",
"Message",
"content",
"."
] |
fe3063d52f47ec2781d43970452595c42f729ebf
|
https://github.com/detro/ghostdriver/blob/fe3063d52f47ec2781d43970452595c42f729ebf/src/third_party/console++.js#L162-L168
|
|
15,521
|
bunkat/later
|
src/constraint/time.js
|
function(d, val) {
val = val > 86399 ? 0 : val;
var next = later.date.next(
later.Y.val(d),
later.M.val(d),
later.D.val(d) + (val <= later.t.val(d) ? 1 : 0),
0,
0,
val);
// correct for passing over a daylight savings boundry
if(!later.date.isUTC && next.getTime() < d.getTime()) {
next = later.date.next(
later.Y.val(next),
later.M.val(next),
later.D.val(next),
later.h.val(next),
later.m.val(next),
val + 7200);
}
return next;
}
|
javascript
|
function(d, val) {
val = val > 86399 ? 0 : val;
var next = later.date.next(
later.Y.val(d),
later.M.val(d),
later.D.val(d) + (val <= later.t.val(d) ? 1 : 0),
0,
0,
val);
// correct for passing over a daylight savings boundry
if(!later.date.isUTC && next.getTime() < d.getTime()) {
next = later.date.next(
later.Y.val(next),
later.M.val(next),
later.D.val(next),
later.h.val(next),
later.m.val(next),
val + 7200);
}
return next;
}
|
[
"function",
"(",
"d",
",",
"val",
")",
"{",
"val",
"=",
"val",
">",
"86399",
"?",
"0",
":",
"val",
";",
"var",
"next",
"=",
"later",
".",
"date",
".",
"next",
"(",
"later",
".",
"Y",
".",
"val",
"(",
"d",
")",
",",
"later",
".",
"M",
".",
"val",
"(",
"d",
")",
",",
"later",
".",
"D",
".",
"val",
"(",
"d",
")",
"+",
"(",
"val",
"<=",
"later",
".",
"t",
".",
"val",
"(",
"d",
")",
"?",
"1",
":",
"0",
")",
",",
"0",
",",
"0",
",",
"val",
")",
";",
"// correct for passing over a daylight savings boundry",
"if",
"(",
"!",
"later",
".",
"date",
".",
"isUTC",
"&&",
"next",
".",
"getTime",
"(",
")",
"<",
"d",
".",
"getTime",
"(",
")",
")",
"{",
"next",
"=",
"later",
".",
"date",
".",
"next",
"(",
"later",
".",
"Y",
".",
"val",
"(",
"next",
")",
",",
"later",
".",
"M",
".",
"val",
"(",
"next",
")",
",",
"later",
".",
"D",
".",
"val",
"(",
"next",
")",
",",
"later",
".",
"h",
".",
"val",
"(",
"next",
")",
",",
"later",
".",
"m",
".",
"val",
"(",
"next",
")",
",",
"val",
"+",
"7200",
")",
";",
"}",
"return",
"next",
";",
"}"
] |
Returns the start of the next instance of the time value indicated.
@param {Date} d: The starting date
@param {int} val: The desired value, must be within extent
|
[
"Returns",
"the",
"start",
"of",
"the",
"next",
"instance",
"of",
"the",
"time",
"value",
"indicated",
"."
] |
c5b45ef076d7a2c175c27427e5af22b29a0cc241
|
https://github.com/bunkat/later/blob/c5b45ef076d7a2c175c27427e5af22b29a0cc241/src/constraint/time.js#L76-L99
|
|
15,522
|
bunkat/later
|
src/constraint/weekofyear.js
|
function(d) {
if (d.wy) return d.wy;
// move to the Thursday in the target week and find Thurs of target year
var wThur = later.dw.next(later.wy.start(d), 5),
YThur = later.dw.next(later.Y.prev(wThur, later.Y.val(wThur)-1), 5);
// caculate the difference between the two dates in weeks
return (d.wy = 1 + Math.ceil((wThur.getTime() - YThur.getTime()) / later.WEEK));
}
|
javascript
|
function(d) {
if (d.wy) return d.wy;
// move to the Thursday in the target week and find Thurs of target year
var wThur = later.dw.next(later.wy.start(d), 5),
YThur = later.dw.next(later.Y.prev(wThur, later.Y.val(wThur)-1), 5);
// caculate the difference between the two dates in weeks
return (d.wy = 1 + Math.ceil((wThur.getTime() - YThur.getTime()) / later.WEEK));
}
|
[
"function",
"(",
"d",
")",
"{",
"if",
"(",
"d",
".",
"wy",
")",
"return",
"d",
".",
"wy",
";",
"// move to the Thursday in the target week and find Thurs of target year",
"var",
"wThur",
"=",
"later",
".",
"dw",
".",
"next",
"(",
"later",
".",
"wy",
".",
"start",
"(",
"d",
")",
",",
"5",
")",
",",
"YThur",
"=",
"later",
".",
"dw",
".",
"next",
"(",
"later",
".",
"Y",
".",
"prev",
"(",
"wThur",
",",
"later",
".",
"Y",
".",
"val",
"(",
"wThur",
")",
"-",
"1",
")",
",",
"5",
")",
";",
"// caculate the difference between the two dates in weeks",
"return",
"(",
"d",
".",
"wy",
"=",
"1",
"+",
"Math",
".",
"ceil",
"(",
"(",
"wThur",
".",
"getTime",
"(",
")",
"-",
"YThur",
".",
"getTime",
"(",
")",
")",
"/",
"later",
".",
"WEEK",
")",
")",
";",
"}"
] |
The ISO week year value of the specified date.
@param {Date} d: The date to calculate the value of
|
[
"The",
"ISO",
"week",
"year",
"value",
"of",
"the",
"specified",
"date",
"."
] |
c5b45ef076d7a2c175c27427e5af22b29a0cc241
|
https://github.com/bunkat/later/blob/c5b45ef076d7a2c175c27427e5af22b29a0cc241/src/constraint/weekofyear.js#L30-L39
|
|
15,523
|
bunkat/later
|
src/constraint/weekofyear.js
|
function(d) {
if (d.wyExtent) return d.wyExtent;
// go to start of ISO week to get to the right year
var year = later.dw.next(later.wy.start(d), 5),
dwFirst = later.dw.val(later.Y.start(year)),
dwLast = later.dw.val(later.Y.end(year));
return (d.wyExtent = [1, dwFirst === 5 || dwLast === 5 ? 53 : 52]);
}
|
javascript
|
function(d) {
if (d.wyExtent) return d.wyExtent;
// go to start of ISO week to get to the right year
var year = later.dw.next(later.wy.start(d), 5),
dwFirst = later.dw.val(later.Y.start(year)),
dwLast = later.dw.val(later.Y.end(year));
return (d.wyExtent = [1, dwFirst === 5 || dwLast === 5 ? 53 : 52]);
}
|
[
"function",
"(",
"d",
")",
"{",
"if",
"(",
"d",
".",
"wyExtent",
")",
"return",
"d",
".",
"wyExtent",
";",
"// go to start of ISO week to get to the right year",
"var",
"year",
"=",
"later",
".",
"dw",
".",
"next",
"(",
"later",
".",
"wy",
".",
"start",
"(",
"d",
")",
",",
"5",
")",
",",
"dwFirst",
"=",
"later",
".",
"dw",
".",
"val",
"(",
"later",
".",
"Y",
".",
"start",
"(",
"year",
")",
")",
",",
"dwLast",
"=",
"later",
".",
"dw",
".",
"val",
"(",
"later",
".",
"Y",
".",
"end",
"(",
"year",
")",
")",
";",
"return",
"(",
"d",
".",
"wyExtent",
"=",
"[",
"1",
",",
"dwFirst",
"===",
"5",
"||",
"dwLast",
"===",
"5",
"?",
"53",
":",
"52",
"]",
")",
";",
"}"
] |
The minimum and maximum valid ISO week values for the year indicated.
@param {Date} d: The date indicating the year to find ISO values for
|
[
"The",
"minimum",
"and",
"maximum",
"valid",
"ISO",
"week",
"values",
"for",
"the",
"year",
"indicated",
"."
] |
c5b45ef076d7a2c175c27427e5af22b29a0cc241
|
https://github.com/bunkat/later/blob/c5b45ef076d7a2c175c27427e5af22b29a0cc241/src/constraint/weekofyear.js#L56-L65
|
|
15,524
|
bunkat/later
|
src/constraint/weekofyear.js
|
function(d, val) {
var wyThur = later.dw.next(later.wy.start(d), 5),
year = later.date.prevRollover(wyThur, val, later.wy, later.Y);
// handle case where 1st of year is last week of previous month
if(later.wy.val(year) !== 1) {
year = later.dw.next(year, 2);
}
var wyMax = later.wy.extent(year)[1],
wyEnd = later.wy.end(year);
val = val > wyMax ? wyMax : val || wyMax;
return later.wy.end(later.date.next(
later.Y.val(wyEnd),
later.M.val(wyEnd),
later.D.val(wyEnd) + 7 * (val-1)
));
}
|
javascript
|
function(d, val) {
var wyThur = later.dw.next(later.wy.start(d), 5),
year = later.date.prevRollover(wyThur, val, later.wy, later.Y);
// handle case where 1st of year is last week of previous month
if(later.wy.val(year) !== 1) {
year = later.dw.next(year, 2);
}
var wyMax = later.wy.extent(year)[1],
wyEnd = later.wy.end(year);
val = val > wyMax ? wyMax : val || wyMax;
return later.wy.end(later.date.next(
later.Y.val(wyEnd),
later.M.val(wyEnd),
later.D.val(wyEnd) + 7 * (val-1)
));
}
|
[
"function",
"(",
"d",
",",
"val",
")",
"{",
"var",
"wyThur",
"=",
"later",
".",
"dw",
".",
"next",
"(",
"later",
".",
"wy",
".",
"start",
"(",
"d",
")",
",",
"5",
")",
",",
"year",
"=",
"later",
".",
"date",
".",
"prevRollover",
"(",
"wyThur",
",",
"val",
",",
"later",
".",
"wy",
",",
"later",
".",
"Y",
")",
";",
"// handle case where 1st of year is last week of previous month",
"if",
"(",
"later",
".",
"wy",
".",
"val",
"(",
"year",
")",
"!==",
"1",
")",
"{",
"year",
"=",
"later",
".",
"dw",
".",
"next",
"(",
"year",
",",
"2",
")",
";",
"}",
"var",
"wyMax",
"=",
"later",
".",
"wy",
".",
"extent",
"(",
"year",
")",
"[",
"1",
"]",
",",
"wyEnd",
"=",
"later",
".",
"wy",
".",
"end",
"(",
"year",
")",
";",
"val",
"=",
"val",
">",
"wyMax",
"?",
"wyMax",
":",
"val",
"||",
"wyMax",
";",
"return",
"later",
".",
"wy",
".",
"end",
"(",
"later",
".",
"date",
".",
"next",
"(",
"later",
".",
"Y",
".",
"val",
"(",
"wyEnd",
")",
",",
"later",
".",
"M",
".",
"val",
"(",
"wyEnd",
")",
",",
"later",
".",
"D",
".",
"val",
"(",
"wyEnd",
")",
"+",
"7",
"*",
"(",
"val",
"-",
"1",
")",
")",
")",
";",
"}"
] |
Returns the end of the previous instance of the ISO week value indicated.
@param {Date} d: The starting date
@param {int} val: The desired value, must be within extent
|
[
"Returns",
"the",
"end",
"of",
"the",
"previous",
"instance",
"of",
"the",
"ISO",
"week",
"value",
"indicated",
"."
] |
c5b45ef076d7a2c175c27427e5af22b29a0cc241
|
https://github.com/bunkat/later/blob/c5b45ef076d7a2c175c27427e5af22b29a0cc241/src/constraint/weekofyear.js#L130-L149
|
|
15,525
|
bunkat/later
|
src/constraint/dayofweekcount.js
|
function(d) {
return d.dc || (d.dc = Math.floor((later.D.val(d)-1)/7)+1);
}
|
javascript
|
function(d) {
return d.dc || (d.dc = Math.floor((later.D.val(d)-1)/7)+1);
}
|
[
"function",
"(",
"d",
")",
"{",
"return",
"d",
".",
"dc",
"||",
"(",
"d",
".",
"dc",
"=",
"Math",
".",
"floor",
"(",
"(",
"later",
".",
"D",
".",
"val",
"(",
"d",
")",
"-",
"1",
")",
"/",
"7",
")",
"+",
"1",
")",
";",
"}"
] |
The day of week count value of the specified date.
@param {Date} d: The date to calculate the value of
|
[
"The",
"day",
"of",
"week",
"count",
"value",
"of",
"the",
"specified",
"date",
"."
] |
c5b45ef076d7a2c175c27427e5af22b29a0cc241
|
https://github.com/bunkat/later/blob/c5b45ef076d7a2c175c27427e5af22b29a0cc241/src/constraint/dayofweekcount.js#L30-L32
|
|
15,526
|
bunkat/later
|
src/constraint/dayofweekcount.js
|
function(d) {
return d.dcExtent || (d.dcExtent = [1, Math.ceil(later.D.extent(d)[1] /7)]);
}
|
javascript
|
function(d) {
return d.dcExtent || (d.dcExtent = [1, Math.ceil(later.D.extent(d)[1] /7)]);
}
|
[
"function",
"(",
"d",
")",
"{",
"return",
"d",
".",
"dcExtent",
"||",
"(",
"d",
".",
"dcExtent",
"=",
"[",
"1",
",",
"Math",
".",
"ceil",
"(",
"later",
".",
"D",
".",
"extent",
"(",
"d",
")",
"[",
"1",
"]",
"/",
"7",
")",
"]",
")",
";",
"}"
] |
The minimum and maximum valid day values of the month specified.
Zero to specify the last day of week count of the month.
@param {Date} d: The date indicating the month to find the extent of
|
[
"The",
"minimum",
"and",
"maximum",
"valid",
"day",
"values",
"of",
"the",
"month",
"specified",
".",
"Zero",
"to",
"specify",
"the",
"last",
"day",
"of",
"week",
"count",
"of",
"the",
"month",
"."
] |
c5b45ef076d7a2c175c27427e5af22b29a0cc241
|
https://github.com/bunkat/later/blob/c5b45ef076d7a2c175c27427e5af22b29a0cc241/src/constraint/dayofweekcount.js#L51-L53
|
|
15,527
|
bunkat/later
|
src/constraint/dayofweekcount.js
|
function(d) {
return d.dcStart || (d.dcStart =
later.date.next(
later.Y.val(d),
later.M.val(d),
Math.max(1, ((later.dc.val(d) - 1) * 7) + 1 || 1)));
}
|
javascript
|
function(d) {
return d.dcStart || (d.dcStart =
later.date.next(
later.Y.val(d),
later.M.val(d),
Math.max(1, ((later.dc.val(d) - 1) * 7) + 1 || 1)));
}
|
[
"function",
"(",
"d",
")",
"{",
"return",
"d",
".",
"dcStart",
"||",
"(",
"d",
".",
"dcStart",
"=",
"later",
".",
"date",
".",
"next",
"(",
"later",
".",
"Y",
".",
"val",
"(",
"d",
")",
",",
"later",
".",
"M",
".",
"val",
"(",
"d",
")",
",",
"Math",
".",
"max",
"(",
"1",
",",
"(",
"(",
"later",
".",
"dc",
".",
"val",
"(",
"d",
")",
"-",
"1",
")",
"*",
"7",
")",
"+",
"1",
"||",
"1",
")",
")",
")",
";",
"}"
] |
The first day of the month with the same day of week count as the date
specified.
@param {Date} d: The specified date
|
[
"The",
"first",
"day",
"of",
"the",
"month",
"with",
"the",
"same",
"day",
"of",
"week",
"count",
"as",
"the",
"date",
"specified",
"."
] |
c5b45ef076d7a2c175c27427e5af22b29a0cc241
|
https://github.com/bunkat/later/blob/c5b45ef076d7a2c175c27427e5af22b29a0cc241/src/constraint/dayofweekcount.js#L61-L67
|
|
15,528
|
bunkat/later
|
src/constraint/dayofweekcount.js
|
function(d) {
return d.dcEnd || (d.dcEnd =
later.date.prev(
later.Y.val(d),
later.M.val(d),
Math.min(later.dc.val(d) * 7, later.D.extent(d)[1])));
}
|
javascript
|
function(d) {
return d.dcEnd || (d.dcEnd =
later.date.prev(
later.Y.val(d),
later.M.val(d),
Math.min(later.dc.val(d) * 7, later.D.extent(d)[1])));
}
|
[
"function",
"(",
"d",
")",
"{",
"return",
"d",
".",
"dcEnd",
"||",
"(",
"d",
".",
"dcEnd",
"=",
"later",
".",
"date",
".",
"prev",
"(",
"later",
".",
"Y",
".",
"val",
"(",
"d",
")",
",",
"later",
".",
"M",
".",
"val",
"(",
"d",
")",
",",
"Math",
".",
"min",
"(",
"later",
".",
"dc",
".",
"val",
"(",
"d",
")",
"*",
"7",
",",
"later",
".",
"D",
".",
"extent",
"(",
"d",
")",
"[",
"1",
"]",
")",
")",
")",
";",
"}"
] |
The last day of the month with the same day of week count as the date
specified.
@param {Date} d: The specified date
|
[
"The",
"last",
"day",
"of",
"the",
"month",
"with",
"the",
"same",
"day",
"of",
"week",
"count",
"as",
"the",
"date",
"specified",
"."
] |
c5b45ef076d7a2c175c27427e5af22b29a0cc241
|
https://github.com/bunkat/later/blob/c5b45ef076d7a2c175c27427e5af22b29a0cc241/src/constraint/dayofweekcount.js#L75-L81
|
|
15,529
|
bunkat/later
|
src/constraint/dayofweekcount.js
|
function(d, val) {
val = val > later.dc.extent(d)[1] ? 1 : val;
var month = later.date.nextRollover(d, val, later.dc, later.M),
dcMax = later.dc.extent(month)[1];
val = val > dcMax ? 1 : val;
var next = later.date.next(
later.Y.val(month),
later.M.val(month),
val === 0 ? later.D.extent(month)[1] - 6 : 1 + (7 * (val - 1))
);
if(next.getTime() <= d.getTime()) {
month = later.M.next(d, later.M.val(d)+1);
return later.date.next(
later.Y.val(month),
later.M.val(month),
val === 0 ? later.D.extent(month)[1] - 6 : 1 + (7 * (val - 1))
);
}
return next;
}
|
javascript
|
function(d, val) {
val = val > later.dc.extent(d)[1] ? 1 : val;
var month = later.date.nextRollover(d, val, later.dc, later.M),
dcMax = later.dc.extent(month)[1];
val = val > dcMax ? 1 : val;
var next = later.date.next(
later.Y.val(month),
later.M.val(month),
val === 0 ? later.D.extent(month)[1] - 6 : 1 + (7 * (val - 1))
);
if(next.getTime() <= d.getTime()) {
month = later.M.next(d, later.M.val(d)+1);
return later.date.next(
later.Y.val(month),
later.M.val(month),
val === 0 ? later.D.extent(month)[1] - 6 : 1 + (7 * (val - 1))
);
}
return next;
}
|
[
"function",
"(",
"d",
",",
"val",
")",
"{",
"val",
"=",
"val",
">",
"later",
".",
"dc",
".",
"extent",
"(",
"d",
")",
"[",
"1",
"]",
"?",
"1",
":",
"val",
";",
"var",
"month",
"=",
"later",
".",
"date",
".",
"nextRollover",
"(",
"d",
",",
"val",
",",
"later",
".",
"dc",
",",
"later",
".",
"M",
")",
",",
"dcMax",
"=",
"later",
".",
"dc",
".",
"extent",
"(",
"month",
")",
"[",
"1",
"]",
";",
"val",
"=",
"val",
">",
"dcMax",
"?",
"1",
":",
"val",
";",
"var",
"next",
"=",
"later",
".",
"date",
".",
"next",
"(",
"later",
".",
"Y",
".",
"val",
"(",
"month",
")",
",",
"later",
".",
"M",
".",
"val",
"(",
"month",
")",
",",
"val",
"===",
"0",
"?",
"later",
".",
"D",
".",
"extent",
"(",
"month",
")",
"[",
"1",
"]",
"-",
"6",
":",
"1",
"+",
"(",
"7",
"*",
"(",
"val",
"-",
"1",
")",
")",
")",
";",
"if",
"(",
"next",
".",
"getTime",
"(",
")",
"<=",
"d",
".",
"getTime",
"(",
")",
")",
"{",
"month",
"=",
"later",
".",
"M",
".",
"next",
"(",
"d",
",",
"later",
".",
"M",
".",
"val",
"(",
"d",
")",
"+",
"1",
")",
";",
"return",
"later",
".",
"date",
".",
"next",
"(",
"later",
".",
"Y",
".",
"val",
"(",
"month",
")",
",",
"later",
".",
"M",
".",
"val",
"(",
"month",
")",
",",
"val",
"===",
"0",
"?",
"later",
".",
"D",
".",
"extent",
"(",
"month",
")",
"[",
"1",
"]",
"-",
"6",
":",
"1",
"+",
"(",
"7",
"*",
"(",
"val",
"-",
"1",
")",
")",
")",
";",
"}",
"return",
"next",
";",
"}"
] |
Returns the next earliest date with the day of week count specified.
@param {Date} d: The starting date
@param {int} val: The desired value, must be within extent
|
[
"Returns",
"the",
"next",
"earliest",
"date",
"with",
"the",
"day",
"of",
"week",
"count",
"specified",
"."
] |
c5b45ef076d7a2c175c27427e5af22b29a0cc241
|
https://github.com/bunkat/later/blob/c5b45ef076d7a2c175c27427e5af22b29a0cc241/src/constraint/dayofweekcount.js#L89-L113
|
|
15,530
|
bunkat/later
|
src/constraint/dayofweekcount.js
|
function(d, val) {
var month = later.date.prevRollover(d, val, later.dc, later.M),
dcMax = later.dc.extent(month)[1];
val = val > dcMax ? dcMax : val || dcMax;
return later.dc.end(later.date.prev(
later.Y.val(month),
later.M.val(month),
1 + (7 * (val - 1))
));
}
|
javascript
|
function(d, val) {
var month = later.date.prevRollover(d, val, later.dc, later.M),
dcMax = later.dc.extent(month)[1];
val = val > dcMax ? dcMax : val || dcMax;
return later.dc.end(later.date.prev(
later.Y.val(month),
later.M.val(month),
1 + (7 * (val - 1))
));
}
|
[
"function",
"(",
"d",
",",
"val",
")",
"{",
"var",
"month",
"=",
"later",
".",
"date",
".",
"prevRollover",
"(",
"d",
",",
"val",
",",
"later",
".",
"dc",
",",
"later",
".",
"M",
")",
",",
"dcMax",
"=",
"later",
".",
"dc",
".",
"extent",
"(",
"month",
")",
"[",
"1",
"]",
";",
"val",
"=",
"val",
">",
"dcMax",
"?",
"dcMax",
":",
"val",
"||",
"dcMax",
";",
"return",
"later",
".",
"dc",
".",
"end",
"(",
"later",
".",
"date",
".",
"prev",
"(",
"later",
".",
"Y",
".",
"val",
"(",
"month",
")",
",",
"later",
".",
"M",
".",
"val",
"(",
"month",
")",
",",
"1",
"+",
"(",
"7",
"*",
"(",
"val",
"-",
"1",
")",
")",
")",
")",
";",
"}"
] |
Returns the closest previous date with the day of week count specified.
@param {Date} d: The starting date
@param {int} val: The desired value, must be within extent
|
[
"Returns",
"the",
"closest",
"previous",
"date",
"with",
"the",
"day",
"of",
"week",
"count",
"specified",
"."
] |
c5b45ef076d7a2c175c27427e5af22b29a0cc241
|
https://github.com/bunkat/later/blob/c5b45ef076d7a2c175c27427e5af22b29a0cc241/src/constraint/dayofweekcount.js#L121-L132
|
|
15,531
|
bunkat/later
|
src/constraint/weekofmonth.js
|
function(d) {
return d.wm || (d.wm =
(later.D.val(d) +
(later.dw.val(later.M.start(d)) - 1) + (7 - later.dw.val(d))) / 7);
}
|
javascript
|
function(d) {
return d.wm || (d.wm =
(later.D.val(d) +
(later.dw.val(later.M.start(d)) - 1) + (7 - later.dw.val(d))) / 7);
}
|
[
"function",
"(",
"d",
")",
"{",
"return",
"d",
".",
"wm",
"||",
"(",
"d",
".",
"wm",
"=",
"(",
"later",
".",
"D",
".",
"val",
"(",
"d",
")",
"+",
"(",
"later",
".",
"dw",
".",
"val",
"(",
"later",
".",
"M",
".",
"start",
"(",
"d",
")",
")",
"-",
"1",
")",
"+",
"(",
"7",
"-",
"later",
".",
"dw",
".",
"val",
"(",
"d",
")",
")",
")",
"/",
"7",
")",
";",
"}"
] |
The week of month value of the specified date.
@param {Date} d: The date to calculate the value of
|
[
"The",
"week",
"of",
"month",
"value",
"of",
"the",
"specified",
"date",
"."
] |
c5b45ef076d7a2c175c27427e5af22b29a0cc241
|
https://github.com/bunkat/later/blob/c5b45ef076d7a2c175c27427e5af22b29a0cc241/src/constraint/weekofmonth.js#L31-L35
|
|
15,532
|
bunkat/later
|
src/constraint/weekofmonth.js
|
function(d) {
return d.wmExtent || (d.wmExtent = [1,
(later.D.extent(d)[1] + (later.dw.val(later.M.start(d)) - 1) +
(7 - later.dw.val(later.M.end(d)))) / 7]);
}
|
javascript
|
function(d) {
return d.wmExtent || (d.wmExtent = [1,
(later.D.extent(d)[1] + (later.dw.val(later.M.start(d)) - 1) +
(7 - later.dw.val(later.M.end(d)))) / 7]);
}
|
[
"function",
"(",
"d",
")",
"{",
"return",
"d",
".",
"wmExtent",
"||",
"(",
"d",
".",
"wmExtent",
"=",
"[",
"1",
",",
"(",
"later",
".",
"D",
".",
"extent",
"(",
"d",
")",
"[",
"1",
"]",
"+",
"(",
"later",
".",
"dw",
".",
"val",
"(",
"later",
".",
"M",
".",
"start",
"(",
"d",
")",
")",
"-",
"1",
")",
"+",
"(",
"7",
"-",
"later",
".",
"dw",
".",
"val",
"(",
"later",
".",
"M",
".",
"end",
"(",
"d",
")",
")",
")",
")",
"/",
"7",
"]",
")",
";",
"}"
] |
The minimum and maximum valid week of month values for the month indicated.
Zero indicates the last week in the month.
@param {Date} d: The date indicating the month to find values for
|
[
"The",
"minimum",
"and",
"maximum",
"valid",
"week",
"of",
"month",
"values",
"for",
"the",
"month",
"indicated",
".",
"Zero",
"indicates",
"the",
"last",
"week",
"in",
"the",
"month",
"."
] |
c5b45ef076d7a2c175c27427e5af22b29a0cc241
|
https://github.com/bunkat/later/blob/c5b45ef076d7a2c175c27427e5af22b29a0cc241/src/constraint/weekofmonth.js#L53-L57
|
|
15,533
|
bunkat/later
|
src/constraint/weekofmonth.js
|
function(d) {
return d.wmStart || (d.wmStart = later.date.next(
later.Y.val(d),
later.M.val(d),
Math.max(later.D.val(d) - later.dw.val(d) + 1, 1)));
}
|
javascript
|
function(d) {
return d.wmStart || (d.wmStart = later.date.next(
later.Y.val(d),
later.M.val(d),
Math.max(later.D.val(d) - later.dw.val(d) + 1, 1)));
}
|
[
"function",
"(",
"d",
")",
"{",
"return",
"d",
".",
"wmStart",
"||",
"(",
"d",
".",
"wmStart",
"=",
"later",
".",
"date",
".",
"next",
"(",
"later",
".",
"Y",
".",
"val",
"(",
"d",
")",
",",
"later",
".",
"M",
".",
"val",
"(",
"d",
")",
",",
"Math",
".",
"max",
"(",
"later",
".",
"D",
".",
"val",
"(",
"d",
")",
"-",
"later",
".",
"dw",
".",
"val",
"(",
"d",
")",
"+",
"1",
",",
"1",
")",
")",
")",
";",
"}"
] |
The start of the week of the specified date.
@param {Date} d: The specified date
|
[
"The",
"start",
"of",
"the",
"week",
"of",
"the",
"specified",
"date",
"."
] |
c5b45ef076d7a2c175c27427e5af22b29a0cc241
|
https://github.com/bunkat/later/blob/c5b45ef076d7a2c175c27427e5af22b29a0cc241/src/constraint/weekofmonth.js#L64-L69
|
|
15,534
|
bunkat/later
|
src/constraint/weekofmonth.js
|
function(d) {
return d.wmEnd || (d.wmEnd = later.date.prev(
later.Y.val(d),
later.M.val(d),
Math.min(later.D.val(d) + (7 - later.dw.val(d)), later.D.extent(d)[1])));
}
|
javascript
|
function(d) {
return d.wmEnd || (d.wmEnd = later.date.prev(
later.Y.val(d),
later.M.val(d),
Math.min(later.D.val(d) + (7 - later.dw.val(d)), later.D.extent(d)[1])));
}
|
[
"function",
"(",
"d",
")",
"{",
"return",
"d",
".",
"wmEnd",
"||",
"(",
"d",
".",
"wmEnd",
"=",
"later",
".",
"date",
".",
"prev",
"(",
"later",
".",
"Y",
".",
"val",
"(",
"d",
")",
",",
"later",
".",
"M",
".",
"val",
"(",
"d",
")",
",",
"Math",
".",
"min",
"(",
"later",
".",
"D",
".",
"val",
"(",
"d",
")",
"+",
"(",
"7",
"-",
"later",
".",
"dw",
".",
"val",
"(",
"d",
")",
")",
",",
"later",
".",
"D",
".",
"extent",
"(",
"d",
")",
"[",
"1",
"]",
")",
")",
")",
";",
"}"
] |
The end of the week of the specified date.
@param {Date} d: The specified date
|
[
"The",
"end",
"of",
"the",
"week",
"of",
"the",
"specified",
"date",
"."
] |
c5b45ef076d7a2c175c27427e5af22b29a0cc241
|
https://github.com/bunkat/later/blob/c5b45ef076d7a2c175c27427e5af22b29a0cc241/src/constraint/weekofmonth.js#L76-L81
|
|
15,535
|
bunkat/later
|
src/constraint/weekofmonth.js
|
function(d, val) {
val = val > later.wm.extent(d)[1] ? 1 : val;
var month = later.date.nextRollover(d, val, later.wm, later.M),
wmMax = later.wm.extent(month)[1];
val = val > wmMax ? 1 : val || wmMax;
// jump to the Sunday of the desired week, set to 1st of month for week 1
return later.date.next(
later.Y.val(month),
later.M.val(month),
Math.max(1, (val-1) * 7 - (later.dw.val(month)-2)));
}
|
javascript
|
function(d, val) {
val = val > later.wm.extent(d)[1] ? 1 : val;
var month = later.date.nextRollover(d, val, later.wm, later.M),
wmMax = later.wm.extent(month)[1];
val = val > wmMax ? 1 : val || wmMax;
// jump to the Sunday of the desired week, set to 1st of month for week 1
return later.date.next(
later.Y.val(month),
later.M.val(month),
Math.max(1, (val-1) * 7 - (later.dw.val(month)-2)));
}
|
[
"function",
"(",
"d",
",",
"val",
")",
"{",
"val",
"=",
"val",
">",
"later",
".",
"wm",
".",
"extent",
"(",
"d",
")",
"[",
"1",
"]",
"?",
"1",
":",
"val",
";",
"var",
"month",
"=",
"later",
".",
"date",
".",
"nextRollover",
"(",
"d",
",",
"val",
",",
"later",
".",
"wm",
",",
"later",
".",
"M",
")",
",",
"wmMax",
"=",
"later",
".",
"wm",
".",
"extent",
"(",
"month",
")",
"[",
"1",
"]",
";",
"val",
"=",
"val",
">",
"wmMax",
"?",
"1",
":",
"val",
"||",
"wmMax",
";",
"// jump to the Sunday of the desired week, set to 1st of month for week 1",
"return",
"later",
".",
"date",
".",
"next",
"(",
"later",
".",
"Y",
".",
"val",
"(",
"month",
")",
",",
"later",
".",
"M",
".",
"val",
"(",
"month",
")",
",",
"Math",
".",
"max",
"(",
"1",
",",
"(",
"val",
"-",
"1",
")",
"*",
"7",
"-",
"(",
"later",
".",
"dw",
".",
"val",
"(",
"month",
")",
"-",
"2",
")",
")",
")",
";",
"}"
] |
Returns the start of the next instance of the week value indicated. Returns
the first day of the next month if val is greater than the number of
days in the following month.
@param {Date} d: The starting date
@param {int} val: The desired value, must be within extent
|
[
"Returns",
"the",
"start",
"of",
"the",
"next",
"instance",
"of",
"the",
"week",
"value",
"indicated",
".",
"Returns",
"the",
"first",
"day",
"of",
"the",
"next",
"month",
"if",
"val",
"is",
"greater",
"than",
"the",
"number",
"of",
"days",
"in",
"the",
"following",
"month",
"."
] |
c5b45ef076d7a2c175c27427e5af22b29a0cc241
|
https://github.com/bunkat/later/blob/c5b45ef076d7a2c175c27427e5af22b29a0cc241/src/constraint/weekofmonth.js#L91-L104
|
|
15,536
|
bunkat/later
|
src/parse/recur.js
|
function (id, vals) {
var custom = later.modifier[id];
if(!custom) throw new Error('Custom modifier ' + id + ' not recognized!');
modifier = id;
values = arguments[1] instanceof Array ? arguments[1] : [arguments[1]];
return this;
}
|
javascript
|
function (id, vals) {
var custom = later.modifier[id];
if(!custom) throw new Error('Custom modifier ' + id + ' not recognized!');
modifier = id;
values = arguments[1] instanceof Array ? arguments[1] : [arguments[1]];
return this;
}
|
[
"function",
"(",
"id",
",",
"vals",
")",
"{",
"var",
"custom",
"=",
"later",
".",
"modifier",
"[",
"id",
"]",
";",
"if",
"(",
"!",
"custom",
")",
"throw",
"new",
"Error",
"(",
"'Custom modifier '",
"+",
"id",
"+",
"' not recognized!'",
")",
";",
"modifier",
"=",
"id",
";",
"values",
"=",
"arguments",
"[",
"1",
"]",
"instanceof",
"Array",
"?",
"arguments",
"[",
"1",
"]",
":",
"[",
"arguments",
"[",
"1",
"]",
"]",
";",
"return",
"this",
";",
"}"
] |
Custom modifier.
recur().on(2011, 2012, 2013).custom('partOfDay');
@api public
|
[
"Custom",
"modifier",
"."
] |
c5b45ef076d7a2c175c27427e5af22b29a0cc241
|
https://github.com/bunkat/later/blob/c5b45ef076d7a2c175c27427e5af22b29a0cc241/src/parse/recur.js#L418-L425
|
|
15,537
|
bunkat/later
|
src/parse/recur.js
|
function (id) {
var custom = later[id];
if(!custom) throw new Error('Custom time period ' + id + ' not recognized!');
add(id, custom.extent(new Date())[0], custom.extent(new Date())[1]);
return this;
}
|
javascript
|
function (id) {
var custom = later[id];
if(!custom) throw new Error('Custom time period ' + id + ' not recognized!');
add(id, custom.extent(new Date())[0], custom.extent(new Date())[1]);
return this;
}
|
[
"function",
"(",
"id",
")",
"{",
"var",
"custom",
"=",
"later",
"[",
"id",
"]",
";",
"if",
"(",
"!",
"custom",
")",
"throw",
"new",
"Error",
"(",
"'Custom time period '",
"+",
"id",
"+",
"' not recognized!'",
")",
";",
"add",
"(",
"id",
",",
"custom",
".",
"extent",
"(",
"new",
"Date",
"(",
")",
")",
"[",
"0",
"]",
",",
"custom",
".",
"extent",
"(",
"new",
"Date",
"(",
")",
")",
"[",
"1",
"]",
")",
";",
"return",
"this",
";",
"}"
] |
Custom time period.
recur().on(2011, 2012, 2013).customPeriod('partOfDay');
@api public
|
[
"Custom",
"time",
"period",
"."
] |
c5b45ef076d7a2c175c27427e5af22b29a0cc241
|
https://github.com/bunkat/later/blob/c5b45ef076d7a2c175c27427e5af22b29a0cc241/src/parse/recur.js#L434-L440
|
|
15,538
|
bunkat/later
|
src/constraint/second.js
|
function(d) {
return d.s || (d.s = later.date.getSec.call(d));
}
|
javascript
|
function(d) {
return d.s || (d.s = later.date.getSec.call(d));
}
|
[
"function",
"(",
"d",
")",
"{",
"return",
"d",
".",
"s",
"||",
"(",
"d",
".",
"s",
"=",
"later",
".",
"date",
".",
"getSec",
".",
"call",
"(",
"d",
")",
")",
";",
"}"
] |
The second value of the specified date.
@param {Date} d: The date to calculate the value of
|
[
"The",
"second",
"value",
"of",
"the",
"specified",
"date",
"."
] |
c5b45ef076d7a2c175c27427e5af22b29a0cc241
|
https://github.com/bunkat/later/blob/c5b45ef076d7a2c175c27427e5af22b29a0cc241/src/constraint/second.js#L29-L31
|
|
15,539
|
bunkat/later
|
src/constraint/dayofyear.js
|
function(d) {
var year = later.Y.val(d);
// shortcut on finding leap years since this function gets called a lot
// works between 1901 and 2099
return d.dyExtent || (d.dyExtent = [1, year % 4 ? 365 : 366]);
}
|
javascript
|
function(d) {
var year = later.Y.val(d);
// shortcut on finding leap years since this function gets called a lot
// works between 1901 and 2099
return d.dyExtent || (d.dyExtent = [1, year % 4 ? 365 : 366]);
}
|
[
"function",
"(",
"d",
")",
"{",
"var",
"year",
"=",
"later",
".",
"Y",
".",
"val",
"(",
"d",
")",
";",
"// shortcut on finding leap years since this function gets called a lot",
"// works between 1901 and 2099",
"return",
"d",
".",
"dyExtent",
"||",
"(",
"d",
".",
"dyExtent",
"=",
"[",
"1",
",",
"year",
"%",
"4",
"?",
"365",
":",
"366",
"]",
")",
";",
"}"
] |
The minimum and maximum valid day of year values of the month specified.
Zero indicates the last day of the year.
@param {Date} d: The date indicating the month to find the extent of
|
[
"The",
"minimum",
"and",
"maximum",
"valid",
"day",
"of",
"year",
"values",
"of",
"the",
"month",
"specified",
".",
"Zero",
"indicates",
"the",
"last",
"day",
"of",
"the",
"year",
"."
] |
c5b45ef076d7a2c175c27427e5af22b29a0cc241
|
https://github.com/bunkat/later/blob/c5b45ef076d7a2c175c27427e5af22b29a0cc241/src/constraint/dayofyear.js#L50-L56
|
|
15,540
|
bunkat/later
|
src/constraint/minute.js
|
function(d, val) {
var m = later.m.val(d),
s = later.s.val(d),
inc = val > 59 ? 60-m : (val <= m ? (60-m) + val : val-m),
next = new Date(d.getTime() + (inc * later.MIN) - (s * later.SEC));
// correct for passing over a daylight savings boundry
if(!later.date.isUTC && next.getTime() <= d.getTime()) {
next = new Date(d.getTime() + ((inc + 120) * later.MIN) - (s * later.SEC));
}
return next;
}
|
javascript
|
function(d, val) {
var m = later.m.val(d),
s = later.s.val(d),
inc = val > 59 ? 60-m : (val <= m ? (60-m) + val : val-m),
next = new Date(d.getTime() + (inc * later.MIN) - (s * later.SEC));
// correct for passing over a daylight savings boundry
if(!later.date.isUTC && next.getTime() <= d.getTime()) {
next = new Date(d.getTime() + ((inc + 120) * later.MIN) - (s * later.SEC));
}
return next;
}
|
[
"function",
"(",
"d",
",",
"val",
")",
"{",
"var",
"m",
"=",
"later",
".",
"m",
".",
"val",
"(",
"d",
")",
",",
"s",
"=",
"later",
".",
"s",
".",
"val",
"(",
"d",
")",
",",
"inc",
"=",
"val",
">",
"59",
"?",
"60",
"-",
"m",
":",
"(",
"val",
"<=",
"m",
"?",
"(",
"60",
"-",
"m",
")",
"+",
"val",
":",
"val",
"-",
"m",
")",
",",
"next",
"=",
"new",
"Date",
"(",
"d",
".",
"getTime",
"(",
")",
"+",
"(",
"inc",
"*",
"later",
".",
"MIN",
")",
"-",
"(",
"s",
"*",
"later",
".",
"SEC",
")",
")",
";",
"// correct for passing over a daylight savings boundry",
"if",
"(",
"!",
"later",
".",
"date",
".",
"isUTC",
"&&",
"next",
".",
"getTime",
"(",
")",
"<=",
"d",
".",
"getTime",
"(",
")",
")",
"{",
"next",
"=",
"new",
"Date",
"(",
"d",
".",
"getTime",
"(",
")",
"+",
"(",
"(",
"inc",
"+",
"120",
")",
"*",
"later",
".",
"MIN",
")",
"-",
"(",
"s",
"*",
"later",
".",
"SEC",
")",
")",
";",
"}",
"return",
"next",
";",
"}"
] |
Returns the start of the next instance of the minute value indicated.
@param {Date} d: The starting date
@param {int} val: The desired value, must be within extent
|
[
"Returns",
"the",
"start",
"of",
"the",
"next",
"instance",
"of",
"the",
"minute",
"value",
"indicated",
"."
] |
c5b45ef076d7a2c175c27427e5af22b29a0cc241
|
https://github.com/bunkat/later/blob/c5b45ef076d7a2c175c27427e5af22b29a0cc241/src/constraint/minute.js#L76-L88
|
|
15,541
|
bunkat/later
|
src/core/schedule.js
|
calcEnd
|
function calcEnd(dir, schedArr, startsArr, startDate, maxEndDate) {
var compare = compareFn(dir), result;
for(var i = 0, len = schedArr.length; i < len; i++) {
var start = startsArr[i];
if(start && start.getTime() === startDate.getTime()) {
var end = schedArr[i].end(dir, start);
// if the end date is past the maxEndDate, just return the maxEndDate
if(maxEndDate && (!end || compare(end, maxEndDate))) {
return maxEndDate;
}
// otherwise, return the maximum end date that was calculated
if(!result || compare(end, result)) {
result = end;
}
}
}
return result;
}
|
javascript
|
function calcEnd(dir, schedArr, startsArr, startDate, maxEndDate) {
var compare = compareFn(dir), result;
for(var i = 0, len = schedArr.length; i < len; i++) {
var start = startsArr[i];
if(start && start.getTime() === startDate.getTime()) {
var end = schedArr[i].end(dir, start);
// if the end date is past the maxEndDate, just return the maxEndDate
if(maxEndDate && (!end || compare(end, maxEndDate))) {
return maxEndDate;
}
// otherwise, return the maximum end date that was calculated
if(!result || compare(end, result)) {
result = end;
}
}
}
return result;
}
|
[
"function",
"calcEnd",
"(",
"dir",
",",
"schedArr",
",",
"startsArr",
",",
"startDate",
",",
"maxEndDate",
")",
"{",
"var",
"compare",
"=",
"compareFn",
"(",
"dir",
")",
",",
"result",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"schedArr",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"var",
"start",
"=",
"startsArr",
"[",
"i",
"]",
";",
"if",
"(",
"start",
"&&",
"start",
".",
"getTime",
"(",
")",
"===",
"startDate",
".",
"getTime",
"(",
")",
")",
"{",
"var",
"end",
"=",
"schedArr",
"[",
"i",
"]",
".",
"end",
"(",
"dir",
",",
"start",
")",
";",
"// if the end date is past the maxEndDate, just return the maxEndDate",
"if",
"(",
"maxEndDate",
"&&",
"(",
"!",
"end",
"||",
"compare",
"(",
"end",
",",
"maxEndDate",
")",
")",
")",
"{",
"return",
"maxEndDate",
";",
"}",
"// otherwise, return the maximum end date that was calculated",
"if",
"(",
"!",
"result",
"||",
"compare",
"(",
"end",
",",
"result",
")",
")",
"{",
"result",
"=",
"end",
";",
"}",
"}",
"}",
"return",
"result",
";",
"}"
] |
Calculates the next invalid date for a particular schedules starting from
the specified valid start date.
@param {String} dir: The direction to use, either 'next' or 'prev'
@param {Array} schedArr: The set of compiled schedules to use
@param {Array} startsArr: The set of cached start dates for the schedules
@param {Date} startDate: The valid date for which the end date will be found
@param {Date} maxEndDate: The latested possible end date or null for none
|
[
"Calculates",
"the",
"next",
"invalid",
"date",
"for",
"a",
"particular",
"schedules",
"starting",
"from",
"the",
"specified",
"valid",
"start",
"date",
"."
] |
c5b45ef076d7a2c175c27427e5af22b29a0cc241
|
https://github.com/bunkat/later/blob/c5b45ef076d7a2c175c27427e5af22b29a0cc241/src/core/schedule.js#L324-L346
|
15,542
|
bunkat/later
|
src/parse/cron.js
|
cloneSchedule
|
function cloneSchedule(sched) {
var clone = {}, field;
for(field in sched) {
if (field !== 'dc' && field !== 'd') {
clone[field] = sched[field].slice(0);
}
}
return clone;
}
|
javascript
|
function cloneSchedule(sched) {
var clone = {}, field;
for(field in sched) {
if (field !== 'dc' && field !== 'd') {
clone[field] = sched[field].slice(0);
}
}
return clone;
}
|
[
"function",
"cloneSchedule",
"(",
"sched",
")",
"{",
"var",
"clone",
"=",
"{",
"}",
",",
"field",
";",
"for",
"(",
"field",
"in",
"sched",
")",
"{",
"if",
"(",
"field",
"!==",
"'dc'",
"&&",
"field",
"!==",
"'d'",
")",
"{",
"clone",
"[",
"field",
"]",
"=",
"sched",
"[",
"field",
"]",
".",
"slice",
"(",
"0",
")",
";",
"}",
"}",
"return",
"clone",
";",
"}"
] |
Returns a deep clone of a schedule skipping any day of week
constraints.
@param {Sched} sched: The schedule that will be cloned
|
[
"Returns",
"a",
"deep",
"clone",
"of",
"a",
"schedule",
"skipping",
"any",
"day",
"of",
"week",
"constraints",
"."
] |
c5b45ef076d7a2c175c27427e5af22b29a0cc241
|
https://github.com/bunkat/later/blob/c5b45ef076d7a2c175c27427e5af22b29a0cc241/src/parse/cron.js#L71-L81
|
15,543
|
bunkat/later
|
src/parse/cron.js
|
parse
|
function parse(item, s, name, min, max, offset) {
var value,
split,
schedules = s.schedules,
curSched = schedules[schedules.length-1];
// L just means min - 1 (this also makes it work for any field)
if (item === 'L') {
item = min - 1;
}
// parse x
if ((value = getValue(item, offset, max)) !== null) {
add(curSched, name, value, value);
}
// parse xW
else if ((value = getValue(item.replace('W', ''), offset, max)) !== null) {
addWeekday(s, curSched, value);
}
// parse xL
else if ((value = getValue(item.replace('L', ''), offset, max)) !== null) {
addHash(schedules, curSched, value, min-1);
}
// parse x#y
else if ((split = item.split('#')).length === 2) {
value = getValue(split[0], offset, max);
addHash(schedules, curSched, value, getValue(split[1]));
}
// parse x-y or x-y/z or */z or 0/z
else {
addRange(item, curSched, name, min, max, offset);
}
}
|
javascript
|
function parse(item, s, name, min, max, offset) {
var value,
split,
schedules = s.schedules,
curSched = schedules[schedules.length-1];
// L just means min - 1 (this also makes it work for any field)
if (item === 'L') {
item = min - 1;
}
// parse x
if ((value = getValue(item, offset, max)) !== null) {
add(curSched, name, value, value);
}
// parse xW
else if ((value = getValue(item.replace('W', ''), offset, max)) !== null) {
addWeekday(s, curSched, value);
}
// parse xL
else if ((value = getValue(item.replace('L', ''), offset, max)) !== null) {
addHash(schedules, curSched, value, min-1);
}
// parse x#y
else if ((split = item.split('#')).length === 2) {
value = getValue(split[0], offset, max);
addHash(schedules, curSched, value, getValue(split[1]));
}
// parse x-y or x-y/z or */z or 0/z
else {
addRange(item, curSched, name, min, max, offset);
}
}
|
[
"function",
"parse",
"(",
"item",
",",
"s",
",",
"name",
",",
"min",
",",
"max",
",",
"offset",
")",
"{",
"var",
"value",
",",
"split",
",",
"schedules",
"=",
"s",
".",
"schedules",
",",
"curSched",
"=",
"schedules",
"[",
"schedules",
".",
"length",
"-",
"1",
"]",
";",
"// L just means min - 1 (this also makes it work for any field)",
"if",
"(",
"item",
"===",
"'L'",
")",
"{",
"item",
"=",
"min",
"-",
"1",
";",
"}",
"// parse x",
"if",
"(",
"(",
"value",
"=",
"getValue",
"(",
"item",
",",
"offset",
",",
"max",
")",
")",
"!==",
"null",
")",
"{",
"add",
"(",
"curSched",
",",
"name",
",",
"value",
",",
"value",
")",
";",
"}",
"// parse xW",
"else",
"if",
"(",
"(",
"value",
"=",
"getValue",
"(",
"item",
".",
"replace",
"(",
"'W'",
",",
"''",
")",
",",
"offset",
",",
"max",
")",
")",
"!==",
"null",
")",
"{",
"addWeekday",
"(",
"s",
",",
"curSched",
",",
"value",
")",
";",
"}",
"// parse xL",
"else",
"if",
"(",
"(",
"value",
"=",
"getValue",
"(",
"item",
".",
"replace",
"(",
"'L'",
",",
"''",
")",
",",
"offset",
",",
"max",
")",
")",
"!==",
"null",
")",
"{",
"addHash",
"(",
"schedules",
",",
"curSched",
",",
"value",
",",
"min",
"-",
"1",
")",
";",
"}",
"// parse x#y",
"else",
"if",
"(",
"(",
"split",
"=",
"item",
".",
"split",
"(",
"'#'",
")",
")",
".",
"length",
"===",
"2",
")",
"{",
"value",
"=",
"getValue",
"(",
"split",
"[",
"0",
"]",
",",
"offset",
",",
"max",
")",
";",
"addHash",
"(",
"schedules",
",",
"curSched",
",",
"value",
",",
"getValue",
"(",
"split",
"[",
"1",
"]",
")",
")",
";",
"}",
"// parse x-y or x-y/z or */z or 0/z",
"else",
"{",
"addRange",
"(",
"item",
",",
"curSched",
",",
"name",
",",
"min",
",",
"max",
",",
"offset",
")",
";",
"}",
"}"
] |
Parses a particular item within a cron expression.
@param {String} item: The cron expression item to parse
@param {Schedule} s: The existing set of schedules
@param {String} name: The name to use for this constraint
@param {Int} min: The min value for the constraint
@param {Int} max: The max value for the constraint
@param {Int} offset: The offset to apply to the cron value
|
[
"Parses",
"a",
"particular",
"item",
"within",
"a",
"cron",
"expression",
"."
] |
c5b45ef076d7a2c175c27427e5af22b29a0cc241
|
https://github.com/bunkat/later/blob/c5b45ef076d7a2c175c27427e5af22b29a0cc241/src/parse/cron.js#L195-L227
|
15,544
|
Mobius1/Selectr
|
docs/js/plugins.js
|
extend
|
function extend(src, props) {
props = props || {};
var p;
for (p in src) {
if (src.hasOwnProperty(p)) {
if (!props.hasOwnProperty(p)) {
props[p] = src[p];
}
}
}
return props;
}
|
javascript
|
function extend(src, props) {
props = props || {};
var p;
for (p in src) {
if (src.hasOwnProperty(p)) {
if (!props.hasOwnProperty(p)) {
props[p] = src[p];
}
}
}
return props;
}
|
[
"function",
"extend",
"(",
"src",
",",
"props",
")",
"{",
"props",
"=",
"props",
"||",
"{",
"}",
";",
"var",
"p",
";",
"for",
"(",
"p",
"in",
"src",
")",
"{",
"if",
"(",
"src",
".",
"hasOwnProperty",
"(",
"p",
")",
")",
"{",
"if",
"(",
"!",
"props",
".",
"hasOwnProperty",
"(",
"p",
")",
")",
"{",
"props",
"[",
"p",
"]",
"=",
"src",
"[",
"p",
"]",
";",
"}",
"}",
"}",
"return",
"props",
";",
"}"
] |
Merge objects together into the first.
@param {Object} src Source object
@param {Object} obj Object to merge into source object
@return {Object}
|
[
"Merge",
"objects",
"together",
"into",
"the",
"first",
"."
] |
f7e825fc97f95b6489408492ba15e3968fde943b
|
https://github.com/Mobius1/Selectr/blob/f7e825fc97f95b6489408492ba15e3968fde943b/docs/js/plugins.js#L85-L96
|
15,545
|
Mobius1/Selectr
|
docs/js/plugins.js
|
createElement
|
function createElement(name, props) {
var c = document,
d = c.createElement(name);
if (props && "[object Object]" === Object.prototype.toString.call(props)) {
var e;
for (e in props)
if ("html" === e) d.innerHTML = props[e];
else if ("text" === e) {
var f = c.createTextNode(props[e]);
d.appendChild(f);
} else d.setAttribute(e, props[e]);
}
return d;
}
|
javascript
|
function createElement(name, props) {
var c = document,
d = c.createElement(name);
if (props && "[object Object]" === Object.prototype.toString.call(props)) {
var e;
for (e in props)
if ("html" === e) d.innerHTML = props[e];
else if ("text" === e) {
var f = c.createTextNode(props[e]);
d.appendChild(f);
} else d.setAttribute(e, props[e]);
}
return d;
}
|
[
"function",
"createElement",
"(",
"name",
",",
"props",
")",
"{",
"var",
"c",
"=",
"document",
",",
"d",
"=",
"c",
".",
"createElement",
"(",
"name",
")",
";",
"if",
"(",
"props",
"&&",
"\"[object Object]\"",
"===",
"Object",
".",
"prototype",
".",
"toString",
".",
"call",
"(",
"props",
")",
")",
"{",
"var",
"e",
";",
"for",
"(",
"e",
"in",
"props",
")",
"if",
"(",
"\"html\"",
"===",
"e",
")",
"d",
".",
"innerHTML",
"=",
"props",
"[",
"e",
"]",
";",
"else",
"if",
"(",
"\"text\"",
"===",
"e",
")",
"{",
"var",
"f",
"=",
"c",
".",
"createTextNode",
"(",
"props",
"[",
"e",
"]",
")",
";",
"d",
".",
"appendChild",
"(",
"f",
")",
";",
"}",
"else",
"d",
".",
"setAttribute",
"(",
"e",
",",
"props",
"[",
"e",
"]",
")",
";",
"}",
"return",
"d",
";",
"}"
] |
Create new element and apply propertiess and attributes
@param {String} name The new element's nodeName
@param {Object} prop CSS properties and values
@return {Object} The newly create HTMLElement
|
[
"Create",
"new",
"element",
"and",
"apply",
"propertiess",
"and",
"attributes"
] |
f7e825fc97f95b6489408492ba15e3968fde943b
|
https://github.com/Mobius1/Selectr/blob/f7e825fc97f95b6489408492ba15e3968fde943b/docs/js/plugins.js#L104-L117
|
15,546
|
Mobius1/Selectr
|
docs/js/plugins.js
|
style
|
function style(el, obj) {
if ( !obj ) {
return window.getComputedStyle(el);
}
if ("[object Object]" === Object.prototype.toString.call(obj)) {
var s = "";
each(obj, function(prop, val) {
if ( typeof val !== "string" && prop !== "opacity" ) {
val += "px";
}
s += prop + ": " + val + ";";
});
el.style.cssText += s;
}
}
|
javascript
|
function style(el, obj) {
if ( !obj ) {
return window.getComputedStyle(el);
}
if ("[object Object]" === Object.prototype.toString.call(obj)) {
var s = "";
each(obj, function(prop, val) {
if ( typeof val !== "string" && prop !== "opacity" ) {
val += "px";
}
s += prop + ": " + val + ";";
});
el.style.cssText += s;
}
}
|
[
"function",
"style",
"(",
"el",
",",
"obj",
")",
"{",
"if",
"(",
"!",
"obj",
")",
"{",
"return",
"window",
".",
"getComputedStyle",
"(",
"el",
")",
";",
"}",
"if",
"(",
"\"[object Object]\"",
"===",
"Object",
".",
"prototype",
".",
"toString",
".",
"call",
"(",
"obj",
")",
")",
"{",
"var",
"s",
"=",
"\"\"",
";",
"each",
"(",
"obj",
",",
"function",
"(",
"prop",
",",
"val",
")",
"{",
"if",
"(",
"typeof",
"val",
"!==",
"\"string\"",
"&&",
"prop",
"!==",
"\"opacity\"",
")",
"{",
"val",
"+=",
"\"px\"",
";",
"}",
"s",
"+=",
"prop",
"+",
"\": \"",
"+",
"val",
"+",
"\";\"",
";",
"}",
")",
";",
"el",
".",
"style",
".",
"cssText",
"+=",
"s",
";",
"}",
"}"
] |
Emulate jQuery's css method
@param {Object} el HTMLElement
@param {Object} prop CSS properties and values
@return {Object|Void}
|
[
"Emulate",
"jQuery",
"s",
"css",
"method"
] |
f7e825fc97f95b6489408492ba15e3968fde943b
|
https://github.com/Mobius1/Selectr/blob/f7e825fc97f95b6489408492ba15e3968fde943b/docs/js/plugins.js#L125-L141
|
15,547
|
Mobius1/Selectr
|
docs/js/plugins.js
|
rect
|
function rect(t, e) {
var o = window,
r = t.getBoundingClientRect(),
x = o.pageXOffset,
y = o.pageYOffset,
m = {},
f = "none";
if (e) {
var s = style(t);
m = {
top: parseInt(s["margin-top"], 10),
left: parseInt(s["margin-left"], 10),
right: parseInt(s["margin-right"], 10),
bottom: parseInt(s["margin-bottom"], 10)
};
f = s.float;
}
return {
w: r.width,
h: r.height,
x1: r.left + x,
x2: r.right + x,
y1: r.top + y,
y2: r.bottom + y,
margin: m,
float: f
};
}
|
javascript
|
function rect(t, e) {
var o = window,
r = t.getBoundingClientRect(),
x = o.pageXOffset,
y = o.pageYOffset,
m = {},
f = "none";
if (e) {
var s = style(t);
m = {
top: parseInt(s["margin-top"], 10),
left: parseInt(s["margin-left"], 10),
right: parseInt(s["margin-right"], 10),
bottom: parseInt(s["margin-bottom"], 10)
};
f = s.float;
}
return {
w: r.width,
h: r.height,
x1: r.left + x,
x2: r.right + x,
y1: r.top + y,
y2: r.bottom + y,
margin: m,
float: f
};
}
|
[
"function",
"rect",
"(",
"t",
",",
"e",
")",
"{",
"var",
"o",
"=",
"window",
",",
"r",
"=",
"t",
".",
"getBoundingClientRect",
"(",
")",
",",
"x",
"=",
"o",
".",
"pageXOffset",
",",
"y",
"=",
"o",
".",
"pageYOffset",
",",
"m",
"=",
"{",
"}",
",",
"f",
"=",
"\"none\"",
";",
"if",
"(",
"e",
")",
"{",
"var",
"s",
"=",
"style",
"(",
"t",
")",
";",
"m",
"=",
"{",
"top",
":",
"parseInt",
"(",
"s",
"[",
"\"margin-top\"",
"]",
",",
"10",
")",
",",
"left",
":",
"parseInt",
"(",
"s",
"[",
"\"margin-left\"",
"]",
",",
"10",
")",
",",
"right",
":",
"parseInt",
"(",
"s",
"[",
"\"margin-right\"",
"]",
",",
"10",
")",
",",
"bottom",
":",
"parseInt",
"(",
"s",
"[",
"\"margin-bottom\"",
"]",
",",
"10",
")",
"}",
";",
"f",
"=",
"s",
".",
"float",
";",
"}",
"return",
"{",
"w",
":",
"r",
".",
"width",
",",
"h",
":",
"r",
".",
"height",
",",
"x1",
":",
"r",
".",
"left",
"+",
"x",
",",
"x2",
":",
"r",
".",
"right",
"+",
"x",
",",
"y1",
":",
"r",
".",
"top",
"+",
"y",
",",
"y2",
":",
"r",
".",
"bottom",
"+",
"y",
",",
"margin",
":",
"m",
",",
"float",
":",
"f",
"}",
";",
"}"
] |
Get an element's DOMRect relative to the document instead of the viewport.
@param {Object} t HTMLElement
@param {Boolean} e Include margins
@return {Object} Formatted DOMRect copy
|
[
"Get",
"an",
"element",
"s",
"DOMRect",
"relative",
"to",
"the",
"document",
"instead",
"of",
"the",
"viewport",
"."
] |
f7e825fc97f95b6489408492ba15e3968fde943b
|
https://github.com/Mobius1/Selectr/blob/f7e825fc97f95b6489408492ba15e3968fde943b/docs/js/plugins.js#L159-L189
|
15,548
|
Mobius1/Selectr
|
docs/js/plugins.js
|
getScrollBarWidth
|
function getScrollBarWidth() {
var width = 0, div = createElement("div", { class: "scrollbar-measure" });
style(div, {
width: 100,
height: 100,
overflow: "scroll",
position: "absolute",
top: -9999
});
document.body.appendChild(div);
width = div.offsetWidth - div.clientWidth;
document.body.removeChild(div);
return width;
}
|
javascript
|
function getScrollBarWidth() {
var width = 0, div = createElement("div", { class: "scrollbar-measure" });
style(div, {
width: 100,
height: 100,
overflow: "scroll",
position: "absolute",
top: -9999
});
document.body.appendChild(div);
width = div.offsetWidth - div.clientWidth;
document.body.removeChild(div);
return width;
}
|
[
"function",
"getScrollBarWidth",
"(",
")",
"{",
"var",
"width",
"=",
"0",
",",
"div",
"=",
"createElement",
"(",
"\"div\"",
",",
"{",
"class",
":",
"\"scrollbar-measure\"",
"}",
")",
";",
"style",
"(",
"div",
",",
"{",
"width",
":",
"100",
",",
"height",
":",
"100",
",",
"overflow",
":",
"\"scroll\"",
",",
"position",
":",
"\"absolute\"",
",",
"top",
":",
"-",
"9999",
"}",
")",
";",
"document",
".",
"body",
".",
"appendChild",
"(",
"div",
")",
";",
"width",
"=",
"div",
".",
"offsetWidth",
"-",
"div",
".",
"clientWidth",
";",
"document",
".",
"body",
".",
"removeChild",
"(",
"div",
")",
";",
"return",
"width",
";",
"}"
] |
Get native scrollbar width
@return {Number} Scrollbar width
|
[
"Get",
"native",
"scrollbar",
"width"
] |
f7e825fc97f95b6489408492ba15e3968fde943b
|
https://github.com/Mobius1/Selectr/blob/f7e825fc97f95b6489408492ba15e3968fde943b/docs/js/plugins.js#L237-L253
|
15,549
|
postwait/node-amqp
|
lib/exchange.js
|
createExchangeErrorHandlerFor
|
function createExchangeErrorHandlerFor (exchange) {
return function (err) {
if (!exchange.options.confirm) return;
// should requeue instead?
// https://www.rabbitmq.com/reliability.html#producer
debug && debug('Exchange error handler triggered, erroring and wiping all unacked publishes');
for (var id in exchange._unAcked) {
var task = exchange._unAcked[id];
task.emit('ack error', err);
delete exchange._unAcked[id];
}
};
}
|
javascript
|
function createExchangeErrorHandlerFor (exchange) {
return function (err) {
if (!exchange.options.confirm) return;
// should requeue instead?
// https://www.rabbitmq.com/reliability.html#producer
debug && debug('Exchange error handler triggered, erroring and wiping all unacked publishes');
for (var id in exchange._unAcked) {
var task = exchange._unAcked[id];
task.emit('ack error', err);
delete exchange._unAcked[id];
}
};
}
|
[
"function",
"createExchangeErrorHandlerFor",
"(",
"exchange",
")",
"{",
"return",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"!",
"exchange",
".",
"options",
".",
"confirm",
")",
"return",
";",
"// should requeue instead?",
"// https://www.rabbitmq.com/reliability.html#producer",
"debug",
"&&",
"debug",
"(",
"'Exchange error handler triggered, erroring and wiping all unacked publishes'",
")",
";",
"for",
"(",
"var",
"id",
"in",
"exchange",
".",
"_unAcked",
")",
"{",
"var",
"task",
"=",
"exchange",
".",
"_unAcked",
"[",
"id",
"]",
";",
"task",
".",
"emit",
"(",
"'ack error'",
",",
"err",
")",
";",
"delete",
"exchange",
".",
"_unAcked",
"[",
"id",
"]",
";",
"}",
"}",
";",
"}"
] |
creates an error handler scoped to the given `exchange`
|
[
"creates",
"an",
"error",
"handler",
"scoped",
"to",
"the",
"given",
"exchange"
] |
0bc3ffab79dd62f3579571579e3e52a4eb2df0c1
|
https://github.com/postwait/node-amqp/blob/0bc3ffab79dd62f3579571579e3e52a4eb2df0c1/lib/exchange.js#L28-L41
|
15,550
|
postwait/node-amqp
|
lib/parser.js
|
parseInt
|
function parseInt (buffer, size) {
switch (size) {
case 1:
return buffer[buffer.read++];
case 2:
return (buffer[buffer.read++] << 8) + buffer[buffer.read++];
case 4:
return (buffer[buffer.read++] << 24) + (buffer[buffer.read++] << 16) +
(buffer[buffer.read++] << 8) + buffer[buffer.read++];
case 8:
return (buffer[buffer.read++] << 56) + (buffer[buffer.read++] << 48) +
(buffer[buffer.read++] << 40) + (buffer[buffer.read++] << 32) +
(buffer[buffer.read++] << 24) + (buffer[buffer.read++] << 16) +
(buffer[buffer.read++] << 8) + buffer[buffer.read++];
default:
throw new Error("cannot parse ints of that size");
}
}
|
javascript
|
function parseInt (buffer, size) {
switch (size) {
case 1:
return buffer[buffer.read++];
case 2:
return (buffer[buffer.read++] << 8) + buffer[buffer.read++];
case 4:
return (buffer[buffer.read++] << 24) + (buffer[buffer.read++] << 16) +
(buffer[buffer.read++] << 8) + buffer[buffer.read++];
case 8:
return (buffer[buffer.read++] << 56) + (buffer[buffer.read++] << 48) +
(buffer[buffer.read++] << 40) + (buffer[buffer.read++] << 32) +
(buffer[buffer.read++] << 24) + (buffer[buffer.read++] << 16) +
(buffer[buffer.read++] << 8) + buffer[buffer.read++];
default:
throw new Error("cannot parse ints of that size");
}
}
|
[
"function",
"parseInt",
"(",
"buffer",
",",
"size",
")",
"{",
"switch",
"(",
"size",
")",
"{",
"case",
"1",
":",
"return",
"buffer",
"[",
"buffer",
".",
"read",
"++",
"]",
";",
"case",
"2",
":",
"return",
"(",
"buffer",
"[",
"buffer",
".",
"read",
"++",
"]",
"<<",
"8",
")",
"+",
"buffer",
"[",
"buffer",
".",
"read",
"++",
"]",
";",
"case",
"4",
":",
"return",
"(",
"buffer",
"[",
"buffer",
".",
"read",
"++",
"]",
"<<",
"24",
")",
"+",
"(",
"buffer",
"[",
"buffer",
".",
"read",
"++",
"]",
"<<",
"16",
")",
"+",
"(",
"buffer",
"[",
"buffer",
".",
"read",
"++",
"]",
"<<",
"8",
")",
"+",
"buffer",
"[",
"buffer",
".",
"read",
"++",
"]",
";",
"case",
"8",
":",
"return",
"(",
"buffer",
"[",
"buffer",
".",
"read",
"++",
"]",
"<<",
"56",
")",
"+",
"(",
"buffer",
"[",
"buffer",
".",
"read",
"++",
"]",
"<<",
"48",
")",
"+",
"(",
"buffer",
"[",
"buffer",
".",
"read",
"++",
"]",
"<<",
"40",
")",
"+",
"(",
"buffer",
"[",
"buffer",
".",
"read",
"++",
"]",
"<<",
"32",
")",
"+",
"(",
"buffer",
"[",
"buffer",
".",
"read",
"++",
"]",
"<<",
"24",
")",
"+",
"(",
"buffer",
"[",
"buffer",
".",
"read",
"++",
"]",
"<<",
"16",
")",
"+",
"(",
"buffer",
"[",
"buffer",
".",
"read",
"++",
"]",
"<<",
"8",
")",
"+",
"buffer",
"[",
"buffer",
".",
"read",
"++",
"]",
";",
"default",
":",
"throw",
"new",
"Error",
"(",
"\"cannot parse ints of that size\"",
")",
";",
"}",
"}"
] |
parse Network Byte Order integers. size can be 1,2,4,8
|
[
"parse",
"Network",
"Byte",
"Order",
"integers",
".",
"size",
"can",
"be",
"1",
"2",
"4",
"8"
] |
0bc3ffab79dd62f3579571579e3e52a4eb2df0c1
|
https://github.com/postwait/node-amqp/blob/0bc3ffab79dd62f3579571579e3e52a4eb2df0c1/lib/parser.js#L153-L174
|
15,551
|
airtap/airtap
|
lib/builder-browserify.js
|
registerable
|
function registerable (cfgObj) {
_.forIn(cfgObj, function (value, key) {
if (registerableCfg.indexOf(key) !== -1) {
register(key, cfgObj)
}
})
}
|
javascript
|
function registerable (cfgObj) {
_.forIn(cfgObj, function (value, key) {
if (registerableCfg.indexOf(key) !== -1) {
register(key, cfgObj)
}
})
}
|
[
"function",
"registerable",
"(",
"cfgObj",
")",
"{",
"_",
".",
"forIn",
"(",
"cfgObj",
",",
"function",
"(",
"value",
",",
"key",
")",
"{",
"if",
"(",
"registerableCfg",
".",
"indexOf",
"(",
"key",
")",
"!==",
"-",
"1",
")",
"{",
"register",
"(",
"key",
",",
"cfgObj",
")",
"}",
"}",
")",
"}"
] |
grab registerable configs and register them
|
[
"grab",
"registerable",
"configs",
"and",
"register",
"them"
] |
deb4da83b39267f16454e3373ce4ab48a8832f9f
|
https://github.com/airtap/airtap/blob/deb4da83b39267f16454e3373ce4ab48a8832f9f/lib/builder-browserify.js#L29-L35
|
15,552
|
jshttp/cookie
|
index.js
|
parse
|
function parse(str, options) {
if (typeof str !== 'string') {
throw new TypeError('argument str must be a string');
}
var obj = {}
var opt = options || {};
var pairs = str.split(pairSplitRegExp);
var dec = opt.decode || decode;
for (var i = 0; i < pairs.length; i++) {
var pair = pairs[i];
var eq_idx = pair.indexOf('=');
// skip things that don't look like key=value
if (eq_idx < 0) {
continue;
}
var key = pair.substr(0, eq_idx).trim()
var val = pair.substr(++eq_idx, pair.length).trim();
// quoted values
if ('"' == val[0]) {
val = val.slice(1, -1);
}
// only assign once
if (undefined == obj[key]) {
obj[key] = tryDecode(val, dec);
}
}
return obj;
}
|
javascript
|
function parse(str, options) {
if (typeof str !== 'string') {
throw new TypeError('argument str must be a string');
}
var obj = {}
var opt = options || {};
var pairs = str.split(pairSplitRegExp);
var dec = opt.decode || decode;
for (var i = 0; i < pairs.length; i++) {
var pair = pairs[i];
var eq_idx = pair.indexOf('=');
// skip things that don't look like key=value
if (eq_idx < 0) {
continue;
}
var key = pair.substr(0, eq_idx).trim()
var val = pair.substr(++eq_idx, pair.length).trim();
// quoted values
if ('"' == val[0]) {
val = val.slice(1, -1);
}
// only assign once
if (undefined == obj[key]) {
obj[key] = tryDecode(val, dec);
}
}
return obj;
}
|
[
"function",
"parse",
"(",
"str",
",",
"options",
")",
"{",
"if",
"(",
"typeof",
"str",
"!==",
"'string'",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'argument str must be a string'",
")",
";",
"}",
"var",
"obj",
"=",
"{",
"}",
"var",
"opt",
"=",
"options",
"||",
"{",
"}",
";",
"var",
"pairs",
"=",
"str",
".",
"split",
"(",
"pairSplitRegExp",
")",
";",
"var",
"dec",
"=",
"opt",
".",
"decode",
"||",
"decode",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"pairs",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"pair",
"=",
"pairs",
"[",
"i",
"]",
";",
"var",
"eq_idx",
"=",
"pair",
".",
"indexOf",
"(",
"'='",
")",
";",
"// skip things that don't look like key=value",
"if",
"(",
"eq_idx",
"<",
"0",
")",
"{",
"continue",
";",
"}",
"var",
"key",
"=",
"pair",
".",
"substr",
"(",
"0",
",",
"eq_idx",
")",
".",
"trim",
"(",
")",
"var",
"val",
"=",
"pair",
".",
"substr",
"(",
"++",
"eq_idx",
",",
"pair",
".",
"length",
")",
".",
"trim",
"(",
")",
";",
"// quoted values",
"if",
"(",
"'\"'",
"==",
"val",
"[",
"0",
"]",
")",
"{",
"val",
"=",
"val",
".",
"slice",
"(",
"1",
",",
"-",
"1",
")",
";",
"}",
"// only assign once",
"if",
"(",
"undefined",
"==",
"obj",
"[",
"key",
"]",
")",
"{",
"obj",
"[",
"key",
"]",
"=",
"tryDecode",
"(",
"val",
",",
"dec",
")",
";",
"}",
"}",
"return",
"obj",
";",
"}"
] |
Parse a cookie header.
Parse the given cookie header string into an object
The object has the various cookies as keys(names) => values
@param {string} str
@param {object} [options]
@return {object}
@public
|
[
"Parse",
"a",
"cookie",
"header",
"."
] |
7f9265da44887a8d7ca881a8a6317314195ec303
|
https://github.com/jshttp/cookie/blob/7f9265da44887a8d7ca881a8a6317314195ec303/index.js#L49-L83
|
15,553
|
formly-js/angular-formly
|
src/other/utils.js
|
findByNodeName
|
function findByNodeName(el, nodeName) {
if (!el.prop) { // not a jQuery or jqLite object -> wrap it
el = angular.element(el)
}
if (el.prop('nodeName') === nodeName.toUpperCase()) {
return el
}
const c = el.children()
for (let i = 0; c && i < c.length; i++) {
const node = findByNodeName(c[i], nodeName)
if (node) {
return node
}
}
}
|
javascript
|
function findByNodeName(el, nodeName) {
if (!el.prop) { // not a jQuery or jqLite object -> wrap it
el = angular.element(el)
}
if (el.prop('nodeName') === nodeName.toUpperCase()) {
return el
}
const c = el.children()
for (let i = 0; c && i < c.length; i++) {
const node = findByNodeName(c[i], nodeName)
if (node) {
return node
}
}
}
|
[
"function",
"findByNodeName",
"(",
"el",
",",
"nodeName",
")",
"{",
"if",
"(",
"!",
"el",
".",
"prop",
")",
"{",
"// not a jQuery or jqLite object -> wrap it",
"el",
"=",
"angular",
".",
"element",
"(",
"el",
")",
"}",
"if",
"(",
"el",
".",
"prop",
"(",
"'nodeName'",
")",
"===",
"nodeName",
".",
"toUpperCase",
"(",
")",
")",
"{",
"return",
"el",
"}",
"const",
"c",
"=",
"el",
".",
"children",
"(",
")",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"c",
"&&",
"i",
"<",
"c",
".",
"length",
";",
"i",
"++",
")",
"{",
"const",
"node",
"=",
"findByNodeName",
"(",
"c",
"[",
"i",
"]",
",",
"nodeName",
")",
"if",
"(",
"node",
")",
"{",
"return",
"node",
"}",
"}",
"}"
] |
recurse down a node tree to find a node with matching nodeName, for custom tags jQuery.find doesn't work in IE8
|
[
"recurse",
"down",
"a",
"node",
"tree",
"to",
"find",
"a",
"node",
"with",
"matching",
"nodeName",
"for",
"custom",
"tags",
"jQuery",
".",
"find",
"doesn",
"t",
"work",
"in",
"IE8"
] |
c1bd043dc56bed4eecb573717c60804e993e1ab0
|
https://github.com/formly-js/angular-formly/blob/c1bd043dc56bed4eecb573717c60804e993e1ab0/src/other/utils.js#L65-L81
|
15,554
|
mapbox/shp-write
|
src/write.js
|
write
|
function write(rows, geometry_type, geometries, callback) {
var TYPE = types.geometries[geometry_type],
writer = writers[TYPE],
parts = writer.parts(geometries, TYPE),
shpLength = 100 + (parts - geometries.length) * 4 + writer.shpLength(geometries),
shxLength = 100 + writer.shxLength(geometries),
shpBuffer = new ArrayBuffer(shpLength),
shpView = new DataView(shpBuffer),
shxBuffer = new ArrayBuffer(shxLength),
shxView = new DataView(shxBuffer),
extent = writer.extent(geometries);
writeHeader(shpView, TYPE);
writeHeader(shxView, TYPE);
writeExtent(extent, shpView);
writeExtent(extent, shxView);
writer.write(geometries, extent,
new DataView(shpBuffer, 100),
new DataView(shxBuffer, 100),
TYPE);
shpView.setInt32(24, shpLength / 2);
shxView.setInt32(24, (50 + geometries.length * 4));
var dbfBuf = dbf.structure(rows);
callback(null, {
shp: shpView,
shx: shxView,
dbf: dbfBuf,
prj: prj
});
}
|
javascript
|
function write(rows, geometry_type, geometries, callback) {
var TYPE = types.geometries[geometry_type],
writer = writers[TYPE],
parts = writer.parts(geometries, TYPE),
shpLength = 100 + (parts - geometries.length) * 4 + writer.shpLength(geometries),
shxLength = 100 + writer.shxLength(geometries),
shpBuffer = new ArrayBuffer(shpLength),
shpView = new DataView(shpBuffer),
shxBuffer = new ArrayBuffer(shxLength),
shxView = new DataView(shxBuffer),
extent = writer.extent(geometries);
writeHeader(shpView, TYPE);
writeHeader(shxView, TYPE);
writeExtent(extent, shpView);
writeExtent(extent, shxView);
writer.write(geometries, extent,
new DataView(shpBuffer, 100),
new DataView(shxBuffer, 100),
TYPE);
shpView.setInt32(24, shpLength / 2);
shxView.setInt32(24, (50 + geometries.length * 4));
var dbfBuf = dbf.structure(rows);
callback(null, {
shp: shpView,
shx: shxView,
dbf: dbfBuf,
prj: prj
});
}
|
[
"function",
"write",
"(",
"rows",
",",
"geometry_type",
",",
"geometries",
",",
"callback",
")",
"{",
"var",
"TYPE",
"=",
"types",
".",
"geometries",
"[",
"geometry_type",
"]",
",",
"writer",
"=",
"writers",
"[",
"TYPE",
"]",
",",
"parts",
"=",
"writer",
".",
"parts",
"(",
"geometries",
",",
"TYPE",
")",
",",
"shpLength",
"=",
"100",
"+",
"(",
"parts",
"-",
"geometries",
".",
"length",
")",
"*",
"4",
"+",
"writer",
".",
"shpLength",
"(",
"geometries",
")",
",",
"shxLength",
"=",
"100",
"+",
"writer",
".",
"shxLength",
"(",
"geometries",
")",
",",
"shpBuffer",
"=",
"new",
"ArrayBuffer",
"(",
"shpLength",
")",
",",
"shpView",
"=",
"new",
"DataView",
"(",
"shpBuffer",
")",
",",
"shxBuffer",
"=",
"new",
"ArrayBuffer",
"(",
"shxLength",
")",
",",
"shxView",
"=",
"new",
"DataView",
"(",
"shxBuffer",
")",
",",
"extent",
"=",
"writer",
".",
"extent",
"(",
"geometries",
")",
";",
"writeHeader",
"(",
"shpView",
",",
"TYPE",
")",
";",
"writeHeader",
"(",
"shxView",
",",
"TYPE",
")",
";",
"writeExtent",
"(",
"extent",
",",
"shpView",
")",
";",
"writeExtent",
"(",
"extent",
",",
"shxView",
")",
";",
"writer",
".",
"write",
"(",
"geometries",
",",
"extent",
",",
"new",
"DataView",
"(",
"shpBuffer",
",",
"100",
")",
",",
"new",
"DataView",
"(",
"shxBuffer",
",",
"100",
")",
",",
"TYPE",
")",
";",
"shpView",
".",
"setInt32",
"(",
"24",
",",
"shpLength",
"/",
"2",
")",
";",
"shxView",
".",
"setInt32",
"(",
"24",
",",
"(",
"50",
"+",
"geometries",
".",
"length",
"*",
"4",
")",
")",
";",
"var",
"dbfBuf",
"=",
"dbf",
".",
"structure",
"(",
"rows",
")",
";",
"callback",
"(",
"null",
",",
"{",
"shp",
":",
"shpView",
",",
"shx",
":",
"shxView",
",",
"dbf",
":",
"dbfBuf",
",",
"prj",
":",
"prj",
"}",
")",
";",
"}"
] |
Low-level writing interface
|
[
"Low",
"-",
"level",
"writing",
"interface"
] |
9681b583927c94fb563f7ad38a159934060026f1
|
https://github.com/mapbox/shp-write/blob/9681b583927c94fb563f7ad38a159934060026f1/src/write.js#L21-L55
|
15,555
|
guymorita/recommendationRaccoon
|
lib/algorithms.js
|
function(otherUserId, callback){
// if there is only one other user or the other user is the same user
if (otherUserIdsWhoRated.length === 1 || userId === otherUserId){
// then call the callback and exciting the similarity check
callback();
}
// if the userid is not the same as the user
if (userId !== otherUserId){
// calculate the jaccard coefficient for similarity. it will return a value between -1 and 1 showing the two users
// similarity
jaccardCoefficient(userId, otherUserId, function(result) {
// with the returned similarity score, add it to a sorted set named above
client.zadd(similarityZSet, result, otherUserId, function(err){
// call the async callback function once finished to indicate that the process is finished
callback();
});
});
}
}
|
javascript
|
function(otherUserId, callback){
// if there is only one other user or the other user is the same user
if (otherUserIdsWhoRated.length === 1 || userId === otherUserId){
// then call the callback and exciting the similarity check
callback();
}
// if the userid is not the same as the user
if (userId !== otherUserId){
// calculate the jaccard coefficient for similarity. it will return a value between -1 and 1 showing the two users
// similarity
jaccardCoefficient(userId, otherUserId, function(result) {
// with the returned similarity score, add it to a sorted set named above
client.zadd(similarityZSet, result, otherUserId, function(err){
// call the async callback function once finished to indicate that the process is finished
callback();
});
});
}
}
|
[
"function",
"(",
"otherUserId",
",",
"callback",
")",
"{",
"// if there is only one other user or the other user is the same user",
"if",
"(",
"otherUserIdsWhoRated",
".",
"length",
"===",
"1",
"||",
"userId",
"===",
"otherUserId",
")",
"{",
"// then call the callback and exciting the similarity check",
"callback",
"(",
")",
";",
"}",
"// if the userid is not the same as the user",
"if",
"(",
"userId",
"!==",
"otherUserId",
")",
"{",
"// calculate the jaccard coefficient for similarity. it will return a value between -1 and 1 showing the two users",
"// similarity",
"jaccardCoefficient",
"(",
"userId",
",",
"otherUserId",
",",
"function",
"(",
"result",
")",
"{",
"// with the returned similarity score, add it to a sorted set named above",
"client",
".",
"zadd",
"(",
"similarityZSet",
",",
"result",
",",
"otherUserId",
",",
"function",
"(",
"err",
")",
"{",
"// call the async callback function once finished to indicate that the process is finished",
"callback",
"(",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
"}"
] |
running a function on each item in the list
|
[
"running",
"a",
"function",
"on",
"each",
"item",
"in",
"the",
"list"
] |
cc99d193938993107cf02a2caaff4803f3e6a476
|
https://github.com/guymorita/recommendationRaccoon/blob/cc99d193938993107cf02a2caaff4803f3e6a476/lib/algorithms.js#L74-L92
|
|
15,556
|
guymorita/recommendationRaccoon
|
lib/algorithms.js
|
function(err){
client.del(recommendedZSet, function(err){
async.each(scoreMap,
function(scorePair, callback){
client.zadd(recommendedZSet, scorePair[0], scorePair[1], function(err){
callback();
});
},
// after all the additions have been made to the recommended set,
function(err){
client.del(tempAllLikedSet, function(err){
client.zcard(recommendedZSet, function(err, length){
client.zremrangebyrank(recommendedZSet, 0, length-config.numOfRecsStore-1, function(err){
cb();
});
});
});
}
);
});
}
|
javascript
|
function(err){
client.del(recommendedZSet, function(err){
async.each(scoreMap,
function(scorePair, callback){
client.zadd(recommendedZSet, scorePair[0], scorePair[1], function(err){
callback();
});
},
// after all the additions have been made to the recommended set,
function(err){
client.del(tempAllLikedSet, function(err){
client.zcard(recommendedZSet, function(err, length){
client.zremrangebyrank(recommendedZSet, 0, length-config.numOfRecsStore-1, function(err){
cb();
});
});
});
}
);
});
}
|
[
"function",
"(",
"err",
")",
"{",
"client",
".",
"del",
"(",
"recommendedZSet",
",",
"function",
"(",
"err",
")",
"{",
"async",
".",
"each",
"(",
"scoreMap",
",",
"function",
"(",
"scorePair",
",",
"callback",
")",
"{",
"client",
".",
"zadd",
"(",
"recommendedZSet",
",",
"scorePair",
"[",
"0",
"]",
",",
"scorePair",
"[",
"1",
"]",
",",
"function",
"(",
"err",
")",
"{",
"callback",
"(",
")",
";",
"}",
")",
";",
"}",
",",
"// after all the additions have been made to the recommended set,",
"function",
"(",
"err",
")",
"{",
"client",
".",
"del",
"(",
"tempAllLikedSet",
",",
"function",
"(",
"err",
")",
"{",
"client",
".",
"zcard",
"(",
"recommendedZSet",
",",
"function",
"(",
"err",
",",
"length",
")",
"{",
"client",
".",
"zremrangebyrank",
"(",
"recommendedZSet",
",",
"0",
",",
"length",
"-",
"config",
".",
"numOfRecsStore",
"-",
"1",
",",
"function",
"(",
"err",
")",
"{",
"cb",
"(",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
using score map which is an array of what the current user would rate all the unrated items, add them to that users sorted recommended set
|
[
"using",
"score",
"map",
"which",
"is",
"an",
"array",
"of",
"what",
"the",
"current",
"user",
"would",
"rate",
"all",
"the",
"unrated",
"items",
"add",
"them",
"to",
"that",
"users",
"sorted",
"recommended",
"set"
] |
cc99d193938993107cf02a2caaff4803f3e6a476
|
https://github.com/guymorita/recommendationRaccoon/blob/cc99d193938993107cf02a2caaff4803f3e6a476/lib/algorithms.js#L194-L214
|
|
15,557
|
75lb/command-line-args
|
dist/index.js
|
findReplace
|
function findReplace (array, testFn) {
const found = [];
const replaceWiths = arrayify$1(arguments);
replaceWiths.splice(0, 2);
arrayify$1(array).forEach((value, index) => {
let expanded = [];
replaceWiths.forEach(replaceWith => {
if (typeof replaceWith === 'function') {
expanded = expanded.concat(replaceWith(value));
} else {
expanded.push(replaceWith);
}
});
if (testFn(value)) {
found.push({
index: index,
replaceWithValue: expanded
});
}
});
found.reverse().forEach(item => {
const spliceArgs = [ item.index, 1 ].concat(item.replaceWithValue);
array.splice.apply(array, spliceArgs);
});
return array
}
|
javascript
|
function findReplace (array, testFn) {
const found = [];
const replaceWiths = arrayify$1(arguments);
replaceWiths.splice(0, 2);
arrayify$1(array).forEach((value, index) => {
let expanded = [];
replaceWiths.forEach(replaceWith => {
if (typeof replaceWith === 'function') {
expanded = expanded.concat(replaceWith(value));
} else {
expanded.push(replaceWith);
}
});
if (testFn(value)) {
found.push({
index: index,
replaceWithValue: expanded
});
}
});
found.reverse().forEach(item => {
const spliceArgs = [ item.index, 1 ].concat(item.replaceWithValue);
array.splice.apply(array, spliceArgs);
});
return array
}
|
[
"function",
"findReplace",
"(",
"array",
",",
"testFn",
")",
"{",
"const",
"found",
"=",
"[",
"]",
";",
"const",
"replaceWiths",
"=",
"arrayify$1",
"(",
"arguments",
")",
";",
"replaceWiths",
".",
"splice",
"(",
"0",
",",
"2",
")",
";",
"arrayify$1",
"(",
"array",
")",
".",
"forEach",
"(",
"(",
"value",
",",
"index",
")",
"=>",
"{",
"let",
"expanded",
"=",
"[",
"]",
";",
"replaceWiths",
".",
"forEach",
"(",
"replaceWith",
"=>",
"{",
"if",
"(",
"typeof",
"replaceWith",
"===",
"'function'",
")",
"{",
"expanded",
"=",
"expanded",
".",
"concat",
"(",
"replaceWith",
"(",
"value",
")",
")",
";",
"}",
"else",
"{",
"expanded",
".",
"push",
"(",
"replaceWith",
")",
";",
"}",
"}",
")",
";",
"if",
"(",
"testFn",
"(",
"value",
")",
")",
"{",
"found",
".",
"push",
"(",
"{",
"index",
":",
"index",
",",
"replaceWithValue",
":",
"expanded",
"}",
")",
";",
"}",
"}",
")",
";",
"found",
".",
"reverse",
"(",
")",
".",
"forEach",
"(",
"item",
"=>",
"{",
"const",
"spliceArgs",
"=",
"[",
"item",
".",
"index",
",",
"1",
"]",
".",
"concat",
"(",
"item",
".",
"replaceWithValue",
")",
";",
"array",
".",
"splice",
".",
"apply",
"(",
"array",
",",
"spliceArgs",
")",
";",
"}",
")",
";",
"return",
"array",
"}"
] |
Find and either replace or remove items in an array.
@module find-replace
@example
> const findReplace = require('find-replace')
> const numbers = [ 1, 2, 3]
> findReplace(numbers, n => n === 2, 'two')
[ 1, 'two', 3 ]
> findReplace(numbers, n => n === 2, [ 'two', 'zwei' ])
[ 1, [ 'two', 'zwei' ], 3 ]
> findReplace(numbers, n => n === 2, 'two', 'zwei')
[ 1, 'two', 'zwei', 3 ]
> findReplace(numbers, n => n === 2) // no replacement, so remove
[ 1, 3 ]
@param {array} - The input array
@param {testFn} - A predicate function which, if returning `true` causes the current item to be operated on.
@param [replaceWith] {...any} - If specified, found values will be replaced with these values, else removed.
@returns {array}
@alias module:find-replace
|
[
"Find",
"and",
"either",
"replace",
"or",
"remove",
"items",
"in",
"an",
"array",
"."
] |
b07cb35ed0d1f3632230cb658e1e8c5a238e38fa
|
https://github.com/75lb/command-line-args/blob/b07cb35ed0d1f3632230cb658e1e8c5a238e38fa/dist/index.js#L147-L176
|
15,558
|
75lb/command-line-args
|
dist/index.js
|
isClass
|
function isClass (input) {
if (isFunction(input)) {
return /^class /.test(Function.prototype.toString.call(input))
} else {
return false
}
}
|
javascript
|
function isClass (input) {
if (isFunction(input)) {
return /^class /.test(Function.prototype.toString.call(input))
} else {
return false
}
}
|
[
"function",
"isClass",
"(",
"input",
")",
"{",
"if",
"(",
"isFunction",
"(",
"input",
")",
")",
"{",
"return",
"/",
"^class ",
"/",
".",
"test",
"(",
"Function",
".",
"prototype",
".",
"toString",
".",
"call",
"(",
"input",
")",
")",
"}",
"else",
"{",
"return",
"false",
"}",
"}"
] |
Returns true if the input value is an es2015 `class`.
@param {*} - the input to test
@returns {boolean}
@static
|
[
"Returns",
"true",
"if",
"the",
"input",
"value",
"is",
"an",
"es2015",
"class",
"."
] |
b07cb35ed0d1f3632230cb658e1e8c5a238e38fa
|
https://github.com/75lb/command-line-args/blob/b07cb35ed0d1f3632230cb658e1e8c5a238e38fa/dist/index.js#L475-L481
|
15,559
|
75lb/command-line-args
|
dist/index.js
|
isPromise
|
function isPromise (input) {
if (input) {
const isPromise = isDefined(Promise) && input instanceof Promise;
const isThenable = input.then && typeof input.then === 'function';
return !!(isPromise || isThenable)
} else {
return false
}
}
|
javascript
|
function isPromise (input) {
if (input) {
const isPromise = isDefined(Promise) && input instanceof Promise;
const isThenable = input.then && typeof input.then === 'function';
return !!(isPromise || isThenable)
} else {
return false
}
}
|
[
"function",
"isPromise",
"(",
"input",
")",
"{",
"if",
"(",
"input",
")",
"{",
"const",
"isPromise",
"=",
"isDefined",
"(",
"Promise",
")",
"&&",
"input",
"instanceof",
"Promise",
";",
"const",
"isThenable",
"=",
"input",
".",
"then",
"&&",
"typeof",
"input",
".",
"then",
"===",
"'function'",
";",
"return",
"!",
"!",
"(",
"isPromise",
"||",
"isThenable",
")",
"}",
"else",
"{",
"return",
"false",
"}",
"}"
] |
Returns true if the input is a Promise.
@param {*} - the input to test
@returns {boolean}
@static
|
[
"Returns",
"true",
"if",
"the",
"input",
"is",
"a",
"Promise",
"."
] |
b07cb35ed0d1f3632230cb658e1e8c5a238e38fa
|
https://github.com/75lb/command-line-args/blob/b07cb35ed0d1f3632230cb658e1e8c5a238e38fa/dist/index.js#L509-L517
|
15,560
|
pelias/schema
|
scripts/drop_index.js
|
warnIfNotLocal
|
function warnIfNotLocal() {
if (config.esclient.hosts.some((env) => { return env.host !== 'localhost'; } )) {
console.log(colors.red(`WARNING: DROPPING SCHEMA NOT ON LOCALHOST: ${config.esclient.hosts[0].host}`));
}
}
|
javascript
|
function warnIfNotLocal() {
if (config.esclient.hosts.some((env) => { return env.host !== 'localhost'; } )) {
console.log(colors.red(`WARNING: DROPPING SCHEMA NOT ON LOCALHOST: ${config.esclient.hosts[0].host}`));
}
}
|
[
"function",
"warnIfNotLocal",
"(",
")",
"{",
"if",
"(",
"config",
".",
"esclient",
".",
"hosts",
".",
"some",
"(",
"(",
"env",
")",
"=>",
"{",
"return",
"env",
".",
"host",
"!==",
"'localhost'",
";",
"}",
")",
")",
"{",
"console",
".",
"log",
"(",
"colors",
".",
"red",
"(",
"`",
"${",
"config",
".",
"esclient",
".",
"hosts",
"[",
"0",
"]",
".",
"host",
"}",
"`",
")",
")",
";",
"}",
"}"
] |
check all hosts to see if any is not localhost
|
[
"check",
"all",
"hosts",
"to",
"see",
"if",
"any",
"is",
"not",
"localhost"
] |
0f1305a2c87bd9c778c187435dfc94dc0d7e3d97
|
https://github.com/pelias/schema/blob/0f1305a2c87bd9c778c187435dfc94dc0d7e3d97/scripts/drop_index.js#L21-L26
|
15,561
|
onehilltech/blueprint
|
lib/router-builder.js
|
makeAction
|
function makeAction (controller, method, opts) {
let action = {action: controller + '@' + method};
return extend (action, opts);
}
|
javascript
|
function makeAction (controller, method, opts) {
let action = {action: controller + '@' + method};
return extend (action, opts);
}
|
[
"function",
"makeAction",
"(",
"controller",
",",
"method",
",",
"opts",
")",
"{",
"let",
"action",
"=",
"{",
"action",
":",
"controller",
"+",
"'@'",
"+",
"method",
"}",
";",
"return",
"extend",
"(",
"action",
",",
"opts",
")",
";",
"}"
] |
Factory method that generates an action object.
|
[
"Factory",
"method",
"that",
"generates",
"an",
"action",
"object",
"."
] |
3a90b1f463e82a68427bcd1d85b2eb3660d1f385
|
https://github.com/onehilltech/blueprint/blob/3a90b1f463e82a68427bcd1d85b2eb3660d1f385/lib/router-builder.js#L62-L65
|
15,562
|
onehilltech/blueprint
|
lib/barrier/index.js
|
registerParticipant
|
function registerParticipant (name, participant) {
let barrier = barriers[name];
if (!barrier) {
debug (`creating barrier ${name}`);
barrier = barriers[name] = new Barrier ({name});
}
debug (`registering participant with barrier ${name}`);
return barrier.registerParticipant (participant);
}
|
javascript
|
function registerParticipant (name, participant) {
let barrier = barriers[name];
if (!barrier) {
debug (`creating barrier ${name}`);
barrier = barriers[name] = new Barrier ({name});
}
debug (`registering participant with barrier ${name}`);
return barrier.registerParticipant (participant);
}
|
[
"function",
"registerParticipant",
"(",
"name",
",",
"participant",
")",
"{",
"let",
"barrier",
"=",
"barriers",
"[",
"name",
"]",
";",
"if",
"(",
"!",
"barrier",
")",
"{",
"debug",
"(",
"`",
"${",
"name",
"}",
"`",
")",
";",
"barrier",
"=",
"barriers",
"[",
"name",
"]",
"=",
"new",
"Barrier",
"(",
"{",
"name",
"}",
")",
";",
"}",
"debug",
"(",
"`",
"${",
"name",
"}",
"`",
")",
";",
"return",
"barrier",
".",
"registerParticipant",
"(",
"participant",
")",
";",
"}"
] |
Factory method for registering a participant with a barrier. If the barrier
does not exist, then a new barrier is created.
@param name Name of the barrier
@param participant JavaScript object
@returns {Barrier}
|
[
"Factory",
"method",
"for",
"registering",
"a",
"participant",
"with",
"a",
"barrier",
".",
"If",
"the",
"barrier",
"does",
"not",
"exist",
"then",
"a",
"new",
"barrier",
"is",
"created",
"."
] |
3a90b1f463e82a68427bcd1d85b2eb3660d1f385
|
https://github.com/onehilltech/blueprint/blob/3a90b1f463e82a68427bcd1d85b2eb3660d1f385/lib/barrier/index.js#L14-L24
|
15,563
|
lightstep/lightstep-tracer-javascript
|
src/plugins/instrument_xhr.js
|
getResponseHeaders
|
function getResponseHeaders(xhr) {
let raw = xhr.getAllResponseHeaders();
let parts = raw.replace(/\s+$/, '').split(/\n/);
for (let i = 0; i < parts.length; i++) {
parts[i] = parts[i].replace(/\r/g, '').replace(/^\s+/, '').replace(/\s+$/, '');
}
return parts;
}
|
javascript
|
function getResponseHeaders(xhr) {
let raw = xhr.getAllResponseHeaders();
let parts = raw.replace(/\s+$/, '').split(/\n/);
for (let i = 0; i < parts.length; i++) {
parts[i] = parts[i].replace(/\r/g, '').replace(/^\s+/, '').replace(/\s+$/, '');
}
return parts;
}
|
[
"function",
"getResponseHeaders",
"(",
"xhr",
")",
"{",
"let",
"raw",
"=",
"xhr",
".",
"getAllResponseHeaders",
"(",
")",
";",
"let",
"parts",
"=",
"raw",
".",
"replace",
"(",
"/",
"\\s+$",
"/",
",",
"''",
")",
".",
"split",
"(",
"/",
"\\n",
"/",
")",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"parts",
".",
"length",
";",
"i",
"++",
")",
"{",
"parts",
"[",
"i",
"]",
"=",
"parts",
"[",
"i",
"]",
".",
"replace",
"(",
"/",
"\\r",
"/",
"g",
",",
"''",
")",
".",
"replace",
"(",
"/",
"^\\s+",
"/",
",",
"''",
")",
".",
"replace",
"(",
"/",
"\\s+$",
"/",
",",
"''",
")",
";",
"}",
"return",
"parts",
";",
"}"
] |
Normalize the getAllResponseHeaders output
|
[
"Normalize",
"the",
"getAllResponseHeaders",
"output"
] |
648797fbf02ad78eb567665ee7e6e4f83c98a0c3
|
https://github.com/lightstep/lightstep-tracer-javascript/blob/648797fbf02ad78eb567665ee7e6e4f83c98a0c3/src/plugins/instrument_xhr.js#L41-L48
|
15,564
|
lightstep/lightstep-tracer-javascript
|
examples/node/index.js
|
queryUserInfo
|
function queryUserInfo(parentSpan, username, callback) {
// Aggregated user information across multiple API calls
var user = {
login : null,
type : null,
repoNames : [],
recentEvents : 0,
eventCounts : {},
};
// Call the callback only when all three API requests finish or on the
// first error.
var remainingCalls = 3;
var next = function (err) {
// Early terminate on any error
remainingCalls -= err ? Math.max(remainingCalls, 1) : 1;
if (remainingCalls === 0) {
callback(err, err ? null : user);
}
};
// First query the user info for the given username
httpGet(parentSpan, 'http://api.github.com/users/' + username, function (err, json) {
if (err) {
return next(err);
}
user.login = json.login;
user.type = json.type;
// Use the user info to query names of all the user's public repositories
httpGet(parentSpan, json.repos_url, function (err, json) {
if (err) {
return next(err);
}
for (var i = 0; i < json.length; i++) {
user.repoNames.push(json[i].name);
}
next(null);
});
// In parallel, query the recent events activity for the user
httpGet(parentSpan, json.received_events_url, function (err, json) {
if (err) {
return next(err);
}
user.recentEvents = json.length;
for (var i = 0; i < json.length; i++) {
var eventType = json[i].type;
user.eventCounts[eventType] = user.eventCounts[eventType] || 0;
user.eventCounts[eventType]++;
}
next(null);
});
next(null);
});
}
|
javascript
|
function queryUserInfo(parentSpan, username, callback) {
// Aggregated user information across multiple API calls
var user = {
login : null,
type : null,
repoNames : [],
recentEvents : 0,
eventCounts : {},
};
// Call the callback only when all three API requests finish or on the
// first error.
var remainingCalls = 3;
var next = function (err) {
// Early terminate on any error
remainingCalls -= err ? Math.max(remainingCalls, 1) : 1;
if (remainingCalls === 0) {
callback(err, err ? null : user);
}
};
// First query the user info for the given username
httpGet(parentSpan, 'http://api.github.com/users/' + username, function (err, json) {
if (err) {
return next(err);
}
user.login = json.login;
user.type = json.type;
// Use the user info to query names of all the user's public repositories
httpGet(parentSpan, json.repos_url, function (err, json) {
if (err) {
return next(err);
}
for (var i = 0; i < json.length; i++) {
user.repoNames.push(json[i].name);
}
next(null);
});
// In parallel, query the recent events activity for the user
httpGet(parentSpan, json.received_events_url, function (err, json) {
if (err) {
return next(err);
}
user.recentEvents = json.length;
for (var i = 0; i < json.length; i++) {
var eventType = json[i].type;
user.eventCounts[eventType] = user.eventCounts[eventType] || 0;
user.eventCounts[eventType]++;
}
next(null);
});
next(null);
});
}
|
[
"function",
"queryUserInfo",
"(",
"parentSpan",
",",
"username",
",",
"callback",
")",
"{",
"// Aggregated user information across multiple API calls",
"var",
"user",
"=",
"{",
"login",
":",
"null",
",",
"type",
":",
"null",
",",
"repoNames",
":",
"[",
"]",
",",
"recentEvents",
":",
"0",
",",
"eventCounts",
":",
"{",
"}",
",",
"}",
";",
"// Call the callback only when all three API requests finish or on the",
"// first error.",
"var",
"remainingCalls",
"=",
"3",
";",
"var",
"next",
"=",
"function",
"(",
"err",
")",
"{",
"// Early terminate on any error",
"remainingCalls",
"-=",
"err",
"?",
"Math",
".",
"max",
"(",
"remainingCalls",
",",
"1",
")",
":",
"1",
";",
"if",
"(",
"remainingCalls",
"===",
"0",
")",
"{",
"callback",
"(",
"err",
",",
"err",
"?",
"null",
":",
"user",
")",
";",
"}",
"}",
";",
"// First query the user info for the given username",
"httpGet",
"(",
"parentSpan",
",",
"'http://api.github.com/users/'",
"+",
"username",
",",
"function",
"(",
"err",
",",
"json",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"next",
"(",
"err",
")",
";",
"}",
"user",
".",
"login",
"=",
"json",
".",
"login",
";",
"user",
".",
"type",
"=",
"json",
".",
"type",
";",
"// Use the user info to query names of all the user's public repositories",
"httpGet",
"(",
"parentSpan",
",",
"json",
".",
"repos_url",
",",
"function",
"(",
"err",
",",
"json",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"next",
"(",
"err",
")",
";",
"}",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"json",
".",
"length",
";",
"i",
"++",
")",
"{",
"user",
".",
"repoNames",
".",
"push",
"(",
"json",
"[",
"i",
"]",
".",
"name",
")",
";",
"}",
"next",
"(",
"null",
")",
";",
"}",
")",
";",
"// In parallel, query the recent events activity for the user",
"httpGet",
"(",
"parentSpan",
",",
"json",
".",
"received_events_url",
",",
"function",
"(",
"err",
",",
"json",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"next",
"(",
"err",
")",
";",
"}",
"user",
".",
"recentEvents",
"=",
"json",
".",
"length",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"json",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"eventType",
"=",
"json",
"[",
"i",
"]",
".",
"type",
";",
"user",
".",
"eventCounts",
"[",
"eventType",
"]",
"=",
"user",
".",
"eventCounts",
"[",
"eventType",
"]",
"||",
"0",
";",
"user",
".",
"eventCounts",
"[",
"eventType",
"]",
"++",
";",
"}",
"next",
"(",
"null",
")",
";",
"}",
")",
";",
"next",
"(",
"null",
")",
";",
"}",
")",
";",
"}"
] |
Make a series GitHub calls and aggregate the data into the `user` object
defined below.
|
[
"Make",
"a",
"series",
"GitHub",
"calls",
"and",
"aggregate",
"the",
"data",
"into",
"the",
"user",
"object",
"defined",
"below",
"."
] |
648797fbf02ad78eb567665ee7e6e4f83c98a0c3
|
https://github.com/lightstep/lightstep-tracer-javascript/blob/648797fbf02ad78eb567665ee7e6e4f83c98a0c3/examples/node/index.js#L110-L166
|
15,565
|
lightstep/lightstep-tracer-javascript
|
examples/node/index.js
|
httpGet
|
function httpGet(parentSpan, urlString, callback) {
var span = opentracing.globalTracer().startSpan('http.get', { childOf : parentSpan });
var callbackWrapper = function (err, data) {
span.finish();
callback(err, data);
};
try {
var carrier = {};
opentracing.globalTracer().inject(span, opentracing.FORMAT_TEXT_MAP, carrier);
var dest = url.parse(urlString);
var options = {
host : PROXY_HOST,
path : dest.path,
port : PROXY_PORT,
headers: {
// User-Agent is required by the GitHub APIs
'User-Agent': 'LightStep Example',
}
};
for (var key in carrier) {
options.headers[key] = carrier[key];
}
// Create a span representing the https request
span.setTag('url', urlString);
span.log({
event : 'options',
'options': options,
});
return http.get(options, function(response) {
var bodyBuffer = '';
response.on('data', function(chunk) {
bodyBuffer += chunk;
});
response.on('end', function() {
span.log({
body : bodyBuffer,
length : bodyBuffer.length,
});
var parsedJSON, err;
try {
parsedJSON = JSON.parse(bodyBuffer);
} catch (exception) {
err = {
buffer : bodyBuffer,
exception : exception,
};
span.setTag('error', true);
span.log({
event : 'error',
'error.object': err,
});
}
callbackWrapper(err, parsedJSON);
});
});
} catch (exception) {
span.setTag('error', true);
span.log({
event : 'error',
'error.object': exception,
});
callbackWrapper(exception, null);
}
}
|
javascript
|
function httpGet(parentSpan, urlString, callback) {
var span = opentracing.globalTracer().startSpan('http.get', { childOf : parentSpan });
var callbackWrapper = function (err, data) {
span.finish();
callback(err, data);
};
try {
var carrier = {};
opentracing.globalTracer().inject(span, opentracing.FORMAT_TEXT_MAP, carrier);
var dest = url.parse(urlString);
var options = {
host : PROXY_HOST,
path : dest.path,
port : PROXY_PORT,
headers: {
// User-Agent is required by the GitHub APIs
'User-Agent': 'LightStep Example',
}
};
for (var key in carrier) {
options.headers[key] = carrier[key];
}
// Create a span representing the https request
span.setTag('url', urlString);
span.log({
event : 'options',
'options': options,
});
return http.get(options, function(response) {
var bodyBuffer = '';
response.on('data', function(chunk) {
bodyBuffer += chunk;
});
response.on('end', function() {
span.log({
body : bodyBuffer,
length : bodyBuffer.length,
});
var parsedJSON, err;
try {
parsedJSON = JSON.parse(bodyBuffer);
} catch (exception) {
err = {
buffer : bodyBuffer,
exception : exception,
};
span.setTag('error', true);
span.log({
event : 'error',
'error.object': err,
});
}
callbackWrapper(err, parsedJSON);
});
});
} catch (exception) {
span.setTag('error', true);
span.log({
event : 'error',
'error.object': exception,
});
callbackWrapper(exception, null);
}
}
|
[
"function",
"httpGet",
"(",
"parentSpan",
",",
"urlString",
",",
"callback",
")",
"{",
"var",
"span",
"=",
"opentracing",
".",
"globalTracer",
"(",
")",
".",
"startSpan",
"(",
"'http.get'",
",",
"{",
"childOf",
":",
"parentSpan",
"}",
")",
";",
"var",
"callbackWrapper",
"=",
"function",
"(",
"err",
",",
"data",
")",
"{",
"span",
".",
"finish",
"(",
")",
";",
"callback",
"(",
"err",
",",
"data",
")",
";",
"}",
";",
"try",
"{",
"var",
"carrier",
"=",
"{",
"}",
";",
"opentracing",
".",
"globalTracer",
"(",
")",
".",
"inject",
"(",
"span",
",",
"opentracing",
".",
"FORMAT_TEXT_MAP",
",",
"carrier",
")",
";",
"var",
"dest",
"=",
"url",
".",
"parse",
"(",
"urlString",
")",
";",
"var",
"options",
"=",
"{",
"host",
":",
"PROXY_HOST",
",",
"path",
":",
"dest",
".",
"path",
",",
"port",
":",
"PROXY_PORT",
",",
"headers",
":",
"{",
"// User-Agent is required by the GitHub APIs",
"'User-Agent'",
":",
"'LightStep Example'",
",",
"}",
"}",
";",
"for",
"(",
"var",
"key",
"in",
"carrier",
")",
"{",
"options",
".",
"headers",
"[",
"key",
"]",
"=",
"carrier",
"[",
"key",
"]",
";",
"}",
"// Create a span representing the https request",
"span",
".",
"setTag",
"(",
"'url'",
",",
"urlString",
")",
";",
"span",
".",
"log",
"(",
"{",
"event",
":",
"'options'",
",",
"'options'",
":",
"options",
",",
"}",
")",
";",
"return",
"http",
".",
"get",
"(",
"options",
",",
"function",
"(",
"response",
")",
"{",
"var",
"bodyBuffer",
"=",
"''",
";",
"response",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"chunk",
")",
"{",
"bodyBuffer",
"+=",
"chunk",
";",
"}",
")",
";",
"response",
".",
"on",
"(",
"'end'",
",",
"function",
"(",
")",
"{",
"span",
".",
"log",
"(",
"{",
"body",
":",
"bodyBuffer",
",",
"length",
":",
"bodyBuffer",
".",
"length",
",",
"}",
")",
";",
"var",
"parsedJSON",
",",
"err",
";",
"try",
"{",
"parsedJSON",
"=",
"JSON",
".",
"parse",
"(",
"bodyBuffer",
")",
";",
"}",
"catch",
"(",
"exception",
")",
"{",
"err",
"=",
"{",
"buffer",
":",
"bodyBuffer",
",",
"exception",
":",
"exception",
",",
"}",
";",
"span",
".",
"setTag",
"(",
"'error'",
",",
"true",
")",
";",
"span",
".",
"log",
"(",
"{",
"event",
":",
"'error'",
",",
"'error.object'",
":",
"err",
",",
"}",
")",
";",
"}",
"callbackWrapper",
"(",
"err",
",",
"parsedJSON",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
"catch",
"(",
"exception",
")",
"{",
"span",
".",
"setTag",
"(",
"'error'",
",",
"true",
")",
";",
"span",
".",
"log",
"(",
"{",
"event",
":",
"'error'",
",",
"'error.object'",
":",
"exception",
",",
"}",
")",
";",
"callbackWrapper",
"(",
"exception",
",",
"null",
")",
";",
"}",
"}"
] |
Helper function to make a GET request and return parsed JSON data.
|
[
"Helper",
"function",
"to",
"make",
"a",
"GET",
"request",
"and",
"return",
"parsed",
"JSON",
"data",
"."
] |
648797fbf02ad78eb567665ee7e6e4f83c98a0c3
|
https://github.com/lightstep/lightstep-tracer-javascript/blob/648797fbf02ad78eb567665ee7e6e4f83c98a0c3/examples/node/index.js#L171-L239
|
15,566
|
patosai/tree-multiselect.js
|
src/tree-multiselect/utility/array.js
|
filterInPlace
|
function filterInPlace (arr, pred) {
var idx = 0;
for (var ii = 0; ii < arr.length; ++ii) {
if (pred(arr[ii])) {
arr[idx] = arr[ii];
++idx;
}
}
arr.length = idx;
}
|
javascript
|
function filterInPlace (arr, pred) {
var idx = 0;
for (var ii = 0; ii < arr.length; ++ii) {
if (pred(arr[ii])) {
arr[idx] = arr[ii];
++idx;
}
}
arr.length = idx;
}
|
[
"function",
"filterInPlace",
"(",
"arr",
",",
"pred",
")",
"{",
"var",
"idx",
"=",
"0",
";",
"for",
"(",
"var",
"ii",
"=",
"0",
";",
"ii",
"<",
"arr",
".",
"length",
";",
"++",
"ii",
")",
"{",
"if",
"(",
"pred",
"(",
"arr",
"[",
"ii",
"]",
")",
")",
"{",
"arr",
"[",
"idx",
"]",
"=",
"arr",
"[",
"ii",
"]",
";",
"++",
"idx",
";",
"}",
"}",
"arr",
".",
"length",
"=",
"idx",
";",
"}"
] |
keeps if pred is true
|
[
"keeps",
"if",
"pred",
"is",
"true"
] |
0eca6336c7f41866618edb3ef7b1f46528627b72
|
https://github.com/patosai/tree-multiselect.js/blob/0eca6336c7f41866618edb3ef7b1f46528627b72/src/tree-multiselect/utility/array.js#L2-L11
|
15,567
|
ProseMirror/prosemirror-model
|
src/from_dom.js
|
normalizeList
|
function normalizeList(dom) {
for (let child = dom.firstChild, prevItem = null; child; child = child.nextSibling) {
let name = child.nodeType == 1 ? child.nodeName.toLowerCase() : null
if (name && listTags.hasOwnProperty(name) && prevItem) {
prevItem.appendChild(child)
child = prevItem
} else if (name == "li") {
prevItem = child
} else if (name) {
prevItem = null
}
}
}
|
javascript
|
function normalizeList(dom) {
for (let child = dom.firstChild, prevItem = null; child; child = child.nextSibling) {
let name = child.nodeType == 1 ? child.nodeName.toLowerCase() : null
if (name && listTags.hasOwnProperty(name) && prevItem) {
prevItem.appendChild(child)
child = prevItem
} else if (name == "li") {
prevItem = child
} else if (name) {
prevItem = null
}
}
}
|
[
"function",
"normalizeList",
"(",
"dom",
")",
"{",
"for",
"(",
"let",
"child",
"=",
"dom",
".",
"firstChild",
",",
"prevItem",
"=",
"null",
";",
"child",
";",
"child",
"=",
"child",
".",
"nextSibling",
")",
"{",
"let",
"name",
"=",
"child",
".",
"nodeType",
"==",
"1",
"?",
"child",
".",
"nodeName",
".",
"toLowerCase",
"(",
")",
":",
"null",
"if",
"(",
"name",
"&&",
"listTags",
".",
"hasOwnProperty",
"(",
"name",
")",
"&&",
"prevItem",
")",
"{",
"prevItem",
".",
"appendChild",
"(",
"child",
")",
"child",
"=",
"prevItem",
"}",
"else",
"if",
"(",
"name",
"==",
"\"li\"",
")",
"{",
"prevItem",
"=",
"child",
"}",
"else",
"if",
"(",
"name",
")",
"{",
"prevItem",
"=",
"null",
"}",
"}",
"}"
] |
Kludge to work around directly nested list nodes produced by some tools and allowed by browsers to mean that the nested list is actually part of the list item above it.
|
[
"Kludge",
"to",
"work",
"around",
"directly",
"nested",
"list",
"nodes",
"produced",
"by",
"some",
"tools",
"and",
"allowed",
"by",
"browsers",
"to",
"mean",
"that",
"the",
"nested",
"list",
"is",
"actually",
"part",
"of",
"the",
"list",
"item",
"above",
"it",
"."
] |
8bf01f1b58e81ffabf64e2944538fca80fc578d8
|
https://github.com/ProseMirror/prosemirror-model/blob/8bf01f1b58e81ffabf64e2944538fca80fc578d8/src/from_dom.js#L692-L704
|
15,568
|
ProseMirror/prosemirror-model
|
src/from_dom.js
|
matches
|
function matches(dom, selector) {
return (dom.matches || dom.msMatchesSelector || dom.webkitMatchesSelector || dom.mozMatchesSelector).call(dom, selector)
}
|
javascript
|
function matches(dom, selector) {
return (dom.matches || dom.msMatchesSelector || dom.webkitMatchesSelector || dom.mozMatchesSelector).call(dom, selector)
}
|
[
"function",
"matches",
"(",
"dom",
",",
"selector",
")",
"{",
"return",
"(",
"dom",
".",
"matches",
"||",
"dom",
".",
"msMatchesSelector",
"||",
"dom",
".",
"webkitMatchesSelector",
"||",
"dom",
".",
"mozMatchesSelector",
")",
".",
"call",
"(",
"dom",
",",
"selector",
")",
"}"
] |
Apply a CSS selector.
|
[
"Apply",
"a",
"CSS",
"selector",
"."
] |
8bf01f1b58e81ffabf64e2944538fca80fc578d8
|
https://github.com/ProseMirror/prosemirror-model/blob/8bf01f1b58e81ffabf64e2944538fca80fc578d8/src/from_dom.js#L707-L709
|
15,569
|
ProseMirror/prosemirror-model
|
src/content.js
|
nullFrom
|
function nullFrom(nfa, node) {
let result = []
scan(node)
return result.sort(cmp)
function scan(node) {
let edges = nfa[node]
if (edges.length == 1 && !edges[0].term) return scan(edges[0].to)
result.push(node)
for (let i = 0; i < edges.length; i++) {
let {term, to} = edges[i]
if (!term && result.indexOf(to) == -1) scan(to)
}
}
}
|
javascript
|
function nullFrom(nfa, node) {
let result = []
scan(node)
return result.sort(cmp)
function scan(node) {
let edges = nfa[node]
if (edges.length == 1 && !edges[0].term) return scan(edges[0].to)
result.push(node)
for (let i = 0; i < edges.length; i++) {
let {term, to} = edges[i]
if (!term && result.indexOf(to) == -1) scan(to)
}
}
}
|
[
"function",
"nullFrom",
"(",
"nfa",
",",
"node",
")",
"{",
"let",
"result",
"=",
"[",
"]",
"scan",
"(",
"node",
")",
"return",
"result",
".",
"sort",
"(",
"cmp",
")",
"function",
"scan",
"(",
"node",
")",
"{",
"let",
"edges",
"=",
"nfa",
"[",
"node",
"]",
"if",
"(",
"edges",
".",
"length",
"==",
"1",
"&&",
"!",
"edges",
"[",
"0",
"]",
".",
"term",
")",
"return",
"scan",
"(",
"edges",
"[",
"0",
"]",
".",
"to",
")",
"result",
".",
"push",
"(",
"node",
")",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"edges",
".",
"length",
";",
"i",
"++",
")",
"{",
"let",
"{",
"term",
",",
"to",
"}",
"=",
"edges",
"[",
"i",
"]",
"if",
"(",
"!",
"term",
"&&",
"result",
".",
"indexOf",
"(",
"to",
")",
"==",
"-",
"1",
")",
"scan",
"(",
"to",
")",
"}",
"}",
"}"
] |
Get the set of nodes reachable by null edges from `node`. Omit nodes with only a single null-out-edge, since they may lead to needless duplicated nodes.
|
[
"Get",
"the",
"set",
"of",
"nodes",
"reachable",
"by",
"null",
"edges",
"from",
"node",
".",
"Omit",
"nodes",
"with",
"only",
"a",
"single",
"null",
"-",
"out",
"-",
"edge",
"since",
"they",
"may",
"lead",
"to",
"needless",
"duplicated",
"nodes",
"."
] |
8bf01f1b58e81ffabf64e2944538fca80fc578d8
|
https://github.com/ProseMirror/prosemirror-model/blob/8bf01f1b58e81ffabf64e2944538fca80fc578d8/src/content.js#L333-L347
|
15,570
|
orbotix/sphero.js
|
examples/conway.js
|
connect
|
function connect(orbs, callback) {
var total = Object.keys(orbs).length,
finished = 0;
function done() {
finished++;
if (finished >= total) { callback(); }
}
for (var name in orbs) {
orbs[name].connect(done);
}
}
|
javascript
|
function connect(orbs, callback) {
var total = Object.keys(orbs).length,
finished = 0;
function done() {
finished++;
if (finished >= total) { callback(); }
}
for (var name in orbs) {
orbs[name].connect(done);
}
}
|
[
"function",
"connect",
"(",
"orbs",
",",
"callback",
")",
"{",
"var",
"total",
"=",
"Object",
".",
"keys",
"(",
"orbs",
")",
".",
"length",
",",
"finished",
"=",
"0",
";",
"function",
"done",
"(",
")",
"{",
"finished",
"++",
";",
"if",
"(",
"finished",
">=",
"total",
")",
"{",
"callback",
"(",
")",
";",
"}",
"}",
"for",
"(",
"var",
"name",
"in",
"orbs",
")",
"{",
"orbs",
"[",
"name",
"]",
".",
"connect",
"(",
"done",
")",
";",
"}",
"}"
] |
connects all spheros, triggering callback when done
|
[
"connects",
"all",
"spheros",
"triggering",
"callback",
"when",
"done"
] |
75ccac9caaa823da2ff816c27afac509c34dafc5
|
https://github.com/orbotix/sphero.js/blob/75ccac9caaa823da2ff816c27afac509c34dafc5/examples/conway.js#L22-L34
|
15,571
|
orbotix/sphero.js
|
examples/conway.js
|
start
|
function start(name) {
var orb = spheros[name],
contacts = 0,
age = 0,
alive = false;
orb.detectCollisions();
born();
orb.on("collision", function() { contacts += 1; });
setInterval(function() { if (alive) { move(); } }, 3000);
setInterval(birthday, 10000);
// roll Sphero in a random direction
function move() {
orb.roll(60, Math.floor(Math.random() * 360));
}
// stop Sphero
function stop() {
orb.stop();
}
// set Sphero's color
function color(str) {
orb.color(str);
}
function born() {
contacts = 0;
age = 0;
life();
move();
}
function life() {
alive = true;
color("green");
}
function death() {
alive = false;
color("red");
stop();
}
function enoughContacts() {
return contacts >= 2 && contacts < 7;
}
function birthday() {
age += 1;
if (alive) {
console.log("Happy birthday,", name);
console.log("You are", age, "and had", contacts, "contacts.");
}
if (enoughContacts()) {
if (!alive) { born(); }
} else {
death();
}
}
}
|
javascript
|
function start(name) {
var orb = spheros[name],
contacts = 0,
age = 0,
alive = false;
orb.detectCollisions();
born();
orb.on("collision", function() { contacts += 1; });
setInterval(function() { if (alive) { move(); } }, 3000);
setInterval(birthday, 10000);
// roll Sphero in a random direction
function move() {
orb.roll(60, Math.floor(Math.random() * 360));
}
// stop Sphero
function stop() {
orb.stop();
}
// set Sphero's color
function color(str) {
orb.color(str);
}
function born() {
contacts = 0;
age = 0;
life();
move();
}
function life() {
alive = true;
color("green");
}
function death() {
alive = false;
color("red");
stop();
}
function enoughContacts() {
return contacts >= 2 && contacts < 7;
}
function birthday() {
age += 1;
if (alive) {
console.log("Happy birthday,", name);
console.log("You are", age, "and had", contacts, "contacts.");
}
if (enoughContacts()) {
if (!alive) { born(); }
} else {
death();
}
}
}
|
[
"function",
"start",
"(",
"name",
")",
"{",
"var",
"orb",
"=",
"spheros",
"[",
"name",
"]",
",",
"contacts",
"=",
"0",
",",
"age",
"=",
"0",
",",
"alive",
"=",
"false",
";",
"orb",
".",
"detectCollisions",
"(",
")",
";",
"born",
"(",
")",
";",
"orb",
".",
"on",
"(",
"\"collision\"",
",",
"function",
"(",
")",
"{",
"contacts",
"+=",
"1",
";",
"}",
")",
";",
"setInterval",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"alive",
")",
"{",
"move",
"(",
")",
";",
"}",
"}",
",",
"3000",
")",
";",
"setInterval",
"(",
"birthday",
",",
"10000",
")",
";",
"// roll Sphero in a random direction",
"function",
"move",
"(",
")",
"{",
"orb",
".",
"roll",
"(",
"60",
",",
"Math",
".",
"floor",
"(",
"Math",
".",
"random",
"(",
")",
"*",
"360",
")",
")",
";",
"}",
"// stop Sphero",
"function",
"stop",
"(",
")",
"{",
"orb",
".",
"stop",
"(",
")",
";",
"}",
"// set Sphero's color",
"function",
"color",
"(",
"str",
")",
"{",
"orb",
".",
"color",
"(",
"str",
")",
";",
"}",
"function",
"born",
"(",
")",
"{",
"contacts",
"=",
"0",
";",
"age",
"=",
"0",
";",
"life",
"(",
")",
";",
"move",
"(",
")",
";",
"}",
"function",
"life",
"(",
")",
"{",
"alive",
"=",
"true",
";",
"color",
"(",
"\"green\"",
")",
";",
"}",
"function",
"death",
"(",
")",
"{",
"alive",
"=",
"false",
";",
"color",
"(",
"\"red\"",
")",
";",
"stop",
"(",
")",
";",
"}",
"function",
"enoughContacts",
"(",
")",
"{",
"return",
"contacts",
">=",
"2",
"&&",
"contacts",
"<",
"7",
";",
"}",
"function",
"birthday",
"(",
")",
"{",
"age",
"+=",
"1",
";",
"if",
"(",
"alive",
")",
"{",
"console",
".",
"log",
"(",
"\"Happy birthday,\"",
",",
"name",
")",
";",
"console",
".",
"log",
"(",
"\"You are\"",
",",
"age",
",",
"\"and had\"",
",",
"contacts",
",",
"\"contacts.\"",
")",
";",
"}",
"if",
"(",
"enoughContacts",
"(",
")",
")",
"{",
"if",
"(",
"!",
"alive",
")",
"{",
"born",
"(",
")",
";",
"}",
"}",
"else",
"{",
"death",
"(",
")",
";",
"}",
"}",
"}"
] |
tells each Sphero what to do
|
[
"tells",
"each",
"Sphero",
"what",
"to",
"do"
] |
75ccac9caaa823da2ff816c27afac509c34dafc5
|
https://github.com/orbotix/sphero.js/blob/75ccac9caaa823da2ff816c27afac509c34dafc5/examples/conway.js#L37-L103
|
15,572
|
orbotix/sphero.js
|
lib/devices/custom.js
|
calculateLuminance
|
function calculateLuminance(hex, lum) {
return Math.round(Math.min(Math.max(0, hex + (hex * lum)), 255));
}
|
javascript
|
function calculateLuminance(hex, lum) {
return Math.round(Math.min(Math.max(0, hex + (hex * lum)), 255));
}
|
[
"function",
"calculateLuminance",
"(",
"hex",
",",
"lum",
")",
"{",
"return",
"Math",
".",
"round",
"(",
"Math",
".",
"min",
"(",
"Math",
".",
"max",
"(",
"0",
",",
"hex",
"+",
"(",
"hex",
"*",
"lum",
")",
")",
",",
"255",
")",
")",
";",
"}"
] |
Converts a hex color number to luminance adjusted value
@private
@param {Object} hex hex color value to convert
@param {Number} lum percentage of luminance
@return {Object} converted color value
|
[
"Converts",
"a",
"hex",
"color",
"number",
"to",
"luminance",
"adjusted",
"value"
] |
75ccac9caaa823da2ff816c27afac509c34dafc5
|
https://github.com/orbotix/sphero.js/blob/75ccac9caaa823da2ff816c27afac509c34dafc5/lib/devices/custom.js#L36-L38
|
15,573
|
orbotix/sphero.js
|
lib/devices/custom.js
|
adjustLuminance
|
function adjustLuminance(rgb, lum) {
var newRgb = {};
newRgb.red = calculateLuminance(rgb.red, lum);
newRgb.green = calculateLuminance(rgb.green, lum);
newRgb.blue = calculateLuminance(rgb.blue, lum);
return newRgb;
}
|
javascript
|
function adjustLuminance(rgb, lum) {
var newRgb = {};
newRgb.red = calculateLuminance(rgb.red, lum);
newRgb.green = calculateLuminance(rgb.green, lum);
newRgb.blue = calculateLuminance(rgb.blue, lum);
return newRgb;
}
|
[
"function",
"adjustLuminance",
"(",
"rgb",
",",
"lum",
")",
"{",
"var",
"newRgb",
"=",
"{",
"}",
";",
"newRgb",
".",
"red",
"=",
"calculateLuminance",
"(",
"rgb",
".",
"red",
",",
"lum",
")",
";",
"newRgb",
".",
"green",
"=",
"calculateLuminance",
"(",
"rgb",
".",
"green",
",",
"lum",
")",
";",
"newRgb",
".",
"blue",
"=",
"calculateLuminance",
"(",
"rgb",
".",
"blue",
",",
"lum",
")",
";",
"return",
"newRgb",
";",
"}"
] |
Adjusts an RGB color by the relative luminance
@private
@param {Object} rgb rgb color value to convert
@param {Number} lum percentage of luminance
@return {Object} RGB color values
|
[
"Adjusts",
"an",
"RGB",
"color",
"by",
"the",
"relative",
"luminance"
] |
75ccac9caaa823da2ff816c27afac509c34dafc5
|
https://github.com/orbotix/sphero.js/blob/75ccac9caaa823da2ff816c27afac509c34dafc5/lib/devices/custom.js#L48-L55
|
15,574
|
webdeveric/webpack-assets-manifest
|
src/helpers.js
|
warn
|
function warn( message )
{
if ( message in warn.cache ) {
return;
}
const prefix = chalk.hex('#CC4A8B')('WARNING:');
console.warn(chalk`${prefix} ${message}`);
}
|
javascript
|
function warn( message )
{
if ( message in warn.cache ) {
return;
}
const prefix = chalk.hex('#CC4A8B')('WARNING:');
console.warn(chalk`${prefix} ${message}`);
}
|
[
"function",
"warn",
"(",
"message",
")",
"{",
"if",
"(",
"message",
"in",
"warn",
".",
"cache",
")",
"{",
"return",
";",
"}",
"const",
"prefix",
"=",
"chalk",
".",
"hex",
"(",
"'#CC4A8B'",
")",
"(",
"'WARNING:'",
")",
";",
"console",
".",
"warn",
"(",
"chalk",
"`",
"${",
"prefix",
"}",
"${",
"message",
"}",
"`",
")",
";",
"}"
] |
Display a warning message.
@param {string} message
|
[
"Display",
"a",
"warning",
"message",
"."
] |
051243ec8963be69ab8565b5998032cc3a020a7a
|
https://github.com/webdeveric/webpack-assets-manifest/blob/051243ec8963be69ab8565b5998032cc3a020a7a/src/helpers.js#L9-L18
|
15,575
|
webdeveric/webpack-assets-manifest
|
src/helpers.js
|
filterHashes
|
function filterHashes( hashes )
{
const validHashes = crypto.getHashes();
return hashes.filter( hash => {
if ( validHashes.includes(hash) ) {
return true;
}
warn(chalk`{blueBright ${hash}} is not a supported hash algorithm`);
return false;
});
}
|
javascript
|
function filterHashes( hashes )
{
const validHashes = crypto.getHashes();
return hashes.filter( hash => {
if ( validHashes.includes(hash) ) {
return true;
}
warn(chalk`{blueBright ${hash}} is not a supported hash algorithm`);
return false;
});
}
|
[
"function",
"filterHashes",
"(",
"hashes",
")",
"{",
"const",
"validHashes",
"=",
"crypto",
".",
"getHashes",
"(",
")",
";",
"return",
"hashes",
".",
"filter",
"(",
"hash",
"=>",
"{",
"if",
"(",
"validHashes",
".",
"includes",
"(",
"hash",
")",
")",
"{",
"return",
"true",
";",
"}",
"warn",
"(",
"chalk",
"`",
"${",
"hash",
"}",
"`",
")",
";",
"return",
"false",
";",
"}",
")",
";",
"}"
] |
Filter out invalid hash algorithms.
@param {array} hashes
@return {array} Valid hash algorithms
|
[
"Filter",
"out",
"invalid",
"hash",
"algorithms",
"."
] |
051243ec8963be69ab8565b5998032cc3a020a7a
|
https://github.com/webdeveric/webpack-assets-manifest/blob/051243ec8963be69ab8565b5998032cc3a020a7a/src/helpers.js#L47-L60
|
15,576
|
webdeveric/webpack-assets-manifest
|
src/helpers.js
|
varType
|
function varType( v )
{
const [ , type ] = Object.prototype.toString.call( v ).match(/\[object\s(\w+)\]/);
return type;
}
|
javascript
|
function varType( v )
{
const [ , type ] = Object.prototype.toString.call( v ).match(/\[object\s(\w+)\]/);
return type;
}
|
[
"function",
"varType",
"(",
"v",
")",
"{",
"const",
"[",
",",
"type",
"]",
"=",
"Object",
".",
"prototype",
".",
"toString",
".",
"call",
"(",
"v",
")",
".",
"match",
"(",
"/",
"\\[object\\s(\\w+)\\]",
"/",
")",
";",
"return",
"type",
";",
"}"
] |
Get the data type of an argument.
@param {*} v - Some variable
@return {string} Data type
|
[
"Get",
"the",
"data",
"type",
"of",
"an",
"argument",
"."
] |
051243ec8963be69ab8565b5998032cc3a020a7a
|
https://github.com/webdeveric/webpack-assets-manifest/blob/051243ec8963be69ab8565b5998032cc3a020a7a/src/helpers.js#L84-L89
|
15,577
|
webdeveric/webpack-assets-manifest
|
src/helpers.js
|
getSortedObject
|
function getSortedObject(object, compareFunction)
{
const keys = Object.keys(object);
keys.sort( compareFunction );
return keys.reduce(
(sorted, key) => (sorted[ key ] = object[ key ], sorted),
Object.create(null)
);
}
|
javascript
|
function getSortedObject(object, compareFunction)
{
const keys = Object.keys(object);
keys.sort( compareFunction );
return keys.reduce(
(sorted, key) => (sorted[ key ] = object[ key ], sorted),
Object.create(null)
);
}
|
[
"function",
"getSortedObject",
"(",
"object",
",",
"compareFunction",
")",
"{",
"const",
"keys",
"=",
"Object",
".",
"keys",
"(",
"object",
")",
";",
"keys",
".",
"sort",
"(",
"compareFunction",
")",
";",
"return",
"keys",
".",
"reduce",
"(",
"(",
"sorted",
",",
"key",
")",
"=>",
"(",
"sorted",
"[",
"key",
"]",
"=",
"object",
"[",
"key",
"]",
",",
"sorted",
")",
",",
"Object",
".",
"create",
"(",
"null",
")",
")",
";",
"}"
] |
Get an object sorted by keys.
@param {object} object
@param {function} compareFunction
@return {object}
|
[
"Get",
"an",
"object",
"sorted",
"by",
"keys",
"."
] |
051243ec8963be69ab8565b5998032cc3a020a7a
|
https://github.com/webdeveric/webpack-assets-manifest/blob/051243ec8963be69ab8565b5998032cc3a020a7a/src/helpers.js#L98-L108
|
15,578
|
patternfly/patternfly-ng
|
config/html-elements-plugin/index.js
|
createTag
|
function createTag(tagName, attrMap, publicPath) {
publicPath = publicPath || '';
// add trailing slash if we have a publicPath and it doesn't have one.
if (publicPath && !RE_ENDS_WITH_BS.test(publicPath)) {
publicPath += '/';
}
const attributes = Object.getOwnPropertyNames(attrMap)
.filter(function(name) { return name[0] !== '='; } )
.map(function(name) {
var value = attrMap[name];
if (publicPath) {
// check if we have explicit instruction, use it if so (e.g: =herf: false)
// if no instruction, use public path if it's href attribute.
const usePublicPath = attrMap.hasOwnProperty('=' + name) ? !!attrMap['=' + name] : name === 'href';
if (usePublicPath) {
// remove a starting trailing slash if the value has one so we wont have //
value = publicPath + (value[0] === '/' ? value.substr(1) : value);
}
}
return `${name}="${value}"`;
});
const closingTag = tagName === 'script' ? '</script>' : '';
return `<${tagName} ${attributes.join(' ')}>${closingTag}`;
}
|
javascript
|
function createTag(tagName, attrMap, publicPath) {
publicPath = publicPath || '';
// add trailing slash if we have a publicPath and it doesn't have one.
if (publicPath && !RE_ENDS_WITH_BS.test(publicPath)) {
publicPath += '/';
}
const attributes = Object.getOwnPropertyNames(attrMap)
.filter(function(name) { return name[0] !== '='; } )
.map(function(name) {
var value = attrMap[name];
if (publicPath) {
// check if we have explicit instruction, use it if so (e.g: =herf: false)
// if no instruction, use public path if it's href attribute.
const usePublicPath = attrMap.hasOwnProperty('=' + name) ? !!attrMap['=' + name] : name === 'href';
if (usePublicPath) {
// remove a starting trailing slash if the value has one so we wont have //
value = publicPath + (value[0] === '/' ? value.substr(1) : value);
}
}
return `${name}="${value}"`;
});
const closingTag = tagName === 'script' ? '</script>' : '';
return `<${tagName} ${attributes.join(' ')}>${closingTag}`;
}
|
[
"function",
"createTag",
"(",
"tagName",
",",
"attrMap",
",",
"publicPath",
")",
"{",
"publicPath",
"=",
"publicPath",
"||",
"''",
";",
"// add trailing slash if we have a publicPath and it doesn't have one.",
"if",
"(",
"publicPath",
"&&",
"!",
"RE_ENDS_WITH_BS",
".",
"test",
"(",
"publicPath",
")",
")",
"{",
"publicPath",
"+=",
"'/'",
";",
"}",
"const",
"attributes",
"=",
"Object",
".",
"getOwnPropertyNames",
"(",
"attrMap",
")",
".",
"filter",
"(",
"function",
"(",
"name",
")",
"{",
"return",
"name",
"[",
"0",
"]",
"!==",
"'='",
";",
"}",
")",
".",
"map",
"(",
"function",
"(",
"name",
")",
"{",
"var",
"value",
"=",
"attrMap",
"[",
"name",
"]",
";",
"if",
"(",
"publicPath",
")",
"{",
"// check if we have explicit instruction, use it if so (e.g: =herf: false)",
"// if no instruction, use public path if it's href attribute.",
"const",
"usePublicPath",
"=",
"attrMap",
".",
"hasOwnProperty",
"(",
"'='",
"+",
"name",
")",
"?",
"!",
"!",
"attrMap",
"[",
"'='",
"+",
"name",
"]",
":",
"name",
"===",
"'href'",
";",
"if",
"(",
"usePublicPath",
")",
"{",
"// remove a starting trailing slash if the value has one so we wont have //",
"value",
"=",
"publicPath",
"+",
"(",
"value",
"[",
"0",
"]",
"===",
"'/'",
"?",
"value",
".",
"substr",
"(",
"1",
")",
":",
"value",
")",
";",
"}",
"}",
"return",
"`",
"${",
"name",
"}",
"${",
"value",
"}",
"`",
";",
"}",
")",
";",
"const",
"closingTag",
"=",
"tagName",
"===",
"'script'",
"?",
"'</script>'",
":",
"''",
";",
"return",
"`",
"${",
"tagName",
"}",
"${",
"attributes",
".",
"join",
"(",
"' '",
")",
"}",
"${",
"closingTag",
"}",
"`",
";",
"}"
] |
Create an HTML tag with attributes from a map.
Example:
createTag('link', { rel: "manifest", href: "/assets/manifest.json" })
// <link rel="manifest" href="/assets/manifest.json">
@param tagName The name of the tag
@param attrMap A Map of attribute names (keys) and their values.
@param publicPath a path to add to eh start of static asset url
@returns {string}
|
[
"Create",
"an",
"HTML",
"tag",
"with",
"attributes",
"from",
"a",
"map",
"."
] |
06e46d70834d90ef275ddf85bd5e311410c8c943
|
https://github.com/patternfly/patternfly-ng/blob/06e46d70834d90ef275ddf85bd5e311410c8c943/config/html-elements-plugin/index.js#L42-L72
|
15,579
|
patternfly/patternfly-ng
|
config/html-elements-plugin/index.js
|
getHtmlElementString
|
function getHtmlElementString(dataSource, publicPath) {
return Object.getOwnPropertyNames(dataSource)
.map(function(name) {
if (Array.isArray(dataSource[name])) {
return dataSource[name].map(function(attrs) { return createTag(name, attrs, publicPath); } );
} else {
return [ createTag(name, dataSource[name], publicPath) ];
}
})
.reduce(function(arr, curr) {
return arr.concat(curr);
}, [])
.join('\n\t');
}
|
javascript
|
function getHtmlElementString(dataSource, publicPath) {
return Object.getOwnPropertyNames(dataSource)
.map(function(name) {
if (Array.isArray(dataSource[name])) {
return dataSource[name].map(function(attrs) { return createTag(name, attrs, publicPath); } );
} else {
return [ createTag(name, dataSource[name], publicPath) ];
}
})
.reduce(function(arr, curr) {
return arr.concat(curr);
}, [])
.join('\n\t');
}
|
[
"function",
"getHtmlElementString",
"(",
"dataSource",
",",
"publicPath",
")",
"{",
"return",
"Object",
".",
"getOwnPropertyNames",
"(",
"dataSource",
")",
".",
"map",
"(",
"function",
"(",
"name",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"dataSource",
"[",
"name",
"]",
")",
")",
"{",
"return",
"dataSource",
"[",
"name",
"]",
".",
"map",
"(",
"function",
"(",
"attrs",
")",
"{",
"return",
"createTag",
"(",
"name",
",",
"attrs",
",",
"publicPath",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"return",
"[",
"createTag",
"(",
"name",
",",
"dataSource",
"[",
"name",
"]",
",",
"publicPath",
")",
"]",
";",
"}",
"}",
")",
".",
"reduce",
"(",
"function",
"(",
"arr",
",",
"curr",
")",
"{",
"return",
"arr",
".",
"concat",
"(",
"curr",
")",
";",
"}",
",",
"[",
"]",
")",
".",
"join",
"(",
"'\\n\\t'",
")",
";",
"}"
] |
Returns a string representing all html elements defined in a data source.
Example:
const ds = {
link: [
{ rel: "apple-touch-icon", sizes: "57x57", href: "/assets/icon/apple-icon-57x57.png" }
],
meta: [
{ name: "msapplication-TileColor", content: "#00bcd4" }
]
}
getHeadTags(ds);
// "<link rel="apple-touch-icon" sizes="57x57" href="/assets/icon/apple-icon-57x57.png">"
"<meta name="msapplication-TileColor" content="#00bcd4">"
@returns {string}
|
[
"Returns",
"a",
"string",
"representing",
"all",
"html",
"elements",
"defined",
"in",
"a",
"data",
"source",
"."
] |
06e46d70834d90ef275ddf85bd5e311410c8c943
|
https://github.com/patternfly/patternfly-ng/blob/06e46d70834d90ef275ddf85bd5e311410c8c943/config/html-elements-plugin/index.js#L94-L107
|
15,580
|
patternfly/patternfly-ng
|
gulpfile.js
|
copyToDemo
|
function copyToDemo(srcArr) {
return gulp.src(srcArr)
.pipe(gulp.dest(function (file) {
return demoDist + file.base.slice(__dirname.length); // save directly to demo
}));
}
|
javascript
|
function copyToDemo(srcArr) {
return gulp.src(srcArr)
.pipe(gulp.dest(function (file) {
return demoDist + file.base.slice(__dirname.length); // save directly to demo
}));
}
|
[
"function",
"copyToDemo",
"(",
"srcArr",
")",
"{",
"return",
"gulp",
".",
"src",
"(",
"srcArr",
")",
".",
"pipe",
"(",
"gulp",
".",
"dest",
"(",
"function",
"(",
"file",
")",
"{",
"return",
"demoDist",
"+",
"file",
".",
"base",
".",
"slice",
"(",
"__dirname",
".",
"length",
")",
";",
"// save directly to demo",
"}",
")",
")",
";",
"}"
] |
Copy given files to demo directory
|
[
"Copy",
"given",
"files",
"to",
"demo",
"directory"
] |
06e46d70834d90ef275ddf85bd5e311410c8c943
|
https://github.com/patternfly/patternfly-ng/blob/06e46d70834d90ef275ddf85bd5e311410c8c943/gulpfile.js#L55-L60
|
15,581
|
patternfly/patternfly-ng
|
gulpfile.js
|
copyToDist
|
function copyToDist(srcArr) {
return gulp.src(srcArr.concat(globalExcludes))
.pipe(gulp.dest(function (file) {
return libraryDist + file.base.slice(__dirname.length); // save directly to dist
}));
}
|
javascript
|
function copyToDist(srcArr) {
return gulp.src(srcArr.concat(globalExcludes))
.pipe(gulp.dest(function (file) {
return libraryDist + file.base.slice(__dirname.length); // save directly to dist
}));
}
|
[
"function",
"copyToDist",
"(",
"srcArr",
")",
"{",
"return",
"gulp",
".",
"src",
"(",
"srcArr",
".",
"concat",
"(",
"globalExcludes",
")",
")",
".",
"pipe",
"(",
"gulp",
".",
"dest",
"(",
"function",
"(",
"file",
")",
"{",
"return",
"libraryDist",
"+",
"file",
".",
"base",
".",
"slice",
"(",
"__dirname",
".",
"length",
")",
";",
"// save directly to dist",
"}",
")",
")",
";",
"}"
] |
Copy given files to dist directory
|
[
"Copy",
"given",
"files",
"to",
"dist",
"directory"
] |
06e46d70834d90ef275ddf85bd5e311410c8c943
|
https://github.com/patternfly/patternfly-ng/blob/06e46d70834d90ef275ddf85bd5e311410c8c943/gulpfile.js#L63-L68
|
15,582
|
patternfly/patternfly-ng
|
gulpfile.js
|
transpileMinifyLESS
|
function transpileMinifyLESS(src) {
return gulp.src(src)
.pipe(sourcemaps.init())
.pipe(lessCompiler({
paths: [ path.join(__dirname, 'less', 'includes') ]
}))
.pipe(cssmin().on('error', function(err) {
console.log(err);
}))
.pipe(rename({suffix: '.min'}))
.pipe(sourcemaps.write())
.pipe(gulp.dest(function (file) {
return __dirname + file.base.slice(__dirname.length);
}));
}
|
javascript
|
function transpileMinifyLESS(src) {
return gulp.src(src)
.pipe(sourcemaps.init())
.pipe(lessCompiler({
paths: [ path.join(__dirname, 'less', 'includes') ]
}))
.pipe(cssmin().on('error', function(err) {
console.log(err);
}))
.pipe(rename({suffix: '.min'}))
.pipe(sourcemaps.write())
.pipe(gulp.dest(function (file) {
return __dirname + file.base.slice(__dirname.length);
}));
}
|
[
"function",
"transpileMinifyLESS",
"(",
"src",
")",
"{",
"return",
"gulp",
".",
"src",
"(",
"src",
")",
".",
"pipe",
"(",
"sourcemaps",
".",
"init",
"(",
")",
")",
".",
"pipe",
"(",
"lessCompiler",
"(",
"{",
"paths",
":",
"[",
"path",
".",
"join",
"(",
"__dirname",
",",
"'less'",
",",
"'includes'",
")",
"]",
"}",
")",
")",
".",
"pipe",
"(",
"cssmin",
"(",
")",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"err",
")",
"{",
"console",
".",
"log",
"(",
"err",
")",
";",
"}",
")",
")",
".",
"pipe",
"(",
"rename",
"(",
"{",
"suffix",
":",
"'.min'",
"}",
")",
")",
".",
"pipe",
"(",
"sourcemaps",
".",
"write",
"(",
")",
")",
".",
"pipe",
"(",
"gulp",
".",
"dest",
"(",
"function",
"(",
"file",
")",
"{",
"return",
"__dirname",
"+",
"file",
".",
"base",
".",
"slice",
"(",
"__dirname",
".",
"length",
")",
";",
"}",
")",
")",
";",
"}"
] |
Build and minify LESS separately
|
[
"Build",
"and",
"minify",
"LESS",
"separately"
] |
06e46d70834d90ef275ddf85bd5e311410c8c943
|
https://github.com/patternfly/patternfly-ng/blob/06e46d70834d90ef275ddf85bd5e311410c8c943/gulpfile.js#L98-L112
|
15,583
|
patternfly/patternfly-ng
|
gulpfile.js
|
inlineTemplate
|
function inlineTemplate() {
return gulp.src(['./src/app/**/*.ts'].concat(globalExcludes), {base: './'})
.pipe(replace(/templateUrl.*\'/g, function (matched) {
var fileName = matched.match(/\/.*html/g).toString();
var dirName = this.file.relative.substring(0, this.file.relative.lastIndexOf('/'));
var fileContent = fs.readFileSync(dirName + fileName, "utf8");
return 'template: \`' + minifyTemplate(fileContent) + '\`';
}))
.pipe(gulp.dest(libraryBuild));
}
|
javascript
|
function inlineTemplate() {
return gulp.src(['./src/app/**/*.ts'].concat(globalExcludes), {base: './'})
.pipe(replace(/templateUrl.*\'/g, function (matched) {
var fileName = matched.match(/\/.*html/g).toString();
var dirName = this.file.relative.substring(0, this.file.relative.lastIndexOf('/'));
var fileContent = fs.readFileSync(dirName + fileName, "utf8");
return 'template: \`' + minifyTemplate(fileContent) + '\`';
}))
.pipe(gulp.dest(libraryBuild));
}
|
[
"function",
"inlineTemplate",
"(",
")",
"{",
"return",
"gulp",
".",
"src",
"(",
"[",
"'./src/app/**/*.ts'",
"]",
".",
"concat",
"(",
"globalExcludes",
")",
",",
"{",
"base",
":",
"'./'",
"}",
")",
".",
"pipe",
"(",
"replace",
"(",
"/",
"templateUrl.*\\'",
"/",
"g",
",",
"function",
"(",
"matched",
")",
"{",
"var",
"fileName",
"=",
"matched",
".",
"match",
"(",
"/",
"\\/.*html",
"/",
"g",
")",
".",
"toString",
"(",
")",
";",
"var",
"dirName",
"=",
"this",
".",
"file",
".",
"relative",
".",
"substring",
"(",
"0",
",",
"this",
".",
"file",
".",
"relative",
".",
"lastIndexOf",
"(",
"'/'",
")",
")",
";",
"var",
"fileContent",
"=",
"fs",
".",
"readFileSync",
"(",
"dirName",
"+",
"fileName",
",",
"\"utf8\"",
")",
";",
"return",
"'template: \\`'",
"+",
"minifyTemplate",
"(",
"fileContent",
")",
"+",
"'\\`'",
";",
"}",
")",
")",
".",
"pipe",
"(",
"gulp",
".",
"dest",
"(",
"libraryBuild",
")",
")",
";",
"}"
] |
Typescript
Inline HTML templates in component classes
|
[
"Typescript",
"Inline",
"HTML",
"templates",
"in",
"component",
"classes"
] |
06e46d70834d90ef275ddf85bd5e311410c8c943
|
https://github.com/patternfly/patternfly-ng/blob/06e46d70834d90ef275ddf85bd5e311410c8c943/gulpfile.js#L177-L186
|
15,584
|
patternfly/patternfly-ng
|
gulpfile.js
|
transpileAot
|
function transpileAot() {
// https://stackoverflow.com/questions/36897877/gulp-error-the-following-tasks-did-not-complete-did-you-forget-to-signal-async
return new Promise(function(resolve, reject) {
// Need to capture the exit code
exec('node_modules/.bin/ngc -p tsconfig-aot.json', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
if (err !== null) {
process.exit(1);
}
});
resolve();
});
}
|
javascript
|
function transpileAot() {
// https://stackoverflow.com/questions/36897877/gulp-error-the-following-tasks-did-not-complete-did-you-forget-to-signal-async
return new Promise(function(resolve, reject) {
// Need to capture the exit code
exec('node_modules/.bin/ngc -p tsconfig-aot.json', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
if (err !== null) {
process.exit(1);
}
});
resolve();
});
}
|
[
"function",
"transpileAot",
"(",
")",
"{",
"// https://stackoverflow.com/questions/36897877/gulp-error-the-following-tasks-did-not-complete-did-you-forget-to-signal-async",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"// Need to capture the exit code",
"exec",
"(",
"'node_modules/.bin/ngc -p tsconfig-aot.json'",
",",
"function",
"(",
"err",
",",
"stdout",
",",
"stderr",
")",
"{",
"console",
".",
"log",
"(",
"stdout",
")",
";",
"console",
".",
"log",
"(",
"stderr",
")",
";",
"if",
"(",
"err",
"!==",
"null",
")",
"{",
"process",
".",
"exit",
"(",
"1",
")",
";",
"}",
"}",
")",
";",
"resolve",
"(",
")",
";",
"}",
")",
";",
"}"
] |
Build with AOT enabled
|
[
"Build",
"with",
"AOT",
"enabled"
] |
06e46d70834d90ef275ddf85bd5e311410c8c943
|
https://github.com/patternfly/patternfly-ng/blob/06e46d70834d90ef275ddf85bd5e311410c8c943/gulpfile.js#L203-L216
|
15,585
|
patternfly/patternfly-ng
|
gulpfile.js
|
updateWatchDist
|
function updateWatchDist() {
return gulp
.src([libraryDist + '/**'].concat(globalExcludes))
.pipe(changed(watchDist))
.pipe(gulp.dest(watchDist));
}
|
javascript
|
function updateWatchDist() {
return gulp
.src([libraryDist + '/**'].concat(globalExcludes))
.pipe(changed(watchDist))
.pipe(gulp.dest(watchDist));
}
|
[
"function",
"updateWatchDist",
"(",
")",
"{",
"return",
"gulp",
".",
"src",
"(",
"[",
"libraryDist",
"+",
"'/**'",
"]",
".",
"concat",
"(",
"globalExcludes",
")",
")",
".",
"pipe",
"(",
"changed",
"(",
"watchDist",
")",
")",
".",
"pipe",
"(",
"gulp",
".",
"dest",
"(",
"watchDist",
")",
")",
";",
"}"
] |
Update watch dist directory
|
[
"Update",
"watch",
"dist",
"directory"
] |
06e46d70834d90ef275ddf85bd5e311410c8c943
|
https://github.com/patternfly/patternfly-ng/blob/06e46d70834d90ef275ddf85bd5e311410c8c943/gulpfile.js#L240-L245
|
15,586
|
pouchdb-community/socket-pouch
|
lib/client/index.js
|
checkBinaryReady
|
function checkBinaryReady(uuid) {
if (!(uuid in api._blobs && uuid in api._binaryMessages)) {
return;
}
log('receive full binary message', uuid);
var blob = api._blobs[uuid];
var msg = api._binaryMessages[uuid];
delete api._blobs[uuid];
delete api._binaryMessages[uuid];
var blobToDeliver;
if (isBrowser) {
blobToDeliver = blobUtil.createBlob([blob], {type: msg.contentType});
} else {
blobToDeliver = blob;
blob.type = msg.contentType; // non-standard, but we do it for the tests
}
msg.cb(null, blobToDeliver);
}
|
javascript
|
function checkBinaryReady(uuid) {
if (!(uuid in api._blobs && uuid in api._binaryMessages)) {
return;
}
log('receive full binary message', uuid);
var blob = api._blobs[uuid];
var msg = api._binaryMessages[uuid];
delete api._blobs[uuid];
delete api._binaryMessages[uuid];
var blobToDeliver;
if (isBrowser) {
blobToDeliver = blobUtil.createBlob([blob], {type: msg.contentType});
} else {
blobToDeliver = blob;
blob.type = msg.contentType; // non-standard, but we do it for the tests
}
msg.cb(null, blobToDeliver);
}
|
[
"function",
"checkBinaryReady",
"(",
"uuid",
")",
"{",
"if",
"(",
"!",
"(",
"uuid",
"in",
"api",
".",
"_blobs",
"&&",
"uuid",
"in",
"api",
".",
"_binaryMessages",
")",
")",
"{",
"return",
";",
"}",
"log",
"(",
"'receive full binary message'",
",",
"uuid",
")",
";",
"var",
"blob",
"=",
"api",
".",
"_blobs",
"[",
"uuid",
"]",
";",
"var",
"msg",
"=",
"api",
".",
"_binaryMessages",
"[",
"uuid",
"]",
";",
"delete",
"api",
".",
"_blobs",
"[",
"uuid",
"]",
";",
"delete",
"api",
".",
"_binaryMessages",
"[",
"uuid",
"]",
";",
"var",
"blobToDeliver",
";",
"if",
"(",
"isBrowser",
")",
"{",
"blobToDeliver",
"=",
"blobUtil",
".",
"createBlob",
"(",
"[",
"blob",
"]",
",",
"{",
"type",
":",
"msg",
".",
"contentType",
"}",
")",
";",
"}",
"else",
"{",
"blobToDeliver",
"=",
"blob",
";",
"blob",
".",
"type",
"=",
"msg",
".",
"contentType",
";",
"// non-standard, but we do it for the tests",
"}",
"msg",
".",
"cb",
"(",
"null",
",",
"blobToDeliver",
")",
";",
"}"
] |
binary messages come in two parts; wait until we've received both
|
[
"binary",
"messages",
"come",
"in",
"two",
"parts",
";",
"wait",
"until",
"we",
"ve",
"received",
"both"
] |
6911f9a47b41f579708be74c88c8d227f2f8afdd
|
https://github.com/pouchdb-community/socket-pouch/blob/6911f9a47b41f579708be74c88c8d227f2f8afdd/lib/client/index.js#L211-L231
|
15,587
|
leapmotion/leapjs
|
lib/controller.js
|
function(){
if (controller.connection.opts.requestProtocolVersion < 5 && controller.streamingCount == 0){
controller.streamingCount = 1;
var info = {
attached: true,
streaming: true,
type: 'unknown',
id: "Lx00000000000"
};
controller.devices[info.id] = info;
controller.emit('deviceAttached', info);
controller.emit('deviceStreaming', info);
controller.emit('streamingStarted', info);
controller.connection.removeListener('frame', backfillStreamingStartedEventsHandler)
}
}
|
javascript
|
function(){
if (controller.connection.opts.requestProtocolVersion < 5 && controller.streamingCount == 0){
controller.streamingCount = 1;
var info = {
attached: true,
streaming: true,
type: 'unknown',
id: "Lx00000000000"
};
controller.devices[info.id] = info;
controller.emit('deviceAttached', info);
controller.emit('deviceStreaming', info);
controller.emit('streamingStarted', info);
controller.connection.removeListener('frame', backfillStreamingStartedEventsHandler)
}
}
|
[
"function",
"(",
")",
"{",
"if",
"(",
"controller",
".",
"connection",
".",
"opts",
".",
"requestProtocolVersion",
"<",
"5",
"&&",
"controller",
".",
"streamingCount",
"==",
"0",
")",
"{",
"controller",
".",
"streamingCount",
"=",
"1",
";",
"var",
"info",
"=",
"{",
"attached",
":",
"true",
",",
"streaming",
":",
"true",
",",
"type",
":",
"'unknown'",
",",
"id",
":",
"\"Lx00000000000\"",
"}",
";",
"controller",
".",
"devices",
"[",
"info",
".",
"id",
"]",
"=",
"info",
";",
"controller",
".",
"emit",
"(",
"'deviceAttached'",
",",
"info",
")",
";",
"controller",
".",
"emit",
"(",
"'deviceStreaming'",
",",
"info",
")",
";",
"controller",
".",
"emit",
"(",
"'streamingStarted'",
",",
"info",
")",
";",
"controller",
".",
"connection",
".",
"removeListener",
"(",
"'frame'",
",",
"backfillStreamingStartedEventsHandler",
")",
"}",
"}"
] |
here we backfill the 0.5.0 deviceEvents as best possible backfill begin streaming events
|
[
"here",
"we",
"backfill",
"the",
"0",
".",
"5",
".",
"0",
"deviceEvents",
"as",
"best",
"possible",
"backfill",
"begin",
"streaming",
"events"
] |
31b00723f98077304acda3200f9fbcbaaf29294a
|
https://github.com/leapmotion/leapjs/blob/31b00723f98077304acda3200f9fbcbaaf29294a/lib/controller.js#L307-L323
|
|
15,588
|
leapmotion/leapjs
|
lib/gesture.js
|
function(data) {
/**
* The center point of the circle within the Leap frame of reference.
*
* @member center
* @memberof Leap.CircleGesture.prototype
* @type {number[]}
*/
this.center = data.center;
/**
* The normal vector for the circle being traced.
*
* If you draw the circle clockwise, the normal vector points in the same
* general direction as the pointable object drawing the circle. If you draw
* the circle counterclockwise, the normal points back toward the
* pointable. If the angle between the normal and the pointable object
* drawing the circle is less than 90 degrees, then the circle is clockwise.
*
* ```javascript
* var clockwiseness;
* if (circle.pointable.direction.angleTo(circle.normal) <= PI/4) {
* clockwiseness = "clockwise";
* }
* else
* {
* clockwiseness = "counterclockwise";
* }
* ```
*
* @member normal
* @memberof Leap.CircleGesture.prototype
* @type {number[]}
*/
this.normal = data.normal;
/**
* The number of times the finger tip has traversed the circle.
*
* Progress is reported as a positive number of the number. For example,
* a progress value of .5 indicates that the finger has gone halfway
* around, while a value of 3 indicates that the finger has gone around
* the the circle three times.
*
* Progress starts where the circle gesture began. Since the circle
* must be partially formed before the Leap can recognize it, progress
* will be greater than zero when a circle gesture first appears in the
* frame.
*
* @member progress
* @memberof Leap.CircleGesture.prototype
* @type {number}
*/
this.progress = data.progress;
/**
* The radius of the circle in mm.
*
* @member radius
* @memberof Leap.CircleGesture.prototype
* @type {number}
*/
this.radius = data.radius;
}
|
javascript
|
function(data) {
/**
* The center point of the circle within the Leap frame of reference.
*
* @member center
* @memberof Leap.CircleGesture.prototype
* @type {number[]}
*/
this.center = data.center;
/**
* The normal vector for the circle being traced.
*
* If you draw the circle clockwise, the normal vector points in the same
* general direction as the pointable object drawing the circle. If you draw
* the circle counterclockwise, the normal points back toward the
* pointable. If the angle between the normal and the pointable object
* drawing the circle is less than 90 degrees, then the circle is clockwise.
*
* ```javascript
* var clockwiseness;
* if (circle.pointable.direction.angleTo(circle.normal) <= PI/4) {
* clockwiseness = "clockwise";
* }
* else
* {
* clockwiseness = "counterclockwise";
* }
* ```
*
* @member normal
* @memberof Leap.CircleGesture.prototype
* @type {number[]}
*/
this.normal = data.normal;
/**
* The number of times the finger tip has traversed the circle.
*
* Progress is reported as a positive number of the number. For example,
* a progress value of .5 indicates that the finger has gone halfway
* around, while a value of 3 indicates that the finger has gone around
* the the circle three times.
*
* Progress starts where the circle gesture began. Since the circle
* must be partially formed before the Leap can recognize it, progress
* will be greater than zero when a circle gesture first appears in the
* frame.
*
* @member progress
* @memberof Leap.CircleGesture.prototype
* @type {number}
*/
this.progress = data.progress;
/**
* The radius of the circle in mm.
*
* @member radius
* @memberof Leap.CircleGesture.prototype
* @type {number}
*/
this.radius = data.radius;
}
|
[
"function",
"(",
"data",
")",
"{",
"/**\n * The center point of the circle within the Leap frame of reference.\n *\n * @member center\n * @memberof Leap.CircleGesture.prototype\n * @type {number[]}\n */",
"this",
".",
"center",
"=",
"data",
".",
"center",
";",
"/**\n * The normal vector for the circle being traced.\n *\n * If you draw the circle clockwise, the normal vector points in the same\n * general direction as the pointable object drawing the circle. If you draw\n * the circle counterclockwise, the normal points back toward the\n * pointable. If the angle between the normal and the pointable object\n * drawing the circle is less than 90 degrees, then the circle is clockwise.\n *\n * ```javascript\n * var clockwiseness;\n * if (circle.pointable.direction.angleTo(circle.normal) <= PI/4) {\n * clockwiseness = \"clockwise\";\n * }\n * else\n * {\n * clockwiseness = \"counterclockwise\";\n * }\n * ```\n *\n * @member normal\n * @memberof Leap.CircleGesture.prototype\n * @type {number[]}\n */",
"this",
".",
"normal",
"=",
"data",
".",
"normal",
";",
"/**\n * The number of times the finger tip has traversed the circle.\n *\n * Progress is reported as a positive number of the number. For example,\n * a progress value of .5 indicates that the finger has gone halfway\n * around, while a value of 3 indicates that the finger has gone around\n * the the circle three times.\n *\n * Progress starts where the circle gesture began. Since the circle\n * must be partially formed before the Leap can recognize it, progress\n * will be greater than zero when a circle gesture first appears in the\n * frame.\n *\n * @member progress\n * @memberof Leap.CircleGesture.prototype\n * @type {number}\n */",
"this",
".",
"progress",
"=",
"data",
".",
"progress",
";",
"/**\n * The radius of the circle in mm.\n *\n * @member radius\n * @memberof Leap.CircleGesture.prototype\n * @type {number}\n */",
"this",
".",
"radius",
"=",
"data",
".",
"radius",
";",
"}"
] |
Constructs a new CircleGesture object.
An uninitialized CircleGesture object is considered invalid. Get valid instances
of the CircleGesture class from a Frame object.
@class CircleGesture
@memberof Leap
@augments Leap.Gesture
@classdesc
The CircleGesture classes represents a circular finger movement.
A circle movement is recognized when the tip of a finger draws a circle
within the Leap field of view.

Circle gestures are continuous. The CircleGesture objects for the gesture have
three possible states:
* start -- The circle gesture has just started. The movement has
progressed far enough for the recognizer to classify it as a circle.
* update -- The circle gesture is continuing.
* stop -- The circle gesture is finished.
|
[
"Constructs",
"a",
"new",
"CircleGesture",
"object",
"."
] |
31b00723f98077304acda3200f9fbcbaaf29294a
|
https://github.com/leapmotion/leapjs/blob/31b00723f98077304acda3200f9fbcbaaf29294a/lib/gesture.js#L250-L310
|
|
15,589
|
leapmotion/leapjs
|
lib/gesture.js
|
function(data) {
/**
* The starting position within the Leap frame of
* reference, in mm.
*
* @member startPosition
* @memberof Leap.SwipeGesture.prototype
* @type {number[]}
*/
this.startPosition = data.startPosition;
/**
* The current swipe position within the Leap frame of
* reference, in mm.
*
* @member position
* @memberof Leap.SwipeGesture.prototype
* @type {number[]}
*/
this.position = data.position;
/**
* The unit direction vector parallel to the swipe motion.
*
* You can compare the components of the vector to classify the swipe as
* appropriate for your application. For example, if you are using swipes
* for two dimensional scrolling, you can compare the x and y values to
* determine if the swipe is primarily horizontal or vertical.
*
* @member direction
* @memberof Leap.SwipeGesture.prototype
* @type {number[]}
*/
this.direction = data.direction;
/**
* The speed of the finger performing the swipe gesture in
* millimeters per second.
*
* @member speed
* @memberof Leap.SwipeGesture.prototype
* @type {number}
*/
this.speed = data.speed;
}
|
javascript
|
function(data) {
/**
* The starting position within the Leap frame of
* reference, in mm.
*
* @member startPosition
* @memberof Leap.SwipeGesture.prototype
* @type {number[]}
*/
this.startPosition = data.startPosition;
/**
* The current swipe position within the Leap frame of
* reference, in mm.
*
* @member position
* @memberof Leap.SwipeGesture.prototype
* @type {number[]}
*/
this.position = data.position;
/**
* The unit direction vector parallel to the swipe motion.
*
* You can compare the components of the vector to classify the swipe as
* appropriate for your application. For example, if you are using swipes
* for two dimensional scrolling, you can compare the x and y values to
* determine if the swipe is primarily horizontal or vertical.
*
* @member direction
* @memberof Leap.SwipeGesture.prototype
* @type {number[]}
*/
this.direction = data.direction;
/**
* The speed of the finger performing the swipe gesture in
* millimeters per second.
*
* @member speed
* @memberof Leap.SwipeGesture.prototype
* @type {number}
*/
this.speed = data.speed;
}
|
[
"function",
"(",
"data",
")",
"{",
"/**\n * The starting position within the Leap frame of\n * reference, in mm.\n *\n * @member startPosition\n * @memberof Leap.SwipeGesture.prototype\n * @type {number[]}\n */",
"this",
".",
"startPosition",
"=",
"data",
".",
"startPosition",
";",
"/**\n * The current swipe position within the Leap frame of\n * reference, in mm.\n *\n * @member position\n * @memberof Leap.SwipeGesture.prototype\n * @type {number[]}\n */",
"this",
".",
"position",
"=",
"data",
".",
"position",
";",
"/**\n * The unit direction vector parallel to the swipe motion.\n *\n * You can compare the components of the vector to classify the swipe as\n * appropriate for your application. For example, if you are using swipes\n * for two dimensional scrolling, you can compare the x and y values to\n * determine if the swipe is primarily horizontal or vertical.\n *\n * @member direction\n * @memberof Leap.SwipeGesture.prototype\n * @type {number[]}\n */",
"this",
".",
"direction",
"=",
"data",
".",
"direction",
";",
"/**\n * The speed of the finger performing the swipe gesture in\n * millimeters per second.\n *\n * @member speed\n * @memberof Leap.SwipeGesture.prototype\n * @type {number}\n */",
"this",
".",
"speed",
"=",
"data",
".",
"speed",
";",
"}"
] |
Constructs a new SwipeGesture object.
An uninitialized SwipeGesture object is considered invalid. Get valid instances
of the SwipeGesture class from a Frame object.
@class SwipeGesture
@memberof Leap
@augments Leap.Gesture
@classdesc
The SwipeGesture class represents a swiping motion of a finger or tool.

Swipe gestures are continuous.
|
[
"Constructs",
"a",
"new",
"SwipeGesture",
"object",
"."
] |
31b00723f98077304acda3200f9fbcbaaf29294a
|
https://github.com/leapmotion/leapjs/blob/31b00723f98077304acda3200f9fbcbaaf29294a/lib/gesture.js#L332-L373
|
|
15,590
|
leapmotion/leapjs
|
lib/gesture.js
|
function(data) {
/**
* The position where the key tap is registered.
*
* @member position
* @memberof Leap.KeyTapGesture.prototype
* @type {number[]}
*/
this.position = data.position;
/**
* The direction of finger tip motion.
*
* @member direction
* @memberof Leap.KeyTapGesture.prototype
* @type {number[]}
*/
this.direction = data.direction;
/**
* The progess value is always 1.0 for a key tap gesture.
*
* @member progress
* @memberof Leap.KeyTapGesture.prototype
* @type {number}
*/
this.progress = data.progress;
}
|
javascript
|
function(data) {
/**
* The position where the key tap is registered.
*
* @member position
* @memberof Leap.KeyTapGesture.prototype
* @type {number[]}
*/
this.position = data.position;
/**
* The direction of finger tip motion.
*
* @member direction
* @memberof Leap.KeyTapGesture.prototype
* @type {number[]}
*/
this.direction = data.direction;
/**
* The progess value is always 1.0 for a key tap gesture.
*
* @member progress
* @memberof Leap.KeyTapGesture.prototype
* @type {number}
*/
this.progress = data.progress;
}
|
[
"function",
"(",
"data",
")",
"{",
"/**\n * The position where the key tap is registered.\n *\n * @member position\n * @memberof Leap.KeyTapGesture.prototype\n * @type {number[]}\n */",
"this",
".",
"position",
"=",
"data",
".",
"position",
";",
"/**\n * The direction of finger tip motion.\n *\n * @member direction\n * @memberof Leap.KeyTapGesture.prototype\n * @type {number[]}\n */",
"this",
".",
"direction",
"=",
"data",
".",
"direction",
";",
"/**\n * The progess value is always 1.0 for a key tap gesture.\n *\n * @member progress\n * @memberof Leap.KeyTapGesture.prototype\n * @type {number}\n */",
"this",
".",
"progress",
"=",
"data",
".",
"progress",
";",
"}"
] |
Constructs a new KeyTapGesture object.
An uninitialized KeyTapGesture object is considered invalid. Get valid instances
of the KeyTapGesture class from a Frame object.
@class KeyTapGesture
@memberof Leap
@augments Leap.Gesture
@classdesc
The KeyTapGesture class represents a tapping gesture by a finger or tool.
A key tap gesture is recognized when the tip of a finger rotates down toward the
palm and then springs back to approximately the original postion, as if
tapping. The tapping finger must pause briefly before beginning the tap.

Key tap gestures are discrete. The KeyTapGesture object representing a tap always
has the state, STATE_STOP. Only one KeyTapGesture object is created for each
key tap gesture recognized.
|
[
"Constructs",
"a",
"new",
"KeyTapGesture",
"object",
"."
] |
31b00723f98077304acda3200f9fbcbaaf29294a
|
https://github.com/leapmotion/leapjs/blob/31b00723f98077304acda3200f9fbcbaaf29294a/lib/gesture.js#L454-L479
|
|
15,591
|
leapmotion/leapjs
|
examples/lib/three.js
|
expand
|
function expand( v1, v2, pixels ) {
var x = v2.x - v1.x, y = v2.y - v1.y,
det = x * x + y * y, idet;
if ( det === 0 ) return;
idet = pixels / Math.sqrt( det );
x *= idet; y *= idet;
v2.x += x; v2.y += y;
v1.x -= x; v1.y -= y;
}
|
javascript
|
function expand( v1, v2, pixels ) {
var x = v2.x - v1.x, y = v2.y - v1.y,
det = x * x + y * y, idet;
if ( det === 0 ) return;
idet = pixels / Math.sqrt( det );
x *= idet; y *= idet;
v2.x += x; v2.y += y;
v1.x -= x; v1.y -= y;
}
|
[
"function",
"expand",
"(",
"v1",
",",
"v2",
",",
"pixels",
")",
"{",
"var",
"x",
"=",
"v2",
".",
"x",
"-",
"v1",
".",
"x",
",",
"y",
"=",
"v2",
".",
"y",
"-",
"v1",
".",
"y",
",",
"det",
"=",
"x",
"*",
"x",
"+",
"y",
"*",
"y",
",",
"idet",
";",
"if",
"(",
"det",
"===",
"0",
")",
"return",
";",
"idet",
"=",
"pixels",
"/",
"Math",
".",
"sqrt",
"(",
"det",
")",
";",
"x",
"*=",
"idet",
";",
"y",
"*=",
"idet",
";",
"v2",
".",
"x",
"+=",
"x",
";",
"v2",
".",
"y",
"+=",
"y",
";",
"v1",
".",
"x",
"-=",
"x",
";",
"v1",
".",
"y",
"-=",
"y",
";",
"}"
] |
Hide anti-alias gaps
|
[
"Hide",
"anti",
"-",
"alias",
"gaps"
] |
31b00723f98077304acda3200f9fbcbaaf29294a
|
https://github.com/leapmotion/leapjs/blob/31b00723f98077304acda3200f9fbcbaaf29294a/examples/lib/three.js#L17442-L17456
|
15,592
|
leapmotion/leapjs
|
examples/lib/three.js
|
binarySearchIndices
|
function binarySearchIndices( value ) {
function binarySearch( start, end ) {
// return closest larger index
// if exact number is not found
if ( end < start )
return start;
var mid = start + Math.floor( ( end - start ) / 2 );
if ( cumulativeAreas[ mid ] > value ) {
return binarySearch( start, mid - 1 );
} else if ( cumulativeAreas[ mid ] < value ) {
return binarySearch( mid + 1, end );
} else {
return mid;
}
}
var result = binarySearch( 0, cumulativeAreas.length - 1 )
return result;
}
|
javascript
|
function binarySearchIndices( value ) {
function binarySearch( start, end ) {
// return closest larger index
// if exact number is not found
if ( end < start )
return start;
var mid = start + Math.floor( ( end - start ) / 2 );
if ( cumulativeAreas[ mid ] > value ) {
return binarySearch( start, mid - 1 );
} else if ( cumulativeAreas[ mid ] < value ) {
return binarySearch( mid + 1, end );
} else {
return mid;
}
}
var result = binarySearch( 0, cumulativeAreas.length - 1 )
return result;
}
|
[
"function",
"binarySearchIndices",
"(",
"value",
")",
"{",
"function",
"binarySearch",
"(",
"start",
",",
"end",
")",
"{",
"// return closest larger index",
"// if exact number is not found",
"if",
"(",
"end",
"<",
"start",
")",
"return",
"start",
";",
"var",
"mid",
"=",
"start",
"+",
"Math",
".",
"floor",
"(",
"(",
"end",
"-",
"start",
")",
"/",
"2",
")",
";",
"if",
"(",
"cumulativeAreas",
"[",
"mid",
"]",
">",
"value",
")",
"{",
"return",
"binarySearch",
"(",
"start",
",",
"mid",
"-",
"1",
")",
";",
"}",
"else",
"if",
"(",
"cumulativeAreas",
"[",
"mid",
"]",
"<",
"value",
")",
"{",
"return",
"binarySearch",
"(",
"mid",
"+",
"1",
",",
"end",
")",
";",
"}",
"else",
"{",
"return",
"mid",
";",
"}",
"}",
"var",
"result",
"=",
"binarySearch",
"(",
"0",
",",
"cumulativeAreas",
".",
"length",
"-",
"1",
")",
"return",
"result",
";",
"}"
] |
binary search cumulative areas array
|
[
"binary",
"search",
"cumulative",
"areas",
"array"
] |
31b00723f98077304acda3200f9fbcbaaf29294a
|
https://github.com/leapmotion/leapjs/blob/31b00723f98077304acda3200f9fbcbaaf29294a/examples/lib/three.js#L27739-L27770
|
15,593
|
leapmotion/leapjs
|
examples/lib/three.js
|
function ( geometry ) {
geometry.computeBoundingBox();
var bb = geometry.boundingBox;
var offset = new THREE.Vector3();
offset.addVectors( bb.min, bb.max );
offset.multiplyScalar( -0.5 );
geometry.applyMatrix( new THREE.Matrix4().makeTranslation( offset.x, offset.y, offset.z ) );
geometry.computeBoundingBox();
return offset;
}
|
javascript
|
function ( geometry ) {
geometry.computeBoundingBox();
var bb = geometry.boundingBox;
var offset = new THREE.Vector3();
offset.addVectors( bb.min, bb.max );
offset.multiplyScalar( -0.5 );
geometry.applyMatrix( new THREE.Matrix4().makeTranslation( offset.x, offset.y, offset.z ) );
geometry.computeBoundingBox();
return offset;
}
|
[
"function",
"(",
"geometry",
")",
"{",
"geometry",
".",
"computeBoundingBox",
"(",
")",
";",
"var",
"bb",
"=",
"geometry",
".",
"boundingBox",
";",
"var",
"offset",
"=",
"new",
"THREE",
".",
"Vector3",
"(",
")",
";",
"offset",
".",
"addVectors",
"(",
"bb",
".",
"min",
",",
"bb",
".",
"max",
")",
";",
"offset",
".",
"multiplyScalar",
"(",
"-",
"0.5",
")",
";",
"geometry",
".",
"applyMatrix",
"(",
"new",
"THREE",
".",
"Matrix4",
"(",
")",
".",
"makeTranslation",
"(",
"offset",
".",
"x",
",",
"offset",
".",
"y",
",",
"offset",
".",
"z",
")",
")",
";",
"geometry",
".",
"computeBoundingBox",
"(",
")",
";",
"return",
"offset",
";",
"}"
] |
Center geometry so that 0,0,0 is in center of bounding box
|
[
"Center",
"geometry",
"so",
"that",
"0",
"0",
"0",
"is",
"in",
"center",
"of",
"bounding",
"box"
] |
31b00723f98077304acda3200f9fbcbaaf29294a
|
https://github.com/leapmotion/leapjs/blob/31b00723f98077304acda3200f9fbcbaaf29294a/examples/lib/three.js#L27825-L27841
|
|
15,594
|
leapmotion/leapjs
|
examples/lib/three.js
|
function ( points, scale ) {
var c = [], v3 = [],
point, intPoint, weight, w2, w3,
pa, pb, pc, pd;
point = ( points.length - 1 ) * scale;
intPoint = Math.floor( point );
weight = point - intPoint;
c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
c[ 1 ] = intPoint;
c[ 2 ] = intPoint > points.length - 2 ? intPoint : intPoint + 1;
c[ 3 ] = intPoint > points.length - 3 ? intPoint : intPoint + 2;
pa = points[ c[ 0 ] ];
pb = points[ c[ 1 ] ];
pc = points[ c[ 2 ] ];
pd = points[ c[ 3 ] ];
w2 = weight * weight;
w3 = weight * w2;
v3[ 0 ] = interpolate( pa[ 0 ], pb[ 0 ], pc[ 0 ], pd[ 0 ], weight, w2, w3 );
v3[ 1 ] = interpolate( pa[ 1 ], pb[ 1 ], pc[ 1 ], pd[ 1 ], weight, w2, w3 );
v3[ 2 ] = interpolate( pa[ 2 ], pb[ 2 ], pc[ 2 ], pd[ 2 ], weight, w2, w3 );
return v3;
}
|
javascript
|
function ( points, scale ) {
var c = [], v3 = [],
point, intPoint, weight, w2, w3,
pa, pb, pc, pd;
point = ( points.length - 1 ) * scale;
intPoint = Math.floor( point );
weight = point - intPoint;
c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
c[ 1 ] = intPoint;
c[ 2 ] = intPoint > points.length - 2 ? intPoint : intPoint + 1;
c[ 3 ] = intPoint > points.length - 3 ? intPoint : intPoint + 2;
pa = points[ c[ 0 ] ];
pb = points[ c[ 1 ] ];
pc = points[ c[ 2 ] ];
pd = points[ c[ 3 ] ];
w2 = weight * weight;
w3 = weight * w2;
v3[ 0 ] = interpolate( pa[ 0 ], pb[ 0 ], pc[ 0 ], pd[ 0 ], weight, w2, w3 );
v3[ 1 ] = interpolate( pa[ 1 ], pb[ 1 ], pc[ 1 ], pd[ 1 ], weight, w2, w3 );
v3[ 2 ] = interpolate( pa[ 2 ], pb[ 2 ], pc[ 2 ], pd[ 2 ], weight, w2, w3 );
return v3;
}
|
[
"function",
"(",
"points",
",",
"scale",
")",
"{",
"var",
"c",
"=",
"[",
"]",
",",
"v3",
"=",
"[",
"]",
",",
"point",
",",
"intPoint",
",",
"weight",
",",
"w2",
",",
"w3",
",",
"pa",
",",
"pb",
",",
"pc",
",",
"pd",
";",
"point",
"=",
"(",
"points",
".",
"length",
"-",
"1",
")",
"*",
"scale",
";",
"intPoint",
"=",
"Math",
".",
"floor",
"(",
"point",
")",
";",
"weight",
"=",
"point",
"-",
"intPoint",
";",
"c",
"[",
"0",
"]",
"=",
"intPoint",
"===",
"0",
"?",
"intPoint",
":",
"intPoint",
"-",
"1",
";",
"c",
"[",
"1",
"]",
"=",
"intPoint",
";",
"c",
"[",
"2",
"]",
"=",
"intPoint",
">",
"points",
".",
"length",
"-",
"2",
"?",
"intPoint",
":",
"intPoint",
"+",
"1",
";",
"c",
"[",
"3",
"]",
"=",
"intPoint",
">",
"points",
".",
"length",
"-",
"3",
"?",
"intPoint",
":",
"intPoint",
"+",
"2",
";",
"pa",
"=",
"points",
"[",
"c",
"[",
"0",
"]",
"]",
";",
"pb",
"=",
"points",
"[",
"c",
"[",
"1",
"]",
"]",
";",
"pc",
"=",
"points",
"[",
"c",
"[",
"2",
"]",
"]",
";",
"pd",
"=",
"points",
"[",
"c",
"[",
"3",
"]",
"]",
";",
"w2",
"=",
"weight",
"*",
"weight",
";",
"w3",
"=",
"weight",
"*",
"w2",
";",
"v3",
"[",
"0",
"]",
"=",
"interpolate",
"(",
"pa",
"[",
"0",
"]",
",",
"pb",
"[",
"0",
"]",
",",
"pc",
"[",
"0",
"]",
",",
"pd",
"[",
"0",
"]",
",",
"weight",
",",
"w2",
",",
"w3",
")",
";",
"v3",
"[",
"1",
"]",
"=",
"interpolate",
"(",
"pa",
"[",
"1",
"]",
",",
"pb",
"[",
"1",
"]",
",",
"pc",
"[",
"1",
"]",
",",
"pd",
"[",
"1",
"]",
",",
"weight",
",",
"w2",
",",
"w3",
")",
";",
"v3",
"[",
"2",
"]",
"=",
"interpolate",
"(",
"pa",
"[",
"2",
"]",
",",
"pb",
"[",
"2",
"]",
",",
"pc",
"[",
"2",
"]",
",",
"pd",
"[",
"2",
"]",
",",
"weight",
",",
"w2",
",",
"w3",
")",
";",
"return",
"v3",
";",
"}"
] |
Catmull-Rom spline
|
[
"Catmull",
"-",
"Rom",
"spline"
] |
31b00723f98077304acda3200f9fbcbaaf29294a
|
https://github.com/leapmotion/leapjs/blob/31b00723f98077304acda3200f9fbcbaaf29294a/examples/lib/three.js#L31762-L31791
|
|
15,595
|
leapmotion/leapjs
|
examples/lib/three.js
|
updateVirtualLight
|
function updateVirtualLight( light, cascade ) {
var virtualLight = light.shadowCascadeArray[ cascade ];
virtualLight.position.copy( light.position );
virtualLight.target.position.copy( light.target.position );
virtualLight.lookAt( virtualLight.target );
virtualLight.shadowCameraVisible = light.shadowCameraVisible;
virtualLight.shadowDarkness = light.shadowDarkness;
virtualLight.shadowBias = light.shadowCascadeBias[ cascade ];
var nearZ = light.shadowCascadeNearZ[ cascade ];
var farZ = light.shadowCascadeFarZ[ cascade ];
var pointsFrustum = virtualLight.pointsFrustum;
pointsFrustum[ 0 ].z = nearZ;
pointsFrustum[ 1 ].z = nearZ;
pointsFrustum[ 2 ].z = nearZ;
pointsFrustum[ 3 ].z = nearZ;
pointsFrustum[ 4 ].z = farZ;
pointsFrustum[ 5 ].z = farZ;
pointsFrustum[ 6 ].z = farZ;
pointsFrustum[ 7 ].z = farZ;
}
|
javascript
|
function updateVirtualLight( light, cascade ) {
var virtualLight = light.shadowCascadeArray[ cascade ];
virtualLight.position.copy( light.position );
virtualLight.target.position.copy( light.target.position );
virtualLight.lookAt( virtualLight.target );
virtualLight.shadowCameraVisible = light.shadowCameraVisible;
virtualLight.shadowDarkness = light.shadowDarkness;
virtualLight.shadowBias = light.shadowCascadeBias[ cascade ];
var nearZ = light.shadowCascadeNearZ[ cascade ];
var farZ = light.shadowCascadeFarZ[ cascade ];
var pointsFrustum = virtualLight.pointsFrustum;
pointsFrustum[ 0 ].z = nearZ;
pointsFrustum[ 1 ].z = nearZ;
pointsFrustum[ 2 ].z = nearZ;
pointsFrustum[ 3 ].z = nearZ;
pointsFrustum[ 4 ].z = farZ;
pointsFrustum[ 5 ].z = farZ;
pointsFrustum[ 6 ].z = farZ;
pointsFrustum[ 7 ].z = farZ;
}
|
[
"function",
"updateVirtualLight",
"(",
"light",
",",
"cascade",
")",
"{",
"var",
"virtualLight",
"=",
"light",
".",
"shadowCascadeArray",
"[",
"cascade",
"]",
";",
"virtualLight",
".",
"position",
".",
"copy",
"(",
"light",
".",
"position",
")",
";",
"virtualLight",
".",
"target",
".",
"position",
".",
"copy",
"(",
"light",
".",
"target",
".",
"position",
")",
";",
"virtualLight",
".",
"lookAt",
"(",
"virtualLight",
".",
"target",
")",
";",
"virtualLight",
".",
"shadowCameraVisible",
"=",
"light",
".",
"shadowCameraVisible",
";",
"virtualLight",
".",
"shadowDarkness",
"=",
"light",
".",
"shadowDarkness",
";",
"virtualLight",
".",
"shadowBias",
"=",
"light",
".",
"shadowCascadeBias",
"[",
"cascade",
"]",
";",
"var",
"nearZ",
"=",
"light",
".",
"shadowCascadeNearZ",
"[",
"cascade",
"]",
";",
"var",
"farZ",
"=",
"light",
".",
"shadowCascadeFarZ",
"[",
"cascade",
"]",
";",
"var",
"pointsFrustum",
"=",
"virtualLight",
".",
"pointsFrustum",
";",
"pointsFrustum",
"[",
"0",
"]",
".",
"z",
"=",
"nearZ",
";",
"pointsFrustum",
"[",
"1",
"]",
".",
"z",
"=",
"nearZ",
";",
"pointsFrustum",
"[",
"2",
"]",
".",
"z",
"=",
"nearZ",
";",
"pointsFrustum",
"[",
"3",
"]",
".",
"z",
"=",
"nearZ",
";",
"pointsFrustum",
"[",
"4",
"]",
".",
"z",
"=",
"farZ",
";",
"pointsFrustum",
"[",
"5",
"]",
".",
"z",
"=",
"farZ",
";",
"pointsFrustum",
"[",
"6",
"]",
".",
"z",
"=",
"farZ",
";",
"pointsFrustum",
"[",
"7",
"]",
".",
"z",
"=",
"farZ",
";",
"}"
] |
Synchronize virtual light with the original light
|
[
"Synchronize",
"virtual",
"light",
"with",
"the",
"original",
"light"
] |
31b00723f98077304acda3200f9fbcbaaf29294a
|
https://github.com/leapmotion/leapjs/blob/31b00723f98077304acda3200f9fbcbaaf29294a/examples/lib/three.js#L37655-L37683
|
15,596
|
leapmotion/leapjs
|
examples/lib/three.js
|
updateShadowCamera
|
function updateShadowCamera( camera, light ) {
var shadowCamera = light.shadowCamera,
pointsFrustum = light.pointsFrustum,
pointsWorld = light.pointsWorld;
_min.set( Infinity, Infinity, Infinity );
_max.set( -Infinity, -Infinity, -Infinity );
for ( var i = 0; i < 8; i ++ ) {
var p = pointsWorld[ i ];
p.copy( pointsFrustum[ i ] );
THREE.ShadowMapPlugin.__projector.unprojectVector( p, camera );
p.applyMatrix4( shadowCamera.matrixWorldInverse );
if ( p.x < _min.x ) _min.x = p.x;
if ( p.x > _max.x ) _max.x = p.x;
if ( p.y < _min.y ) _min.y = p.y;
if ( p.y > _max.y ) _max.y = p.y;
if ( p.z < _min.z ) _min.z = p.z;
if ( p.z > _max.z ) _max.z = p.z;
}
shadowCamera.left = _min.x;
shadowCamera.right = _max.x;
shadowCamera.top = _max.y;
shadowCamera.bottom = _min.y;
// can't really fit near/far
//shadowCamera.near = _min.z;
//shadowCamera.far = _max.z;
shadowCamera.updateProjectionMatrix();
}
|
javascript
|
function updateShadowCamera( camera, light ) {
var shadowCamera = light.shadowCamera,
pointsFrustum = light.pointsFrustum,
pointsWorld = light.pointsWorld;
_min.set( Infinity, Infinity, Infinity );
_max.set( -Infinity, -Infinity, -Infinity );
for ( var i = 0; i < 8; i ++ ) {
var p = pointsWorld[ i ];
p.copy( pointsFrustum[ i ] );
THREE.ShadowMapPlugin.__projector.unprojectVector( p, camera );
p.applyMatrix4( shadowCamera.matrixWorldInverse );
if ( p.x < _min.x ) _min.x = p.x;
if ( p.x > _max.x ) _max.x = p.x;
if ( p.y < _min.y ) _min.y = p.y;
if ( p.y > _max.y ) _max.y = p.y;
if ( p.z < _min.z ) _min.z = p.z;
if ( p.z > _max.z ) _max.z = p.z;
}
shadowCamera.left = _min.x;
shadowCamera.right = _max.x;
shadowCamera.top = _max.y;
shadowCamera.bottom = _min.y;
// can't really fit near/far
//shadowCamera.near = _min.z;
//shadowCamera.far = _max.z;
shadowCamera.updateProjectionMatrix();
}
|
[
"function",
"updateShadowCamera",
"(",
"camera",
",",
"light",
")",
"{",
"var",
"shadowCamera",
"=",
"light",
".",
"shadowCamera",
",",
"pointsFrustum",
"=",
"light",
".",
"pointsFrustum",
",",
"pointsWorld",
"=",
"light",
".",
"pointsWorld",
";",
"_min",
".",
"set",
"(",
"Infinity",
",",
"Infinity",
",",
"Infinity",
")",
";",
"_max",
".",
"set",
"(",
"-",
"Infinity",
",",
"-",
"Infinity",
",",
"-",
"Infinity",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"8",
";",
"i",
"++",
")",
"{",
"var",
"p",
"=",
"pointsWorld",
"[",
"i",
"]",
";",
"p",
".",
"copy",
"(",
"pointsFrustum",
"[",
"i",
"]",
")",
";",
"THREE",
".",
"ShadowMapPlugin",
".",
"__projector",
".",
"unprojectVector",
"(",
"p",
",",
"camera",
")",
";",
"p",
".",
"applyMatrix4",
"(",
"shadowCamera",
".",
"matrixWorldInverse",
")",
";",
"if",
"(",
"p",
".",
"x",
"<",
"_min",
".",
"x",
")",
"_min",
".",
"x",
"=",
"p",
".",
"x",
";",
"if",
"(",
"p",
".",
"x",
">",
"_max",
".",
"x",
")",
"_max",
".",
"x",
"=",
"p",
".",
"x",
";",
"if",
"(",
"p",
".",
"y",
"<",
"_min",
".",
"y",
")",
"_min",
".",
"y",
"=",
"p",
".",
"y",
";",
"if",
"(",
"p",
".",
"y",
">",
"_max",
".",
"y",
")",
"_max",
".",
"y",
"=",
"p",
".",
"y",
";",
"if",
"(",
"p",
".",
"z",
"<",
"_min",
".",
"z",
")",
"_min",
".",
"z",
"=",
"p",
".",
"z",
";",
"if",
"(",
"p",
".",
"z",
">",
"_max",
".",
"z",
")",
"_max",
".",
"z",
"=",
"p",
".",
"z",
";",
"}",
"shadowCamera",
".",
"left",
"=",
"_min",
".",
"x",
";",
"shadowCamera",
".",
"right",
"=",
"_max",
".",
"x",
";",
"shadowCamera",
".",
"top",
"=",
"_max",
".",
"y",
";",
"shadowCamera",
".",
"bottom",
"=",
"_min",
".",
"y",
";",
"// can't really fit near/far",
"//shadowCamera.near = _min.z;",
"//shadowCamera.far = _max.z;",
"shadowCamera",
".",
"updateProjectionMatrix",
"(",
")",
";",
"}"
] |
Fit shadow camera's ortho frustum to camera frustum
|
[
"Fit",
"shadow",
"camera",
"s",
"ortho",
"frustum",
"to",
"camera",
"frustum"
] |
31b00723f98077304acda3200f9fbcbaaf29294a
|
https://github.com/leapmotion/leapjs/blob/31b00723f98077304acda3200f9fbcbaaf29294a/examples/lib/three.js#L37687-L37727
|
15,597
|
leapmotion/leapjs
|
examples/lib/three.js
|
getObjectMaterial
|
function getObjectMaterial( object ) {
return object.material instanceof THREE.MeshFaceMaterial
? object.material.materials[ 0 ]
: object.material;
}
|
javascript
|
function getObjectMaterial( object ) {
return object.material instanceof THREE.MeshFaceMaterial
? object.material.materials[ 0 ]
: object.material;
}
|
[
"function",
"getObjectMaterial",
"(",
"object",
")",
"{",
"return",
"object",
".",
"material",
"instanceof",
"THREE",
".",
"MeshFaceMaterial",
"?",
"object",
".",
"material",
".",
"materials",
"[",
"0",
"]",
":",
"object",
".",
"material",
";",
"}"
] |
For the moment just ignore objects that have multiple materials with different animation methods Only the first material will be taken into account for deciding which depth material to use for shadow maps
|
[
"For",
"the",
"moment",
"just",
"ignore",
"objects",
"that",
"have",
"multiple",
"materials",
"with",
"different",
"animation",
"methods",
"Only",
"the",
"first",
"material",
"will",
"be",
"taken",
"into",
"account",
"for",
"deciding",
"which",
"depth",
"material",
"to",
"use",
"for",
"shadow",
"maps"
] |
31b00723f98077304acda3200f9fbcbaaf29294a
|
https://github.com/leapmotion/leapjs/blob/31b00723f98077304acda3200f9fbcbaaf29294a/examples/lib/three.js#L37732-L37738
|
15,598
|
leapmotion/leapjs
|
examples/lib/leap-plugins-0.1.6.js
|
function(){
this.frameIndex++;
if (this.frameIndex >= this.rightCropPosition) {
this.frameIndex = this.frameIndex % (this.rightCropPosition || 1);
if ((this.frameIndex < this.leftCropPosition)) {
this.frameIndex = this.leftCropPosition;
}
}else{
this.frameIndex--;
}
}
|
javascript
|
function(){
this.frameIndex++;
if (this.frameIndex >= this.rightCropPosition) {
this.frameIndex = this.frameIndex % (this.rightCropPosition || 1);
if ((this.frameIndex < this.leftCropPosition)) {
this.frameIndex = this.leftCropPosition;
}
}else{
this.frameIndex--;
}
}
|
[
"function",
"(",
")",
"{",
"this",
".",
"frameIndex",
"++",
";",
"if",
"(",
"this",
".",
"frameIndex",
">=",
"this",
".",
"rightCropPosition",
")",
"{",
"this",
".",
"frameIndex",
"=",
"this",
".",
"frameIndex",
"%",
"(",
"this",
".",
"rightCropPosition",
"||",
"1",
")",
";",
"if",
"(",
"(",
"this",
".",
"frameIndex",
"<",
"this",
".",
"leftCropPosition",
")",
")",
"{",
"this",
".",
"frameIndex",
"=",
"this",
".",
"leftCropPosition",
";",
"}",
"}",
"else",
"{",
"this",
".",
"frameIndex",
"--",
";",
"}",
"}"
] |
resets to beginning if at end
|
[
"resets",
"to",
"beginning",
"if",
"at",
"end"
] |
31b00723f98077304acda3200f9fbcbaaf29294a
|
https://github.com/leapmotion/leapjs/blob/31b00723f98077304acda3200f9fbcbaaf29294a/examples/lib/leap-plugins-0.1.6.js#L996-L1007
|
|
15,599
|
leapmotion/leapjs
|
examples/lib/leap-plugins-0.1.6.js
|
function (factor) {
console.log('cull frames', factor);
factor || (factor = 1);
for (var i = 0; i < this.frameData.length; i++) {
this.frameData.splice(i, factor);
}
this.setMetaData();
}
|
javascript
|
function (factor) {
console.log('cull frames', factor);
factor || (factor = 1);
for (var i = 0; i < this.frameData.length; i++) {
this.frameData.splice(i, factor);
}
this.setMetaData();
}
|
[
"function",
"(",
"factor",
")",
"{",
"console",
".",
"log",
"(",
"'cull frames'",
",",
"factor",
")",
";",
"factor",
"||",
"(",
"factor",
"=",
"1",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"frameData",
".",
"length",
";",
"i",
"++",
")",
"{",
"this",
".",
"frameData",
".",
"splice",
"(",
"i",
",",
"factor",
")",
";",
"}",
"this",
".",
"setMetaData",
"(",
")",
";",
"}"
] |
removes every other frame from the array Accepts an optional `factor` integer, which is the number of frames discarded for every frame kept.
|
[
"removes",
"every",
"other",
"frame",
"from",
"the",
"array",
"Accepts",
"an",
"optional",
"factor",
"integer",
"which",
"is",
"the",
"number",
"of",
"frames",
"discarded",
"for",
"every",
"frame",
"kept",
"."
] |
31b00723f98077304acda3200f9fbcbaaf29294a
|
https://github.com/leapmotion/leapjs/blob/31b00723f98077304acda3200f9fbcbaaf29294a/examples/lib/leap-plugins-0.1.6.js#L1115-L1122
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.