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
sequence | docstring
stringlengths 4
11.8k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
8,200 | gilbitron/Raneto | app/functions/contentProcessors.js | slugToTitle | function slugToTitle (slug) {
slug = slug.replace('.md', '').trim();
return _s.titleize(_s.humanize(path.basename(slug)));
} | javascript | function slugToTitle (slug) {
slug = slug.replace('.md', '').trim();
return _s.titleize(_s.humanize(path.basename(slug)));
} | [
"function",
"slugToTitle",
"(",
"slug",
")",
"{",
"slug",
"=",
"slug",
".",
"replace",
"(",
"'.md'",
",",
"''",
")",
".",
"trim",
"(",
")",
";",
"return",
"_s",
".",
"titleize",
"(",
"_s",
".",
"humanize",
"(",
"path",
".",
"basename",
"(",
"slug",
")",
")",
")",
";",
"}"
] | Convert a slug to a title | [
"Convert",
"a",
"slug",
"to",
"a",
"title"
] | b142a33948bb0e29c77f49bebac6b58f40a4255f | https://github.com/gilbitron/Raneto/blob/b142a33948bb0e29c77f49bebac6b58f40a4255f/app/functions/contentProcessors.js#L43-L46 |
8,201 | gilbitron/Raneto | app/functions/contentProcessors.js | stripMeta | function stripMeta (markdownContent) {
switch (true) {
case _metaRegex.test(markdownContent):
return markdownContent.replace(_metaRegex, '').trim();
case _metaRegexYaml.test(markdownContent):
return markdownContent.replace(_metaRegexYaml, '').trim();
default:
return markdownContent.trim();
}
} | javascript | function stripMeta (markdownContent) {
switch (true) {
case _metaRegex.test(markdownContent):
return markdownContent.replace(_metaRegex, '').trim();
case _metaRegexYaml.test(markdownContent):
return markdownContent.replace(_metaRegexYaml, '').trim();
default:
return markdownContent.trim();
}
} | [
"function",
"stripMeta",
"(",
"markdownContent",
")",
"{",
"switch",
"(",
"true",
")",
"{",
"case",
"_metaRegex",
".",
"test",
"(",
"markdownContent",
")",
":",
"return",
"markdownContent",
".",
"replace",
"(",
"_metaRegex",
",",
"''",
")",
".",
"trim",
"(",
")",
";",
"case",
"_metaRegexYaml",
".",
"test",
"(",
"markdownContent",
")",
":",
"return",
"markdownContent",
".",
"replace",
"(",
"_metaRegexYaml",
",",
"''",
")",
".",
"trim",
"(",
")",
";",
"default",
":",
"return",
"markdownContent",
".",
"trim",
"(",
")",
";",
"}",
"}"
] | Strip meta from Markdown content | [
"Strip",
"meta",
"from",
"Markdown",
"content"
] | b142a33948bb0e29c77f49bebac6b58f40a4255f | https://github.com/gilbitron/Raneto/blob/b142a33948bb0e29c77f49bebac6b58f40a4255f/app/functions/contentProcessors.js#L49-L58 |
8,202 | gilbitron/Raneto | app/functions/contentProcessors.js | processMeta | function processMeta (markdownContent) {
let meta = {};
let metaArr;
let metaString;
let metas;
let yamlObject;
switch (true) {
case _metaRegex.test(markdownContent):
metaArr = markdownContent.match(_metaRegex);
metaString = metaArr ? metaArr[1].trim() : '';
if (metaString) {
metas = metaString.match(/(.*): (.*)/ig);
metas.forEach(item => {
const parts = item.split(': ');
if (parts[0] && parts[1]) {
meta[cleanString(parts[0], true)] = parts[1].trim();
}
});
}
break;
case _metaRegexYaml.test(markdownContent):
metaArr = markdownContent.match(_metaRegexYaml);
metaString = metaArr ? metaArr[1].trim() : '';
yamlObject = yaml.safeLoad(metaString);
meta = cleanObjectStrings(yamlObject);
break;
default:
// No meta information
}
return meta;
} | javascript | function processMeta (markdownContent) {
let meta = {};
let metaArr;
let metaString;
let metas;
let yamlObject;
switch (true) {
case _metaRegex.test(markdownContent):
metaArr = markdownContent.match(_metaRegex);
metaString = metaArr ? metaArr[1].trim() : '';
if (metaString) {
metas = metaString.match(/(.*): (.*)/ig);
metas.forEach(item => {
const parts = item.split(': ');
if (parts[0] && parts[1]) {
meta[cleanString(parts[0], true)] = parts[1].trim();
}
});
}
break;
case _metaRegexYaml.test(markdownContent):
metaArr = markdownContent.match(_metaRegexYaml);
metaString = metaArr ? metaArr[1].trim() : '';
yamlObject = yaml.safeLoad(metaString);
meta = cleanObjectStrings(yamlObject);
break;
default:
// No meta information
}
return meta;
} | [
"function",
"processMeta",
"(",
"markdownContent",
")",
"{",
"let",
"meta",
"=",
"{",
"}",
";",
"let",
"metaArr",
";",
"let",
"metaString",
";",
"let",
"metas",
";",
"let",
"yamlObject",
";",
"switch",
"(",
"true",
")",
"{",
"case",
"_metaRegex",
".",
"test",
"(",
"markdownContent",
")",
":",
"metaArr",
"=",
"markdownContent",
".",
"match",
"(",
"_metaRegex",
")",
";",
"metaString",
"=",
"metaArr",
"?",
"metaArr",
"[",
"1",
"]",
".",
"trim",
"(",
")",
":",
"''",
";",
"if",
"(",
"metaString",
")",
"{",
"metas",
"=",
"metaString",
".",
"match",
"(",
"/",
"(.*): (.*)",
"/",
"ig",
")",
";",
"metas",
".",
"forEach",
"(",
"item",
"=>",
"{",
"const",
"parts",
"=",
"item",
".",
"split",
"(",
"': '",
")",
";",
"if",
"(",
"parts",
"[",
"0",
"]",
"&&",
"parts",
"[",
"1",
"]",
")",
"{",
"meta",
"[",
"cleanString",
"(",
"parts",
"[",
"0",
"]",
",",
"true",
")",
"]",
"=",
"parts",
"[",
"1",
"]",
".",
"trim",
"(",
")",
";",
"}",
"}",
")",
";",
"}",
"break",
";",
"case",
"_metaRegexYaml",
".",
"test",
"(",
"markdownContent",
")",
":",
"metaArr",
"=",
"markdownContent",
".",
"match",
"(",
"_metaRegexYaml",
")",
";",
"metaString",
"=",
"metaArr",
"?",
"metaArr",
"[",
"1",
"]",
".",
"trim",
"(",
")",
":",
"''",
";",
"yamlObject",
"=",
"yaml",
".",
"safeLoad",
"(",
"metaString",
")",
";",
"meta",
"=",
"cleanObjectStrings",
"(",
"yamlObject",
")",
";",
"break",
";",
"default",
":",
"// No meta information",
"}",
"return",
"meta",
";",
"}"
] | Get meta information from Markdown content | [
"Get",
"meta",
"information",
"from",
"Markdown",
"content"
] | b142a33948bb0e29c77f49bebac6b58f40a4255f | https://github.com/gilbitron/Raneto/blob/b142a33948bb0e29c77f49bebac6b58f40a4255f/app/functions/contentProcessors.js#L61-L97 |
8,203 | gilbitron/Raneto | app/functions/contentProcessors.js | processVars | function processVars (markdownContent, config) {
if (config.variables && Array.isArray(config.variables)) {
config.variables.forEach((v) => {
markdownContent = markdownContent.replace(new RegExp('%' + v.name + '%', 'g'), v.content);
});
}
if (config.base_url) {
markdownContent = markdownContent.replace(/%base_url%/g, config.base_url);
}
if (config.image_url) {
markdownContent = markdownContent.replace(/%image_url%/g, config.image_url);
}
return markdownContent;
} | javascript | function processVars (markdownContent, config) {
if (config.variables && Array.isArray(config.variables)) {
config.variables.forEach((v) => {
markdownContent = markdownContent.replace(new RegExp('%' + v.name + '%', 'g'), v.content);
});
}
if (config.base_url) {
markdownContent = markdownContent.replace(/%base_url%/g, config.base_url);
}
if (config.image_url) {
markdownContent = markdownContent.replace(/%image_url%/g, config.image_url);
}
return markdownContent;
} | [
"function",
"processVars",
"(",
"markdownContent",
",",
"config",
")",
"{",
"if",
"(",
"config",
".",
"variables",
"&&",
"Array",
".",
"isArray",
"(",
"config",
".",
"variables",
")",
")",
"{",
"config",
".",
"variables",
".",
"forEach",
"(",
"(",
"v",
")",
"=>",
"{",
"markdownContent",
"=",
"markdownContent",
".",
"replace",
"(",
"new",
"RegExp",
"(",
"'%'",
"+",
"v",
".",
"name",
"+",
"'%'",
",",
"'g'",
")",
",",
"v",
".",
"content",
")",
";",
"}",
")",
";",
"}",
"if",
"(",
"config",
".",
"base_url",
")",
"{",
"markdownContent",
"=",
"markdownContent",
".",
"replace",
"(",
"/",
"%base_url%",
"/",
"g",
",",
"config",
".",
"base_url",
")",
";",
"}",
"if",
"(",
"config",
".",
"image_url",
")",
"{",
"markdownContent",
"=",
"markdownContent",
".",
"replace",
"(",
"/",
"%image_url%",
"/",
"g",
",",
"config",
".",
"image_url",
")",
";",
"}",
"return",
"markdownContent",
";",
"}"
] | Replace content variables in Markdown content | [
"Replace",
"content",
"variables",
"in",
"Markdown",
"content"
] | b142a33948bb0e29c77f49bebac6b58f40a4255f | https://github.com/gilbitron/Raneto/blob/b142a33948bb0e29c77f49bebac6b58f40a4255f/app/functions/contentProcessors.js#L100-L113 |
8,204 | gilbitron/Raneto | app/functions/create_meta_info.js | create_meta_info | function create_meta_info (meta_title, meta_description, meta_sort) {
var yamlDocument = {};
var meta_info_is_present = meta_title || meta_description || meta_sort;
if (meta_info_is_present) {
if (meta_title) { yamlDocument.Title = meta_title; }
if (meta_description) { yamlDocument.Description = meta_description; }
if (meta_sort) { yamlDocument.Sort = parseInt(meta_sort, 10); }
return '---\n' + yaml.safeDump(yamlDocument) + '---\n';
} else {
return '---\n---\n';
}
} | javascript | function create_meta_info (meta_title, meta_description, meta_sort) {
var yamlDocument = {};
var meta_info_is_present = meta_title || meta_description || meta_sort;
if (meta_info_is_present) {
if (meta_title) { yamlDocument.Title = meta_title; }
if (meta_description) { yamlDocument.Description = meta_description; }
if (meta_sort) { yamlDocument.Sort = parseInt(meta_sort, 10); }
return '---\n' + yaml.safeDump(yamlDocument) + '---\n';
} else {
return '---\n---\n';
}
} | [
"function",
"create_meta_info",
"(",
"meta_title",
",",
"meta_description",
",",
"meta_sort",
")",
"{",
"var",
"yamlDocument",
"=",
"{",
"}",
";",
"var",
"meta_info_is_present",
"=",
"meta_title",
"||",
"meta_description",
"||",
"meta_sort",
";",
"if",
"(",
"meta_info_is_present",
")",
"{",
"if",
"(",
"meta_title",
")",
"{",
"yamlDocument",
".",
"Title",
"=",
"meta_title",
";",
"}",
"if",
"(",
"meta_description",
")",
"{",
"yamlDocument",
".",
"Description",
"=",
"meta_description",
";",
"}",
"if",
"(",
"meta_sort",
")",
"{",
"yamlDocument",
".",
"Sort",
"=",
"parseInt",
"(",
"meta_sort",
",",
"10",
")",
";",
"}",
"return",
"'---\\n'",
"+",
"yaml",
".",
"safeDump",
"(",
"yamlDocument",
")",
"+",
"'---\\n'",
";",
"}",
"else",
"{",
"return",
"'---\\n---\\n'",
";",
"}",
"}"
] | Returns an empty string if all input strings are empty | [
"Returns",
"an",
"empty",
"string",
"if",
"all",
"input",
"strings",
"are",
"empty"
] | b142a33948bb0e29c77f49bebac6b58f40a4255f | https://github.com/gilbitron/Raneto/blob/b142a33948bb0e29c77f49bebac6b58f40a4255f/app/functions/create_meta_info.js#L8-L23 |
8,205 | jnordberg/gif.js | src/LZWEncoder.js | cl_block | function cl_block(outs) {
cl_hash(HSIZE);
free_ent = ClearCode + 2;
clear_flg = true;
output(ClearCode, outs);
} | javascript | function cl_block(outs) {
cl_hash(HSIZE);
free_ent = ClearCode + 2;
clear_flg = true;
output(ClearCode, outs);
} | [
"function",
"cl_block",
"(",
"outs",
")",
"{",
"cl_hash",
"(",
"HSIZE",
")",
";",
"free_ent",
"=",
"ClearCode",
"+",
"2",
";",
"clear_flg",
"=",
"true",
";",
"output",
"(",
"ClearCode",
",",
"outs",
")",
";",
"}"
] | Clear out the hash table table clear for block compress | [
"Clear",
"out",
"the",
"hash",
"table",
"table",
"clear",
"for",
"block",
"compress"
] | a2201f123ed9e5582e57c3d15f5df00c0b8367bd | https://github.com/jnordberg/gif.js/blob/a2201f123ed9e5582e57c3d15f5df00c0b8367bd/src/LZWEncoder.js#L68-L73 |
8,206 | jnordberg/gif.js | src/LZWEncoder.js | flush_char | function flush_char(outs) {
if (a_count > 0) {
outs.writeByte(a_count);
outs.writeBytes(accum, 0, a_count);
a_count = 0;
}
} | javascript | function flush_char(outs) {
if (a_count > 0) {
outs.writeByte(a_count);
outs.writeBytes(accum, 0, a_count);
a_count = 0;
}
} | [
"function",
"flush_char",
"(",
"outs",
")",
"{",
"if",
"(",
"a_count",
">",
"0",
")",
"{",
"outs",
".",
"writeByte",
"(",
"a_count",
")",
";",
"outs",
".",
"writeBytes",
"(",
"accum",
",",
"0",
",",
"a_count",
")",
";",
"a_count",
"=",
"0",
";",
"}",
"}"
] | Flush the packet to disk, and reset the accumulator | [
"Flush",
"the",
"packet",
"to",
"disk",
"and",
"reset",
"the",
"accumulator"
] | a2201f123ed9e5582e57c3d15f5df00c0b8367bd | https://github.com/jnordberg/gif.js/blob/a2201f123ed9e5582e57c3d15f5df00c0b8367bd/src/LZWEncoder.js#L148-L154 |
8,207 | okonet/lint-staged | src/getConfig.js | isSimple | function isSimple(config) {
return (
isObject(config) &&
!config.hasOwnProperty('linters') &&
intersection(Object.keys(defaultConfig), Object.keys(config)).length === 0
)
} | javascript | function isSimple(config) {
return (
isObject(config) &&
!config.hasOwnProperty('linters') &&
intersection(Object.keys(defaultConfig), Object.keys(config)).length === 0
)
} | [
"function",
"isSimple",
"(",
"config",
")",
"{",
"return",
"(",
"isObject",
"(",
"config",
")",
"&&",
"!",
"config",
".",
"hasOwnProperty",
"(",
"'linters'",
")",
"&&",
"intersection",
"(",
"Object",
".",
"keys",
"(",
"defaultConfig",
")",
",",
"Object",
".",
"keys",
"(",
"config",
")",
")",
".",
"length",
"===",
"0",
")",
"}"
] | Check if the config is "simple" i.e. doesn't contains any of full config keys
@param config
@returns {boolean} | [
"Check",
"if",
"the",
"config",
"is",
"simple",
"i",
".",
"e",
".",
"doesn",
"t",
"contains",
"any",
"of",
"full",
"config",
"keys"
] | 098452423fd3cdc4d80f861d330d64bc82f7bbaf | https://github.com/okonet/lint-staged/blob/098452423fd3cdc4d80f861d330d64bc82f7bbaf/src/getConfig.js#L73-L79 |
8,208 | okonet/lint-staged | src/getConfig.js | unknownValidationReporter | function unknownValidationReporter(config, option) {
/**
* If the unkonwn property is a glob this is probably
* a typical mistake of mixing simple and advanced configs
*/
if (isGlob(option)) {
// prettier-ignore
const message = `You are probably trying to mix simple and advanced config formats. Adding
${chalk.bold(`"linters": {
"${option}": ${JSON.stringify(config[option])}
}`)}
will fix it and remove this message.`
return logUnknown(option, message, config[option])
}
// If it is not glob pattern, simply notify of unknown value
return logUnknown(option, '', config[option])
} | javascript | function unknownValidationReporter(config, option) {
/**
* If the unkonwn property is a glob this is probably
* a typical mistake of mixing simple and advanced configs
*/
if (isGlob(option)) {
// prettier-ignore
const message = `You are probably trying to mix simple and advanced config formats. Adding
${chalk.bold(`"linters": {
"${option}": ${JSON.stringify(config[option])}
}`)}
will fix it and remove this message.`
return logUnknown(option, message, config[option])
}
// If it is not glob pattern, simply notify of unknown value
return logUnknown(option, '', config[option])
} | [
"function",
"unknownValidationReporter",
"(",
"config",
",",
"option",
")",
"{",
"/**\n * If the unkonwn property is a glob this is probably\n * a typical mistake of mixing simple and advanced configs\n */",
"if",
"(",
"isGlob",
"(",
"option",
")",
")",
"{",
"// prettier-ignore",
"const",
"message",
"=",
"`",
"${",
"chalk",
".",
"bold",
"(",
"`",
"${",
"option",
"}",
"${",
"JSON",
".",
"stringify",
"(",
"config",
"[",
"option",
"]",
")",
"}",
"`",
")",
"}",
"`",
"return",
"logUnknown",
"(",
"option",
",",
"message",
",",
"config",
"[",
"option",
"]",
")",
"}",
"// If it is not glob pattern, simply notify of unknown value",
"return",
"logUnknown",
"(",
"option",
",",
"''",
",",
"config",
"[",
"option",
"]",
")",
"}"
] | Reporter for unknown options
@param config
@param option
@returns {void} | [
"Reporter",
"for",
"unknown",
"options"
] | 098452423fd3cdc4d80f861d330d64bc82f7bbaf | https://github.com/okonet/lint-staged/blob/098452423fd3cdc4d80f861d330d64bc82f7bbaf/src/getConfig.js#L124-L144 |
8,209 | okonet/lint-staged | src/getConfig.js | getConfig | function getConfig(sourceConfig, debugMode) {
debug('Normalizing config')
const config = defaultsDeep(
{}, // Do not mutate sourceConfig!!!
isSimple(sourceConfig) ? { linters: sourceConfig } : sourceConfig,
defaultConfig
)
// Check if renderer is set in sourceConfig and if not, set accordingly to verbose
if (isObject(sourceConfig) && !sourceConfig.hasOwnProperty('renderer')) {
config.renderer = debugMode ? 'verbose' : 'update'
}
return config
} | javascript | function getConfig(sourceConfig, debugMode) {
debug('Normalizing config')
const config = defaultsDeep(
{}, // Do not mutate sourceConfig!!!
isSimple(sourceConfig) ? { linters: sourceConfig } : sourceConfig,
defaultConfig
)
// Check if renderer is set in sourceConfig and if not, set accordingly to verbose
if (isObject(sourceConfig) && !sourceConfig.hasOwnProperty('renderer')) {
config.renderer = debugMode ? 'verbose' : 'update'
}
return config
} | [
"function",
"getConfig",
"(",
"sourceConfig",
",",
"debugMode",
")",
"{",
"debug",
"(",
"'Normalizing config'",
")",
"const",
"config",
"=",
"defaultsDeep",
"(",
"{",
"}",
",",
"// Do not mutate sourceConfig!!!",
"isSimple",
"(",
"sourceConfig",
")",
"?",
"{",
"linters",
":",
"sourceConfig",
"}",
":",
"sourceConfig",
",",
"defaultConfig",
")",
"// Check if renderer is set in sourceConfig and if not, set accordingly to verbose",
"if",
"(",
"isObject",
"(",
"sourceConfig",
")",
"&&",
"!",
"sourceConfig",
".",
"hasOwnProperty",
"(",
"'renderer'",
")",
")",
"{",
"config",
".",
"renderer",
"=",
"debugMode",
"?",
"'verbose'",
":",
"'update'",
"}",
"return",
"config",
"}"
] | For a given configuration object that we retrive from .lintstagedrc or package.json
construct a full configuration with all options set.
This is a bit tricky since we support 2 different syntxes: simple and full
For simple config, only the `linters` configuration is provided.
@param {Object} sourceConfig
@returns {{
concurrent: boolean, chunkSize: number, globOptions: {matchBase: boolean, dot: boolean}, linters: {}, subTaskConcurrency: number, renderer: string
}} | [
"For",
"a",
"given",
"configuration",
"object",
"that",
"we",
"retrive",
"from",
".",
"lintstagedrc",
"or",
"package",
".",
"json",
"construct",
"a",
"full",
"configuration",
"with",
"all",
"options",
"set",
"."
] | 098452423fd3cdc4d80f861d330d64bc82f7bbaf | https://github.com/okonet/lint-staged/blob/098452423fd3cdc4d80f861d330d64bc82f7bbaf/src/getConfig.js#L158-L172 |
8,210 | okonet/lint-staged | src/getConfig.js | validateConfig | function validateConfig(config) {
debug('Validating config')
const deprecatedConfig = {
gitDir: "lint-staged now automatically resolves '.git' directory.",
verbose: `Use the command line flag ${chalk.bold('--debug')} instead.`
}
const errors = []
try {
schema.validateSync(config, { abortEarly: false, strict: true })
} catch (error) {
error.errors.forEach(message => errors.push(formatError(message)))
}
if (isObject(config.linters)) {
Object.keys(config.linters).forEach(key => {
if (
(!isArray(config.linters[key]) || config.linters[key].some(item => !isString(item))) &&
!isString(config.linters[key])
) {
errors.push(
createError(`linters[${key}]`, 'Should be a string or an array of strings', key)
)
}
})
}
Object.keys(config)
.filter(key => !defaultConfig.hasOwnProperty(key))
.forEach(option => {
if (deprecatedConfig.hasOwnProperty(option)) {
logDeprecation(option, deprecatedConfig[option])
return
}
unknownValidationReporter(config, option)
})
if (errors.length) {
throw new Error(errors.join('\n'))
}
return config
} | javascript | function validateConfig(config) {
debug('Validating config')
const deprecatedConfig = {
gitDir: "lint-staged now automatically resolves '.git' directory.",
verbose: `Use the command line flag ${chalk.bold('--debug')} instead.`
}
const errors = []
try {
schema.validateSync(config, { abortEarly: false, strict: true })
} catch (error) {
error.errors.forEach(message => errors.push(formatError(message)))
}
if (isObject(config.linters)) {
Object.keys(config.linters).forEach(key => {
if (
(!isArray(config.linters[key]) || config.linters[key].some(item => !isString(item))) &&
!isString(config.linters[key])
) {
errors.push(
createError(`linters[${key}]`, 'Should be a string or an array of strings', key)
)
}
})
}
Object.keys(config)
.filter(key => !defaultConfig.hasOwnProperty(key))
.forEach(option => {
if (deprecatedConfig.hasOwnProperty(option)) {
logDeprecation(option, deprecatedConfig[option])
return
}
unknownValidationReporter(config, option)
})
if (errors.length) {
throw new Error(errors.join('\n'))
}
return config
} | [
"function",
"validateConfig",
"(",
"config",
")",
"{",
"debug",
"(",
"'Validating config'",
")",
"const",
"deprecatedConfig",
"=",
"{",
"gitDir",
":",
"\"lint-staged now automatically resolves '.git' directory.\"",
",",
"verbose",
":",
"`",
"${",
"chalk",
".",
"bold",
"(",
"'--debug'",
")",
"}",
"`",
"}",
"const",
"errors",
"=",
"[",
"]",
"try",
"{",
"schema",
".",
"validateSync",
"(",
"config",
",",
"{",
"abortEarly",
":",
"false",
",",
"strict",
":",
"true",
"}",
")",
"}",
"catch",
"(",
"error",
")",
"{",
"error",
".",
"errors",
".",
"forEach",
"(",
"message",
"=>",
"errors",
".",
"push",
"(",
"formatError",
"(",
"message",
")",
")",
")",
"}",
"if",
"(",
"isObject",
"(",
"config",
".",
"linters",
")",
")",
"{",
"Object",
".",
"keys",
"(",
"config",
".",
"linters",
")",
".",
"forEach",
"(",
"key",
"=>",
"{",
"if",
"(",
"(",
"!",
"isArray",
"(",
"config",
".",
"linters",
"[",
"key",
"]",
")",
"||",
"config",
".",
"linters",
"[",
"key",
"]",
".",
"some",
"(",
"item",
"=>",
"!",
"isString",
"(",
"item",
")",
")",
")",
"&&",
"!",
"isString",
"(",
"config",
".",
"linters",
"[",
"key",
"]",
")",
")",
"{",
"errors",
".",
"push",
"(",
"createError",
"(",
"`",
"${",
"key",
"}",
"`",
",",
"'Should be a string or an array of strings'",
",",
"key",
")",
")",
"}",
"}",
")",
"}",
"Object",
".",
"keys",
"(",
"config",
")",
".",
"filter",
"(",
"key",
"=>",
"!",
"defaultConfig",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
".",
"forEach",
"(",
"option",
"=>",
"{",
"if",
"(",
"deprecatedConfig",
".",
"hasOwnProperty",
"(",
"option",
")",
")",
"{",
"logDeprecation",
"(",
"option",
",",
"deprecatedConfig",
"[",
"option",
"]",
")",
"return",
"}",
"unknownValidationReporter",
"(",
"config",
",",
"option",
")",
"}",
")",
"if",
"(",
"errors",
".",
"length",
")",
"{",
"throw",
"new",
"Error",
"(",
"errors",
".",
"join",
"(",
"'\\n'",
")",
")",
"}",
"return",
"config",
"}"
] | Runs config validation. Throws error if the config is not valid.
@param config {Object}
@returns config {Object} | [
"Runs",
"config",
"validation",
".",
"Throws",
"error",
"if",
"the",
"config",
"is",
"not",
"valid",
"."
] | 098452423fd3cdc4d80f861d330d64bc82f7bbaf | https://github.com/okonet/lint-staged/blob/098452423fd3cdc4d80f861d330d64bc82f7bbaf/src/getConfig.js#L179-L224 |
8,211 | okonet/lint-staged | src/resolveTaskFn.js | execLinter | function execLinter(bin, args, execaOptions, pathsToLint) {
const binArgs = args.concat(pathsToLint)
debug('bin:', bin)
debug('args: %O', binArgs)
debug('opts: %o', execaOptions)
return execa(bin, binArgs, { ...execaOptions })
} | javascript | function execLinter(bin, args, execaOptions, pathsToLint) {
const binArgs = args.concat(pathsToLint)
debug('bin:', bin)
debug('args: %O', binArgs)
debug('opts: %o', execaOptions)
return execa(bin, binArgs, { ...execaOptions })
} | [
"function",
"execLinter",
"(",
"bin",
",",
"args",
",",
"execaOptions",
",",
"pathsToLint",
")",
"{",
"const",
"binArgs",
"=",
"args",
".",
"concat",
"(",
"pathsToLint",
")",
"debug",
"(",
"'bin:'",
",",
"bin",
")",
"debug",
"(",
"'args: %O'",
",",
"binArgs",
")",
"debug",
"(",
"'opts: %o'",
",",
"execaOptions",
")",
"return",
"execa",
"(",
"bin",
",",
"binArgs",
",",
"{",
"...",
"execaOptions",
"}",
")",
"}"
] | Execute the given linter binary with arguments and file paths using execa and
return the promise.
@param {string} bin
@param {Array<string>} args
@param {Object} execaOptions
@param {Array<string>} pathsToLint
@return {Promise} child_process | [
"Execute",
"the",
"given",
"linter",
"binary",
"with",
"arguments",
"and",
"file",
"paths",
"using",
"execa",
"and",
"return",
"the",
"promise",
"."
] | 098452423fd3cdc4d80f861d330d64bc82f7bbaf | https://github.com/okonet/lint-staged/blob/098452423fd3cdc4d80f861d330d64bc82f7bbaf/src/resolveTaskFn.js#L25-L33 |
8,212 | okonet/lint-staged | src/resolveTaskFn.js | makeErr | function makeErr(linter, result, context = {}) {
// Indicate that some linter will fail so we don't update the index with formatting changes
context.hasErrors = true // eslint-disable-line no-param-reassign
const { stdout, stderr, killed, signal } = result
if (killed || (signal && signal !== '')) {
return throwError(
`${symbols.warning} ${chalk.yellow(`${linter} was terminated with ${signal}`)}`
)
}
return throwError(dedent`${symbols.error} ${chalk.redBright(
`${linter} found some errors. Please fix them and try committing again.`
)}
${stdout}
${stderr}
`)
} | javascript | function makeErr(linter, result, context = {}) {
// Indicate that some linter will fail so we don't update the index with formatting changes
context.hasErrors = true // eslint-disable-line no-param-reassign
const { stdout, stderr, killed, signal } = result
if (killed || (signal && signal !== '')) {
return throwError(
`${symbols.warning} ${chalk.yellow(`${linter} was terminated with ${signal}`)}`
)
}
return throwError(dedent`${symbols.error} ${chalk.redBright(
`${linter} found some errors. Please fix them and try committing again.`
)}
${stdout}
${stderr}
`)
} | [
"function",
"makeErr",
"(",
"linter",
",",
"result",
",",
"context",
"=",
"{",
"}",
")",
"{",
"// Indicate that some linter will fail so we don't update the index with formatting changes",
"context",
".",
"hasErrors",
"=",
"true",
"// eslint-disable-line no-param-reassign",
"const",
"{",
"stdout",
",",
"stderr",
",",
"killed",
",",
"signal",
"}",
"=",
"result",
"if",
"(",
"killed",
"||",
"(",
"signal",
"&&",
"signal",
"!==",
"''",
")",
")",
"{",
"return",
"throwError",
"(",
"`",
"${",
"symbols",
".",
"warning",
"}",
"${",
"chalk",
".",
"yellow",
"(",
"`",
"${",
"linter",
"}",
"${",
"signal",
"}",
"`",
")",
"}",
"`",
")",
"}",
"return",
"throwError",
"(",
"dedent",
"`",
"${",
"symbols",
".",
"error",
"}",
"${",
"chalk",
".",
"redBright",
"(",
"`",
"${",
"linter",
"}",
"`",
")",
"}",
"${",
"stdout",
"}",
"${",
"stderr",
"}",
"`",
")",
"}"
] | Create a failure message dependding on process result.
@param {string} linter
@param {Object} result
@param {string} result.stdout
@param {string} result.stderr
@param {boolean} result.failed
@param {boolean} result.killed
@param {string} result.signal
@param {Object} context (see https://github.com/SamVerschueren/listr#context)
@returns {Error} | [
"Create",
"a",
"failure",
"message",
"dependding",
"on",
"process",
"result",
"."
] | 098452423fd3cdc4d80f861d330d64bc82f7bbaf | https://github.com/okonet/lint-staged/blob/098452423fd3cdc4d80f861d330d64bc82f7bbaf/src/resolveTaskFn.js#L65-L80 |
8,213 | oliviertassinari/react-swipeable-views | packages/react-swipeable-views-core/src/mod.js | mod | function mod(n, m) {
const q = n % m;
return q < 0 ? q + m : q;
} | javascript | function mod(n, m) {
const q = n % m;
return q < 0 ? q + m : q;
} | [
"function",
"mod",
"(",
"n",
",",
"m",
")",
"{",
"const",
"q",
"=",
"n",
"%",
"m",
";",
"return",
"q",
"<",
"0",
"?",
"q",
"+",
"m",
":",
"q",
";",
"}"
] | Extended version of % with negative integer support. | [
"Extended",
"version",
"of",
"%",
"with",
"negative",
"integer",
"support",
"."
] | 400a004ef2a1c3f7804091a9f47f48c94d2125bf | https://github.com/oliviertassinari/react-swipeable-views/blob/400a004ef2a1c3f7804091a9f47f48c94d2125bf/packages/react-swipeable-views-core/src/mod.js#L2-L5 |
8,214 | oliviertassinari/react-swipeable-views | packages/react-swipeable-views/src/SwipeableViews.js | applyRotationMatrix | function applyRotationMatrix(touch, axis) {
const rotationMatrix = axisProperties.rotationMatrix[axis];
return {
pageX: rotationMatrix.x[0] * touch.pageX + rotationMatrix.x[1] * touch.pageY,
pageY: rotationMatrix.y[0] * touch.pageX + rotationMatrix.y[1] * touch.pageY,
};
} | javascript | function applyRotationMatrix(touch, axis) {
const rotationMatrix = axisProperties.rotationMatrix[axis];
return {
pageX: rotationMatrix.x[0] * touch.pageX + rotationMatrix.x[1] * touch.pageY,
pageY: rotationMatrix.y[0] * touch.pageX + rotationMatrix.y[1] * touch.pageY,
};
} | [
"function",
"applyRotationMatrix",
"(",
"touch",
",",
"axis",
")",
"{",
"const",
"rotationMatrix",
"=",
"axisProperties",
".",
"rotationMatrix",
"[",
"axis",
"]",
";",
"return",
"{",
"pageX",
":",
"rotationMatrix",
".",
"x",
"[",
"0",
"]",
"*",
"touch",
".",
"pageX",
"+",
"rotationMatrix",
".",
"x",
"[",
"1",
"]",
"*",
"touch",
".",
"pageY",
",",
"pageY",
":",
"rotationMatrix",
".",
"y",
"[",
"0",
"]",
"*",
"touch",
".",
"pageX",
"+",
"rotationMatrix",
".",
"y",
"[",
"1",
"]",
"*",
"touch",
".",
"pageY",
",",
"}",
";",
"}"
] | We are using a 2x2 rotation matrix. | [
"We",
"are",
"using",
"a",
"2x2",
"rotation",
"matrix",
"."
] | 400a004ef2a1c3f7804091a9f47f48c94d2125bf | https://github.com/oliviertassinari/react-swipeable-views/blob/400a004ef2a1c3f7804091a9f47f48c94d2125bf/packages/react-swipeable-views/src/SwipeableViews.js#L115-L122 |
8,215 | jhildenbiddle/css-vars-ponyfill | src/transform-css.js | resolveFunc | function resolveFunc(value) {
const name = value.split(',')[0].replace(/[\s\n\t]/g, '');
const fallback = (value.match(/(?:\s*,\s*){1}(.*)?/) || [])[1];
const match = settings.variables.hasOwnProperty(name) ? String(settings.variables[name]) : undefined;
const replacement = match || (fallback ? String(fallback) : undefined);
const unresolvedFallback = __recursiveFallback || value;
if (!match) {
settings.onWarning(`variable "${name}" is undefined`);
}
if (replacement && replacement !== 'undefined' && replacement.length > 0) {
return resolveValue(replacement, settings, unresolvedFallback);
}
else {
return `var(${unresolvedFallback})`;
}
} | javascript | function resolveFunc(value) {
const name = value.split(',')[0].replace(/[\s\n\t]/g, '');
const fallback = (value.match(/(?:\s*,\s*){1}(.*)?/) || [])[1];
const match = settings.variables.hasOwnProperty(name) ? String(settings.variables[name]) : undefined;
const replacement = match || (fallback ? String(fallback) : undefined);
const unresolvedFallback = __recursiveFallback || value;
if (!match) {
settings.onWarning(`variable "${name}" is undefined`);
}
if (replacement && replacement !== 'undefined' && replacement.length > 0) {
return resolveValue(replacement, settings, unresolvedFallback);
}
else {
return `var(${unresolvedFallback})`;
}
} | [
"function",
"resolveFunc",
"(",
"value",
")",
"{",
"const",
"name",
"=",
"value",
".",
"split",
"(",
"','",
")",
"[",
"0",
"]",
".",
"replace",
"(",
"/",
"[\\s\\n\\t]",
"/",
"g",
",",
"''",
")",
";",
"const",
"fallback",
"=",
"(",
"value",
".",
"match",
"(",
"/",
"(?:\\s*,\\s*){1}(.*)?",
"/",
")",
"||",
"[",
"]",
")",
"[",
"1",
"]",
";",
"const",
"match",
"=",
"settings",
".",
"variables",
".",
"hasOwnProperty",
"(",
"name",
")",
"?",
"String",
"(",
"settings",
".",
"variables",
"[",
"name",
"]",
")",
":",
"undefined",
";",
"const",
"replacement",
"=",
"match",
"||",
"(",
"fallback",
"?",
"String",
"(",
"fallback",
")",
":",
"undefined",
")",
";",
"const",
"unresolvedFallback",
"=",
"__recursiveFallback",
"||",
"value",
";",
"if",
"(",
"!",
"match",
")",
"{",
"settings",
".",
"onWarning",
"(",
"`",
"${",
"name",
"}",
"`",
")",
";",
"}",
"if",
"(",
"replacement",
"&&",
"replacement",
"!==",
"'undefined'",
"&&",
"replacement",
".",
"length",
">",
"0",
")",
"{",
"return",
"resolveValue",
"(",
"replacement",
",",
"settings",
",",
"unresolvedFallback",
")",
";",
"}",
"else",
"{",
"return",
"`",
"${",
"unresolvedFallback",
"}",
"`",
";",
"}",
"}"
] | Resolves contents of CSS custom property function
@param {string} value String containing contents of CSS var() function
@returns {string}
@example
resolveFunc('--x, var(--y, green)')
// => obj['--x'] or obj['--y'] or 'green'
resolveFunc('--fail')
// => 'var(--fail)' when obj['--fail'] does not exist | [
"Resolves",
"contents",
"of",
"CSS",
"custom",
"property",
"function"
] | e22453fba24bdf0d593b0dbca17b05a947c7ed32 | https://github.com/jhildenbiddle/css-vars-ponyfill/blob/e22453fba24bdf0d593b0dbca17b05a947c7ed32/src/transform-css.js#L170-L187 |
8,216 | jhildenbiddle/css-vars-ponyfill | src/index.js | getTimeStamp | function getTimeStamp() {
return isBrowser && (window.performance || {}).now ? window.performance.now() : new Date().getTime();
} | javascript | function getTimeStamp() {
return isBrowser && (window.performance || {}).now ? window.performance.now() : new Date().getTime();
} | [
"function",
"getTimeStamp",
"(",
")",
"{",
"return",
"isBrowser",
"&&",
"(",
"window",
".",
"performance",
"||",
"{",
"}",
")",
".",
"now",
"?",
"window",
".",
"performance",
".",
"now",
"(",
")",
":",
"new",
"Date",
"(",
")",
".",
"getTime",
"(",
")",
";",
"}"
] | Returns a time stamp in milliseconds
@returns {number} | [
"Returns",
"a",
"time",
"stamp",
"in",
"milliseconds"
] | e22453fba24bdf0d593b0dbca17b05a947c7ed32 | https://github.com/jhildenbiddle/css-vars-ponyfill/blob/e22453fba24bdf0d593b0dbca17b05a947c7ed32/src/index.js#L797-L799 |
8,217 | iamdustan/smoothscroll | src/smoothscroll.js | shouldBailOut | function shouldBailOut(firstArg) {
if (
firstArg === null ||
typeof firstArg !== 'object' ||
firstArg.behavior === undefined ||
firstArg.behavior === 'auto' ||
firstArg.behavior === 'instant'
) {
// first argument is not an object/null
// or behavior is auto, instant or undefined
return true;
}
if (typeof firstArg === 'object' && firstArg.behavior === 'smooth') {
// first argument is an object and behavior is smooth
return false;
}
// throw error when behavior is not supported
throw new TypeError(
'behavior member of ScrollOptions ' +
firstArg.behavior +
' is not a valid value for enumeration ScrollBehavior.'
);
} | javascript | function shouldBailOut(firstArg) {
if (
firstArg === null ||
typeof firstArg !== 'object' ||
firstArg.behavior === undefined ||
firstArg.behavior === 'auto' ||
firstArg.behavior === 'instant'
) {
// first argument is not an object/null
// or behavior is auto, instant or undefined
return true;
}
if (typeof firstArg === 'object' && firstArg.behavior === 'smooth') {
// first argument is an object and behavior is smooth
return false;
}
// throw error when behavior is not supported
throw new TypeError(
'behavior member of ScrollOptions ' +
firstArg.behavior +
' is not a valid value for enumeration ScrollBehavior.'
);
} | [
"function",
"shouldBailOut",
"(",
"firstArg",
")",
"{",
"if",
"(",
"firstArg",
"===",
"null",
"||",
"typeof",
"firstArg",
"!==",
"'object'",
"||",
"firstArg",
".",
"behavior",
"===",
"undefined",
"||",
"firstArg",
".",
"behavior",
"===",
"'auto'",
"||",
"firstArg",
".",
"behavior",
"===",
"'instant'",
")",
"{",
"// first argument is not an object/null",
"// or behavior is auto, instant or undefined",
"return",
"true",
";",
"}",
"if",
"(",
"typeof",
"firstArg",
"===",
"'object'",
"&&",
"firstArg",
".",
"behavior",
"===",
"'smooth'",
")",
"{",
"// first argument is an object and behavior is smooth",
"return",
"false",
";",
"}",
"// throw error when behavior is not supported",
"throw",
"new",
"TypeError",
"(",
"'behavior member of ScrollOptions '",
"+",
"firstArg",
".",
"behavior",
"+",
"' is not a valid value for enumeration ScrollBehavior.'",
")",
";",
"}"
] | indicates if a smooth behavior should be applied
@method shouldBailOut
@param {Number|Object} firstArg
@returns {Boolean} | [
"indicates",
"if",
"a",
"smooth",
"behavior",
"should",
"be",
"applied"
] | 46ce13e65eee17640dacbbd50f7c64f4a393b3ef | https://github.com/iamdustan/smoothscroll/blob/46ce13e65eee17640dacbbd50f7c64f4a393b3ef/src/smoothscroll.js#L82-L106 |
8,218 | iamdustan/smoothscroll | src/smoothscroll.js | hasScrollableSpace | function hasScrollableSpace(el, axis) {
if (axis === 'Y') {
return el.clientHeight + ROUNDING_TOLERANCE < el.scrollHeight;
}
if (axis === 'X') {
return el.clientWidth + ROUNDING_TOLERANCE < el.scrollWidth;
}
} | javascript | function hasScrollableSpace(el, axis) {
if (axis === 'Y') {
return el.clientHeight + ROUNDING_TOLERANCE < el.scrollHeight;
}
if (axis === 'X') {
return el.clientWidth + ROUNDING_TOLERANCE < el.scrollWidth;
}
} | [
"function",
"hasScrollableSpace",
"(",
"el",
",",
"axis",
")",
"{",
"if",
"(",
"axis",
"===",
"'Y'",
")",
"{",
"return",
"el",
".",
"clientHeight",
"+",
"ROUNDING_TOLERANCE",
"<",
"el",
".",
"scrollHeight",
";",
"}",
"if",
"(",
"axis",
"===",
"'X'",
")",
"{",
"return",
"el",
".",
"clientWidth",
"+",
"ROUNDING_TOLERANCE",
"<",
"el",
".",
"scrollWidth",
";",
"}",
"}"
] | indicates if an element has scrollable space in the provided axis
@method hasScrollableSpace
@param {Node} el
@param {String} axis
@returns {Boolean} | [
"indicates",
"if",
"an",
"element",
"has",
"scrollable",
"space",
"in",
"the",
"provided",
"axis"
] | 46ce13e65eee17640dacbbd50f7c64f4a393b3ef | https://github.com/iamdustan/smoothscroll/blob/46ce13e65eee17640dacbbd50f7c64f4a393b3ef/src/smoothscroll.js#L115-L123 |
8,219 | iamdustan/smoothscroll | src/smoothscroll.js | canOverflow | function canOverflow(el, axis) {
var overflowValue = w.getComputedStyle(el, null)['overflow' + axis];
return overflowValue === 'auto' || overflowValue === 'scroll';
} | javascript | function canOverflow(el, axis) {
var overflowValue = w.getComputedStyle(el, null)['overflow' + axis];
return overflowValue === 'auto' || overflowValue === 'scroll';
} | [
"function",
"canOverflow",
"(",
"el",
",",
"axis",
")",
"{",
"var",
"overflowValue",
"=",
"w",
".",
"getComputedStyle",
"(",
"el",
",",
"null",
")",
"[",
"'overflow'",
"+",
"axis",
"]",
";",
"return",
"overflowValue",
"===",
"'auto'",
"||",
"overflowValue",
"===",
"'scroll'",
";",
"}"
] | indicates if an element has a scrollable overflow property in the axis
@method canOverflow
@param {Node} el
@param {String} axis
@returns {Boolean} | [
"indicates",
"if",
"an",
"element",
"has",
"a",
"scrollable",
"overflow",
"property",
"in",
"the",
"axis"
] | 46ce13e65eee17640dacbbd50f7c64f4a393b3ef | https://github.com/iamdustan/smoothscroll/blob/46ce13e65eee17640dacbbd50f7c64f4a393b3ef/src/smoothscroll.js#L132-L136 |
8,220 | iamdustan/smoothscroll | src/smoothscroll.js | isScrollable | function isScrollable(el) {
var isScrollableY = hasScrollableSpace(el, 'Y') && canOverflow(el, 'Y');
var isScrollableX = hasScrollableSpace(el, 'X') && canOverflow(el, 'X');
return isScrollableY || isScrollableX;
} | javascript | function isScrollable(el) {
var isScrollableY = hasScrollableSpace(el, 'Y') && canOverflow(el, 'Y');
var isScrollableX = hasScrollableSpace(el, 'X') && canOverflow(el, 'X');
return isScrollableY || isScrollableX;
} | [
"function",
"isScrollable",
"(",
"el",
")",
"{",
"var",
"isScrollableY",
"=",
"hasScrollableSpace",
"(",
"el",
",",
"'Y'",
")",
"&&",
"canOverflow",
"(",
"el",
",",
"'Y'",
")",
";",
"var",
"isScrollableX",
"=",
"hasScrollableSpace",
"(",
"el",
",",
"'X'",
")",
"&&",
"canOverflow",
"(",
"el",
",",
"'X'",
")",
";",
"return",
"isScrollableY",
"||",
"isScrollableX",
";",
"}"
] | indicates if an element can be scrolled in either axis
@method isScrollable
@param {Node} el
@param {String} axis
@returns {Boolean} | [
"indicates",
"if",
"an",
"element",
"can",
"be",
"scrolled",
"in",
"either",
"axis"
] | 46ce13e65eee17640dacbbd50f7c64f4a393b3ef | https://github.com/iamdustan/smoothscroll/blob/46ce13e65eee17640dacbbd50f7c64f4a393b3ef/src/smoothscroll.js#L145-L150 |
8,221 | iamdustan/smoothscroll | src/smoothscroll.js | findScrollableParent | function findScrollableParent(el) {
while (el !== d.body && isScrollable(el) === false) {
el = el.parentNode || el.host;
}
return el;
} | javascript | function findScrollableParent(el) {
while (el !== d.body && isScrollable(el) === false) {
el = el.parentNode || el.host;
}
return el;
} | [
"function",
"findScrollableParent",
"(",
"el",
")",
"{",
"while",
"(",
"el",
"!==",
"d",
".",
"body",
"&&",
"isScrollable",
"(",
"el",
")",
"===",
"false",
")",
"{",
"el",
"=",
"el",
".",
"parentNode",
"||",
"el",
".",
"host",
";",
"}",
"return",
"el",
";",
"}"
] | finds scrollable parent of an element
@method findScrollableParent
@param {Node} el
@returns {Node} el | [
"finds",
"scrollable",
"parent",
"of",
"an",
"element"
] | 46ce13e65eee17640dacbbd50f7c64f4a393b3ef | https://github.com/iamdustan/smoothscroll/blob/46ce13e65eee17640dacbbd50f7c64f4a393b3ef/src/smoothscroll.js#L158-L164 |
8,222 | iamdustan/smoothscroll | src/smoothscroll.js | smoothScroll | function smoothScroll(el, x, y) {
var scrollable;
var startX;
var startY;
var method;
var startTime = now();
// define scroll context
if (el === d.body) {
scrollable = w;
startX = w.scrollX || w.pageXOffset;
startY = w.scrollY || w.pageYOffset;
method = original.scroll;
} else {
scrollable = el;
startX = el.scrollLeft;
startY = el.scrollTop;
method = scrollElement;
}
// scroll looping over a frame
step({
scrollable: scrollable,
method: method,
startTime: startTime,
startX: startX,
startY: startY,
x: x,
y: y
});
} | javascript | function smoothScroll(el, x, y) {
var scrollable;
var startX;
var startY;
var method;
var startTime = now();
// define scroll context
if (el === d.body) {
scrollable = w;
startX = w.scrollX || w.pageXOffset;
startY = w.scrollY || w.pageYOffset;
method = original.scroll;
} else {
scrollable = el;
startX = el.scrollLeft;
startY = el.scrollTop;
method = scrollElement;
}
// scroll looping over a frame
step({
scrollable: scrollable,
method: method,
startTime: startTime,
startX: startX,
startY: startY,
x: x,
y: y
});
} | [
"function",
"smoothScroll",
"(",
"el",
",",
"x",
",",
"y",
")",
"{",
"var",
"scrollable",
";",
"var",
"startX",
";",
"var",
"startY",
";",
"var",
"method",
";",
"var",
"startTime",
"=",
"now",
"(",
")",
";",
"// define scroll context",
"if",
"(",
"el",
"===",
"d",
".",
"body",
")",
"{",
"scrollable",
"=",
"w",
";",
"startX",
"=",
"w",
".",
"scrollX",
"||",
"w",
".",
"pageXOffset",
";",
"startY",
"=",
"w",
".",
"scrollY",
"||",
"w",
".",
"pageYOffset",
";",
"method",
"=",
"original",
".",
"scroll",
";",
"}",
"else",
"{",
"scrollable",
"=",
"el",
";",
"startX",
"=",
"el",
".",
"scrollLeft",
";",
"startY",
"=",
"el",
".",
"scrollTop",
";",
"method",
"=",
"scrollElement",
";",
"}",
"// scroll looping over a frame",
"step",
"(",
"{",
"scrollable",
":",
"scrollable",
",",
"method",
":",
"method",
",",
"startTime",
":",
"startTime",
",",
"startX",
":",
"startX",
",",
"startY",
":",
"startY",
",",
"x",
":",
"x",
",",
"y",
":",
"y",
"}",
")",
";",
"}"
] | scrolls window or element with a smooth behavior
@method smoothScroll
@param {Object|Node} el
@param {Number} x
@param {Number} y
@returns {undefined} | [
"scrolls",
"window",
"or",
"element",
"with",
"a",
"smooth",
"behavior"
] | 46ce13e65eee17640dacbbd50f7c64f4a393b3ef | https://github.com/iamdustan/smoothscroll/blob/46ce13e65eee17640dacbbd50f7c64f4a393b3ef/src/smoothscroll.js#L204-L234 |
8,223 | kaola-fed/megalo | dist/vue.runtime.esm.js | defineReactive$$1 | function defineReactive$$1 (
obj,
key,
val,
customSetter,
shallow
) {
var dep = new Dep();
var property = Object.getOwnPropertyDescriptor(obj, key);
if (property && property.configurable === false) {
return
}
// cater for pre-defined getter/setters
var getter = property && property.get;
var setter = property && property.set;
if ((!getter || setter) && arguments.length === 2) {
val = obj[key];
}
var childOb = !shallow && observe(val);
Object.defineProperty(obj, key, {
enumerable: true,
configurable: true,
get: function reactiveGetter () {
var value = getter ? getter.call(obj) : val;
if (Dep.target) {
dep.depend();
if (childOb) {
childOb.dep.depend();
if (Array.isArray(value)) {
dependArray(value);
}
}
}
return value
},
set: function reactiveSetter (newVal) {
var value = getter ? getter.call(obj) : val;
/* eslint-disable no-self-compare */
if (newVal === value || (newVal !== newVal && value !== value)) {
return
}
/* eslint-enable no-self-compare */
if (process.env.NODE_ENV !== 'production' && customSetter) {
customSetter();
}
// #7981: for accessor properties without setter
if (getter && !setter) { return }
if (setter) {
setter.call(obj, newVal);
} else {
val = newVal;
}
childOb = !shallow && observe(newVal);
dep.notify();
}
});
} | javascript | function defineReactive$$1 (
obj,
key,
val,
customSetter,
shallow
) {
var dep = new Dep();
var property = Object.getOwnPropertyDescriptor(obj, key);
if (property && property.configurable === false) {
return
}
// cater for pre-defined getter/setters
var getter = property && property.get;
var setter = property && property.set;
if ((!getter || setter) && arguments.length === 2) {
val = obj[key];
}
var childOb = !shallow && observe(val);
Object.defineProperty(obj, key, {
enumerable: true,
configurable: true,
get: function reactiveGetter () {
var value = getter ? getter.call(obj) : val;
if (Dep.target) {
dep.depend();
if (childOb) {
childOb.dep.depend();
if (Array.isArray(value)) {
dependArray(value);
}
}
}
return value
},
set: function reactiveSetter (newVal) {
var value = getter ? getter.call(obj) : val;
/* eslint-disable no-self-compare */
if (newVal === value || (newVal !== newVal && value !== value)) {
return
}
/* eslint-enable no-self-compare */
if (process.env.NODE_ENV !== 'production' && customSetter) {
customSetter();
}
// #7981: for accessor properties without setter
if (getter && !setter) { return }
if (setter) {
setter.call(obj, newVal);
} else {
val = newVal;
}
childOb = !shallow && observe(newVal);
dep.notify();
}
});
} | [
"function",
"defineReactive$$1",
"(",
"obj",
",",
"key",
",",
"val",
",",
"customSetter",
",",
"shallow",
")",
"{",
"var",
"dep",
"=",
"new",
"Dep",
"(",
")",
";",
"var",
"property",
"=",
"Object",
".",
"getOwnPropertyDescriptor",
"(",
"obj",
",",
"key",
")",
";",
"if",
"(",
"property",
"&&",
"property",
".",
"configurable",
"===",
"false",
")",
"{",
"return",
"}",
"// cater for pre-defined getter/setters",
"var",
"getter",
"=",
"property",
"&&",
"property",
".",
"get",
";",
"var",
"setter",
"=",
"property",
"&&",
"property",
".",
"set",
";",
"if",
"(",
"(",
"!",
"getter",
"||",
"setter",
")",
"&&",
"arguments",
".",
"length",
"===",
"2",
")",
"{",
"val",
"=",
"obj",
"[",
"key",
"]",
";",
"}",
"var",
"childOb",
"=",
"!",
"shallow",
"&&",
"observe",
"(",
"val",
")",
";",
"Object",
".",
"defineProperty",
"(",
"obj",
",",
"key",
",",
"{",
"enumerable",
":",
"true",
",",
"configurable",
":",
"true",
",",
"get",
":",
"function",
"reactiveGetter",
"(",
")",
"{",
"var",
"value",
"=",
"getter",
"?",
"getter",
".",
"call",
"(",
"obj",
")",
":",
"val",
";",
"if",
"(",
"Dep",
".",
"target",
")",
"{",
"dep",
".",
"depend",
"(",
")",
";",
"if",
"(",
"childOb",
")",
"{",
"childOb",
".",
"dep",
".",
"depend",
"(",
")",
";",
"if",
"(",
"Array",
".",
"isArray",
"(",
"value",
")",
")",
"{",
"dependArray",
"(",
"value",
")",
";",
"}",
"}",
"}",
"return",
"value",
"}",
",",
"set",
":",
"function",
"reactiveSetter",
"(",
"newVal",
")",
"{",
"var",
"value",
"=",
"getter",
"?",
"getter",
".",
"call",
"(",
"obj",
")",
":",
"val",
";",
"/* eslint-disable no-self-compare */",
"if",
"(",
"newVal",
"===",
"value",
"||",
"(",
"newVal",
"!==",
"newVal",
"&&",
"value",
"!==",
"value",
")",
")",
"{",
"return",
"}",
"/* eslint-enable no-self-compare */",
"if",
"(",
"process",
".",
"env",
".",
"NODE_ENV",
"!==",
"'production'",
"&&",
"customSetter",
")",
"{",
"customSetter",
"(",
")",
";",
"}",
"// #7981: for accessor properties without setter",
"if",
"(",
"getter",
"&&",
"!",
"setter",
")",
"{",
"return",
"}",
"if",
"(",
"setter",
")",
"{",
"setter",
".",
"call",
"(",
"obj",
",",
"newVal",
")",
";",
"}",
"else",
"{",
"val",
"=",
"newVal",
";",
"}",
"childOb",
"=",
"!",
"shallow",
"&&",
"observe",
"(",
"newVal",
")",
";",
"dep",
".",
"notify",
"(",
")",
";",
"}",
"}",
")",
";",
"}"
] | Define a reactive property on an Object. | [
"Define",
"a",
"reactive",
"property",
"on",
"an",
"Object",
"."
] | c5d971837c3467430469351084e0df9e4da34c4d | https://github.com/kaola-fed/megalo/blob/c5d971837c3467430469351084e0df9e4da34c4d/dist/vue.runtime.esm.js#L999-L1058 |
8,224 | kaola-fed/megalo | dist/vue.runtime.esm.js | queueWatcher | function queueWatcher (watcher) {
var id = watcher.id;
if (has[id] == null) {
has[id] = true;
if (!flushing) {
queue.push(watcher);
} else {
// if already flushing, splice the watcher based on its id
// if already past its id, it will be run next immediately.
var i = queue.length - 1;
while (i > index && queue[i].id > watcher.id) {
i--;
}
queue.splice(i + 1, 0, watcher);
}
// queue the flush
if (!waiting) {
waiting = true;
if (process.env.NODE_ENV !== 'production' && !config.async) {
flushSchedulerQueue();
return
}
nextTick(flushSchedulerQueue);
}
}
} | javascript | function queueWatcher (watcher) {
var id = watcher.id;
if (has[id] == null) {
has[id] = true;
if (!flushing) {
queue.push(watcher);
} else {
// if already flushing, splice the watcher based on its id
// if already past its id, it will be run next immediately.
var i = queue.length - 1;
while (i > index && queue[i].id > watcher.id) {
i--;
}
queue.splice(i + 1, 0, watcher);
}
// queue the flush
if (!waiting) {
waiting = true;
if (process.env.NODE_ENV !== 'production' && !config.async) {
flushSchedulerQueue();
return
}
nextTick(flushSchedulerQueue);
}
}
} | [
"function",
"queueWatcher",
"(",
"watcher",
")",
"{",
"var",
"id",
"=",
"watcher",
".",
"id",
";",
"if",
"(",
"has",
"[",
"id",
"]",
"==",
"null",
")",
"{",
"has",
"[",
"id",
"]",
"=",
"true",
";",
"if",
"(",
"!",
"flushing",
")",
"{",
"queue",
".",
"push",
"(",
"watcher",
")",
";",
"}",
"else",
"{",
"// if already flushing, splice the watcher based on its id",
"// if already past its id, it will be run next immediately.",
"var",
"i",
"=",
"queue",
".",
"length",
"-",
"1",
";",
"while",
"(",
"i",
">",
"index",
"&&",
"queue",
"[",
"i",
"]",
".",
"id",
">",
"watcher",
".",
"id",
")",
"{",
"i",
"--",
";",
"}",
"queue",
".",
"splice",
"(",
"i",
"+",
"1",
",",
"0",
",",
"watcher",
")",
";",
"}",
"// queue the flush",
"if",
"(",
"!",
"waiting",
")",
"{",
"waiting",
"=",
"true",
";",
"if",
"(",
"process",
".",
"env",
".",
"NODE_ENV",
"!==",
"'production'",
"&&",
"!",
"config",
".",
"async",
")",
"{",
"flushSchedulerQueue",
"(",
")",
";",
"return",
"}",
"nextTick",
"(",
"flushSchedulerQueue",
")",
";",
"}",
"}",
"}"
] | Push a watcher into the watcher queue.
Jobs with duplicate IDs will be skipped unless it's
pushed when the queue is being flushed. | [
"Push",
"a",
"watcher",
"into",
"the",
"watcher",
"queue",
".",
"Jobs",
"with",
"duplicate",
"IDs",
"will",
"be",
"skipped",
"unless",
"it",
"s",
"pushed",
"when",
"the",
"queue",
"is",
"being",
"flushed",
"."
] | c5d971837c3467430469351084e0df9e4da34c4d | https://github.com/kaola-fed/megalo/blob/c5d971837c3467430469351084e0df9e4da34c4d/dist/vue.runtime.esm.js#L4319-L4345 |
8,225 | kaola-fed/megalo | dist/vue.runtime.esm.js | getStyle | function getStyle (vnode, checkChild) {
var res = {};
var styleData;
if (checkChild) {
var childNode = vnode;
while (childNode.componentInstance) {
childNode = childNode.componentInstance._vnode;
if (
childNode && childNode.data &&
(styleData = normalizeStyleData(childNode.data))
) {
extend(res, styleData);
}
}
}
if ((styleData = normalizeStyleData(vnode.data))) {
extend(res, styleData);
}
var parentNode = vnode;
while ((parentNode = parentNode.parent)) {
if (parentNode.data && (styleData = normalizeStyleData(parentNode.data))) {
extend(res, styleData);
}
}
return res
} | javascript | function getStyle (vnode, checkChild) {
var res = {};
var styleData;
if (checkChild) {
var childNode = vnode;
while (childNode.componentInstance) {
childNode = childNode.componentInstance._vnode;
if (
childNode && childNode.data &&
(styleData = normalizeStyleData(childNode.data))
) {
extend(res, styleData);
}
}
}
if ((styleData = normalizeStyleData(vnode.data))) {
extend(res, styleData);
}
var parentNode = vnode;
while ((parentNode = parentNode.parent)) {
if (parentNode.data && (styleData = normalizeStyleData(parentNode.data))) {
extend(res, styleData);
}
}
return res
} | [
"function",
"getStyle",
"(",
"vnode",
",",
"checkChild",
")",
"{",
"var",
"res",
"=",
"{",
"}",
";",
"var",
"styleData",
";",
"if",
"(",
"checkChild",
")",
"{",
"var",
"childNode",
"=",
"vnode",
";",
"while",
"(",
"childNode",
".",
"componentInstance",
")",
"{",
"childNode",
"=",
"childNode",
".",
"componentInstance",
".",
"_vnode",
";",
"if",
"(",
"childNode",
"&&",
"childNode",
".",
"data",
"&&",
"(",
"styleData",
"=",
"normalizeStyleData",
"(",
"childNode",
".",
"data",
")",
")",
")",
"{",
"extend",
"(",
"res",
",",
"styleData",
")",
";",
"}",
"}",
"}",
"if",
"(",
"(",
"styleData",
"=",
"normalizeStyleData",
"(",
"vnode",
".",
"data",
")",
")",
")",
"{",
"extend",
"(",
"res",
",",
"styleData",
")",
";",
"}",
"var",
"parentNode",
"=",
"vnode",
";",
"while",
"(",
"(",
"parentNode",
"=",
"parentNode",
".",
"parent",
")",
")",
"{",
"if",
"(",
"parentNode",
".",
"data",
"&&",
"(",
"styleData",
"=",
"normalizeStyleData",
"(",
"parentNode",
".",
"data",
")",
")",
")",
"{",
"extend",
"(",
"res",
",",
"styleData",
")",
";",
"}",
"}",
"return",
"res",
"}"
] | parent component style should be after child's
so that parent component's style could override it | [
"parent",
"component",
"style",
"should",
"be",
"after",
"child",
"s",
"so",
"that",
"parent",
"component",
"s",
"style",
"could",
"override",
"it"
] | c5d971837c3467430469351084e0df9e4da34c4d | https://github.com/kaola-fed/megalo/blob/c5d971837c3467430469351084e0df9e4da34c4d/dist/vue.runtime.esm.js#L7048-L7076 |
8,226 | kaola-fed/megalo | packages/weex-template-compiler/build.js | postTransformComponent | function postTransformComponent (
el,
options
) {
// $flow-disable-line (we know isReservedTag is there)
if (!options.isReservedTag(el.tag) && el.tag !== 'cell-slot') {
addAttr(el, RECYCLE_LIST_MARKER, 'true');
}
} | javascript | function postTransformComponent (
el,
options
) {
// $flow-disable-line (we know isReservedTag is there)
if (!options.isReservedTag(el.tag) && el.tag !== 'cell-slot') {
addAttr(el, RECYCLE_LIST_MARKER, 'true');
}
} | [
"function",
"postTransformComponent",
"(",
"el",
",",
"options",
")",
"{",
"// $flow-disable-line (we know isReservedTag is there)",
"if",
"(",
"!",
"options",
".",
"isReservedTag",
"(",
"el",
".",
"tag",
")",
"&&",
"el",
".",
"tag",
"!==",
"'cell-slot'",
")",
"{",
"addAttr",
"(",
"el",
",",
"RECYCLE_LIST_MARKER",
",",
"'true'",
")",
";",
"}",
"}"
] | mark components as inside recycle-list so that we know we need to invoke their special @render function instead of render in create-component.js | [
"mark",
"components",
"as",
"inside",
"recycle",
"-",
"list",
"so",
"that",
"we",
"know",
"we",
"need",
"to",
"invoke",
"their",
"special"
] | c5d971837c3467430469351084e0df9e4da34c4d | https://github.com/kaola-fed/megalo/blob/c5d971837c3467430469351084e0df9e4da34c4d/packages/weex-template-compiler/build.js#L3965-L3973 |
8,227 | kaola-fed/megalo | packages/weex-vue-framework/factory.js | registerComponentHook | function registerComponentHook (
componentId,
type, // hook type, could be "lifecycle" or "instance"
hook, // hook name
fn
) {
if (!document || !document.taskCenter) {
warn("Can't find available \"document\" or \"taskCenter\".");
return
}
if (typeof document.taskCenter.registerHook === 'function') {
return document.taskCenter.registerHook(componentId, type, hook, fn)
}
warn(("Failed to register component hook \"" + type + "@" + hook + "#" + componentId + "\"."));
} | javascript | function registerComponentHook (
componentId,
type, // hook type, could be "lifecycle" or "instance"
hook, // hook name
fn
) {
if (!document || !document.taskCenter) {
warn("Can't find available \"document\" or \"taskCenter\".");
return
}
if (typeof document.taskCenter.registerHook === 'function') {
return document.taskCenter.registerHook(componentId, type, hook, fn)
}
warn(("Failed to register component hook \"" + type + "@" + hook + "#" + componentId + "\"."));
} | [
"function",
"registerComponentHook",
"(",
"componentId",
",",
"type",
",",
"// hook type, could be \"lifecycle\" or \"instance\"",
"hook",
",",
"// hook name",
"fn",
")",
"{",
"if",
"(",
"!",
"document",
"||",
"!",
"document",
".",
"taskCenter",
")",
"{",
"warn",
"(",
"\"Can't find available \\\"document\\\" or \\\"taskCenter\\\".\"",
")",
";",
"return",
"}",
"if",
"(",
"typeof",
"document",
".",
"taskCenter",
".",
"registerHook",
"===",
"'function'",
")",
"{",
"return",
"document",
".",
"taskCenter",
".",
"registerHook",
"(",
"componentId",
",",
"type",
",",
"hook",
",",
"fn",
")",
"}",
"warn",
"(",
"(",
"\"Failed to register component hook \\\"\"",
"+",
"type",
"+",
"\"@\"",
"+",
"hook",
"+",
"\"#\"",
"+",
"componentId",
"+",
"\"\\\".\"",
")",
")",
";",
"}"
] | Register the component hook to weex native render engine. The hook will be triggered by native, not javascript. | [
"Register",
"the",
"component",
"hook",
"to",
"weex",
"native",
"render",
"engine",
".",
"The",
"hook",
"will",
"be",
"triggered",
"by",
"native",
"not",
"javascript",
"."
] | c5d971837c3467430469351084e0df9e4da34c4d | https://github.com/kaola-fed/megalo/blob/c5d971837c3467430469351084e0df9e4da34c4d/packages/weex-vue-framework/factory.js#L4082-L4096 |
8,228 | kaola-fed/megalo | packages/weex-vue-framework/factory.js | updateComponentData | function updateComponentData (
componentId,
newData,
callback
) {
if (!document || !document.taskCenter) {
warn("Can't find available \"document\" or \"taskCenter\".");
return
}
if (typeof document.taskCenter.updateData === 'function') {
return document.taskCenter.updateData(componentId, newData, callback)
}
warn(("Failed to update component data (" + componentId + ")."));
} | javascript | function updateComponentData (
componentId,
newData,
callback
) {
if (!document || !document.taskCenter) {
warn("Can't find available \"document\" or \"taskCenter\".");
return
}
if (typeof document.taskCenter.updateData === 'function') {
return document.taskCenter.updateData(componentId, newData, callback)
}
warn(("Failed to update component data (" + componentId + ")."));
} | [
"function",
"updateComponentData",
"(",
"componentId",
",",
"newData",
",",
"callback",
")",
"{",
"if",
"(",
"!",
"document",
"||",
"!",
"document",
".",
"taskCenter",
")",
"{",
"warn",
"(",
"\"Can't find available \\\"document\\\" or \\\"taskCenter\\\".\"",
")",
";",
"return",
"}",
"if",
"(",
"typeof",
"document",
".",
"taskCenter",
".",
"updateData",
"===",
"'function'",
")",
"{",
"return",
"document",
".",
"taskCenter",
".",
"updateData",
"(",
"componentId",
",",
"newData",
",",
"callback",
")",
"}",
"warn",
"(",
"(",
"\"Failed to update component data (\"",
"+",
"componentId",
"+",
"\").\"",
")",
")",
";",
"}"
] | Updates the state of the component to weex native render engine. | [
"Updates",
"the",
"state",
"of",
"the",
"component",
"to",
"weex",
"native",
"render",
"engine",
"."
] | c5d971837c3467430469351084e0df9e4da34c4d | https://github.com/kaola-fed/megalo/blob/c5d971837c3467430469351084e0df9e4da34c4d/packages/weex-vue-framework/factory.js#L4099-L4112 |
8,229 | kaola-fed/megalo | packages/weex-vue-framework/factory.js | initVirtualComponent | function initVirtualComponent (options) {
if ( options === void 0 ) options = {};
var vm = this;
var componentId = options.componentId;
// virtual component uid
vm._uid = "virtual-component-" + (uid$2++);
// a flag to avoid this being observed
vm._isVue = true;
// merge options
if (options && options._isComponent) {
// optimize internal component instantiation
// since dynamic options merging is pretty slow, and none of the
// internal component options needs special treatment.
initInternalComponent(vm, options);
} else {
vm.$options = mergeOptions(
resolveConstructorOptions(vm.constructor),
options || {},
vm
);
}
/* istanbul ignore else */
if (process.env.NODE_ENV !== 'production') {
initProxy(vm);
} else {
vm._renderProxy = vm;
}
vm._self = vm;
initLifecycle(vm);
initEvents(vm);
initRender(vm);
callHook(vm, 'beforeCreate');
initInjections(vm); // resolve injections before data/props
initState(vm);
initProvide(vm); // resolve provide after data/props
callHook(vm, 'created');
// send initial data to native
var data = vm.$options.data;
var params = typeof data === 'function'
? getData(data, vm)
: data || {};
if (isPlainObject(params)) {
updateComponentData(componentId, params);
}
registerComponentHook(componentId, 'lifecycle', 'attach', function () {
callHook(vm, 'beforeMount');
var updateComponent = function () {
vm._update(vm._vnode, false);
};
new Watcher(vm, updateComponent, noop, null, true);
vm._isMounted = true;
callHook(vm, 'mounted');
});
registerComponentHook(componentId, 'lifecycle', 'detach', function () {
vm.$destroy();
});
} | javascript | function initVirtualComponent (options) {
if ( options === void 0 ) options = {};
var vm = this;
var componentId = options.componentId;
// virtual component uid
vm._uid = "virtual-component-" + (uid$2++);
// a flag to avoid this being observed
vm._isVue = true;
// merge options
if (options && options._isComponent) {
// optimize internal component instantiation
// since dynamic options merging is pretty slow, and none of the
// internal component options needs special treatment.
initInternalComponent(vm, options);
} else {
vm.$options = mergeOptions(
resolveConstructorOptions(vm.constructor),
options || {},
vm
);
}
/* istanbul ignore else */
if (process.env.NODE_ENV !== 'production') {
initProxy(vm);
} else {
vm._renderProxy = vm;
}
vm._self = vm;
initLifecycle(vm);
initEvents(vm);
initRender(vm);
callHook(vm, 'beforeCreate');
initInjections(vm); // resolve injections before data/props
initState(vm);
initProvide(vm); // resolve provide after data/props
callHook(vm, 'created');
// send initial data to native
var data = vm.$options.data;
var params = typeof data === 'function'
? getData(data, vm)
: data || {};
if (isPlainObject(params)) {
updateComponentData(componentId, params);
}
registerComponentHook(componentId, 'lifecycle', 'attach', function () {
callHook(vm, 'beforeMount');
var updateComponent = function () {
vm._update(vm._vnode, false);
};
new Watcher(vm, updateComponent, noop, null, true);
vm._isMounted = true;
callHook(vm, 'mounted');
});
registerComponentHook(componentId, 'lifecycle', 'detach', function () {
vm.$destroy();
});
} | [
"function",
"initVirtualComponent",
"(",
"options",
")",
"{",
"if",
"(",
"options",
"===",
"void",
"0",
")",
"options",
"=",
"{",
"}",
";",
"var",
"vm",
"=",
"this",
";",
"var",
"componentId",
"=",
"options",
".",
"componentId",
";",
"// virtual component uid",
"vm",
".",
"_uid",
"=",
"\"virtual-component-\"",
"+",
"(",
"uid$2",
"++",
")",
";",
"// a flag to avoid this being observed",
"vm",
".",
"_isVue",
"=",
"true",
";",
"// merge options",
"if",
"(",
"options",
"&&",
"options",
".",
"_isComponent",
")",
"{",
"// optimize internal component instantiation",
"// since dynamic options merging is pretty slow, and none of the",
"// internal component options needs special treatment.",
"initInternalComponent",
"(",
"vm",
",",
"options",
")",
";",
"}",
"else",
"{",
"vm",
".",
"$options",
"=",
"mergeOptions",
"(",
"resolveConstructorOptions",
"(",
"vm",
".",
"constructor",
")",
",",
"options",
"||",
"{",
"}",
",",
"vm",
")",
";",
"}",
"/* istanbul ignore else */",
"if",
"(",
"process",
".",
"env",
".",
"NODE_ENV",
"!==",
"'production'",
")",
"{",
"initProxy",
"(",
"vm",
")",
";",
"}",
"else",
"{",
"vm",
".",
"_renderProxy",
"=",
"vm",
";",
"}",
"vm",
".",
"_self",
"=",
"vm",
";",
"initLifecycle",
"(",
"vm",
")",
";",
"initEvents",
"(",
"vm",
")",
";",
"initRender",
"(",
"vm",
")",
";",
"callHook",
"(",
"vm",
",",
"'beforeCreate'",
")",
";",
"initInjections",
"(",
"vm",
")",
";",
"// resolve injections before data/props",
"initState",
"(",
"vm",
")",
";",
"initProvide",
"(",
"vm",
")",
";",
"// resolve provide after data/props",
"callHook",
"(",
"vm",
",",
"'created'",
")",
";",
"// send initial data to native",
"var",
"data",
"=",
"vm",
".",
"$options",
".",
"data",
";",
"var",
"params",
"=",
"typeof",
"data",
"===",
"'function'",
"?",
"getData",
"(",
"data",
",",
"vm",
")",
":",
"data",
"||",
"{",
"}",
";",
"if",
"(",
"isPlainObject",
"(",
"params",
")",
")",
"{",
"updateComponentData",
"(",
"componentId",
",",
"params",
")",
";",
"}",
"registerComponentHook",
"(",
"componentId",
",",
"'lifecycle'",
",",
"'attach'",
",",
"function",
"(",
")",
"{",
"callHook",
"(",
"vm",
",",
"'beforeMount'",
")",
";",
"var",
"updateComponent",
"=",
"function",
"(",
")",
"{",
"vm",
".",
"_update",
"(",
"vm",
".",
"_vnode",
",",
"false",
")",
";",
"}",
";",
"new",
"Watcher",
"(",
"vm",
",",
"updateComponent",
",",
"noop",
",",
"null",
",",
"true",
")",
";",
"vm",
".",
"_isMounted",
"=",
"true",
";",
"callHook",
"(",
"vm",
",",
"'mounted'",
")",
";",
"}",
")",
";",
"registerComponentHook",
"(",
"componentId",
",",
"'lifecycle'",
",",
"'detach'",
",",
"function",
"(",
")",
"{",
"vm",
".",
"$destroy",
"(",
")",
";",
"}",
")",
";",
"}"
] | override Vue.prototype._init | [
"override",
"Vue",
".",
"prototype",
".",
"_init"
] | c5d971837c3467430469351084e0df9e4da34c4d | https://github.com/kaola-fed/megalo/blob/c5d971837c3467430469351084e0df9e4da34c4d/packages/weex-vue-framework/factory.js#L4121-L4187 |
8,230 | kaola-fed/megalo | packages/weex-vue-framework/factory.js | updateVirtualComponent | function updateVirtualComponent (vnode) {
var vm = this;
var componentId = vm.$options.componentId;
if (vm._isMounted) {
callHook(vm, 'beforeUpdate');
}
vm._vnode = vnode;
if (vm._isMounted && componentId) {
// TODO: data should be filtered and without bindings
var data = Object.assign({}, vm._data);
updateComponentData(componentId, data, function () {
callHook(vm, 'updated');
});
}
} | javascript | function updateVirtualComponent (vnode) {
var vm = this;
var componentId = vm.$options.componentId;
if (vm._isMounted) {
callHook(vm, 'beforeUpdate');
}
vm._vnode = vnode;
if (vm._isMounted && componentId) {
// TODO: data should be filtered and without bindings
var data = Object.assign({}, vm._data);
updateComponentData(componentId, data, function () {
callHook(vm, 'updated');
});
}
} | [
"function",
"updateVirtualComponent",
"(",
"vnode",
")",
"{",
"var",
"vm",
"=",
"this",
";",
"var",
"componentId",
"=",
"vm",
".",
"$options",
".",
"componentId",
";",
"if",
"(",
"vm",
".",
"_isMounted",
")",
"{",
"callHook",
"(",
"vm",
",",
"'beforeUpdate'",
")",
";",
"}",
"vm",
".",
"_vnode",
"=",
"vnode",
";",
"if",
"(",
"vm",
".",
"_isMounted",
"&&",
"componentId",
")",
"{",
"// TODO: data should be filtered and without bindings",
"var",
"data",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"vm",
".",
"_data",
")",
";",
"updateComponentData",
"(",
"componentId",
",",
"data",
",",
"function",
"(",
")",
"{",
"callHook",
"(",
"vm",
",",
"'updated'",
")",
";",
"}",
")",
";",
"}",
"}"
] | override Vue.prototype._update | [
"override",
"Vue",
".",
"prototype",
".",
"_update"
] | c5d971837c3467430469351084e0df9e4da34c4d | https://github.com/kaola-fed/megalo/blob/c5d971837c3467430469351084e0df9e4da34c4d/packages/weex-vue-framework/factory.js#L4190-L4204 |
8,231 | kaola-fed/megalo | packages/weex-vue-framework/factory.js | resolveVirtualComponent | function resolveVirtualComponent (vnode) {
var BaseCtor = vnode.componentOptions.Ctor;
var VirtualComponent = BaseCtor.extend({});
var cid = VirtualComponent.cid;
VirtualComponent.prototype._init = initVirtualComponent;
VirtualComponent.prototype._update = updateVirtualComponent;
vnode.componentOptions.Ctor = BaseCtor.extend({
beforeCreate: function beforeCreate () {
// const vm: Component = this
// TODO: listen on all events and dispatch them to the
// corresponding virtual components according to the componentId.
// vm._virtualComponents = {}
var createVirtualComponent = function (componentId, propsData) {
// create virtual component
// const subVm =
new VirtualComponent({
componentId: componentId,
propsData: propsData
});
// if (vm._virtualComponents) {
// vm._virtualComponents[componentId] = subVm
// }
};
registerComponentHook(cid, 'lifecycle', 'create', createVirtualComponent);
},
beforeDestroy: function beforeDestroy () {
delete this._virtualComponents;
}
});
} | javascript | function resolveVirtualComponent (vnode) {
var BaseCtor = vnode.componentOptions.Ctor;
var VirtualComponent = BaseCtor.extend({});
var cid = VirtualComponent.cid;
VirtualComponent.prototype._init = initVirtualComponent;
VirtualComponent.prototype._update = updateVirtualComponent;
vnode.componentOptions.Ctor = BaseCtor.extend({
beforeCreate: function beforeCreate () {
// const vm: Component = this
// TODO: listen on all events and dispatch them to the
// corresponding virtual components according to the componentId.
// vm._virtualComponents = {}
var createVirtualComponent = function (componentId, propsData) {
// create virtual component
// const subVm =
new VirtualComponent({
componentId: componentId,
propsData: propsData
});
// if (vm._virtualComponents) {
// vm._virtualComponents[componentId] = subVm
// }
};
registerComponentHook(cid, 'lifecycle', 'create', createVirtualComponent);
},
beforeDestroy: function beforeDestroy () {
delete this._virtualComponents;
}
});
} | [
"function",
"resolveVirtualComponent",
"(",
"vnode",
")",
"{",
"var",
"BaseCtor",
"=",
"vnode",
".",
"componentOptions",
".",
"Ctor",
";",
"var",
"VirtualComponent",
"=",
"BaseCtor",
".",
"extend",
"(",
"{",
"}",
")",
";",
"var",
"cid",
"=",
"VirtualComponent",
".",
"cid",
";",
"VirtualComponent",
".",
"prototype",
".",
"_init",
"=",
"initVirtualComponent",
";",
"VirtualComponent",
".",
"prototype",
".",
"_update",
"=",
"updateVirtualComponent",
";",
"vnode",
".",
"componentOptions",
".",
"Ctor",
"=",
"BaseCtor",
".",
"extend",
"(",
"{",
"beforeCreate",
":",
"function",
"beforeCreate",
"(",
")",
"{",
"// const vm: Component = this",
"// TODO: listen on all events and dispatch them to the",
"// corresponding virtual components according to the componentId.",
"// vm._virtualComponents = {}",
"var",
"createVirtualComponent",
"=",
"function",
"(",
"componentId",
",",
"propsData",
")",
"{",
"// create virtual component",
"// const subVm =",
"new",
"VirtualComponent",
"(",
"{",
"componentId",
":",
"componentId",
",",
"propsData",
":",
"propsData",
"}",
")",
";",
"// if (vm._virtualComponents) {",
"// vm._virtualComponents[componentId] = subVm",
"// }",
"}",
";",
"registerComponentHook",
"(",
"cid",
",",
"'lifecycle'",
",",
"'create'",
",",
"createVirtualComponent",
")",
";",
"}",
",",
"beforeDestroy",
":",
"function",
"beforeDestroy",
"(",
")",
"{",
"delete",
"this",
".",
"_virtualComponents",
";",
"}",
"}",
")",
";",
"}"
] | listening on native callback | [
"listening",
"on",
"native",
"callback"
] | c5d971837c3467430469351084e0df9e4da34c4d | https://github.com/kaola-fed/megalo/blob/c5d971837c3467430469351084e0df9e4da34c4d/packages/weex-vue-framework/factory.js#L4207-L4239 |
8,232 | kaola-fed/megalo | packages/weex-vue-framework/index.js | createInstanceContext | function createInstanceContext (
instanceId,
runtimeContext,
data
) {
if ( data === void 0 ) data = {};
var weex = runtimeContext.weex;
var instance = instanceOptions[instanceId] = {
instanceId: instanceId,
config: weex.config,
document: weex.document,
data: data
};
// Each instance has a independent `Vue` module instance
var Vue = instance.Vue = createVueModuleInstance(instanceId, weex);
// DEPRECATED
var timerAPIs = getInstanceTimer(instanceId, weex.requireModule);
var instanceContext = Object.assign({ Vue: Vue }, timerAPIs);
Object.freeze(instanceContext);
return instanceContext
} | javascript | function createInstanceContext (
instanceId,
runtimeContext,
data
) {
if ( data === void 0 ) data = {};
var weex = runtimeContext.weex;
var instance = instanceOptions[instanceId] = {
instanceId: instanceId,
config: weex.config,
document: weex.document,
data: data
};
// Each instance has a independent `Vue` module instance
var Vue = instance.Vue = createVueModuleInstance(instanceId, weex);
// DEPRECATED
var timerAPIs = getInstanceTimer(instanceId, weex.requireModule);
var instanceContext = Object.assign({ Vue: Vue }, timerAPIs);
Object.freeze(instanceContext);
return instanceContext
} | [
"function",
"createInstanceContext",
"(",
"instanceId",
",",
"runtimeContext",
",",
"data",
")",
"{",
"if",
"(",
"data",
"===",
"void",
"0",
")",
"data",
"=",
"{",
"}",
";",
"var",
"weex",
"=",
"runtimeContext",
".",
"weex",
";",
"var",
"instance",
"=",
"instanceOptions",
"[",
"instanceId",
"]",
"=",
"{",
"instanceId",
":",
"instanceId",
",",
"config",
":",
"weex",
".",
"config",
",",
"document",
":",
"weex",
".",
"document",
",",
"data",
":",
"data",
"}",
";",
"// Each instance has a independent `Vue` module instance",
"var",
"Vue",
"=",
"instance",
".",
"Vue",
"=",
"createVueModuleInstance",
"(",
"instanceId",
",",
"weex",
")",
";",
"// DEPRECATED",
"var",
"timerAPIs",
"=",
"getInstanceTimer",
"(",
"instanceId",
",",
"weex",
".",
"requireModule",
")",
";",
"var",
"instanceContext",
"=",
"Object",
".",
"assign",
"(",
"{",
"Vue",
":",
"Vue",
"}",
",",
"timerAPIs",
")",
";",
"Object",
".",
"freeze",
"(",
"instanceContext",
")",
";",
"return",
"instanceContext",
"}"
] | Create instance context. | [
"Create",
"instance",
"context",
"."
] | c5d971837c3467430469351084e0df9e4da34c4d | https://github.com/kaola-fed/megalo/blob/c5d971837c3467430469351084e0df9e4da34c4d/packages/weex-vue-framework/index.js#L16-L40 |
8,233 | kaola-fed/megalo | packages/weex-vue-framework/index.js | getInstanceTimer | function getInstanceTimer (
instanceId,
moduleGetter
) {
var instance = instanceOptions[instanceId];
var timer = moduleGetter('timer');
var timerAPIs = {
setTimeout: function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var handler = function () {
args[0].apply(args, args.slice(2));
};
timer.setTimeout(handler, args[1]);
return instance.document.taskCenter.callbackManager.lastCallbackId.toString()
},
setInterval: function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var handler = function () {
args[0].apply(args, args.slice(2));
};
timer.setInterval(handler, args[1]);
return instance.document.taskCenter.callbackManager.lastCallbackId.toString()
},
clearTimeout: function (n) {
timer.clearTimeout(n);
},
clearInterval: function (n) {
timer.clearInterval(n);
}
};
return timerAPIs
} | javascript | function getInstanceTimer (
instanceId,
moduleGetter
) {
var instance = instanceOptions[instanceId];
var timer = moduleGetter('timer');
var timerAPIs = {
setTimeout: function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var handler = function () {
args[0].apply(args, args.slice(2));
};
timer.setTimeout(handler, args[1]);
return instance.document.taskCenter.callbackManager.lastCallbackId.toString()
},
setInterval: function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var handler = function () {
args[0].apply(args, args.slice(2));
};
timer.setInterval(handler, args[1]);
return instance.document.taskCenter.callbackManager.lastCallbackId.toString()
},
clearTimeout: function (n) {
timer.clearTimeout(n);
},
clearInterval: function (n) {
timer.clearInterval(n);
}
};
return timerAPIs
} | [
"function",
"getInstanceTimer",
"(",
"instanceId",
",",
"moduleGetter",
")",
"{",
"var",
"instance",
"=",
"instanceOptions",
"[",
"instanceId",
"]",
";",
"var",
"timer",
"=",
"moduleGetter",
"(",
"'timer'",
")",
";",
"var",
"timerAPIs",
"=",
"{",
"setTimeout",
":",
"function",
"(",
")",
"{",
"var",
"args",
"=",
"[",
"]",
",",
"len",
"=",
"arguments",
".",
"length",
";",
"while",
"(",
"len",
"--",
")",
"args",
"[",
"len",
"]",
"=",
"arguments",
"[",
"len",
"]",
";",
"var",
"handler",
"=",
"function",
"(",
")",
"{",
"args",
"[",
"0",
"]",
".",
"apply",
"(",
"args",
",",
"args",
".",
"slice",
"(",
"2",
")",
")",
";",
"}",
";",
"timer",
".",
"setTimeout",
"(",
"handler",
",",
"args",
"[",
"1",
"]",
")",
";",
"return",
"instance",
".",
"document",
".",
"taskCenter",
".",
"callbackManager",
".",
"lastCallbackId",
".",
"toString",
"(",
")",
"}",
",",
"setInterval",
":",
"function",
"(",
")",
"{",
"var",
"args",
"=",
"[",
"]",
",",
"len",
"=",
"arguments",
".",
"length",
";",
"while",
"(",
"len",
"--",
")",
"args",
"[",
"len",
"]",
"=",
"arguments",
"[",
"len",
"]",
";",
"var",
"handler",
"=",
"function",
"(",
")",
"{",
"args",
"[",
"0",
"]",
".",
"apply",
"(",
"args",
",",
"args",
".",
"slice",
"(",
"2",
")",
")",
";",
"}",
";",
"timer",
".",
"setInterval",
"(",
"handler",
",",
"args",
"[",
"1",
"]",
")",
";",
"return",
"instance",
".",
"document",
".",
"taskCenter",
".",
"callbackManager",
".",
"lastCallbackId",
".",
"toString",
"(",
")",
"}",
",",
"clearTimeout",
":",
"function",
"(",
"n",
")",
"{",
"timer",
".",
"clearTimeout",
"(",
"n",
")",
";",
"}",
",",
"clearInterval",
":",
"function",
"(",
"n",
")",
"{",
"timer",
".",
"clearInterval",
"(",
"n",
")",
";",
"}",
"}",
";",
"return",
"timerAPIs",
"}"
] | DEPRECATED
Generate HTML5 Timer APIs. An important point is that the callback
will be converted into callback id when sent to native. So the
framework can make sure no side effect of the callback happened after
an instance destroyed. | [
"DEPRECATED",
"Generate",
"HTML5",
"Timer",
"APIs",
".",
"An",
"important",
"point",
"is",
"that",
"the",
"callback",
"will",
"be",
"converted",
"into",
"callback",
"id",
"when",
"sent",
"to",
"native",
".",
"So",
"the",
"framework",
"can",
"make",
"sure",
"no",
"side",
"effect",
"of",
"the",
"callback",
"happened",
"after",
"an",
"instance",
"destroyed",
"."
] | c5d971837c3467430469351084e0df9e4da34c4d | https://github.com/kaola-fed/megalo/blob/c5d971837c3467430469351084e0df9e4da34c4d/packages/weex-vue-framework/index.js#L162-L199 |
8,234 | kaola-fed/megalo | packages/vue-server-renderer/build.dev.js | applyModelTransform | function applyModelTransform (el, state) {
if (el.directives) {
for (var i = 0; i < el.directives.length; i++) {
var dir = el.directives[i];
if (dir.name === 'model') {
state.directives.model(el, dir, state.warn);
// remove value for textarea as its converted to text
if (el.tag === 'textarea' && el.props) {
el.props = el.props.filter(function (p) { return p.name !== 'value'; });
}
break
}
}
}
} | javascript | function applyModelTransform (el, state) {
if (el.directives) {
for (var i = 0; i < el.directives.length; i++) {
var dir = el.directives[i];
if (dir.name === 'model') {
state.directives.model(el, dir, state.warn);
// remove value for textarea as its converted to text
if (el.tag === 'textarea' && el.props) {
el.props = el.props.filter(function (p) { return p.name !== 'value'; });
}
break
}
}
}
} | [
"function",
"applyModelTransform",
"(",
"el",
",",
"state",
")",
"{",
"if",
"(",
"el",
".",
"directives",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"el",
".",
"directives",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"dir",
"=",
"el",
".",
"directives",
"[",
"i",
"]",
";",
"if",
"(",
"dir",
".",
"name",
"===",
"'model'",
")",
"{",
"state",
".",
"directives",
".",
"model",
"(",
"el",
",",
"dir",
",",
"state",
".",
"warn",
")",
";",
"// remove value for textarea as its converted to text",
"if",
"(",
"el",
".",
"tag",
"===",
"'textarea'",
"&&",
"el",
".",
"props",
")",
"{",
"el",
".",
"props",
"=",
"el",
".",
"props",
".",
"filter",
"(",
"function",
"(",
"p",
")",
"{",
"return",
"p",
".",
"name",
"!==",
"'value'",
";",
"}",
")",
";",
"}",
"break",
"}",
"}",
"}",
"}"
] | let the model AST transform translate v-model into appropriate props bindings | [
"let",
"the",
"model",
"AST",
"transform",
"translate",
"v",
"-",
"model",
"into",
"appropriate",
"props",
"bindings"
] | c5d971837c3467430469351084e0df9e4da34c4d | https://github.com/kaola-fed/megalo/blob/c5d971837c3467430469351084e0df9e4da34c4d/packages/vue-server-renderer/build.dev.js#L5489-L5503 |
8,235 | kaola-fed/megalo | dist/vue.esm.browser.js | isValidArrayIndex | function isValidArrayIndex (val) {
const n = parseFloat(String(val));
return n >= 0 && Math.floor(n) === n && isFinite(val)
} | javascript | function isValidArrayIndex (val) {
const n = parseFloat(String(val));
return n >= 0 && Math.floor(n) === n && isFinite(val)
} | [
"function",
"isValidArrayIndex",
"(",
"val",
")",
"{",
"const",
"n",
"=",
"parseFloat",
"(",
"String",
"(",
"val",
")",
")",
";",
"return",
"n",
">=",
"0",
"&&",
"Math",
".",
"floor",
"(",
"n",
")",
"===",
"n",
"&&",
"isFinite",
"(",
"val",
")",
"}"
] | Check if val is a valid array index. | [
"Check",
"if",
"val",
"is",
"a",
"valid",
"array",
"index",
"."
] | c5d971837c3467430469351084e0df9e4da34c4d | https://github.com/kaola-fed/megalo/blob/c5d971837c3467430469351084e0df9e4da34c4d/dist/vue.esm.browser.js#L74-L77 |
8,236 | kaola-fed/megalo | dist/vue.esm.browser.js | makeMap | function makeMap (
str,
expectsLowerCase
) {
const map = Object.create(null);
const list = str.split(',');
for (let i = 0; i < list.length; i++) {
map[list[i]] = true;
}
return expectsLowerCase
? val => map[val.toLowerCase()]
: val => map[val]
} | javascript | function makeMap (
str,
expectsLowerCase
) {
const map = Object.create(null);
const list = str.split(',');
for (let i = 0; i < list.length; i++) {
map[list[i]] = true;
}
return expectsLowerCase
? val => map[val.toLowerCase()]
: val => map[val]
} | [
"function",
"makeMap",
"(",
"str",
",",
"expectsLowerCase",
")",
"{",
"const",
"map",
"=",
"Object",
".",
"create",
"(",
"null",
")",
";",
"const",
"list",
"=",
"str",
".",
"split",
"(",
"','",
")",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"list",
".",
"length",
";",
"i",
"++",
")",
"{",
"map",
"[",
"list",
"[",
"i",
"]",
"]",
"=",
"true",
";",
"}",
"return",
"expectsLowerCase",
"?",
"val",
"=>",
"map",
"[",
"val",
".",
"toLowerCase",
"(",
")",
"]",
":",
"val",
"=>",
"map",
"[",
"val",
"]",
"}"
] | Make a map and return a function for checking if a key
is in that map. | [
"Make",
"a",
"map",
"and",
"return",
"a",
"function",
"for",
"checking",
"if",
"a",
"key",
"is",
"in",
"that",
"map",
"."
] | c5d971837c3467430469351084e0df9e4da34c4d | https://github.com/kaola-fed/megalo/blob/c5d971837c3467430469351084e0df9e4da34c4d/dist/vue.esm.browser.js#L111-L123 |
8,237 | kaola-fed/megalo | dist/vue.esm.browser.js | toArray | function toArray (list, start) {
start = start || 0;
let i = list.length - start;
const ret = new Array(i);
while (i--) {
ret[i] = list[i + start];
}
return ret
} | javascript | function toArray (list, start) {
start = start || 0;
let i = list.length - start;
const ret = new Array(i);
while (i--) {
ret[i] = list[i + start];
}
return ret
} | [
"function",
"toArray",
"(",
"list",
",",
"start",
")",
"{",
"start",
"=",
"start",
"||",
"0",
";",
"let",
"i",
"=",
"list",
".",
"length",
"-",
"start",
";",
"const",
"ret",
"=",
"new",
"Array",
"(",
"i",
")",
";",
"while",
"(",
"i",
"--",
")",
"{",
"ret",
"[",
"i",
"]",
"=",
"list",
"[",
"i",
"+",
"start",
"]",
";",
"}",
"return",
"ret",
"}"
] | Convert an Array-like object to a real Array. | [
"Convert",
"an",
"Array",
"-",
"like",
"object",
"to",
"a",
"real",
"Array",
"."
] | c5d971837c3467430469351084e0df9e4da34c4d | https://github.com/kaola-fed/megalo/blob/c5d971837c3467430469351084e0df9e4da34c4d/dist/vue.esm.browser.js#L223-L231 |
8,238 | kaola-fed/megalo | dist/vue.esm.browser.js | cloneVNode | function cloneVNode (vnode) {
const cloned = new VNode(
vnode.tag,
vnode.data,
// #7975
// clone children array to avoid mutating original in case of cloning
// a child.
vnode.children && vnode.children.slice(),
vnode.text,
vnode.elm,
vnode.context,
vnode.componentOptions,
vnode.asyncFactory
);
cloned.ns = vnode.ns;
cloned.isStatic = vnode.isStatic;
cloned.key = vnode.key;
cloned.isComment = vnode.isComment;
cloned.fnContext = vnode.fnContext;
cloned.fnOptions = vnode.fnOptions;
cloned.fnScopeId = vnode.fnScopeId;
cloned.asyncMeta = vnode.asyncMeta;
cloned.isCloned = true;
return cloned
} | javascript | function cloneVNode (vnode) {
const cloned = new VNode(
vnode.tag,
vnode.data,
// #7975
// clone children array to avoid mutating original in case of cloning
// a child.
vnode.children && vnode.children.slice(),
vnode.text,
vnode.elm,
vnode.context,
vnode.componentOptions,
vnode.asyncFactory
);
cloned.ns = vnode.ns;
cloned.isStatic = vnode.isStatic;
cloned.key = vnode.key;
cloned.isComment = vnode.isComment;
cloned.fnContext = vnode.fnContext;
cloned.fnOptions = vnode.fnOptions;
cloned.fnScopeId = vnode.fnScopeId;
cloned.asyncMeta = vnode.asyncMeta;
cloned.isCloned = true;
return cloned
} | [
"function",
"cloneVNode",
"(",
"vnode",
")",
"{",
"const",
"cloned",
"=",
"new",
"VNode",
"(",
"vnode",
".",
"tag",
",",
"vnode",
".",
"data",
",",
"// #7975",
"// clone children array to avoid mutating original in case of cloning",
"// a child.",
"vnode",
".",
"children",
"&&",
"vnode",
".",
"children",
".",
"slice",
"(",
")",
",",
"vnode",
".",
"text",
",",
"vnode",
".",
"elm",
",",
"vnode",
".",
"context",
",",
"vnode",
".",
"componentOptions",
",",
"vnode",
".",
"asyncFactory",
")",
";",
"cloned",
".",
"ns",
"=",
"vnode",
".",
"ns",
";",
"cloned",
".",
"isStatic",
"=",
"vnode",
".",
"isStatic",
";",
"cloned",
".",
"key",
"=",
"vnode",
".",
"key",
";",
"cloned",
".",
"isComment",
"=",
"vnode",
".",
"isComment",
";",
"cloned",
".",
"fnContext",
"=",
"vnode",
".",
"fnContext",
";",
"cloned",
".",
"fnOptions",
"=",
"vnode",
".",
"fnOptions",
";",
"cloned",
".",
"fnScopeId",
"=",
"vnode",
".",
"fnScopeId",
";",
"cloned",
".",
"asyncMeta",
"=",
"vnode",
".",
"asyncMeta",
";",
"cloned",
".",
"isCloned",
"=",
"true",
";",
"return",
"cloned",
"}"
] | optimized shallow clone used for static nodes and slot nodes because they may be reused across multiple renders, cloning them avoids errors when DOM manipulations rely on their elm reference. | [
"optimized",
"shallow",
"clone",
"used",
"for",
"static",
"nodes",
"and",
"slot",
"nodes",
"because",
"they",
"may",
"be",
"reused",
"across",
"multiple",
"renders",
"cloning",
"them",
"avoids",
"errors",
"when",
"DOM",
"manipulations",
"rely",
"on",
"their",
"elm",
"reference",
"."
] | c5d971837c3467430469351084e0df9e4da34c4d | https://github.com/kaola-fed/megalo/blob/c5d971837c3467430469351084e0df9e4da34c4d/dist/vue.esm.browser.js#L856-L880 |
8,239 | kaola-fed/megalo | dist/vue.esm.browser.js | normalizeProps | function normalizeProps (options, vm) {
const props = options.props;
if (!props) return
const res = {};
let i, val, name;
if (Array.isArray(props)) {
i = props.length;
while (i--) {
val = props[i];
if (typeof val === 'string') {
name = camelize(val);
res[name] = { type: null };
} else {
warn('props must be strings when using array syntax.');
}
}
} else if (isPlainObject(props)) {
for (const key in props) {
val = props[key];
name = camelize(key);
res[name] = isPlainObject(val)
? val
: { type: val };
}
} else {
warn(
`Invalid value for option "props": expected an Array or an Object, ` +
`but got ${toRawType(props)}.`,
vm
);
}
options.props = res;
} | javascript | function normalizeProps (options, vm) {
const props = options.props;
if (!props) return
const res = {};
let i, val, name;
if (Array.isArray(props)) {
i = props.length;
while (i--) {
val = props[i];
if (typeof val === 'string') {
name = camelize(val);
res[name] = { type: null };
} else {
warn('props must be strings when using array syntax.');
}
}
} else if (isPlainObject(props)) {
for (const key in props) {
val = props[key];
name = camelize(key);
res[name] = isPlainObject(val)
? val
: { type: val };
}
} else {
warn(
`Invalid value for option "props": expected an Array or an Object, ` +
`but got ${toRawType(props)}.`,
vm
);
}
options.props = res;
} | [
"function",
"normalizeProps",
"(",
"options",
",",
"vm",
")",
"{",
"const",
"props",
"=",
"options",
".",
"props",
";",
"if",
"(",
"!",
"props",
")",
"return",
"const",
"res",
"=",
"{",
"}",
";",
"let",
"i",
",",
"val",
",",
"name",
";",
"if",
"(",
"Array",
".",
"isArray",
"(",
"props",
")",
")",
"{",
"i",
"=",
"props",
".",
"length",
";",
"while",
"(",
"i",
"--",
")",
"{",
"val",
"=",
"props",
"[",
"i",
"]",
";",
"if",
"(",
"typeof",
"val",
"===",
"'string'",
")",
"{",
"name",
"=",
"camelize",
"(",
"val",
")",
";",
"res",
"[",
"name",
"]",
"=",
"{",
"type",
":",
"null",
"}",
";",
"}",
"else",
"{",
"warn",
"(",
"'props must be strings when using array syntax.'",
")",
";",
"}",
"}",
"}",
"else",
"if",
"(",
"isPlainObject",
"(",
"props",
")",
")",
"{",
"for",
"(",
"const",
"key",
"in",
"props",
")",
"{",
"val",
"=",
"props",
"[",
"key",
"]",
";",
"name",
"=",
"camelize",
"(",
"key",
")",
";",
"res",
"[",
"name",
"]",
"=",
"isPlainObject",
"(",
"val",
")",
"?",
"val",
":",
"{",
"type",
":",
"val",
"}",
";",
"}",
"}",
"else",
"{",
"warn",
"(",
"`",
"`",
"+",
"`",
"${",
"toRawType",
"(",
"props",
")",
"}",
"`",
",",
"vm",
")",
";",
"}",
"options",
".",
"props",
"=",
"res",
";",
"}"
] | Ensure all props option syntax are normalized into the
Object-based format. | [
"Ensure",
"all",
"props",
"option",
"syntax",
"are",
"normalized",
"into",
"the",
"Object",
"-",
"based",
"format",
"."
] | c5d971837c3467430469351084e0df9e4da34c4d | https://github.com/kaola-fed/megalo/blob/c5d971837c3467430469351084e0df9e4da34c4d/dist/vue.esm.browser.js#L1461-L1493 |
8,240 | kaola-fed/megalo | dist/vue.esm.browser.js | assertProp | function assertProp (
prop,
name,
value,
vm,
absent
) {
if (prop.required && absent) {
warn(
'Missing required prop: "' + name + '"',
vm
);
return
}
if (value == null && !prop.required) {
return
}
let type = prop.type;
let valid = !type || type === true;
const expectedTypes = [];
if (type) {
if (!Array.isArray(type)) {
type = [type];
}
for (let i = 0; i < type.length && !valid; i++) {
const assertedType = assertType(value, type[i]);
expectedTypes.push(assertedType.expectedType || '');
valid = assertedType.valid;
}
}
if (!valid) {
warn(
getInvalidTypeMessage(name, value, expectedTypes),
vm
);
return
}
const validator = prop.validator;
if (validator) {
if (!validator(value)) {
warn(
'Invalid prop: custom validator check failed for prop "' + name + '".',
vm
);
}
}
} | javascript | function assertProp (
prop,
name,
value,
vm,
absent
) {
if (prop.required && absent) {
warn(
'Missing required prop: "' + name + '"',
vm
);
return
}
if (value == null && !prop.required) {
return
}
let type = prop.type;
let valid = !type || type === true;
const expectedTypes = [];
if (type) {
if (!Array.isArray(type)) {
type = [type];
}
for (let i = 0; i < type.length && !valid; i++) {
const assertedType = assertType(value, type[i]);
expectedTypes.push(assertedType.expectedType || '');
valid = assertedType.valid;
}
}
if (!valid) {
warn(
getInvalidTypeMessage(name, value, expectedTypes),
vm
);
return
}
const validator = prop.validator;
if (validator) {
if (!validator(value)) {
warn(
'Invalid prop: custom validator check failed for prop "' + name + '".',
vm
);
}
}
} | [
"function",
"assertProp",
"(",
"prop",
",",
"name",
",",
"value",
",",
"vm",
",",
"absent",
")",
"{",
"if",
"(",
"prop",
".",
"required",
"&&",
"absent",
")",
"{",
"warn",
"(",
"'Missing required prop: \"'",
"+",
"name",
"+",
"'\"'",
",",
"vm",
")",
";",
"return",
"}",
"if",
"(",
"value",
"==",
"null",
"&&",
"!",
"prop",
".",
"required",
")",
"{",
"return",
"}",
"let",
"type",
"=",
"prop",
".",
"type",
";",
"let",
"valid",
"=",
"!",
"type",
"||",
"type",
"===",
"true",
";",
"const",
"expectedTypes",
"=",
"[",
"]",
";",
"if",
"(",
"type",
")",
"{",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"type",
")",
")",
"{",
"type",
"=",
"[",
"type",
"]",
";",
"}",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"type",
".",
"length",
"&&",
"!",
"valid",
";",
"i",
"++",
")",
"{",
"const",
"assertedType",
"=",
"assertType",
"(",
"value",
",",
"type",
"[",
"i",
"]",
")",
";",
"expectedTypes",
".",
"push",
"(",
"assertedType",
".",
"expectedType",
"||",
"''",
")",
";",
"valid",
"=",
"assertedType",
".",
"valid",
";",
"}",
"}",
"if",
"(",
"!",
"valid",
")",
"{",
"warn",
"(",
"getInvalidTypeMessage",
"(",
"name",
",",
"value",
",",
"expectedTypes",
")",
",",
"vm",
")",
";",
"return",
"}",
"const",
"validator",
"=",
"prop",
".",
"validator",
";",
"if",
"(",
"validator",
")",
"{",
"if",
"(",
"!",
"validator",
"(",
"value",
")",
")",
"{",
"warn",
"(",
"'Invalid prop: custom validator check failed for prop \"'",
"+",
"name",
"+",
"'\".'",
",",
"vm",
")",
";",
"}",
"}",
"}"
] | Assert whether a prop is valid. | [
"Assert",
"whether",
"a",
"prop",
"is",
"valid",
"."
] | c5d971837c3467430469351084e0df9e4da34c4d | https://github.com/kaola-fed/megalo/blob/c5d971837c3467430469351084e0df9e4da34c4d/dist/vue.esm.browser.js#L1712-L1759 |
8,241 | kaola-fed/megalo | dist/vue.esm.browser.js | checkKeyCodes | function checkKeyCodes (
eventKeyCode,
key,
builtInKeyCode,
eventKeyName,
builtInKeyName
) {
const mappedKeyCode = config.keyCodes[key] || builtInKeyCode;
if (builtInKeyName && eventKeyName && !config.keyCodes[key]) {
return isKeyNotMatch(builtInKeyName, eventKeyName)
} else if (mappedKeyCode) {
return isKeyNotMatch(mappedKeyCode, eventKeyCode)
} else if (eventKeyName) {
return hyphenate(eventKeyName) !== key
}
} | javascript | function checkKeyCodes (
eventKeyCode,
key,
builtInKeyCode,
eventKeyName,
builtInKeyName
) {
const mappedKeyCode = config.keyCodes[key] || builtInKeyCode;
if (builtInKeyName && eventKeyName && !config.keyCodes[key]) {
return isKeyNotMatch(builtInKeyName, eventKeyName)
} else if (mappedKeyCode) {
return isKeyNotMatch(mappedKeyCode, eventKeyCode)
} else if (eventKeyName) {
return hyphenate(eventKeyName) !== key
}
} | [
"function",
"checkKeyCodes",
"(",
"eventKeyCode",
",",
"key",
",",
"builtInKeyCode",
",",
"eventKeyName",
",",
"builtInKeyName",
")",
"{",
"const",
"mappedKeyCode",
"=",
"config",
".",
"keyCodes",
"[",
"key",
"]",
"||",
"builtInKeyCode",
";",
"if",
"(",
"builtInKeyName",
"&&",
"eventKeyName",
"&&",
"!",
"config",
".",
"keyCodes",
"[",
"key",
"]",
")",
"{",
"return",
"isKeyNotMatch",
"(",
"builtInKeyName",
",",
"eventKeyName",
")",
"}",
"else",
"if",
"(",
"mappedKeyCode",
")",
"{",
"return",
"isKeyNotMatch",
"(",
"mappedKeyCode",
",",
"eventKeyCode",
")",
"}",
"else",
"if",
"(",
"eventKeyName",
")",
"{",
"return",
"hyphenate",
"(",
"eventKeyName",
")",
"!==",
"key",
"}",
"}"
] | Runtime helper for checking keyCodes from config.
exposed as Vue.prototype._k
passing in eventKeyName as last argument separately for backwards compat | [
"Runtime",
"helper",
"for",
"checking",
"keyCodes",
"from",
"config",
".",
"exposed",
"as",
"Vue",
".",
"prototype",
".",
"_k",
"passing",
"in",
"eventKeyName",
"as",
"last",
"argument",
"separately",
"for",
"backwards",
"compat"
] | c5d971837c3467430469351084e0df9e4da34c4d | https://github.com/kaola-fed/megalo/blob/c5d971837c3467430469351084e0df9e4da34c4d/dist/vue.esm.browser.js#L2735-L2750 |
8,242 | kaola-fed/megalo | dist/vue.esm.browser.js | markOnce | function markOnce (
tree,
index,
key
) {
markStatic(tree, `__once__${index}${key ? `_${key}` : ``}`, true);
return tree
} | javascript | function markOnce (
tree,
index,
key
) {
markStatic(tree, `__once__${index}${key ? `_${key}` : ``}`, true);
return tree
} | [
"function",
"markOnce",
"(",
"tree",
",",
"index",
",",
"key",
")",
"{",
"markStatic",
"(",
"tree",
",",
"`",
"${",
"index",
"}",
"${",
"key",
"?",
"`",
"${",
"key",
"}",
"`",
":",
"`",
"`",
"}",
"`",
",",
"true",
")",
";",
"return",
"tree",
"}"
] | Runtime helper for v-once.
Effectively it means marking the node as static with a unique key. | [
"Runtime",
"helper",
"for",
"v",
"-",
"once",
".",
"Effectively",
"it",
"means",
"marking",
"the",
"node",
"as",
"static",
"with",
"a",
"unique",
"key",
"."
] | c5d971837c3467430469351084e0df9e4da34c4d | https://github.com/kaola-fed/megalo/blob/c5d971837c3467430469351084e0df9e4da34c4d/dist/vue.esm.browser.js#L2835-L2842 |
8,243 | kaola-fed/megalo | dist/vue.esm.browser.js | getOuterHTML | function getOuterHTML (el) {
if (el.outerHTML) {
return el.outerHTML
} else {
const container = document.createElement('div');
container.appendChild(el.cloneNode(true));
return container.innerHTML
}
} | javascript | function getOuterHTML (el) {
if (el.outerHTML) {
return el.outerHTML
} else {
const container = document.createElement('div');
container.appendChild(el.cloneNode(true));
return container.innerHTML
}
} | [
"function",
"getOuterHTML",
"(",
"el",
")",
"{",
"if",
"(",
"el",
".",
"outerHTML",
")",
"{",
"return",
"el",
".",
"outerHTML",
"}",
"else",
"{",
"const",
"container",
"=",
"document",
".",
"createElement",
"(",
"'div'",
")",
";",
"container",
".",
"appendChild",
"(",
"el",
".",
"cloneNode",
"(",
"true",
")",
")",
";",
"return",
"container",
".",
"innerHTML",
"}",
"}"
] | Get outerHTML of elements, taking care
of SVG elements in IE as well. | [
"Get",
"outerHTML",
"of",
"elements",
"taking",
"care",
"of",
"SVG",
"elements",
"in",
"IE",
"as",
"well",
"."
] | c5d971837c3467430469351084e0df9e4da34c4d | https://github.com/kaola-fed/megalo/blob/c5d971837c3467430469351084e0df9e4da34c4d/dist/vue.esm.browser.js#L11892-L11900 |
8,244 | kaola-fed/megalo | packages/megalo-template-compiler/build.js | mpify | function mpify (node, options) {
var target = options.target; if ( target === void 0 ) target = 'wechat';
var imports = options.imports; if ( imports === void 0 ) imports = {};
var transformAssetUrls = options.transformAssetUrls; if ( transformAssetUrls === void 0 ) transformAssetUrls = {};
var scopeId = options.scopeId; if ( scopeId === void 0 ) scopeId = '';
sep = "'" + (LIST_TAIL_SEPS[target]) + "'";
var preset = presets[target];
var state = new State({
rootNode: node,
target: target,
preset: preset,
imports: imports,
transformAssetUrls: transformAssetUrls,
scopeId: scopeId
});
if (scopeId) {
addAttr$1(node, 'sc_', ("\"" + scopeId + "\""));
}
walk(node, state);
} | javascript | function mpify (node, options) {
var target = options.target; if ( target === void 0 ) target = 'wechat';
var imports = options.imports; if ( imports === void 0 ) imports = {};
var transformAssetUrls = options.transformAssetUrls; if ( transformAssetUrls === void 0 ) transformAssetUrls = {};
var scopeId = options.scopeId; if ( scopeId === void 0 ) scopeId = '';
sep = "'" + (LIST_TAIL_SEPS[target]) + "'";
var preset = presets[target];
var state = new State({
rootNode: node,
target: target,
preset: preset,
imports: imports,
transformAssetUrls: transformAssetUrls,
scopeId: scopeId
});
if (scopeId) {
addAttr$1(node, 'sc_', ("\"" + scopeId + "\""));
}
walk(node, state);
} | [
"function",
"mpify",
"(",
"node",
",",
"options",
")",
"{",
"var",
"target",
"=",
"options",
".",
"target",
";",
"if",
"(",
"target",
"===",
"void",
"0",
")",
"target",
"=",
"'wechat'",
";",
"var",
"imports",
"=",
"options",
".",
"imports",
";",
"if",
"(",
"imports",
"===",
"void",
"0",
")",
"imports",
"=",
"{",
"}",
";",
"var",
"transformAssetUrls",
"=",
"options",
".",
"transformAssetUrls",
";",
"if",
"(",
"transformAssetUrls",
"===",
"void",
"0",
")",
"transformAssetUrls",
"=",
"{",
"}",
";",
"var",
"scopeId",
"=",
"options",
".",
"scopeId",
";",
"if",
"(",
"scopeId",
"===",
"void",
"0",
")",
"scopeId",
"=",
"''",
";",
"sep",
"=",
"\"'\"",
"+",
"(",
"LIST_TAIL_SEPS",
"[",
"target",
"]",
")",
"+",
"\"'\"",
";",
"var",
"preset",
"=",
"presets",
"[",
"target",
"]",
";",
"var",
"state",
"=",
"new",
"State",
"(",
"{",
"rootNode",
":",
"node",
",",
"target",
":",
"target",
",",
"preset",
":",
"preset",
",",
"imports",
":",
"imports",
",",
"transformAssetUrls",
":",
"transformAssetUrls",
",",
"scopeId",
":",
"scopeId",
"}",
")",
";",
"if",
"(",
"scopeId",
")",
"{",
"addAttr$1",
"(",
"node",
",",
"'sc_'",
",",
"(",
"\"\\\"\"",
"+",
"scopeId",
"+",
"\"\\\"\"",
")",
")",
";",
"}",
"walk",
"(",
"node",
",",
"state",
")",
";",
"}"
] | walk and modify ast before render function is generated | [
"walk",
"and",
"modify",
"ast",
"before",
"render",
"function",
"is",
"generated"
] | c5d971837c3467430469351084e0df9e4da34c4d | https://github.com/kaola-fed/megalo/blob/c5d971837c3467430469351084e0df9e4da34c4d/packages/megalo-template-compiler/build.js#L5227-L5246 |
8,245 | apache/cordova-plugin-statusbar | src/windows/StatusBarProxy.js | isSupported | function isSupported() {
// if not checked before, run check
if (_supported === null) {
var viewMan = Windows.UI.ViewManagement;
_supported = (viewMan.StatusBar && viewMan.StatusBar.getForCurrentView);
}
return _supported;
} | javascript | function isSupported() {
// if not checked before, run check
if (_supported === null) {
var viewMan = Windows.UI.ViewManagement;
_supported = (viewMan.StatusBar && viewMan.StatusBar.getForCurrentView);
}
return _supported;
} | [
"function",
"isSupported",
"(",
")",
"{",
"// if not checked before, run check",
"if",
"(",
"_supported",
"===",
"null",
")",
"{",
"var",
"viewMan",
"=",
"Windows",
".",
"UI",
".",
"ViewManagement",
";",
"_supported",
"=",
"(",
"viewMan",
".",
"StatusBar",
"&&",
"viewMan",
".",
"StatusBar",
".",
"getForCurrentView",
")",
";",
"}",
"return",
"_supported",
";",
"}"
] | set to null so we can check first time | [
"set",
"to",
"null",
"so",
"we",
"can",
"check",
"first",
"time"
] | 003fa610307f0d2b68aed2cebdc04a939d77912f | https://github.com/apache/cordova-plugin-statusbar/blob/003fa610307f0d2b68aed2cebdc04a939d77912f/src/windows/StatusBarProxy.js#L25-L32 |
8,246 | aholstenson/miio | lib/devices/gateway.js | generateKey | function generateKey() {
let result = '';
for(let i=0; i<16; i++) {
let idx = Math.floor(Math.random() * CHARS.length);
result += CHARS[idx];
}
return result;
} | javascript | function generateKey() {
let result = '';
for(let i=0; i<16; i++) {
let idx = Math.floor(Math.random() * CHARS.length);
result += CHARS[idx];
}
return result;
} | [
"function",
"generateKey",
"(",
")",
"{",
"let",
"result",
"=",
"''",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"16",
";",
"i",
"++",
")",
"{",
"let",
"idx",
"=",
"Math",
".",
"floor",
"(",
"Math",
".",
"random",
"(",
")",
"*",
"CHARS",
".",
"length",
")",
";",
"result",
"+=",
"CHARS",
"[",
"idx",
"]",
";",
"}",
"return",
"result",
";",
"}"
] | Generate a key for use with the local developer API. This does not generate
a secure key, but the Mi Home app does not seem to do that either. | [
"Generate",
"a",
"key",
"for",
"use",
"with",
"the",
"local",
"developer",
"API",
".",
"This",
"does",
"not",
"generate",
"a",
"secure",
"key",
"but",
"the",
"Mi",
"Home",
"app",
"does",
"not",
"seem",
"to",
"do",
"that",
"either",
"."
] | dbd66fd9c6ebe7a206eb202624c268a1d77424d0 | https://github.com/aholstenson/miio/blob/dbd66fd9c6ebe7a206eb202624c268a1d77424d0/lib/devices/gateway.js#L20-L27 |
8,247 | aholstenson/miio | lib/devices/capabilities/sensor.js | mixin | function mixin(device, options) {
if(device.capabilities.indexOf('sensor') < 0) {
device.capabilities.push('sensor');
}
device.capabilities.push(options.name);
Object.defineProperty(device, options.name, {
get: function() {
return this.property(options.name);
}
});
} | javascript | function mixin(device, options) {
if(device.capabilities.indexOf('sensor') < 0) {
device.capabilities.push('sensor');
}
device.capabilities.push(options.name);
Object.defineProperty(device, options.name, {
get: function() {
return this.property(options.name);
}
});
} | [
"function",
"mixin",
"(",
"device",
",",
"options",
")",
"{",
"if",
"(",
"device",
".",
"capabilities",
".",
"indexOf",
"(",
"'sensor'",
")",
"<",
"0",
")",
"{",
"device",
".",
"capabilities",
".",
"push",
"(",
"'sensor'",
")",
";",
"}",
"device",
".",
"capabilities",
".",
"push",
"(",
"options",
".",
"name",
")",
";",
"Object",
".",
"defineProperty",
"(",
"device",
",",
"options",
".",
"name",
",",
"{",
"get",
":",
"function",
"(",
")",
"{",
"return",
"this",
".",
"property",
"(",
"options",
".",
"name",
")",
";",
"}",
"}",
")",
";",
"}"
] | Setup sensor support for a device. | [
"Setup",
"sensor",
"support",
"for",
"a",
"device",
"."
] | dbd66fd9c6ebe7a206eb202624c268a1d77424d0 | https://github.com/aholstenson/miio/blob/dbd66fd9c6ebe7a206eb202624c268a1d77424d0/lib/devices/capabilities/sensor.js#L37-L48 |
8,248 | bpmn-io/diagram-js | lib/features/grid-snapping/GridSnapping.js | getSnapOffset | function getSnapOffset(event, axis) {
var context = event.context,
shape = event.shape,
gridSnappingContext = context.gridSnappingContext || {},
snapLocation = gridSnappingContext.snapLocation;
if (!shape || !snapLocation) {
return 0;
}
if (axis === 'x') {
if (/left/.test(snapLocation)) {
return -shape.width / 2;
}
if (/right/.test(snapLocation)) {
return shape.width / 2;
}
} else {
if (/top/.test(snapLocation)) {
return -shape.height / 2;
}
if (/bottom/.test(snapLocation)) {
return shape.height / 2;
}
}
return 0;
} | javascript | function getSnapOffset(event, axis) {
var context = event.context,
shape = event.shape,
gridSnappingContext = context.gridSnappingContext || {},
snapLocation = gridSnappingContext.snapLocation;
if (!shape || !snapLocation) {
return 0;
}
if (axis === 'x') {
if (/left/.test(snapLocation)) {
return -shape.width / 2;
}
if (/right/.test(snapLocation)) {
return shape.width / 2;
}
} else {
if (/top/.test(snapLocation)) {
return -shape.height / 2;
}
if (/bottom/.test(snapLocation)) {
return shape.height / 2;
}
}
return 0;
} | [
"function",
"getSnapOffset",
"(",
"event",
",",
"axis",
")",
"{",
"var",
"context",
"=",
"event",
".",
"context",
",",
"shape",
"=",
"event",
".",
"shape",
",",
"gridSnappingContext",
"=",
"context",
".",
"gridSnappingContext",
"||",
"{",
"}",
",",
"snapLocation",
"=",
"gridSnappingContext",
".",
"snapLocation",
";",
"if",
"(",
"!",
"shape",
"||",
"!",
"snapLocation",
")",
"{",
"return",
"0",
";",
"}",
"if",
"(",
"axis",
"===",
"'x'",
")",
"{",
"if",
"(",
"/",
"left",
"/",
".",
"test",
"(",
"snapLocation",
")",
")",
"{",
"return",
"-",
"shape",
".",
"width",
"/",
"2",
";",
"}",
"if",
"(",
"/",
"right",
"/",
".",
"test",
"(",
"snapLocation",
")",
")",
"{",
"return",
"shape",
".",
"width",
"/",
"2",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"/",
"top",
"/",
".",
"test",
"(",
"snapLocation",
")",
")",
"{",
"return",
"-",
"shape",
".",
"height",
"/",
"2",
";",
"}",
"if",
"(",
"/",
"bottom",
"/",
".",
"test",
"(",
"snapLocation",
")",
")",
"{",
"return",
"shape",
".",
"height",
"/",
"2",
";",
"}",
"}",
"return",
"0",
";",
"}"
] | Get snap offset assuming that event is at center of shape.
@param {Object} event
@param {string} axis
@returns {number} | [
"Get",
"snap",
"offset",
"assuming",
"that",
"event",
"is",
"at",
"center",
"of",
"shape",
"."
] | fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde | https://github.com/bpmn-io/diagram-js/blob/fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde/lib/features/grid-snapping/GridSnapping.js#L253-L282 |
8,249 | bpmn-io/diagram-js | lib/features/attach-support/AttachSupport.js | removeAttached | function removeAttached(elements) {
var ids = groupBy(elements, 'id');
return filter(elements, function(element) {
while (element) {
// host in selection
if (element.host && ids[element.host.id]) {
return false;
}
element = element.parent;
}
return true;
});
} | javascript | function removeAttached(elements) {
var ids = groupBy(elements, 'id');
return filter(elements, function(element) {
while (element) {
// host in selection
if (element.host && ids[element.host.id]) {
return false;
}
element = element.parent;
}
return true;
});
} | [
"function",
"removeAttached",
"(",
"elements",
")",
"{",
"var",
"ids",
"=",
"groupBy",
"(",
"elements",
",",
"'id'",
")",
";",
"return",
"filter",
"(",
"elements",
",",
"function",
"(",
"element",
")",
"{",
"while",
"(",
"element",
")",
"{",
"// host in selection",
"if",
"(",
"element",
".",
"host",
"&&",
"ids",
"[",
"element",
".",
"host",
".",
"id",
"]",
")",
"{",
"return",
"false",
";",
"}",
"element",
"=",
"element",
".",
"parent",
";",
"}",
"return",
"true",
";",
"}",
")",
";",
"}"
] | Return a filtered list of elements that do not
contain attached elements with hosts being part
of the selection.
@param {Array<djs.model.Base>} elements
@return {Array<djs.model.Base>} filtered | [
"Return",
"a",
"filtered",
"list",
"of",
"elements",
"that",
"do",
"not",
"contain",
"attached",
"elements",
"with",
"hosts",
"being",
"part",
"of",
"the",
"selection",
"."
] | fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde | https://github.com/bpmn-io/diagram-js/blob/fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde/lib/features/attach-support/AttachSupport.js#L309-L326 |
8,250 | bpmn-io/diagram-js | lib/features/move/Move.js | start | function start(event, element, activate, context) {
if (isObject(activate)) {
context = activate;
activate = false;
}
// do not move connections or the root element
if (element.waypoints || !element.parent) {
return;
}
var referencePoint = mid(element);
dragging.init(event, referencePoint, 'shape.move', {
cursor: 'grabbing',
autoActivate: activate,
data: {
shape: element,
context: context || {}
}
});
// we've handled the event
return true;
} | javascript | function start(event, element, activate, context) {
if (isObject(activate)) {
context = activate;
activate = false;
}
// do not move connections or the root element
if (element.waypoints || !element.parent) {
return;
}
var referencePoint = mid(element);
dragging.init(event, referencePoint, 'shape.move', {
cursor: 'grabbing',
autoActivate: activate,
data: {
shape: element,
context: context || {}
}
});
// we've handled the event
return true;
} | [
"function",
"start",
"(",
"event",
",",
"element",
",",
"activate",
",",
"context",
")",
"{",
"if",
"(",
"isObject",
"(",
"activate",
")",
")",
"{",
"context",
"=",
"activate",
";",
"activate",
"=",
"false",
";",
"}",
"// do not move connections or the root element",
"if",
"(",
"element",
".",
"waypoints",
"||",
"!",
"element",
".",
"parent",
")",
"{",
"return",
";",
"}",
"var",
"referencePoint",
"=",
"mid",
"(",
"element",
")",
";",
"dragging",
".",
"init",
"(",
"event",
",",
"referencePoint",
",",
"'shape.move'",
",",
"{",
"cursor",
":",
"'grabbing'",
",",
"autoActivate",
":",
"activate",
",",
"data",
":",
"{",
"shape",
":",
"element",
",",
"context",
":",
"context",
"||",
"{",
"}",
"}",
"}",
")",
";",
"// we've handled the event",
"return",
"true",
";",
"}"
] | Start move.
@param {MouseEvent} event
@param {djs.model.Shape} shape
@param {boolean} [activate]
@param {Object} [context] | [
"Start",
"move",
"."
] | fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde | https://github.com/bpmn-io/diagram-js/blob/fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde/lib/features/move/Move.js#L180-L204 |
8,251 | bpmn-io/diagram-js | lib/features/move/Move.js | removeNested | function removeNested(elements) {
var ids = groupBy(elements, 'id');
return filter(elements, function(element) {
while ((element = element.parent)) {
// parent in selection
if (ids[element.id]) {
return false;
}
}
return true;
});
} | javascript | function removeNested(elements) {
var ids = groupBy(elements, 'id');
return filter(elements, function(element) {
while ((element = element.parent)) {
// parent in selection
if (ids[element.id]) {
return false;
}
}
return true;
});
} | [
"function",
"removeNested",
"(",
"elements",
")",
"{",
"var",
"ids",
"=",
"groupBy",
"(",
"elements",
",",
"'id'",
")",
";",
"return",
"filter",
"(",
"elements",
",",
"function",
"(",
"element",
")",
"{",
"while",
"(",
"(",
"element",
"=",
"element",
".",
"parent",
")",
")",
"{",
"// parent in selection",
"if",
"(",
"ids",
"[",
"element",
".",
"id",
"]",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}",
")",
";",
"}"
] | Return a filtered list of elements that do not contain
those nested into others.
@param {Array<djs.model.Base>} elements
@return {Array<djs.model.Base>} filtered | [
"Return",
"a",
"filtered",
"list",
"of",
"elements",
"that",
"do",
"not",
"contain",
"those",
"nested",
"into",
"others",
"."
] | fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde | https://github.com/bpmn-io/diagram-js/blob/fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde/lib/features/move/Move.js#L228-L243 |
8,252 | bpmn-io/diagram-js | lib/features/move/MovePreview.js | setMarker | function setMarker(element, marker) {
[ MARKER_ATTACH, MARKER_OK, MARKER_NOT_OK, MARKER_NEW_PARENT ].forEach(function(m) {
if (m === marker) {
canvas.addMarker(element, m);
} else {
canvas.removeMarker(element, m);
}
});
} | javascript | function setMarker(element, marker) {
[ MARKER_ATTACH, MARKER_OK, MARKER_NOT_OK, MARKER_NEW_PARENT ].forEach(function(m) {
if (m === marker) {
canvas.addMarker(element, m);
} else {
canvas.removeMarker(element, m);
}
});
} | [
"function",
"setMarker",
"(",
"element",
",",
"marker",
")",
"{",
"[",
"MARKER_ATTACH",
",",
"MARKER_OK",
",",
"MARKER_NOT_OK",
",",
"MARKER_NEW_PARENT",
"]",
".",
"forEach",
"(",
"function",
"(",
"m",
")",
"{",
"if",
"(",
"m",
"===",
"marker",
")",
"{",
"canvas",
".",
"addMarker",
"(",
"element",
",",
"m",
")",
";",
"}",
"else",
"{",
"canvas",
".",
"removeMarker",
"(",
"element",
",",
"m",
")",
";",
"}",
"}",
")",
";",
"}"
] | Sets drop marker on an element. | [
"Sets",
"drop",
"marker",
"on",
"an",
"element",
"."
] | fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde | https://github.com/bpmn-io/diagram-js/blob/fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde/lib/features/move/MovePreview.js#L66-L76 |
8,253 | bpmn-io/diagram-js | lib/features/move/MovePreview.js | makeDraggable | function makeDraggable(context, element, addMarker) {
previewSupport.addDragger(element, context.dragGroup);
if (addMarker) {
canvas.addMarker(element, MARKER_DRAGGING);
}
if (context.allDraggedElements) {
context.allDraggedElements.push(element);
} else {
context.allDraggedElements = [ element ];
}
} | javascript | function makeDraggable(context, element, addMarker) {
previewSupport.addDragger(element, context.dragGroup);
if (addMarker) {
canvas.addMarker(element, MARKER_DRAGGING);
}
if (context.allDraggedElements) {
context.allDraggedElements.push(element);
} else {
context.allDraggedElements = [ element ];
}
} | [
"function",
"makeDraggable",
"(",
"context",
",",
"element",
",",
"addMarker",
")",
"{",
"previewSupport",
".",
"addDragger",
"(",
"element",
",",
"context",
".",
"dragGroup",
")",
";",
"if",
"(",
"addMarker",
")",
"{",
"canvas",
".",
"addMarker",
"(",
"element",
",",
"MARKER_DRAGGING",
")",
";",
"}",
"if",
"(",
"context",
".",
"allDraggedElements",
")",
"{",
"context",
".",
"allDraggedElements",
".",
"push",
"(",
"element",
")",
";",
"}",
"else",
"{",
"context",
".",
"allDraggedElements",
"=",
"[",
"element",
"]",
";",
"}",
"}"
] | Make an element draggable.
@param {Object} context
@param {djs.model.Base} element
@param {Boolean} addMarker | [
"Make",
"an",
"element",
"draggable",
"."
] | fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde | https://github.com/bpmn-io/diagram-js/blob/fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde/lib/features/move/MovePreview.js#L85-L98 |
8,254 | bpmn-io/diagram-js | lib/features/search-pad/SearchPad.js | constructOverlay | function constructOverlay(box) {
var offset = 6;
var w = box.width + offset * 2;
var h = box.height + offset * 2;
var styles = [
'width: '+ w +'px',
'height: '+ h + 'px'
].join('; ');
return {
position: {
bottom: h - offset,
right: w - offset
},
show: true,
html: '<div style="' + styles + '" class="' + SearchPad.OVERLAY_CLASS + '"></div>'
};
} | javascript | function constructOverlay(box) {
var offset = 6;
var w = box.width + offset * 2;
var h = box.height + offset * 2;
var styles = [
'width: '+ w +'px',
'height: '+ h + 'px'
].join('; ');
return {
position: {
bottom: h - offset,
right: w - offset
},
show: true,
html: '<div style="' + styles + '" class="' + SearchPad.OVERLAY_CLASS + '"></div>'
};
} | [
"function",
"constructOverlay",
"(",
"box",
")",
"{",
"var",
"offset",
"=",
"6",
";",
"var",
"w",
"=",
"box",
".",
"width",
"+",
"offset",
"*",
"2",
";",
"var",
"h",
"=",
"box",
".",
"height",
"+",
"offset",
"*",
"2",
";",
"var",
"styles",
"=",
"[",
"'width: '",
"+",
"w",
"+",
"'px'",
",",
"'height: '",
"+",
"h",
"+",
"'px'",
"]",
".",
"join",
"(",
"'; '",
")",
";",
"return",
"{",
"position",
":",
"{",
"bottom",
":",
"h",
"-",
"offset",
",",
"right",
":",
"w",
"-",
"offset",
"}",
",",
"show",
":",
"true",
",",
"html",
":",
"'<div style=\"'",
"+",
"styles",
"+",
"'\" class=\"'",
"+",
"SearchPad",
".",
"OVERLAY_CLASS",
"+",
"'\"></div>'",
"}",
";",
"}"
] | Construct overlay object for the given bounding box.
@param {BoundingBox} box
@return {Object} | [
"Construct",
"overlay",
"object",
"for",
"the",
"given",
"bounding",
"box",
"."
] | fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde | https://github.com/bpmn-io/diagram-js/blob/fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde/lib/features/search-pad/SearchPad.js#L462-L481 |
8,255 | bpmn-io/diagram-js | lib/features/search-pad/SearchPad.js | createInnerTextNode | function createInnerTextNode(parentNode, tokens, template) {
var text = createHtmlText(tokens);
var childNode = domify(template);
childNode.innerHTML = text;
parentNode.appendChild(childNode);
} | javascript | function createInnerTextNode(parentNode, tokens, template) {
var text = createHtmlText(tokens);
var childNode = domify(template);
childNode.innerHTML = text;
parentNode.appendChild(childNode);
} | [
"function",
"createInnerTextNode",
"(",
"parentNode",
",",
"tokens",
",",
"template",
")",
"{",
"var",
"text",
"=",
"createHtmlText",
"(",
"tokens",
")",
";",
"var",
"childNode",
"=",
"domify",
"(",
"template",
")",
";",
"childNode",
".",
"innerHTML",
"=",
"text",
";",
"parentNode",
".",
"appendChild",
"(",
"childNode",
")",
";",
"}"
] | Creates and appends child node from result tokens and HTML template.
@param {Element} node
@param {Array<Object>} tokens
@param {String} template | [
"Creates",
"and",
"appends",
"child",
"node",
"from",
"result",
"tokens",
"and",
"HTML",
"template",
"."
] | fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde | https://github.com/bpmn-io/diagram-js/blob/fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde/lib/features/search-pad/SearchPad.js#L491-L496 |
8,256 | bpmn-io/diagram-js | lib/features/search-pad/SearchPad.js | createHtmlText | function createHtmlText(tokens) {
var htmlText = '';
tokens.forEach(function(t) {
if (t.matched) {
htmlText += '<strong class="' + SearchPad.RESULT_HIGHLIGHT_CLASS + '">' + t.matched + '</strong>';
} else {
htmlText += t.normal;
}
});
return htmlText !== '' ? htmlText : null;
} | javascript | function createHtmlText(tokens) {
var htmlText = '';
tokens.forEach(function(t) {
if (t.matched) {
htmlText += '<strong class="' + SearchPad.RESULT_HIGHLIGHT_CLASS + '">' + t.matched + '</strong>';
} else {
htmlText += t.normal;
}
});
return htmlText !== '' ? htmlText : null;
} | [
"function",
"createHtmlText",
"(",
"tokens",
")",
"{",
"var",
"htmlText",
"=",
"''",
";",
"tokens",
".",
"forEach",
"(",
"function",
"(",
"t",
")",
"{",
"if",
"(",
"t",
".",
"matched",
")",
"{",
"htmlText",
"+=",
"'<strong class=\"'",
"+",
"SearchPad",
".",
"RESULT_HIGHLIGHT_CLASS",
"+",
"'\">'",
"+",
"t",
".",
"matched",
"+",
"'</strong>'",
";",
"}",
"else",
"{",
"htmlText",
"+=",
"t",
".",
"normal",
";",
"}",
"}",
")",
";",
"return",
"htmlText",
"!==",
"''",
"?",
"htmlText",
":",
"null",
";",
"}"
] | Create internal HTML markup from result tokens.
Caters for highlighting pattern matched tokens.
@param {Array<Object>} tokens
@return {String} | [
"Create",
"internal",
"HTML",
"markup",
"from",
"result",
"tokens",
".",
"Caters",
"for",
"highlighting",
"pattern",
"matched",
"tokens",
"."
] | fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde | https://github.com/bpmn-io/diagram-js/blob/fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde/lib/features/search-pad/SearchPad.js#L505-L517 |
8,257 | bpmn-io/diagram-js | lib/util/Text.js | layoutNext | function layoutNext(lines, maxWidth, fakeText) {
var originalLine = lines.shift(),
fitLine = originalLine;
var textBBox;
for (;;) {
textBBox = getTextBBox(fitLine, fakeText);
textBBox.width = fitLine ? textBBox.width : 0;
// try to fit
if (fitLine === ' ' || fitLine === '' || textBBox.width < Math.round(maxWidth) || fitLine.length < 2) {
return fit(lines, fitLine, originalLine, textBBox);
}
fitLine = shortenLine(fitLine, textBBox.width, maxWidth);
}
} | javascript | function layoutNext(lines, maxWidth, fakeText) {
var originalLine = lines.shift(),
fitLine = originalLine;
var textBBox;
for (;;) {
textBBox = getTextBBox(fitLine, fakeText);
textBBox.width = fitLine ? textBBox.width : 0;
// try to fit
if (fitLine === ' ' || fitLine === '' || textBBox.width < Math.round(maxWidth) || fitLine.length < 2) {
return fit(lines, fitLine, originalLine, textBBox);
}
fitLine = shortenLine(fitLine, textBBox.width, maxWidth);
}
} | [
"function",
"layoutNext",
"(",
"lines",
",",
"maxWidth",
",",
"fakeText",
")",
"{",
"var",
"originalLine",
"=",
"lines",
".",
"shift",
"(",
")",
",",
"fitLine",
"=",
"originalLine",
";",
"var",
"textBBox",
";",
"for",
"(",
";",
";",
")",
"{",
"textBBox",
"=",
"getTextBBox",
"(",
"fitLine",
",",
"fakeText",
")",
";",
"textBBox",
".",
"width",
"=",
"fitLine",
"?",
"textBBox",
".",
"width",
":",
"0",
";",
"// try to fit",
"if",
"(",
"fitLine",
"===",
"' '",
"||",
"fitLine",
"===",
"''",
"||",
"textBBox",
".",
"width",
"<",
"Math",
".",
"round",
"(",
"maxWidth",
")",
"||",
"fitLine",
".",
"length",
"<",
"2",
")",
"{",
"return",
"fit",
"(",
"lines",
",",
"fitLine",
",",
"originalLine",
",",
"textBBox",
")",
";",
"}",
"fitLine",
"=",
"shortenLine",
"(",
"fitLine",
",",
"textBBox",
".",
"width",
",",
"maxWidth",
")",
";",
"}",
"}"
] | Layout the next line and return the layouted element.
Alters the lines passed.
@param {Array<String>} lines
@return {Object} the line descriptor, an object { width, height, text } | [
"Layout",
"the",
"next",
"line",
"and",
"return",
"the",
"layouted",
"element",
"."
] | fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde | https://github.com/bpmn-io/diagram-js/blob/fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde/lib/util/Text.js#L90-L109 |
8,258 | bpmn-io/diagram-js | lib/util/Text.js | semanticShorten | function semanticShorten(line, maxLength) {
var parts = line.split(/(\s|-)/g),
part,
shortenedParts = [],
length = 0;
// try to shorten via spaces + hyphens
if (parts.length > 1) {
while ((part = parts.shift())) {
if (part.length + length < maxLength) {
shortenedParts.push(part);
length += part.length;
} else {
// remove previous part, too if hyphen does not fit anymore
if (part === '-') {
shortenedParts.pop();
}
break;
}
}
}
return shortenedParts.join('');
} | javascript | function semanticShorten(line, maxLength) {
var parts = line.split(/(\s|-)/g),
part,
shortenedParts = [],
length = 0;
// try to shorten via spaces + hyphens
if (parts.length > 1) {
while ((part = parts.shift())) {
if (part.length + length < maxLength) {
shortenedParts.push(part);
length += part.length;
} else {
// remove previous part, too if hyphen does not fit anymore
if (part === '-') {
shortenedParts.pop();
}
break;
}
}
}
return shortenedParts.join('');
} | [
"function",
"semanticShorten",
"(",
"line",
",",
"maxLength",
")",
"{",
"var",
"parts",
"=",
"line",
".",
"split",
"(",
"/",
"(\\s|-)",
"/",
"g",
")",
",",
"part",
",",
"shortenedParts",
"=",
"[",
"]",
",",
"length",
"=",
"0",
";",
"// try to shorten via spaces + hyphens",
"if",
"(",
"parts",
".",
"length",
">",
"1",
")",
"{",
"while",
"(",
"(",
"part",
"=",
"parts",
".",
"shift",
"(",
")",
")",
")",
"{",
"if",
"(",
"part",
".",
"length",
"+",
"length",
"<",
"maxLength",
")",
"{",
"shortenedParts",
".",
"push",
"(",
"part",
")",
";",
"length",
"+=",
"part",
".",
"length",
";",
"}",
"else",
"{",
"// remove previous part, too if hyphen does not fit anymore",
"if",
"(",
"part",
"===",
"'-'",
")",
"{",
"shortenedParts",
".",
"pop",
"(",
")",
";",
"}",
"break",
";",
"}",
"}",
"}",
"return",
"shortenedParts",
".",
"join",
"(",
"''",
")",
";",
"}"
] | Shortens a line based on spacing and hyphens.
Returns the shortened result on success.
@param {String} line
@param {Number} maxLength the maximum characters of the string
@return {String} the shortened string | [
"Shortens",
"a",
"line",
"based",
"on",
"spacing",
"and",
"hyphens",
".",
"Returns",
"the",
"shortened",
"result",
"on",
"success",
"."
] | fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde | https://github.com/bpmn-io/diagram-js/blob/fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde/lib/util/Text.js#L134-L158 |
8,259 | bpmn-io/diagram-js | lib/layout/ManhattanLayout.js | getSimpleBendpoints | function getSimpleBendpoints(a, b, directions) {
var xmid = round((b.x - a.x) / 2 + a.x),
ymid = round((b.y - a.y) / 2 + a.y);
// one point, right or left from a
if (directions === 'h:v') {
return [ { x: b.x, y: a.y } ];
}
// one point, above or below a
if (directions === 'v:h') {
return [ { x: a.x, y: b.y } ];
}
// vertical segment between a and b
if (directions === 'h:h') {
return [
{ x: xmid, y: a.y },
{ x: xmid, y: b.y }
];
}
// horizontal segment between a and b
if (directions === 'v:v') {
return [
{ x: a.x, y: ymid },
{ x: b.x, y: ymid }
];
}
throw new Error('invalid directions: can only handle varians of [hv]:[hv]');
} | javascript | function getSimpleBendpoints(a, b, directions) {
var xmid = round((b.x - a.x) / 2 + a.x),
ymid = round((b.y - a.y) / 2 + a.y);
// one point, right or left from a
if (directions === 'h:v') {
return [ { x: b.x, y: a.y } ];
}
// one point, above or below a
if (directions === 'v:h') {
return [ { x: a.x, y: b.y } ];
}
// vertical segment between a and b
if (directions === 'h:h') {
return [
{ x: xmid, y: a.y },
{ x: xmid, y: b.y }
];
}
// horizontal segment between a and b
if (directions === 'v:v') {
return [
{ x: a.x, y: ymid },
{ x: b.x, y: ymid }
];
}
throw new Error('invalid directions: can only handle varians of [hv]:[hv]');
} | [
"function",
"getSimpleBendpoints",
"(",
"a",
",",
"b",
",",
"directions",
")",
"{",
"var",
"xmid",
"=",
"round",
"(",
"(",
"b",
".",
"x",
"-",
"a",
".",
"x",
")",
"/",
"2",
"+",
"a",
".",
"x",
")",
",",
"ymid",
"=",
"round",
"(",
"(",
"b",
".",
"y",
"-",
"a",
".",
"y",
")",
"/",
"2",
"+",
"a",
".",
"y",
")",
";",
"// one point, right or left from a",
"if",
"(",
"directions",
"===",
"'h:v'",
")",
"{",
"return",
"[",
"{",
"x",
":",
"b",
".",
"x",
",",
"y",
":",
"a",
".",
"y",
"}",
"]",
";",
"}",
"// one point, above or below a",
"if",
"(",
"directions",
"===",
"'v:h'",
")",
"{",
"return",
"[",
"{",
"x",
":",
"a",
".",
"x",
",",
"y",
":",
"b",
".",
"y",
"}",
"]",
";",
"}",
"// vertical segment between a and b",
"if",
"(",
"directions",
"===",
"'h:h'",
")",
"{",
"return",
"[",
"{",
"x",
":",
"xmid",
",",
"y",
":",
"a",
".",
"y",
"}",
",",
"{",
"x",
":",
"xmid",
",",
"y",
":",
"b",
".",
"y",
"}",
"]",
";",
"}",
"// horizontal segment between a and b",
"if",
"(",
"directions",
"===",
"'v:v'",
")",
"{",
"return",
"[",
"{",
"x",
":",
"a",
".",
"x",
",",
"y",
":",
"ymid",
"}",
",",
"{",
"x",
":",
"b",
".",
"x",
",",
"y",
":",
"ymid",
"}",
"]",
";",
"}",
"throw",
"new",
"Error",
"(",
"'invalid directions: can only handle varians of [hv]:[hv]'",
")",
";",
"}"
] | Handle simple layouts with maximum two bendpoints. | [
"Handle",
"simple",
"layouts",
"with",
"maximum",
"two",
"bendpoints",
"."
] | fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde | https://github.com/bpmn-io/diagram-js/blob/fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde/lib/layout/ManhattanLayout.js#L161-L193 |
8,260 | bpmn-io/diagram-js | lib/layout/ManhattanLayout.js | getBendpoints | function getBendpoints(a, b, directions) {
directions = directions || 'h:h';
if (!isValidDirections(directions)) {
throw new Error(
'unknown directions: <' + directions + '>: ' +
'must be specified as <start>:<end> ' +
'with start/end in { h,v,t,r,b,l }'
);
}
// compute explicit directions, involving trbl dockings
// using a three segmented layouting algorithm
if (isExplicitDirections(directions)) {
var startSegment = getStartSegment(a, b, directions),
endSegment = getEndSegment(a, b, directions),
midSegment = getMidSegment(startSegment, endSegment);
return [].concat(
startSegment.waypoints,
midSegment.waypoints,
endSegment.waypoints
);
}
// handle simple [hv]:[hv] cases that can be easily computed
return getSimpleBendpoints(a, b, directions);
} | javascript | function getBendpoints(a, b, directions) {
directions = directions || 'h:h';
if (!isValidDirections(directions)) {
throw new Error(
'unknown directions: <' + directions + '>: ' +
'must be specified as <start>:<end> ' +
'with start/end in { h,v,t,r,b,l }'
);
}
// compute explicit directions, involving trbl dockings
// using a three segmented layouting algorithm
if (isExplicitDirections(directions)) {
var startSegment = getStartSegment(a, b, directions),
endSegment = getEndSegment(a, b, directions),
midSegment = getMidSegment(startSegment, endSegment);
return [].concat(
startSegment.waypoints,
midSegment.waypoints,
endSegment.waypoints
);
}
// handle simple [hv]:[hv] cases that can be easily computed
return getSimpleBendpoints(a, b, directions);
} | [
"function",
"getBendpoints",
"(",
"a",
",",
"b",
",",
"directions",
")",
"{",
"directions",
"=",
"directions",
"||",
"'h:h'",
";",
"if",
"(",
"!",
"isValidDirections",
"(",
"directions",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'unknown directions: <'",
"+",
"directions",
"+",
"'>: '",
"+",
"'must be specified as <start>:<end> '",
"+",
"'with start/end in { h,v,t,r,b,l }'",
")",
";",
"}",
"// compute explicit directions, involving trbl dockings",
"// using a three segmented layouting algorithm",
"if",
"(",
"isExplicitDirections",
"(",
"directions",
")",
")",
"{",
"var",
"startSegment",
"=",
"getStartSegment",
"(",
"a",
",",
"b",
",",
"directions",
")",
",",
"endSegment",
"=",
"getEndSegment",
"(",
"a",
",",
"b",
",",
"directions",
")",
",",
"midSegment",
"=",
"getMidSegment",
"(",
"startSegment",
",",
"endSegment",
")",
";",
"return",
"[",
"]",
".",
"concat",
"(",
"startSegment",
".",
"waypoints",
",",
"midSegment",
".",
"waypoints",
",",
"endSegment",
".",
"waypoints",
")",
";",
"}",
"// handle simple [hv]:[hv] cases that can be easily computed",
"return",
"getSimpleBendpoints",
"(",
"a",
",",
"b",
",",
"directions",
")",
";",
"}"
] | Returns the mid points for a manhattan connection between two points.
@example h:h (horizontal:horizontal)
[a]----[x]
|
[x]----[b]
@example h:v (horizontal:vertical)
[a]----[x]
|
[b]
@example h:r (horizontal:right)
[a]----[x]
|
[b]-[x]
@param {Point} a
@param {Point} b
@param {String} directions
@return {Array<Point>} | [
"Returns",
"the",
"mid",
"points",
"for",
"a",
"manhattan",
"connection",
"between",
"two",
"points",
"."
] | fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde | https://github.com/bpmn-io/diagram-js/blob/fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde/lib/layout/ManhattanLayout.js#L223-L250 |
8,261 | bpmn-io/diagram-js | lib/layout/ManhattanLayout.js | tryRepairConnectionStart | function tryRepairConnectionStart(moved, other, newDocking, points) {
return _tryRepairConnectionSide(moved, other, newDocking, points);
} | javascript | function tryRepairConnectionStart(moved, other, newDocking, points) {
return _tryRepairConnectionSide(moved, other, newDocking, points);
} | [
"function",
"tryRepairConnectionStart",
"(",
"moved",
",",
"other",
",",
"newDocking",
",",
"points",
")",
"{",
"return",
"_tryRepairConnectionSide",
"(",
"moved",
",",
"other",
",",
"newDocking",
",",
"points",
")",
";",
"}"
] | Repair a connection from start.
@param {Bounds} moved
@param {Bounds} other
@param {Point} newDocking
@param {Array<Point>} points originalPoints from moved to other
@return {Array<Point>|null} the repaired points between the two rectangles | [
"Repair",
"a",
"connection",
"from",
"start",
"."
] | fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde | https://github.com/bpmn-io/diagram-js/blob/fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde/lib/layout/ManhattanLayout.js#L488-L490 |
8,262 | bpmn-io/diagram-js | lib/layout/ManhattanLayout.js | tryRepairConnectionEnd | function tryRepairConnectionEnd(moved, other, newDocking, points) {
var waypoints = points.slice().reverse();
waypoints = _tryRepairConnectionSide(moved, other, newDocking, waypoints);
return waypoints ? waypoints.reverse() : null;
} | javascript | function tryRepairConnectionEnd(moved, other, newDocking, points) {
var waypoints = points.slice().reverse();
waypoints = _tryRepairConnectionSide(moved, other, newDocking, waypoints);
return waypoints ? waypoints.reverse() : null;
} | [
"function",
"tryRepairConnectionEnd",
"(",
"moved",
",",
"other",
",",
"newDocking",
",",
"points",
")",
"{",
"var",
"waypoints",
"=",
"points",
".",
"slice",
"(",
")",
".",
"reverse",
"(",
")",
";",
"waypoints",
"=",
"_tryRepairConnectionSide",
"(",
"moved",
",",
"other",
",",
"newDocking",
",",
"waypoints",
")",
";",
"return",
"waypoints",
"?",
"waypoints",
".",
"reverse",
"(",
")",
":",
"null",
";",
"}"
] | Repair a connection from end.
@param {Bounds} moved
@param {Bounds} other
@param {Point} newDocking
@param {Array<Point>} points originalPoints from moved to other
@return {Array<Point>|null} the repaired points between the two rectangles | [
"Repair",
"a",
"connection",
"from",
"end",
"."
] | fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde | https://github.com/bpmn-io/diagram-js/blob/fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde/lib/layout/ManhattanLayout.js#L502-L508 |
8,263 | bpmn-io/diagram-js | lib/layout/ManhattanLayout.js | _tryRepairConnectionSide | function _tryRepairConnectionSide(moved, other, newDocking, points) {
function needsRelayout(moved, other, points) {
if (points.length < 3) {
return true;
}
if (points.length > 4) {
return false;
}
// relayout if two points overlap
// this is most likely due to
return !!find(points, function(p, idx) {
var q = points[idx - 1];
return q && pointDistance(p, q) < 3;
});
}
function repairBendpoint(candidate, oldPeer, newPeer) {
var alignment = pointsAligned(oldPeer, candidate);
switch (alignment) {
case 'v':
// repair vertical alignment
return { x: candidate.x, y: newPeer.y };
case 'h':
// repair horizontal alignment
return { x: newPeer.x, y: candidate.y };
}
return { x: candidate.x, y: candidate. y };
}
function removeOverlapping(points, a, b) {
var i;
for (i = points.length - 2; i !== 0; i--) {
// intersects (?) break, remove all bendpoints up to this one and relayout
if (pointInRect(points[i], a, INTERSECTION_THRESHOLD) ||
pointInRect(points[i], b, INTERSECTION_THRESHOLD)) {
// return sliced old connection
return points.slice(i);
}
}
return points;
}
// (0) only repair what has layoutable bendpoints
// (1) if only one bendpoint and on shape moved onto other shapes axis
// (horizontally / vertically), relayout
if (needsRelayout(moved, other, points)) {
return null;
}
var oldDocking = points[0],
newPoints = points.slice(),
slicedPoints;
// (2) repair only last line segment and only if it was layouted before
newPoints[0] = newDocking;
newPoints[1] = repairBendpoint(newPoints[1], oldDocking, newDocking);
// (3) if shape intersects with any bendpoint after repair,
// remove all segments up to this bendpoint and repair from there
slicedPoints = removeOverlapping(newPoints, moved, other);
if (slicedPoints !== newPoints) {
return _tryRepairConnectionSide(moved, other, newDocking, slicedPoints);
}
return newPoints;
} | javascript | function _tryRepairConnectionSide(moved, other, newDocking, points) {
function needsRelayout(moved, other, points) {
if (points.length < 3) {
return true;
}
if (points.length > 4) {
return false;
}
// relayout if two points overlap
// this is most likely due to
return !!find(points, function(p, idx) {
var q = points[idx - 1];
return q && pointDistance(p, q) < 3;
});
}
function repairBendpoint(candidate, oldPeer, newPeer) {
var alignment = pointsAligned(oldPeer, candidate);
switch (alignment) {
case 'v':
// repair vertical alignment
return { x: candidate.x, y: newPeer.y };
case 'h':
// repair horizontal alignment
return { x: newPeer.x, y: candidate.y };
}
return { x: candidate.x, y: candidate. y };
}
function removeOverlapping(points, a, b) {
var i;
for (i = points.length - 2; i !== 0; i--) {
// intersects (?) break, remove all bendpoints up to this one and relayout
if (pointInRect(points[i], a, INTERSECTION_THRESHOLD) ||
pointInRect(points[i], b, INTERSECTION_THRESHOLD)) {
// return sliced old connection
return points.slice(i);
}
}
return points;
}
// (0) only repair what has layoutable bendpoints
// (1) if only one bendpoint and on shape moved onto other shapes axis
// (horizontally / vertically), relayout
if (needsRelayout(moved, other, points)) {
return null;
}
var oldDocking = points[0],
newPoints = points.slice(),
slicedPoints;
// (2) repair only last line segment and only if it was layouted before
newPoints[0] = newDocking;
newPoints[1] = repairBendpoint(newPoints[1], oldDocking, newDocking);
// (3) if shape intersects with any bendpoint after repair,
// remove all segments up to this bendpoint and repair from there
slicedPoints = removeOverlapping(newPoints, moved, other);
if (slicedPoints !== newPoints) {
return _tryRepairConnectionSide(moved, other, newDocking, slicedPoints);
}
return newPoints;
} | [
"function",
"_tryRepairConnectionSide",
"(",
"moved",
",",
"other",
",",
"newDocking",
",",
"points",
")",
"{",
"function",
"needsRelayout",
"(",
"moved",
",",
"other",
",",
"points",
")",
"{",
"if",
"(",
"points",
".",
"length",
"<",
"3",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"points",
".",
"length",
">",
"4",
")",
"{",
"return",
"false",
";",
"}",
"// relayout if two points overlap",
"// this is most likely due to",
"return",
"!",
"!",
"find",
"(",
"points",
",",
"function",
"(",
"p",
",",
"idx",
")",
"{",
"var",
"q",
"=",
"points",
"[",
"idx",
"-",
"1",
"]",
";",
"return",
"q",
"&&",
"pointDistance",
"(",
"p",
",",
"q",
")",
"<",
"3",
";",
"}",
")",
";",
"}",
"function",
"repairBendpoint",
"(",
"candidate",
",",
"oldPeer",
",",
"newPeer",
")",
"{",
"var",
"alignment",
"=",
"pointsAligned",
"(",
"oldPeer",
",",
"candidate",
")",
";",
"switch",
"(",
"alignment",
")",
"{",
"case",
"'v'",
":",
"// repair vertical alignment",
"return",
"{",
"x",
":",
"candidate",
".",
"x",
",",
"y",
":",
"newPeer",
".",
"y",
"}",
";",
"case",
"'h'",
":",
"// repair horizontal alignment",
"return",
"{",
"x",
":",
"newPeer",
".",
"x",
",",
"y",
":",
"candidate",
".",
"y",
"}",
";",
"}",
"return",
"{",
"x",
":",
"candidate",
".",
"x",
",",
"y",
":",
"candidate",
".",
"y",
"}",
";",
"}",
"function",
"removeOverlapping",
"(",
"points",
",",
"a",
",",
"b",
")",
"{",
"var",
"i",
";",
"for",
"(",
"i",
"=",
"points",
".",
"length",
"-",
"2",
";",
"i",
"!==",
"0",
";",
"i",
"--",
")",
"{",
"// intersects (?) break, remove all bendpoints up to this one and relayout",
"if",
"(",
"pointInRect",
"(",
"points",
"[",
"i",
"]",
",",
"a",
",",
"INTERSECTION_THRESHOLD",
")",
"||",
"pointInRect",
"(",
"points",
"[",
"i",
"]",
",",
"b",
",",
"INTERSECTION_THRESHOLD",
")",
")",
"{",
"// return sliced old connection",
"return",
"points",
".",
"slice",
"(",
"i",
")",
";",
"}",
"}",
"return",
"points",
";",
"}",
"// (0) only repair what has layoutable bendpoints",
"// (1) if only one bendpoint and on shape moved onto other shapes axis",
"// (horizontally / vertically), relayout",
"if",
"(",
"needsRelayout",
"(",
"moved",
",",
"other",
",",
"points",
")",
")",
"{",
"return",
"null",
";",
"}",
"var",
"oldDocking",
"=",
"points",
"[",
"0",
"]",
",",
"newPoints",
"=",
"points",
".",
"slice",
"(",
")",
",",
"slicedPoints",
";",
"// (2) repair only last line segment and only if it was layouted before",
"newPoints",
"[",
"0",
"]",
"=",
"newDocking",
";",
"newPoints",
"[",
"1",
"]",
"=",
"repairBendpoint",
"(",
"newPoints",
"[",
"1",
"]",
",",
"oldDocking",
",",
"newDocking",
")",
";",
"// (3) if shape intersects with any bendpoint after repair,",
"// remove all segments up to this bendpoint and repair from there",
"slicedPoints",
"=",
"removeOverlapping",
"(",
"newPoints",
",",
"moved",
",",
"other",
")",
";",
"if",
"(",
"slicedPoints",
"!==",
"newPoints",
")",
"{",
"return",
"_tryRepairConnectionSide",
"(",
"moved",
",",
"other",
",",
"newDocking",
",",
"slicedPoints",
")",
";",
"}",
"return",
"newPoints",
";",
"}"
] | Repair a connection from one side that moved.
@param {Bounds} moved
@param {Bounds} other
@param {Point} newDocking
@param {Array<Point>} points originalPoints from moved to other
@return {Array<Point>} the repaired points between the two rectangles | [
"Repair",
"a",
"connection",
"from",
"one",
"side",
"that",
"moved",
"."
] | fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde | https://github.com/bpmn-io/diagram-js/blob/fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde/lib/layout/ManhattanLayout.js#L520-L604 |
8,264 | bpmn-io/diagram-js | lib/core/Canvas.js | createContainer | function createContainer(options) {
options = assign({}, { width: '100%', height: '100%' }, options);
var container = options.container || document.body;
// create a <div> around the svg element with the respective size
// this way we can always get the correct container size
// (this is impossible for <svg> elements at the moment)
var parent = document.createElement('div');
parent.setAttribute('class', 'djs-container');
assign(parent.style, {
position: 'relative',
overflow: 'hidden',
width: ensurePx(options.width),
height: ensurePx(options.height)
});
container.appendChild(parent);
return parent;
} | javascript | function createContainer(options) {
options = assign({}, { width: '100%', height: '100%' }, options);
var container = options.container || document.body;
// create a <div> around the svg element with the respective size
// this way we can always get the correct container size
// (this is impossible for <svg> elements at the moment)
var parent = document.createElement('div');
parent.setAttribute('class', 'djs-container');
assign(parent.style, {
position: 'relative',
overflow: 'hidden',
width: ensurePx(options.width),
height: ensurePx(options.height)
});
container.appendChild(parent);
return parent;
} | [
"function",
"createContainer",
"(",
"options",
")",
"{",
"options",
"=",
"assign",
"(",
"{",
"}",
",",
"{",
"width",
":",
"'100%'",
",",
"height",
":",
"'100%'",
"}",
",",
"options",
")",
";",
"var",
"container",
"=",
"options",
".",
"container",
"||",
"document",
".",
"body",
";",
"// create a <div> around the svg element with the respective size",
"// this way we can always get the correct container size",
"// (this is impossible for <svg> elements at the moment)",
"var",
"parent",
"=",
"document",
".",
"createElement",
"(",
"'div'",
")",
";",
"parent",
".",
"setAttribute",
"(",
"'class'",
",",
"'djs-container'",
")",
";",
"assign",
"(",
"parent",
".",
"style",
",",
"{",
"position",
":",
"'relative'",
",",
"overflow",
":",
"'hidden'",
",",
"width",
":",
"ensurePx",
"(",
"options",
".",
"width",
")",
",",
"height",
":",
"ensurePx",
"(",
"options",
".",
"height",
")",
"}",
")",
";",
"container",
".",
"appendChild",
"(",
"parent",
")",
";",
"return",
"parent",
";",
"}"
] | Creates a HTML container element for a SVG element with
the given configuration
@param {Object} options
@return {HTMLElement} the container element | [
"Creates",
"a",
"HTML",
"container",
"element",
"for",
"a",
"SVG",
"element",
"with",
"the",
"given",
"configuration"
] | fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde | https://github.com/bpmn-io/diagram-js/blob/fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde/lib/core/Canvas.js#L46-L68 |
8,265 | bpmn-io/diagram-js | lib/features/resize/Resize.js | handleMove | function handleMove(context, delta) {
var shape = context.shape,
direction = context.direction,
resizeConstraints = context.resizeConstraints,
newBounds;
context.delta = delta;
newBounds = resizeBounds(shape, direction, delta);
// ensure constraints during resize
context.newBounds = ensureConstraints(newBounds, resizeConstraints);
// update + cache executable state
context.canExecute = self.canResize(context);
} | javascript | function handleMove(context, delta) {
var shape = context.shape,
direction = context.direction,
resizeConstraints = context.resizeConstraints,
newBounds;
context.delta = delta;
newBounds = resizeBounds(shape, direction, delta);
// ensure constraints during resize
context.newBounds = ensureConstraints(newBounds, resizeConstraints);
// update + cache executable state
context.canExecute = self.canResize(context);
} | [
"function",
"handleMove",
"(",
"context",
",",
"delta",
")",
"{",
"var",
"shape",
"=",
"context",
".",
"shape",
",",
"direction",
"=",
"context",
".",
"direction",
",",
"resizeConstraints",
"=",
"context",
".",
"resizeConstraints",
",",
"newBounds",
";",
"context",
".",
"delta",
"=",
"delta",
";",
"newBounds",
"=",
"resizeBounds",
"(",
"shape",
",",
"direction",
",",
"delta",
")",
";",
"// ensure constraints during resize",
"context",
".",
"newBounds",
"=",
"ensureConstraints",
"(",
"newBounds",
",",
"resizeConstraints",
")",
";",
"// update + cache executable state",
"context",
".",
"canExecute",
"=",
"self",
".",
"canResize",
"(",
"context",
")",
";",
"}"
] | Handle resize move by specified delta.
@param {Object} context
@param {Point} delta | [
"Handle",
"resize",
"move",
"by",
"specified",
"delta",
"."
] | fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde | https://github.com/bpmn-io/diagram-js/blob/fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde/lib/features/resize/Resize.js#L72-L88 |
8,266 | bpmn-io/diagram-js | lib/features/resize/Resize.js | handleStart | function handleStart(context) {
var resizeConstraints = context.resizeConstraints,
// evaluate minBounds for backwards compatibility
minBounds = context.minBounds;
if (resizeConstraints !== undefined) {
return;
}
if (minBounds === undefined) {
minBounds = self.computeMinResizeBox(context);
}
context.resizeConstraints = {
min: asTRBL(minBounds)
};
} | javascript | function handleStart(context) {
var resizeConstraints = context.resizeConstraints,
// evaluate minBounds for backwards compatibility
minBounds = context.minBounds;
if (resizeConstraints !== undefined) {
return;
}
if (minBounds === undefined) {
minBounds = self.computeMinResizeBox(context);
}
context.resizeConstraints = {
min: asTRBL(minBounds)
};
} | [
"function",
"handleStart",
"(",
"context",
")",
"{",
"var",
"resizeConstraints",
"=",
"context",
".",
"resizeConstraints",
",",
"// evaluate minBounds for backwards compatibility",
"minBounds",
"=",
"context",
".",
"minBounds",
";",
"if",
"(",
"resizeConstraints",
"!==",
"undefined",
")",
"{",
"return",
";",
"}",
"if",
"(",
"minBounds",
"===",
"undefined",
")",
"{",
"minBounds",
"=",
"self",
".",
"computeMinResizeBox",
"(",
"context",
")",
";",
"}",
"context",
".",
"resizeConstraints",
"=",
"{",
"min",
":",
"asTRBL",
"(",
"minBounds",
")",
"}",
";",
"}"
] | Handle resize start.
@param {Object} context | [
"Handle",
"resize",
"start",
"."
] | fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde | https://github.com/bpmn-io/diagram-js/blob/fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde/lib/features/resize/Resize.js#L95-L112 |
8,267 | bpmn-io/diagram-js | lib/features/resize/Resize.js | handleEnd | function handleEnd(context) {
var shape = context.shape,
canExecute = context.canExecute,
newBounds = context.newBounds;
if (canExecute) {
// ensure we have actual pixel values for new bounds
// (important when zoom level was > 1 during move)
newBounds = roundBounds(newBounds);
// perform the actual resize
modeling.resizeShape(shape, newBounds);
}
} | javascript | function handleEnd(context) {
var shape = context.shape,
canExecute = context.canExecute,
newBounds = context.newBounds;
if (canExecute) {
// ensure we have actual pixel values for new bounds
// (important when zoom level was > 1 during move)
newBounds = roundBounds(newBounds);
// perform the actual resize
modeling.resizeShape(shape, newBounds);
}
} | [
"function",
"handleEnd",
"(",
"context",
")",
"{",
"var",
"shape",
"=",
"context",
".",
"shape",
",",
"canExecute",
"=",
"context",
".",
"canExecute",
",",
"newBounds",
"=",
"context",
".",
"newBounds",
";",
"if",
"(",
"canExecute",
")",
"{",
"// ensure we have actual pixel values for new bounds",
"// (important when zoom level was > 1 during move)",
"newBounds",
"=",
"roundBounds",
"(",
"newBounds",
")",
";",
"// perform the actual resize",
"modeling",
".",
"resizeShape",
"(",
"shape",
",",
"newBounds",
")",
";",
"}",
"}"
] | Handle resize end.
@param {Object} context | [
"Handle",
"resize",
"end",
"."
] | fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde | https://github.com/bpmn-io/diagram-js/blob/fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde/lib/features/resize/Resize.js#L119-L132 |
8,268 | bpmn-io/diagram-js | lib/Diagram.js | bootstrap | function bootstrap(bootstrapModules) {
var modules = [],
components = [];
function hasModule(m) {
return modules.indexOf(m) >= 0;
}
function addModule(m) {
modules.push(m);
}
function visit(m) {
if (hasModule(m)) {
return;
}
(m.__depends__ || []).forEach(visit);
if (hasModule(m)) {
return;
}
addModule(m);
(m.__init__ || []).forEach(function(c) {
components.push(c);
});
}
bootstrapModules.forEach(visit);
var injector = new Injector(modules);
components.forEach(function(c) {
try {
// eagerly resolve component (fn or string)
injector[typeof c === 'string' ? 'get' : 'invoke'](c);
} catch (e) {
console.error('Failed to instantiate component');
console.error(e.stack);
throw e;
}
});
return injector;
} | javascript | function bootstrap(bootstrapModules) {
var modules = [],
components = [];
function hasModule(m) {
return modules.indexOf(m) >= 0;
}
function addModule(m) {
modules.push(m);
}
function visit(m) {
if (hasModule(m)) {
return;
}
(m.__depends__ || []).forEach(visit);
if (hasModule(m)) {
return;
}
addModule(m);
(m.__init__ || []).forEach(function(c) {
components.push(c);
});
}
bootstrapModules.forEach(visit);
var injector = new Injector(modules);
components.forEach(function(c) {
try {
// eagerly resolve component (fn or string)
injector[typeof c === 'string' ? 'get' : 'invoke'](c);
} catch (e) {
console.error('Failed to instantiate component');
console.error(e.stack);
throw e;
}
});
return injector;
} | [
"function",
"bootstrap",
"(",
"bootstrapModules",
")",
"{",
"var",
"modules",
"=",
"[",
"]",
",",
"components",
"=",
"[",
"]",
";",
"function",
"hasModule",
"(",
"m",
")",
"{",
"return",
"modules",
".",
"indexOf",
"(",
"m",
")",
">=",
"0",
";",
"}",
"function",
"addModule",
"(",
"m",
")",
"{",
"modules",
".",
"push",
"(",
"m",
")",
";",
"}",
"function",
"visit",
"(",
"m",
")",
"{",
"if",
"(",
"hasModule",
"(",
"m",
")",
")",
"{",
"return",
";",
"}",
"(",
"m",
".",
"__depends__",
"||",
"[",
"]",
")",
".",
"forEach",
"(",
"visit",
")",
";",
"if",
"(",
"hasModule",
"(",
"m",
")",
")",
"{",
"return",
";",
"}",
"addModule",
"(",
"m",
")",
";",
"(",
"m",
".",
"__init__",
"||",
"[",
"]",
")",
".",
"forEach",
"(",
"function",
"(",
"c",
")",
"{",
"components",
".",
"push",
"(",
"c",
")",
";",
"}",
")",
";",
"}",
"bootstrapModules",
".",
"forEach",
"(",
"visit",
")",
";",
"var",
"injector",
"=",
"new",
"Injector",
"(",
"modules",
")",
";",
"components",
".",
"forEach",
"(",
"function",
"(",
"c",
")",
"{",
"try",
"{",
"// eagerly resolve component (fn or string)",
"injector",
"[",
"typeof",
"c",
"===",
"'string'",
"?",
"'get'",
":",
"'invoke'",
"]",
"(",
"c",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"console",
".",
"error",
"(",
"'Failed to instantiate component'",
")",
";",
"console",
".",
"error",
"(",
"e",
".",
"stack",
")",
";",
"throw",
"e",
";",
"}",
"}",
")",
";",
"return",
"injector",
";",
"}"
] | Bootstrap an injector from a list of modules, instantiating a number of default components
@ignore
@param {Array<didi.Module>} bootstrapModules
@return {didi.Injector} a injector to use to access the components | [
"Bootstrap",
"an",
"injector",
"from",
"a",
"list",
"of",
"modules",
"instantiating",
"a",
"number",
"of",
"default",
"components"
] | fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde | https://github.com/bpmn-io/diagram-js/blob/fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde/lib/Diagram.js#L14-L63 |
8,269 | bpmn-io/diagram-js | lib/Diagram.js | createInjector | function createInjector(options) {
options = options || {};
var configModule = {
'config': ['value', options]
};
var modules = [ configModule, CoreModule ].concat(options.modules || []);
return bootstrap(modules);
} | javascript | function createInjector(options) {
options = options || {};
var configModule = {
'config': ['value', options]
};
var modules = [ configModule, CoreModule ].concat(options.modules || []);
return bootstrap(modules);
} | [
"function",
"createInjector",
"(",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"var",
"configModule",
"=",
"{",
"'config'",
":",
"[",
"'value'",
",",
"options",
"]",
"}",
";",
"var",
"modules",
"=",
"[",
"configModule",
",",
"CoreModule",
"]",
".",
"concat",
"(",
"options",
".",
"modules",
"||",
"[",
"]",
")",
";",
"return",
"bootstrap",
"(",
"modules",
")",
";",
"}"
] | Creates an injector from passed options.
@ignore
@param {Object} options
@return {didi.Injector} | [
"Creates",
"an",
"injector",
"from",
"passed",
"options",
"."
] | fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde | https://github.com/bpmn-io/diagram-js/blob/fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde/lib/Diagram.js#L72-L83 |
8,270 | bpmn-io/diagram-js | lib/features/dragging/Dragging.js | trapClickAndEnd | function trapClickAndEnd(event) {
var untrap;
// trap the click in case we are part of an active
// drag operation. This will effectively prevent
// the ghost click that cannot be canceled otherwise.
if (context.active) {
untrap = installClickTrap(eventBus);
// remove trap after minimal delay
setTimeout(untrap, 400);
// prevent default action (click)
preventDefault(event);
}
end(event);
} | javascript | function trapClickAndEnd(event) {
var untrap;
// trap the click in case we are part of an active
// drag operation. This will effectively prevent
// the ghost click that cannot be canceled otherwise.
if (context.active) {
untrap = installClickTrap(eventBus);
// remove trap after minimal delay
setTimeout(untrap, 400);
// prevent default action (click)
preventDefault(event);
}
end(event);
} | [
"function",
"trapClickAndEnd",
"(",
"event",
")",
"{",
"var",
"untrap",
";",
"// trap the click in case we are part of an active",
"// drag operation. This will effectively prevent",
"// the ghost click that cannot be canceled otherwise.",
"if",
"(",
"context",
".",
"active",
")",
"{",
"untrap",
"=",
"installClickTrap",
"(",
"eventBus",
")",
";",
"// remove trap after minimal delay",
"setTimeout",
"(",
"untrap",
",",
"400",
")",
";",
"// prevent default action (click)",
"preventDefault",
"(",
"event",
")",
";",
"}",
"end",
"(",
"event",
")",
";",
"}"
] | prevent ghost click that might occur after a finished drag and drop session | [
"prevent",
"ghost",
"click",
"that",
"might",
"occur",
"after",
"a",
"finished",
"drag",
"and",
"drop",
"session"
] | fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde | https://github.com/bpmn-io/diagram-js/blob/fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde/lib/features/dragging/Dragging.js#L289-L308 |
8,271 | bpmn-io/diagram-js | lib/features/dragging/Dragging.js | cancel | function cancel(restore) {
var previousContext;
if (!context) {
return;
}
var wasActive = context.active;
if (wasActive) {
fire('cancel');
}
previousContext = cleanup(restore);
if (wasActive) {
// last event to be fired when all drag operations are done
// at this point in time no drag operation is in progress anymore
fire('canceled', previousContext);
}
} | javascript | function cancel(restore) {
var previousContext;
if (!context) {
return;
}
var wasActive = context.active;
if (wasActive) {
fire('cancel');
}
previousContext = cleanup(restore);
if (wasActive) {
// last event to be fired when all drag operations are done
// at this point in time no drag operation is in progress anymore
fire('canceled', previousContext);
}
} | [
"function",
"cancel",
"(",
"restore",
")",
"{",
"var",
"previousContext",
";",
"if",
"(",
"!",
"context",
")",
"{",
"return",
";",
"}",
"var",
"wasActive",
"=",
"context",
".",
"active",
";",
"if",
"(",
"wasActive",
")",
"{",
"fire",
"(",
"'cancel'",
")",
";",
"}",
"previousContext",
"=",
"cleanup",
"(",
"restore",
")",
";",
"if",
"(",
"wasActive",
")",
"{",
"// last event to be fired when all drag operations are done",
"// at this point in time no drag operation is in progress anymore",
"fire",
"(",
"'canceled'",
",",
"previousContext",
")",
";",
"}",
"}"
] | life-cycle methods | [
"life",
"-",
"cycle",
"methods"
] | fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde | https://github.com/bpmn-io/diagram-js/blob/fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde/lib/features/dragging/Dragging.js#L339-L359 |
8,272 | bpmn-io/diagram-js | lib/features/dragging/Dragging.js | init | function init(event, relativeTo, prefix, options) {
// only one drag operation may be active, at a time
if (context) {
cancel(false);
}
if (typeof relativeTo === 'string') {
options = prefix;
prefix = relativeTo;
relativeTo = null;
}
options = assign({}, defaultOptions, options || {});
var data = options.data || {},
originalEvent,
globalStart,
localStart,
endDrag,
isTouch;
if (options.trapClick) {
endDrag = trapClickAndEnd;
} else {
endDrag = end;
}
if (event) {
originalEvent = getOriginal(event) || event;
globalStart = toPoint(event);
stopPropagation(event);
// prevent default browser dragging behavior
if (originalEvent.type === 'dragstart') {
preventDefault(originalEvent);
}
} else {
originalEvent = null;
globalStart = { x: 0, y: 0 };
}
localStart = toLocalPoint(globalStart);
if (!relativeTo) {
relativeTo = localStart;
}
isTouch = isTouchEvent(originalEvent);
context = assign({
prefix: prefix,
data: data,
payload: {},
globalStart: globalStart,
displacement: deltaPos(relativeTo, localStart),
localStart: localStart,
isTouch: isTouch
}, options);
// skip dom registration if trigger
// is set to manual (during testing)
if (!options.manual) {
// add dom listeners
if (isTouch) {
domEvent.bind(document, 'touchstart', trapTouch, true);
domEvent.bind(document, 'touchcancel', cancel, true);
domEvent.bind(document, 'touchmove', move, true);
domEvent.bind(document, 'touchend', end, true);
} else {
// assume we use the mouse to interact per default
domEvent.bind(document, 'mousemove', move);
// prevent default browser drag and text selection behavior
domEvent.bind(document, 'dragstart', preventDefault);
domEvent.bind(document, 'selectstart', preventDefault);
domEvent.bind(document, 'mousedown', endDrag, true);
domEvent.bind(document, 'mouseup', endDrag, true);
}
domEvent.bind(document, 'keyup', checkCancel);
eventBus.on('element.hover', hover);
eventBus.on('element.out', out);
}
fire('init');
if (options.autoActivate) {
move(event, true);
}
} | javascript | function init(event, relativeTo, prefix, options) {
// only one drag operation may be active, at a time
if (context) {
cancel(false);
}
if (typeof relativeTo === 'string') {
options = prefix;
prefix = relativeTo;
relativeTo = null;
}
options = assign({}, defaultOptions, options || {});
var data = options.data || {},
originalEvent,
globalStart,
localStart,
endDrag,
isTouch;
if (options.trapClick) {
endDrag = trapClickAndEnd;
} else {
endDrag = end;
}
if (event) {
originalEvent = getOriginal(event) || event;
globalStart = toPoint(event);
stopPropagation(event);
// prevent default browser dragging behavior
if (originalEvent.type === 'dragstart') {
preventDefault(originalEvent);
}
} else {
originalEvent = null;
globalStart = { x: 0, y: 0 };
}
localStart = toLocalPoint(globalStart);
if (!relativeTo) {
relativeTo = localStart;
}
isTouch = isTouchEvent(originalEvent);
context = assign({
prefix: prefix,
data: data,
payload: {},
globalStart: globalStart,
displacement: deltaPos(relativeTo, localStart),
localStart: localStart,
isTouch: isTouch
}, options);
// skip dom registration if trigger
// is set to manual (during testing)
if (!options.manual) {
// add dom listeners
if (isTouch) {
domEvent.bind(document, 'touchstart', trapTouch, true);
domEvent.bind(document, 'touchcancel', cancel, true);
domEvent.bind(document, 'touchmove', move, true);
domEvent.bind(document, 'touchend', end, true);
} else {
// assume we use the mouse to interact per default
domEvent.bind(document, 'mousemove', move);
// prevent default browser drag and text selection behavior
domEvent.bind(document, 'dragstart', preventDefault);
domEvent.bind(document, 'selectstart', preventDefault);
domEvent.bind(document, 'mousedown', endDrag, true);
domEvent.bind(document, 'mouseup', endDrag, true);
}
domEvent.bind(document, 'keyup', checkCancel);
eventBus.on('element.hover', hover);
eventBus.on('element.out', out);
}
fire('init');
if (options.autoActivate) {
move(event, true);
}
} | [
"function",
"init",
"(",
"event",
",",
"relativeTo",
",",
"prefix",
",",
"options",
")",
"{",
"// only one drag operation may be active, at a time",
"if",
"(",
"context",
")",
"{",
"cancel",
"(",
"false",
")",
";",
"}",
"if",
"(",
"typeof",
"relativeTo",
"===",
"'string'",
")",
"{",
"options",
"=",
"prefix",
";",
"prefix",
"=",
"relativeTo",
";",
"relativeTo",
"=",
"null",
";",
"}",
"options",
"=",
"assign",
"(",
"{",
"}",
",",
"defaultOptions",
",",
"options",
"||",
"{",
"}",
")",
";",
"var",
"data",
"=",
"options",
".",
"data",
"||",
"{",
"}",
",",
"originalEvent",
",",
"globalStart",
",",
"localStart",
",",
"endDrag",
",",
"isTouch",
";",
"if",
"(",
"options",
".",
"trapClick",
")",
"{",
"endDrag",
"=",
"trapClickAndEnd",
";",
"}",
"else",
"{",
"endDrag",
"=",
"end",
";",
"}",
"if",
"(",
"event",
")",
"{",
"originalEvent",
"=",
"getOriginal",
"(",
"event",
")",
"||",
"event",
";",
"globalStart",
"=",
"toPoint",
"(",
"event",
")",
";",
"stopPropagation",
"(",
"event",
")",
";",
"// prevent default browser dragging behavior",
"if",
"(",
"originalEvent",
".",
"type",
"===",
"'dragstart'",
")",
"{",
"preventDefault",
"(",
"originalEvent",
")",
";",
"}",
"}",
"else",
"{",
"originalEvent",
"=",
"null",
";",
"globalStart",
"=",
"{",
"x",
":",
"0",
",",
"y",
":",
"0",
"}",
";",
"}",
"localStart",
"=",
"toLocalPoint",
"(",
"globalStart",
")",
";",
"if",
"(",
"!",
"relativeTo",
")",
"{",
"relativeTo",
"=",
"localStart",
";",
"}",
"isTouch",
"=",
"isTouchEvent",
"(",
"originalEvent",
")",
";",
"context",
"=",
"assign",
"(",
"{",
"prefix",
":",
"prefix",
",",
"data",
":",
"data",
",",
"payload",
":",
"{",
"}",
",",
"globalStart",
":",
"globalStart",
",",
"displacement",
":",
"deltaPos",
"(",
"relativeTo",
",",
"localStart",
")",
",",
"localStart",
":",
"localStart",
",",
"isTouch",
":",
"isTouch",
"}",
",",
"options",
")",
";",
"// skip dom registration if trigger",
"// is set to manual (during testing)",
"if",
"(",
"!",
"options",
".",
"manual",
")",
"{",
"// add dom listeners",
"if",
"(",
"isTouch",
")",
"{",
"domEvent",
".",
"bind",
"(",
"document",
",",
"'touchstart'",
",",
"trapTouch",
",",
"true",
")",
";",
"domEvent",
".",
"bind",
"(",
"document",
",",
"'touchcancel'",
",",
"cancel",
",",
"true",
")",
";",
"domEvent",
".",
"bind",
"(",
"document",
",",
"'touchmove'",
",",
"move",
",",
"true",
")",
";",
"domEvent",
".",
"bind",
"(",
"document",
",",
"'touchend'",
",",
"end",
",",
"true",
")",
";",
"}",
"else",
"{",
"// assume we use the mouse to interact per default",
"domEvent",
".",
"bind",
"(",
"document",
",",
"'mousemove'",
",",
"move",
")",
";",
"// prevent default browser drag and text selection behavior",
"domEvent",
".",
"bind",
"(",
"document",
",",
"'dragstart'",
",",
"preventDefault",
")",
";",
"domEvent",
".",
"bind",
"(",
"document",
",",
"'selectstart'",
",",
"preventDefault",
")",
";",
"domEvent",
".",
"bind",
"(",
"document",
",",
"'mousedown'",
",",
"endDrag",
",",
"true",
")",
";",
"domEvent",
".",
"bind",
"(",
"document",
",",
"'mouseup'",
",",
"endDrag",
",",
"true",
")",
";",
"}",
"domEvent",
".",
"bind",
"(",
"document",
",",
"'keyup'",
",",
"checkCancel",
")",
";",
"eventBus",
".",
"on",
"(",
"'element.hover'",
",",
"hover",
")",
";",
"eventBus",
".",
"on",
"(",
"'element.out'",
",",
"out",
")",
";",
"}",
"fire",
"(",
"'init'",
")",
";",
"if",
"(",
"options",
".",
"autoActivate",
")",
"{",
"move",
"(",
"event",
",",
"true",
")",
";",
"}",
"}"
] | Initialize a drag operation.
If `localPosition` is given, drag events will be emitted
relative to it.
@param {MouseEvent|TouchEvent} [event]
@param {Point} [localPosition] actual diagram local position this drag operation should start at
@param {String} prefix
@param {Object} [options] | [
"Initialize",
"a",
"drag",
"operation",
"."
] | fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde | https://github.com/bpmn-io/diagram-js/blob/fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde/lib/features/dragging/Dragging.js#L423-L518 |
8,273 | bpmn-io/diagram-js | lib/features/bendpoints/ConnectionSegmentMove.js | getDocking | function getDocking(point, referenceElement, moveAxis) {
var referenceMid,
inverseAxis;
if (point.original) {
return point.original;
} else {
referenceMid = getMid(referenceElement);
inverseAxis = flipAxis(moveAxis);
return axisSet(point, inverseAxis, referenceMid[inverseAxis]);
}
} | javascript | function getDocking(point, referenceElement, moveAxis) {
var referenceMid,
inverseAxis;
if (point.original) {
return point.original;
} else {
referenceMid = getMid(referenceElement);
inverseAxis = flipAxis(moveAxis);
return axisSet(point, inverseAxis, referenceMid[inverseAxis]);
}
} | [
"function",
"getDocking",
"(",
"point",
",",
"referenceElement",
",",
"moveAxis",
")",
"{",
"var",
"referenceMid",
",",
"inverseAxis",
";",
"if",
"(",
"point",
".",
"original",
")",
"{",
"return",
"point",
".",
"original",
";",
"}",
"else",
"{",
"referenceMid",
"=",
"getMid",
"(",
"referenceElement",
")",
";",
"inverseAxis",
"=",
"flipAxis",
"(",
"moveAxis",
")",
";",
"return",
"axisSet",
"(",
"point",
",",
"inverseAxis",
",",
"referenceMid",
"[",
"inverseAxis",
"]",
")",
";",
"}",
"}"
] | Get the docking point on the given element.
Compute a reasonable docking, if non exists.
@param {Point} point
@param {djs.model.Shape} referenceElement
@param {String} moveAxis (x|y)
@return {Point} | [
"Get",
"the",
"docking",
"point",
"on",
"the",
"given",
"element",
"."
] | fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde | https://github.com/bpmn-io/diagram-js/blob/fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde/lib/features/bendpoints/ConnectionSegmentMove.js#L66-L79 |
8,274 | bpmn-io/diagram-js | lib/features/bendpoints/ConnectionSegmentMove.js | cropConnection | function cropConnection(connection, newWaypoints) {
// crop connection, if docking service is provided only
if (!connectionDocking) {
return newWaypoints;
}
var oldWaypoints = connection.waypoints,
croppedWaypoints;
// temporary set new waypoints
connection.waypoints = newWaypoints;
croppedWaypoints = connectionDocking.getCroppedWaypoints(connection);
// restore old waypoints
connection.waypoints = oldWaypoints;
return croppedWaypoints;
} | javascript | function cropConnection(connection, newWaypoints) {
// crop connection, if docking service is provided only
if (!connectionDocking) {
return newWaypoints;
}
var oldWaypoints = connection.waypoints,
croppedWaypoints;
// temporary set new waypoints
connection.waypoints = newWaypoints;
croppedWaypoints = connectionDocking.getCroppedWaypoints(connection);
// restore old waypoints
connection.waypoints = oldWaypoints;
return croppedWaypoints;
} | [
"function",
"cropConnection",
"(",
"connection",
",",
"newWaypoints",
")",
"{",
"// crop connection, if docking service is provided only",
"if",
"(",
"!",
"connectionDocking",
")",
"{",
"return",
"newWaypoints",
";",
"}",
"var",
"oldWaypoints",
"=",
"connection",
".",
"waypoints",
",",
"croppedWaypoints",
";",
"// temporary set new waypoints",
"connection",
".",
"waypoints",
"=",
"newWaypoints",
";",
"croppedWaypoints",
"=",
"connectionDocking",
".",
"getCroppedWaypoints",
"(",
"connection",
")",
";",
"// restore old waypoints",
"connection",
".",
"waypoints",
"=",
"oldWaypoints",
";",
"return",
"croppedWaypoints",
";",
"}"
] | Crop connection if connection cropping is provided.
@param {Connection} connection
@param {Array<Point>} newWaypoints
@return {Array<Point>} cropped connection waypoints | [
"Crop",
"connection",
"if",
"connection",
"cropping",
"is",
"provided",
"."
] | fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde | https://github.com/bpmn-io/diagram-js/blob/fe4918cc1fefa3f5cd8e946cb9fff44e7ebb4cde/lib/features/bendpoints/ConnectionSegmentMove.js#L155-L174 |
8,275 | Akryum/v-tooltip | dist/v-tooltip.esm.js | addClasses | function addClasses(el, classes) {
var newClasses = convertToArray(classes);
var classList;
if (el.className instanceof SVGAnimatedString) {
classList = convertToArray(el.className.baseVal);
} else {
classList = convertToArray(el.className);
}
newClasses.forEach(function (newClass) {
if (classList.indexOf(newClass) === -1) {
classList.push(newClass);
}
});
if (el instanceof SVGElement) {
el.setAttribute('class', classList.join(' '));
} else {
el.className = classList.join(' ');
}
} | javascript | function addClasses(el, classes) {
var newClasses = convertToArray(classes);
var classList;
if (el.className instanceof SVGAnimatedString) {
classList = convertToArray(el.className.baseVal);
} else {
classList = convertToArray(el.className);
}
newClasses.forEach(function (newClass) {
if (classList.indexOf(newClass) === -1) {
classList.push(newClass);
}
});
if (el instanceof SVGElement) {
el.setAttribute('class', classList.join(' '));
} else {
el.className = classList.join(' ');
}
} | [
"function",
"addClasses",
"(",
"el",
",",
"classes",
")",
"{",
"var",
"newClasses",
"=",
"convertToArray",
"(",
"classes",
")",
";",
"var",
"classList",
";",
"if",
"(",
"el",
".",
"className",
"instanceof",
"SVGAnimatedString",
")",
"{",
"classList",
"=",
"convertToArray",
"(",
"el",
".",
"className",
".",
"baseVal",
")",
";",
"}",
"else",
"{",
"classList",
"=",
"convertToArray",
"(",
"el",
".",
"className",
")",
";",
"}",
"newClasses",
".",
"forEach",
"(",
"function",
"(",
"newClass",
")",
"{",
"if",
"(",
"classList",
".",
"indexOf",
"(",
"newClass",
")",
"===",
"-",
"1",
")",
"{",
"classList",
".",
"push",
"(",
"newClass",
")",
";",
"}",
"}",
")",
";",
"if",
"(",
"el",
"instanceof",
"SVGElement",
")",
"{",
"el",
".",
"setAttribute",
"(",
"'class'",
",",
"classList",
".",
"join",
"(",
"' '",
")",
")",
";",
"}",
"else",
"{",
"el",
".",
"className",
"=",
"classList",
".",
"join",
"(",
"' '",
")",
";",
"}",
"}"
] | Add classes to an element.
This method checks to ensure that the classes don't already exist before adding them.
It uses el.className rather than classList in order to be IE friendly.
@param {object} el - The element to add the classes to.
@param {classes} string - List of space separated classes to be added to the element. | [
"Add",
"classes",
"to",
"an",
"element",
".",
"This",
"method",
"checks",
"to",
"ensure",
"that",
"the",
"classes",
"don",
"t",
"already",
"exist",
"before",
"adding",
"them",
".",
"It",
"uses",
"el",
".",
"className",
"rather",
"than",
"classList",
"in",
"order",
"to",
"be",
"IE",
"friendly",
"."
] | d60513c64c266f0c1e926e2e583a5733819138bd | https://github.com/Akryum/v-tooltip/blob/d60513c64c266f0c1e926e2e583a5733819138bd/dist/v-tooltip.esm.js#L95-L116 |
8,276 | Akryum/v-tooltip | dist/v-tooltip.esm.js | removeClasses | function removeClasses(el, classes) {
var newClasses = convertToArray(classes);
var classList;
if (el.className instanceof SVGAnimatedString) {
classList = convertToArray(el.className.baseVal);
} else {
classList = convertToArray(el.className);
}
newClasses.forEach(function (newClass) {
var index = classList.indexOf(newClass);
if (index !== -1) {
classList.splice(index, 1);
}
});
if (el instanceof SVGElement) {
el.setAttribute('class', classList.join(' '));
} else {
el.className = classList.join(' ');
}
} | javascript | function removeClasses(el, classes) {
var newClasses = convertToArray(classes);
var classList;
if (el.className instanceof SVGAnimatedString) {
classList = convertToArray(el.className.baseVal);
} else {
classList = convertToArray(el.className);
}
newClasses.forEach(function (newClass) {
var index = classList.indexOf(newClass);
if (index !== -1) {
classList.splice(index, 1);
}
});
if (el instanceof SVGElement) {
el.setAttribute('class', classList.join(' '));
} else {
el.className = classList.join(' ');
}
} | [
"function",
"removeClasses",
"(",
"el",
",",
"classes",
")",
"{",
"var",
"newClasses",
"=",
"convertToArray",
"(",
"classes",
")",
";",
"var",
"classList",
";",
"if",
"(",
"el",
".",
"className",
"instanceof",
"SVGAnimatedString",
")",
"{",
"classList",
"=",
"convertToArray",
"(",
"el",
".",
"className",
".",
"baseVal",
")",
";",
"}",
"else",
"{",
"classList",
"=",
"convertToArray",
"(",
"el",
".",
"className",
")",
";",
"}",
"newClasses",
".",
"forEach",
"(",
"function",
"(",
"newClass",
")",
"{",
"var",
"index",
"=",
"classList",
".",
"indexOf",
"(",
"newClass",
")",
";",
"if",
"(",
"index",
"!==",
"-",
"1",
")",
"{",
"classList",
".",
"splice",
"(",
"index",
",",
"1",
")",
";",
"}",
"}",
")",
";",
"if",
"(",
"el",
"instanceof",
"SVGElement",
")",
"{",
"el",
".",
"setAttribute",
"(",
"'class'",
",",
"classList",
".",
"join",
"(",
"' '",
")",
")",
";",
"}",
"else",
"{",
"el",
".",
"className",
"=",
"classList",
".",
"join",
"(",
"' '",
")",
";",
"}",
"}"
] | Remove classes from an element.
It uses el.className rather than classList in order to be IE friendly.
@export
@param {any} el The element to remove the classes from.
@param {any} classes List of space separated classes to be removed from the element. | [
"Remove",
"classes",
"from",
"an",
"element",
".",
"It",
"uses",
"el",
".",
"className",
"rather",
"than",
"classList",
"in",
"order",
"to",
"be",
"IE",
"friendly",
"."
] | d60513c64c266f0c1e926e2e583a5733819138bd | https://github.com/Akryum/v-tooltip/blob/d60513c64c266f0c1e926e2e583a5733819138bd/dist/v-tooltip.esm.js#L125-L148 |
8,277 | Akryum/v-tooltip | dist/v-tooltip.esm.js | Tooltip | function Tooltip(_reference, _options) {
var _this = this;
_classCallCheck(this, Tooltip);
_defineProperty(this, "_events", []);
_defineProperty(this, "_setTooltipNodeEvent", function (evt, reference, delay, options) {
var relatedreference = evt.relatedreference || evt.toElement || evt.relatedTarget;
var callback = function callback(evt2) {
var relatedreference2 = evt2.relatedreference || evt2.toElement || evt2.relatedTarget; // Remove event listener after call
_this._tooltipNode.removeEventListener(evt.type, callback); // If the new reference is not the reference element
if (!reference.contains(relatedreference2)) {
// Schedule to hide tooltip
_this._scheduleHide(reference, options.delay, options, evt2);
}
};
if (_this._tooltipNode.contains(relatedreference)) {
// listen to mouseleave on the tooltip element to be able to hide the tooltip
_this._tooltipNode.addEventListener(evt.type, callback);
return true;
}
return false;
});
// apply user options over default ones
_options = _objectSpread({}, DEFAULT_OPTIONS, _options);
_reference.jquery && (_reference = _reference[0]);
this.show = this.show.bind(this);
this.hide = this.hide.bind(this); // cache reference and options
this.reference = _reference;
this.options = _options; // set initial state
this._isOpen = false;
this._init();
} | javascript | function Tooltip(_reference, _options) {
var _this = this;
_classCallCheck(this, Tooltip);
_defineProperty(this, "_events", []);
_defineProperty(this, "_setTooltipNodeEvent", function (evt, reference, delay, options) {
var relatedreference = evt.relatedreference || evt.toElement || evt.relatedTarget;
var callback = function callback(evt2) {
var relatedreference2 = evt2.relatedreference || evt2.toElement || evt2.relatedTarget; // Remove event listener after call
_this._tooltipNode.removeEventListener(evt.type, callback); // If the new reference is not the reference element
if (!reference.contains(relatedreference2)) {
// Schedule to hide tooltip
_this._scheduleHide(reference, options.delay, options, evt2);
}
};
if (_this._tooltipNode.contains(relatedreference)) {
// listen to mouseleave on the tooltip element to be able to hide the tooltip
_this._tooltipNode.addEventListener(evt.type, callback);
return true;
}
return false;
});
// apply user options over default ones
_options = _objectSpread({}, DEFAULT_OPTIONS, _options);
_reference.jquery && (_reference = _reference[0]);
this.show = this.show.bind(this);
this.hide = this.hide.bind(this); // cache reference and options
this.reference = _reference;
this.options = _options; // set initial state
this._isOpen = false;
this._init();
} | [
"function",
"Tooltip",
"(",
"_reference",
",",
"_options",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"_classCallCheck",
"(",
"this",
",",
"Tooltip",
")",
";",
"_defineProperty",
"(",
"this",
",",
"\"_events\"",
",",
"[",
"]",
")",
";",
"_defineProperty",
"(",
"this",
",",
"\"_setTooltipNodeEvent\"",
",",
"function",
"(",
"evt",
",",
"reference",
",",
"delay",
",",
"options",
")",
"{",
"var",
"relatedreference",
"=",
"evt",
".",
"relatedreference",
"||",
"evt",
".",
"toElement",
"||",
"evt",
".",
"relatedTarget",
";",
"var",
"callback",
"=",
"function",
"callback",
"(",
"evt2",
")",
"{",
"var",
"relatedreference2",
"=",
"evt2",
".",
"relatedreference",
"||",
"evt2",
".",
"toElement",
"||",
"evt2",
".",
"relatedTarget",
";",
"// Remove event listener after call",
"_this",
".",
"_tooltipNode",
".",
"removeEventListener",
"(",
"evt",
".",
"type",
",",
"callback",
")",
";",
"// If the new reference is not the reference element",
"if",
"(",
"!",
"reference",
".",
"contains",
"(",
"relatedreference2",
")",
")",
"{",
"// Schedule to hide tooltip",
"_this",
".",
"_scheduleHide",
"(",
"reference",
",",
"options",
".",
"delay",
",",
"options",
",",
"evt2",
")",
";",
"}",
"}",
";",
"if",
"(",
"_this",
".",
"_tooltipNode",
".",
"contains",
"(",
"relatedreference",
")",
")",
"{",
"// listen to mouseleave on the tooltip element to be able to hide the tooltip",
"_this",
".",
"_tooltipNode",
".",
"addEventListener",
"(",
"evt",
".",
"type",
",",
"callback",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}",
")",
";",
"// apply user options over default ones",
"_options",
"=",
"_objectSpread",
"(",
"{",
"}",
",",
"DEFAULT_OPTIONS",
",",
"_options",
")",
";",
"_reference",
".",
"jquery",
"&&",
"(",
"_reference",
"=",
"_reference",
"[",
"0",
"]",
")",
";",
"this",
".",
"show",
"=",
"this",
".",
"show",
".",
"bind",
"(",
"this",
")",
";",
"this",
".",
"hide",
"=",
"this",
".",
"hide",
".",
"bind",
"(",
"this",
")",
";",
"// cache reference and options",
"this",
".",
"reference",
"=",
"_reference",
";",
"this",
".",
"options",
"=",
"_options",
";",
"// set initial state",
"this",
".",
"_isOpen",
"=",
"false",
";",
"this",
".",
"_init",
"(",
")",
";",
"}"
] | Create a new Tooltip.js instance
@class Tooltip
@param {HTMLElement} reference - The DOM node used as reference of the tooltip (it can be a jQuery element).
@param {Object} options
@param {String} options.placement=bottom
Placement of the popper accepted values: `top(-start, -end), right(-start, -end), bottom(-start, -end),
left(-start, -end)`
@param {HTMLElement|String|false} options.container=false - Append the tooltip to a specific element.
@param {Number|Object} options.delay=0
Delay showing and hiding the tooltip (ms) - does not apply to manual trigger type.
If a number is supplied, delay is applied to both hide/show.
Object structure is: `{ show: 500, hide: 100 }`
@param {Boolean} options.html=false - Insert HTML into the tooltip. If false, the content will inserted with `innerText`.
@param {String|PlacementFunction} options.placement='top' - One of the allowed placements, or a function returning one of them.
@param {String} [options.template='<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>']
Base HTML to used when creating the tooltip.
The tooltip's `title` will be injected into the `.tooltip-inner` or `.tooltip__inner`.
`.tooltip-arrow` or `.tooltip__arrow` will become the tooltip's arrow.
The outermost wrapper element should have the `.tooltip` class.
@param {String|HTMLElement|TitleFunction} options.title='' - Default title value if `title` attribute isn't present.
@param {String} [options.trigger='hover focus']
How tooltip is triggered - click, hover, focus, manual.
You may pass multiple triggers; separate them with a space. `manual` cannot be combined with any other trigger.
@param {HTMLElement} options.boundariesElement
The element used as boundaries for the tooltip. For more information refer to Popper.js'
[boundariesElement docs](https://popper.js.org/popper-documentation.html)
@param {Number|String} options.offset=0 - Offset of the tooltip relative to its reference. For more information refer to Popper.js'
[offset docs](https://popper.js.org/popper-documentation.html)
@param {Object} options.popperOptions={} - Popper options, will be passed directly to popper instance. For more information refer to Popper.js'
[options docs](https://popper.js.org/popper-documentation.html)
@return {Object} instance - The generated tooltip instance | [
"Create",
"a",
"new",
"Tooltip",
".",
"js",
"instance"
] | d60513c64c266f0c1e926e2e583a5733819138bd | https://github.com/Akryum/v-tooltip/blob/d60513c64c266f0c1e926e2e583a5733819138bd/dist/v-tooltip.esm.js#L212-L256 |
8,278 | IonicaBizau/scrape-it | lib/index.js | scrapeIt | function scrapeIt (url, opts, cb) {
cb = assured(cb)
req(url, (err, $, res, body) => {
if (err) { return cb(err) }
try {
let scrapedData = scrapeIt.scrapeHTML($, opts)
cb(null, {
data: scrapedData,
$,
response: res,
body
})
}
catch (err) {
cb(err);
}
})
return cb._
} | javascript | function scrapeIt (url, opts, cb) {
cb = assured(cb)
req(url, (err, $, res, body) => {
if (err) { return cb(err) }
try {
let scrapedData = scrapeIt.scrapeHTML($, opts)
cb(null, {
data: scrapedData,
$,
response: res,
body
})
}
catch (err) {
cb(err);
}
})
return cb._
} | [
"function",
"scrapeIt",
"(",
"url",
",",
"opts",
",",
"cb",
")",
"{",
"cb",
"=",
"assured",
"(",
"cb",
")",
"req",
"(",
"url",
",",
"(",
"err",
",",
"$",
",",
"res",
",",
"body",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"cb",
"(",
"err",
")",
"}",
"try",
"{",
"let",
"scrapedData",
"=",
"scrapeIt",
".",
"scrapeHTML",
"(",
"$",
",",
"opts",
")",
"cb",
"(",
"null",
",",
"{",
"data",
":",
"scrapedData",
",",
"$",
",",
"response",
":",
"res",
",",
"body",
"}",
")",
"}",
"catch",
"(",
"err",
")",
"{",
"cb",
"(",
"err",
")",
";",
"}",
"}",
")",
"return",
"cb",
".",
"_",
"}"
] | scrapeIt
A scraping module for humans.
@name scrapeIt
@function
@param {String|Object} url The page url or request options.
@param {Object} opts The options passed to `scrapeHTML` method.
@param {Function} cb The callback function.
@return {Promise} A promise object resolving with:
- `data` (Object): The scraped data.
- `$` (Function): The Cheeerio function. This may be handy to do some other manipulation on the DOM, if needed.
- `response` (Object): The response object.
- `body` (String): The raw body as a string. | [
"scrapeIt",
"A",
"scraping",
"module",
"for",
"humans",
"."
] | 596191dfdbd5613ba88a58c9ee5a39f061c5b395 | https://github.com/IonicaBizau/scrape-it/blob/596191dfdbd5613ba88a58c9ee5a39f061c5b395/lib/index.js#L29-L47 |
8,279 | instea/react-native-popup-menu | build/rnpm.js | measure | function measure(ref) {
return new Promise(function (resolve) {
ref.measure(function (x, y, width, height, pageX, pageY) {
resolve({
x: pageX,
y: pageY,
width: width,
height: height
});
});
});
} | javascript | function measure(ref) {
return new Promise(function (resolve) {
ref.measure(function (x, y, width, height, pageX, pageY) {
resolve({
x: pageX,
y: pageY,
width: width,
height: height
});
});
});
} | [
"function",
"measure",
"(",
"ref",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
")",
"{",
"ref",
".",
"measure",
"(",
"function",
"(",
"x",
",",
"y",
",",
"width",
",",
"height",
",",
"pageX",
",",
"pageY",
")",
"{",
"resolve",
"(",
"{",
"x",
":",
"pageX",
",",
"y",
":",
"pageY",
",",
"width",
":",
"width",
",",
"height",
":",
"height",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Promisifies measure's callback function and returns layout object. | [
"Promisifies",
"measure",
"s",
"callback",
"function",
"and",
"returns",
"layout",
"object",
"."
] | 46197a3a72a2031c040b6c1c5971199bb53f938b | https://github.com/instea/react-native-popup-menu/blob/46197a3a72a2031c040b6c1c5971199bb53f938b/build/rnpm.js#L178-L189 |
8,280 | instea/react-native-popup-menu | build/rnpm.js | makeTouchable | function makeTouchable(TouchableComponent) {
var Touchable = TouchableComponent || reactNative.Platform.select({
android: reactNative.TouchableNativeFeedback,
ios: reactNative.TouchableHighlight,
default: reactNative.TouchableHighlight
});
var defaultTouchableProps = {};
if (Touchable === reactNative.TouchableHighlight) {
defaultTouchableProps = {
underlayColor: 'rgba(0, 0, 0, 0.1)'
};
}
return {
Touchable: Touchable,
defaultTouchableProps: defaultTouchableProps
};
} | javascript | function makeTouchable(TouchableComponent) {
var Touchable = TouchableComponent || reactNative.Platform.select({
android: reactNative.TouchableNativeFeedback,
ios: reactNative.TouchableHighlight,
default: reactNative.TouchableHighlight
});
var defaultTouchableProps = {};
if (Touchable === reactNative.TouchableHighlight) {
defaultTouchableProps = {
underlayColor: 'rgba(0, 0, 0, 0.1)'
};
}
return {
Touchable: Touchable,
defaultTouchableProps: defaultTouchableProps
};
} | [
"function",
"makeTouchable",
"(",
"TouchableComponent",
")",
"{",
"var",
"Touchable",
"=",
"TouchableComponent",
"||",
"reactNative",
".",
"Platform",
".",
"select",
"(",
"{",
"android",
":",
"reactNative",
".",
"TouchableNativeFeedback",
",",
"ios",
":",
"reactNative",
".",
"TouchableHighlight",
",",
"default",
":",
"reactNative",
".",
"TouchableHighlight",
"}",
")",
";",
"var",
"defaultTouchableProps",
"=",
"{",
"}",
";",
"if",
"(",
"Touchable",
"===",
"reactNative",
".",
"TouchableHighlight",
")",
"{",
"defaultTouchableProps",
"=",
"{",
"underlayColor",
":",
"'rgba(0, 0, 0, 0.1)'",
"}",
";",
"}",
"return",
"{",
"Touchable",
":",
"Touchable",
",",
"defaultTouchableProps",
":",
"defaultTouchableProps",
"}",
";",
"}"
] | Create touchable component based on passed parameter and platform.
It also returns default props for specific touchable types. | [
"Create",
"touchable",
"component",
"based",
"on",
"passed",
"parameter",
"and",
"platform",
".",
"It",
"also",
"returns",
"default",
"props",
"for",
"specific",
"touchable",
"types",
"."
] | 46197a3a72a2031c040b6c1c5971199bb53f938b | https://github.com/instea/react-native-popup-menu/blob/46197a3a72a2031c040b6c1c5971199bb53f938b/build/rnpm.js#L205-L223 |
8,281 | instea/react-native-popup-menu | build/rnpm.js | iterator2array | function iterator2array(it) {
// workaround around https://github.com/instea/react-native-popup-menu/issues/41#issuecomment-340290127
var arr = [];
for (var next = it.next(); !next.done; next = it.next()) {
arr.push(next.value);
}
return arr;
} | javascript | function iterator2array(it) {
// workaround around https://github.com/instea/react-native-popup-menu/issues/41#issuecomment-340290127
var arr = [];
for (var next = it.next(); !next.done; next = it.next()) {
arr.push(next.value);
}
return arr;
} | [
"function",
"iterator2array",
"(",
"it",
")",
"{",
"// workaround around https://github.com/instea/react-native-popup-menu/issues/41#issuecomment-340290127",
"var",
"arr",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"next",
"=",
"it",
".",
"next",
"(",
")",
";",
"!",
"next",
".",
"done",
";",
"next",
"=",
"it",
".",
"next",
"(",
")",
")",
"{",
"arr",
".",
"push",
"(",
"next",
".",
"value",
")",
";",
"}",
"return",
"arr",
";",
"}"
] | Converts iterator to array | [
"Converts",
"iterator",
"to",
"array"
] | 46197a3a72a2031c040b6c1c5971199bb53f938b | https://github.com/instea/react-native-popup-menu/blob/46197a3a72a2031c040b6c1c5971199bb53f938b/build/rnpm.js#L228-L237 |
8,282 | instea/react-native-popup-menu | build/rnpm.js | deprecatedComponent | function deprecatedComponent(message) {
var methods = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
return function deprecatedComponentHOC(Component) {
var _temp;
return _temp =
/*#__PURE__*/
function (_React$Component) {
_inherits(DeprecatedComponent, _React$Component);
function DeprecatedComponent() {
var _getPrototypeOf2;
var _this;
_classCallCheck(this, DeprecatedComponent);
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(DeprecatedComponent)).call.apply(_getPrototypeOf2, [this].concat(args)));
_defineProperty(_assertThisInitialized(_this), "onRef", function (ref) {
return _this.ref = ref;
});
methods.forEach(function (name) {
// delegate methods to the component
_this[name] = function () {
var _this$ref;
return _this.ref && (_this$ref = _this.ref)[name].apply(_this$ref, arguments);
};
});
return _this;
}
_createClass(DeprecatedComponent, [{
key: "render",
value: function render() {
return React__default.createElement(Component, _extends({}, this.props, {
ref: this.onRef
}));
}
}, {
key: "componentDidMount",
value: function componentDidMount() {
console.warn(message);
}
}]);
return DeprecatedComponent;
}(React__default.Component), _temp;
};
} | javascript | function deprecatedComponent(message) {
var methods = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
return function deprecatedComponentHOC(Component) {
var _temp;
return _temp =
/*#__PURE__*/
function (_React$Component) {
_inherits(DeprecatedComponent, _React$Component);
function DeprecatedComponent() {
var _getPrototypeOf2;
var _this;
_classCallCheck(this, DeprecatedComponent);
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(DeprecatedComponent)).call.apply(_getPrototypeOf2, [this].concat(args)));
_defineProperty(_assertThisInitialized(_this), "onRef", function (ref) {
return _this.ref = ref;
});
methods.forEach(function (name) {
// delegate methods to the component
_this[name] = function () {
var _this$ref;
return _this.ref && (_this$ref = _this.ref)[name].apply(_this$ref, arguments);
};
});
return _this;
}
_createClass(DeprecatedComponent, [{
key: "render",
value: function render() {
return React__default.createElement(Component, _extends({}, this.props, {
ref: this.onRef
}));
}
}, {
key: "componentDidMount",
value: function componentDidMount() {
console.warn(message);
}
}]);
return DeprecatedComponent;
}(React__default.Component), _temp;
};
} | [
"function",
"deprecatedComponent",
"(",
"message",
")",
"{",
"var",
"methods",
"=",
"arguments",
".",
"length",
">",
"1",
"&&",
"arguments",
"[",
"1",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"1",
"]",
":",
"[",
"]",
";",
"return",
"function",
"deprecatedComponentHOC",
"(",
"Component",
")",
"{",
"var",
"_temp",
";",
"return",
"_temp",
"=",
"/*#__PURE__*/",
"function",
"(",
"_React$Component",
")",
"{",
"_inherits",
"(",
"DeprecatedComponent",
",",
"_React$Component",
")",
";",
"function",
"DeprecatedComponent",
"(",
")",
"{",
"var",
"_getPrototypeOf2",
";",
"var",
"_this",
";",
"_classCallCheck",
"(",
"this",
",",
"DeprecatedComponent",
")",
";",
"for",
"(",
"var",
"_len2",
"=",
"arguments",
".",
"length",
",",
"args",
"=",
"new",
"Array",
"(",
"_len2",
")",
",",
"_key2",
"=",
"0",
";",
"_key2",
"<",
"_len2",
";",
"_key2",
"++",
")",
"{",
"args",
"[",
"_key2",
"]",
"=",
"arguments",
"[",
"_key2",
"]",
";",
"}",
"_this",
"=",
"_possibleConstructorReturn",
"(",
"this",
",",
"(",
"_getPrototypeOf2",
"=",
"_getPrototypeOf",
"(",
"DeprecatedComponent",
")",
")",
".",
"call",
".",
"apply",
"(",
"_getPrototypeOf2",
",",
"[",
"this",
"]",
".",
"concat",
"(",
"args",
")",
")",
")",
";",
"_defineProperty",
"(",
"_assertThisInitialized",
"(",
"_this",
")",
",",
"\"onRef\"",
",",
"function",
"(",
"ref",
")",
"{",
"return",
"_this",
".",
"ref",
"=",
"ref",
";",
"}",
")",
";",
"methods",
".",
"forEach",
"(",
"function",
"(",
"name",
")",
"{",
"// delegate methods to the component",
"_this",
"[",
"name",
"]",
"=",
"function",
"(",
")",
"{",
"var",
"_this$ref",
";",
"return",
"_this",
".",
"ref",
"&&",
"(",
"_this$ref",
"=",
"_this",
".",
"ref",
")",
"[",
"name",
"]",
".",
"apply",
"(",
"_this$ref",
",",
"arguments",
")",
";",
"}",
";",
"}",
")",
";",
"return",
"_this",
";",
"}",
"_createClass",
"(",
"DeprecatedComponent",
",",
"[",
"{",
"key",
":",
"\"render\"",
",",
"value",
":",
"function",
"render",
"(",
")",
"{",
"return",
"React__default",
".",
"createElement",
"(",
"Component",
",",
"_extends",
"(",
"{",
"}",
",",
"this",
".",
"props",
",",
"{",
"ref",
":",
"this",
".",
"onRef",
"}",
")",
")",
";",
"}",
"}",
",",
"{",
"key",
":",
"\"componentDidMount\"",
",",
"value",
":",
"function",
"componentDidMount",
"(",
")",
"{",
"console",
".",
"warn",
"(",
"message",
")",
";",
"}",
"}",
"]",
")",
";",
"return",
"DeprecatedComponent",
";",
"}",
"(",
"React__default",
".",
"Component",
")",
",",
"_temp",
";",
"}",
";",
"}"
] | Higher order component to deprecate usage of component.
message - deprecate warning message
methods - array of method names to be delegated to deprecated component | [
"Higher",
"order",
"component",
"to",
"deprecate",
"usage",
"of",
"component",
".",
"message",
"-",
"deprecate",
"warning",
"message",
"methods",
"-",
"array",
"of",
"method",
"names",
"to",
"be",
"delegated",
"to",
"deprecated",
"component"
] | 46197a3a72a2031c040b6c1c5971199bb53f938b | https://github.com/instea/react-native-popup-menu/blob/46197a3a72a2031c040b6c1c5971199bb53f938b/build/rnpm.js#L244-L299 |
8,283 | instea/react-native-popup-menu | build/rnpm.js | isAsyncMode | function isAsyncMode(object) {
{
if (!hasWarnedAboutDeprecatedIsAsyncMode) {
hasWarnedAboutDeprecatedIsAsyncMode = true;
lowPriorityWarning$1(false, 'The ReactIs.isAsyncMode() alias has been deprecated, ' + 'and will be removed in React 17+. Update your code to use ' + 'ReactIs.isConcurrentMode() instead. It has the exact same API.');
}
}
return isConcurrentMode(object) || typeOf(object) === REACT_ASYNC_MODE_TYPE;
} | javascript | function isAsyncMode(object) {
{
if (!hasWarnedAboutDeprecatedIsAsyncMode) {
hasWarnedAboutDeprecatedIsAsyncMode = true;
lowPriorityWarning$1(false, 'The ReactIs.isAsyncMode() alias has been deprecated, ' + 'and will be removed in React 17+. Update your code to use ' + 'ReactIs.isConcurrentMode() instead. It has the exact same API.');
}
}
return isConcurrentMode(object) || typeOf(object) === REACT_ASYNC_MODE_TYPE;
} | [
"function",
"isAsyncMode",
"(",
"object",
")",
"{",
"{",
"if",
"(",
"!",
"hasWarnedAboutDeprecatedIsAsyncMode",
")",
"{",
"hasWarnedAboutDeprecatedIsAsyncMode",
"=",
"true",
";",
"lowPriorityWarning$1",
"(",
"false",
",",
"'The ReactIs.isAsyncMode() alias has been deprecated, '",
"+",
"'and will be removed in React 17+. Update your code to use '",
"+",
"'ReactIs.isConcurrentMode() instead. It has the exact same API.'",
")",
";",
"}",
"}",
"return",
"isConcurrentMode",
"(",
"object",
")",
"||",
"typeOf",
"(",
"object",
")",
"===",
"REACT_ASYNC_MODE_TYPE",
";",
"}"
] | AsyncMode should be deprecated | [
"AsyncMode",
"should",
"be",
"deprecated"
] | 46197a3a72a2031c040b6c1c5971199bb53f938b | https://github.com/instea/react-native-popup-menu/blob/46197a3a72a2031c040b6c1c5971199bb53f938b/build/rnpm.js#L450-L458 |
8,284 | instea/react-native-popup-menu | build/rnpm.js | makeMenuRegistry | function makeMenuRegistry() {
var menus = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Map();
/**
* Subscribes menu instance.
*/
function subscribe(instance) {
var name = instance.getName();
if (menus.get(name)) {
console.warn("incorrect usage of popup menu - menu with name ".concat(name, " already exists"));
}
menus.set(name, {
name: name,
instance: instance
});
}
/**
* Unsubscribes menu instance.
*/
function unsubscribe(instance) {
menus.delete(instance.getName());
}
/**
* Updates layout infomration.
*/
function updateLayoutInfo(name) {
var layouts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (!menus.has(name)) {
return;
}
var menu = Object.assign({}, menus.get(name));
if (layouts.hasOwnProperty('triggerLayout')) {
menu.triggerLayout = layouts.triggerLayout;
}
if (layouts.hasOwnProperty('optionsLayout')) {
menu.optionsLayout = layouts.optionsLayout;
}
menus.set(name, menu);
}
function setOptionsCustomStyles(name, optionsCustomStyles) {
if (!menus.has(name)) {
return;
}
var menu = _objectSpread({}, menus.get(name), {
optionsCustomStyles: optionsCustomStyles
});
menus.set(name, menu);
}
/**
* Get `menu data` by name.
*/
function getMenu(name) {
return menus.get(name);
}
/**
* Returns all subscribed menus as array of `menu data`
*/
function getAll() {
return iterator2array(menus.values());
}
return {
subscribe: subscribe,
unsubscribe: unsubscribe,
updateLayoutInfo: updateLayoutInfo,
getMenu: getMenu,
getAll: getAll,
setOptionsCustomStyles: setOptionsCustomStyles
};
} | javascript | function makeMenuRegistry() {
var menus = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Map();
/**
* Subscribes menu instance.
*/
function subscribe(instance) {
var name = instance.getName();
if (menus.get(name)) {
console.warn("incorrect usage of popup menu - menu with name ".concat(name, " already exists"));
}
menus.set(name, {
name: name,
instance: instance
});
}
/**
* Unsubscribes menu instance.
*/
function unsubscribe(instance) {
menus.delete(instance.getName());
}
/**
* Updates layout infomration.
*/
function updateLayoutInfo(name) {
var layouts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (!menus.has(name)) {
return;
}
var menu = Object.assign({}, menus.get(name));
if (layouts.hasOwnProperty('triggerLayout')) {
menu.triggerLayout = layouts.triggerLayout;
}
if (layouts.hasOwnProperty('optionsLayout')) {
menu.optionsLayout = layouts.optionsLayout;
}
menus.set(name, menu);
}
function setOptionsCustomStyles(name, optionsCustomStyles) {
if (!menus.has(name)) {
return;
}
var menu = _objectSpread({}, menus.get(name), {
optionsCustomStyles: optionsCustomStyles
});
menus.set(name, menu);
}
/**
* Get `menu data` by name.
*/
function getMenu(name) {
return menus.get(name);
}
/**
* Returns all subscribed menus as array of `menu data`
*/
function getAll() {
return iterator2array(menus.values());
}
return {
subscribe: subscribe,
unsubscribe: unsubscribe,
updateLayoutInfo: updateLayoutInfo,
getMenu: getMenu,
getAll: getAll,
setOptionsCustomStyles: setOptionsCustomStyles
};
} | [
"function",
"makeMenuRegistry",
"(",
")",
"{",
"var",
"menus",
"=",
"arguments",
".",
"length",
">",
"0",
"&&",
"arguments",
"[",
"0",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"0",
"]",
":",
"new",
"Map",
"(",
")",
";",
"/**\n * Subscribes menu instance.\n */",
"function",
"subscribe",
"(",
"instance",
")",
"{",
"var",
"name",
"=",
"instance",
".",
"getName",
"(",
")",
";",
"if",
"(",
"menus",
".",
"get",
"(",
"name",
")",
")",
"{",
"console",
".",
"warn",
"(",
"\"incorrect usage of popup menu - menu with name \"",
".",
"concat",
"(",
"name",
",",
"\" already exists\"",
")",
")",
";",
"}",
"menus",
".",
"set",
"(",
"name",
",",
"{",
"name",
":",
"name",
",",
"instance",
":",
"instance",
"}",
")",
";",
"}",
"/**\n * Unsubscribes menu instance.\n */",
"function",
"unsubscribe",
"(",
"instance",
")",
"{",
"menus",
".",
"delete",
"(",
"instance",
".",
"getName",
"(",
")",
")",
";",
"}",
"/**\n * Updates layout infomration.\n */",
"function",
"updateLayoutInfo",
"(",
"name",
")",
"{",
"var",
"layouts",
"=",
"arguments",
".",
"length",
">",
"1",
"&&",
"arguments",
"[",
"1",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"1",
"]",
":",
"{",
"}",
";",
"if",
"(",
"!",
"menus",
".",
"has",
"(",
"name",
")",
")",
"{",
"return",
";",
"}",
"var",
"menu",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"menus",
".",
"get",
"(",
"name",
")",
")",
";",
"if",
"(",
"layouts",
".",
"hasOwnProperty",
"(",
"'triggerLayout'",
")",
")",
"{",
"menu",
".",
"triggerLayout",
"=",
"layouts",
".",
"triggerLayout",
";",
"}",
"if",
"(",
"layouts",
".",
"hasOwnProperty",
"(",
"'optionsLayout'",
")",
")",
"{",
"menu",
".",
"optionsLayout",
"=",
"layouts",
".",
"optionsLayout",
";",
"}",
"menus",
".",
"set",
"(",
"name",
",",
"menu",
")",
";",
"}",
"function",
"setOptionsCustomStyles",
"(",
"name",
",",
"optionsCustomStyles",
")",
"{",
"if",
"(",
"!",
"menus",
".",
"has",
"(",
"name",
")",
")",
"{",
"return",
";",
"}",
"var",
"menu",
"=",
"_objectSpread",
"(",
"{",
"}",
",",
"menus",
".",
"get",
"(",
"name",
")",
",",
"{",
"optionsCustomStyles",
":",
"optionsCustomStyles",
"}",
")",
";",
"menus",
".",
"set",
"(",
"name",
",",
"menu",
")",
";",
"}",
"/**\n * Get `menu data` by name.\n */",
"function",
"getMenu",
"(",
"name",
")",
"{",
"return",
"menus",
".",
"get",
"(",
"name",
")",
";",
"}",
"/**\n * Returns all subscribed menus as array of `menu data`\n */",
"function",
"getAll",
"(",
")",
"{",
"return",
"iterator2array",
"(",
"menus",
".",
"values",
"(",
")",
")",
";",
"}",
"return",
"{",
"subscribe",
":",
"subscribe",
",",
"unsubscribe",
":",
"unsubscribe",
",",
"updateLayoutInfo",
":",
"updateLayoutInfo",
",",
"getMenu",
":",
"getMenu",
",",
"getAll",
":",
"getAll",
",",
"setOptionsCustomStyles",
":",
"setOptionsCustomStyles",
"}",
";",
"}"
] | Registry to subscribe, unsubscribe and update data of menus.
menu data: {
instance: react instance
triggerLayout: Object - layout of menu trigger if known
optionsLayout: Object - layout of menu options if known
optionsCustomStyles: Object - custom styles of options
} | [
"Registry",
"to",
"subscribe",
"unsubscribe",
"and",
"update",
"data",
"of",
"menus",
"."
] | 46197a3a72a2031c040b6c1c5971199bb53f938b | https://github.com/instea/react-native-popup-menu/blob/46197a3a72a2031c040b6c1c5971199bb53f938b/build/rnpm.js#L1415-L1502 |
8,285 | instea/react-native-popup-menu | build/rnpm.js | subscribe | function subscribe(instance) {
var name = instance.getName();
if (menus.get(name)) {
console.warn("incorrect usage of popup menu - menu with name ".concat(name, " already exists"));
}
menus.set(name, {
name: name,
instance: instance
});
} | javascript | function subscribe(instance) {
var name = instance.getName();
if (menus.get(name)) {
console.warn("incorrect usage of popup menu - menu with name ".concat(name, " already exists"));
}
menus.set(name, {
name: name,
instance: instance
});
} | [
"function",
"subscribe",
"(",
"instance",
")",
"{",
"var",
"name",
"=",
"instance",
".",
"getName",
"(",
")",
";",
"if",
"(",
"menus",
".",
"get",
"(",
"name",
")",
")",
"{",
"console",
".",
"warn",
"(",
"\"incorrect usage of popup menu - menu with name \"",
".",
"concat",
"(",
"name",
",",
"\" already exists\"",
")",
")",
";",
"}",
"menus",
".",
"set",
"(",
"name",
",",
"{",
"name",
":",
"name",
",",
"instance",
":",
"instance",
"}",
")",
";",
"}"
] | Subscribes menu instance. | [
"Subscribes",
"menu",
"instance",
"."
] | 46197a3a72a2031c040b6c1c5971199bb53f938b | https://github.com/instea/react-native-popup-menu/blob/46197a3a72a2031c040b6c1c5971199bb53f938b/build/rnpm.js#L1421-L1432 |
8,286 | instea/react-native-popup-menu | build/rnpm.js | updateLayoutInfo | function updateLayoutInfo(name) {
var layouts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (!menus.has(name)) {
return;
}
var menu = Object.assign({}, menus.get(name));
if (layouts.hasOwnProperty('triggerLayout')) {
menu.triggerLayout = layouts.triggerLayout;
}
if (layouts.hasOwnProperty('optionsLayout')) {
menu.optionsLayout = layouts.optionsLayout;
}
menus.set(name, menu);
} | javascript | function updateLayoutInfo(name) {
var layouts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (!menus.has(name)) {
return;
}
var menu = Object.assign({}, menus.get(name));
if (layouts.hasOwnProperty('triggerLayout')) {
menu.triggerLayout = layouts.triggerLayout;
}
if (layouts.hasOwnProperty('optionsLayout')) {
menu.optionsLayout = layouts.optionsLayout;
}
menus.set(name, menu);
} | [
"function",
"updateLayoutInfo",
"(",
"name",
")",
"{",
"var",
"layouts",
"=",
"arguments",
".",
"length",
">",
"1",
"&&",
"arguments",
"[",
"1",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"1",
"]",
":",
"{",
"}",
";",
"if",
"(",
"!",
"menus",
".",
"has",
"(",
"name",
")",
")",
"{",
"return",
";",
"}",
"var",
"menu",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"menus",
".",
"get",
"(",
"name",
")",
")",
";",
"if",
"(",
"layouts",
".",
"hasOwnProperty",
"(",
"'triggerLayout'",
")",
")",
"{",
"menu",
".",
"triggerLayout",
"=",
"layouts",
".",
"triggerLayout",
";",
"}",
"if",
"(",
"layouts",
".",
"hasOwnProperty",
"(",
"'optionsLayout'",
")",
")",
"{",
"menu",
".",
"optionsLayout",
"=",
"layouts",
".",
"optionsLayout",
";",
"}",
"menus",
".",
"set",
"(",
"name",
",",
"menu",
")",
";",
"}"
] | Updates layout infomration. | [
"Updates",
"layout",
"infomration",
"."
] | 46197a3a72a2031c040b6c1c5971199bb53f938b | https://github.com/instea/react-native-popup-menu/blob/46197a3a72a2031c040b6c1c5971199bb53f938b/build/rnpm.js#L1446-L1464 |
8,287 | elastic/apm-agent-rum-js | packages/rum-core/src/common/utils.js | setTag | function setTag(key, value, obj) {
if (!obj || !key) return
var skey = removeInvalidChars(key)
if (value) {
value = String(value)
}
obj[skey] = value
return obj
} | javascript | function setTag(key, value, obj) {
if (!obj || !key) return
var skey = removeInvalidChars(key)
if (value) {
value = String(value)
}
obj[skey] = value
return obj
} | [
"function",
"setTag",
"(",
"key",
",",
"value",
",",
"obj",
")",
"{",
"if",
"(",
"!",
"obj",
"||",
"!",
"key",
")",
"return",
"var",
"skey",
"=",
"removeInvalidChars",
"(",
"key",
")",
"if",
"(",
"value",
")",
"{",
"value",
"=",
"String",
"(",
"value",
")",
"}",
"obj",
"[",
"skey",
"]",
"=",
"value",
"return",
"obj",
"}"
] | Convert values of the tag to be string to be compatible
with the apm server prior to <6.7 version
TODO: Remove string conversion in the next major release since
support for boolean and number in the APM server has landed in 6.7
https://github.com/elastic/apm-server/pull/1712/ | [
"Convert",
"values",
"of",
"the",
"tag",
"to",
"be",
"string",
"to",
"be",
"compatible",
"with",
"the",
"apm",
"server",
"prior",
"to",
"<6",
".",
"7",
"version"
] | b877fa9e8ee8255e2f5d91e2d5dae61ff489fcd4 | https://github.com/elastic/apm-agent-rum-js/blob/b877fa9e8ee8255e2f5d91e2d5dae61ff489fcd4/packages/rum-core/src/common/utils.js#L145-L153 |
8,288 | mauron85/react-native-background-geolocation | index.js | function (successFn, errorFn) {
successFn = successFn || emptyFn;
errorFn = errorFn || emptyFn;
RNBackgroundGeolocation.getStationaryLocation(successFn, errorFn);
} | javascript | function (successFn, errorFn) {
successFn = successFn || emptyFn;
errorFn = errorFn || emptyFn;
RNBackgroundGeolocation.getStationaryLocation(successFn, errorFn);
} | [
"function",
"(",
"successFn",
",",
"errorFn",
")",
"{",
"successFn",
"=",
"successFn",
"||",
"emptyFn",
";",
"errorFn",
"=",
"errorFn",
"||",
"emptyFn",
";",
"RNBackgroundGeolocation",
".",
"getStationaryLocation",
"(",
"successFn",
",",
"errorFn",
")",
";",
"}"
] | Returns current stationaryLocation if available. null if not | [
"Returns",
"current",
"stationaryLocation",
"if",
"available",
".",
"null",
"if",
"not"
] | 6bdedbee827f698b91d81c2b8db91663e3260462 | https://github.com/mauron85/react-native-background-geolocation/blob/6bdedbee827f698b91d81c2b8db91663e3260462/index.js#L120-L124 |
|
8,289 | Shopify/theme-scripts | packages/theme-product/theme-product.js | _validateProductStructure | function _validateProductStructure(product) {
if (typeof product !== 'object') {
throw new TypeError(product + ' is not an object.');
}
if (Object.keys(product).length === 0 && product.constructor === Object) {
throw new Error(product + ' is empty.');
}
} | javascript | function _validateProductStructure(product) {
if (typeof product !== 'object') {
throw new TypeError(product + ' is not an object.');
}
if (Object.keys(product).length === 0 && product.constructor === Object) {
throw new Error(product + ' is empty.');
}
} | [
"function",
"_validateProductStructure",
"(",
"product",
")",
"{",
"if",
"(",
"typeof",
"product",
"!==",
"'object'",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"product",
"+",
"' is not an object.'",
")",
";",
"}",
"if",
"(",
"Object",
".",
"keys",
"(",
"product",
")",
".",
"length",
"===",
"0",
"&&",
"product",
".",
"constructor",
"===",
"Object",
")",
"{",
"throw",
"new",
"Error",
"(",
"product",
"+",
"' is empty.'",
")",
";",
"}",
"}"
] | Check if the product data is a valid JS object
Error will be thrown if type is invalid
@param {object} product Product JSON object | [
"Check",
"if",
"the",
"product",
"data",
"is",
"a",
"valid",
"JS",
"object",
"Error",
"will",
"be",
"thrown",
"if",
"type",
"is",
"invalid"
] | b2fb8f43db5f2115786051f3941207b65794c3d5 | https://github.com/Shopify/theme-scripts/blob/b2fb8f43db5f2115786051f3941207b65794c3d5/packages/theme-product/theme-product.js#L94-L102 |
8,290 | Shopify/theme-scripts | packages/theme-addresses/theme-addresses.js | buildOptions | function buildOptions (provinceNodeElement, provinces) {
var defaultValue = provinceNodeElement.getAttribute('data-default');
provinces.forEach(function (option) {
var optionElement = document.createElement('option');
optionElement.value = option[0];
optionElement.textContent = option[1];
provinceNodeElement.appendChild(optionElement);
})
if (defaultValue && getOption(provinceNodeElement, defaultValue)) {
provinceNodeElement.value = defaultValue;
}
} | javascript | function buildOptions (provinceNodeElement, provinces) {
var defaultValue = provinceNodeElement.getAttribute('data-default');
provinces.forEach(function (option) {
var optionElement = document.createElement('option');
optionElement.value = option[0];
optionElement.textContent = option[1];
provinceNodeElement.appendChild(optionElement);
})
if (defaultValue && getOption(provinceNodeElement, defaultValue)) {
provinceNodeElement.value = defaultValue;
}
} | [
"function",
"buildOptions",
"(",
"provinceNodeElement",
",",
"provinces",
")",
"{",
"var",
"defaultValue",
"=",
"provinceNodeElement",
".",
"getAttribute",
"(",
"'data-default'",
")",
";",
"provinces",
".",
"forEach",
"(",
"function",
"(",
"option",
")",
"{",
"var",
"optionElement",
"=",
"document",
".",
"createElement",
"(",
"'option'",
")",
";",
"optionElement",
".",
"value",
"=",
"option",
"[",
"0",
"]",
";",
"optionElement",
".",
"textContent",
"=",
"option",
"[",
"1",
"]",
";",
"provinceNodeElement",
".",
"appendChild",
"(",
"optionElement",
")",
";",
"}",
")",
"if",
"(",
"defaultValue",
"&&",
"getOption",
"(",
"provinceNodeElement",
",",
"defaultValue",
")",
")",
"{",
"provinceNodeElement",
".",
"value",
"=",
"defaultValue",
";",
"}",
"}"
] | Builds the options for province selector | [
"Builds",
"the",
"options",
"for",
"province",
"selector"
] | b2fb8f43db5f2115786051f3941207b65794c3d5 | https://github.com/Shopify/theme-scripts/blob/b2fb8f43db5f2115786051f3941207b65794c3d5/packages/theme-addresses/theme-addresses.js#L78-L92 |
8,291 | Shopify/theme-scripts | packages/theme-addresses/theme-addresses.js | buildProvince | function buildProvince (countryNodeElement, provinceNodeElement, selectedValue) {
var selectedOption = getOption(countryNodeElement, selectedValue);
var provinces = JSON.parse(selectedOption.getAttribute('data-provinces'));
provinceNodeElement.options.length = 0;
if (provinces.length) {
buildOptions(provinceNodeElement, provinces)
}
return provinces;
} | javascript | function buildProvince (countryNodeElement, provinceNodeElement, selectedValue) {
var selectedOption = getOption(countryNodeElement, selectedValue);
var provinces = JSON.parse(selectedOption.getAttribute('data-provinces'));
provinceNodeElement.options.length = 0;
if (provinces.length) {
buildOptions(provinceNodeElement, provinces)
}
return provinces;
} | [
"function",
"buildProvince",
"(",
"countryNodeElement",
",",
"provinceNodeElement",
",",
"selectedValue",
")",
"{",
"var",
"selectedOption",
"=",
"getOption",
"(",
"countryNodeElement",
",",
"selectedValue",
")",
";",
"var",
"provinces",
"=",
"JSON",
".",
"parse",
"(",
"selectedOption",
".",
"getAttribute",
"(",
"'data-provinces'",
")",
")",
";",
"provinceNodeElement",
".",
"options",
".",
"length",
"=",
"0",
";",
"if",
"(",
"provinces",
".",
"length",
")",
"{",
"buildOptions",
"(",
"provinceNodeElement",
",",
"provinces",
")",
"}",
"return",
"provinces",
";",
"}"
] | Builds the province selector | [
"Builds",
"the",
"province",
"selector"
] | b2fb8f43db5f2115786051f3941207b65794c3d5 | https://github.com/Shopify/theme-scripts/blob/b2fb8f43db5f2115786051f3941207b65794c3d5/packages/theme-addresses/theme-addresses.js#L97-L108 |
8,292 | jenkinsci/blueocean-plugin | blueocean-dashboard/src/main/js/creation/github/api/GithubApiUtils.js | appendApiUrlParam | function appendApiUrlParam(fullUrl, apiUrl) {
let appendedUrl = fullUrl;
if (typeof apiUrl === 'string') {
if (fullUrl.indexOf('?') === -1) {
appendedUrl += '?';
} else {
appendedUrl += '&';
}
appendedUrl += 'apiUrl=';
// trim trailing slash from URL
appendedUrl += apiUrl.slice(-1) === '/' ? apiUrl.slice(0, -1) : apiUrl;
}
return appendedUrl;
} | javascript | function appendApiUrlParam(fullUrl, apiUrl) {
let appendedUrl = fullUrl;
if (typeof apiUrl === 'string') {
if (fullUrl.indexOf('?') === -1) {
appendedUrl += '?';
} else {
appendedUrl += '&';
}
appendedUrl += 'apiUrl=';
// trim trailing slash from URL
appendedUrl += apiUrl.slice(-1) === '/' ? apiUrl.slice(0, -1) : apiUrl;
}
return appendedUrl;
} | [
"function",
"appendApiUrlParam",
"(",
"fullUrl",
",",
"apiUrl",
")",
"{",
"let",
"appendedUrl",
"=",
"fullUrl",
";",
"if",
"(",
"typeof",
"apiUrl",
"===",
"'string'",
")",
"{",
"if",
"(",
"fullUrl",
".",
"indexOf",
"(",
"'?'",
")",
"===",
"-",
"1",
")",
"{",
"appendedUrl",
"+=",
"'?'",
";",
"}",
"else",
"{",
"appendedUrl",
"+=",
"'&'",
";",
"}",
"appendedUrl",
"+=",
"'apiUrl='",
";",
"// trim trailing slash from URL",
"appendedUrl",
"+=",
"apiUrl",
".",
"slice",
"(",
"-",
"1",
")",
"===",
"'/'",
"?",
"apiUrl",
".",
"slice",
"(",
"0",
",",
"-",
"1",
")",
":",
"apiUrl",
";",
"}",
"return",
"appendedUrl",
";",
"}"
] | Append the GitHub "apiUrl" param onto the URL if necessary.
@param fullUrl
@param apiUrl
@returns {String} | [
"Append",
"the",
"GitHub",
"apiUrl",
"param",
"onto",
"the",
"URL",
"if",
"necessary",
"."
] | 6e87cc0e76449669a942d66a9391cd7a46a943e0 | https://github.com/jenkinsci/blueocean-plugin/blob/6e87cc0e76449669a942d66a9391cd7a46a943e0/blueocean-dashboard/src/main/js/creation/github/api/GithubApiUtils.js#L7-L23 |
8,293 | jenkinsci/blueocean-plugin | blueocean-dashboard/src/main/js/creation/github/api/GithubApiUtils.js | extractProtocolHost | function extractProtocolHost(url) {
const urlNoQuery = url.split('?')[0];
const [protocol, hostAndPath] = urlNoQuery.split('//');
const host = hostAndPath.split('/')[0];
return `${protocol}//${host}`;
} | javascript | function extractProtocolHost(url) {
const urlNoQuery = url.split('?')[0];
const [protocol, hostAndPath] = urlNoQuery.split('//');
const host = hostAndPath.split('/')[0];
return `${protocol}//${host}`;
} | [
"function",
"extractProtocolHost",
"(",
"url",
")",
"{",
"const",
"urlNoQuery",
"=",
"url",
".",
"split",
"(",
"'?'",
")",
"[",
"0",
"]",
";",
"const",
"[",
"protocol",
",",
"hostAndPath",
"]",
"=",
"urlNoQuery",
".",
"split",
"(",
"'//'",
")",
";",
"const",
"host",
"=",
"hostAndPath",
".",
"split",
"(",
"'/'",
")",
"[",
"0",
"]",
";",
"return",
"`",
"${",
"protocol",
"}",
"${",
"host",
"}",
"`",
";",
"}"
] | Extract the protocol and host from a URL.
Will not include the trailing slash.
@param url
@returns {string} | [
"Extract",
"the",
"protocol",
"and",
"host",
"from",
"a",
"URL",
".",
"Will",
"not",
"include",
"the",
"trailing",
"slash",
"."
] | 6e87cc0e76449669a942d66a9391cd7a46a943e0 | https://github.com/jenkinsci/blueocean-plugin/blob/6e87cc0e76449669a942d66a9391cd7a46a943e0/blueocean-dashboard/src/main/js/creation/github/api/GithubApiUtils.js#L32-L37 |
8,294 | jenkinsci/blueocean-plugin | blueocean-core-js/src/js/LoadingIndicator.js | setLoaderClass | function setLoaderClass(c, t) {
timeouts.push(
setTimeout(() => {
loadbar.classList.add(c);
}, t)
);
} | javascript | function setLoaderClass(c, t) {
timeouts.push(
setTimeout(() => {
loadbar.classList.add(c);
}, t)
);
} | [
"function",
"setLoaderClass",
"(",
"c",
",",
"t",
")",
"{",
"timeouts",
".",
"push",
"(",
"setTimeout",
"(",
"(",
")",
"=>",
"{",
"loadbar",
".",
"classList",
".",
"add",
"(",
"c",
")",
";",
"}",
",",
"t",
")",
")",
";",
"}"
] | Add a timeout to transition the loading animation differently | [
"Add",
"a",
"timeout",
"to",
"transition",
"the",
"loading",
"animation",
"differently"
] | 6e87cc0e76449669a942d66a9391cd7a46a943e0 | https://github.com/jenkinsci/blueocean-plugin/blob/6e87cc0e76449669a942d66a9391cd7a46a943e0/blueocean-core-js/src/js/LoadingIndicator.js#L26-L32 |
8,295 | jenkinsci/blueocean-plugin | js-extensions/@jenkins-cd/subs/extensions-bundle.js | findExtensionsYAMLFile | function findExtensionsYAMLFile() {
for (var i = 0; i < paths.srcPaths.length; i++) {
var srcPath = path.resolve(cwd, paths.srcPaths[i]);
var extFile = path.resolve(srcPath, 'jenkins-js-extension.yaml');
if (fs.existsSync(extFile)) {
return extFile;
}
}
return undefined;
} | javascript | function findExtensionsYAMLFile() {
for (var i = 0; i < paths.srcPaths.length; i++) {
var srcPath = path.resolve(cwd, paths.srcPaths[i]);
var extFile = path.resolve(srcPath, 'jenkins-js-extension.yaml');
if (fs.existsSync(extFile)) {
return extFile;
}
}
return undefined;
} | [
"function",
"findExtensionsYAMLFile",
"(",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"paths",
".",
"srcPaths",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"srcPath",
"=",
"path",
".",
"resolve",
"(",
"cwd",
",",
"paths",
".",
"srcPaths",
"[",
"i",
"]",
")",
";",
"var",
"extFile",
"=",
"path",
".",
"resolve",
"(",
"srcPath",
",",
"'jenkins-js-extension.yaml'",
")",
";",
"if",
"(",
"fs",
".",
"existsSync",
"(",
"extFile",
")",
")",
"{",
"return",
"extFile",
";",
"}",
"}",
"return",
"undefined",
";",
"}"
] | Find the jenkins-js-extension.yaml file in the src paths. | [
"Find",
"the",
"jenkins",
"-",
"js",
"-",
"extension",
".",
"yaml",
"file",
"in",
"the",
"src",
"paths",
"."
] | 6e87cc0e76449669a942d66a9391cd7a46a943e0 | https://github.com/jenkinsci/blueocean-plugin/blob/6e87cc0e76449669a942d66a9391cd7a46a943e0/js-extensions/@jenkins-cd/subs/extensions-bundle.js#L90-L100 |
8,296 | jenkinsci/blueocean-plugin | bin/pretty.js | loadSource | function loadSource(sourcePath) {
return new Promise((fulfil, reject) => {
fs.readFile(sourcePath, 'utf8', (err, data) => {
if (err) {
reject(err);
} else {
fulfil(data);
}
});
});
} | javascript | function loadSource(sourcePath) {
return new Promise((fulfil, reject) => {
fs.readFile(sourcePath, 'utf8', (err, data) => {
if (err) {
reject(err);
} else {
fulfil(data);
}
});
});
} | [
"function",
"loadSource",
"(",
"sourcePath",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"fulfil",
",",
"reject",
")",
"=>",
"{",
"fs",
".",
"readFile",
"(",
"sourcePath",
",",
"'utf8'",
",",
"(",
"err",
",",
"data",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"reject",
"(",
"err",
")",
";",
"}",
"else",
"{",
"fulfil",
"(",
"data",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}"
] | Load w promise | [
"Load",
"w",
"promise"
] | 6e87cc0e76449669a942d66a9391cd7a46a943e0 | https://github.com/jenkinsci/blueocean-plugin/blob/6e87cc0e76449669a942d66a9391cd7a46a943e0/bin/pretty.js#L87-L97 |
8,297 | jenkinsci/blueocean-plugin | bin/pretty.js | saveSource | function saveSource(sourcePath, data) {
return new Promise((fulfil, reject) => {
fs.writeFile(sourcePath, data, 'utf8', err => {
if (err) {
reject(err);
} else {
fulfil(true);
}
});
});
} | javascript | function saveSource(sourcePath, data) {
return new Promise((fulfil, reject) => {
fs.writeFile(sourcePath, data, 'utf8', err => {
if (err) {
reject(err);
} else {
fulfil(true);
}
});
});
} | [
"function",
"saveSource",
"(",
"sourcePath",
",",
"data",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"fulfil",
",",
"reject",
")",
"=>",
"{",
"fs",
".",
"writeFile",
"(",
"sourcePath",
",",
"data",
",",
"'utf8'",
",",
"err",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"reject",
"(",
"err",
")",
";",
"}",
"else",
"{",
"fulfil",
"(",
"true",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}"
] | Save w promise | [
"Save",
"w",
"promise"
] | 6e87cc0e76449669a942d66a9391cd7a46a943e0 | https://github.com/jenkinsci/blueocean-plugin/blob/6e87cc0e76449669a942d66a9391cd7a46a943e0/bin/pretty.js#L100-L110 |
8,298 | jenkinsci/blueocean-plugin | bin/pretty.js | getSourceFilesFromGlob | function getSourceFilesFromGlob(globPattern, ignoreGlobs) {
return new Promise((fulfil, reject) => {
glob(globPattern, { ignore: ignoreGlobs }, (err, files) => {
if (err) {
reject(err);
} else {
fulfil(files);
}
});
});
} | javascript | function getSourceFilesFromGlob(globPattern, ignoreGlobs) {
return new Promise((fulfil, reject) => {
glob(globPattern, { ignore: ignoreGlobs }, (err, files) => {
if (err) {
reject(err);
} else {
fulfil(files);
}
});
});
} | [
"function",
"getSourceFilesFromGlob",
"(",
"globPattern",
",",
"ignoreGlobs",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"fulfil",
",",
"reject",
")",
"=>",
"{",
"glob",
"(",
"globPattern",
",",
"{",
"ignore",
":",
"ignoreGlobs",
"}",
",",
"(",
"err",
",",
"files",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"reject",
"(",
"err",
")",
";",
"}",
"else",
"{",
"fulfil",
"(",
"files",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}"
] | Calls out to glob, but returns a promise | [
"Calls",
"out",
"to",
"glob",
"but",
"returns",
"a",
"promise"
] | 6e87cc0e76449669a942d66a9391cd7a46a943e0 | https://github.com/jenkinsci/blueocean-plugin/blob/6e87cc0e76449669a942d66a9391cd7a46a943e0/bin/pretty.js#L113-L123 |
8,299 | jenkinsci/blueocean-plugin | bin/pretty.js | filterFiles | function filterFiles(files, validExtensions) {
const accepted = [];
for (const fileName of files) {
if (accepted.indexOf(fileName) === -1 && fileMatchesExtension(fileName, validExtensions)) {
accepted.push(fileName);
}
}
return accepted;
} | javascript | function filterFiles(files, validExtensions) {
const accepted = [];
for (const fileName of files) {
if (accepted.indexOf(fileName) === -1 && fileMatchesExtension(fileName, validExtensions)) {
accepted.push(fileName);
}
}
return accepted;
} | [
"function",
"filterFiles",
"(",
"files",
",",
"validExtensions",
")",
"{",
"const",
"accepted",
"=",
"[",
"]",
";",
"for",
"(",
"const",
"fileName",
"of",
"files",
")",
"{",
"if",
"(",
"accepted",
".",
"indexOf",
"(",
"fileName",
")",
"===",
"-",
"1",
"&&",
"fileMatchesExtension",
"(",
"fileName",
",",
"validExtensions",
")",
")",
"{",
"accepted",
".",
"push",
"(",
"fileName",
")",
";",
"}",
"}",
"return",
"accepted",
";",
"}"
] | Make sure we only use valid extensions, and each fileName appears only once | [
"Make",
"sure",
"we",
"only",
"use",
"valid",
"extensions",
"and",
"each",
"fileName",
"appears",
"only",
"once"
] | 6e87cc0e76449669a942d66a9391cd7a46a943e0 | https://github.com/jenkinsci/blueocean-plugin/blob/6e87cc0e76449669a942d66a9391cd7a46a943e0/bin/pretty.js#L126-L136 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.