_id stringlengths 2 6 | title stringlengths 0 58 | partition stringclasses 3
values | text stringlengths 52 373k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q51000 | acceptable | train | function acceptable(value) {
return vowels.test(value.charAt(0))
? value.length > 1
: value.length > 2 && vowels.test(value)
} | javascript | {
"resource": ""
} |
q51001 | train | function (value) {
if (! _defined(value)) return defaults;
angular.forEach(value, function (val, key) {
if (defaults.hasOwnProperty(key)) defaults[key] = val;
});
} | javascript | {
"resource": ""
} | |
q51002 | train | function (key, value, def) {
if (! this.has(key)) {
this.put(key, value, def);
return true;
}
return false;
} | javascript | {
"resource": ""
} | |
q51003 | train | function (key, def) {
if (angular.isArray(key)) {
var items = {};
angular.forEach(key, function (k) {
if (this.has(k)) items[k] = this._getItem(k);
}, this);
... | javascript | {
"resource": ""
} | |
q51004 | transformJSX | train | function transformJSX(fileStream, fileName, opts, cb){
// Allow omitting filename
if (typeof fileName === "object"){
cb = opts;
opts = fileName;
fileName = fileStream;
}
if (!babel && (opts['--babel'] || opts['--babel-experimental'])) {
throw new Error("Optional babel parser not installed. Ple... | javascript | {
"resource": ""
} |
q51005 | showHelp | train | function showHelp(){
var jshint_proc = fork(require.resolve('jshint/bin/jshint'), ['-h'], {silent: true});
var ts = through(function write(chunk){
this.queue(chunk.toString().replace(/(jshint)\b/g, 'jsxhint'));
}, function end() {
// This feels like a hack. There might be a better way to do this.
this... | javascript | {
"resource": ""
} |
q51006 | showVersion | train | function showVersion(){
var jshint_proc = fork(__dirname + '/node_modules/jshint/bin/jshint', ['-v'], {silent: true});
var ts = through(function write(chunk){
this.queue("JSXHint v" + require('./package.json').version + " (" +
chunk.toString().replace("\n", "") + ")\n");
});
jshint_proc.stderr.pipe(ts... | javascript | {
"resource": ""
} |
q51007 | runGlob | train | function runGlob(args, opts, cb) {
var dotIdx = args.indexOf('.');
if (dotIdx !== -1) {
args.splice(dotIdx, 1);
}
glob(args, opts, function(err, globbed) {
if (Array.isArray(globbed) && dotIdx !== -1) globbed.push('.');
cb(err, globbed);
});
} | javascript | {
"resource": ""
} |
q51008 | run | train | function run(opts, cb){
opts.extensions = opts.extensions ? opts.extensions + ',.jsx' : '.jsx';
// glob-all fixes windows glob issues and provides array support
// i.e. jsxhint ['jsx/**/*','!scripts/**/*','scripts/outlier.jsx']
runGlob(opts.args, {nodir: true}, function(err, globbed) {
if (err) return cb(e... | javascript | {
"resource": ""
} |
q51009 | interceptReporter | train | function interceptReporter(reporter, filesMap){
if(!reporter) reporter = require('jshint/src/reporters/default').reporter;
return function(results, data, opts){
if (filesMap) {
results.forEach(function(result){
result.file = filesMap[result.file];
});
}
return reporter(results, data,... | javascript | {
"resource": ""
} |
q51010 | train | function (dimensions) {
var _this = this;
return new Promise(function (resolve, reject) {
_this._paneDimensions = dimensions;
_this.paneDimensions.next(dimensions);
resolve();
});
} | javascript | {
"resource": ""
} | |
q51011 | train | function (positions) {
var _this = this;
this._points = positions;
positions.forEach(function (position) {
_this.positionChange(position);
});
this.repositionEvent.next(positions);
} | javascript | {
"resource": ""
} | |
q51012 | train | function (positionChangeData) {
var _this = this;
// update positions according to current position change
this.updatePosition(positionChangeData);
// for each direction:
// 1. filter the _points that have a role as the direction's limit
... | javascript | {
"resource": ""
} | |
q51013 | train | function (positionChange) {
var _this = this;
// finds the current position of the point by it's roles, than splices it for the new position or pushes it if it's not yet in the array
/** @type {?} */
var index = this._points.findIndex(function (point) {
... | javascript | {
"resource": ""
} | |
q51014 | train | function (positionChange) {
var _this = this;
/** @type {?} */
var pointLimits = this.limitDirections.filter(function (direction) {
return !positionChange.roles.includes(direction);
});
/** @type {?} */
v... | javascript | {
"resource": ""
} | |
q51015 | train | function (resizeRatios, initialPreviewDimensions, initialPositions) {
var _this = this;
// convert positions to ratio between position to initial pane dimension
initialPositions = initialPositions.map(function (point) {
return new PositionChangeData({
... | javascript | {
"resource": ""
} | |
q51016 | train | function (corner) {
var _this = this;
/** @type {?} */
var rotated = {
x: this._paneDimensions.width * (1 - corner.y),
y: this._paneDimensions.height * corner.x,
roles: []
};
// ro... | javascript | {
"resource": ""
} | |
q51017 | train | function (array1, array2) {
return array1.every(function (element) {
return array2.includes(element);
}) && array1.length === array2.length;
} | javascript | {
"resource": ""
} | |
q51018 | train | function (position) {
/** @type {?} */
var positionChangeData = new PositionChangeData(position, this.limitRoles);
/** @type {?} */
var limitException = this.limitsService.exceedsLimit(positionChangeData);
if (limitException.exceeds) {
... | javascript | {
"resource": ""
} | |
q51019 | train | function (limitException) {
/** @type {?} */
var newPosition = {
x: 0,
y: 0
};
Object.keys(this.startPosition).forEach(function (axis) {
newPosition[axis] = limitException.resetCoordinates[axis] +... | javascript | {
"resource": ""
} | |
q51020 | train | function (position) {
/** @type {?} */
var positionChangeData = new PositionChangeData(position, this.limitRoles);
/** @type {?} */
var limitException = this.limitsService.exceedsLimit(positionChangeData);
if (limitException.exceeds) {
... | javascript | {
"resource": ""
} | |
q51021 | train | function (dimensions) {
return {
x: this.limitRoles.includes('left') ? 0 : dimensions.width - this.width / 2,
y: this.limitRoles.includes('top') ? 0 : dimensions.height - this.height / 2
};
} | javascript | {
"resource": ""
} | |
q51022 | train | function (position) {
if (this._paneDimensions.width === 0 || this._paneDimensions.height === 0) {
return position;
}
else {
if (position.x > this._paneDimensions.width) {
position.x = this._paneDimensions.wi... | javascript | {
"resource": ""
} | |
q51023 | train | function () {
/** @type {?} */
var canvas = this.canvas.nativeElement;
/** @type {?} */
var ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, this.dimensions.width, this.dimensions.height);
} | javascript | {
"resource": ""
} | |
q51024 | train | function () {
var _this = this;
/** @type {?} */
var _points = Array.from(this._points);
/** @type {?} */
var sortedPoints = [];
/** @type {?} */
var sortOrder = {
vertical: ['top', 'top',... | javascript | {
"resource": ""
} | |
q51025 | train | function () {
var _this = this;
/** @type {?} */
var canvas = this.canvas.nativeElement;
/** @type {?} */
var ctx = canvas.getContext('2d');
ctx.lineWidth = this.weight;
ctx.strokeStyle = this.color;
... | javascript | {
"resource": ""
} | |
q51026 | train | function () {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.applyFilter(false)];
... | javascript | {
"resource": ""
} | |
q51027 | train | function () {
var _this = this;
/** @type {?} */
var data = { filter: this.selectedFilter };
/** @type {?} */
var bottomSheetRef = this.bottomSheet.open(NgxFilterMenuComponent, {
data: data
});
... | javascript | {
"resource": ""
} | |
q51028 | train | function (file) {
var _this = this;
return new Promise(function (resolve, reject) {
return __awaiter(_this, void 0, void 0, function () {
var imageSrc, err_3, img;
var _this = this;
return __gener... | javascript | {
"resource": ""
} | |
q51029 | readFile | train | function readFile() {
return new Promise(function (resolve, reject) {
/** @type {?} */
var reader = new FileReader();
reader.onload = function (event) {
resolve(reader.result);
... | javascript | {
"resource": ""
} |
q51030 | train | function () {
var _this = this;
return new Promise(function (resolve, reject) {
_this.processing.emit(true);
setTimeout(function () {
// load the image and compute the ratio of the old height to the new height, clone it, and... | javascript | {
"resource": ""
} | |
q51031 | train | function () {
var _this = this;
return new Promise(function (resolve, reject) {
_this.processing.emit(true);
setTimeout(function () {
/** @type {?} */
var dst = cv.imread(_this.editedImage);
... | javascript | {
"resource": ""
} | |
q51032 | train | function (image) {
var _this = this;
return new Promise(function (resolve, reject) {
_this.processing.emit(true);
setTimeout(function () {
/** @type {?} */
var src = cv.imread(image);
... | javascript | {
"resource": ""
} | |
q51033 | train | function (width, height) {
/** @type {?} */
var ratio = width / height;
/** @type {?} */
var maxWidth = this.screenDimensions.width > this.maxPreviewWidth ?
this.maxPreviewWidth : this.screenDimensions.width - 40;
/** @t... | javascript | {
"resource": ""
} | |
q51034 | train | function (roles) {
var _this = this;
return this.points.find(function (point) {
return _this.limitsService.compareArray(point.roles, roles);
});
} | javascript | {
"resource": ""
} | |
q51035 | longpollStream | train | function longpollStream(http, mutable) {
return asyncMapRecover(function(creds) {
return http({
timeout: LONGPOLL_TIMEOUT,
url: makeUrl(assign({}, creds, mutable))
}).then(function(body) {
return JSON.parse(body);
}).catch((error) => {
return Promise.reject({
type: ERROR_TY... | javascript | {
"resource": ""
} |
q51036 | cacher | train | function cacher() {
let cache = false;
return function(read) {
return function readable(end, cb) {
if (end === null && cache) {
cb(null, cache);
} else {
read(end, function (end, data) {
cache = data;
cb(end, data)
});
}
}
}
} | javascript | {
"resource": ""
} |
q51037 | safe3 | train | function safe3(fn) {
var queue = Queue.new();
var safe = true;
function checkQueue() {
var next = queue.shift();
safe = false;
fn(next[0], next[1], next[2], function (error, result) {
next[3](error, result);
if (queue.length > 0) {
checkQueue();
} else {
safe = true;
... | javascript | {
"resource": ""
} |
q51038 | removeNestedBlocks | train | function removeNestedBlocks (ast) {
var tagged;
while((tagged = findNestedBlocks(ast)).length) {
fast.forEach(tagged, function (item) {
var node = item[0],
parent = item[1],
index = parent.body.indexOf(node);
fast.apply(Array.prototype.splice, parent.body, fast.concat([index, 1],... | javascript | {
"resource": ""
} |
q51039 | findNestedBlocks | train | function findNestedBlocks (ast) {
var tagged = [];
traverse.traverse(ast, {
enter: function (node, parent) {
if (node.type === 'BlockStatement' && parent && parent.type === 'BlockStatement') {
tagged.push([node, parent]);
}
}
});
return tagged;
} | javascript | {
"resource": ""
} |
q51040 | findHoistableFunctionDeclarations | train | function findHoistableFunctionDeclarations (ast) {
var tagged = [];
traverse.traverse(ast, {
enter: function (node, parent) {
if (node.type === 'FunctionDeclaration' && ~node.id.name.indexOf('$')) {
tagged.push([node, parent]);
}
}
});
return tagged;
} | javascript | {
"resource": ""
} |
q51041 | combineContiguousOutputStatements | train | function combineContiguousOutputStatements (ast) {
traverse.traverse(ast, {
enter: function (node, parent) {
if (node.type !== 'BlockStatement') {
return;
}
var prev = false;
node.body = fast.reduce(node.body, function (body, statement) {
if (
!body.length ||
... | javascript | {
"resource": ""
} |
q51042 | removeUnusedAssignmentExpressions | train | function removeUnusedAssignmentExpressions (ast) {
var unused = findUnusedAssignmentExpressions(ast);
traverse.traverse(ast, {
enter: function (node, parent) {
if (node.type !== 'BlockStatement') {
return;
}
node.body = fast.filter(node.body, function (item) {
return !~fast.ind... | javascript | {
"resource": ""
} |
q51043 | removeUnusedVariableDeclarators | train | function removeUnusedVariableDeclarators (ast) {
var unused = findUnusedVariableDeclarators(ast);
traverse.traverse(ast, {
enter: function (node, parent) {
if (node.type !== 'VariableDeclaration') {
return;
}
node.declarations = fast.filter(node.declarations, function (item) {
... | javascript | {
"resource": ""
} |
q51044 | findUnusedVariableDeclarators | train | function findUnusedVariableDeclarators (ast) {
var unused = [];
traverse.traverse(ast, {
enter: function (node, parent) {
var scope, refs;
if (node.type === 'VariableDeclarator' && (scope = findScope(ast, node))) {
refs = fast.filter(findVariableReferences(scope, node.id), function (item) {
... | javascript | {
"resource": ""
} |
q51045 | findVariableReferences | train | function findVariableReferences (ast, identifier, skip) {
var references = [];
traverse.traverse(ast, {
enter: function (node, parent) {
if (node === skip) {
this.skip();
}
else if (
node.type === 'Identifier' &&
node.name === identifier.name &&
(parent.ty... | javascript | {
"resource": ""
} |
q51046 | findScope | train | function findScope (ast, item) {
var scopes = [],
found = false;
traverse.traverse(ast, {
enter: function (node, parent) {
if (node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression') {
scopes.push(node);
}
else if (node === item) {
found = scopes[scopes... | javascript | {
"resource": ""
} |
q51047 | getBumpType | train | function getBumpType(){
if (args.patch && args.minor || args.minor && args.major || args.major && args.patch) {
throw '\nYou can not use more than one version bump type at a time\n';
}
if (args.patch){
return 'patch';
} else if (args.minor){
return 'minor';
} else if (args.major) {
return 'major';
} else... | javascript | {
"resource": ""
} |
q51048 | bumpVersion | train | function bumpVersion(importance){
return function bump_version (done){
if (!importance) throw new Error(`
An importance must be specified for a version bump to occur.
Valid importances: "--patch", "--minor", "--major"
`);
// get all the files to bump version in
return gulp.src('./package.json')
// bump th... | javascript | {
"resource": ""
} |
q51049 | tag_version | train | function tag_version(){
return new Promise((resolve, reject)=>{
const pkg = reload('../../package.json');
const tag = `v${pkg.version}`;
gutil.log('Tagging as: '+gutil.colors.cyan(tag));
git.tag(tag, `Tagging as ${tag}`, (err)=>{
checkError(err);
resolve(tag);
})
})
} | javascript | {
"resource": ""
} |
q51050 | release | train | function release(importance) {
const version_bump = done => importance !== false ? gulp.series(bumpVersion(importance))(done) : done();
return done => gulp.series(
() => check_out('develop'),
version_bump,
finish_release
)(done);
} | javascript | {
"resource": ""
} |
q51051 | validateMetaType | train | function validateMetaType(name, metaType) {
assert(_.isObject(metaType), ERR_METATYPE_OBJECT, { name: name });
assert(metaType.name, ERR_REQUIRE_FIELD, { metaType: metaType, field: "name" });
assert(metaType.kind === "enum" || metaType.kind === "class", ERR_METATYPE_KIND, { metaType: metaType })... | javascript | {
"resource": ""
} |
q51052 | register | train | function register(metamodel) {
var name, metaType;
// Registering MetaTypes to global.meta
for (name in metamodel) {
if (metamodel.hasOwnProperty(name)) {
metaType = metamodel[name];
metaType.name = name;
// Check duplicated MetaType
... | javascript | {
"resource": ""
} |
q51053 | getMetaAttributes | train | function getMetaAttributes(typeName) {
var metaClass = _global.meta[typeName],
attrs = [];
if (metaClass.super) {
attrs = getMetaAttributes(metaClass.super);
}
if (metaClass.attributes) {
var i, len, item;
for (i = 0, len = metaClass.at... | javascript | {
"resource": ""
} |
q51054 | getViewTypeOf | train | function getViewTypeOf(typeName) {
var metaClass = _global.meta[typeName];
if (metaClass) {
return metaClass.view || null;
}
return null;
} | javascript | {
"resource": ""
} |
q51055 | getAvailableViewTypes | train | function getAvailableViewTypes(diagramTypeName) {
var metaClass = _global.meta[diagramTypeName],
views = [];
if (metaClass.super) {
views = getAvailableViewTypes(metaClass.super);
}
if (metaClass.views) {
var i, len, item;
for (i = 0, l... | javascript | {
"resource": ""
} |
q51056 | callAPI | train | function callAPI(session, path, data, subdomain = 'api', isJson = true, headers = null) {
const authorization = 'Bearer ' + session.token;
const reqOptions = {
url: `https://${subdomain}.dropboxapi.com/2${path}`,
method: 'POST',
headers: {
'Authorization': authorization,
'User-Agent': 'Unifile'
},
js... | javascript | {
"resource": ""
} |
q51057 | safeStringify | train | function safeStringify(v) {
return JSON.stringify(v).replace(charsToEncode,
function(c) {
return '\\u' + ('000' + c.charCodeAt(0).toString(16)).slice(-4);
}
);
} | javascript | {
"resource": ""
} |
q51058 | exportToHTML | train | function exportToHTML(targetDir, exportDiagram) {
fs.ensureDirSync(targetDir);
fs.ensureDirSync(targetDir + "/contents");
fs.ensureDirSync(targetDir + "/diagrams");
fs.copySync(__dirname + "/../resources/html/assets", targetDir + "/assets");
// Generate html documents
try {
var root = md... | javascript | {
"resource": ""
} |
q51059 | addRules | train | function addRules(rules) {
_.each(rules, function (rule) {
_global.rules[rule.id] = rule;
});
} | javascript | {
"resource": ""
} |
q51060 | getImageData | train | function getImageData(diagram, type) {
// Make a new canvas element for making image data
var canvasElement = new Canvas(500, 500, type),
canvas = new mdjson.Graphics.Canvas(canvasElement.getContext("2d")),
boundingBox = diagram.getBoundingBox(canvas),
rectExpand = 10;
/... | javascript | {
"resource": ""
} |
q51061 | ScrapeError | train | function ScrapeError(msg, response, bodyString) {
Error.call(this, msg);
this.response = response;
this.bodyString = bodyString;
} | javascript | {
"resource": ""
} |
q51062 | scrape | train | function scrape(url, model, options, cb) {
/**
* Make `options` argument optional
*/
if ('function' === typeof options) {
/**
* Interchange `cb`'s position and fill `options` with nice defaults
*/
cb = options;
options = _.cloneDeep(DEFAULTS);
} else {
/**
* Merge all op... | javascript | {
"resource": ""
} |
q51063 | parseBody | train | function parseBody(bodyString, model, options, cb) {
var result;
var dom;
/**
* Load the HTML and parse it with cheerio to create a DOM
*/
try {
dom = cheerio.load(bodyString, options.cheerioOptions);
} catch (err) {
err.bodyString = bodyString;
return cb(err);
}
result = getItem(dom... | javascript | {
"resource": ""
} |
q51064 | getItem | train | function getItem(dom, item, defaults) {
var data;
var get;
var trim;
var nodes;
var selector;
/**
* If the `item` itself is a selector, grab it as `selector` and set item to
* a new empty object.
*/
if ('string' === typeof item) {
selector = item;
item = {};
/**
* If not, it sho... | javascript | {
"resource": ""
} |
q51065 | getSuperType | train | function getSuperType(subType) {
if (subType) {
return _global.type[_global.meta[subType.name].super];
} else {
return null;
}
} | javascript | {
"resource": ""
} |
q51066 | getCommonType | train | function getCommonType(elems) {
if (elems && elems.length > 0) {
var commonType = elems[0].getClass();
while (!_.every(elems, function (e) { return (e instanceof commonType); })) {
commonType = getSuperType(commonType);
}
return commonType;
... | javascript | {
"resource": ""
} |
q51067 | findByName | train | function findByName(array, name) {
if (array && array.length > 0) {
for (var i = 0, len = array.length; i < len; i++) {
var elem = array[i];
if (elem.name == name) {
return elem;
}
}
}
return null;
} | javascript | {
"resource": ""
} |
q51068 | _getBase | train | function _getBase(name) {
var operation = {
id: IdGenerator.generateGuid(),
time: getTimestamp(),
name: name,
bypass: false,
ops: []
};
return operation;
} | javascript | {
"resource": ""
} |
q51069 | _getArray | train | function _getArray(elem, field) {
var f = elem._id + "." + field;
if (!_currentArray[f]) {
_currentArray[f] = _.clone(elem[field]);
}
return _currentArray[f];
} | javascript | {
"resource": ""
} |
q51070 | begin | train | function begin(name, bypass) {
_currentOperation = _getBase(name);
if (bypass === true) {
_currentOperation.bypass = true;
}
} | javascript | {
"resource": ""
} |
q51071 | insert | train | function insert(elem) {
try {
$(exports).triggerHandler('insert', [elem]);
} catch (err) {
console.error(err);
}
var writer = new Writer();
elem.save(writer);
_currentOperation.ops.push({op: OP_INSERT, arg: writer.current});
} | javascript | {
"resource": ""
} |
q51072 | remove | train | function remove(elem) {
try {
$(exports).triggerHandler('remove', [elem]);
} catch (err) {
console.error(err);
}
var writer = new Writer();
elem.save(writer);
_currentOperation.ops.push({op: OP_REMOVE, arg: writer.current});
} | javascript | {
"resource": ""
} |
q51073 | fieldAssign | train | function fieldAssign(elem, field, val) {
try {
$(exports).triggerHandler('fieldAssign', [elem, field, val]);
} catch (err) {
console.error(err);
}
var isCustomField = (elem[field] && elem[field].__read);
var oldVal;
if (isCustomField) {
... | javascript | {
"resource": ""
} |
q51074 | fieldInsert | train | function fieldInsert(elem, field, val) {
try {
$(exports).triggerHandler('fieldInsert', [elem, field, val]);
} catch (err) {
console.error(err);
}
var array = _getArray(elem, field);
array.push(val);
_currentOperation.ops.push({
op: OP_... | javascript | {
"resource": ""
} |
q51075 | fieldReorder | train | function fieldReorder(elem, field, val, pos) {
try {
$(exports).triggerHandler('fieldReorder', [elem, field, val, pos]);
} catch (err) {
console.error(err);
}
_currentOperation.ops.push({
op: OP_FIELD_REORDER,
arg: {
_id: el... | javascript | {
"resource": ""
} |
q51076 | fieldRelocate | train | function fieldRelocate(elem, field, oldParent, newParent) {
try {
$(exports).triggerHandler('fieldRelocate', [elem, field, oldParent, newParent]);
} catch (err) {
console.error(err);
}
_currentOperation.ops.push({
op: OP_FIELD_RELOCATE,
arg... | javascript | {
"resource": ""
} |
q51077 | paginate | train | function paginate(reqOptions, link, memo) {
const links = link.split(/,\s*/);
let matches;
links.some(function(link) {
matches = link.trim().match(/<(.+)>;\s*rel="next"/);
return matches !== null;
});
// End of pagination
if(!matches) {
return Promise.resolve(memo);
}
return new Promise(function(resolve, ... | javascript | {
"resource": ""
} |
q51078 | move | train | function move(src, dest, treeRes) {
return treeRes.tree.map(function(file) {
const regex = new RegExp('^' + src + '$|^' + src + '(/)');
// Overrides file path
return Object.assign({}, file, {path: file.path.replace(regex, dest + '$1')});
});
} | javascript | {
"resource": ""
} |
q51079 | validate | train | function validate(schema) {
var key, item;
for (key in schema) {
if (schema.hasOwnProperty(key)) {
item = schema[key];
if (!item.text) {
console.error("[PreferenceManager] missing required field: 'text' of '" + key + "'");
}... | javascript | {
"resource": ""
} |
q51080 | register | train | function register(id, name, schema) {
if (!id || !name || !schema) {
console.error("register(): missing required parameters: id, name, or schema");
return;
}
if (validate(schema)) {
_schemaMap[id] = {
id: id,
name: name,
... | javascript | {
"resource": ""
} |
q51081 | get | train | function get(key, defaultValue) {
defaultValue = typeof defaultValue === "undefined" ? null : defaultValue;
if (global.localStorage) {
var _value = global.localStorage.getItem(key),
value = null;
if (_value) {
try {
value = JSON... | javascript | {
"resource": ""
} |
q51082 | set | train | function set(key, value) {
if (global.localStorage) {
var _value;
try {
_value = JSON.stringify(value);
global.localStorage.setItem(key, _value);
$(exports).triggerHandler("change", [key, value]);
} catch (e) {
c... | javascript | {
"resource": ""
} |
q51083 | render | train | function render(templatePath, outputPath, element, options) {
var template = fs.readFileSync(templatePath, 'utf8'),
rendered = "",
renderedOutput = "";
element = element || null;
options = options || {};
_.extend(options, {
mdjson : mdjson,
filename : templatePath, ... | javascript | {
"resource": ""
} |
q51084 | renderBulk | train | function renderBulk(templatePath, outputPath, elements, options, fn) {
var template = fs.readFileSync(templatePath, 'utf8'),
rendered = "",
renderedOutput = "";
elements = elements || [];
options = options || {};
// if elements parameter is selector expression, retrieve them from Repo... | javascript | {
"resource": ""
} |
q51085 | train | function () {
var tagArray = [];
if (this.tags && this.tags.length > 0) {
var i, len, tag;
for (i = 0, len = this.tags.length; i < len; i++) {
tag = this.tags[i];
switch (tag.kind) {
case Core.TK_STRING:
... | javascript | {
"resource": ""
} | |
q51086 | registerFont | train | function registerFont(folder) {
var data = fs.readFileSync(folder + "/font.json", {encoding: "utf8"});
var fontArray = JSON.parse(data);
for (var i = 0, len = fontArray.length; i < len; i++) {
var font = fontArray[i];
font.path = folder;
mdjson.Font.registerFont(font);
}
} | javascript | {
"resource": ""
} |
q51087 | exportToPDF | train | function exportToPDF(diagrams, fullPath, options) {
var doc = new PDFDocument(options);
_.each(mdjson.Font.files, function (path, name) {
doc.registerFont(name, path);
});
doc.pipe(fs.createWriteStream(fullPath));
var canvas = new mdjson.PDFGraphics.Canvas(doc);
var i, len;
for (i = ... | javascript | {
"resource": ""
} |
q51088 | writeObject | train | function writeObject(elem) {
var writer = new Core.Writer();
elem.save(writer);
var data = JSON.stringify(writer.current, null, "\t");
return data;
} | javascript | {
"resource": ""
} |
q51089 | extractChanged | train | function extractChanged(operation) {
var i, len, op, elem, changed = [];
if (operation.ops.length > 0) {
for (i = 0, len = operation.ops.length; i < len; i++) {
op = operation.ops[i];
if (op._elem && op._elem._id) {
elem = get(op._elem._id)... | javascript | {
"resource": ""
} |
q51090 | doOperation | train | function doOperation(operation) {
if (operation.ops.length > 0) {
try {
$(exports).triggerHandler('beforeExecuteOperation', [operation]);
_applyOperation(operation);
if (operation.bypass !== true) {
_undoStack.push(operation);
... | javascript | {
"resource": ""
} |
q51091 | select | train | function select(selector) {
selector = selector || "";
// Parse selector into an array of terms
var interm = selector
.replace(/::/g, "\n::\n")
.replace(/@/g, "\n@")
.replace(/\./g, "\n.")
.replace(/\[/g, "\n[");
var i, len,
s... | javascript | {
"resource": ""
} |
q51092 | find | train | function find(predicate) {
var key, elem;
for (key in _idMap) {
if (_idMap.hasOwnProperty(key)) {
elem = _idMap[key];
if (predicate(elem)) {
return elem;
}
}
}
return null;
} | javascript | {
"resource": ""
} |
q51093 | findAll | train | function findAll(predicate) {
var key,
elem,
result = [];
for (key in _idMap) {
if (_idMap.hasOwnProperty(key)) {
elem = _idMap[key];
if (predicate(elem)) {
result.push(elem);
}
}
... | javascript | {
"resource": ""
} |
q51094 | search | train | function search(keyword, typeFilter) {
keyword = keyword.toLowerCase();
typeFilter = typeFilter || type.Element;
var results = findAll(function (elem) {
var name = elem.name ? elem.name.toLowerCase() : "";
return (name.indexOf(keyword) > -1 && elem instanceof typeFilter);... | javascript | {
"resource": ""
} |
q51095 | getRefsTo | train | function getRefsTo(elem, iterator) {
var id,
ref,
obj,
list = [];
if (elem) {
obj = _refMap[elem._id];
if (obj) {
for (id in obj) {
if (obj.hasOwnProperty(id)) {
ref = _idMap[id];
... | javascript | {
"resource": ""
} |
q51096 | getRelationshipsOf | train | function getRelationshipsOf(model, iterator) {
var i,
len,
ref,
refs = getRefsTo(model),
results = [];
function _add(rel) {
if (!_.contains(results, rel)) {
results.push(rel);
}
}
for (i = 0, len = ... | javascript | {
"resource": ""
} |
q51097 | getViewsOf | train | function getViewsOf(model) {
return getRefsTo(model, function (ref) {
return (ref instanceof Core.View) && (ref.model === model);
});
} | javascript | {
"resource": ""
} |
q51098 | getEdgeViewsOf | train | function getEdgeViewsOf(view) {
return getRefsTo(view, function (ref) {
return (ref instanceof Core.EdgeView) &&
(ref.head === view || ref.tail === view);
});
} | javascript | {
"resource": ""
} |
q51099 | getClient | train | function getClient(credentials) {
return new Promise((resolve, reject) => {
const ftp = new Ftp(credentials);
ftp.once('connect', () => {
resolve(ftp);
});
});
} | javascript | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.