id int32 0 58k | repo stringlengths 5 67 | path stringlengths 4 116 | func_name stringlengths 0 58 | original_string stringlengths 52 373k | language stringclasses 1 value | code stringlengths 52 373k | code_tokens list | docstring stringlengths 4 11.8k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 86 226 |
|---|---|---|---|---|---|---|---|---|---|---|---|
26,200 | gonzalocasas/node-proxy-middleware | index.js | merge | function merge(src1, src2) {
var merged = {};
extend(merged, src1);
extend(merged, src2);
return merged;
} | javascript | function merge(src1, src2) {
var merged = {};
extend(merged, src1);
extend(merged, src2);
return merged;
} | [
"function",
"merge",
"(",
"src1",
",",
"src2",
")",
"{",
"var",
"merged",
"=",
"{",
"}",
";",
"extend",
"(",
"merged",
",",
"src1",
")",
";",
"extend",
"(",
"merged",
",",
"src2",
")",
";",
"return",
"merged",
";",
"}"
] | merges data without changing state in either argument | [
"merges",
"data",
"without",
"changing",
"state",
"in",
"either",
"argument"
] | d3f462e23d4dda4483fac601649bec33735548f1 | https://github.com/gonzalocasas/node-proxy-middleware/blob/d3f462e23d4dda4483fac601649bec33735548f1/index.js#L136-L141 |
26,201 | MikeRalphson/bbcparse | iblApi/ibl.js | getChannelsSchedule | function getChannelsSchedule(channel,date){
var p = '/ibl/v1/channels/{channel}/schedule/{date}';
p = p.replace('{channel}',channel);
p = p.replace('{date}',date);
return p;
} | javascript | function getChannelsSchedule(channel,date){
var p = '/ibl/v1/channels/{channel}/schedule/{date}';
p = p.replace('{channel}',channel);
p = p.replace('{date}',date);
return p;
} | [
"function",
"getChannelsSchedule",
"(",
"channel",
",",
"date",
")",
"{",
"var",
"p",
"=",
"'/ibl/v1/channels/{channel}/schedule/{date}'",
";",
"p",
"=",
"p",
".",
"replace",
"(",
"'{channel}'",
",",
"channel",
")",
";",
"p",
"=",
"p",
".",
"replace",
"(",
"'{date}'",
",",
"date",
")",
";",
"return",
"p",
";",
"}"
] | Get schedule by channel
@param {string} channel The channel identifier to limit results to.
@param {string} date The date to return the schedule for, yyyy-mm-dd format
@return {string} The path to request | [
"Get",
"schedule",
"by",
"channel"
] | 785e0c2807c2d189c9c8779f7ac3f9b6f603bb57 | https://github.com/MikeRalphson/bbcparse/blob/785e0c2807c2d189c9c8779f7ac3f9b6f603bb57/iblApi/ibl.js#L134-L139 |
26,202 | canjs/can-connect | helpers/validate.js | BehaviorInterfaceError | function BehaviorInterfaceError(baseBehavior, extendingBehavior, missingProps) {
var extendingName = extendingBehavior.behaviorName || 'anonymous behavior',
baseName = baseBehavior.__behaviorName || 'anonymous behavior',
message = 'can-connect: Extending behavior "' + extendingName + '" found base behavior "' + baseName
+ '" was missing required properties: ' + JSON.stringify(missingProps.related),
instance = new Error(message);
if (Object.setPrototypeOf){
Object.setPrototypeOf(instance, Object.getPrototypeOf(this));
}
return instance;
} | javascript | function BehaviorInterfaceError(baseBehavior, extendingBehavior, missingProps) {
var extendingName = extendingBehavior.behaviorName || 'anonymous behavior',
baseName = baseBehavior.__behaviorName || 'anonymous behavior',
message = 'can-connect: Extending behavior "' + extendingName + '" found base behavior "' + baseName
+ '" was missing required properties: ' + JSON.stringify(missingProps.related),
instance = new Error(message);
if (Object.setPrototypeOf){
Object.setPrototypeOf(instance, Object.getPrototypeOf(this));
}
return instance;
} | [
"function",
"BehaviorInterfaceError",
"(",
"baseBehavior",
",",
"extendingBehavior",
",",
"missingProps",
")",
"{",
"var",
"extendingName",
"=",
"extendingBehavior",
".",
"behaviorName",
"||",
"'anonymous behavior'",
",",
"baseName",
"=",
"baseBehavior",
".",
"__behaviorName",
"||",
"'anonymous behavior'",
",",
"message",
"=",
"'can-connect: Extending behavior \"'",
"+",
"extendingName",
"+",
"'\" found base behavior \"'",
"+",
"baseName",
"+",
"'\" was missing required properties: '",
"+",
"JSON",
".",
"stringify",
"(",
"missingProps",
".",
"related",
")",
",",
"instance",
"=",
"new",
"Error",
"(",
"message",
")",
";",
"if",
"(",
"Object",
".",
"setPrototypeOf",
")",
"{",
"Object",
".",
"setPrototypeOf",
"(",
"instance",
",",
"Object",
".",
"getPrototypeOf",
"(",
"this",
")",
")",
";",
"}",
"return",
"instance",
";",
"}"
] | change to 'BehaviourInterfaceError extends Error' once we drop support for pre-ES2015 | [
"change",
"to",
"BehaviourInterfaceError",
"extends",
"Error",
"once",
"we",
"drop",
"support",
"for",
"pre",
"-",
"ES2015"
] | 513064178e1b229349cc219949aa69380c871a52 | https://github.com/canjs/can-connect/blob/513064178e1b229349cc219949aa69380c871a52/helpers/validate.js#L35-L46 |
26,203 | silklabs/silk | docs/examples/hid/hid.js | enableHID | async function enableHID() {
const usbConfig = getstrprop('sys.usb.state');
if (!usbConfig.startsWith('hid,')) {
log.warn('HID function does not seem to be enabled.');
const usbConfigWithHid = `hid,${usbConfig}`;
log.info(`changing USB config to ${usbConfigWithHid}`);
// WARNING! If this device is not Kenzo or this otherwise fails, it's likely
// that adb access will be lost until the next reboot
setprop('sys.usb.config', usbConfigWithHid);
// Wait for USB to be reconfigured.
await sleep(1000);
const newUsbConfig = getstrprop('sys.usb.state');
if (newUsbConfig !== usbConfigWithHid) {
throw new Error(`USB config expected to be ${usbConfigWithHid}, but it was ${newUsbConfig}`);
}
}
// Ensure the two HID devices are present
Promise.all(
['/dev/hidg0', '/dev/hidg1'].map(
file => fs.access(file, fs.constants.R_OK | fs.constants.W_OK)
)
);
} | javascript | async function enableHID() {
const usbConfig = getstrprop('sys.usb.state');
if (!usbConfig.startsWith('hid,')) {
log.warn('HID function does not seem to be enabled.');
const usbConfigWithHid = `hid,${usbConfig}`;
log.info(`changing USB config to ${usbConfigWithHid}`);
// WARNING! If this device is not Kenzo or this otherwise fails, it's likely
// that adb access will be lost until the next reboot
setprop('sys.usb.config', usbConfigWithHid);
// Wait for USB to be reconfigured.
await sleep(1000);
const newUsbConfig = getstrprop('sys.usb.state');
if (newUsbConfig !== usbConfigWithHid) {
throw new Error(`USB config expected to be ${usbConfigWithHid}, but it was ${newUsbConfig}`);
}
}
// Ensure the two HID devices are present
Promise.all(
['/dev/hidg0', '/dev/hidg1'].map(
file => fs.access(file, fs.constants.R_OK | fs.constants.W_OK)
)
);
} | [
"async",
"function",
"enableHID",
"(",
")",
"{",
"const",
"usbConfig",
"=",
"getstrprop",
"(",
"'sys.usb.state'",
")",
";",
"if",
"(",
"!",
"usbConfig",
".",
"startsWith",
"(",
"'hid,'",
")",
")",
"{",
"log",
".",
"warn",
"(",
"'HID function does not seem to be enabled.'",
")",
";",
"const",
"usbConfigWithHid",
"=",
"`",
"${",
"usbConfig",
"}",
"`",
";",
"log",
".",
"info",
"(",
"`",
"${",
"usbConfigWithHid",
"}",
"`",
")",
";",
"// WARNING! If this device is not Kenzo or this otherwise fails, it's likely",
"// that adb access will be lost until the next reboot",
"setprop",
"(",
"'sys.usb.config'",
",",
"usbConfigWithHid",
")",
";",
"// Wait for USB to be reconfigured.",
"await",
"sleep",
"(",
"1000",
")",
";",
"const",
"newUsbConfig",
"=",
"getstrprop",
"(",
"'sys.usb.state'",
")",
";",
"if",
"(",
"newUsbConfig",
"!==",
"usbConfigWithHid",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"usbConfigWithHid",
"}",
"${",
"newUsbConfig",
"}",
"`",
")",
";",
"}",
"}",
"// Ensure the two HID devices are present",
"Promise",
".",
"all",
"(",
"[",
"'/dev/hidg0'",
",",
"'/dev/hidg1'",
"]",
".",
"map",
"(",
"file",
"=>",
"fs",
".",
"access",
"(",
"file",
",",
"fs",
".",
"constants",
".",
"R_OK",
"|",
"fs",
".",
"constants",
".",
"W_OK",
")",
")",
")",
";",
"}"
] | Ensures the HID function in the USB Android gadget driver is active | [
"Ensures",
"the",
"HID",
"function",
"in",
"the",
"USB",
"Android",
"gadget",
"driver",
"is",
"active"
] | 08c273949086350aeddd8e23e92f0f79243f446f | https://github.com/silklabs/silk/blob/08c273949086350aeddd8e23e92f0f79243f446f/docs/examples/hid/hid.js#L14-L40 |
26,204 | silklabs/silk | sdk/src/cli.js | ensureSetup | function ensureSetup(argv) {
const root = findPackageRoot();
const emulatorBin = path.join(root, 'node_modules/silk-sdk-emulator/vendor/bin');
// Additional paths to search for outside of PATH.
const additionalPaths = [];
if (fs.existsSync(emulatorBin)) {
additionalPaths.push(emulatorBin);
}
argv.arguments = argv.arguments || [];
argv.arguments = [
[['--device', '-d'], {
help: 'Specific device to operate under.',
}],
...argv.arguments,
];
const main = argv.main;
argv.main = function (args) {
const {device} = args;
const api = new SDKApi({
device: device,
additionalPaths: additionalPaths,
});
return main(api, args);
};
return argv;
} | javascript | function ensureSetup(argv) {
const root = findPackageRoot();
const emulatorBin = path.join(root, 'node_modules/silk-sdk-emulator/vendor/bin');
// Additional paths to search for outside of PATH.
const additionalPaths = [];
if (fs.existsSync(emulatorBin)) {
additionalPaths.push(emulatorBin);
}
argv.arguments = argv.arguments || [];
argv.arguments = [
[['--device', '-d'], {
help: 'Specific device to operate under.',
}],
...argv.arguments,
];
const main = argv.main;
argv.main = function (args) {
const {device} = args;
const api = new SDKApi({
device: device,
additionalPaths: additionalPaths,
});
return main(api, args);
};
return argv;
} | [
"function",
"ensureSetup",
"(",
"argv",
")",
"{",
"const",
"root",
"=",
"findPackageRoot",
"(",
")",
";",
"const",
"emulatorBin",
"=",
"path",
".",
"join",
"(",
"root",
",",
"'node_modules/silk-sdk-emulator/vendor/bin'",
")",
";",
"// Additional paths to search for outside of PATH.",
"const",
"additionalPaths",
"=",
"[",
"]",
";",
"if",
"(",
"fs",
".",
"existsSync",
"(",
"emulatorBin",
")",
")",
"{",
"additionalPaths",
".",
"push",
"(",
"emulatorBin",
")",
";",
"}",
"argv",
".",
"arguments",
"=",
"argv",
".",
"arguments",
"||",
"[",
"]",
";",
"argv",
".",
"arguments",
"=",
"[",
"[",
"[",
"'--device'",
",",
"'-d'",
"]",
",",
"{",
"help",
":",
"'Specific device to operate under.'",
",",
"}",
"]",
",",
"...",
"argv",
".",
"arguments",
",",
"]",
";",
"const",
"main",
"=",
"argv",
".",
"main",
";",
"argv",
".",
"main",
"=",
"function",
"(",
"args",
")",
"{",
"const",
"{",
"device",
"}",
"=",
"args",
";",
"const",
"api",
"=",
"new",
"SDKApi",
"(",
"{",
"device",
":",
"device",
",",
"additionalPaths",
":",
"additionalPaths",
",",
"}",
")",
";",
"return",
"main",
"(",
"api",
",",
"args",
")",
";",
"}",
";",
"return",
"argv",
";",
"}"
] | This function is run from every cli call to ensure the enviornment is
correctly setup. | [
"This",
"function",
"is",
"run",
"from",
"every",
"cli",
"call",
"to",
"ensure",
"the",
"enviornment",
"is",
"correctly",
"setup",
"."
] | 08c273949086350aeddd8e23e92f0f79243f446f | https://github.com/silklabs/silk/blob/08c273949086350aeddd8e23e92f0f79243f446f/sdk/src/cli.js#L84-L115 |
26,205 | mdasberg/grunt-karma-sonar | install.js | fetchCdnVersion | function fetchCdnVersion(cdnUrl) {
var fullUrl = cdnUrl + path.sep + SONAR_RUNNER_DIST;
console.log('Fetching sonar-runner from CDN url [' + fullUrl + '].');
try {
var response = request('GET', fullUrl);
if(response.statusCode === 200) {
var destination = path.join('.tmp', SONAR_RUNNER_DIST);
fs.mkdirsSync('.tmp', '0775');
fs.writeFileSync(destination, response.getBody(), {replace: true});
return destination;
} else if(response.statusCode === 404) {
console.error('Could not find '+ SONAR_RUNNER_DIST + ' on the specified CDN url[' + fullUrl +'].');
} else {
console.error('Something went wrong while fetching '+ SONAR_RUNNER_DIST + ' on the specified CDN url[' + fullUrl +'], statusCode [' + response.statusCode + '] was received.');
}
} catch (e) {
console.error('Could not connect to CDN url[' + cdnUrl +'], received message [' + e + ']');
}
} | javascript | function fetchCdnVersion(cdnUrl) {
var fullUrl = cdnUrl + path.sep + SONAR_RUNNER_DIST;
console.log('Fetching sonar-runner from CDN url [' + fullUrl + '].');
try {
var response = request('GET', fullUrl);
if(response.statusCode === 200) {
var destination = path.join('.tmp', SONAR_RUNNER_DIST);
fs.mkdirsSync('.tmp', '0775');
fs.writeFileSync(destination, response.getBody(), {replace: true});
return destination;
} else if(response.statusCode === 404) {
console.error('Could not find '+ SONAR_RUNNER_DIST + ' on the specified CDN url[' + fullUrl +'].');
} else {
console.error('Something went wrong while fetching '+ SONAR_RUNNER_DIST + ' on the specified CDN url[' + fullUrl +'], statusCode [' + response.statusCode + '] was received.');
}
} catch (e) {
console.error('Could not connect to CDN url[' + cdnUrl +'], received message [' + e + ']');
}
} | [
"function",
"fetchCdnVersion",
"(",
"cdnUrl",
")",
"{",
"var",
"fullUrl",
"=",
"cdnUrl",
"+",
"path",
".",
"sep",
"+",
"SONAR_RUNNER_DIST",
";",
"console",
".",
"log",
"(",
"'Fetching sonar-runner from CDN url ['",
"+",
"fullUrl",
"+",
"'].'",
")",
";",
"try",
"{",
"var",
"response",
"=",
"request",
"(",
"'GET'",
",",
"fullUrl",
")",
";",
"if",
"(",
"response",
".",
"statusCode",
"===",
"200",
")",
"{",
"var",
"destination",
"=",
"path",
".",
"join",
"(",
"'.tmp'",
",",
"SONAR_RUNNER_DIST",
")",
";",
"fs",
".",
"mkdirsSync",
"(",
"'.tmp'",
",",
"'0775'",
")",
";",
"fs",
".",
"writeFileSync",
"(",
"destination",
",",
"response",
".",
"getBody",
"(",
")",
",",
"{",
"replace",
":",
"true",
"}",
")",
";",
"return",
"destination",
";",
"}",
"else",
"if",
"(",
"response",
".",
"statusCode",
"===",
"404",
")",
"{",
"console",
".",
"error",
"(",
"'Could not find '",
"+",
"SONAR_RUNNER_DIST",
"+",
"' on the specified CDN url['",
"+",
"fullUrl",
"+",
"'].'",
")",
";",
"}",
"else",
"{",
"console",
".",
"error",
"(",
"'Something went wrong while fetching '",
"+",
"SONAR_RUNNER_DIST",
"+",
"' on the specified CDN url['",
"+",
"fullUrl",
"+",
"'], statusCode ['",
"+",
"response",
".",
"statusCode",
"+",
"'] was received.'",
")",
";",
"}",
"}",
"catch",
"(",
"e",
")",
"{",
"console",
".",
"error",
"(",
"'Could not connect to CDN url['",
"+",
"cdnUrl",
"+",
"'], received message ['",
"+",
"e",
"+",
"']'",
")",
";",
"}",
"}"
] | Fetch the cdn release of sonar-runner from nexus.
@param cdnDir The cdn url.
@return destination The location where the cdn sonar-runner is copied to. | [
"Fetch",
"the",
"cdn",
"release",
"of",
"sonar",
"-",
"runner",
"from",
"nexus",
"."
] | 6b632d3cfdda05eee37165ea87531f1171a10117 | https://github.com/mdasberg/grunt-karma-sonar/blob/6b632d3cfdda05eee37165ea87531f1171a10117/install.js#L119-L137 |
26,206 | mdasberg/grunt-karma-sonar | tasks/sonar.js | copyFiles | function copyFiles(g, defaultOutputDir, targetDir) {
var files = glob.sync(g.src.toString(), {cwd: g.cwd, root: '/'});
files.forEach(function (file) {
var destinationDirectory = defaultOutputDir + path.sep + targetDir;
var fileDirectory = path.dirname(file);
if (fileDirectory !== '.') {
destinationDirectory = destinationDirectory + path.sep + fileDirectory;
}
fs.mkdirpSync(destinationDirectory);
var source = path.resolve(g.cwd, file);
var extension = path.extname(file);
var destination;
if (targetDir === 'test') {
var base = path.basename(file, extension);
if (extension === '.js') {
destination = destinationDirectory + path.sep + path.basename(base.replace(/\./g, '_') + extension);
} else if (extension === '.feature') {
destination = destinationDirectory + path.sep + path.basename(base.concat(extension).replace(/\./g, '_') + '.js');
}
} else {
destination = destinationDirectory + path.sep + path.basename(file);
}
fs.copySync(source, destination, {replace: true});
});
} | javascript | function copyFiles(g, defaultOutputDir, targetDir) {
var files = glob.sync(g.src.toString(), {cwd: g.cwd, root: '/'});
files.forEach(function (file) {
var destinationDirectory = defaultOutputDir + path.sep + targetDir;
var fileDirectory = path.dirname(file);
if (fileDirectory !== '.') {
destinationDirectory = destinationDirectory + path.sep + fileDirectory;
}
fs.mkdirpSync(destinationDirectory);
var source = path.resolve(g.cwd, file);
var extension = path.extname(file);
var destination;
if (targetDir === 'test') {
var base = path.basename(file, extension);
if (extension === '.js') {
destination = destinationDirectory + path.sep + path.basename(base.replace(/\./g, '_') + extension);
} else if (extension === '.feature') {
destination = destinationDirectory + path.sep + path.basename(base.concat(extension).replace(/\./g, '_') + '.js');
}
} else {
destination = destinationDirectory + path.sep + path.basename(file);
}
fs.copySync(source, destination, {replace: true});
});
} | [
"function",
"copyFiles",
"(",
"g",
",",
"defaultOutputDir",
",",
"targetDir",
")",
"{",
"var",
"files",
"=",
"glob",
".",
"sync",
"(",
"g",
".",
"src",
".",
"toString",
"(",
")",
",",
"{",
"cwd",
":",
"g",
".",
"cwd",
",",
"root",
":",
"'/'",
"}",
")",
";",
"files",
".",
"forEach",
"(",
"function",
"(",
"file",
")",
"{",
"var",
"destinationDirectory",
"=",
"defaultOutputDir",
"+",
"path",
".",
"sep",
"+",
"targetDir",
";",
"var",
"fileDirectory",
"=",
"path",
".",
"dirname",
"(",
"file",
")",
";",
"if",
"(",
"fileDirectory",
"!==",
"'.'",
")",
"{",
"destinationDirectory",
"=",
"destinationDirectory",
"+",
"path",
".",
"sep",
"+",
"fileDirectory",
";",
"}",
"fs",
".",
"mkdirpSync",
"(",
"destinationDirectory",
")",
";",
"var",
"source",
"=",
"path",
".",
"resolve",
"(",
"g",
".",
"cwd",
",",
"file",
")",
";",
"var",
"extension",
"=",
"path",
".",
"extname",
"(",
"file",
")",
";",
"var",
"destination",
";",
"if",
"(",
"targetDir",
"===",
"'test'",
")",
"{",
"var",
"base",
"=",
"path",
".",
"basename",
"(",
"file",
",",
"extension",
")",
";",
"if",
"(",
"extension",
"===",
"'.js'",
")",
"{",
"destination",
"=",
"destinationDirectory",
"+",
"path",
".",
"sep",
"+",
"path",
".",
"basename",
"(",
"base",
".",
"replace",
"(",
"/",
"\\.",
"/",
"g",
",",
"'_'",
")",
"+",
"extension",
")",
";",
"}",
"else",
"if",
"(",
"extension",
"===",
"'.feature'",
")",
"{",
"destination",
"=",
"destinationDirectory",
"+",
"path",
".",
"sep",
"+",
"path",
".",
"basename",
"(",
"base",
".",
"concat",
"(",
"extension",
")",
".",
"replace",
"(",
"/",
"\\.",
"/",
"g",
",",
"'_'",
")",
"+",
"'.js'",
")",
";",
"}",
"}",
"else",
"{",
"destination",
"=",
"destinationDirectory",
"+",
"path",
".",
"sep",
"+",
"path",
".",
"basename",
"(",
"file",
")",
";",
"}",
"fs",
".",
"copySync",
"(",
"source",
",",
"destination",
",",
"{",
"replace",
":",
"true",
"}",
")",
";",
"}",
")",
";",
"}"
] | Copy files to the temp directory.
@param g The glob. | [
"Copy",
"files",
"to",
"the",
"temp",
"directory",
"."
] | 6b632d3cfdda05eee37165ea87531f1171a10117 | https://github.com/mdasberg/grunt-karma-sonar/blob/6b632d3cfdda05eee37165ea87531f1171a10117/tasks/sonar.js#L27-L52 |
26,207 | mdasberg/grunt-karma-sonar | tasks/sonar.js | mergeJson | function mergeJson(original, override) {
return _.merge(original, override, function (a, b, key, aParent, bParent) {
if (_.isUndefined(b)) {
aParent[key] = undefined;
return;
}
});
} | javascript | function mergeJson(original, override) {
return _.merge(original, override, function (a, b, key, aParent, bParent) {
if (_.isUndefined(b)) {
aParent[key] = undefined;
return;
}
});
} | [
"function",
"mergeJson",
"(",
"original",
",",
"override",
")",
"{",
"return",
"_",
".",
"merge",
"(",
"original",
",",
"override",
",",
"function",
"(",
"a",
",",
"b",
",",
"key",
",",
"aParent",
",",
"bParent",
")",
"{",
"if",
"(",
"_",
".",
"isUndefined",
"(",
"b",
")",
")",
"{",
"aParent",
"[",
"key",
"]",
"=",
"undefined",
";",
"return",
";",
"}",
"}",
")",
";",
"}"
] | Deep merge json objects.
@param original The original object.
@param override The override object.
@return merged The merged object. | [
"Deep",
"merge",
"json",
"objects",
"."
] | 6b632d3cfdda05eee37165ea87531f1171a10117 | https://github.com/mdasberg/grunt-karma-sonar/blob/6b632d3cfdda05eee37165ea87531f1171a10117/tasks/sonar.js#L60-L67 |
26,208 | mdasberg/grunt-karma-sonar | tasks/sonar.js | buildArgs | function buildArgs(sonarOptions, data) {
// Default arguments
var args = [
'-Dsonar.sources=src',
'-Dsonar.tests=test',
'-Dsonar.javascript.jstestdriver.reportsPath=results',
'-Dsonar.genericcoverage.unitTestReportPaths=' + 'results' + path.sep + 'TESTS-junit.xml',
'-Dsonar.javascript.jstestdriver.itReportsPath=results',
'-Dsonar.javascript.lcov.reportPaths=' + 'results' + path.sep + 'coverage_report.lcov' + ',' + 'results' + path.sep + 'it_coverage_report.lcov',
'-Dsonar.javascript.lcov.reportPath=' + 'results' + path.sep + 'coverage_report.lcov',
'-Dsonar.javascript.lcov.itReportPath=' + 'results' + path.sep + 'it_coverage_report.lcov'
];
// Add the parameter (-D) only when the 'key' exists in the 'object'
function addParameter(prop, object, key) {
var value = _.result(object, key);
if (value !== undefined && value !== null && sonarOptions.excludedProperties.indexOf(prop) === -1) {
args.push('-D' + prop + '=' + value);
}
}
addParameter('sonar.host.url', sonarOptions.instance, 'hostUrl');
addParameter('sonar.jdbc.url', sonarOptions.instance, 'jdbcUrl');
addParameter('sonar.jdbc.username', sonarOptions.instance, 'jdbcUsername');
addParameter('sonar.jdbc.password', sonarOptions.instance, 'jdbcPassword');
addParameter('sonar.login', sonarOptions.instance, 'login');
addParameter('sonar.password', sonarOptions.instance, 'password');
addParameter('sonar.sourceEncoding', sonarOptions, 'sourceEncoding');
addParameter('sonar.language', sonarOptions, 'language');
addParameter('sonar.dynamicAnalysis', sonarOptions, 'dynamicAnalysis');
addParameter('sonar.projectBaseDir', sonarOptions, 'defaultOutputDir');
addParameter('sonar.scm.disabled', sonarOptions, 'scmDisabled');
addParameter('sonar.projectKey', data.project, 'key');
addParameter('sonar.projectName', data.project, 'name');
addParameter('sonar.projectVersion', data.project, 'version');
addParameter('sonar.exclusions', data, 'exclusions');
return args;
} | javascript | function buildArgs(sonarOptions, data) {
// Default arguments
var args = [
'-Dsonar.sources=src',
'-Dsonar.tests=test',
'-Dsonar.javascript.jstestdriver.reportsPath=results',
'-Dsonar.genericcoverage.unitTestReportPaths=' + 'results' + path.sep + 'TESTS-junit.xml',
'-Dsonar.javascript.jstestdriver.itReportsPath=results',
'-Dsonar.javascript.lcov.reportPaths=' + 'results' + path.sep + 'coverage_report.lcov' + ',' + 'results' + path.sep + 'it_coverage_report.lcov',
'-Dsonar.javascript.lcov.reportPath=' + 'results' + path.sep + 'coverage_report.lcov',
'-Dsonar.javascript.lcov.itReportPath=' + 'results' + path.sep + 'it_coverage_report.lcov'
];
// Add the parameter (-D) only when the 'key' exists in the 'object'
function addParameter(prop, object, key) {
var value = _.result(object, key);
if (value !== undefined && value !== null && sonarOptions.excludedProperties.indexOf(prop) === -1) {
args.push('-D' + prop + '=' + value);
}
}
addParameter('sonar.host.url', sonarOptions.instance, 'hostUrl');
addParameter('sonar.jdbc.url', sonarOptions.instance, 'jdbcUrl');
addParameter('sonar.jdbc.username', sonarOptions.instance, 'jdbcUsername');
addParameter('sonar.jdbc.password', sonarOptions.instance, 'jdbcPassword');
addParameter('sonar.login', sonarOptions.instance, 'login');
addParameter('sonar.password', sonarOptions.instance, 'password');
addParameter('sonar.sourceEncoding', sonarOptions, 'sourceEncoding');
addParameter('sonar.language', sonarOptions, 'language');
addParameter('sonar.dynamicAnalysis', sonarOptions, 'dynamicAnalysis');
addParameter('sonar.projectBaseDir', sonarOptions, 'defaultOutputDir');
addParameter('sonar.scm.disabled', sonarOptions, 'scmDisabled');
addParameter('sonar.projectKey', data.project, 'key');
addParameter('sonar.projectName', data.project, 'name');
addParameter('sonar.projectVersion', data.project, 'version');
addParameter('sonar.exclusions', data, 'exclusions');
return args;
} | [
"function",
"buildArgs",
"(",
"sonarOptions",
",",
"data",
")",
"{",
"// Default arguments",
"var",
"args",
"=",
"[",
"'-Dsonar.sources=src'",
",",
"'-Dsonar.tests=test'",
",",
"'-Dsonar.javascript.jstestdriver.reportsPath=results'",
",",
"'-Dsonar.genericcoverage.unitTestReportPaths='",
"+",
"'results'",
"+",
"path",
".",
"sep",
"+",
"'TESTS-junit.xml'",
",",
"'-Dsonar.javascript.jstestdriver.itReportsPath=results'",
",",
"'-Dsonar.javascript.lcov.reportPaths='",
"+",
"'results'",
"+",
"path",
".",
"sep",
"+",
"'coverage_report.lcov'",
"+",
"','",
"+",
"'results'",
"+",
"path",
".",
"sep",
"+",
"'it_coverage_report.lcov'",
",",
"'-Dsonar.javascript.lcov.reportPath='",
"+",
"'results'",
"+",
"path",
".",
"sep",
"+",
"'coverage_report.lcov'",
",",
"'-Dsonar.javascript.lcov.itReportPath='",
"+",
"'results'",
"+",
"path",
".",
"sep",
"+",
"'it_coverage_report.lcov'",
"]",
";",
"// Add the parameter (-D) only when the 'key' exists in the 'object'",
"function",
"addParameter",
"(",
"prop",
",",
"object",
",",
"key",
")",
"{",
"var",
"value",
"=",
"_",
".",
"result",
"(",
"object",
",",
"key",
")",
";",
"if",
"(",
"value",
"!==",
"undefined",
"&&",
"value",
"!==",
"null",
"&&",
"sonarOptions",
".",
"excludedProperties",
".",
"indexOf",
"(",
"prop",
")",
"===",
"-",
"1",
")",
"{",
"args",
".",
"push",
"(",
"'-D'",
"+",
"prop",
"+",
"'='",
"+",
"value",
")",
";",
"}",
"}",
"addParameter",
"(",
"'sonar.host.url'",
",",
"sonarOptions",
".",
"instance",
",",
"'hostUrl'",
")",
";",
"addParameter",
"(",
"'sonar.jdbc.url'",
",",
"sonarOptions",
".",
"instance",
",",
"'jdbcUrl'",
")",
";",
"addParameter",
"(",
"'sonar.jdbc.username'",
",",
"sonarOptions",
".",
"instance",
",",
"'jdbcUsername'",
")",
";",
"addParameter",
"(",
"'sonar.jdbc.password'",
",",
"sonarOptions",
".",
"instance",
",",
"'jdbcPassword'",
")",
";",
"addParameter",
"(",
"'sonar.login'",
",",
"sonarOptions",
".",
"instance",
",",
"'login'",
")",
";",
"addParameter",
"(",
"'sonar.password'",
",",
"sonarOptions",
".",
"instance",
",",
"'password'",
")",
";",
"addParameter",
"(",
"'sonar.sourceEncoding'",
",",
"sonarOptions",
",",
"'sourceEncoding'",
")",
";",
"addParameter",
"(",
"'sonar.language'",
",",
"sonarOptions",
",",
"'language'",
")",
";",
"addParameter",
"(",
"'sonar.dynamicAnalysis'",
",",
"sonarOptions",
",",
"'dynamicAnalysis'",
")",
";",
"addParameter",
"(",
"'sonar.projectBaseDir'",
",",
"sonarOptions",
",",
"'defaultOutputDir'",
")",
";",
"addParameter",
"(",
"'sonar.scm.disabled'",
",",
"sonarOptions",
",",
"'scmDisabled'",
")",
";",
"addParameter",
"(",
"'sonar.projectKey'",
",",
"data",
".",
"project",
",",
"'key'",
")",
";",
"addParameter",
"(",
"'sonar.projectName'",
",",
"data",
".",
"project",
",",
"'name'",
")",
";",
"addParameter",
"(",
"'sonar.projectVersion'",
",",
"data",
".",
"project",
",",
"'version'",
")",
";",
"addParameter",
"(",
"'sonar.exclusions'",
",",
"data",
",",
"'exclusions'",
")",
";",
"return",
"args",
";",
"}"
] | Builds the arguments that need to be sent to sonar-runner.
@param sonarOptions The sonar options such as username, password etc.
@param data The data such as project name and project version.
@returns The array of command line options for sonar-runner. | [
"Builds",
"the",
"arguments",
"that",
"need",
"to",
"be",
"sent",
"to",
"sonar",
"-",
"runner",
"."
] | 6b632d3cfdda05eee37165ea87531f1171a10117 | https://github.com/mdasberg/grunt-karma-sonar/blob/6b632d3cfdda05eee37165ea87531f1171a10117/tasks/sonar.js#L76-L116 |
26,209 | jonschlinkert/template | lib/mixins/list.js | createPage | function createPage() {
var page = new View(view.clone(), lazy.extend({}, view.options, opts));
page.data.pagination = new Parent(lazy.extend({}, self.options, {Item: Item}));
return page;
} | javascript | function createPage() {
var page = new View(view.clone(), lazy.extend({}, view.options, opts));
page.data.pagination = new Parent(lazy.extend({}, self.options, {Item: Item}));
return page;
} | [
"function",
"createPage",
"(",
")",
"{",
"var",
"page",
"=",
"new",
"View",
"(",
"view",
".",
"clone",
"(",
")",
",",
"lazy",
".",
"extend",
"(",
"{",
"}",
",",
"view",
".",
"options",
",",
"opts",
")",
")",
";",
"page",
".",
"data",
".",
"pagination",
"=",
"new",
"Parent",
"(",
"lazy",
".",
"extend",
"(",
"{",
"}",
",",
"self",
".",
"options",
",",
"{",
"Item",
":",
"Item",
"}",
")",
")",
";",
"return",
"page",
";",
"}"
] | helper function to create a new page to put into the returned list. | [
"helper",
"function",
"to",
"create",
"a",
"new",
"page",
"to",
"put",
"into",
"the",
"returned",
"list",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/mixins/list.js#L57-L61 |
26,210 | jonschlinkert/template | lib/mixins/list.js | function (prop, fn) {
if (typeof prop === 'function') {
fn = prop;
prop = undefined;
}
if (typeof prop === 'undefined') {
return this.sortByKeys(fn);
}
return this.sortByItems(prop, fn);
} | javascript | function (prop, fn) {
if (typeof prop === 'function') {
fn = prop;
prop = undefined;
}
if (typeof prop === 'undefined') {
return this.sortByKeys(fn);
}
return this.sortByItems(prop, fn);
} | [
"function",
"(",
"prop",
",",
"fn",
")",
"{",
"if",
"(",
"typeof",
"prop",
"===",
"'function'",
")",
"{",
"fn",
"=",
"prop",
";",
"prop",
"=",
"undefined",
";",
"}",
"if",
"(",
"typeof",
"prop",
"===",
"'undefined'",
")",
"{",
"return",
"this",
".",
"sortByKeys",
"(",
"fn",
")",
";",
"}",
"return",
"this",
".",
"sortByItems",
"(",
"prop",
",",
"fn",
")",
";",
"}"
] | Sort list items.
@param {String} `prop` Property to sort by, undefined to sort by keys.
@param {Function} `fn` Optional getter function to get items by.
@return {Object} Returns current instance to enable chaining
@api public | [
"Sort",
"list",
"items",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/mixins/list.js#L108-L118 | |
26,211 | jonschlinkert/template | lib/mixins/list.js | function (fn) {
var items = this.items;
var sorted = lazy.sortObject(this.keyMap, {prop: undefined, get: fn});
var keys = Object.keys(sorted);
var len = keys.length, i = -1;
var arr = new Array(len);
while (++i < len) {
var key = keys[i];
arr[i] = items[sorted[key]];
sorted[key] = i;
}
this.items = arr;
this.keyMap = sorted;
return this;
} | javascript | function (fn) {
var items = this.items;
var sorted = lazy.sortObject(this.keyMap, {prop: undefined, get: fn});
var keys = Object.keys(sorted);
var len = keys.length, i = -1;
var arr = new Array(len);
while (++i < len) {
var key = keys[i];
arr[i] = items[sorted[key]];
sorted[key] = i;
}
this.items = arr;
this.keyMap = sorted;
return this;
} | [
"function",
"(",
"fn",
")",
"{",
"var",
"items",
"=",
"this",
".",
"items",
";",
"var",
"sorted",
"=",
"lazy",
".",
"sortObject",
"(",
"this",
".",
"keyMap",
",",
"{",
"prop",
":",
"undefined",
",",
"get",
":",
"fn",
"}",
")",
";",
"var",
"keys",
"=",
"Object",
".",
"keys",
"(",
"sorted",
")",
";",
"var",
"len",
"=",
"keys",
".",
"length",
",",
"i",
"=",
"-",
"1",
";",
"var",
"arr",
"=",
"new",
"Array",
"(",
"len",
")",
";",
"while",
"(",
"++",
"i",
"<",
"len",
")",
"{",
"var",
"key",
"=",
"keys",
"[",
"i",
"]",
";",
"arr",
"[",
"i",
"]",
"=",
"items",
"[",
"sorted",
"[",
"key",
"]",
"]",
";",
"sorted",
"[",
"key",
"]",
"=",
"i",
";",
"}",
"this",
".",
"items",
"=",
"arr",
";",
"this",
".",
"keyMap",
"=",
"sorted",
";",
"return",
"this",
";",
"}"
] | Sort list items by their keys.
@param {Function} `fn` Optional getter function to get items by.
@return {Object} Returns current instance to enable chaining
@api public | [
"Sort",
"list",
"items",
"by",
"their",
"keys",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/mixins/list.js#L128-L144 | |
26,212 | jonschlinkert/template | lib/mixins/list.js | function (prop) {
var keys = Object.keys(this.keyMap);
var items = this.items.map(function (item, i) {
item.key = keys[i];
return item;
});
var sorted = lazy.arraySort(items, prop);
this.items = sorted;
this.keyMap = this.items.reduce(function (acc, item, i) {
acc[item.key] = i;
return acc;
}, {});
return this;
} | javascript | function (prop) {
var keys = Object.keys(this.keyMap);
var items = this.items.map(function (item, i) {
item.key = keys[i];
return item;
});
var sorted = lazy.arraySort(items, prop);
this.items = sorted;
this.keyMap = this.items.reduce(function (acc, item, i) {
acc[item.key] = i;
return acc;
}, {});
return this;
} | [
"function",
"(",
"prop",
")",
"{",
"var",
"keys",
"=",
"Object",
".",
"keys",
"(",
"this",
".",
"keyMap",
")",
";",
"var",
"items",
"=",
"this",
".",
"items",
".",
"map",
"(",
"function",
"(",
"item",
",",
"i",
")",
"{",
"item",
".",
"key",
"=",
"keys",
"[",
"i",
"]",
";",
"return",
"item",
";",
"}",
")",
";",
"var",
"sorted",
"=",
"lazy",
".",
"arraySort",
"(",
"items",
",",
"prop",
")",
";",
"this",
".",
"items",
"=",
"sorted",
";",
"this",
".",
"keyMap",
"=",
"this",
".",
"items",
".",
"reduce",
"(",
"function",
"(",
"acc",
",",
"item",
",",
"i",
")",
"{",
"acc",
"[",
"item",
".",
"key",
"]",
"=",
"i",
";",
"return",
"acc",
";",
"}",
",",
"{",
"}",
")",
";",
"return",
"this",
";",
"}"
] | Sort list items by a property on each item.
@param {String} `prop` Property to sort by.
@param {Function} `fn` Optional getter function to get items by.
@return {Object} Returns current instance to enable chaining
@api public | [
"Sort",
"list",
"items",
"by",
"a",
"property",
"on",
"each",
"item",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/mixins/list.js#L155-L168 | |
26,213 | jonschlinkert/template | lib/file.js | File | function File(file, options) {
Item.call(this, file, options);
this.initFile(file);
return file;
} | javascript | function File(file, options) {
Item.call(this, file, options);
this.initFile(file);
return file;
} | [
"function",
"File",
"(",
"file",
",",
"options",
")",
"{",
"Item",
".",
"call",
"(",
"this",
",",
"file",
",",
"options",
")",
";",
"this",
".",
"initFile",
"(",
"file",
")",
";",
"return",
"file",
";",
"}"
] | Create an instance of `File`. | [
"Create",
"an",
"instance",
"of",
"File",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/file.js#L26-L30 |
26,214 | jonschlinkert/template | lib/file.js | function (file) {
this.src = file.src || {};
if (this.path) {
this.src.path = this.path;
}
if (Buffer.isBuffer(this.contents)) {
this.content = this.contents.toString();
}
if (this.content) {
this.options.orig = this.content;
}
// ensure that `file` has `path` and `content` properties
this.validate(file);
this.options.orig = file.content;
this.options.plural = this.collection.options.plural;
this.options.handled = this.options.handled = [];
this.src = file.src || {};
this.src.path = this.src.path || this.path;
// add non-emumerable properties
this.defineOption('route', this.options.route);
this.define('_callbacks', this._callbacks);
file.__proto__ = this;
file.path = this.path;
// handle `onLoad` middleware routes
this.app.handle('onLoad', file);
} | javascript | function (file) {
this.src = file.src || {};
if (this.path) {
this.src.path = this.path;
}
if (Buffer.isBuffer(this.contents)) {
this.content = this.contents.toString();
}
if (this.content) {
this.options.orig = this.content;
}
// ensure that `file` has `path` and `content` properties
this.validate(file);
this.options.orig = file.content;
this.options.plural = this.collection.options.plural;
this.options.handled = this.options.handled = [];
this.src = file.src || {};
this.src.path = this.src.path || this.path;
// add non-emumerable properties
this.defineOption('route', this.options.route);
this.define('_callbacks', this._callbacks);
file.__proto__ = this;
file.path = this.path;
// handle `onLoad` middleware routes
this.app.handle('onLoad', file);
} | [
"function",
"(",
"file",
")",
"{",
"this",
".",
"src",
"=",
"file",
".",
"src",
"||",
"{",
"}",
";",
"if",
"(",
"this",
".",
"path",
")",
"{",
"this",
".",
"src",
".",
"path",
"=",
"this",
".",
"path",
";",
"}",
"if",
"(",
"Buffer",
".",
"isBuffer",
"(",
"this",
".",
"contents",
")",
")",
"{",
"this",
".",
"content",
"=",
"this",
".",
"contents",
".",
"toString",
"(",
")",
";",
"}",
"if",
"(",
"this",
".",
"content",
")",
"{",
"this",
".",
"options",
".",
"orig",
"=",
"this",
".",
"content",
";",
"}",
"// ensure that `file` has `path` and `content` properties",
"this",
".",
"validate",
"(",
"file",
")",
";",
"this",
".",
"options",
".",
"orig",
"=",
"file",
".",
"content",
";",
"this",
".",
"options",
".",
"plural",
"=",
"this",
".",
"collection",
".",
"options",
".",
"plural",
";",
"this",
".",
"options",
".",
"handled",
"=",
"this",
".",
"options",
".",
"handled",
"=",
"[",
"]",
";",
"this",
".",
"src",
"=",
"file",
".",
"src",
"||",
"{",
"}",
";",
"this",
".",
"src",
".",
"path",
"=",
"this",
".",
"src",
".",
"path",
"||",
"this",
".",
"path",
";",
"// add non-emumerable properties",
"this",
".",
"defineOption",
"(",
"'route'",
",",
"this",
".",
"options",
".",
"route",
")",
";",
"this",
".",
"define",
"(",
"'_callbacks'",
",",
"this",
".",
"_callbacks",
")",
";",
"file",
".",
"__proto__",
"=",
"this",
";",
"file",
".",
"path",
"=",
"this",
".",
"path",
";",
"// handle `onLoad` middleware routes",
"this",
".",
"app",
".",
"handle",
"(",
"'onLoad'",
",",
"file",
")",
";",
"}"
] | Initialize file with base properties. | [
"Initialize",
"file",
"with",
"base",
"properties",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/file.js#L49-L79 | |
26,215 | jonschlinkert/template | lib/file.js | function(key) {
var fn = this.pickOption('renameKey');
if (!fn) {
fn = this.collection.renameKey || this.app.renameKey;
}
if (typeof fn !== 'function') return key;
return fn(key);
} | javascript | function(key) {
var fn = this.pickOption('renameKey');
if (!fn) {
fn = this.collection.renameKey || this.app.renameKey;
}
if (typeof fn !== 'function') return key;
return fn(key);
} | [
"function",
"(",
"key",
")",
"{",
"var",
"fn",
"=",
"this",
".",
"pickOption",
"(",
"'renameKey'",
")",
";",
"if",
"(",
"!",
"fn",
")",
"{",
"fn",
"=",
"this",
".",
"collection",
".",
"renameKey",
"||",
"this",
".",
"app",
".",
"renameKey",
";",
"}",
"if",
"(",
"typeof",
"fn",
"!==",
"'function'",
")",
"return",
"key",
";",
"return",
"fn",
"(",
"key",
")",
";",
"}"
] | Get the basename of a file path. | [
"Get",
"the",
"basename",
"of",
"a",
"file",
"path",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/file.js#L100-L107 | |
26,216 | jonschlinkert/template | lib/view.js | View | function View(view, options) {
this.history = [];
Item.call(this, view, options);
this.init(view);
return view;
} | javascript | function View(view, options) {
this.history = [];
Item.call(this, view, options);
this.init(view);
return view;
} | [
"function",
"View",
"(",
"view",
",",
"options",
")",
"{",
"this",
".",
"history",
"=",
"[",
"]",
";",
"Item",
".",
"call",
"(",
"this",
",",
"view",
",",
"options",
")",
";",
"this",
".",
"init",
"(",
"view",
")",
";",
"return",
"view",
";",
"}"
] | Create an instance of `View`. | [
"Create",
"an",
"instance",
"of",
"View",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/view.js#L34-L39 |
26,217 | jonschlinkert/template | lib/view.js | function (view) {
view.base = view.base || view.cwd || process.cwd();
this.src = this.src || {};
// ensure that `view` has `path` and `content` properties
this.validate(view);
this.options.orig = view.content;
this.options.plural = this.collection.options.plural;
this.options.viewType = this.options.viewType = [];
this.options.handled = this.options.handled = [];
this.contexts = view.contexts = {};
this.locals = view.locals || {};
this.data = view.data || {};
mixins(this);
// add non-emumerable properties
this.defineOption('route', this.options.route);
this.define('_callbacks', this._callbacks);
if (view.stat) {
utils.defineProp(view, 'history', view.history);
utils.defineProp(view, '_contents', view._contents);
utils.defineProp(view, 'stat', view.stat);
}
view.__proto__ = this;
utils.defineProp(view, '_callbacks', view._callbacks);
// handle `onLoad` middleware routes
this.app.handleView('onLoad', view, view.locals);
this.ctx('locals', view.locals);
this.ctx('data', view.data);
} | javascript | function (view) {
view.base = view.base || view.cwd || process.cwd();
this.src = this.src || {};
// ensure that `view` has `path` and `content` properties
this.validate(view);
this.options.orig = view.content;
this.options.plural = this.collection.options.plural;
this.options.viewType = this.options.viewType = [];
this.options.handled = this.options.handled = [];
this.contexts = view.contexts = {};
this.locals = view.locals || {};
this.data = view.data || {};
mixins(this);
// add non-emumerable properties
this.defineOption('route', this.options.route);
this.define('_callbacks', this._callbacks);
if (view.stat) {
utils.defineProp(view, 'history', view.history);
utils.defineProp(view, '_contents', view._contents);
utils.defineProp(view, 'stat', view.stat);
}
view.__proto__ = this;
utils.defineProp(view, '_callbacks', view._callbacks);
// handle `onLoad` middleware routes
this.app.handleView('onLoad', view, view.locals);
this.ctx('locals', view.locals);
this.ctx('data', view.data);
} | [
"function",
"(",
"view",
")",
"{",
"view",
".",
"base",
"=",
"view",
".",
"base",
"||",
"view",
".",
"cwd",
"||",
"process",
".",
"cwd",
"(",
")",
";",
"this",
".",
"src",
"=",
"this",
".",
"src",
"||",
"{",
"}",
";",
"// ensure that `view` has `path` and `content` properties",
"this",
".",
"validate",
"(",
"view",
")",
";",
"this",
".",
"options",
".",
"orig",
"=",
"view",
".",
"content",
";",
"this",
".",
"options",
".",
"plural",
"=",
"this",
".",
"collection",
".",
"options",
".",
"plural",
";",
"this",
".",
"options",
".",
"viewType",
"=",
"this",
".",
"options",
".",
"viewType",
"=",
"[",
"]",
";",
"this",
".",
"options",
".",
"handled",
"=",
"this",
".",
"options",
".",
"handled",
"=",
"[",
"]",
";",
"this",
".",
"contexts",
"=",
"view",
".",
"contexts",
"=",
"{",
"}",
";",
"this",
".",
"locals",
"=",
"view",
".",
"locals",
"||",
"{",
"}",
";",
"this",
".",
"data",
"=",
"view",
".",
"data",
"||",
"{",
"}",
";",
"mixins",
"(",
"this",
")",
";",
"// add non-emumerable properties",
"this",
".",
"defineOption",
"(",
"'route'",
",",
"this",
".",
"options",
".",
"route",
")",
";",
"this",
".",
"define",
"(",
"'_callbacks'",
",",
"this",
".",
"_callbacks",
")",
";",
"if",
"(",
"view",
".",
"stat",
")",
"{",
"utils",
".",
"defineProp",
"(",
"view",
",",
"'history'",
",",
"view",
".",
"history",
")",
";",
"utils",
".",
"defineProp",
"(",
"view",
",",
"'_contents'",
",",
"view",
".",
"_contents",
")",
";",
"utils",
".",
"defineProp",
"(",
"view",
",",
"'stat'",
",",
"view",
".",
"stat",
")",
";",
"}",
"view",
".",
"__proto__",
"=",
"this",
";",
"utils",
".",
"defineProp",
"(",
"view",
",",
"'_callbacks'",
",",
"view",
".",
"_callbacks",
")",
";",
"// handle `onLoad` middleware routes",
"this",
".",
"app",
".",
"handleView",
"(",
"'onLoad'",
",",
"view",
",",
"view",
".",
"locals",
")",
";",
"this",
".",
"ctx",
"(",
"'locals'",
",",
"view",
".",
"locals",
")",
";",
"this",
".",
"ctx",
"(",
"'data'",
",",
"view",
".",
"data",
")",
";",
"}"
] | Initialize view with base properties. | [
"Initialize",
"view",
"with",
"base",
"properties",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/view.js#L58-L91 | |
26,218 | jonschlinkert/template | lib/view.js | function(locals, cb) {
if (typeof locals === 'function') {
cb = locals;
locals = {};
}
this.app.render(this, locals, cb);
return this;
} | javascript | function(locals, cb) {
if (typeof locals === 'function') {
cb = locals;
locals = {};
}
this.app.render(this, locals, cb);
return this;
} | [
"function",
"(",
"locals",
",",
"cb",
")",
"{",
"if",
"(",
"typeof",
"locals",
"===",
"'function'",
")",
"{",
"cb",
"=",
"locals",
";",
"locals",
"=",
"{",
"}",
";",
"}",
"this",
".",
"app",
".",
"render",
"(",
"this",
",",
"locals",
",",
"cb",
")",
";",
"return",
"this",
";",
"}"
] | Asynchronously render a view.
```js
pages.get('home.md')
.render({title: 'Home'}, function(err, res) {
//=> do stuff with `res`
});
```
@param {Object} `locals` Optionally pass locals to the engine.
@return {Object} `View` instance, for chaining.
@api public | [
"Asynchronously",
"render",
"a",
"view",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/view.js#L143-L150 | |
26,219 | jonschlinkert/template | lib/view.js | function(locals, fn) {
if (typeof locals === 'function') {
fn = locals;
locals = {};
}
var res = this.locals;
var data = this.app.cache.data;
this.ctx('global', data);
// extend context with same-named data-property from `app.cache.data`
if (!this.hint('extended')) {
this.hint('extended', true);
var name = this.collection.renameKey(this.path);
this.ctx('matched', data[name]);
}
this.ctx('data', this.data);
this.ctx('options', this.options);
// build up the array of context keys to calculate
var keys = ['global', 'compile', 'render', 'options', 'matched'];
if (this.pickOption('prefer locals') === true) {
keys = keys.concat(['data', 'locals']);
} else {
keys = keys.concat(['locals', 'data']);
}
keys = keys.concat(['helper', 'custom']);
function calculate(obj, contexts, props) {
var len = props.length, i = -1;
while (++i < len) {
var key = props[i];
lazy.extend(obj, contexts[key] || {});
}
}
fn = fn || this.pickOption('context');
if (typeof fn === 'function') {
fn.call(this, res, this.contexts, keys, calculate);
} else {
calculate(res, this.contexts, keys);
}
locals = locals || {};
lazy.extend(res, this.app.mergePartials(locals));
lazy.extend(res, locals);
return res;
} | javascript | function(locals, fn) {
if (typeof locals === 'function') {
fn = locals;
locals = {};
}
var res = this.locals;
var data = this.app.cache.data;
this.ctx('global', data);
// extend context with same-named data-property from `app.cache.data`
if (!this.hint('extended')) {
this.hint('extended', true);
var name = this.collection.renameKey(this.path);
this.ctx('matched', data[name]);
}
this.ctx('data', this.data);
this.ctx('options', this.options);
// build up the array of context keys to calculate
var keys = ['global', 'compile', 'render', 'options', 'matched'];
if (this.pickOption('prefer locals') === true) {
keys = keys.concat(['data', 'locals']);
} else {
keys = keys.concat(['locals', 'data']);
}
keys = keys.concat(['helper', 'custom']);
function calculate(obj, contexts, props) {
var len = props.length, i = -1;
while (++i < len) {
var key = props[i];
lazy.extend(obj, contexts[key] || {});
}
}
fn = fn || this.pickOption('context');
if (typeof fn === 'function') {
fn.call(this, res, this.contexts, keys, calculate);
} else {
calculate(res, this.contexts, keys);
}
locals = locals || {};
lazy.extend(res, this.app.mergePartials(locals));
lazy.extend(res, locals);
return res;
} | [
"function",
"(",
"locals",
",",
"fn",
")",
"{",
"if",
"(",
"typeof",
"locals",
"===",
"'function'",
")",
"{",
"fn",
"=",
"locals",
";",
"locals",
"=",
"{",
"}",
";",
"}",
"var",
"res",
"=",
"this",
".",
"locals",
";",
"var",
"data",
"=",
"this",
".",
"app",
".",
"cache",
".",
"data",
";",
"this",
".",
"ctx",
"(",
"'global'",
",",
"data",
")",
";",
"// extend context with same-named data-property from `app.cache.data`",
"if",
"(",
"!",
"this",
".",
"hint",
"(",
"'extended'",
")",
")",
"{",
"this",
".",
"hint",
"(",
"'extended'",
",",
"true",
")",
";",
"var",
"name",
"=",
"this",
".",
"collection",
".",
"renameKey",
"(",
"this",
".",
"path",
")",
";",
"this",
".",
"ctx",
"(",
"'matched'",
",",
"data",
"[",
"name",
"]",
")",
";",
"}",
"this",
".",
"ctx",
"(",
"'data'",
",",
"this",
".",
"data",
")",
";",
"this",
".",
"ctx",
"(",
"'options'",
",",
"this",
".",
"options",
")",
";",
"// build up the array of context keys to calculate",
"var",
"keys",
"=",
"[",
"'global'",
",",
"'compile'",
",",
"'render'",
",",
"'options'",
",",
"'matched'",
"]",
";",
"if",
"(",
"this",
".",
"pickOption",
"(",
"'prefer locals'",
")",
"===",
"true",
")",
"{",
"keys",
"=",
"keys",
".",
"concat",
"(",
"[",
"'data'",
",",
"'locals'",
"]",
")",
";",
"}",
"else",
"{",
"keys",
"=",
"keys",
".",
"concat",
"(",
"[",
"'locals'",
",",
"'data'",
"]",
")",
";",
"}",
"keys",
"=",
"keys",
".",
"concat",
"(",
"[",
"'helper'",
",",
"'custom'",
"]",
")",
";",
"function",
"calculate",
"(",
"obj",
",",
"contexts",
",",
"props",
")",
"{",
"var",
"len",
"=",
"props",
".",
"length",
",",
"i",
"=",
"-",
"1",
";",
"while",
"(",
"++",
"i",
"<",
"len",
")",
"{",
"var",
"key",
"=",
"props",
"[",
"i",
"]",
";",
"lazy",
".",
"extend",
"(",
"obj",
",",
"contexts",
"[",
"key",
"]",
"||",
"{",
"}",
")",
";",
"}",
"}",
"fn",
"=",
"fn",
"||",
"this",
".",
"pickOption",
"(",
"'context'",
")",
";",
"if",
"(",
"typeof",
"fn",
"===",
"'function'",
")",
"{",
"fn",
".",
"call",
"(",
"this",
",",
"res",
",",
"this",
".",
"contexts",
",",
"keys",
",",
"calculate",
")",
";",
"}",
"else",
"{",
"calculate",
"(",
"res",
",",
"this",
".",
"contexts",
",",
"keys",
")",
";",
"}",
"locals",
"=",
"locals",
"||",
"{",
"}",
";",
"lazy",
".",
"extend",
"(",
"res",
",",
"this",
".",
"app",
".",
"mergePartials",
"(",
"locals",
")",
")",
";",
"lazy",
".",
"extend",
"(",
"res",
",",
"locals",
")",
";",
"return",
"res",
";",
"}"
] | Build the context for a view.
@param {Function} `fn`
@api public | [
"Build",
"the",
"context",
"for",
"a",
"view",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/view.js#L181-L229 | |
26,220 | jonschlinkert/template | lib/collection.js | Collection | function Collection(options) {
Base.call(this, options);
this.define('lists', {});
this.define('_items', {});
this.define('Item', this.options.Item || require('./item'));
this.define('List', this.options.List || require('./list'));
mixins(this);
/**
* Get an object representing the current items on the instance.
*
* ```js
* var items = this.items;
* ```
*
* @return {Object} Object of items
*/
Object.defineProperty(this, 'items', {
enumerable: false,
configurable: true,
get: function () {
return this._items;
},
set: function (items) {
lazy.forIn(items, function (item, key) {
delete this._items[key];
delete this[key];
this.set(key, item);
}, this);
}
});
} | javascript | function Collection(options) {
Base.call(this, options);
this.define('lists', {});
this.define('_items', {});
this.define('Item', this.options.Item || require('./item'));
this.define('List', this.options.List || require('./list'));
mixins(this);
/**
* Get an object representing the current items on the instance.
*
* ```js
* var items = this.items;
* ```
*
* @return {Object} Object of items
*/
Object.defineProperty(this, 'items', {
enumerable: false,
configurable: true,
get: function () {
return this._items;
},
set: function (items) {
lazy.forIn(items, function (item, key) {
delete this._items[key];
delete this[key];
this.set(key, item);
}, this);
}
});
} | [
"function",
"Collection",
"(",
"options",
")",
"{",
"Base",
".",
"call",
"(",
"this",
",",
"options",
")",
";",
"this",
".",
"define",
"(",
"'lists'",
",",
"{",
"}",
")",
";",
"this",
".",
"define",
"(",
"'_items'",
",",
"{",
"}",
")",
";",
"this",
".",
"define",
"(",
"'Item'",
",",
"this",
".",
"options",
".",
"Item",
"||",
"require",
"(",
"'./item'",
")",
")",
";",
"this",
".",
"define",
"(",
"'List'",
",",
"this",
".",
"options",
".",
"List",
"||",
"require",
"(",
"'./list'",
")",
")",
";",
"mixins",
"(",
"this",
")",
";",
"/**\n * Get an object representing the current items on the instance.\n *\n * ```js\n * var items = this.items;\n * ```\n *\n * @return {Object} Object of items\n */",
"Object",
".",
"defineProperty",
"(",
"this",
",",
"'items'",
",",
"{",
"enumerable",
":",
"false",
",",
"configurable",
":",
"true",
",",
"get",
":",
"function",
"(",
")",
"{",
"return",
"this",
".",
"_items",
";",
"}",
",",
"set",
":",
"function",
"(",
"items",
")",
"{",
"lazy",
".",
"forIn",
"(",
"items",
",",
"function",
"(",
"item",
",",
"key",
")",
"{",
"delete",
"this",
".",
"_items",
"[",
"key",
"]",
";",
"delete",
"this",
"[",
"key",
"]",
";",
"this",
".",
"set",
"(",
"key",
",",
"item",
")",
";",
"}",
",",
"this",
")",
";",
"}",
"}",
")",
";",
"}"
] | Create an instance of `Collection` with the specified `options`.
The `Collection` constructor inherits from Base.
```js
var collection = new Collection();
```
@param {Object} `options`
@return {undefined}
@api public | [
"Create",
"an",
"instance",
"of",
"Collection",
"with",
"the",
"specified",
"options",
".",
"The",
"Collection",
"constructor",
"inherits",
"from",
"Base",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/collection.js#L36-L68 |
26,221 | jonschlinkert/template | lib/collection.js | function (prop, val) {
this.setItem(prop, val);
if (prop === 'app' || prop === 'collection') {
this.define(prop, val);
} else {
lazy.set(this, prop, val);
}
return this;
} | javascript | function (prop, val) {
this.setItem(prop, val);
if (prop === 'app' || prop === 'collection') {
this.define(prop, val);
} else {
lazy.set(this, prop, val);
}
return this;
} | [
"function",
"(",
"prop",
",",
"val",
")",
"{",
"this",
".",
"setItem",
"(",
"prop",
",",
"val",
")",
";",
"if",
"(",
"prop",
"===",
"'app'",
"||",
"prop",
"===",
"'collection'",
")",
"{",
"this",
".",
"define",
"(",
"prop",
",",
"val",
")",
";",
"}",
"else",
"{",
"lazy",
".",
"set",
"(",
"this",
",",
"prop",
",",
"val",
")",
";",
"}",
"return",
"this",
";",
"}"
] | Set a value. | [
"Set",
"a",
"value",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/collection.js#L87-L95 | |
26,222 | jonschlinkert/template | lib/collection.js | function (prop, val) {
if (prop === 'app' || prop === 'collection') {
utils.defineProp(this._items, prop, val);
} else {
this._items[prop] = val;
}
return this;
} | javascript | function (prop, val) {
if (prop === 'app' || prop === 'collection') {
utils.defineProp(this._items, prop, val);
} else {
this._items[prop] = val;
}
return this;
} | [
"function",
"(",
"prop",
",",
"val",
")",
"{",
"if",
"(",
"prop",
"===",
"'app'",
"||",
"prop",
"===",
"'collection'",
")",
"{",
"utils",
".",
"defineProp",
"(",
"this",
".",
"_items",
",",
"prop",
",",
"val",
")",
";",
"}",
"else",
"{",
"this",
".",
"_items",
"[",
"prop",
"]",
"=",
"val",
";",
"}",
"return",
"this",
";",
"}"
] | Set an item | [
"Set",
"an",
"item"
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/collection.js#L101-L108 | |
26,223 | jonschlinkert/template | lib/collection.js | function (name, items) {
var List = this.get('List');
var list = this.lists[name];
if (typeof list === 'undefined') {
var opts = lazy.clone(this.options);
opts.items = items || this.items;
opts.collection = this;
this.lists[name] = list = new List(opts);
}
return list;
} | javascript | function (name, items) {
var List = this.get('List');
var list = this.lists[name];
if (typeof list === 'undefined') {
var opts = lazy.clone(this.options);
opts.items = items || this.items;
opts.collection = this;
this.lists[name] = list = new List(opts);
}
return list;
} | [
"function",
"(",
"name",
",",
"items",
")",
"{",
"var",
"List",
"=",
"this",
".",
"get",
"(",
"'List'",
")",
";",
"var",
"list",
"=",
"this",
".",
"lists",
"[",
"name",
"]",
";",
"if",
"(",
"typeof",
"list",
"===",
"'undefined'",
")",
"{",
"var",
"opts",
"=",
"lazy",
".",
"clone",
"(",
"this",
".",
"options",
")",
";",
"opts",
".",
"items",
"=",
"items",
"||",
"this",
".",
"items",
";",
"opts",
".",
"collection",
"=",
"this",
";",
"this",
".",
"lists",
"[",
"name",
"]",
"=",
"list",
"=",
"new",
"List",
"(",
"opts",
")",
";",
"}",
"return",
"list",
";",
"}"
] | Get or create a new list. | [
"Get",
"or",
"create",
"a",
"new",
"list",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/collection.js#L122-L132 | |
26,224 | jonschlinkert/template | lib/collection.js | function (prop, fn) {
if (typeof prop === 'function') {
fn = prop;
prop = undefined;
}
var items = this.items;
this.items = lazy.sortObj(items, {
prop: prop,
get: fn
});
return this;
} | javascript | function (prop, fn) {
if (typeof prop === 'function') {
fn = prop;
prop = undefined;
}
var items = this.items;
this.items = lazy.sortObj(items, {
prop: prop,
get: fn
});
return this;
} | [
"function",
"(",
"prop",
",",
"fn",
")",
"{",
"if",
"(",
"typeof",
"prop",
"===",
"'function'",
")",
"{",
"fn",
"=",
"prop",
";",
"prop",
"=",
"undefined",
";",
"}",
"var",
"items",
"=",
"this",
".",
"items",
";",
"this",
".",
"items",
"=",
"lazy",
".",
"sortObj",
"(",
"items",
",",
"{",
"prop",
":",
"prop",
",",
"get",
":",
"fn",
"}",
")",
";",
"return",
"this",
";",
"}"
] | Return collection items sorted by the given property. | [
"Return",
"collection",
"items",
"sorted",
"by",
"the",
"given",
"property",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/collection.js#L186-L198 | |
26,225 | jonschlinkert/template | lib/item.js | Item | function Item(item, options) {
Base.call(this, options);
this.define('collection', this.options.collection);
if (typeof item === 'object') {
this.visit('set', item);
}
} | javascript | function Item(item, options) {
Base.call(this, options);
this.define('collection', this.options.collection);
if (typeof item === 'object') {
this.visit('set', item);
}
} | [
"function",
"Item",
"(",
"item",
",",
"options",
")",
"{",
"Base",
".",
"call",
"(",
"this",
",",
"options",
")",
";",
"this",
".",
"define",
"(",
"'collection'",
",",
"this",
".",
"options",
".",
"collection",
")",
";",
"if",
"(",
"typeof",
"item",
"===",
"'object'",
")",
"{",
"this",
".",
"visit",
"(",
"'set'",
",",
"item",
")",
";",
"}",
"}"
] | Create an instance of `Item` with the specified `options`.
The `Item` constructor inherits from Base.
```js
var item = new Item();
```
@param {Object} `options`
@return {undefined}
@api public | [
"Create",
"an",
"instance",
"of",
"Item",
"with",
"the",
"specified",
"options",
".",
"The",
"Item",
"constructor",
"inherits",
"from",
"Base",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/item.js#L22-L29 |
26,226 | jonschlinkert/template | lib/item.js | function(prop) {
var opt = this.option(prop);
if (typeof opt === 'undefined') {
opt = this.collection && this.collection.option(prop);
}
if (typeof opt === 'undefined') {
return this.app && this.app.option(prop);
}
return opt;
} | javascript | function(prop) {
var opt = this.option(prop);
if (typeof opt === 'undefined') {
opt = this.collection && this.collection.option(prop);
}
if (typeof opt === 'undefined') {
return this.app && this.app.option(prop);
}
return opt;
} | [
"function",
"(",
"prop",
")",
"{",
"var",
"opt",
"=",
"this",
".",
"option",
"(",
"prop",
")",
";",
"if",
"(",
"typeof",
"opt",
"===",
"'undefined'",
")",
"{",
"opt",
"=",
"this",
".",
"collection",
"&&",
"this",
".",
"collection",
".",
"option",
"(",
"prop",
")",
";",
"}",
"if",
"(",
"typeof",
"opt",
"===",
"'undefined'",
")",
"{",
"return",
"this",
".",
"app",
"&&",
"this",
".",
"app",
".",
"option",
"(",
"prop",
")",
";",
"}",
"return",
"opt",
";",
"}"
] | Get an option from the item, collection or app instance,
in that order. | [
"Get",
"an",
"option",
"from",
"the",
"item",
"collection",
"or",
"app",
"instance",
"in",
"that",
"order",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/item.js#L67-L76 | |
26,227 | jonschlinkert/template | lib/mixins/view.js | function (data) {
var parse = function() {
var parsed = lazy.extend({}, lazy.parseFilepath(this.path), data);
if (typeof parsed.ext === 'undefined') {
parsed.ext = parsed.extname;
}
return parsed;
}.bind(this);
return this.fragmentCache('path', parse);
} | javascript | function (data) {
var parse = function() {
var parsed = lazy.extend({}, lazy.parseFilepath(this.path), data);
if (typeof parsed.ext === 'undefined') {
parsed.ext = parsed.extname;
}
return parsed;
}.bind(this);
return this.fragmentCache('path', parse);
} | [
"function",
"(",
"data",
")",
"{",
"var",
"parse",
"=",
"function",
"(",
")",
"{",
"var",
"parsed",
"=",
"lazy",
".",
"extend",
"(",
"{",
"}",
",",
"lazy",
".",
"parseFilepath",
"(",
"this",
".",
"path",
")",
",",
"data",
")",
";",
"if",
"(",
"typeof",
"parsed",
".",
"ext",
"===",
"'undefined'",
")",
"{",
"parsed",
".",
"ext",
"=",
"parsed",
".",
"extname",
";",
"}",
"return",
"parsed",
";",
"}",
".",
"bind",
"(",
"this",
")",
";",
"return",
"this",
".",
"fragmentCache",
"(",
"'path'",
",",
"parse",
")",
";",
"}"
] | Parse `view.path` into an object. | [
"Parse",
"view",
".",
"path",
"into",
"an",
"object",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/mixins/view.js#L33-L42 | |
26,228 | jonschlinkert/template | lib/mixins/view.js | function(filepath, fn) {
fn = fn || lazy.dashify;
if (typeof filepath === 'undefined') {
var ctx = this.context();
filepath = ctx.slug || this.path;
}
return fn(filepath);
} | javascript | function(filepath, fn) {
fn = fn || lazy.dashify;
if (typeof filepath === 'undefined') {
var ctx = this.context();
filepath = ctx.slug || this.path;
}
return fn(filepath);
} | [
"function",
"(",
"filepath",
",",
"fn",
")",
"{",
"fn",
"=",
"fn",
"||",
"lazy",
".",
"dashify",
";",
"if",
"(",
"typeof",
"filepath",
"===",
"'undefined'",
")",
"{",
"var",
"ctx",
"=",
"this",
".",
"context",
"(",
")",
";",
"filepath",
"=",
"ctx",
".",
"slug",
"||",
"this",
".",
"path",
";",
"}",
"return",
"fn",
"(",
"filepath",
")",
";",
"}"
] | Returns a slugified filepath. If `filepath` is not passed,
`view.data.slug` or `view.path` will be slugified. | [
"Returns",
"a",
"slugified",
"filepath",
".",
"If",
"filepath",
"is",
"not",
"passed",
"view",
".",
"data",
".",
"slug",
"or",
"view",
".",
"path",
"will",
"be",
"slugified",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/mixins/view.js#L49-L56 | |
26,229 | jonschlinkert/template | lib/mixins/view.js | function(str) {
if (typeof str !== 'string') {
str = this.content;
}
if (typeof str !== 'string') return '';
str = str.replace(/(<([^>]+)>)/g, '');
return str.trim();
} | javascript | function(str) {
if (typeof str !== 'string') {
str = this.content;
}
if (typeof str !== 'string') return '';
str = str.replace(/(<([^>]+)>)/g, '');
return str.trim();
} | [
"function",
"(",
"str",
")",
"{",
"if",
"(",
"typeof",
"str",
"!==",
"'string'",
")",
"{",
"str",
"=",
"this",
".",
"content",
";",
"}",
"if",
"(",
"typeof",
"str",
"!==",
"'string'",
")",
"return",
"''",
";",
"str",
"=",
"str",
".",
"replace",
"(",
"/",
"(<([^>]+)>)",
"/",
"g",
",",
"''",
")",
";",
"return",
"str",
".",
"trim",
"(",
")",
";",
"}"
] | Strip HTML from the given `str` or `view.content`
@param {String} str HTML string
@return {String} | [
"Strip",
"HTML",
"from",
"the",
"given",
"str",
"or",
"view",
".",
"content"
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/mixins/view.js#L65-L72 | |
26,230 | jonschlinkert/template | lib/mixins/view.js | function (options) {
options = options || {};
lazy.extend(options, this.options.excerpt || {});
var re = /<!--+\s*more\s*--+>/;
var str = this.content;
var view = this;
var link = options.link || '<a id="more"></a>';
this.content = str.replace(re, function (match, i) {
view.data.excerpt = str.slice(0, i).trim();
view.data.more = str.slice(i + match.length).trim() + link;
return '';
});
return this;
} | javascript | function (options) {
options = options || {};
lazy.extend(options, this.options.excerpt || {});
var re = /<!--+\s*more\s*--+>/;
var str = this.content;
var view = this;
var link = options.link || '<a id="more"></a>';
this.content = str.replace(re, function (match, i) {
view.data.excerpt = str.slice(0, i).trim();
view.data.more = str.slice(i + match.length).trim() + link;
return '';
});
return this;
} | [
"function",
"(",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"lazy",
".",
"extend",
"(",
"options",
",",
"this",
".",
"options",
".",
"excerpt",
"||",
"{",
"}",
")",
";",
"var",
"re",
"=",
"/",
"<!--+\\s*more\\s*--+>",
"/",
";",
"var",
"str",
"=",
"this",
".",
"content",
";",
"var",
"view",
"=",
"this",
";",
"var",
"link",
"=",
"options",
".",
"link",
"||",
"'<a id=\"more\"></a>'",
";",
"this",
".",
"content",
"=",
"str",
".",
"replace",
"(",
"re",
",",
"function",
"(",
"match",
",",
"i",
")",
"{",
"view",
".",
"data",
".",
"excerpt",
"=",
"str",
".",
"slice",
"(",
"0",
",",
"i",
")",
".",
"trim",
"(",
")",
";",
"view",
".",
"data",
".",
"more",
"=",
"str",
".",
"slice",
"(",
"i",
"+",
"match",
".",
"length",
")",
".",
"trim",
"(",
")",
"+",
"link",
";",
"return",
"''",
";",
"}",
")",
";",
"return",
"this",
";",
"}"
] | Generate an excerpt for a view.
```js
app.posts.get('foo.md')
.excerpt()
.render(function (err, res) {
//=>
});
```
@param {Object} `options` Excerpt options.
@option {Object} `template` Template to use for the excerpt tag.
@return {Object} | [
"Generate",
"an",
"excerpt",
"for",
"a",
"view",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/mixins/view.js#L90-L106 | |
26,231 | jonschlinkert/template | lib/mixins/view.js | function (structure, locals) {
if (typeof structure !== 'string') {
locals = structure;
structure = null;
}
var self = this;
var data = {};
lazy.extend(data, this);
lazy.extend(data, this.parsePath());
lazy.extend(data, this.context(locals));
this.data.dest = this.data.dest || {};
var opts = lazy.get(data, 'permalinks') || {};
lazy.extend(opts, this.options.permalinks || {});
if (typeof structure !== 'string') {
structure = opts.structure || ':path';
}
return structure.replace(/:(\w+)(?:\((.*)\))?/g, function (m, param, prop) {
var res = data[param] || param;
if (typeof res === 'function' && prop) {
return res.call(data, prop);
}
self.data.dest = res;
return res;
});
} | javascript | function (structure, locals) {
if (typeof structure !== 'string') {
locals = structure;
structure = null;
}
var self = this;
var data = {};
lazy.extend(data, this);
lazy.extend(data, this.parsePath());
lazy.extend(data, this.context(locals));
this.data.dest = this.data.dest || {};
var opts = lazy.get(data, 'permalinks') || {};
lazy.extend(opts, this.options.permalinks || {});
if (typeof structure !== 'string') {
structure = opts.structure || ':path';
}
return structure.replace(/:(\w+)(?:\((.*)\))?/g, function (m, param, prop) {
var res = data[param] || param;
if (typeof res === 'function' && prop) {
return res.call(data, prop);
}
self.data.dest = res;
return res;
});
} | [
"function",
"(",
"structure",
",",
"locals",
")",
"{",
"if",
"(",
"typeof",
"structure",
"!==",
"'string'",
")",
"{",
"locals",
"=",
"structure",
";",
"structure",
"=",
"null",
";",
"}",
"var",
"self",
"=",
"this",
";",
"var",
"data",
"=",
"{",
"}",
";",
"lazy",
".",
"extend",
"(",
"data",
",",
"this",
")",
";",
"lazy",
".",
"extend",
"(",
"data",
",",
"this",
".",
"parsePath",
"(",
")",
")",
";",
"lazy",
".",
"extend",
"(",
"data",
",",
"this",
".",
"context",
"(",
"locals",
")",
")",
";",
"this",
".",
"data",
".",
"dest",
"=",
"this",
".",
"data",
".",
"dest",
"||",
"{",
"}",
";",
"var",
"opts",
"=",
"lazy",
".",
"get",
"(",
"data",
",",
"'permalinks'",
")",
"||",
"{",
"}",
";",
"lazy",
".",
"extend",
"(",
"opts",
",",
"this",
".",
"options",
".",
"permalinks",
"||",
"{",
"}",
")",
";",
"if",
"(",
"typeof",
"structure",
"!==",
"'string'",
")",
"{",
"structure",
"=",
"opts",
".",
"structure",
"||",
"':path'",
";",
"}",
"return",
"structure",
".",
"replace",
"(",
"/",
":(\\w+)(?:\\((.*)\\))?",
"/",
"g",
",",
"function",
"(",
"m",
",",
"param",
",",
"prop",
")",
"{",
"var",
"res",
"=",
"data",
"[",
"param",
"]",
"||",
"param",
";",
"if",
"(",
"typeof",
"res",
"===",
"'function'",
"&&",
"prop",
")",
"{",
"return",
"res",
".",
"call",
"(",
"data",
",",
"prop",
")",
";",
"}",
"self",
".",
"data",
".",
"dest",
"=",
"res",
";",
"return",
"res",
";",
"}",
")",
";",
"}"
] | Generate a permalink for a view.
```js
app.posts.get('foo.md')
.render(function (err, res) {
dest(res.permalink(), res);
//=>
});
```
@param {Object} `locals` pass any additional locals for context.
@return {String} Returns a permalink string.
@api public | [
"Generate",
"a",
"permalink",
"for",
"a",
"view",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/mixins/view.js#L133-L163 | |
26,232 | jonschlinkert/template | lib/views.js | Views | function Views(options) {
Collection.call(this, options);
this.options.collection = this.options.collection || this;
this.define('View', this.options.View || require('./view'));
this.define('Item', this.View);
} | javascript | function Views(options) {
Collection.call(this, options);
this.options.collection = this.options.collection || this;
this.define('View', this.options.View || require('./view'));
this.define('Item', this.View);
} | [
"function",
"Views",
"(",
"options",
")",
"{",
"Collection",
".",
"call",
"(",
"this",
",",
"options",
")",
";",
"this",
".",
"options",
".",
"collection",
"=",
"this",
".",
"options",
".",
"collection",
"||",
"this",
";",
"this",
".",
"define",
"(",
"'View'",
",",
"this",
".",
"options",
".",
"View",
"||",
"require",
"(",
"'./view'",
")",
")",
";",
"this",
".",
"define",
"(",
"'Item'",
",",
"this",
".",
"View",
")",
";",
"}"
] | Create an instance of `Views`.
@api public | [
"Create",
"an",
"instance",
"of",
"Views",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/views.js#L32-L37 |
26,233 | jonschlinkert/template | lib/views.js | function (key, val) {
if (lazy.typeOf(val) !== 'object') {
lazy.set(this, key, val);
return this;
}
this.addView(key, val);
return this;
} | javascript | function (key, val) {
if (lazy.typeOf(val) !== 'object') {
lazy.set(this, key, val);
return this;
}
this.addView(key, val);
return this;
} | [
"function",
"(",
"key",
",",
"val",
")",
"{",
"if",
"(",
"lazy",
".",
"typeOf",
"(",
"val",
")",
"!==",
"'object'",
")",
"{",
"lazy",
".",
"set",
"(",
"this",
",",
"key",
",",
"val",
")",
";",
"return",
"this",
";",
"}",
"this",
".",
"addView",
"(",
"key",
",",
"val",
")",
";",
"return",
"this",
";",
"}"
] | Set a value on the collection instance.
@param {String} `key`
@param {Object} `val` The view object
@param {Object} Returns the instance of `Views` for chaining.
@api public | [
"Set",
"a",
"value",
"on",
"the",
"collection",
"instance",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/views.js#L61-L68 | |
26,234 | jonschlinkert/template | lib/views.js | function (key, val) {
var opts = lazy.clone(this.options);
var View = this.get('View');
val.path = val.path || key;
key = val.key = this.renameKey(key);
this.setItem(key, (this[key] = new View(val, opts)));
return this;
} | javascript | function (key, val) {
var opts = lazy.clone(this.options);
var View = this.get('View');
val.path = val.path || key;
key = val.key = this.renameKey(key);
this.setItem(key, (this[key] = new View(val, opts)));
return this;
} | [
"function",
"(",
"key",
",",
"val",
")",
"{",
"var",
"opts",
"=",
"lazy",
".",
"clone",
"(",
"this",
".",
"options",
")",
";",
"var",
"View",
"=",
"this",
".",
"get",
"(",
"'View'",
")",
";",
"val",
".",
"path",
"=",
"val",
".",
"path",
"||",
"key",
";",
"key",
"=",
"val",
".",
"key",
"=",
"this",
".",
"renameKey",
"(",
"key",
")",
";",
"this",
".",
"setItem",
"(",
"key",
",",
"(",
"this",
"[",
"key",
"]",
"=",
"new",
"View",
"(",
"val",
",",
"opts",
")",
")",
")",
";",
"return",
"this",
";",
"}"
] | Add a view to the current collection.
@param {String} `key`
@param {Object} `val` The view object
@param {Object} Returns the instance of `Views` for chaining.
@api public | [
"Add",
"a",
"view",
"to",
"the",
"current",
"collection",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/views.js#L79-L86 | |
26,235 | jonschlinkert/template | lib/views.js | function(prop) {
var res = this[prop];
if (typeof res === 'undefined') {
var name = this.renameKey(prop);
if (name && name !== prop) {
res = this[name];
}
}
if (typeof res === 'undefined') {
res = lazy.get(this, prop);
}
if (typeof res === 'undefined') {
res = this.find(prop);
}
return res;
} | javascript | function(prop) {
var res = this[prop];
if (typeof res === 'undefined') {
var name = this.renameKey(prop);
if (name && name !== prop) {
res = this[name];
}
}
if (typeof res === 'undefined') {
res = lazy.get(this, prop);
}
if (typeof res === 'undefined') {
res = this.find(prop);
}
return res;
} | [
"function",
"(",
"prop",
")",
"{",
"var",
"res",
"=",
"this",
"[",
"prop",
"]",
";",
"if",
"(",
"typeof",
"res",
"===",
"'undefined'",
")",
"{",
"var",
"name",
"=",
"this",
".",
"renameKey",
"(",
"prop",
")",
";",
"if",
"(",
"name",
"&&",
"name",
"!==",
"prop",
")",
"{",
"res",
"=",
"this",
"[",
"name",
"]",
";",
"}",
"}",
"if",
"(",
"typeof",
"res",
"===",
"'undefined'",
")",
"{",
"res",
"=",
"lazy",
".",
"get",
"(",
"this",
",",
"prop",
")",
";",
"}",
"if",
"(",
"typeof",
"res",
"===",
"'undefined'",
")",
"{",
"res",
"=",
"this",
".",
"find",
"(",
"prop",
")",
";",
"}",
"return",
"res",
";",
"}"
] | Get a view. | [
"Get",
"a",
"view",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/views.js#L105-L120 | |
26,236 | jonschlinkert/template | lib/views.js | function (pattern, options) {
var self = this;
function find() {
var isMatch = lazy.mm.matcher(pattern, options);
for (var key in self) {
var val = self[key];
if (typeof val === 'object' && isMatch(key)) {
return val;
}
}
}
var res = this.fragmentCache(pattern, find);
res.__proto__ = this;
return res;
} | javascript | function (pattern, options) {
var self = this;
function find() {
var isMatch = lazy.mm.matcher(pattern, options);
for (var key in self) {
var val = self[key];
if (typeof val === 'object' && isMatch(key)) {
return val;
}
}
}
var res = this.fragmentCache(pattern, find);
res.__proto__ = this;
return res;
} | [
"function",
"(",
"pattern",
",",
"options",
")",
"{",
"var",
"self",
"=",
"this",
";",
"function",
"find",
"(",
")",
"{",
"var",
"isMatch",
"=",
"lazy",
".",
"mm",
".",
"matcher",
"(",
"pattern",
",",
"options",
")",
";",
"for",
"(",
"var",
"key",
"in",
"self",
")",
"{",
"var",
"val",
"=",
"self",
"[",
"key",
"]",
";",
"if",
"(",
"typeof",
"val",
"===",
"'object'",
"&&",
"isMatch",
"(",
"key",
")",
")",
"{",
"return",
"val",
";",
"}",
"}",
"}",
"var",
"res",
"=",
"this",
".",
"fragmentCache",
"(",
"pattern",
",",
"find",
")",
";",
"res",
".",
"__proto__",
"=",
"this",
";",
"return",
"res",
";",
"}"
] | Find a view by `key` or glob pattern.
@param {String} `pattern` Key or glob pattern.
@param {Object} `options` Options for [micromatch]
@return {Object} Matching view. | [
"Find",
"a",
"view",
"by",
"key",
"or",
"glob",
"pattern",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/views.js#L130-L144 | |
26,237 | jonschlinkert/template | lib/views.js | function (view/*, locals, fn*/) {
var args = [].slice.call(arguments, 1);
var app = this.app;
if (typeof view === 'string') view = this[view];
app.render.apply(app, [view].concat(args));
return this;
} | javascript | function (view/*, locals, fn*/) {
var args = [].slice.call(arguments, 1);
var app = this.app;
if (typeof view === 'string') view = this[view];
app.render.apply(app, [view].concat(args));
return this;
} | [
"function",
"(",
"view",
"/*, locals, fn*/",
")",
"{",
"var",
"args",
"=",
"[",
"]",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"1",
")",
";",
"var",
"app",
"=",
"this",
".",
"app",
";",
"if",
"(",
"typeof",
"view",
"===",
"'string'",
")",
"view",
"=",
"this",
"[",
"view",
"]",
";",
"app",
".",
"render",
".",
"apply",
"(",
"app",
",",
"[",
"view",
"]",
".",
"concat",
"(",
"args",
")",
")",
";",
"return",
"this",
";",
"}"
] | Render a view in the collection.
@param {String|Object} `view` View key or object.
@param {Object} `locals`
@param {Function} `fn`
@return {Object} | [
"Render",
"a",
"view",
"in",
"the",
"collection",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/views.js#L172-L179 | |
26,238 | jonschlinkert/template | lib/views.js | function (prop, pattern, options) {
options = options || {};
var views = this.items;
var res = Object.create(this);
var matcher = pattern ? lazy.mm.isMatch(pattern, options) : null;
for (var key in views) {
if (views.hasOwnProperty(key)) {
var file = views[key];
if (prop === 'key') {
if (matcher) {
if (matcher(path.relative(process.cwd(), key))) {
res[key] = file;
}
} else {
res[key] = file;
}
} else {
var val = lazy.get(file, prop);
if (prop === 'path' || prop === 'cwd') {
val = path.relative(process.cwd(), val);
}
if (lazy.has(val)) {
if (matcher) {
if (matcher(val)) {
res[key] = file;
}
} else {
res[key] = file;
}
}
}
}
}
return res;
} | javascript | function (prop, pattern, options) {
options = options || {};
var views = this.items;
var res = Object.create(this);
var matcher = pattern ? lazy.mm.isMatch(pattern, options) : null;
for (var key in views) {
if (views.hasOwnProperty(key)) {
var file = views[key];
if (prop === 'key') {
if (matcher) {
if (matcher(path.relative(process.cwd(), key))) {
res[key] = file;
}
} else {
res[key] = file;
}
} else {
var val = lazy.get(file, prop);
if (prop === 'path' || prop === 'cwd') {
val = path.relative(process.cwd(), val);
}
if (lazy.has(val)) {
if (matcher) {
if (matcher(val)) {
res[key] = file;
}
} else {
res[key] = file;
}
}
}
}
}
return res;
} | [
"function",
"(",
"prop",
",",
"pattern",
",",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"var",
"views",
"=",
"this",
".",
"items",
";",
"var",
"res",
"=",
"Object",
".",
"create",
"(",
"this",
")",
";",
"var",
"matcher",
"=",
"pattern",
"?",
"lazy",
".",
"mm",
".",
"isMatch",
"(",
"pattern",
",",
"options",
")",
":",
"null",
";",
"for",
"(",
"var",
"key",
"in",
"views",
")",
"{",
"if",
"(",
"views",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"var",
"file",
"=",
"views",
"[",
"key",
"]",
";",
"if",
"(",
"prop",
"===",
"'key'",
")",
"{",
"if",
"(",
"matcher",
")",
"{",
"if",
"(",
"matcher",
"(",
"path",
".",
"relative",
"(",
"process",
".",
"cwd",
"(",
")",
",",
"key",
")",
")",
")",
"{",
"res",
"[",
"key",
"]",
"=",
"file",
";",
"}",
"}",
"else",
"{",
"res",
"[",
"key",
"]",
"=",
"file",
";",
"}",
"}",
"else",
"{",
"var",
"val",
"=",
"lazy",
".",
"get",
"(",
"file",
",",
"prop",
")",
";",
"if",
"(",
"prop",
"===",
"'path'",
"||",
"prop",
"===",
"'cwd'",
")",
"{",
"val",
"=",
"path",
".",
"relative",
"(",
"process",
".",
"cwd",
"(",
")",
",",
"val",
")",
";",
"}",
"if",
"(",
"lazy",
".",
"has",
"(",
"val",
")",
")",
"{",
"if",
"(",
"matcher",
")",
"{",
"if",
"(",
"matcher",
"(",
"val",
")",
")",
"{",
"res",
"[",
"key",
"]",
"=",
"file",
";",
"}",
"}",
"else",
"{",
"res",
"[",
"key",
"]",
"=",
"file",
";",
"}",
"}",
"}",
"}",
"}",
"return",
"res",
";",
"}"
] | Filter views by the given `prop`, using the specified `pattern` and `options.
@param {String} `prop` The property to sort by.
@param {String|Object|Array|Function} `pattern` Function, glob patterns, object, array, or string pattern to use for pre-filtering views.
@param {Object} `options`
@option {Object} `limit` [options]
@option {Object} `limit` [options]
@return {Object} | [
"Filter",
"views",
"by",
"the",
"given",
"prop",
"using",
"the",
"specified",
"pattern",
"and",
"options",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/views.js#L192-L228 | |
26,239 | jonschlinkert/template | lib/views.js | function() {
this.options.viewType = utils.arrayify(this.options.viewType || []);
if (this.options.viewType.length === 0) {
this.options.viewType.push('renderable');
}
return this.options.viewType;
} | javascript | function() {
this.options.viewType = utils.arrayify(this.options.viewType || []);
if (this.options.viewType.length === 0) {
this.options.viewType.push('renderable');
}
return this.options.viewType;
} | [
"function",
"(",
")",
"{",
"this",
".",
"options",
".",
"viewType",
"=",
"utils",
".",
"arrayify",
"(",
"this",
".",
"options",
".",
"viewType",
"||",
"[",
"]",
")",
";",
"if",
"(",
"this",
".",
"options",
".",
"viewType",
".",
"length",
"===",
"0",
")",
"{",
"this",
".",
"options",
".",
"viewType",
".",
"push",
"(",
"'renderable'",
")",
";",
"}",
"return",
"this",
".",
"options",
".",
"viewType",
";",
"}"
] | Set view types for the collection.
@param {String} `plural` e.g. `pages`
@param {Object} `options`
@api private | [
"Set",
"view",
"types",
"for",
"the",
"collection",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/views.js#L238-L244 | |
26,240 | jonschlinkert/template | lib/base.js | Base | function Base(options) {
this.define('options', options || {});
this.define('hints', this.hints || {});
this.define('data', this.data || {});
this.define('app', this.app || this.options.app || {});
this.define('_cache', {});
this.define('_callbacks', this._callbacks);
if (typeof this.options.mixins === 'object') {
this.visit('mixin', this.options.mixins);
}
} | javascript | function Base(options) {
this.define('options', options || {});
this.define('hints', this.hints || {});
this.define('data', this.data || {});
this.define('app', this.app || this.options.app || {});
this.define('_cache', {});
this.define('_callbacks', this._callbacks);
if (typeof this.options.mixins === 'object') {
this.visit('mixin', this.options.mixins);
}
} | [
"function",
"Base",
"(",
"options",
")",
"{",
"this",
".",
"define",
"(",
"'options'",
",",
"options",
"||",
"{",
"}",
")",
";",
"this",
".",
"define",
"(",
"'hints'",
",",
"this",
".",
"hints",
"||",
"{",
"}",
")",
";",
"this",
".",
"define",
"(",
"'data'",
",",
"this",
".",
"data",
"||",
"{",
"}",
")",
";",
"this",
".",
"define",
"(",
"'app'",
",",
"this",
".",
"app",
"||",
"this",
".",
"options",
".",
"app",
"||",
"{",
"}",
")",
";",
"this",
".",
"define",
"(",
"'_cache'",
",",
"{",
"}",
")",
";",
"this",
".",
"define",
"(",
"'_callbacks'",
",",
"this",
".",
"_callbacks",
")",
";",
"if",
"(",
"typeof",
"this",
".",
"options",
".",
"mixins",
"===",
"'object'",
")",
"{",
"this",
".",
"visit",
"(",
"'mixin'",
",",
"this",
".",
"options",
".",
"mixins",
")",
";",
"}",
"}"
] | Create an instance of `Base` with specified `options.
The `Base` class extends `Collection`, `List` and `Item`
with common methods, properties and behavior.
```js
function MyClass(options) {
Base.call(this, options);
}
Base.extend(MyClass);
```
@param {Object} `options`
@return {undefined}
@api public | [
"Create",
"an",
"instance",
"of",
"Base",
"with",
"specified",
"options",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/base.js#L44-L55 |
26,241 | jonschlinkert/template | lib/base.js | function (key, val) {
if (this._cache[key]) {
return this._cache[key];
}
if (typeof val === 'function') {
val = val.call(this);
}
return (this._cache[key] = val);
} | javascript | function (key, val) {
if (this._cache[key]) {
return this._cache[key];
}
if (typeof val === 'function') {
val = val.call(this);
}
return (this._cache[key] = val);
} | [
"function",
"(",
"key",
",",
"val",
")",
"{",
"if",
"(",
"this",
".",
"_cache",
"[",
"key",
"]",
")",
"{",
"return",
"this",
".",
"_cache",
"[",
"key",
"]",
";",
"}",
"if",
"(",
"typeof",
"val",
"===",
"'function'",
")",
"{",
"val",
"=",
"val",
".",
"call",
"(",
"this",
")",
";",
"}",
"return",
"(",
"this",
".",
"_cache",
"[",
"key",
"]",
"=",
"val",
")",
";",
"}"
] | Get a value if it exists, otherwise call the given function
and cache the result and return it on subsequent calls.
@param {String} `key`
@param {any} `val`
@return {any}
@api public | [
"Get",
"a",
"value",
"if",
"it",
"exists",
"otherwise",
"call",
"the",
"given",
"function",
"and",
"cache",
"the",
"result",
"and",
"return",
"it",
"on",
"subsequent",
"calls",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/base.js#L74-L82 | |
26,242 | jonschlinkert/template | lib/base.js | function (keys) {
var Parent = this.constructor;
var opts = lazy.clone(this.options);
var res = new Parent(opts);
lazy.omit(this, keys, function (val, key) {
res[key] = lazy.clone(val);
});
return res;
} | javascript | function (keys) {
var Parent = this.constructor;
var opts = lazy.clone(this.options);
var res = new Parent(opts);
lazy.omit(this, keys, function (val, key) {
res[key] = lazy.clone(val);
});
return res;
} | [
"function",
"(",
"keys",
")",
"{",
"var",
"Parent",
"=",
"this",
".",
"constructor",
";",
"var",
"opts",
"=",
"lazy",
".",
"clone",
"(",
"this",
".",
"options",
")",
";",
"var",
"res",
"=",
"new",
"Parent",
"(",
"opts",
")",
";",
"lazy",
".",
"omit",
"(",
"this",
",",
"keys",
",",
"function",
"(",
"val",
",",
"key",
")",
"{",
"res",
"[",
"key",
"]",
"=",
"lazy",
".",
"clone",
"(",
"val",
")",
";",
"}",
")",
";",
"return",
"res",
";",
"}"
] | Return a clone of the instance.
```js
var foo = app.clone();
```
@param {Array} keys Optionally pass an array of keys to omit.
@return {Object}
@api public | [
"Return",
"a",
"clone",
"of",
"the",
"instance",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/base.js#L95-L104 | |
26,243 | jonschlinkert/template | lib/base.js | function(prop) {
var opt = this.option(prop);
if (typeof opt === 'undefined') {
return this.app && this.app.option ? this.app.option(prop) : null;
}
return opt;
} | javascript | function(prop) {
var opt = this.option(prop);
if (typeof opt === 'undefined') {
return this.app && this.app.option ? this.app.option(prop) : null;
}
return opt;
} | [
"function",
"(",
"prop",
")",
"{",
"var",
"opt",
"=",
"this",
".",
"option",
"(",
"prop",
")",
";",
"if",
"(",
"typeof",
"opt",
"===",
"'undefined'",
")",
"{",
"return",
"this",
".",
"app",
"&&",
"this",
".",
"app",
".",
"option",
"?",
"this",
".",
"app",
".",
"option",
"(",
"prop",
")",
":",
"null",
";",
"}",
"return",
"opt",
";",
"}"
] | Get an option from either the view, collection, or app instance,
in that order.
@param {String} prop Property name. Dot notation may be used.
@return {any}
@api public | [
"Get",
"an",
"option",
"from",
"either",
"the",
"view",
"collection",
"or",
"app",
"instance",
"in",
"that",
"order",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/base.js#L259-L265 | |
26,244 | jonschlinkert/template | lib/base.js | function (key, fn) {
if (typeof key === 'function') {
fn = key;
key = null;
}
if (typeof fn !== 'function') {
fn = this.pickOption('renameKey');
}
if (typeof fn !== 'function') {
fn = utils.identity;
}
this.options.renameKey = fn;
if (arguments.length === 2) {
return fn(key);
}
if (typeof key === 'string') {
return fn(key);
}
return fn;
} | javascript | function (key, fn) {
if (typeof key === 'function') {
fn = key;
key = null;
}
if (typeof fn !== 'function') {
fn = this.pickOption('renameKey');
}
if (typeof fn !== 'function') {
fn = utils.identity;
}
this.options.renameKey = fn;
if (arguments.length === 2) {
return fn(key);
}
if (typeof key === 'string') {
return fn(key);
}
return fn;
} | [
"function",
"(",
"key",
",",
"fn",
")",
"{",
"if",
"(",
"typeof",
"key",
"===",
"'function'",
")",
"{",
"fn",
"=",
"key",
";",
"key",
"=",
"null",
";",
"}",
"if",
"(",
"typeof",
"fn",
"!==",
"'function'",
")",
"{",
"fn",
"=",
"this",
".",
"pickOption",
"(",
"'renameKey'",
")",
";",
"}",
"if",
"(",
"typeof",
"fn",
"!==",
"'function'",
")",
"{",
"fn",
"=",
"utils",
".",
"identity",
";",
"}",
"this",
".",
"options",
".",
"renameKey",
"=",
"fn",
";",
"if",
"(",
"arguments",
".",
"length",
"===",
"2",
")",
"{",
"return",
"fn",
"(",
"key",
")",
";",
"}",
"if",
"(",
"typeof",
"key",
"===",
"'string'",
")",
"{",
"return",
"fn",
"(",
"key",
")",
";",
"}",
"return",
"fn",
";",
"}"
] | Resolves the renaming function to use on `view` keys. | [
"Resolves",
"the",
"renaming",
"function",
"to",
"use",
"on",
"view",
"keys",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/base.js#L271-L291 | |
26,245 | johno/ember-linkify | addon/utils/url-regex.js | shortenUrl | function shortenUrl ( url , length ) {
if( !isBlank( url ) && url.length > length) {
url = url.substr( 0 , length ) + "...";
}
return url;
} | javascript | function shortenUrl ( url , length ) {
if( !isBlank( url ) && url.length > length) {
url = url.substr( 0 , length ) + "...";
}
return url;
} | [
"function",
"shortenUrl",
"(",
"url",
",",
"length",
")",
"{",
"if",
"(",
"!",
"isBlank",
"(",
"url",
")",
"&&",
"url",
".",
"length",
">",
"length",
")",
"{",
"url",
"=",
"url",
".",
"substr",
"(",
"0",
",",
"length",
")",
"+",
"\"...\"",
";",
"}",
"return",
"url",
";",
"}"
] | Shortens the URL and adds three dots to the end | [
"Shortens",
"the",
"URL",
"and",
"adds",
"three",
"dots",
"to",
"the",
"end"
] | dd3b59f6602218aab3244d00ffcbd9f42e4fdb7c | https://github.com/johno/ember-linkify/blob/dd3b59f6602218aab3244d00ffcbd9f42e4fdb7c/addon/utils/url-regex.js#L9-L16 |
26,246 | jonschlinkert/template | lib/helpers/methods.js | function(helpers, options) {
if (typeof helpers === 'object') {
this.visit('helper', helpers);
return this;
}
if (lazy.isGlob(helpers)) {
this.loader('helpers-glob', ['base-glob'], function (files) {
return files.map(function (fp) {
return require(path.resolve(fp));
});
});
var res = this.compose('helpers-glob')(helpers, options);
this.visit('helper', res);
return this;
}
if (typeof helpers === 'string') {
console.log('loading helpers from a string is not implemented yet.');
}
return this;
} | javascript | function(helpers, options) {
if (typeof helpers === 'object') {
this.visit('helper', helpers);
return this;
}
if (lazy.isGlob(helpers)) {
this.loader('helpers-glob', ['base-glob'], function (files) {
return files.map(function (fp) {
return require(path.resolve(fp));
});
});
var res = this.compose('helpers-glob')(helpers, options);
this.visit('helper', res);
return this;
}
if (typeof helpers === 'string') {
console.log('loading helpers from a string is not implemented yet.');
}
return this;
} | [
"function",
"(",
"helpers",
",",
"options",
")",
"{",
"if",
"(",
"typeof",
"helpers",
"===",
"'object'",
")",
"{",
"this",
".",
"visit",
"(",
"'helper'",
",",
"helpers",
")",
";",
"return",
"this",
";",
"}",
"if",
"(",
"lazy",
".",
"isGlob",
"(",
"helpers",
")",
")",
"{",
"this",
".",
"loader",
"(",
"'helpers-glob'",
",",
"[",
"'base-glob'",
"]",
",",
"function",
"(",
"files",
")",
"{",
"return",
"files",
".",
"map",
"(",
"function",
"(",
"fp",
")",
"{",
"return",
"require",
"(",
"path",
".",
"resolve",
"(",
"fp",
")",
")",
";",
"}",
")",
";",
"}",
")",
";",
"var",
"res",
"=",
"this",
".",
"compose",
"(",
"'helpers-glob'",
")",
"(",
"helpers",
",",
"options",
")",
";",
"this",
".",
"visit",
"(",
"'helper'",
",",
"res",
")",
";",
"return",
"this",
";",
"}",
"if",
"(",
"typeof",
"helpers",
"===",
"'string'",
")",
"{",
"console",
".",
"log",
"(",
"'loading helpers from a string is not implemented yet.'",
")",
";",
"}",
"return",
"this",
";",
"}"
] | Register multiple template helpers.
@param {Object|Array} `helpers` Object, array of objects, or glob patterns.
@api public | [
"Register",
"multiple",
"template",
"helpers",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/helpers/methods.js#L77-L99 | |
26,247 | jonschlinkert/template | lib/list.js | List | function List(options) {
Base.call(this, options || {});
this.items = [];
this.define('keyMap', {});
this.define('Item', this.options.Item || require('./item'));
this.visit('item', this.options.items || {});
delete this.options.items;
mixins(this);
} | javascript | function List(options) {
Base.call(this, options || {});
this.items = [];
this.define('keyMap', {});
this.define('Item', this.options.Item || require('./item'));
this.visit('item', this.options.items || {});
delete this.options.items;
mixins(this);
} | [
"function",
"List",
"(",
"options",
")",
"{",
"Base",
".",
"call",
"(",
"this",
",",
"options",
"||",
"{",
"}",
")",
";",
"this",
".",
"items",
"=",
"[",
"]",
";",
"this",
".",
"define",
"(",
"'keyMap'",
",",
"{",
"}",
")",
";",
"this",
".",
"define",
"(",
"'Item'",
",",
"this",
".",
"options",
".",
"Item",
"||",
"require",
"(",
"'./item'",
")",
")",
";",
"this",
".",
"visit",
"(",
"'item'",
",",
"this",
".",
"options",
".",
"items",
"||",
"{",
"}",
")",
";",
"delete",
"this",
".",
"options",
".",
"items",
";",
"mixins",
"(",
"this",
")",
";",
"}"
] | Create an instance of `List` with the given options. Lists are
arrayified collections, with items that can be sorted, filtered,
grouped, and paginated. The `List` constructor inherits from Base.
```js
var list = new List();
```
@param {Object} `options` `List` options (passed to `Base`)
@return {undefined}
@api public | [
"Create",
"an",
"instance",
"of",
"List",
"with",
"the",
"given",
"options",
".",
"Lists",
"are",
"arrayified",
"collections",
"with",
"items",
"that",
"can",
"be",
"sorted",
"filtered",
"grouped",
"and",
"paginated",
".",
"The",
"List",
"constructor",
"inherits",
"from",
"Base",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/list.js#L36-L44 |
26,248 | jonschlinkert/template | lib/list.js | function(key, value) {
if (typeof key !== 'string') {
throw new TypeError('item key must be a string.');
}
if (typeof value === 'undefined') {
return this.getItem(key);
}
this.addItem(key, value);
return value;
} | javascript | function(key, value) {
if (typeof key !== 'string') {
throw new TypeError('item key must be a string.');
}
if (typeof value === 'undefined') {
return this.getItem(key);
}
this.addItem(key, value);
return value;
} | [
"function",
"(",
"key",
",",
"value",
")",
"{",
"if",
"(",
"typeof",
"key",
"!==",
"'string'",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'item key must be a string.'",
")",
";",
"}",
"if",
"(",
"typeof",
"value",
"===",
"'undefined'",
")",
"{",
"return",
"this",
".",
"getItem",
"(",
"key",
")",
";",
"}",
"this",
".",
"addItem",
"(",
"key",
",",
"value",
")",
";",
"return",
"value",
";",
"}"
] | Get or Add an item to the list. Creates a new instance of `Item` when
adding.
```js
var list = new List();
list.item('foo', {name: 'foo'});
console.log(list.items);
//=> [{name: 'foo'}]
```
@param {String} `name` Name of the item to get or add.
@param {Object} `obj` Optional item to add or update.
@return {Object} `item`
@api public | [
"Get",
"or",
"Add",
"an",
"item",
"to",
"the",
"list",
".",
"Creates",
"a",
"new",
"instance",
"of",
"Item",
"when",
"adding",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/list.js#L76-L85 | |
26,249 | jonschlinkert/template | lib/list.js | function (key, value) {
var Item = this.get('Item');
if (!(value instanceof Item)) {
value = new Item(value);
}
value.key = value.key || key;
var i = this.indexOf(key);
if (i !== -1) {
this.items[i] = value;
} else {
this.items.push(value);
this.keyMap[key] = this.items.length - 1;
}
this.emit('item', key, value);
return this;
} | javascript | function (key, value) {
var Item = this.get('Item');
if (!(value instanceof Item)) {
value = new Item(value);
}
value.key = value.key || key;
var i = this.indexOf(key);
if (i !== -1) {
this.items[i] = value;
} else {
this.items.push(value);
this.keyMap[key] = this.items.length - 1;
}
this.emit('item', key, value);
return this;
} | [
"function",
"(",
"key",
",",
"value",
")",
"{",
"var",
"Item",
"=",
"this",
".",
"get",
"(",
"'Item'",
")",
";",
"if",
"(",
"!",
"(",
"value",
"instanceof",
"Item",
")",
")",
"{",
"value",
"=",
"new",
"Item",
"(",
"value",
")",
";",
"}",
"value",
".",
"key",
"=",
"value",
".",
"key",
"||",
"key",
";",
"var",
"i",
"=",
"this",
".",
"indexOf",
"(",
"key",
")",
";",
"if",
"(",
"i",
"!==",
"-",
"1",
")",
"{",
"this",
".",
"items",
"[",
"i",
"]",
"=",
"value",
";",
"}",
"else",
"{",
"this",
".",
"items",
".",
"push",
"(",
"value",
")",
";",
"this",
".",
"keyMap",
"[",
"key",
"]",
"=",
"this",
".",
"items",
".",
"length",
"-",
"1",
";",
"}",
"this",
".",
"emit",
"(",
"'item'",
",",
"key",
",",
"value",
")",
";",
"return",
"this",
";",
"}"
] | Add a new item or update an existing item.
```js
list.addItem('foo', {contents: '...'});
```
@param {String} `key`
@param {Object} `value`
@api public | [
"Add",
"a",
"new",
"item",
"or",
"update",
"an",
"existing",
"item",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/list.js#L99-L118 | |
26,250 | jonschlinkert/template | lib/list.js | function (locals, cb) {
if (typeof locals === 'function') {
cb = locals;
locals = {};
}
lazy.each(this.items, function (item, next) {
this.app.render(item, locals, next);
}.bind(this), cb);
} | javascript | function (locals, cb) {
if (typeof locals === 'function') {
cb = locals;
locals = {};
}
lazy.each(this.items, function (item, next) {
this.app.render(item, locals, next);
}.bind(this), cb);
} | [
"function",
"(",
"locals",
",",
"cb",
")",
"{",
"if",
"(",
"typeof",
"locals",
"===",
"'function'",
")",
"{",
"cb",
"=",
"locals",
";",
"locals",
"=",
"{",
"}",
";",
"}",
"lazy",
".",
"each",
"(",
"this",
".",
"items",
",",
"function",
"(",
"item",
",",
"next",
")",
"{",
"this",
".",
"app",
".",
"render",
"(",
"item",
",",
"locals",
",",
"next",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
",",
"cb",
")",
";",
"}"
] | Render all items in the list and return an array in the callback.
@param {Object} `locals`
@param {Function} `fn`
@return {Object}
@api public | [
"Render",
"all",
"items",
"in",
"the",
"list",
"and",
"return",
"an",
"array",
"in",
"the",
"callback",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/list.js#L191-L200 | |
26,251 | jonschlinkert/template | lib/engines.js | function(exts, fn, options) {
if (arguments.length === 1 && typeof exts === 'string') {
return this.getEngine(exts);
}
exts = utils.arrayify(exts);
var len = exts.length;
while (len--) {
var ext = exts[len];
if (ext && ext[0] !== '.') ext = '.' + ext;
this._.engines.setEngine(ext, fn, options);
}
return this;
} | javascript | function(exts, fn, options) {
if (arguments.length === 1 && typeof exts === 'string') {
return this.getEngine(exts);
}
exts = utils.arrayify(exts);
var len = exts.length;
while (len--) {
var ext = exts[len];
if (ext && ext[0] !== '.') ext = '.' + ext;
this._.engines.setEngine(ext, fn, options);
}
return this;
} | [
"function",
"(",
"exts",
",",
"fn",
",",
"options",
")",
"{",
"if",
"(",
"arguments",
".",
"length",
"===",
"1",
"&&",
"typeof",
"exts",
"===",
"'string'",
")",
"{",
"return",
"this",
".",
"getEngine",
"(",
"exts",
")",
";",
"}",
"exts",
"=",
"utils",
".",
"arrayify",
"(",
"exts",
")",
";",
"var",
"len",
"=",
"exts",
".",
"length",
";",
"while",
"(",
"len",
"--",
")",
"{",
"var",
"ext",
"=",
"exts",
"[",
"len",
"]",
";",
"if",
"(",
"ext",
"&&",
"ext",
"[",
"0",
"]",
"!==",
"'.'",
")",
"ext",
"=",
"'.'",
"+",
"ext",
";",
"this",
".",
"_",
".",
"engines",
".",
"setEngine",
"(",
"ext",
",",
"fn",
",",
"options",
")",
";",
"}",
"return",
"this",
";",
"}"
] | Register the given view engine callback `fn` as `ext`.
@param {String|Array} `exts` File extension or array of extensions.
@param {Function|Object} `fn` or `options`
@param {Object} `options`
@api public | [
"Register",
"the",
"given",
"view",
"engine",
"callback",
"fn",
"as",
"ext",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/engines.js#L32-L44 | |
26,252 | jonschlinkert/template | lib/engines.js | function(ext) {
ext = ext || this.option('view engine');
if (ext && ext[0] !== '.') {
ext = '.' + ext;
}
return this._.engines.getEngine(ext);
} | javascript | function(ext) {
ext = ext || this.option('view engine');
if (ext && ext[0] !== '.') {
ext = '.' + ext;
}
return this._.engines.getEngine(ext);
} | [
"function",
"(",
"ext",
")",
"{",
"ext",
"=",
"ext",
"||",
"this",
".",
"option",
"(",
"'view engine'",
")",
";",
"if",
"(",
"ext",
"&&",
"ext",
"[",
"0",
"]",
"!==",
"'.'",
")",
"{",
"ext",
"=",
"'.'",
"+",
"ext",
";",
"}",
"return",
"this",
".",
"_",
".",
"engines",
".",
"getEngine",
"(",
"ext",
")",
";",
"}"
] | Get the engine settings registered for the given `ext`.
@param {String} `ext` The engine to get.
@api public | [
"Get",
"the",
"engine",
"settings",
"registered",
"for",
"the",
"given",
"ext",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/engines.js#L53-L59 | |
26,253 | jonschlinkert/template | index.js | function(key, val) {
if (arguments.length === 1) {
if (typeof key === 'string') {
if (key.indexOf('.') === -1) {
return this.cache.data[key];
}
if (lazy.isGlob(key)) {
this.compose('data')(key, val);
return this;
}
return lazy.get(this.cache.data, key);
}
}
if (typeof key === 'object') {
var args = [].slice.call(arguments);
key = [].concat.apply([], args);
this.visit('data', key);
return this;
}
lazy.set(this.cache.data, key, val);
this.emit('data', key, val);
return this;
} | javascript | function(key, val) {
if (arguments.length === 1) {
if (typeof key === 'string') {
if (key.indexOf('.') === -1) {
return this.cache.data[key];
}
if (lazy.isGlob(key)) {
this.compose('data')(key, val);
return this;
}
return lazy.get(this.cache.data, key);
}
}
if (typeof key === 'object') {
var args = [].slice.call(arguments);
key = [].concat.apply([], args);
this.visit('data', key);
return this;
}
lazy.set(this.cache.data, key, val);
this.emit('data', key, val);
return this;
} | [
"function",
"(",
"key",
",",
"val",
")",
"{",
"if",
"(",
"arguments",
".",
"length",
"===",
"1",
")",
"{",
"if",
"(",
"typeof",
"key",
"===",
"'string'",
")",
"{",
"if",
"(",
"key",
".",
"indexOf",
"(",
"'.'",
")",
"===",
"-",
"1",
")",
"{",
"return",
"this",
".",
"cache",
".",
"data",
"[",
"key",
"]",
";",
"}",
"if",
"(",
"lazy",
".",
"isGlob",
"(",
"key",
")",
")",
"{",
"this",
".",
"compose",
"(",
"'data'",
")",
"(",
"key",
",",
"val",
")",
";",
"return",
"this",
";",
"}",
"return",
"lazy",
".",
"get",
"(",
"this",
".",
"cache",
".",
"data",
",",
"key",
")",
";",
"}",
"}",
"if",
"(",
"typeof",
"key",
"===",
"'object'",
")",
"{",
"var",
"args",
"=",
"[",
"]",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
";",
"key",
"=",
"[",
"]",
".",
"concat",
".",
"apply",
"(",
"[",
"]",
",",
"args",
")",
";",
"this",
".",
"visit",
"(",
"'data'",
",",
"key",
")",
";",
"return",
"this",
";",
"}",
"lazy",
".",
"set",
"(",
"this",
".",
"cache",
".",
"data",
",",
"key",
",",
"val",
")",
";",
"this",
".",
"emit",
"(",
"'data'",
",",
"key",
",",
"val",
")",
";",
"return",
"this",
";",
"}"
] | Load data onto `app.cache.data`
```js
console.log(app.cache.data);
//=> {};
app.data('a', 'b');
app.data({c: 'd'});
console.log(app.cache.data);
//=> {a: 'b', c: 'd'}
```
@name .data
@param {String|Object} `key` Key of the value to set, or object to extend.
@param {any} `val`
@return {Object} Returns the instance of `Template` for chaining
@api public | [
"Load",
"data",
"onto",
"app",
".",
"cache",
".",
"data"
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/index.js#L159-L183 | |
26,254 | jonschlinkert/template | index.js | function (methods) {
this.lazyLoaders();
var loaders = this.loaders;
var self = this;
utils.arrayify(methods).forEach(function (method) {
self.define(method, function() {
return loaders[method].apply(loaders, arguments);
});
});
} | javascript | function (methods) {
this.lazyLoaders();
var loaders = this.loaders;
var self = this;
utils.arrayify(methods).forEach(function (method) {
self.define(method, function() {
return loaders[method].apply(loaders, arguments);
});
});
} | [
"function",
"(",
"methods",
")",
"{",
"this",
".",
"lazyLoaders",
"(",
")",
";",
"var",
"loaders",
"=",
"this",
".",
"loaders",
";",
"var",
"self",
"=",
"this",
";",
"utils",
".",
"arrayify",
"(",
"methods",
")",
".",
"forEach",
"(",
"function",
"(",
"method",
")",
"{",
"self",
".",
"define",
"(",
"method",
",",
"function",
"(",
")",
"{",
"return",
"loaders",
"[",
"method",
"]",
".",
"apply",
"(",
"loaders",
",",
"arguments",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Delegate loader methods | [
"Delegate",
"loader",
"methods"
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/index.js#L200-L210 | |
26,255 | jonschlinkert/template | index.js | function (name, opts, loaders) {
var args = utils.slice(arguments, 1);
opts = lazy.clone(args.shift());
loaders = args;
var single = lazy.inflect.singularize(name);
var plural = lazy.inflect.pluralize(name);
this.inflections[single] = plural;
if (typeof opts.renameKey === 'undefined' && this.options.renameKey) {
opts.renameKey = this.options.renameKey;
}
opts.plural = plural;
opts.inflection = single;
opts.loaders = loaders;
opts.app = this;
opts = lazy.extend({}, opts, this.options);
if (!opts.loaderType) {
opts.loaderType = 'sync';
}
var Views = this.get('Views');
var views = new Views(opts);
this.viewType(plural, views.viewType());
// add custom View constructor for collection items
var ViewClass = viewFactory(single, opts);
var classKey = single[0].toUpperCase() + single.slice(1);
this.define(classKey, ViewClass);
// init the collection object on `views`
this.views[plural] = views;
this.loader(plural, opts, loaders);
// wrap loaders to expose the collection and opts
utils.defineProp(opts, 'wrap', views.wrap.bind(views, opts));
opts.defaultLoader = opts.defaultLoader || 'default';
// create the actual loader function
var fn = this.compose(plural, opts);
views.forward(fn, ['forOwn']);
// forward collection methods onto loader
utils.setProto(fn, views);
// add loader methods to the instance: `app.pages()`
this.mixin(single, fn);
this.mixin(plural, fn);
// decorate named loader methods back to the collection
// to allow chaining like `.pages().pages()` etc
utils.defineProp(views, plural, fn);
utils.defineProp(views, single, fn);
// add collection and view (item) helpers
helpers.collection(this, views, opts);
helpers.view(this, views, opts);
return this;
} | javascript | function (name, opts, loaders) {
var args = utils.slice(arguments, 1);
opts = lazy.clone(args.shift());
loaders = args;
var single = lazy.inflect.singularize(name);
var plural = lazy.inflect.pluralize(name);
this.inflections[single] = plural;
if (typeof opts.renameKey === 'undefined' && this.options.renameKey) {
opts.renameKey = this.options.renameKey;
}
opts.plural = plural;
opts.inflection = single;
opts.loaders = loaders;
opts.app = this;
opts = lazy.extend({}, opts, this.options);
if (!opts.loaderType) {
opts.loaderType = 'sync';
}
var Views = this.get('Views');
var views = new Views(opts);
this.viewType(plural, views.viewType());
// add custom View constructor for collection items
var ViewClass = viewFactory(single, opts);
var classKey = single[0].toUpperCase() + single.slice(1);
this.define(classKey, ViewClass);
// init the collection object on `views`
this.views[plural] = views;
this.loader(plural, opts, loaders);
// wrap loaders to expose the collection and opts
utils.defineProp(opts, 'wrap', views.wrap.bind(views, opts));
opts.defaultLoader = opts.defaultLoader || 'default';
// create the actual loader function
var fn = this.compose(plural, opts);
views.forward(fn, ['forOwn']);
// forward collection methods onto loader
utils.setProto(fn, views);
// add loader methods to the instance: `app.pages()`
this.mixin(single, fn);
this.mixin(plural, fn);
// decorate named loader methods back to the collection
// to allow chaining like `.pages().pages()` etc
utils.defineProp(views, plural, fn);
utils.defineProp(views, single, fn);
// add collection and view (item) helpers
helpers.collection(this, views, opts);
helpers.view(this, views, opts);
return this;
} | [
"function",
"(",
"name",
",",
"opts",
",",
"loaders",
")",
"{",
"var",
"args",
"=",
"utils",
".",
"slice",
"(",
"arguments",
",",
"1",
")",
";",
"opts",
"=",
"lazy",
".",
"clone",
"(",
"args",
".",
"shift",
"(",
")",
")",
";",
"loaders",
"=",
"args",
";",
"var",
"single",
"=",
"lazy",
".",
"inflect",
".",
"singularize",
"(",
"name",
")",
";",
"var",
"plural",
"=",
"lazy",
".",
"inflect",
".",
"pluralize",
"(",
"name",
")",
";",
"this",
".",
"inflections",
"[",
"single",
"]",
"=",
"plural",
";",
"if",
"(",
"typeof",
"opts",
".",
"renameKey",
"===",
"'undefined'",
"&&",
"this",
".",
"options",
".",
"renameKey",
")",
"{",
"opts",
".",
"renameKey",
"=",
"this",
".",
"options",
".",
"renameKey",
";",
"}",
"opts",
".",
"plural",
"=",
"plural",
";",
"opts",
".",
"inflection",
"=",
"single",
";",
"opts",
".",
"loaders",
"=",
"loaders",
";",
"opts",
".",
"app",
"=",
"this",
";",
"opts",
"=",
"lazy",
".",
"extend",
"(",
"{",
"}",
",",
"opts",
",",
"this",
".",
"options",
")",
";",
"if",
"(",
"!",
"opts",
".",
"loaderType",
")",
"{",
"opts",
".",
"loaderType",
"=",
"'sync'",
";",
"}",
"var",
"Views",
"=",
"this",
".",
"get",
"(",
"'Views'",
")",
";",
"var",
"views",
"=",
"new",
"Views",
"(",
"opts",
")",
";",
"this",
".",
"viewType",
"(",
"plural",
",",
"views",
".",
"viewType",
"(",
")",
")",
";",
"// add custom View constructor for collection items",
"var",
"ViewClass",
"=",
"viewFactory",
"(",
"single",
",",
"opts",
")",
";",
"var",
"classKey",
"=",
"single",
"[",
"0",
"]",
".",
"toUpperCase",
"(",
")",
"+",
"single",
".",
"slice",
"(",
"1",
")",
";",
"this",
".",
"define",
"(",
"classKey",
",",
"ViewClass",
")",
";",
"// init the collection object on `views`",
"this",
".",
"views",
"[",
"plural",
"]",
"=",
"views",
";",
"this",
".",
"loader",
"(",
"plural",
",",
"opts",
",",
"loaders",
")",
";",
"// wrap loaders to expose the collection and opts",
"utils",
".",
"defineProp",
"(",
"opts",
",",
"'wrap'",
",",
"views",
".",
"wrap",
".",
"bind",
"(",
"views",
",",
"opts",
")",
")",
";",
"opts",
".",
"defaultLoader",
"=",
"opts",
".",
"defaultLoader",
"||",
"'default'",
";",
"// create the actual loader function",
"var",
"fn",
"=",
"this",
".",
"compose",
"(",
"plural",
",",
"opts",
")",
";",
"views",
".",
"forward",
"(",
"fn",
",",
"[",
"'forOwn'",
"]",
")",
";",
"// forward collection methods onto loader",
"utils",
".",
"setProto",
"(",
"fn",
",",
"views",
")",
";",
"// add loader methods to the instance: `app.pages()`",
"this",
".",
"mixin",
"(",
"single",
",",
"fn",
")",
";",
"this",
".",
"mixin",
"(",
"plural",
",",
"fn",
")",
";",
"// decorate named loader methods back to the collection",
"// to allow chaining like `.pages().pages()` etc",
"utils",
".",
"defineProp",
"(",
"views",
",",
"plural",
",",
"fn",
")",
";",
"utils",
".",
"defineProp",
"(",
"views",
",",
"single",
",",
"fn",
")",
";",
"// add collection and view (item) helpers",
"helpers",
".",
"collection",
"(",
"this",
",",
"views",
",",
"opts",
")",
";",
"helpers",
".",
"view",
"(",
"this",
",",
"views",
",",
"opts",
")",
";",
"return",
"this",
";",
"}"
] | Create a new `Views` collection.
```js
app.create('foo');
app.foo('*.hbs');
var view = app.foo.get('baz.hbs');
```
@name .create
@param {String} `name` The name of the collection. Plural or singular form.
@param {Object} `opts` Collection options
@param {String|Array|Function} `loaders` Loaders to use for adding views to the created collection.
@return {Object} Returns the `Assemble` instance for chaining.
@api public | [
"Create",
"a",
"new",
"Views",
"collection",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/index.js#L229-L289 | |
26,256 | jonschlinkert/template | index.js | function (method, view, locals, cb) {
if (typeof locals === 'function') {
cb = locals;
locals = {};
}
this.lazyRouter();
view.options = view.options || {};
view.options.handled = view.options.handled || [];
if (typeof cb !== 'function') {
cb = this.handleError(method, view);
}
view.options.method = method;
view.options.handled.push(method);
if (view.emit) {
view.emit('handle', method);
}
this.router.handle(view, function (err) {
if (err) return cb(err);
cb(null, view);
});
} | javascript | function (method, view, locals, cb) {
if (typeof locals === 'function') {
cb = locals;
locals = {};
}
this.lazyRouter();
view.options = view.options || {};
view.options.handled = view.options.handled || [];
if (typeof cb !== 'function') {
cb = this.handleError(method, view);
}
view.options.method = method;
view.options.handled.push(method);
if (view.emit) {
view.emit('handle', method);
}
this.router.handle(view, function (err) {
if (err) return cb(err);
cb(null, view);
});
} | [
"function",
"(",
"method",
",",
"view",
",",
"locals",
",",
"cb",
")",
"{",
"if",
"(",
"typeof",
"locals",
"===",
"'function'",
")",
"{",
"cb",
"=",
"locals",
";",
"locals",
"=",
"{",
"}",
";",
"}",
"this",
".",
"lazyRouter",
"(",
")",
";",
"view",
".",
"options",
"=",
"view",
".",
"options",
"||",
"{",
"}",
";",
"view",
".",
"options",
".",
"handled",
"=",
"view",
".",
"options",
".",
"handled",
"||",
"[",
"]",
";",
"if",
"(",
"typeof",
"cb",
"!==",
"'function'",
")",
"{",
"cb",
"=",
"this",
".",
"handleError",
"(",
"method",
",",
"view",
")",
";",
"}",
"view",
".",
"options",
".",
"method",
"=",
"method",
";",
"view",
".",
"options",
".",
"handled",
".",
"push",
"(",
"method",
")",
";",
"if",
"(",
"view",
".",
"emit",
")",
"{",
"view",
".",
"emit",
"(",
"'handle'",
",",
"method",
")",
";",
"}",
"this",
".",
"router",
".",
"handle",
"(",
"view",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"return",
"cb",
"(",
"err",
")",
";",
"cb",
"(",
"null",
",",
"view",
")",
";",
"}",
")",
";",
"}"
] | Handle middleware for the given `view` and locals.
```js
app.handle('customHandle', view);
```
@name .handle
@param {String} `method` Router VERB
@param {Object} `view` View object
@param {Object} `locals`
@param {Function} `cb`
@return {Object}
@api public | [
"Handle",
"middleware",
"for",
"the",
"given",
"view",
"and",
"locals",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/index.js#L345-L369 | |
26,257 | jonschlinkert/template | index.js | function (method, view, locals/*, cb*/) {
if (view.options.handled.indexOf(method) === -1) {
this.handle.apply(this, arguments);
}
this.emit(method, view, locals);
} | javascript | function (method, view, locals/*, cb*/) {
if (view.options.handled.indexOf(method) === -1) {
this.handle.apply(this, arguments);
}
this.emit(method, view, locals);
} | [
"function",
"(",
"method",
",",
"view",
",",
"locals",
"/*, cb*/",
")",
"{",
"if",
"(",
"view",
".",
"options",
".",
"handled",
".",
"indexOf",
"(",
"method",
")",
"===",
"-",
"1",
")",
"{",
"this",
".",
"handle",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"}",
"this",
".",
"emit",
"(",
"method",
",",
"view",
",",
"locals",
")",
";",
"}"
] | Run the given handler only if the view has not
already been handled by the method
@name .handleView
@param {Object} `collection` Collection name
@param {Object} `locals`
@return {Array} Returns an array of view objects with rendered content. | [
"Run",
"the",
"given",
"handler",
"only",
"if",
"the",
"view",
"has",
"not",
"already",
"been",
"handled",
"by",
"the",
"method"
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/index.js#L381-L386 | |
26,258 | jonschlinkert/template | index.js | function(method, view) {
return function (err) {
if (err) {
err.reason = 'Template#handle' + method + ': ' + view.path;
return err;
}
};
} | javascript | function(method, view) {
return function (err) {
if (err) {
err.reason = 'Template#handle' + method + ': ' + view.path;
return err;
}
};
} | [
"function",
"(",
"method",
",",
"view",
")",
"{",
"return",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"err",
".",
"reason",
"=",
"'Template#handle'",
"+",
"method",
"+",
"': '",
"+",
"view",
".",
"path",
";",
"return",
"err",
";",
"}",
"}",
";",
"}"
] | Handle middleware errors. | [
"Handle",
"middleware",
"errors",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/index.js#L392-L399 | |
26,259 | jonschlinkert/template | index.js | function(path/*, callback*/) {
this.lazyRouter();
var route = this.router.route(path);
route.all.apply(route, [].slice.call(arguments, 1));
return this;
} | javascript | function(path/*, callback*/) {
this.lazyRouter();
var route = this.router.route(path);
route.all.apply(route, [].slice.call(arguments, 1));
return this;
} | [
"function",
"(",
"path",
"/*, callback*/",
")",
"{",
"this",
".",
"lazyRouter",
"(",
")",
";",
"var",
"route",
"=",
"this",
".",
"router",
".",
"route",
"(",
"path",
")",
";",
"route",
".",
"all",
".",
"apply",
"(",
"route",
",",
"[",
"]",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"1",
")",
")",
";",
"return",
"this",
";",
"}"
] | Special-cased "all" method, applying the given route `path`,
middleware, and callback.
@name .all
@param {String} `path`
@param {Function} `callback`
@return {Object} `this` for chaining | [
"Special",
"-",
"cased",
"all",
"method",
"applying",
"the",
"given",
"route",
"path",
"middleware",
"and",
"callback",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/index.js#L411-L416 | |
26,260 | jonschlinkert/template | index.js | function(view) {
if (view.options.layoutApplied) {
return view;
}
// handle pre-layout middleware
this.handle('preLayout', view);
var opts = {};
lazy.extend(opts, this.options);
lazy.extend(opts, view.options);
lazy.extend(opts, view.context());
// get the layout stack
var stack = {};
var alias = this.viewTypes.layout;
var len = alias.length, i = 0;
while (len--) {
var views = this.views[alias[i++]];
for (var key in views) {
var val = views[key];
if (views.hasOwnProperty(key) && typeof val !== 'function' && val.path) {
stack[key] = val;
}
}
}
// get the name of the first layout
var name = view.layout;
var str = view.content;
var self = this;
if (!name) return view;
// Handle each layout before it's applied to a view
function handleLayout(layoutObj) {
view.currentLayout = layoutObj.layout;
self.handle('onLayout', view);
delete view.currentLayout;
}
// actually apply the layout
var res = lazy.layouts(str, name, stack, opts, handleLayout);
view.option('layoutStack', res.history);
view.option('layoutApplied', true);
view.content = res.result;
// handle post-layout middleware
this.handle('postLayout', view);
return view;
} | javascript | function(view) {
if (view.options.layoutApplied) {
return view;
}
// handle pre-layout middleware
this.handle('preLayout', view);
var opts = {};
lazy.extend(opts, this.options);
lazy.extend(opts, view.options);
lazy.extend(opts, view.context());
// get the layout stack
var stack = {};
var alias = this.viewTypes.layout;
var len = alias.length, i = 0;
while (len--) {
var views = this.views[alias[i++]];
for (var key in views) {
var val = views[key];
if (views.hasOwnProperty(key) && typeof val !== 'function' && val.path) {
stack[key] = val;
}
}
}
// get the name of the first layout
var name = view.layout;
var str = view.content;
var self = this;
if (!name) return view;
// Handle each layout before it's applied to a view
function handleLayout(layoutObj) {
view.currentLayout = layoutObj.layout;
self.handle('onLayout', view);
delete view.currentLayout;
}
// actually apply the layout
var res = lazy.layouts(str, name, stack, opts, handleLayout);
view.option('layoutStack', res.history);
view.option('layoutApplied', true);
view.content = res.result;
// handle post-layout middleware
this.handle('postLayout', view);
return view;
} | [
"function",
"(",
"view",
")",
"{",
"if",
"(",
"view",
".",
"options",
".",
"layoutApplied",
")",
"{",
"return",
"view",
";",
"}",
"// handle pre-layout middleware",
"this",
".",
"handle",
"(",
"'preLayout'",
",",
"view",
")",
";",
"var",
"opts",
"=",
"{",
"}",
";",
"lazy",
".",
"extend",
"(",
"opts",
",",
"this",
".",
"options",
")",
";",
"lazy",
".",
"extend",
"(",
"opts",
",",
"view",
".",
"options",
")",
";",
"lazy",
".",
"extend",
"(",
"opts",
",",
"view",
".",
"context",
"(",
")",
")",
";",
"// get the layout stack",
"var",
"stack",
"=",
"{",
"}",
";",
"var",
"alias",
"=",
"this",
".",
"viewTypes",
".",
"layout",
";",
"var",
"len",
"=",
"alias",
".",
"length",
",",
"i",
"=",
"0",
";",
"while",
"(",
"len",
"--",
")",
"{",
"var",
"views",
"=",
"this",
".",
"views",
"[",
"alias",
"[",
"i",
"++",
"]",
"]",
";",
"for",
"(",
"var",
"key",
"in",
"views",
")",
"{",
"var",
"val",
"=",
"views",
"[",
"key",
"]",
";",
"if",
"(",
"views",
".",
"hasOwnProperty",
"(",
"key",
")",
"&&",
"typeof",
"val",
"!==",
"'function'",
"&&",
"val",
".",
"path",
")",
"{",
"stack",
"[",
"key",
"]",
"=",
"val",
";",
"}",
"}",
"}",
"// get the name of the first layout",
"var",
"name",
"=",
"view",
".",
"layout",
";",
"var",
"str",
"=",
"view",
".",
"content",
";",
"var",
"self",
"=",
"this",
";",
"if",
"(",
"!",
"name",
")",
"return",
"view",
";",
"// Handle each layout before it's applied to a view",
"function",
"handleLayout",
"(",
"layoutObj",
")",
"{",
"view",
".",
"currentLayout",
"=",
"layoutObj",
".",
"layout",
";",
"self",
".",
"handle",
"(",
"'onLayout'",
",",
"view",
")",
";",
"delete",
"view",
".",
"currentLayout",
";",
"}",
"// actually apply the layout",
"var",
"res",
"=",
"lazy",
".",
"layouts",
"(",
"str",
",",
"name",
",",
"stack",
",",
"opts",
",",
"handleLayout",
")",
";",
"view",
".",
"option",
"(",
"'layoutStack'",
",",
"res",
".",
"history",
")",
";",
"view",
".",
"option",
"(",
"'layoutApplied'",
",",
"true",
")",
";",
"view",
".",
"content",
"=",
"res",
".",
"result",
";",
"// handle post-layout middleware",
"this",
".",
"handle",
"(",
"'postLayout'",
",",
"view",
")",
";",
"return",
"view",
";",
"}"
] | Apply a layout to the given `view`.
@name .applyLayout
@param {Object} `view`
@return {Object} Returns a `view` object. | [
"Apply",
"a",
"layout",
"to",
"the",
"given",
"view",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/index.js#L441-L493 | |
26,261 | jonschlinkert/template | index.js | function(view, locals, isAsync) {
if (typeof locals === 'boolean') {
isAsync = locals;
locals = {};
}
// get the engine to use
locals = locals || {};
var engine = this.engine(locals.engine ? locals.engine : view.engine);
if (typeof engine === 'undefined') {
throw this.error('compile', 'engine', view);
}
if (!engine.hasOwnProperty('compile')) {
throw this.error('compile', 'method', engine);
}
view.ctx('compile', locals);
// build the context to pass to the engine
var ctx = view.context(locals);
// apply layout
view = this.applyLayout(view, ctx);
// handle `preCompile` middleware
this.handleView('preCompile', view, locals);
// Bind context to helpers before passing to the engine.
this.bindHelpers(view, locals, ctx, (locals.async = isAsync));
var settings = lazy.extend({}, ctx, locals);
// compile the string
view.fn = engine.compile(view.content, settings);
// handle `postCompile` middleware
this.handleView('postCompile', view, locals);
return view;
} | javascript | function(view, locals, isAsync) {
if (typeof locals === 'boolean') {
isAsync = locals;
locals = {};
}
// get the engine to use
locals = locals || {};
var engine = this.engine(locals.engine ? locals.engine : view.engine);
if (typeof engine === 'undefined') {
throw this.error('compile', 'engine', view);
}
if (!engine.hasOwnProperty('compile')) {
throw this.error('compile', 'method', engine);
}
view.ctx('compile', locals);
// build the context to pass to the engine
var ctx = view.context(locals);
// apply layout
view = this.applyLayout(view, ctx);
// handle `preCompile` middleware
this.handleView('preCompile', view, locals);
// Bind context to helpers before passing to the engine.
this.bindHelpers(view, locals, ctx, (locals.async = isAsync));
var settings = lazy.extend({}, ctx, locals);
// compile the string
view.fn = engine.compile(view.content, settings);
// handle `postCompile` middleware
this.handleView('postCompile', view, locals);
return view;
} | [
"function",
"(",
"view",
",",
"locals",
",",
"isAsync",
")",
"{",
"if",
"(",
"typeof",
"locals",
"===",
"'boolean'",
")",
"{",
"isAsync",
"=",
"locals",
";",
"locals",
"=",
"{",
"}",
";",
"}",
"// get the engine to use",
"locals",
"=",
"locals",
"||",
"{",
"}",
";",
"var",
"engine",
"=",
"this",
".",
"engine",
"(",
"locals",
".",
"engine",
"?",
"locals",
".",
"engine",
":",
"view",
".",
"engine",
")",
";",
"if",
"(",
"typeof",
"engine",
"===",
"'undefined'",
")",
"{",
"throw",
"this",
".",
"error",
"(",
"'compile'",
",",
"'engine'",
",",
"view",
")",
";",
"}",
"if",
"(",
"!",
"engine",
".",
"hasOwnProperty",
"(",
"'compile'",
")",
")",
"{",
"throw",
"this",
".",
"error",
"(",
"'compile'",
",",
"'method'",
",",
"engine",
")",
";",
"}",
"view",
".",
"ctx",
"(",
"'compile'",
",",
"locals",
")",
";",
"// build the context to pass to the engine",
"var",
"ctx",
"=",
"view",
".",
"context",
"(",
"locals",
")",
";",
"// apply layout",
"view",
"=",
"this",
".",
"applyLayout",
"(",
"view",
",",
"ctx",
")",
";",
"// handle `preCompile` middleware",
"this",
".",
"handleView",
"(",
"'preCompile'",
",",
"view",
",",
"locals",
")",
";",
"// Bind context to helpers before passing to the engine.",
"this",
".",
"bindHelpers",
"(",
"view",
",",
"locals",
",",
"ctx",
",",
"(",
"locals",
".",
"async",
"=",
"isAsync",
")",
")",
";",
"var",
"settings",
"=",
"lazy",
".",
"extend",
"(",
"{",
"}",
",",
"ctx",
",",
"locals",
")",
";",
"// compile the string",
"view",
".",
"fn",
"=",
"engine",
".",
"compile",
"(",
"view",
".",
"content",
",",
"settings",
")",
";",
"// handle `postCompile` middleware",
"this",
".",
"handleView",
"(",
"'postCompile'",
",",
"view",
",",
"locals",
")",
";",
"return",
"view",
";",
"}"
] | Compile `content` with the given `locals`.
```js
var blogPost = app.post('2015-09-01-foo-bar');
var view = app.compile(blogPost);
// view.fn => [function]
```
@name .compile
@param {Object|String} `view` View object.
@param {Object} `locals`
@param {Boolean} `isAsync` Load async helpers
@return {Object} View object with `fn` property with the compiled function.
@api public | [
"Compile",
"content",
"with",
"the",
"given",
"locals",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/index.js#L512-L546 | |
26,262 | jonschlinkert/template | index.js | function (view, locals, cb) {
if (typeof locals === 'function') {
cb = locals;
locals = {};
}
// if `view` is a function, it's probably from chaining
// a collection method
if (typeof view === 'function') {
return view.call(this);
}
// if `view` is a string, see if it's a cache view
if (typeof view === 'string') {
view = this.lookup(view);
}
locals = locals || {};
// add `locals` to `view.contexts`
view.ctx('render', locals);
var data = this.cache.data;
for (var key in locals) {
if (locals.hasOwnProperty(key) && !data.hasOwnProperty(key)) {
data[key] = locals[key];
}
}
// handle `preRender` middleware
this.handleView('preRender', view, locals);
// build the context for the view
var ctx = this.context(locals);
// get the engine
var engine = this.engine(locals.engine ? locals.engine : view.engine);
if (typeof cb !== 'function') {
throw this.error('render', 'callback');
}
if (typeof engine === 'undefined') {
throw this.error('render', 'engine', path.extname(view.path));
}
if (!engine.hasOwnProperty('render')) {
throw this.error('render', 'method', JSON.stringify(view));
}
// if it's not already compiled, do that first
if (typeof view.fn !== 'function') {
try {
var isAsync = typeof cb === 'function';
view = this.compile(view, locals, isAsync);
return this.render(view, locals, cb);
} catch (err) {
this.emit('error', err);
return cb.call(this, err);
}
}
var context = this.context(view, ctx, locals);
// render the view
return engine.render(view.fn, context, function (err, res) {
if (err) {
this.emit('error', err);
return cb.call(this, err);
}
// handle `postRender` middleware
view.content = res;
this.handle('postRender', view, locals, cb);
}.bind(this));
} | javascript | function (view, locals, cb) {
if (typeof locals === 'function') {
cb = locals;
locals = {};
}
// if `view` is a function, it's probably from chaining
// a collection method
if (typeof view === 'function') {
return view.call(this);
}
// if `view` is a string, see if it's a cache view
if (typeof view === 'string') {
view = this.lookup(view);
}
locals = locals || {};
// add `locals` to `view.contexts`
view.ctx('render', locals);
var data = this.cache.data;
for (var key in locals) {
if (locals.hasOwnProperty(key) && !data.hasOwnProperty(key)) {
data[key] = locals[key];
}
}
// handle `preRender` middleware
this.handleView('preRender', view, locals);
// build the context for the view
var ctx = this.context(locals);
// get the engine
var engine = this.engine(locals.engine ? locals.engine : view.engine);
if (typeof cb !== 'function') {
throw this.error('render', 'callback');
}
if (typeof engine === 'undefined') {
throw this.error('render', 'engine', path.extname(view.path));
}
if (!engine.hasOwnProperty('render')) {
throw this.error('render', 'method', JSON.stringify(view));
}
// if it's not already compiled, do that first
if (typeof view.fn !== 'function') {
try {
var isAsync = typeof cb === 'function';
view = this.compile(view, locals, isAsync);
return this.render(view, locals, cb);
} catch (err) {
this.emit('error', err);
return cb.call(this, err);
}
}
var context = this.context(view, ctx, locals);
// render the view
return engine.render(view.fn, context, function (err, res) {
if (err) {
this.emit('error', err);
return cb.call(this, err);
}
// handle `postRender` middleware
view.content = res;
this.handle('postRender', view, locals, cb);
}.bind(this));
} | [
"function",
"(",
"view",
",",
"locals",
",",
"cb",
")",
"{",
"if",
"(",
"typeof",
"locals",
"===",
"'function'",
")",
"{",
"cb",
"=",
"locals",
";",
"locals",
"=",
"{",
"}",
";",
"}",
"// if `view` is a function, it's probably from chaining",
"// a collection method",
"if",
"(",
"typeof",
"view",
"===",
"'function'",
")",
"{",
"return",
"view",
".",
"call",
"(",
"this",
")",
";",
"}",
"// if `view` is a string, see if it's a cache view",
"if",
"(",
"typeof",
"view",
"===",
"'string'",
")",
"{",
"view",
"=",
"this",
".",
"lookup",
"(",
"view",
")",
";",
"}",
"locals",
"=",
"locals",
"||",
"{",
"}",
";",
"// add `locals` to `view.contexts`",
"view",
".",
"ctx",
"(",
"'render'",
",",
"locals",
")",
";",
"var",
"data",
"=",
"this",
".",
"cache",
".",
"data",
";",
"for",
"(",
"var",
"key",
"in",
"locals",
")",
"{",
"if",
"(",
"locals",
".",
"hasOwnProperty",
"(",
"key",
")",
"&&",
"!",
"data",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"data",
"[",
"key",
"]",
"=",
"locals",
"[",
"key",
"]",
";",
"}",
"}",
"// handle `preRender` middleware",
"this",
".",
"handleView",
"(",
"'preRender'",
",",
"view",
",",
"locals",
")",
";",
"// build the context for the view",
"var",
"ctx",
"=",
"this",
".",
"context",
"(",
"locals",
")",
";",
"// get the engine",
"var",
"engine",
"=",
"this",
".",
"engine",
"(",
"locals",
".",
"engine",
"?",
"locals",
".",
"engine",
":",
"view",
".",
"engine",
")",
";",
"if",
"(",
"typeof",
"cb",
"!==",
"'function'",
")",
"{",
"throw",
"this",
".",
"error",
"(",
"'render'",
",",
"'callback'",
")",
";",
"}",
"if",
"(",
"typeof",
"engine",
"===",
"'undefined'",
")",
"{",
"throw",
"this",
".",
"error",
"(",
"'render'",
",",
"'engine'",
",",
"path",
".",
"extname",
"(",
"view",
".",
"path",
")",
")",
";",
"}",
"if",
"(",
"!",
"engine",
".",
"hasOwnProperty",
"(",
"'render'",
")",
")",
"{",
"throw",
"this",
".",
"error",
"(",
"'render'",
",",
"'method'",
",",
"JSON",
".",
"stringify",
"(",
"view",
")",
")",
";",
"}",
"// if it's not already compiled, do that first",
"if",
"(",
"typeof",
"view",
".",
"fn",
"!==",
"'function'",
")",
"{",
"try",
"{",
"var",
"isAsync",
"=",
"typeof",
"cb",
"===",
"'function'",
";",
"view",
"=",
"this",
".",
"compile",
"(",
"view",
",",
"locals",
",",
"isAsync",
")",
";",
"return",
"this",
".",
"render",
"(",
"view",
",",
"locals",
",",
"cb",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"this",
".",
"emit",
"(",
"'error'",
",",
"err",
")",
";",
"return",
"cb",
".",
"call",
"(",
"this",
",",
"err",
")",
";",
"}",
"}",
"var",
"context",
"=",
"this",
".",
"context",
"(",
"view",
",",
"ctx",
",",
"locals",
")",
";",
"// render the view",
"return",
"engine",
".",
"render",
"(",
"view",
".",
"fn",
",",
"context",
",",
"function",
"(",
"err",
",",
"res",
")",
"{",
"if",
"(",
"err",
")",
"{",
"this",
".",
"emit",
"(",
"'error'",
",",
"err",
")",
";",
"return",
"cb",
".",
"call",
"(",
"this",
",",
"err",
")",
";",
"}",
"// handle `postRender` middleware",
"view",
".",
"content",
"=",
"res",
";",
"this",
".",
"handle",
"(",
"'postRender'",
",",
"view",
",",
"locals",
",",
"cb",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
")",
";",
"}"
] | Render `content` with the given `locals` and `callback`.
```js
var blogPost = app.post('2015-09-01-foo-bar');
app.render(blogPost, function(err, view) {
// `view` is an object with a rendered `content` property
});
```
@name .render
@param {Object|String} `file` String or normalized template object.
@param {Object} `locals` Locals to pass to registered view engines.
@param {Function} `callback`
@api public | [
"Render",
"content",
"with",
"the",
"given",
"locals",
"and",
"callback",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/index.js#L565-L636 | |
26,263 | jonschlinkert/template | index.js | function (locals, viewTypes) {
var names = viewTypes || this.viewTypes.partial;
var opts = lazy.extend({}, this.options, locals);
return names.reduce(function (acc, name) {
var collection = this.views[name];
lazy.forOwn(collection, function (view, key) {
// handle `onMerge` middleware
this.handleView('onMerge', view, locals);
if (view.options.nomerge) return;
if (opts.mergePartials !== false) {
name = 'partials';
}
acc[name] = acc[name] || {};
acc[name][key] = view.content;
}, this);
return acc;
}.bind(this), {});
} | javascript | function (locals, viewTypes) {
var names = viewTypes || this.viewTypes.partial;
var opts = lazy.extend({}, this.options, locals);
return names.reduce(function (acc, name) {
var collection = this.views[name];
lazy.forOwn(collection, function (view, key) {
// handle `onMerge` middleware
this.handleView('onMerge', view, locals);
if (view.options.nomerge) return;
if (opts.mergePartials !== false) {
name = 'partials';
}
acc[name] = acc[name] || {};
acc[name][key] = view.content;
}, this);
return acc;
}.bind(this), {});
} | [
"function",
"(",
"locals",
",",
"viewTypes",
")",
"{",
"var",
"names",
"=",
"viewTypes",
"||",
"this",
".",
"viewTypes",
".",
"partial",
";",
"var",
"opts",
"=",
"lazy",
".",
"extend",
"(",
"{",
"}",
",",
"this",
".",
"options",
",",
"locals",
")",
";",
"return",
"names",
".",
"reduce",
"(",
"function",
"(",
"acc",
",",
"name",
")",
"{",
"var",
"collection",
"=",
"this",
".",
"views",
"[",
"name",
"]",
";",
"lazy",
".",
"forOwn",
"(",
"collection",
",",
"function",
"(",
"view",
",",
"key",
")",
"{",
"// handle `onMerge` middleware",
"this",
".",
"handleView",
"(",
"'onMerge'",
",",
"view",
",",
"locals",
")",
";",
"if",
"(",
"view",
".",
"options",
".",
"nomerge",
")",
"return",
";",
"if",
"(",
"opts",
".",
"mergePartials",
"!==",
"false",
")",
"{",
"name",
"=",
"'partials'",
";",
"}",
"acc",
"[",
"name",
"]",
"=",
"acc",
"[",
"name",
"]",
"||",
"{",
"}",
";",
"acc",
"[",
"name",
"]",
"[",
"key",
"]",
"=",
"view",
".",
"content",
";",
"}",
",",
"this",
")",
";",
"return",
"acc",
";",
"}",
".",
"bind",
"(",
"this",
")",
",",
"{",
"}",
")",
";",
"}"
] | Merge "partials" view types. This is necessary for template
engines that only support one class of partials.
@name .mergePartials
@param {Object} `locals`
@param {Array} `viewTypes` Optionally pass an array of viewTypes to include.
@return {Object} Merged partials | [
"Merge",
"partials",
"view",
"types",
".",
"This",
"is",
"necessary",
"for",
"template",
"engines",
"that",
"only",
"support",
"one",
"class",
"of",
"partials",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/index.js#L648-L668 | |
26,264 | jonschlinkert/template | index.js | function (view, ctx, locals) {
var obj = {};
lazy.mixin(obj, ctx);
lazy.mixin(obj, this.cache.data);
lazy.mixin(obj, view.data);
lazy.mixin(obj, view.locals);
lazy.mixin(obj, locals);
return obj;
} | javascript | function (view, ctx, locals) {
var obj = {};
lazy.mixin(obj, ctx);
lazy.mixin(obj, this.cache.data);
lazy.mixin(obj, view.data);
lazy.mixin(obj, view.locals);
lazy.mixin(obj, locals);
return obj;
} | [
"function",
"(",
"view",
",",
"ctx",
",",
"locals",
")",
"{",
"var",
"obj",
"=",
"{",
"}",
";",
"lazy",
".",
"mixin",
"(",
"obj",
",",
"ctx",
")",
";",
"lazy",
".",
"mixin",
"(",
"obj",
",",
"this",
".",
"cache",
".",
"data",
")",
";",
"lazy",
".",
"mixin",
"(",
"obj",
",",
"view",
".",
"data",
")",
";",
"lazy",
".",
"mixin",
"(",
"obj",
",",
"view",
".",
"locals",
")",
";",
"lazy",
".",
"mixin",
"(",
"obj",
",",
"locals",
")",
";",
"return",
"obj",
";",
"}"
] | Build the context for the given `view` and `locals`.
This can be overridden by passing a function to the
`mergeContext` option.
@name .context
@param {Object} `view` Template object
@param {Object} `locals`
@return {Object} The object to be passed to engines/views as context. | [
"Build",
"the",
"context",
"for",
"the",
"given",
"view",
"and",
"locals",
".",
"This",
"can",
"be",
"overridden",
"by",
"passing",
"a",
"function",
"to",
"the",
"mergeContext",
"option",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/index.js#L681-L689 | |
26,265 | jonschlinkert/template | index.js | function (view, locals, context, isAsync) {
var helpers = {};
lazy.extend(helpers, this.options.helpers);
lazy.extend(helpers, this._.helpers.sync);
if (isAsync) lazy.extend(helpers, this._.helpers.async);
lazy.extend(helpers, locals.helpers);
// build the context to expose as `this` in helpers
var thisArg = {};
thisArg.options = lazy.extend({}, this.options, locals);
thisArg.context = context || {};
thisArg.context.view = view;
thisArg.app = this;
// bind template helpers to the instance
locals.helpers = utils.bindAll(helpers, thisArg);
} | javascript | function (view, locals, context, isAsync) {
var helpers = {};
lazy.extend(helpers, this.options.helpers);
lazy.extend(helpers, this._.helpers.sync);
if (isAsync) lazy.extend(helpers, this._.helpers.async);
lazy.extend(helpers, locals.helpers);
// build the context to expose as `this` in helpers
var thisArg = {};
thisArg.options = lazy.extend({}, this.options, locals);
thisArg.context = context || {};
thisArg.context.view = view;
thisArg.app = this;
// bind template helpers to the instance
locals.helpers = utils.bindAll(helpers, thisArg);
} | [
"function",
"(",
"view",
",",
"locals",
",",
"context",
",",
"isAsync",
")",
"{",
"var",
"helpers",
"=",
"{",
"}",
";",
"lazy",
".",
"extend",
"(",
"helpers",
",",
"this",
".",
"options",
".",
"helpers",
")",
";",
"lazy",
".",
"extend",
"(",
"helpers",
",",
"this",
".",
"_",
".",
"helpers",
".",
"sync",
")",
";",
"if",
"(",
"isAsync",
")",
"lazy",
".",
"extend",
"(",
"helpers",
",",
"this",
".",
"_",
".",
"helpers",
".",
"async",
")",
";",
"lazy",
".",
"extend",
"(",
"helpers",
",",
"locals",
".",
"helpers",
")",
";",
"// build the context to expose as `this` in helpers",
"var",
"thisArg",
"=",
"{",
"}",
";",
"thisArg",
".",
"options",
"=",
"lazy",
".",
"extend",
"(",
"{",
"}",
",",
"this",
".",
"options",
",",
"locals",
")",
";",
"thisArg",
".",
"context",
"=",
"context",
"||",
"{",
"}",
";",
"thisArg",
".",
"context",
".",
"view",
"=",
"view",
";",
"thisArg",
".",
"app",
"=",
"this",
";",
"// bind template helpers to the instance",
"locals",
".",
"helpers",
"=",
"utils",
".",
"bindAll",
"(",
"helpers",
",",
"thisArg",
")",
";",
"}"
] | Build the context for the given `view` and `locals`. | [
"Build",
"the",
"context",
"for",
"the",
"given",
"view",
"and",
"locals",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/index.js#L695-L712 | |
26,266 | jonschlinkert/template | index.js | function (methods) {
this.lazyRouter();
this.router.method(methods);
utils.arrayify(methods).forEach(function (method) {
this.define(method, function(path) {
var route = this.router.route(path);
var args = [].slice.call(arguments, 1);
route[method].apply(route, args);
return this;
}.bind(this));
}.bind(this));
} | javascript | function (methods) {
this.lazyRouter();
this.router.method(methods);
utils.arrayify(methods).forEach(function (method) {
this.define(method, function(path) {
var route = this.router.route(path);
var args = [].slice.call(arguments, 1);
route[method].apply(route, args);
return this;
}.bind(this));
}.bind(this));
} | [
"function",
"(",
"methods",
")",
"{",
"this",
".",
"lazyRouter",
"(",
")",
";",
"this",
".",
"router",
".",
"method",
"(",
"methods",
")",
";",
"utils",
".",
"arrayify",
"(",
"methods",
")",
".",
"forEach",
"(",
"function",
"(",
"method",
")",
"{",
"this",
".",
"define",
"(",
"method",
",",
"function",
"(",
"path",
")",
"{",
"var",
"route",
"=",
"this",
".",
"router",
".",
"route",
"(",
"path",
")",
";",
"var",
"args",
"=",
"[",
"]",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"1",
")",
";",
"route",
"[",
"method",
"]",
".",
"apply",
"(",
"route",
",",
"args",
")",
";",
"return",
"this",
";",
"}",
".",
"bind",
"(",
"this",
")",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
")",
";",
"}"
] | Add default Router handlers to Template. | [
"Add",
"default",
"Router",
"handlers",
"to",
"Template",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/index.js#L728-L739 | |
26,267 | jonschlinkert/template | lib/lookup.js | function(collection, pattern, options) {
var views = this.getViews(collection);
if (views.hasOwnProperty(pattern)) {
return views[pattern];
}
return utils.matchKey(views, pattern, options);
} | javascript | function(collection, pattern, options) {
var views = this.getViews(collection);
if (views.hasOwnProperty(pattern)) {
return views[pattern];
}
return utils.matchKey(views, pattern, options);
} | [
"function",
"(",
"collection",
",",
"pattern",
",",
"options",
")",
"{",
"var",
"views",
"=",
"this",
".",
"getViews",
"(",
"collection",
")",
";",
"if",
"(",
"views",
".",
"hasOwnProperty",
"(",
"pattern",
")",
")",
"{",
"return",
"views",
"[",
"pattern",
"]",
";",
"}",
"return",
"utils",
".",
"matchKey",
"(",
"views",
",",
"pattern",
",",
"options",
")",
";",
"}"
] | Returns the first template from the given collection with a key
that matches the given glob pattern.
```js
var pages = app.matchView('pages', 'home.*');
//=> {'home.hbs': { ... }, ...}
var posts = app.matchView('posts', '2010-*');
//=> {'2015-10-10.md': { ... }, ...}
```
@param {String} `collection` Collection name.
@param {String} `pattern` glob pattern
@param {Object} `options` options to pass to [micromatch]
@return {Object}
@api public | [
"Returns",
"the",
"first",
"template",
"from",
"the",
"given",
"collection",
"with",
"a",
"key",
"that",
"matches",
"the",
"given",
"glob",
"pattern",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/lookup.js#L34-L40 | |
26,268 | jonschlinkert/template | lib/lookup.js | function(collection, pattern, options) {
var views = this.getViews(collection);
return utils.matchKeys(views, pattern, options);
} | javascript | function(collection, pattern, options) {
var views = this.getViews(collection);
return utils.matchKeys(views, pattern, options);
} | [
"function",
"(",
"collection",
",",
"pattern",
",",
"options",
")",
"{",
"var",
"views",
"=",
"this",
".",
"getViews",
"(",
"collection",
")",
";",
"return",
"utils",
".",
"matchKeys",
"(",
"views",
",",
"pattern",
",",
"options",
")",
";",
"}"
] | Returns any templates from the specified collection with keys
that match the given glob pattern.
```js
var pages = app.matchViews('pages', 'home.*');
//=> {'home.hbs': { ... }, ...}
var posts = app.matchViews('posts', '2010-*');
//=> {'2015-10-10.md': { ... }, ...}
```
@param {String} `collection` Collection name.
@param {String} `pattern` glob pattern
@param {Object} `options` options to pass to [micromatch]
@return {Object}
@api public | [
"Returns",
"any",
"templates",
"from",
"the",
"specified",
"collection",
"with",
"keys",
"that",
"match",
"the",
"given",
"glob",
"pattern",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/lookup.js#L61-L64 | |
26,269 | jonschlinkert/template | lib/lookup.js | function(collection, key, fn) {
var views = this.getViews(collection);
// if a custom renameKey function is passed, try using it
if (typeof fn === 'function') {
key = fn(key);
}
if (views.hasOwnProperty(key)) {
return views[key];
}
// try again with the default renameKey function
fn = this.option('renameKey');
var name;
if (typeof fn === 'function') {
name = fn(key);
}
if (name && name !== key && views.hasOwnProperty(name)) {
return views[name];
}
return null;
} | javascript | function(collection, key, fn) {
var views = this.getViews(collection);
// if a custom renameKey function is passed, try using it
if (typeof fn === 'function') {
key = fn(key);
}
if (views.hasOwnProperty(key)) {
return views[key];
}
// try again with the default renameKey function
fn = this.option('renameKey');
var name;
if (typeof fn === 'function') {
name = fn(key);
}
if (name && name !== key && views.hasOwnProperty(name)) {
return views[name];
}
return null;
} | [
"function",
"(",
"collection",
",",
"key",
",",
"fn",
")",
"{",
"var",
"views",
"=",
"this",
".",
"getViews",
"(",
"collection",
")",
";",
"// if a custom renameKey function is passed, try using it",
"if",
"(",
"typeof",
"fn",
"===",
"'function'",
")",
"{",
"key",
"=",
"fn",
"(",
"key",
")",
";",
"}",
"if",
"(",
"views",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"return",
"views",
"[",
"key",
"]",
";",
"}",
"// try again with the default renameKey function",
"fn",
"=",
"this",
".",
"option",
"(",
"'renameKey'",
")",
";",
"var",
"name",
";",
"if",
"(",
"typeof",
"fn",
"===",
"'function'",
")",
"{",
"name",
"=",
"fn",
"(",
"key",
")",
";",
"}",
"if",
"(",
"name",
"&&",
"name",
"!==",
"key",
"&&",
"views",
".",
"hasOwnProperty",
"(",
"name",
")",
")",
"{",
"return",
"views",
"[",
"name",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Get a specific template from the specified collection.
```js
app.getView('pages', 'a.hbs', function(fp) {
return path.basename(fp);
});
```
@param {String} `collectionName` Collection name, like `pages`
@param {String} `key` Template name
@param {Function} `fn` Optionally pass a `renameKey` function
@return {Object}
@api public | [
"Get",
"a",
"specific",
"template",
"from",
"the",
"specified",
"collection",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/lookup.js#L82-L101 | |
26,270 | jonschlinkert/template | lib/lookup.js | function(plural) {
if (lazy.isObject(plural)) return plural;
if (!this.views.hasOwnProperty(plural)) {
plural = this.inflections[plural];
}
if (!this.views.hasOwnProperty(plural)) {
throw new Error('getViews cannot find collection' + plural);
}
return this.views[plural];
} | javascript | function(plural) {
if (lazy.isObject(plural)) return plural;
if (!this.views.hasOwnProperty(plural)) {
plural = this.inflections[plural];
}
if (!this.views.hasOwnProperty(plural)) {
throw new Error('getViews cannot find collection' + plural);
}
return this.views[plural];
} | [
"function",
"(",
"plural",
")",
"{",
"if",
"(",
"lazy",
".",
"isObject",
"(",
"plural",
")",
")",
"return",
"plural",
";",
"if",
"(",
"!",
"this",
".",
"views",
".",
"hasOwnProperty",
"(",
"plural",
")",
")",
"{",
"plural",
"=",
"this",
".",
"inflections",
"[",
"plural",
"]",
";",
"}",
"if",
"(",
"!",
"this",
".",
"views",
".",
"hasOwnProperty",
"(",
"plural",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'getViews cannot find collection'",
"+",
"plural",
")",
";",
"}",
"return",
"this",
".",
"views",
"[",
"plural",
"]",
";",
"}"
] | Get a view `collection` by its singular or plural name.
```js
var pages = app.getViews('pages');
//=> { pages: {'home.hbs': { ... }}
var posts = app.getViews('posts');
//=> { posts: {'2015-10-10.md': { ... }}
```
@param {String} `plural` The plural collection name, e.g. `pages`
@return {Object}
@api public | [
"Get",
"a",
"view",
"collection",
"by",
"its",
"singular",
"or",
"plural",
"name",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/lookup.js#L119-L128 | |
26,271 | jonschlinkert/template | lib/lookup.js | function (view, collection) {
if (typeof view === 'string') {
if (typeof collection === 'string') {
return this[collection].get(view);
}
var collections = this.viewTypes.renderable;
var len = collections.length, i = 0;
while (len--) {
var plural = collections[i++];
var views = this.views[plural];
var res;
if (res = views[view]) {
return res;
}
}
}
return null;
} | javascript | function (view, collection) {
if (typeof view === 'string') {
if (typeof collection === 'string') {
return this[collection].get(view);
}
var collections = this.viewTypes.renderable;
var len = collections.length, i = 0;
while (len--) {
var plural = collections[i++];
var views = this.views[plural];
var res;
if (res = views[view]) {
return res;
}
}
}
return null;
} | [
"function",
"(",
"view",
",",
"collection",
")",
"{",
"if",
"(",
"typeof",
"view",
"===",
"'string'",
")",
"{",
"if",
"(",
"typeof",
"collection",
"===",
"'string'",
")",
"{",
"return",
"this",
"[",
"collection",
"]",
".",
"get",
"(",
"view",
")",
";",
"}",
"var",
"collections",
"=",
"this",
".",
"viewTypes",
".",
"renderable",
";",
"var",
"len",
"=",
"collections",
".",
"length",
",",
"i",
"=",
"0",
";",
"while",
"(",
"len",
"--",
")",
"{",
"var",
"plural",
"=",
"collections",
"[",
"i",
"++",
"]",
";",
"var",
"views",
"=",
"this",
".",
"views",
"[",
"plural",
"]",
";",
"var",
"res",
";",
"if",
"(",
"res",
"=",
"views",
"[",
"view",
"]",
")",
"{",
"return",
"res",
";",
"}",
"}",
"}",
"return",
"null",
";",
"}"
] | Find a stashed view. | [
"Find",
"a",
"stashed",
"view",
"."
] | 51397ab65330a8be9490ba4a5c96ad85548bddc6 | https://github.com/jonschlinkert/template/blob/51397ab65330a8be9490ba4a5c96ad85548bddc6/lib/lookup.js#L134-L153 | |
26,272 | layerhq/layer-websdk | src/client-registry.js | register | function register(client) {
const appId = client.appId;
if (registry[appId] && !registry[appId].isDestroyed) {
registry[appId].destroy();
}
registry[appId] = client;
defer(() => listeners.forEach(listener => listener(client)));
} | javascript | function register(client) {
const appId = client.appId;
if (registry[appId] && !registry[appId].isDestroyed) {
registry[appId].destroy();
}
registry[appId] = client;
defer(() => listeners.forEach(listener => listener(client)));
} | [
"function",
"register",
"(",
"client",
")",
"{",
"const",
"appId",
"=",
"client",
".",
"appId",
";",
"if",
"(",
"registry",
"[",
"appId",
"]",
"&&",
"!",
"registry",
"[",
"appId",
"]",
".",
"isDestroyed",
")",
"{",
"registry",
"[",
"appId",
"]",
".",
"destroy",
"(",
")",
";",
"}",
"registry",
"[",
"appId",
"]",
"=",
"client",
";",
"defer",
"(",
"(",
")",
"=>",
"listeners",
".",
"forEach",
"(",
"listener",
"=>",
"listener",
"(",
"client",
")",
")",
")",
";",
"}"
] | Register a new Client; will destroy any previous client with the same appId.
@method register
@param {layer.Client} client | [
"Register",
"a",
"new",
"Client",
";",
"will",
"destroy",
"any",
"previous",
"client",
"with",
"the",
"same",
"appId",
"."
] | aead2b88b6b01d188d846a1298bc04fb2f42ad1a | https://github.com/layerhq/layer-websdk/blob/aead2b88b6b01d188d846a1298bc04fb2f42ad1a/src/client-registry.js#L20-L28 |
26,273 | layerhq/layer-websdk | src/client-registry.js | removeListener | function removeListener(listener) {
if (listener) {
const index = listeners.indexOf(listener);
if (index >= 0) listeners.splice(index, 1);
} else {
listeners.splice(0, listeners.length);
}
} | javascript | function removeListener(listener) {
if (listener) {
const index = listeners.indexOf(listener);
if (index >= 0) listeners.splice(index, 1);
} else {
listeners.splice(0, listeners.length);
}
} | [
"function",
"removeListener",
"(",
"listener",
")",
"{",
"if",
"(",
"listener",
")",
"{",
"const",
"index",
"=",
"listeners",
".",
"indexOf",
"(",
"listener",
")",
";",
"if",
"(",
"index",
">=",
"0",
")",
"listeners",
".",
"splice",
"(",
"index",
",",
"1",
")",
";",
"}",
"else",
"{",
"listeners",
".",
"splice",
"(",
"0",
",",
"listeners",
".",
"length",
")",
";",
"}",
"}"
] | Remove a registered listener or all listeners.
If called with no arguments or null arguments, removes all listeners.
@method removeListener
@param {Function} | [
"Remove",
"a",
"registered",
"listener",
"or",
"all",
"listeners",
"."
] | aead2b88b6b01d188d846a1298bc04fb2f42ad1a | https://github.com/layerhq/layer-websdk/blob/aead2b88b6b01d188d846a1298bc04fb2f42ad1a/src/client-registry.js#L73-L80 |
26,274 | stjohnjohnson/jenkins-mocha | lib/jenkins.js | getBin | function getBin(filename) {
try {
return escape(whichLocal.sync(filename));
} catch (unused) {
return escape(whichCwd.sync(filename));
}
} | javascript | function getBin(filename) {
try {
return escape(whichLocal.sync(filename));
} catch (unused) {
return escape(whichCwd.sync(filename));
}
} | [
"function",
"getBin",
"(",
"filename",
")",
"{",
"try",
"{",
"return",
"escape",
"(",
"whichLocal",
".",
"sync",
"(",
"filename",
")",
")",
";",
"}",
"catch",
"(",
"unused",
")",
"{",
"return",
"escape",
"(",
"whichCwd",
".",
"sync",
"(",
"filename",
")",
")",
";",
"}",
"}"
] | Get the file location of this node_module binary
@method getBin
@param {string} filename Bin you are looking for
@return {string} Full path to the file | [
"Get",
"the",
"file",
"location",
"of",
"this",
"node_module",
"binary"
] | 35beb42b2dec31c7aeb13650847a9c6fcf902b94 | https://github.com/stjohnjohnson/jenkins-mocha/blob/35beb42b2dec31c7aeb13650847a9c6fcf902b94/lib/jenkins.js#L19-L25 |
26,275 | layerhq/layer-websdk | grunt-template-jasmine-istanbul_src-main-js-template.js | function (sources, tmp) {
var instrumenter = new istanbul.Instrumenter();
var instrumentedSources = [];
sources.forEach(function (source) {
var instrumentedSource = instrumenter.instrumentSync(
grunt.file.read(source), source);
var tmpSource = source;
// don't try to write "C:" as part of a folder name on Windows
if (process.platform == 'win32') {
tmpSource = tmpSource.replace(/^([a-z]):/i, '$1');
}
tmpSource = path.join(tmp, tmpSource);
grunt.file.write(tmpSource, instrumentedSource);
instrumentedSources.push(tmpSource);
});
return instrumentedSources;
} | javascript | function (sources, tmp) {
var instrumenter = new istanbul.Instrumenter();
var instrumentedSources = [];
sources.forEach(function (source) {
var instrumentedSource = instrumenter.instrumentSync(
grunt.file.read(source), source);
var tmpSource = source;
// don't try to write "C:" as part of a folder name on Windows
if (process.platform == 'win32') {
tmpSource = tmpSource.replace(/^([a-z]):/i, '$1');
}
tmpSource = path.join(tmp, tmpSource);
grunt.file.write(tmpSource, instrumentedSource);
instrumentedSources.push(tmpSource);
});
return instrumentedSources;
} | [
"function",
"(",
"sources",
",",
"tmp",
")",
"{",
"var",
"instrumenter",
"=",
"new",
"istanbul",
".",
"Instrumenter",
"(",
")",
";",
"var",
"instrumentedSources",
"=",
"[",
"]",
";",
"sources",
".",
"forEach",
"(",
"function",
"(",
"source",
")",
"{",
"var",
"instrumentedSource",
"=",
"instrumenter",
".",
"instrumentSync",
"(",
"grunt",
".",
"file",
".",
"read",
"(",
"source",
")",
",",
"source",
")",
";",
"var",
"tmpSource",
"=",
"source",
";",
"// don't try to write \"C:\" as part of a folder name on Windows",
"if",
"(",
"process",
".",
"platform",
"==",
"'win32'",
")",
"{",
"tmpSource",
"=",
"tmpSource",
".",
"replace",
"(",
"/",
"^([a-z]):",
"/",
"i",
",",
"'$1'",
")",
";",
"}",
"tmpSource",
"=",
"path",
".",
"join",
"(",
"tmp",
",",
"tmpSource",
")",
";",
"grunt",
".",
"file",
".",
"write",
"(",
"tmpSource",
",",
"instrumentedSource",
")",
";",
"instrumentedSources",
".",
"push",
"(",
"tmpSource",
")",
";",
"}",
")",
";",
"return",
"instrumentedSources",
";",
"}"
] | Instruments the specified sources and moves the instrumented sources to the
temporary location, recreating the original directory structure.
@private
@method instrument
@param {Array} sources The paths of the original sources
@param {String} tmp The path to the temporary directory
@return {Array} The paths to the instrumented sources | [
"Instruments",
"the",
"specified",
"sources",
"and",
"moves",
"the",
"instrumented",
"sources",
"to",
"the",
"temporary",
"location",
"recreating",
"the",
"original",
"directory",
"structure",
"."
] | aead2b88b6b01d188d846a1298bc04fb2f42ad1a | https://github.com/layerhq/layer-websdk/blob/aead2b88b6b01d188d846a1298bc04fb2f42ad1a/grunt-template-jasmine-istanbul_src-main-js-template.js#L43-L59 | |
26,276 | layerhq/layer-websdk | grunt-template-jasmine-istanbul_src-main-js-template.js | function (type, options, collector) {
istanbul.Report.create(type, options).writeReport(collector, true);
} | javascript | function (type, options, collector) {
istanbul.Report.create(type, options).writeReport(collector, true);
} | [
"function",
"(",
"type",
",",
"options",
",",
"collector",
")",
"{",
"istanbul",
".",
"Report",
".",
"create",
"(",
"type",
",",
"options",
")",
".",
"writeReport",
"(",
"collector",
",",
"true",
")",
";",
"}"
] | Writes the report of the specified type, using the specified options and
reporting the coverage collected by the specified collector.
@private
@method writeReport
@param {String} type The report type
@param {Object} options The report options
@param {Collector} collector The collector containing the coverage | [
"Writes",
"the",
"report",
"of",
"the",
"specified",
"type",
"using",
"the",
"specified",
"options",
"and",
"reporting",
"the",
"coverage",
"collected",
"by",
"the",
"specified",
"collector",
"."
] | aead2b88b6b01d188d846a1298bc04fb2f42ad1a | https://github.com/layerhq/layer-websdk/blob/aead2b88b6b01d188d846a1298bc04fb2f42ad1a/grunt-template-jasmine-istanbul_src-main-js-template.js#L85-L87 | |
26,277 | layerhq/layer-websdk | grunt-template-jasmine-istanbul_src-main-js-template.js | function (collector, options) {
if (typeof options == 'string' || options instanceof String) {
// default to html report at options directory
writeReport('html', {
dir: options
}, collector);
} else if (options instanceof Array) {
// multiple reports
for (var i = 0; i < options.length; i = i + 1) {
var report = options[i];
writeReport(report.type, report.options, collector);
}
} else {
// single report
writeReport(options.type, options.options, collector);
}
} | javascript | function (collector, options) {
if (typeof options == 'string' || options instanceof String) {
// default to html report at options directory
writeReport('html', {
dir: options
}, collector);
} else if (options instanceof Array) {
// multiple reports
for (var i = 0; i < options.length; i = i + 1) {
var report = options[i];
writeReport(report.type, report.options, collector);
}
} else {
// single report
writeReport(options.type, options.options, collector);
}
} | [
"function",
"(",
"collector",
",",
"options",
")",
"{",
"if",
"(",
"typeof",
"options",
"==",
"'string'",
"||",
"options",
"instanceof",
"String",
")",
"{",
"// default to html report at options directory",
"writeReport",
"(",
"'html'",
",",
"{",
"dir",
":",
"options",
"}",
",",
"collector",
")",
";",
"}",
"else",
"if",
"(",
"options",
"instanceof",
"Array",
")",
"{",
"// multiple reports",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"options",
".",
"length",
";",
"i",
"=",
"i",
"+",
"1",
")",
"{",
"var",
"report",
"=",
"options",
"[",
"i",
"]",
";",
"writeReport",
"(",
"report",
".",
"type",
",",
"report",
".",
"options",
",",
"collector",
")",
";",
"}",
"}",
"else",
"{",
"// single report",
"writeReport",
"(",
"options",
".",
"type",
",",
"options",
".",
"options",
",",
"collector",
")",
";",
"}",
"}"
] | Writes the istanbul reports created from the specified options.
@private
@method writeReports
@param {Collector} collector The collector containing the coverage
@param {Object} options The options describing the reports | [
"Writes",
"the",
"istanbul",
"reports",
"created",
"from",
"the",
"specified",
"options",
"."
] | aead2b88b6b01d188d846a1298bc04fb2f42ad1a | https://github.com/layerhq/layer-websdk/blob/aead2b88b6b01d188d846a1298bc04fb2f42ad1a/grunt-template-jasmine-istanbul_src-main-js-template.js#L98-L114 | |
26,278 | layerhq/layer-websdk | grunt-template-jasmine-istanbul_src-main-js-template.js | function (collector, options) {
var summaries = [];
var thresholds = options.thresholds;
var files = collector.files();
files.forEach(function(file) {
summaries.push(istanbul.utils.summarizeFileCoverage(
collector.fileCoverageFor(file)));
});
var finalSummary = istanbul.utils.mergeSummaryObjects.apply(null,
summaries);
grunt.util._.each(thresholds, function (threshold, metric) {
var actual = finalSummary[metric];
if(!actual) {
grunt.warn('unrecognized metric: ' + metric);
}
if(actual.pct < threshold) {
grunt.warn('expected ' + metric + ' coverage to be at least '
+ threshold + '% but was ' + actual.pct + '%');
}
});
} | javascript | function (collector, options) {
var summaries = [];
var thresholds = options.thresholds;
var files = collector.files();
files.forEach(function(file) {
summaries.push(istanbul.utils.summarizeFileCoverage(
collector.fileCoverageFor(file)));
});
var finalSummary = istanbul.utils.mergeSummaryObjects.apply(null,
summaries);
grunt.util._.each(thresholds, function (threshold, metric) {
var actual = finalSummary[metric];
if(!actual) {
grunt.warn('unrecognized metric: ' + metric);
}
if(actual.pct < threshold) {
grunt.warn('expected ' + metric + ' coverage to be at least '
+ threshold + '% but was ' + actual.pct + '%');
}
});
} | [
"function",
"(",
"collector",
",",
"options",
")",
"{",
"var",
"summaries",
"=",
"[",
"]",
";",
"var",
"thresholds",
"=",
"options",
".",
"thresholds",
";",
"var",
"files",
"=",
"collector",
".",
"files",
"(",
")",
";",
"files",
".",
"forEach",
"(",
"function",
"(",
"file",
")",
"{",
"summaries",
".",
"push",
"(",
"istanbul",
".",
"utils",
".",
"summarizeFileCoverage",
"(",
"collector",
".",
"fileCoverageFor",
"(",
"file",
")",
")",
")",
";",
"}",
")",
";",
"var",
"finalSummary",
"=",
"istanbul",
".",
"utils",
".",
"mergeSummaryObjects",
".",
"apply",
"(",
"null",
",",
"summaries",
")",
";",
"grunt",
".",
"util",
".",
"_",
".",
"each",
"(",
"thresholds",
",",
"function",
"(",
"threshold",
",",
"metric",
")",
"{",
"var",
"actual",
"=",
"finalSummary",
"[",
"metric",
"]",
";",
"if",
"(",
"!",
"actual",
")",
"{",
"grunt",
".",
"warn",
"(",
"'unrecognized metric: '",
"+",
"metric",
")",
";",
"}",
"if",
"(",
"actual",
".",
"pct",
"<",
"threshold",
")",
"{",
"grunt",
".",
"warn",
"(",
"'expected '",
"+",
"metric",
"+",
"' coverage to be at least '",
"+",
"threshold",
"+",
"'% but was '",
"+",
"actual",
".",
"pct",
"+",
"'%'",
")",
";",
"}",
"}",
")",
";",
"}"
] | Checks whether the specified threshold options have been met. Issues a
warning if not.
@param {Collector} collector The collector containing the coverage
@param {Object} options The options describing the thresholds | [
"Checks",
"whether",
"the",
"specified",
"threshold",
"options",
"have",
"been",
"met",
".",
"Issues",
"a",
"warning",
"if",
"not",
"."
] | aead2b88b6b01d188d846a1298bc04fb2f42ad1a | https://github.com/layerhq/layer-websdk/blob/aead2b88b6b01d188d846a1298bc04fb2f42ad1a/grunt-template-jasmine-istanbul_src-main-js-template.js#L123-L146 | |
26,279 | layerhq/layer-websdk | grunt-template-jasmine-istanbul_src-main-js-template.js | function (grunt, task, context) {
var template = context.options.template;
if (!template) {
template = DEFAULT_TEMPLATE;
}
// clone context
var mixedInContext = JSON.parse(JSON.stringify(context));
// transit templateOptions
mixedInContext.options = context.options.templateOptions || {};
if (template.process) {
return template.process(grunt, task, mixedInContext);
} else {
return grunt.util._.template(grunt.file.read(template), mixedInContext);
}
} | javascript | function (grunt, task, context) {
var template = context.options.template;
if (!template) {
template = DEFAULT_TEMPLATE;
}
// clone context
var mixedInContext = JSON.parse(JSON.stringify(context));
// transit templateOptions
mixedInContext.options = context.options.templateOptions || {};
if (template.process) {
return template.process(grunt, task, mixedInContext);
} else {
return grunt.util._.template(grunt.file.read(template), mixedInContext);
}
} | [
"function",
"(",
"grunt",
",",
"task",
",",
"context",
")",
"{",
"var",
"template",
"=",
"context",
".",
"options",
".",
"template",
";",
"if",
"(",
"!",
"template",
")",
"{",
"template",
"=",
"DEFAULT_TEMPLATE",
";",
"}",
"// clone context",
"var",
"mixedInContext",
"=",
"JSON",
".",
"parse",
"(",
"JSON",
".",
"stringify",
"(",
"context",
")",
")",
";",
"// transit templateOptions",
"mixedInContext",
".",
"options",
"=",
"context",
".",
"options",
".",
"templateOptions",
"||",
"{",
"}",
";",
"if",
"(",
"template",
".",
"process",
")",
"{",
"return",
"template",
".",
"process",
"(",
"grunt",
",",
"task",
",",
"mixedInContext",
")",
";",
"}",
"else",
"{",
"return",
"grunt",
".",
"util",
".",
"_",
".",
"template",
"(",
"grunt",
".",
"file",
".",
"read",
"(",
"template",
")",
",",
"mixedInContext",
")",
";",
"}",
"}"
] | Processes the mixed-in template. Defaults to jasmine's default template and
sets up the context using the mixed-in template's options.
@private
@method processMixedInTemplate
@param {Object} grunt The grunt object
@param {Object} task Provides utility methods to register listeners and
handle temporary files
@param {Object} context Contains all options
@return {String} The template HTML source of the mixed in template | [
"Processes",
"the",
"mixed",
"-",
"in",
"template",
".",
"Defaults",
"to",
"jasmine",
"s",
"default",
"template",
"and",
"sets",
"up",
"the",
"context",
"using",
"the",
"mixed",
"-",
"in",
"template",
"s",
"options",
"."
] | aead2b88b6b01d188d846a1298bc04fb2f42ad1a | https://github.com/layerhq/layer-websdk/blob/aead2b88b6b01d188d846a1298bc04fb2f42ad1a/grunt-template-jasmine-istanbul_src-main-js-template.js#L162-L176 | |
26,280 | knpwrs/gulp-spawn-mocha | lib/index.js | parseArgs | function parseArgs(obj) {
var args = [];
_.each(obj, function (val, key) {
if (_.isArray(val)) {
_.each(val, function (val) {
addArg(args, key, val);
});
} else {
addArg(args, key, val);
}
});
return args;
} | javascript | function parseArgs(obj) {
var args = [];
_.each(obj, function (val, key) {
if (_.isArray(val)) {
_.each(val, function (val) {
addArg(args, key, val);
});
} else {
addArg(args, key, val);
}
});
return args;
} | [
"function",
"parseArgs",
"(",
"obj",
")",
"{",
"var",
"args",
"=",
"[",
"]",
";",
"_",
".",
"each",
"(",
"obj",
",",
"function",
"(",
"val",
",",
"key",
")",
"{",
"if",
"(",
"_",
".",
"isArray",
"(",
"val",
")",
")",
"{",
"_",
".",
"each",
"(",
"val",
",",
"function",
"(",
"val",
")",
"{",
"addArg",
"(",
"args",
",",
"key",
",",
"val",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"addArg",
"(",
"args",
",",
"key",
",",
"val",
")",
";",
"}",
"}",
")",
";",
"return",
"args",
";",
"}"
] | Parses the arugments from a configuration object for passing to a mocha
executable.
@param {Object} obj The object to parse from.
@return {Array} An array of parsed arguments. | [
"Parses",
"the",
"arugments",
"from",
"a",
"configuration",
"object",
"for",
"passing",
"to",
"a",
"mocha",
"executable",
"."
] | 8b5e7fdd41bcb65b6e12164e53111fe4376fd9d4 | https://github.com/knpwrs/gulp-spawn-mocha/blob/8b5e7fdd41bcb65b6e12164e53111fe4376fd9d4/lib/index.js#L90-L102 |
26,281 | knpwrs/gulp-spawn-mocha | lib/index.js | addArg | function addArg(args, name, val) {
if (!val && val !== 0) {
return;
}
var arg = name.length > 1 ? '--' + _.kebabCase(name) : '-' + name;
// --max-old-space-size argument requires an `=`
if (arg === '--max-old-space-size') {
args.push(arg + '=' + val);
return;
} else {
args.push(arg);
}
if (_.isString(val) || _.isNumber(val)) {
args.push(val);
}
} | javascript | function addArg(args, name, val) {
if (!val && val !== 0) {
return;
}
var arg = name.length > 1 ? '--' + _.kebabCase(name) : '-' + name;
// --max-old-space-size argument requires an `=`
if (arg === '--max-old-space-size') {
args.push(arg + '=' + val);
return;
} else {
args.push(arg);
}
if (_.isString(val) || _.isNumber(val)) {
args.push(val);
}
} | [
"function",
"addArg",
"(",
"args",
",",
"name",
",",
"val",
")",
"{",
"if",
"(",
"!",
"val",
"&&",
"val",
"!==",
"0",
")",
"{",
"return",
";",
"}",
"var",
"arg",
"=",
"name",
".",
"length",
">",
"1",
"?",
"'--'",
"+",
"_",
".",
"kebabCase",
"(",
"name",
")",
":",
"'-'",
"+",
"name",
";",
"// --max-old-space-size argument requires an `=`",
"if",
"(",
"arg",
"===",
"'--max-old-space-size'",
")",
"{",
"args",
".",
"push",
"(",
"arg",
"+",
"'='",
"+",
"val",
")",
";",
"return",
";",
"}",
"else",
"{",
"args",
".",
"push",
"(",
"arg",
")",
";",
"}",
"if",
"(",
"_",
".",
"isString",
"(",
"val",
")",
"||",
"_",
".",
"isNumber",
"(",
"val",
")",
")",
"{",
"args",
".",
"push",
"(",
"val",
")",
";",
"}",
"}"
] | Adds a given argument with name and value to arugment array.
@param {Array} args String array of arguments.
@param {String} name Name of the argument.
@param {String} val Value of the argument. Returns without doing anything
if falsy and not zero. | [
"Adds",
"a",
"given",
"argument",
"with",
"name",
"and",
"value",
"to",
"arugment",
"array",
"."
] | 8b5e7fdd41bcb65b6e12164e53111fe4376fd9d4 | https://github.com/knpwrs/gulp-spawn-mocha/blob/8b5e7fdd41bcb65b6e12164e53111fe4376fd9d4/lib/index.js#L111-L126 |
26,282 | expressjs/express-expose | lib/express-expose.js | expose | function expose(obj, namespace, name) {
var app = this.app || this;
var req = this.req;
app._exposed = app._exposed || {};
// support second arg as name
// when a string or function is given
if ('string' === typeof obj || 'function' === typeof obj) {
name = namespace || _name;
} else {
name = name || _name;
namespace = namespace || _namespace;
}
// buffer string
if ('string' === typeof obj) {
this.js = this.js || {};
var buf = this.js[name] = this.js[name] || [];
buf.push(obj);
// buffer function
} else if ('function' === typeof obj && obj.name) {
this.expose(obj.toString(), name);
// buffer self-calling function
} else if ('function' === typeof obj) {
this.expose(';(' + obj + ')();', name);
// buffer object
} else {
this.expose(renderNamespace(namespace), name);
this.expose(renderObject(obj, namespace), name);
this.expose('\n');
}
// locals
function locals(req, res) {
var appjs = app.exposed(name);
var resjs = res.exposed(name);
var js = '';
if (appjs || resjs) {
js += '// app: \n' + appjs;
js += '// res: \n' + resjs;
}
res.locals[name] = js;
}
// app level locals
if (!req && !app._exposed[name]) {
app._exposed[name] = true;
app.use(function(req, res, next){
locals(req, res);
next();
});
// request level locals
} else if (req) {
locals(req, this);
}
return this;
} | javascript | function expose(obj, namespace, name) {
var app = this.app || this;
var req = this.req;
app._exposed = app._exposed || {};
// support second arg as name
// when a string or function is given
if ('string' === typeof obj || 'function' === typeof obj) {
name = namespace || _name;
} else {
name = name || _name;
namespace = namespace || _namespace;
}
// buffer string
if ('string' === typeof obj) {
this.js = this.js || {};
var buf = this.js[name] = this.js[name] || [];
buf.push(obj);
// buffer function
} else if ('function' === typeof obj && obj.name) {
this.expose(obj.toString(), name);
// buffer self-calling function
} else if ('function' === typeof obj) {
this.expose(';(' + obj + ')();', name);
// buffer object
} else {
this.expose(renderNamespace(namespace), name);
this.expose(renderObject(obj, namespace), name);
this.expose('\n');
}
// locals
function locals(req, res) {
var appjs = app.exposed(name);
var resjs = res.exposed(name);
var js = '';
if (appjs || resjs) {
js += '// app: \n' + appjs;
js += '// res: \n' + resjs;
}
res.locals[name] = js;
}
// app level locals
if (!req && !app._exposed[name]) {
app._exposed[name] = true;
app.use(function(req, res, next){
locals(req, res);
next();
});
// request level locals
} else if (req) {
locals(req, this);
}
return this;
} | [
"function",
"expose",
"(",
"obj",
",",
"namespace",
",",
"name",
")",
"{",
"var",
"app",
"=",
"this",
".",
"app",
"||",
"this",
";",
"var",
"req",
"=",
"this",
".",
"req",
";",
"app",
".",
"_exposed",
"=",
"app",
".",
"_exposed",
"||",
"{",
"}",
";",
"// support second arg as name",
"// when a string or function is given",
"if",
"(",
"'string'",
"===",
"typeof",
"obj",
"||",
"'function'",
"===",
"typeof",
"obj",
")",
"{",
"name",
"=",
"namespace",
"||",
"_name",
";",
"}",
"else",
"{",
"name",
"=",
"name",
"||",
"_name",
";",
"namespace",
"=",
"namespace",
"||",
"_namespace",
";",
"}",
"// buffer string",
"if",
"(",
"'string'",
"===",
"typeof",
"obj",
")",
"{",
"this",
".",
"js",
"=",
"this",
".",
"js",
"||",
"{",
"}",
";",
"var",
"buf",
"=",
"this",
".",
"js",
"[",
"name",
"]",
"=",
"this",
".",
"js",
"[",
"name",
"]",
"||",
"[",
"]",
";",
"buf",
".",
"push",
"(",
"obj",
")",
";",
"// buffer function",
"}",
"else",
"if",
"(",
"'function'",
"===",
"typeof",
"obj",
"&&",
"obj",
".",
"name",
")",
"{",
"this",
".",
"expose",
"(",
"obj",
".",
"toString",
"(",
")",
",",
"name",
")",
";",
"// buffer self-calling function",
"}",
"else",
"if",
"(",
"'function'",
"===",
"typeof",
"obj",
")",
"{",
"this",
".",
"expose",
"(",
"';('",
"+",
"obj",
"+",
"')();'",
",",
"name",
")",
";",
"// buffer object",
"}",
"else",
"{",
"this",
".",
"expose",
"(",
"renderNamespace",
"(",
"namespace",
")",
",",
"name",
")",
";",
"this",
".",
"expose",
"(",
"renderObject",
"(",
"obj",
",",
"namespace",
")",
",",
"name",
")",
";",
"this",
".",
"expose",
"(",
"'\\n'",
")",
";",
"}",
"// locals",
"function",
"locals",
"(",
"req",
",",
"res",
")",
"{",
"var",
"appjs",
"=",
"app",
".",
"exposed",
"(",
"name",
")",
";",
"var",
"resjs",
"=",
"res",
".",
"exposed",
"(",
"name",
")",
";",
"var",
"js",
"=",
"''",
";",
"if",
"(",
"appjs",
"||",
"resjs",
")",
"{",
"js",
"+=",
"'// app: \\n'",
"+",
"appjs",
";",
"js",
"+=",
"'// res: \\n'",
"+",
"resjs",
";",
"}",
"res",
".",
"locals",
"[",
"name",
"]",
"=",
"js",
";",
"}",
"// app level locals",
"if",
"(",
"!",
"req",
"&&",
"!",
"app",
".",
"_exposed",
"[",
"name",
"]",
")",
"{",
"app",
".",
"_exposed",
"[",
"name",
"]",
"=",
"true",
";",
"app",
".",
"use",
"(",
"function",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"locals",
"(",
"req",
",",
"res",
")",
";",
"next",
"(",
")",
";",
"}",
")",
";",
"// request level locals",
"}",
"else",
"if",
"(",
"req",
")",
"{",
"locals",
"(",
"req",
",",
"this",
")",
";",
"}",
"return",
"this",
";",
"}"
] | Expose the given `obj` to the client-side, with
an optional `namespace` defaulting to "express".
@param {Object|String|Function} obj
@param {String} namespace
@param {String} name
@return {HTTPServer} for chaining
@api public | [
"Expose",
"the",
"given",
"obj",
"to",
"the",
"client",
"-",
"side",
"with",
"an",
"optional",
"namespace",
"defaulting",
"to",
"express",
"."
] | a270d335464d7ecdd2cb894dd44a16231757aec9 | https://github.com/expressjs/express-expose/blob/a270d335464d7ecdd2cb894dd44a16231757aec9/lib/express-expose.js#L37-L101 |
26,283 | expressjs/express-expose | lib/express-expose.js | exposed | function exposed(name) {
name = name || _name;
this.js = this.js || {};
return this.js[name]
? this.js[name].join('\n')
: '';
} | javascript | function exposed(name) {
name = name || _name;
this.js = this.js || {};
return this.js[name]
? this.js[name].join('\n')
: '';
} | [
"function",
"exposed",
"(",
"name",
")",
"{",
"name",
"=",
"name",
"||",
"_name",
";",
"this",
".",
"js",
"=",
"this",
".",
"js",
"||",
"{",
"}",
";",
"return",
"this",
".",
"js",
"[",
"name",
"]",
"?",
"this",
".",
"js",
"[",
"name",
"]",
".",
"join",
"(",
"'\\n'",
")",
":",
"''",
";",
"}"
] | Render the exposed javascript.
@return {String}
@api private | [
"Render",
"the",
"exposed",
"javascript",
"."
] | a270d335464d7ecdd2cb894dd44a16231757aec9 | https://github.com/expressjs/express-expose/blob/a270d335464d7ecdd2cb894dd44a16231757aec9/lib/express-expose.js#L110-L116 |
26,284 | expressjs/express-expose | lib/express-expose.js | renderNamespace | function renderNamespace(str) {
var parts = [];
var split = str.split('.');
var len = split.length;
return str.split('.').map(function(part, i) {
parts.push(part);
part = parts.join('.');
return (i ? '' : 'window.') + part + ' = window.' + part + ' || {};';
}).join('\n');
} | javascript | function renderNamespace(str) {
var parts = [];
var split = str.split('.');
var len = split.length;
return str.split('.').map(function(part, i) {
parts.push(part);
part = parts.join('.');
return (i ? '' : 'window.') + part + ' = window.' + part + ' || {};';
}).join('\n');
} | [
"function",
"renderNamespace",
"(",
"str",
")",
"{",
"var",
"parts",
"=",
"[",
"]",
";",
"var",
"split",
"=",
"str",
".",
"split",
"(",
"'.'",
")",
";",
"var",
"len",
"=",
"split",
".",
"length",
";",
"return",
"str",
".",
"split",
"(",
"'.'",
")",
".",
"map",
"(",
"function",
"(",
"part",
",",
"i",
")",
"{",
"parts",
".",
"push",
"(",
"part",
")",
";",
"part",
"=",
"parts",
".",
"join",
"(",
"'.'",
")",
";",
"return",
"(",
"i",
"?",
"''",
":",
"'window.'",
")",
"+",
"part",
"+",
"' = window.'",
"+",
"part",
"+",
"' || {};'",
";",
"}",
")",
".",
"join",
"(",
"'\\n'",
")",
";",
"}"
] | Render a namespace from the given `str`.
Examples:
renderNamespace('foo.bar.baz');
var foo = foo || {};
foo.bar = foo.bar || {};
foo.bar.baz = foo.bar.baz || {};
@param {String} str
@return {String}
@api private | [
"Render",
"a",
"namespace",
"from",
"the",
"given",
"str",
"."
] | a270d335464d7ecdd2cb894dd44a16231757aec9 | https://github.com/expressjs/express-expose/blob/a270d335464d7ecdd2cb894dd44a16231757aec9/lib/express-expose.js#L134-L145 |
26,285 | expressjs/express-expose | lib/express-expose.js | renderObject | function renderObject(obj, namespace) {
return Object.keys(obj).map(function(key){
var val = obj[key];
return namespace + '["' + key + '"] = ' + string(val) + ';';
}).join('\n');
} | javascript | function renderObject(obj, namespace) {
return Object.keys(obj).map(function(key){
var val = obj[key];
return namespace + '["' + key + '"] = ' + string(val) + ';';
}).join('\n');
} | [
"function",
"renderObject",
"(",
"obj",
",",
"namespace",
")",
"{",
"return",
"Object",
".",
"keys",
"(",
"obj",
")",
".",
"map",
"(",
"function",
"(",
"key",
")",
"{",
"var",
"val",
"=",
"obj",
"[",
"key",
"]",
";",
"return",
"namespace",
"+",
"'[\"'",
"+",
"key",
"+",
"'\"] = '",
"+",
"string",
"(",
"val",
")",
"+",
"';'",
";",
"}",
")",
".",
"join",
"(",
"'\\n'",
")",
";",
"}"
] | Render `obj` with the given `namespace`.
@param {Object} obj
@param {String} namespace
@return {String}
@api private | [
"Render",
"obj",
"with",
"the",
"given",
"namespace",
"."
] | a270d335464d7ecdd2cb894dd44a16231757aec9 | https://github.com/expressjs/express-expose/blob/a270d335464d7ecdd2cb894dd44a16231757aec9/lib/express-expose.js#L156-L161 |
26,286 | expressjs/express-expose | lib/express-expose.js | string | function string(obj) {
if ('function' === typeof obj) {
return obj.toString();
} else if (obj instanceof Date) {
return 'new Date("' + obj + '")';
} else if (Array.isArray(obj)) {
return '[' + obj.map(string).join(', ') + ']';
} else if ('[object Object]' === Object.prototype.toString.call(obj)) {
return '{' + Object.keys(obj).map(function(key){
return '"' + key + '":' + string(obj[key]);
}).join(', ') + '}';
} else {
return JSON.stringify(obj);
}
} | javascript | function string(obj) {
if ('function' === typeof obj) {
return obj.toString();
} else if (obj instanceof Date) {
return 'new Date("' + obj + '")';
} else if (Array.isArray(obj)) {
return '[' + obj.map(string).join(', ') + ']';
} else if ('[object Object]' === Object.prototype.toString.call(obj)) {
return '{' + Object.keys(obj).map(function(key){
return '"' + key + '":' + string(obj[key]);
}).join(', ') + '}';
} else {
return JSON.stringify(obj);
}
} | [
"function",
"string",
"(",
"obj",
")",
"{",
"if",
"(",
"'function'",
"===",
"typeof",
"obj",
")",
"{",
"return",
"obj",
".",
"toString",
"(",
")",
";",
"}",
"else",
"if",
"(",
"obj",
"instanceof",
"Date",
")",
"{",
"return",
"'new Date(\"'",
"+",
"obj",
"+",
"'\")'",
";",
"}",
"else",
"if",
"(",
"Array",
".",
"isArray",
"(",
"obj",
")",
")",
"{",
"return",
"'['",
"+",
"obj",
".",
"map",
"(",
"string",
")",
".",
"join",
"(",
"', '",
")",
"+",
"']'",
";",
"}",
"else",
"if",
"(",
"'[object Object]'",
"===",
"Object",
".",
"prototype",
".",
"toString",
".",
"call",
"(",
"obj",
")",
")",
"{",
"return",
"'{'",
"+",
"Object",
".",
"keys",
"(",
"obj",
")",
".",
"map",
"(",
"function",
"(",
"key",
")",
"{",
"return",
"'\"'",
"+",
"key",
"+",
"'\":'",
"+",
"string",
"(",
"obj",
"[",
"key",
"]",
")",
";",
"}",
")",
".",
"join",
"(",
"', '",
")",
"+",
"'}'",
";",
"}",
"else",
"{",
"return",
"JSON",
".",
"stringify",
"(",
"obj",
")",
";",
"}",
"}"
] | Return a string representation of `obj`.
@param {Mixed} obj
@return {String}
@api private | [
"Return",
"a",
"string",
"representation",
"of",
"obj",
"."
] | a270d335464d7ecdd2cb894dd44a16231757aec9 | https://github.com/expressjs/express-expose/blob/a270d335464d7ecdd2cb894dd44a16231757aec9/lib/express-expose.js#L171-L185 |
26,287 | bitpay/bloom-filter | lib/murmurhash3.js | MurmurHash3 | function MurmurHash3(seed, data) {
/* jshint maxstatements: 32, maxcomplexity: 10 */
var c1 = 0xcc9e2d51;
var c2 = 0x1b873593;
var r1 = 15;
var r2 = 13;
var m = 5;
var n = 0x6b64e654;
var hash = seed;
function mul32(a, b) {
return (a & 0xffff) * b + (((a >>> 16) * b & 0xffff) << 16) & 0xffffffff;
}
function sum32(a, b) {
return (a & 0xffff) + (b >>> 16) + (((a >>> 16) + b & 0xffff) << 16) & 0xffffffff;
}
function rotl32(a, b) {
return (a << b) | (a >>> (32 - b));
}
var k1;
for (var i = 0; i + 4 <= data.length; i += 4) {
k1 = data[i] |
(data[i + 1] << 8) |
(data[i + 2] << 16) |
(data[i + 3] << 24);
k1 = mul32(k1, c1);
k1 = rotl32(k1, r1);
k1 = mul32(k1, c2);
hash ^= k1;
hash = rotl32(hash, r2);
hash = mul32(hash, m);
hash = sum32(hash, n);
}
k1 = 0;
switch(data.length & 3) {
case 3:
k1 ^= data[i + 2] << 16;
/* falls through */
case 2:
k1 ^= data[i + 1] << 8;
/* falls through */
case 1:
k1 ^= data[i];
k1 = mul32(k1, c1);
k1 = rotl32(k1, r1);
k1 = mul32(k1, c2);
hash ^= k1;
}
hash ^= data.length;
hash ^= hash >>> 16;
hash = mul32(hash, 0x85ebca6b);
hash ^= hash >>> 13;
hash = mul32(hash, 0xc2b2ae35);
hash ^= hash >>> 16;
return hash >>> 0;
} | javascript | function MurmurHash3(seed, data) {
/* jshint maxstatements: 32, maxcomplexity: 10 */
var c1 = 0xcc9e2d51;
var c2 = 0x1b873593;
var r1 = 15;
var r2 = 13;
var m = 5;
var n = 0x6b64e654;
var hash = seed;
function mul32(a, b) {
return (a & 0xffff) * b + (((a >>> 16) * b & 0xffff) << 16) & 0xffffffff;
}
function sum32(a, b) {
return (a & 0xffff) + (b >>> 16) + (((a >>> 16) + b & 0xffff) << 16) & 0xffffffff;
}
function rotl32(a, b) {
return (a << b) | (a >>> (32 - b));
}
var k1;
for (var i = 0; i + 4 <= data.length; i += 4) {
k1 = data[i] |
(data[i + 1] << 8) |
(data[i + 2] << 16) |
(data[i + 3] << 24);
k1 = mul32(k1, c1);
k1 = rotl32(k1, r1);
k1 = mul32(k1, c2);
hash ^= k1;
hash = rotl32(hash, r2);
hash = mul32(hash, m);
hash = sum32(hash, n);
}
k1 = 0;
switch(data.length & 3) {
case 3:
k1 ^= data[i + 2] << 16;
/* falls through */
case 2:
k1 ^= data[i + 1] << 8;
/* falls through */
case 1:
k1 ^= data[i];
k1 = mul32(k1, c1);
k1 = rotl32(k1, r1);
k1 = mul32(k1, c2);
hash ^= k1;
}
hash ^= data.length;
hash ^= hash >>> 16;
hash = mul32(hash, 0x85ebca6b);
hash ^= hash >>> 13;
hash = mul32(hash, 0xc2b2ae35);
hash ^= hash >>> 16;
return hash >>> 0;
} | [
"function",
"MurmurHash3",
"(",
"seed",
",",
"data",
")",
"{",
"/* jshint maxstatements: 32, maxcomplexity: 10 */",
"var",
"c1",
"=",
"0xcc9e2d51",
";",
"var",
"c2",
"=",
"0x1b873593",
";",
"var",
"r1",
"=",
"15",
";",
"var",
"r2",
"=",
"13",
";",
"var",
"m",
"=",
"5",
";",
"var",
"n",
"=",
"0x6b64e654",
";",
"var",
"hash",
"=",
"seed",
";",
"function",
"mul32",
"(",
"a",
",",
"b",
")",
"{",
"return",
"(",
"a",
"&",
"0xffff",
")",
"*",
"b",
"+",
"(",
"(",
"(",
"a",
">>>",
"16",
")",
"*",
"b",
"&",
"0xffff",
")",
"<<",
"16",
")",
"&",
"0xffffffff",
";",
"}",
"function",
"sum32",
"(",
"a",
",",
"b",
")",
"{",
"return",
"(",
"a",
"&",
"0xffff",
")",
"+",
"(",
"b",
">>>",
"16",
")",
"+",
"(",
"(",
"(",
"a",
">>>",
"16",
")",
"+",
"b",
"&",
"0xffff",
")",
"<<",
"16",
")",
"&",
"0xffffffff",
";",
"}",
"function",
"rotl32",
"(",
"a",
",",
"b",
")",
"{",
"return",
"(",
"a",
"<<",
"b",
")",
"|",
"(",
"a",
">>>",
"(",
"32",
"-",
"b",
")",
")",
";",
"}",
"var",
"k1",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"+",
"4",
"<=",
"data",
".",
"length",
";",
"i",
"+=",
"4",
")",
"{",
"k1",
"=",
"data",
"[",
"i",
"]",
"|",
"(",
"data",
"[",
"i",
"+",
"1",
"]",
"<<",
"8",
")",
"|",
"(",
"data",
"[",
"i",
"+",
"2",
"]",
"<<",
"16",
")",
"|",
"(",
"data",
"[",
"i",
"+",
"3",
"]",
"<<",
"24",
")",
";",
"k1",
"=",
"mul32",
"(",
"k1",
",",
"c1",
")",
";",
"k1",
"=",
"rotl32",
"(",
"k1",
",",
"r1",
")",
";",
"k1",
"=",
"mul32",
"(",
"k1",
",",
"c2",
")",
";",
"hash",
"^=",
"k1",
";",
"hash",
"=",
"rotl32",
"(",
"hash",
",",
"r2",
")",
";",
"hash",
"=",
"mul32",
"(",
"hash",
",",
"m",
")",
";",
"hash",
"=",
"sum32",
"(",
"hash",
",",
"n",
")",
";",
"}",
"k1",
"=",
"0",
";",
"switch",
"(",
"data",
".",
"length",
"&",
"3",
")",
"{",
"case",
"3",
":",
"k1",
"^=",
"data",
"[",
"i",
"+",
"2",
"]",
"<<",
"16",
";",
"/* falls through */",
"case",
"2",
":",
"k1",
"^=",
"data",
"[",
"i",
"+",
"1",
"]",
"<<",
"8",
";",
"/* falls through */",
"case",
"1",
":",
"k1",
"^=",
"data",
"[",
"i",
"]",
";",
"k1",
"=",
"mul32",
"(",
"k1",
",",
"c1",
")",
";",
"k1",
"=",
"rotl32",
"(",
"k1",
",",
"r1",
")",
";",
"k1",
"=",
"mul32",
"(",
"k1",
",",
"c2",
")",
";",
"hash",
"^=",
"k1",
";",
"}",
"hash",
"^=",
"data",
".",
"length",
";",
"hash",
"^=",
"hash",
">>>",
"16",
";",
"hash",
"=",
"mul32",
"(",
"hash",
",",
"0x85ebca6b",
")",
";",
"hash",
"^=",
"hash",
">>>",
"13",
";",
"hash",
"=",
"mul32",
"(",
"hash",
",",
"0xc2b2ae35",
")",
";",
"hash",
"^=",
"hash",
">>>",
"16",
";",
"return",
"hash",
">>>",
"0",
";",
"}"
] | MurmurHash is a non-cryptographic hash function suitable for general hash-based lookup
@see https://en.wikipedia.org/wiki/MurmurHash
@see https://github.com/petertodd/python-bitcoinlib/blob/master/bitcoin/bloom.py
@see https://github.com/bitcoinj/bitcoinj/blob/master/core/src/main/java/org/bitcoinj/core/BloomFilter.java#L170
@see https://github.com/bitcoin/bitcoin/blob/master/src/hash.cpp
@see https://github.com/indutny/bcoin/blob/master/lib/bcoin/bloom.js
@see https://github.com/garycourt/murmurhash-js
@param {Buffer} data to be hashed
@param {Number} seed Positive integer only
@return {Number} a 32-bit positive integer hash | [
"MurmurHash",
"is",
"a",
"non",
"-",
"cryptographic",
"hash",
"function",
"suitable",
"for",
"general",
"hash",
"-",
"based",
"lookup"
] | 937f18b33a190a2a94bff166fc82bd9c8977bea0 | https://github.com/bitpay/bloom-filter/blob/937f18b33a190a2a94bff166fc82bd9c8977bea0/lib/murmurhash3.js#L17-L84 |
26,288 | fasttime/JScrewIt | lib/jscrewit.js | function ()
{
var mask = this.mask;
var included =
_Array_prototype_every.call
(
arguments,
function (arg)
{
var otherMask = validMaskFromArrayOrStringOrFeature(arg);
var result = maskIncludes(mask, otherMask);
return result;
}
);
return included;
} | javascript | function ()
{
var mask = this.mask;
var included =
_Array_prototype_every.call
(
arguments,
function (arg)
{
var otherMask = validMaskFromArrayOrStringOrFeature(arg);
var result = maskIncludes(mask, otherMask);
return result;
}
);
return included;
} | [
"function",
"(",
")",
"{",
"var",
"mask",
"=",
"this",
".",
"mask",
";",
"var",
"included",
"=",
"_Array_prototype_every",
".",
"call",
"(",
"arguments",
",",
"function",
"(",
"arg",
")",
"{",
"var",
"otherMask",
"=",
"validMaskFromArrayOrStringOrFeature",
"(",
"arg",
")",
";",
"var",
"result",
"=",
"maskIncludes",
"(",
"mask",
",",
"otherMask",
")",
";",
"return",
"result",
";",
"}",
")",
";",
"return",
"included",
";",
"}"
] | Determines whether this feature object includes all of the specified features.
@function JScrewIt.Feature#includes
@param {...(FeatureElement|CompatibleFeatureArray)} [feature]
@returns {boolean}
`true` if this feature object includes all of the specified features; otherwise, `false`.
If no arguments are specified, the return value is `true`. | [
"Determines",
"whether",
"this",
"feature",
"object",
"includes",
"all",
"of",
"the",
"specified",
"features",
"."
] | f0a9e93ccbc957d72ed775a7ad528a6b1fe9ffcc | https://github.com/fasttime/JScrewIt/blob/f0a9e93ccbc957d72ed775a7ad528a6b1fe9ffcc/lib/jscrewit.js#L1980-L1995 | |
26,289 | fasttime/JScrewIt | lib/jscrewit.js | function (environment, engineFeatureObjs)
{
var resultMask = maskNew();
var thisMask = this.mask;
var attributeCache = createEmpty();
ELEMENTARY.forEach
(
function (featureObj)
{
var otherMask = featureObj.mask;
var included = maskIncludes(thisMask, otherMask);
if (included)
{
var attributeValue = featureObj.attributes[environment];
if
(
attributeValue === undefined ||
engineFeatureObjs !== undefined &&
!isExcludingAttribute(attributeCache, attributeValue, engineFeatureObjs)
)
resultMask = maskUnion(resultMask, otherMask);
}
}
);
var result = featureFromMask(resultMask);
return result;
} | javascript | function (environment, engineFeatureObjs)
{
var resultMask = maskNew();
var thisMask = this.mask;
var attributeCache = createEmpty();
ELEMENTARY.forEach
(
function (featureObj)
{
var otherMask = featureObj.mask;
var included = maskIncludes(thisMask, otherMask);
if (included)
{
var attributeValue = featureObj.attributes[environment];
if
(
attributeValue === undefined ||
engineFeatureObjs !== undefined &&
!isExcludingAttribute(attributeCache, attributeValue, engineFeatureObjs)
)
resultMask = maskUnion(resultMask, otherMask);
}
}
);
var result = featureFromMask(resultMask);
return result;
} | [
"function",
"(",
"environment",
",",
"engineFeatureObjs",
")",
"{",
"var",
"resultMask",
"=",
"maskNew",
"(",
")",
";",
"var",
"thisMask",
"=",
"this",
".",
"mask",
";",
"var",
"attributeCache",
"=",
"createEmpty",
"(",
")",
";",
"ELEMENTARY",
".",
"forEach",
"(",
"function",
"(",
"featureObj",
")",
"{",
"var",
"otherMask",
"=",
"featureObj",
".",
"mask",
";",
"var",
"included",
"=",
"maskIncludes",
"(",
"thisMask",
",",
"otherMask",
")",
";",
"if",
"(",
"included",
")",
"{",
"var",
"attributeValue",
"=",
"featureObj",
".",
"attributes",
"[",
"environment",
"]",
";",
"if",
"(",
"attributeValue",
"===",
"undefined",
"||",
"engineFeatureObjs",
"!==",
"undefined",
"&&",
"!",
"isExcludingAttribute",
"(",
"attributeCache",
",",
"attributeValue",
",",
"engineFeatureObjs",
")",
")",
"resultMask",
"=",
"maskUnion",
"(",
"resultMask",
",",
"otherMask",
")",
";",
"}",
"}",
")",
";",
"var",
"result",
"=",
"featureFromMask",
"(",
"resultMask",
")",
";",
"return",
"result",
";",
"}"
] | Creates a new feature object from this feature by removing elementary features that are
not available inside a particular environment.
This method is useful to selectively exclude features that are available inside a web
worker.
@function JScrewIt.Feature#restrict
@param {string} environment
The environment to which this feature should be restricted.
Two environments are currently supported.
<dl>
<dt><code>"forced-strict-mode"</code></dt>
<dd>
Removes features that are not available in environments that require strict mode
code.</dd>
<dt><code>"web-worker"</code></dt>
<dd>Removes features that are not available inside web workers.</dd>
</dl>
@param {JScrewIt.Feature[]} [engineFeatureObjs]
An array of predefined feature objects, each corresponding to a particular engine in
which the restriction should be enacted.
If this parameter is omitted, the restriction is enacted in all engines.
@returns {JScrewIt.Feature}
A feature object. | [
"Creates",
"a",
"new",
"feature",
"object",
"from",
"this",
"feature",
"by",
"removing",
"elementary",
"features",
"that",
"are",
"not",
"available",
"inside",
"a",
"particular",
"environment",
"."
] | f0a9e93ccbc957d72ed775a7ad528a6b1fe9ffcc | https://github.com/fasttime/JScrewIt/blob/f0a9e93ccbc957d72ed775a7ad528a6b1fe9ffcc/lib/jscrewit.js#L2052-L2078 | |
26,290 | fasttime/JScrewIt | lib/jscrewit.js | function ()
{
var name = this.name;
if (name === undefined)
name = '{' + this.canonicalNames.join(', ') + '}';
var str = '[Feature ' + name + ']';
return str;
} | javascript | function ()
{
var name = this.name;
if (name === undefined)
name = '{' + this.canonicalNames.join(', ') + '}';
var str = '[Feature ' + name + ']';
return str;
} | [
"function",
"(",
")",
"{",
"var",
"name",
"=",
"this",
".",
"name",
";",
"if",
"(",
"name",
"===",
"undefined",
")",
"name",
"=",
"'{'",
"+",
"this",
".",
"canonicalNames",
".",
"join",
"(",
"', '",
")",
"+",
"'}'",
";",
"var",
"str",
"=",
"'[Feature '",
"+",
"name",
"+",
"']'",
";",
"return",
"str",
";",
"}"
] | Returns a string representation of this feature object.
@function JScrewIt.Feature#toString
@returns {string}
A string representation of this feature object. | [
"Returns",
"a",
"string",
"representation",
"of",
"this",
"feature",
"object",
"."
] | f0a9e93ccbc957d72ed775a7ad528a6b1fe9ffcc | https://github.com/fasttime/JScrewIt/blob/f0a9e93ccbc957d72ed775a7ad528a6b1fe9ffcc/lib/jscrewit.js#L2090-L2097 | |
26,291 | fasttime/JScrewIt | lib/jscrewit.js | function (str, options)
{
options = options || { };
var optimize = options.optimize;
var optimizerList = [];
if (optimize)
{
var optimizeComplex;
var optimizeToString;
if (typeof optimize === 'object')
{
optimizeComplex = !!optimize.complexOpt;
optimizeToString = !!optimize.toStringOpt;
}
else
optimizeComplex = optimizeToString = true;
var optimizers = this.optimizers;
var optimizer;
if (optimizeComplex)
{
var complexOptimizers = optimizers.complex;
if (!complexOptimizers)
complexOptimizers = optimizers.complex = createEmpty();
for (var complex in COMPLEX)
{
var entry = COMPLEX[complex];
if (this.hasFeatures(entry.mask) && str.indexOf(complex) >= 0)
{
optimizer =
complexOptimizers[complex] ||
(
complexOptimizers[complex] =
getComplexOptimizer(this, complex, entry.definition)
);
optimizerList.push(optimizer);
}
}
}
if (optimizeToString)
{
optimizer =
optimizers.toString || (optimizers.toString = getToStringOptimizer(this));
optimizerList.push(optimizer);
}
}
var buffer =
new ScrewBuffer
(options.bond, options.forceString, this.maxGroupThreshold, optimizerList);
var firstSolution = options.firstSolution;
var maxLength = options.maxLength;
if (firstSolution)
{
buffer.append(firstSolution);
if (buffer.length > maxLength)
return;
}
var match;
var regExp = _RegExp(STR_TOKEN_PATTERN, 'g');
while (match = regExp.exec(str))
{
var token;
var solution;
if (token = match[2])
solution = this.resolveCharacter(token);
else
{
token = match[1];
solution = SIMPLE[token];
}
if (!buffer.append(solution) || buffer.length > maxLength)
return;
}
var result = _String(buffer);
if (!(result.length > maxLength))
return result;
} | javascript | function (str, options)
{
options = options || { };
var optimize = options.optimize;
var optimizerList = [];
if (optimize)
{
var optimizeComplex;
var optimizeToString;
if (typeof optimize === 'object')
{
optimizeComplex = !!optimize.complexOpt;
optimizeToString = !!optimize.toStringOpt;
}
else
optimizeComplex = optimizeToString = true;
var optimizers = this.optimizers;
var optimizer;
if (optimizeComplex)
{
var complexOptimizers = optimizers.complex;
if (!complexOptimizers)
complexOptimizers = optimizers.complex = createEmpty();
for (var complex in COMPLEX)
{
var entry = COMPLEX[complex];
if (this.hasFeatures(entry.mask) && str.indexOf(complex) >= 0)
{
optimizer =
complexOptimizers[complex] ||
(
complexOptimizers[complex] =
getComplexOptimizer(this, complex, entry.definition)
);
optimizerList.push(optimizer);
}
}
}
if (optimizeToString)
{
optimizer =
optimizers.toString || (optimizers.toString = getToStringOptimizer(this));
optimizerList.push(optimizer);
}
}
var buffer =
new ScrewBuffer
(options.bond, options.forceString, this.maxGroupThreshold, optimizerList);
var firstSolution = options.firstSolution;
var maxLength = options.maxLength;
if (firstSolution)
{
buffer.append(firstSolution);
if (buffer.length > maxLength)
return;
}
var match;
var regExp = _RegExp(STR_TOKEN_PATTERN, 'g');
while (match = regExp.exec(str))
{
var token;
var solution;
if (token = match[2])
solution = this.resolveCharacter(token);
else
{
token = match[1];
solution = SIMPLE[token];
}
if (!buffer.append(solution) || buffer.length > maxLength)
return;
}
var result = _String(buffer);
if (!(result.length > maxLength))
return result;
} | [
"function",
"(",
"str",
",",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"var",
"optimize",
"=",
"options",
".",
"optimize",
";",
"var",
"optimizerList",
"=",
"[",
"]",
";",
"if",
"(",
"optimize",
")",
"{",
"var",
"optimizeComplex",
";",
"var",
"optimizeToString",
";",
"if",
"(",
"typeof",
"optimize",
"===",
"'object'",
")",
"{",
"optimizeComplex",
"=",
"!",
"!",
"optimize",
".",
"complexOpt",
";",
"optimizeToString",
"=",
"!",
"!",
"optimize",
".",
"toStringOpt",
";",
"}",
"else",
"optimizeComplex",
"=",
"optimizeToString",
"=",
"true",
";",
"var",
"optimizers",
"=",
"this",
".",
"optimizers",
";",
"var",
"optimizer",
";",
"if",
"(",
"optimizeComplex",
")",
"{",
"var",
"complexOptimizers",
"=",
"optimizers",
".",
"complex",
";",
"if",
"(",
"!",
"complexOptimizers",
")",
"complexOptimizers",
"=",
"optimizers",
".",
"complex",
"=",
"createEmpty",
"(",
")",
";",
"for",
"(",
"var",
"complex",
"in",
"COMPLEX",
")",
"{",
"var",
"entry",
"=",
"COMPLEX",
"[",
"complex",
"]",
";",
"if",
"(",
"this",
".",
"hasFeatures",
"(",
"entry",
".",
"mask",
")",
"&&",
"str",
".",
"indexOf",
"(",
"complex",
")",
">=",
"0",
")",
"{",
"optimizer",
"=",
"complexOptimizers",
"[",
"complex",
"]",
"||",
"(",
"complexOptimizers",
"[",
"complex",
"]",
"=",
"getComplexOptimizer",
"(",
"this",
",",
"complex",
",",
"entry",
".",
"definition",
")",
")",
";",
"optimizerList",
".",
"push",
"(",
"optimizer",
")",
";",
"}",
"}",
"}",
"if",
"(",
"optimizeToString",
")",
"{",
"optimizer",
"=",
"optimizers",
".",
"toString",
"||",
"(",
"optimizers",
".",
"toString",
"=",
"getToStringOptimizer",
"(",
"this",
")",
")",
";",
"optimizerList",
".",
"push",
"(",
"optimizer",
")",
";",
"}",
"}",
"var",
"buffer",
"=",
"new",
"ScrewBuffer",
"(",
"options",
".",
"bond",
",",
"options",
".",
"forceString",
",",
"this",
".",
"maxGroupThreshold",
",",
"optimizerList",
")",
";",
"var",
"firstSolution",
"=",
"options",
".",
"firstSolution",
";",
"var",
"maxLength",
"=",
"options",
".",
"maxLength",
";",
"if",
"(",
"firstSolution",
")",
"{",
"buffer",
".",
"append",
"(",
"firstSolution",
")",
";",
"if",
"(",
"buffer",
".",
"length",
">",
"maxLength",
")",
"return",
";",
"}",
"var",
"match",
";",
"var",
"regExp",
"=",
"_RegExp",
"(",
"STR_TOKEN_PATTERN",
",",
"'g'",
")",
";",
"while",
"(",
"match",
"=",
"regExp",
".",
"exec",
"(",
"str",
")",
")",
"{",
"var",
"token",
";",
"var",
"solution",
";",
"if",
"(",
"token",
"=",
"match",
"[",
"2",
"]",
")",
"solution",
"=",
"this",
".",
"resolveCharacter",
"(",
"token",
")",
";",
"else",
"{",
"token",
"=",
"match",
"[",
"1",
"]",
";",
"solution",
"=",
"SIMPLE",
"[",
"token",
"]",
";",
"}",
"if",
"(",
"!",
"buffer",
".",
"append",
"(",
"solution",
")",
"||",
"buffer",
".",
"length",
">",
"maxLength",
")",
"return",
";",
"}",
"var",
"result",
"=",
"_String",
"(",
"buffer",
")",
";",
"if",
"(",
"!",
"(",
"result",
".",
"length",
">",
"maxLength",
")",
")",
"return",
"result",
";",
"}"
] | Replaces a given string with equivalent JSFuck code.
@function Encoder#replaceString
@param {string} str
The string to replace.
@param {object} [options={ }]
An optional object specifying replacement options.
@param {boolean} [options.bond=false]
Indicates whether the replacement expression should be bonded.
An expression is bonded if it can be treated as a single unit by any valid operators
placed immediately before or after it.
E.g. `[][[]]` is bonded but `![]` is not, because `![][[]]` is different from
`(![])[[]]`.
More exactly, a bonded expression does not contain an outer plus and does not start
with `!`.
Any expression becomes bonded when enclosed into parentheses.
@param {Solution} [options.firstSolution]
An optional solution to be prepended to the replacement string.
@param {boolean} [options.forceString=false]
Indicates whether the replacement expression should evaluate to a string.
If this parameter is falsy, the value of the replacement expression may not be equal to
the input string, but will have the same string representation.
@param {number} [options.maxLength=(NaN)]
The maximum length of the replacement expression.
If the replacement expression exceeds the specified length, the return value is
`undefined`.
If this parameter is `NaN`, then no length limit is imposed.
@param {boolean|object<string, boolean|*>} [options.optimize=false]
Specifies which optimizations should be attempted.
Optimizations may reduce the length of the replacement string, but they also reduce the
performance and may lead to unwanted circular dependencies when resolving
definitions.
This parameter can be set to a boolean value in order to turn all optimizations on
(`true`) or off (`false`).
In order to turn specific optimizations on or off, specify an object that maps
optimization names with the suffix "Opt" to booleans, or to any other optimization
specific kind of data.
@returns {string|undefined}
The replacement string or `undefined`. | [
"Replaces",
"a",
"given",
"string",
"with",
"equivalent",
"JSFuck",
"code",
"."
] | f0a9e93ccbc957d72ed775a7ad528a6b1fe9ffcc | https://github.com/fasttime/JScrewIt/blob/f0a9e93ccbc957d72ed775a7ad528a6b1fe9ffcc/lib/jscrewit.js#L5801-L5876 | |
26,292 | fasttime/JScrewIt | lib/jscrewit.js | function (array, maxLength)
{
var result =
this.replaceStringArray(array, [FALSE_FREE_DELIMITER], null, false, maxLength);
return result;
} | javascript | function (array, maxLength)
{
var result =
this.replaceStringArray(array, [FALSE_FREE_DELIMITER], null, false, maxLength);
return result;
} | [
"function",
"(",
"array",
",",
"maxLength",
")",
"{",
"var",
"result",
"=",
"this",
".",
"replaceStringArray",
"(",
"array",
",",
"[",
"FALSE_FREE_DELIMITER",
"]",
",",
"null",
",",
"false",
",",
"maxLength",
")",
";",
"return",
"result",
";",
"}"
] | Array elements may not contain the substring "false", because the value false could be used as a separator in the encoding. | [
"Array",
"elements",
"may",
"not",
"contain",
"the",
"substring",
"false",
"because",
"the",
"value",
"false",
"could",
"be",
"used",
"as",
"a",
"separator",
"in",
"the",
"encoding",
"."
] | f0a9e93ccbc957d72ed775a7ad528a6b1fe9ffcc | https://github.com/fasttime/JScrewIt/blob/f0a9e93ccbc957d72ed775a7ad528a6b1fe9ffcc/lib/jscrewit.js#L7469-L7474 | |
26,293 | fasttime/JScrewIt | lib/jscrewit.js | encode | function encode(input, options)
{
input = esToString(input);
options = options || { };
var features = options.features;
var runAsData;
var runAs = options.runAs;
if (runAs !== undefined)
runAsData = filterRunAs(runAs, 'runAs');
else
runAsData = filterRunAs(options.wrapWith, 'wrapWith');
var wrapper = runAsData[0];
var strategyNames = runAsData[1];
if (options.trimCode)
input = trimJS(input);
var perfInfo = options.perfInfo;
var encoder = getEncoder(features);
var output = encoder.exec(input, wrapper, strategyNames, perfInfo);
return output;
} | javascript | function encode(input, options)
{
input = esToString(input);
options = options || { };
var features = options.features;
var runAsData;
var runAs = options.runAs;
if (runAs !== undefined)
runAsData = filterRunAs(runAs, 'runAs');
else
runAsData = filterRunAs(options.wrapWith, 'wrapWith');
var wrapper = runAsData[0];
var strategyNames = runAsData[1];
if (options.trimCode)
input = trimJS(input);
var perfInfo = options.perfInfo;
var encoder = getEncoder(features);
var output = encoder.exec(input, wrapper, strategyNames, perfInfo);
return output;
} | [
"function",
"encode",
"(",
"input",
",",
"options",
")",
"{",
"input",
"=",
"esToString",
"(",
"input",
")",
";",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"var",
"features",
"=",
"options",
".",
"features",
";",
"var",
"runAsData",
";",
"var",
"runAs",
"=",
"options",
".",
"runAs",
";",
"if",
"(",
"runAs",
"!==",
"undefined",
")",
"runAsData",
"=",
"filterRunAs",
"(",
"runAs",
",",
"'runAs'",
")",
";",
"else",
"runAsData",
"=",
"filterRunAs",
"(",
"options",
".",
"wrapWith",
",",
"'wrapWith'",
")",
";",
"var",
"wrapper",
"=",
"runAsData",
"[",
"0",
"]",
";",
"var",
"strategyNames",
"=",
"runAsData",
"[",
"1",
"]",
";",
"if",
"(",
"options",
".",
"trimCode",
")",
"input",
"=",
"trimJS",
"(",
"input",
")",
";",
"var",
"perfInfo",
"=",
"options",
".",
"perfInfo",
";",
"var",
"encoder",
"=",
"getEncoder",
"(",
"features",
")",
";",
"var",
"output",
"=",
"encoder",
".",
"exec",
"(",
"input",
",",
"wrapper",
",",
"strategyNames",
",",
"perfInfo",
")",
";",
"return",
"output",
";",
"}"
] | Encodes a given string into JSFuck.
@function JScrewIt.encode
@param {string} input
The string to encode.
@param {object} [options={ }]
An optional object specifying encoding options.
@param {FeatureElement|CompatibleFeatureArray} [options.features=JScrewIt.Feature.DEFAULT]
<p>
Specifies the features available in the engines that evaluate the encoded output.</p>
<p>
If this parameter is unspecified, [`JScrewIt.Feature.DEFAULT`](Features.md#DEFAULT) is
assumed: this ensures maximum compatibility but also generates the largest code.
To generate shorter code, specify all features available in all target engines
explicitly.</p>
@param {string} [options.runAs=express-eval]
This option controls the type of code generated from the given input.
Allowed values are listed below.
<dl>
<dt><code>"call"</code></dt>
<dd>
Produces code evaluating to a call to a function whose body contains the specified input
string.</dd>
<dt><code>"eval"</code></dt>
<dd>
Produces code evaluating to the result of invoking <code>eval</code> with the specified
input string as parameter.</dd>
<dt><code>"express"</code></dt>
<dd>
Attempts to interpret the specified string as JavaScript code and produce functionally
equivalent JSFuck code.
Fails if the specified string cannot be expressed as JavaScript, or if no functionally
equivalent JSFuck code can be generated.</dd>
<dt><code>"express-call"</code></dt>
<dd>
Applies the code generation process of both <code>"express"</code> and <code>"call"</code>
and returns the shortest output.</dd>
<dt><code>"express-eval"</code> (default)</dt>
<dd>
Applies the code generation process of both <code>"express"</code> and <code>"eval"</code>
and returns the shortest output.</dd>
<dt><code>"none"</code></dt>
<dd>
Produces JSFuck code that translates to the specified input string (except for trimmed parts
when used in conjunction with the option <code>trimCode</code>).
Unlike other methods, <code>"none"</code> does not generate executable code but just a plain
string.
</dd>
</dl>
@param {boolean} [options.trimCode=false]
<p>
If this parameter is truthy, lines in the beginning and in the end of the file containing
nothing but space characters and JavaScript comments are removed from the generated output.
A newline terminator in the last preserved line is also removed.</p>
<p>
This option is especially useful to strip banner comments and trailing newline characters
which are sometimes found in minified scripts.</p>
<p>
Using this option may produce unexpected results if the input is not well-formed JavaScript
code.</p>
@param {string} [options.wrapWith=express-eval]
An alias for `runAs`.
@returns {string}
The encoded string.
@throws
An `Error` is thrown under the following circumstances.
- The specified string cannot be encoded with the specified options.
- Some unknown features were specified.
- A combination of mutually incompatible features was specified.
- The option `runAs` (or `wrapWith`) was specified with an invalid value.
Also, an out of memory condition may occur when processing very large data. | [
"Encodes",
"a",
"given",
"string",
"into",
"JSFuck",
"."
] | f0a9e93ccbc957d72ed775a7ad528a6b1fe9ffcc | https://github.com/fasttime/JScrewIt/blob/f0a9e93ccbc957d72ed775a7ad528a6b1fe9ffcc/lib/jscrewit.js#L7928-L7947 |
26,294 | basho/riak-nodejs-client | lib/commands/crdt/updatemap.js | MapOperation | function MapOperation() {
this.counters = { increment: [], remove : []};
this.maps = { modify: [], remove: []};
this.sets = { adds: [], removes: [], remove: []};
this.registers = { set: [], remove: [] };
this.flags = { set: [], remove: [] };
} | javascript | function MapOperation() {
this.counters = { increment: [], remove : []};
this.maps = { modify: [], remove: []};
this.sets = { adds: [], removes: [], remove: []};
this.registers = { set: [], remove: [] };
this.flags = { set: [], remove: [] };
} | [
"function",
"MapOperation",
"(",
")",
"{",
"this",
".",
"counters",
"=",
"{",
"increment",
":",
"[",
"]",
",",
"remove",
":",
"[",
"]",
"}",
";",
"this",
".",
"maps",
"=",
"{",
"modify",
":",
"[",
"]",
",",
"remove",
":",
"[",
"]",
"}",
";",
"this",
".",
"sets",
"=",
"{",
"adds",
":",
"[",
"]",
",",
"removes",
":",
"[",
"]",
",",
"remove",
":",
"[",
"]",
"}",
";",
"this",
".",
"registers",
"=",
"{",
"set",
":",
"[",
"]",
",",
"remove",
":",
"[",
"]",
"}",
";",
"this",
".",
"flags",
"=",
"{",
"set",
":",
"[",
"]",
",",
"remove",
":",
"[",
"]",
"}",
";",
"}"
] | Class that encapsulates modifications to a Map in Riak.
Rather than manually constructing this yourself, a fluent API is provided.
var mapOp = new UpdateMap.MapOperation();
mapOp.incrementCounter('counter_1', 50)
.addToSet('set_1', 'set_value_1')
.setRegister('register_1', new Buffer('register_value_1'))
.setFlag('flag_1', true)
.map('inner_map')
.incrementCounter('counter_1', 50)
.addToSet('set_2', 'set_value_2');
@class UpdateMap.MapOperation
@constructor | [
"Class",
"that",
"encapsulates",
"modifications",
"to",
"a",
"Map",
"in",
"Riak",
"."
] | 4823460b56b4defee69837995bde98e789b635bd | https://github.com/basho/riak-nodejs-client/blob/4823460b56b4defee69837995bde98e789b635bd/lib/commands/crdt/updatemap.js#L476-L482 |
26,295 | basho/riak-nodejs-client | lib/commands/crdt/updatemap.js | function(key) {
this._removeAddsOrRemoves(this.counters.increment, key);
if (this.counters.remove.indexOf(key) === -1) {
this.counters.remove.push(key);
}
return this;
} | javascript | function(key) {
this._removeAddsOrRemoves(this.counters.increment, key);
if (this.counters.remove.indexOf(key) === -1) {
this.counters.remove.push(key);
}
return this;
} | [
"function",
"(",
"key",
")",
"{",
"this",
".",
"_removeAddsOrRemoves",
"(",
"this",
".",
"counters",
".",
"increment",
",",
"key",
")",
";",
"if",
"(",
"this",
".",
"counters",
".",
"remove",
".",
"indexOf",
"(",
"key",
")",
"===",
"-",
"1",
")",
"{",
"this",
".",
"counters",
".",
"remove",
".",
"push",
"(",
"key",
")",
";",
"}",
"return",
"this",
";",
"}"
] | Remove a counter from a map.
@method removeCounter
@param {String} key the key in the map for this counter.
@chainable | [
"Remove",
"a",
"counter",
"from",
"a",
"map",
"."
] | 4823460b56b4defee69837995bde98e789b635bd | https://github.com/basho/riak-nodejs-client/blob/4823460b56b4defee69837995bde98e789b635bd/lib/commands/crdt/updatemap.js#L509-L515 | |
26,296 | basho/riak-nodejs-client | lib/commands/crdt/updatemap.js | function(key, value) {
this._removeRemove(this.sets.remove, key);
var op = this._getOp(this.sets.removes, key);
if (op) {
op.remove.push(value);
} else {
this.sets.removes.push({key: key, remove: [value]});
}
return this;
} | javascript | function(key, value) {
this._removeRemove(this.sets.remove, key);
var op = this._getOp(this.sets.removes, key);
if (op) {
op.remove.push(value);
} else {
this.sets.removes.push({key: key, remove: [value]});
}
return this;
} | [
"function",
"(",
"key",
",",
"value",
")",
"{",
"this",
".",
"_removeRemove",
"(",
"this",
".",
"sets",
".",
"remove",
",",
"key",
")",
";",
"var",
"op",
"=",
"this",
".",
"_getOp",
"(",
"this",
".",
"sets",
".",
"removes",
",",
"key",
")",
";",
"if",
"(",
"op",
")",
"{",
"op",
".",
"remove",
".",
"push",
"(",
"value",
")",
";",
"}",
"else",
"{",
"this",
".",
"sets",
".",
"removes",
".",
"push",
"(",
"{",
"key",
":",
"key",
",",
"remove",
":",
"[",
"value",
"]",
"}",
")",
";",
"}",
"return",
"this",
";",
"}"
] | Remove a value from a set in a map.
@method removeFromSet
@param {String} key the key for the set in the map.
@param {String|Buffer} value the value to remove from the set.
@chainable | [
"Remove",
"a",
"value",
"from",
"a",
"set",
"in",
"a",
"map",
"."
] | 4823460b56b4defee69837995bde98e789b635bd | https://github.com/basho/riak-nodejs-client/blob/4823460b56b4defee69837995bde98e789b635bd/lib/commands/crdt/updatemap.js#L540-L549 | |
26,297 | basho/riak-nodejs-client | lib/commands/crdt/updatemap.js | function(key) {
this._removeAddsOrRemoves(this.sets.adds, key);
this._removeAddsOrRemoves(this.sets.removes, key);
if (this.sets.remove.indexOf(key) === -1) {
this.sets.remove.push(key);
}
return this;
} | javascript | function(key) {
this._removeAddsOrRemoves(this.sets.adds, key);
this._removeAddsOrRemoves(this.sets.removes, key);
if (this.sets.remove.indexOf(key) === -1) {
this.sets.remove.push(key);
}
return this;
} | [
"function",
"(",
"key",
")",
"{",
"this",
".",
"_removeAddsOrRemoves",
"(",
"this",
".",
"sets",
".",
"adds",
",",
"key",
")",
";",
"this",
".",
"_removeAddsOrRemoves",
"(",
"this",
".",
"sets",
".",
"removes",
",",
"key",
")",
";",
"if",
"(",
"this",
".",
"sets",
".",
"remove",
".",
"indexOf",
"(",
"key",
")",
"===",
"-",
"1",
")",
"{",
"this",
".",
"sets",
".",
"remove",
".",
"push",
"(",
"key",
")",
";",
"}",
"return",
"this",
";",
"}"
] | Remove a set from a map.
@method removeSet
@param {String} key the key for the set in the map.
@chainable | [
"Remove",
"a",
"set",
"from",
"a",
"map",
"."
] | 4823460b56b4defee69837995bde98e789b635bd | https://github.com/basho/riak-nodejs-client/blob/4823460b56b4defee69837995bde98e789b635bd/lib/commands/crdt/updatemap.js#L556-L563 | |
26,298 | basho/riak-nodejs-client | lib/commands/crdt/updatemap.js | function(key, value) {
this._removeRemove(this.registers.remove, key);
var op = this._getOp(this.registers.set, key);
if (op) {
op.value = value;
} else {
this.registers.set.push({key: key, value: value});
}
return this;
} | javascript | function(key, value) {
this._removeRemove(this.registers.remove, key);
var op = this._getOp(this.registers.set, key);
if (op) {
op.value = value;
} else {
this.registers.set.push({key: key, value: value});
}
return this;
} | [
"function",
"(",
"key",
",",
"value",
")",
"{",
"this",
".",
"_removeRemove",
"(",
"this",
".",
"registers",
".",
"remove",
",",
"key",
")",
";",
"var",
"op",
"=",
"this",
".",
"_getOp",
"(",
"this",
".",
"registers",
".",
"set",
",",
"key",
")",
";",
"if",
"(",
"op",
")",
"{",
"op",
".",
"value",
"=",
"value",
";",
"}",
"else",
"{",
"this",
".",
"registers",
".",
"set",
".",
"push",
"(",
"{",
"key",
":",
"key",
",",
"value",
":",
"value",
"}",
")",
";",
"}",
"return",
"this",
";",
"}"
] | Set a register in a map.
@method setRegister
@param {String} key the key for the register in the map.
@param {String|Buffer} value the value for the register.
@chainable} | [
"Set",
"a",
"register",
"in",
"a",
"map",
"."
] | 4823460b56b4defee69837995bde98e789b635bd | https://github.com/basho/riak-nodejs-client/blob/4823460b56b4defee69837995bde98e789b635bd/lib/commands/crdt/updatemap.js#L571-L580 | |
26,299 | basho/riak-nodejs-client | lib/commands/crdt/updatemap.js | function(key) {
this._removeAddsOrRemoves(this.registers.set, key);
if (this.registers.remove.indexOf(key) === -1) {
this.registers.remove.push(key);
}
return this;
} | javascript | function(key) {
this._removeAddsOrRemoves(this.registers.set, key);
if (this.registers.remove.indexOf(key) === -1) {
this.registers.remove.push(key);
}
return this;
} | [
"function",
"(",
"key",
")",
"{",
"this",
".",
"_removeAddsOrRemoves",
"(",
"this",
".",
"registers",
".",
"set",
",",
"key",
")",
";",
"if",
"(",
"this",
".",
"registers",
".",
"remove",
".",
"indexOf",
"(",
"key",
")",
"===",
"-",
"1",
")",
"{",
"this",
".",
"registers",
".",
"remove",
".",
"push",
"(",
"key",
")",
";",
"}",
"return",
"this",
";",
"}"
] | Remove a register from a map.
@method removeRegister
@param {String} key the key for the register in the map.
@chainable | [
"Remove",
"a",
"register",
"from",
"a",
"map",
"."
] | 4823460b56b4defee69837995bde98e789b635bd | https://github.com/basho/riak-nodejs-client/blob/4823460b56b4defee69837995bde98e789b635bd/lib/commands/crdt/updatemap.js#L587-L593 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.