_id
stringlengths 2
6
| title
stringlengths 0
58
| partition
stringclasses 3
values | text
stringlengths 52
373k
| language
stringclasses 1
value | meta_information
dict |
|---|---|---|---|---|---|
q59900
|
validation
|
function(start, len) {
if (_.isUndefined(start) || start === null)
return null;
if (start instanceof Range)
return start;
if (_.isObject(start) && 'start' in start && 'end' in start) {
len = start.end - start.start;
start = start.start;
}
return new Range(start, len);
}
|
javascript
|
{
"resource": ""
}
|
|
q59901
|
validation
|
function(fn, options) {
this._list.push(_.extend({order: 0}, options || {}, {fn: fn}));
}
|
javascript
|
{
"resource": ""
}
|
|
q59902
|
validation
|
function(fn) {
this._list = _.without(this._list, _.find(this._list, function(item) {
return item.fn === fn;
}));
}
|
javascript
|
{
"resource": ""
}
|
|
q59903
|
validation
|
function(name) {
if (!name)
return null;
if (!(name in cache)) {
cache[name] = require('utils').deepMerge({}, systemSettings[name], userSettings[name]);
}
var data = cache[name], subsections = _.rest(arguments), key;
while (data && (key = subsections.shift())) {
if (key in data) {
data = data[key];
} else {
return null;
}
}
return data;
}
|
javascript
|
{
"resource": ""
}
|
|
q59904
|
validation
|
function(syntax, name, memo) {
if (!syntax || !name)
return null;
memo = memo || [];
var names = [name];
// create automatic aliases to properties with colons,
// e.g. pos-a == pos:a
if (~name.indexOf('-'))
names.push(name.replace(/\-/g, ':'));
var data = this.getSection(syntax), matchedItem = null;
_.find(['snippets', 'abbreviations'], function(sectionName) {
var data = this.getSection(syntax, sectionName);
if (data) {
return _.find(names, function(n) {
if (data[n])
return matchedItem = parseItem(n, data[n], sectionName);
});
}
}, this);
memo.push(syntax);
if (!matchedItem && data['extends'] && !_.include(memo, data['extends'])) {
// try to find item in parent syntax section
return this.findSnippet(data['extends'], name, memo);
}
return matchedItem;
}
|
javascript
|
{
"resource": ""
}
|
|
q59905
|
validation
|
function(syntax, name, minScore) {
minScore = minScore || 0.3;
var payload = this.getAllSnippets(syntax);
var sc = require('string-score');
name = normalizeName(name);
var scores = _.map(payload, function(value, key) {
return {
key: key,
score: sc.score(value.nk, name, 0.1)
};
});
var result = _.last(_.sortBy(scores, 'score'));
if (result && result.score >= minScore) {
var k = result.key;
return payload[k].parsedValue;
// return parseItem(k, payload[k].value, payload[k].type);
}
}
|
javascript
|
{
"resource": ""
}
|
|
q59906
|
validation
|
function(title, menu) {
var item = null;
_.find(menu || this.getMenu(), function(val) {
if (val.type == 'action') {
if (val.label == title || val.name == title) {
return item = val.name;
}
} else {
return item = this.getActionNameForMenuTitle(title, val.items);
}
}, this);
return item || null;
}
|
javascript
|
{
"resource": ""
}
|
|
q59907
|
validation
|
function(name, syntax) {
if (!name && syntax) {
// search in user resources first
var profile = require('resources').findItem(syntax, 'profile');
if (profile) {
name = profile;
}
}
if (!name) {
return profiles.plain;
}
if (name instanceof OutputProfile) {
return name;
}
if (_.isString(name) && name.toLowerCase() in profiles) {
return profiles[name.toLowerCase()];
}
return this.create(name);
}
|
javascript
|
{
"resource": ""
}
|
|
q59908
|
validation
|
function(editor) {
var allowedSyntaxes = {'html': 1, 'xml': 1, 'xsl': 1};
var syntax = String(editor.getSyntax());
if (syntax in allowedSyntaxes) {
var content = String(editor.getContent());
var tag = require('htmlMatcher').find(content, editor.getCaretPos());
if (tag && tag.type == 'tag') {
var startTag = tag.open;
var contextNode = {
name: startTag.name,
attributes: []
};
// parse attributes
var tagTree = require('xmlEditTree').parse(startTag.range.substring(content));
if (tagTree) {
contextNode.attributes = _.map(tagTree.getAll(), function(item) {
return {
name: item.name(),
value: item.value()
};
});
}
return contextNode;
}
}
return null;
}
|
javascript
|
{
"resource": ""
}
|
|
q59909
|
validation
|
function(editor) {
var syntax = editor.getSyntax();
// get profile from syntax definition
var profile = require('resources').findItem(syntax, 'profile');
if (profile) {
return profile;
}
switch(syntax) {
case 'xml':
case 'xsl':
return 'xml';
case 'css':
if (this.isInlineCSS(editor)) {
return 'line';
}
break;
case 'html':
var profile = require('resources').getVariable('profile');
if (!profile) { // no forced profile, guess from content
// html or xhtml?
profile = this.isXHTML(editor) ? 'xhtml': 'html';
}
return profile;
}
return 'xhtml';
}
|
javascript
|
{
"resource": ""
}
|
|
q59910
|
validation
|
function(editor) {
var content = String(editor.getContent());
var caretPos = editor.getCaretPos();
var tag = require('htmlMatcher').tag(content, caretPos);
return tag && tag.open.name.toLowerCase() == 'style'
&& tag.innerRange.cmp(caretPos, 'lte', 'gte');
}
|
javascript
|
{
"resource": ""
}
|
|
q59911
|
validation
|
function(editor) {
var content = String(editor.getContent());
var caretPos = editor.getCaretPos();
var tree = require('xmlEditTree').parseFromPosition(content, caretPos, true);
if (tree) {
var attr = tree.itemFromPosition(caretPos, true);
return attr && attr.name().toLowerCase() == 'style'
&& attr.valueRange(true).cmp(caretPos, 'lte', 'gte');
}
return false;
}
|
javascript
|
{
"resource": ""
}
|
|
q59912
|
validation
|
function(node) {
return (this.hasTagsInContent(node) && this.isBlock(node))
|| _.any(node.children, function(child) {
return this.isBlock(child);
}, this);
}
|
javascript
|
{
"resource": ""
}
|
|
q59913
|
validation
|
function(input) {
var output = [];
var chr1, chr2, chr3, enc1, enc2, enc3, enc4, cdp1, cdp2, cdp3;
var i = 0, il = input.length, b64 = chars;
while (i < il) {
cdp1 = input.charCodeAt(i++);
cdp2 = input.charCodeAt(i++);
cdp3 = input.charCodeAt(i++);
chr1 = cdp1 & 0xff;
chr2 = cdp2 & 0xff;
chr3 = cdp3 & 0xff;
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(cdp2)) {
enc3 = enc4 = 64;
} else if (isNaN(cdp3)) {
enc4 = 64;
}
output.push(b64.charAt(enc1) + b64.charAt(enc2) + b64.charAt(enc3) + b64.charAt(enc4));
}
return output.join('');
}
|
javascript
|
{
"resource": ""
}
|
|
q59914
|
validation
|
function(data) {
var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, tmpArr = [];
var b64 = chars, il = data.length;
if (!data) {
return data;
}
data += '';
do { // unpack four hexets into three octets using index points in b64
h1 = b64.indexOf(data.charAt(i++));
h2 = b64.indexOf(data.charAt(i++));
h3 = b64.indexOf(data.charAt(i++));
h4 = b64.indexOf(data.charAt(i++));
bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;
o1 = bits >> 16 & 0xff;
o2 = bits >> 8 & 0xff;
o3 = bits & 0xff;
if (h3 == 64) {
tmpArr[ac++] = String.fromCharCode(o1);
} else if (h4 == 64) {
tmpArr[ac++] = String.fromCharCode(o1, o2);
} else {
tmpArr[ac++] = String.fromCharCode(o1, o2, o3);
}
} while (i < il);
return tmpArr.join('');
}
|
javascript
|
{
"resource": ""
}
|
|
q59915
|
createMatcher
|
validation
|
function createMatcher(text) {
var memo = {}, m;
return {
/**
* Test if given position matches opening tag
* @param {Number} i
* @returns {Object} Matched tag object
*/
open: function(i) {
var m = this.matches(i);
return m && m.type == 'open' ? m : null;
},
/**
* Test if given position matches closing tag
* @param {Number} i
* @returns {Object} Matched tag object
*/
close: function(i) {
var m = this.matches(i);
return m && m.type == 'close' ? m : null;
},
/**
* Matches either opening or closing tag for given position
* @param i
* @returns
*/
matches: function(i) {
var key = 'p' + i;
if (!(key in memo)) {
if (text.charAt(i) == '<') {
var substr = text.slice(i);
if (m = substr.match(reOpenTag)) {
memo[key] = openTag(i, m);
} else if (m = substr.match(reCloseTag)) {
memo[key] = closeTag(i, m);
} else {
// remember that given position contains no valid tag
memo[key] = false;
}
}
}
return memo[key];
},
/**
* Returns original text
* @returns {String}
*/
text: function() {
return text;
}
};
}
|
javascript
|
{
"resource": ""
}
|
q59916
|
validation
|
function(node, offset) {
var maxNum = 0;
var options = {
tabstop: function(data) {
var group = parseInt(data.group);
if (group > maxNum) maxNum = group;
if (data.placeholder)
return '${' + (group + offset) + ':' + data.placeholder + '}';
else
return '${' + (group + offset) + '}';
}
};
_.each(['start', 'end', 'content'], function(p) {
node[p] = this.processText(node[p], options);
}, this);
return maxNum;
}
|
javascript
|
{
"resource": ""
}
|
|
q59917
|
validation
|
function(name, value, description) {
var prefs = name;
if (_.isString(name)) {
prefs = {};
prefs[name] = {
value: value,
description: description
};
}
_.each(prefs, function(v, k) {
defaults[k] = isValueObj(v) ? v : {value: v};
});
}
|
javascript
|
{
"resource": ""
}
|
|
q59918
|
validation
|
function(name) {
if (name in preferences)
return preferences[name];
if (name in defaults)
return defaults[name].value;
return void 0;
}
|
javascript
|
{
"resource": ""
}
|
|
q59919
|
validation
|
function(name) {
var val = this.get(name);
if (_.isUndefined(val) || val === null || val === '') {
return null;
}
val = _.map(val.split(','), require('utils').trim);
if (!val.length) {
return null;
}
return val;
}
|
javascript
|
{
"resource": ""
}
|
|
q59920
|
validation
|
function(name) {
var result = {};
_.each(this.getArray(name), function(val) {
var parts = val.split(':');
result[parts[0]] = parts[1];
});
return result;
}
|
javascript
|
{
"resource": ""
}
|
|
q59921
|
validation
|
function(tree, filters, profile) {
var utils = require('utils');
profile = require('profile').get(profile);
_.each(list(filters), function(filter) {
var name = utils.trim(filter.toLowerCase());
if (name && name in registeredFilters) {
tree = registeredFilters[name](tree, profile);
}
});
return tree;
}
|
javascript
|
{
"resource": ""
}
|
|
q59922
|
validation
|
function(syntax, profile, additionalFilters) {
profile = require('profile').get(profile);
var filters = list(profile.filters || require('resources').findItem(syntax, 'filters') || basicFilters);
if (profile.extraFilters) {
filters = filters.concat(list(profile.extraFilters));
}
if (additionalFilters) {
filters = filters.concat(list(additionalFilters));
}
if (!filters || !filters.length) {
// looks like unknown syntax, apply basic filters
filters = list(basicFilters);
}
return filters;
}
|
javascript
|
{
"resource": ""
}
|
|
q59923
|
validation
|
function(value, start, end) {
// create modification range
var r = range(start, _.isUndefined(end) ? 0 : end - start);
var delta = value.length - r.length();
var update = function(obj) {
_.each(obj, function(v, k) {
if (v >= r.end)
obj[k] += delta;
});
};
// update affected positions of current container
update(this._positions);
// update affected positions of children
_.each(this.list(), function(item) {
update(item._positions);
});
this.source = require('utils').replaceSubstring(this.source, value, r);
}
|
javascript
|
{
"resource": ""
}
|
|
q59924
|
validation
|
function(name) {
if (_.isNumber(name))
return this.list()[name];
if (_.isString(name))
return _.find(this.list(), function(prop) {
return prop.name() === name;
});
return name;
}
|
javascript
|
{
"resource": ""
}
|
|
q59925
|
validation
|
function(name) {
if (!_.isArray(name))
name = [name];
// split names and indexes
var names = [], indexes = [];
_.each(name, function(item) {
if (_.isString(item))
names.push(item);
else if (_.isNumber(item))
indexes.push(item);
});
return _.filter(this.list(), function(attribute, i) {
return _.include(indexes, i) || _.include(names, attribute.name());
});
}
|
javascript
|
{
"resource": ""
}
|
|
q59926
|
validation
|
function(name, value, pos) {
var element = this.get(name);
if (element)
return element.value(value);
if (!_.isUndefined(value)) {
// no such element — create it
return this.add(name, value, pos);
}
}
|
javascript
|
{
"resource": ""
}
|
|
q59927
|
validation
|
function(name) {
var element = this.get(name);
if (element) {
this._updateSource('', element.fullRange());
this._children = _.without(this._children, element);
}
}
|
javascript
|
{
"resource": ""
}
|
|
q59928
|
validation
|
function(val) {
if (!_.isUndefined(val) && this._name !== (val = String(val))) {
this._updateSource(val, this._positions.name, this._positions.name + this._name.length);
this._name = val;
}
return this._name;
}
|
javascript
|
{
"resource": ""
}
|
|
q59929
|
validation
|
function(pos, isAbsolute) {
return _.find(this.list(), function(elem) {
return elem.range(isAbsolute).inside(pos);
});
}
|
javascript
|
{
"resource": ""
}
|
|
q59930
|
validation
|
function(val) {
if (!_.isUndefined(val) && this._value !== (val = String(val))) {
this.parent._updateSource(val, this.valueRange());
this._value = val;
}
return this._value;
}
|
javascript
|
{
"resource": ""
}
|
|
q59931
|
validation
|
function(val) {
if (!_.isUndefined(val) && this._name !== (val = String(val))) {
this.parent._updateSource(val, this.nameRange());
this._name = val;
}
return this._name;
}
|
javascript
|
{
"resource": ""
}
|
|
q59932
|
trimWhitespaceTokens
|
validation
|
function trimWhitespaceTokens(tokens, mask) {
mask = mask || (WHITESPACE_REMOVE_FROM_START | WHITESPACE_REMOVE_FROM_END);
var whitespace = ['white', 'line'];
if ((mask & WHITESPACE_REMOVE_FROM_END) == WHITESPACE_REMOVE_FROM_END)
while (tokens.length && _.include(whitespace, _.last(tokens).type)) {
tokens.pop();
}
if ((mask & WHITESPACE_REMOVE_FROM_START) == WHITESPACE_REMOVE_FROM_START)
while (tokens.length && _.include(whitespace, tokens[0].type)) {
tokens.shift();
}
return tokens;
}
|
javascript
|
{
"resource": ""
}
|
q59933
|
findValueRange
|
validation
|
function findValueRange(it) {
// find value start position
var skipTokens = ['white', 'line', ':'];
var tokens = [], token, start, end;
it.nextUntil(function(tok) {
return !_.include(skipTokens, this.itemNext().type);
});
start = it.current().end;
// consume value
while (token = it.next()) {
if (token.type == '}' || token.type == ';') {
// found value end
trimWhitespaceTokens(tokens, WHITESPACE_REMOVE_FROM_START
| (token.type == '}' ? WHITESPACE_REMOVE_FROM_END : 0));
if (tokens.length) {
start = tokens[0].start;
end = _.last(tokens).end;
} else {
end = start;
}
return range(start, end - start);
}
tokens.push(token);
}
// reached the end of tokens list
if (tokens.length) {
return range(tokens[0].start, _.last(tokens).end - tokens[0].start);
}
}
|
javascript
|
{
"resource": ""
}
|
q59934
|
findParts
|
validation
|
function findParts(str) {
/** @type StringStream */
var stream = require('stringStream').create(str);
var ch;
var result = [];
var sep = /[\s\u00a0,]/;
var add = function() {
stream.next();
result.push(range(stream.start, stream.current()));
stream.start = stream.pos;
};
// skip whitespace
stream.eatSpace();
stream.start = stream.pos;
while (ch = stream.next()) {
if (ch == '"' || ch == "'") {
stream.next();
if (!stream.skipTo(ch)) break;
add();
} else if (ch == '(') {
// function found, may have nested function
stream.backUp(1);
if (!stream.skipToPair('(', ')')) break;
stream.backUp(1);
add();
} else {
if (sep.test(ch)) {
result.push(range(stream.start, stream.current().length - 1));
stream.eatWhile(sep);
stream.start = stream.pos;
}
}
}
add();
return _.chain(result)
.filter(function(item) {
return !!item.length();
})
.uniq(false, function(item) {
return item.toString();
})
.value();
}
|
javascript
|
{
"resource": ""
}
|
q59935
|
validation
|
function(isAbsolute) {
var parts = findParts(this.value());
if (isAbsolute) {
var offset = this.valuePosition(true);
_.each(parts, function(p) {
p.shift(offset);
});
}
return parts;
}
|
javascript
|
{
"resource": ""
}
|
|
q59936
|
validation
|
function(content, pos, isBackward) {
var result = '';
var len = content.length;
var offset = pos;
var stopChars = '{}/\\<>\n\r';
var bracePos = -1, ch;
// search left until we find rule edge
while (offset >= 0) {
ch = content.charAt(offset);
if (ch == '{') {
bracePos = offset;
break;
}
else if (ch == '}' && !isBackward) {
offset++;
break;
}
offset--;
}
// search right for full rule set
while (offset < len) {
ch = content.charAt(offset);
if (ch == '{') {
bracePos = offset;
} else if (ch == '}') {
if (bracePos != -1)
result = content.substring(bracePos, offset + 1);
break;
}
offset++;
}
if (result) {
// find CSS selector
offset = bracePos - 1;
var selector = '';
while (offset >= 0) {
ch = content.charAt(offset);
if (stopChars.indexOf(ch) != -1) break;
offset--;
}
// also trim whitespace
selector = content.substring(offset + 1, bracePos).replace(/^[\s\n\r]+/m, '');
return require('range').create(bracePos - selector.length, result.length + selector.length);
}
return null;
}
|
javascript
|
{
"resource": ""
}
|
|
q59937
|
validation
|
function(name, value, pos) {
var list = this.list();
var start = this.nameRange().end;
var editTree = require('editTree');
var styles = _.pick(this.options, 'styleBefore', 'styleSeparator', 'styleQuote');
if (_.isUndefined(pos))
pos = list.length;
/** @type XMLEditAttribute */
var donor = list[pos];
if (donor) {
start = donor.fullRange().start;
} else if (donor = list[pos - 1]) {
start = donor.range().end;
}
if (donor) {
styles = _.pick(donor, 'styleBefore', 'styleSeparator', 'styleQuote');
}
value = styles.styleQuote + value + styles.styleQuote;
var attribute = new XMLEditElement(this,
editTree.createToken(start + styles.styleBefore.length, name),
editTree.createToken(start + styles.styleBefore.length + name.length
+ styles.styleSeparator.length, value)
);
_.extend(attribute, styles);
// write new attribute into the source
this._updateSource(attribute.styleBefore + attribute.toString(), start);
// insert new attribute
this._children.splice(pos, 0, attribute);
return attribute;
}
|
javascript
|
{
"resource": ""
}
|
|
q59938
|
validation
|
function(editor) {
/** @type Range */
var range = require('range').create(editor.getSelectionRange());
var content = String(editor.getContent());
if (range.length()) {
// abbreviation is selected by user
return range.substring(content);
}
// search for new abbreviation from current caret position
var curLine = editor.getCurrentLineRange();
return require('actionUtils').extractAbbreviation(content.substring(curLine.start, range.start));
}
|
javascript
|
{
"resource": ""
}
|
|
q59939
|
validation
|
function(abbr, text, syntax, profile, contextNode) {
/** @type emmet.filters */
var filters = require('filters');
/** @type emmet.utils */
var utils = require('utils');
syntax = syntax || emmet.defaultSyntax();
profile = require('profile').get(profile, syntax);
require('tabStops').resetTabstopIndex();
var data = filters.extractFromAbbreviation(abbr);
var parsedTree = require('abbreviationParser').parse(data[0], {
syntax: syntax,
pastedContent: text,
contextNode: contextNode
});
if (parsedTree) {
var filtersList = filters.composeList(syntax, profile, data[1]);
filters.apply(parsedTree, filtersList, profile);
return utils.replaceVariables(parsedTree.toString());
}
return null;
}
|
javascript
|
{
"resource": ""
}
|
|
q59940
|
toggleHTMLComment
|
validation
|
function toggleHTMLComment(editor) {
/** @type Range */
var range = require('range').create(editor.getSelectionRange());
var info = require('editorUtils').outputInfo(editor);
if (!range.length()) {
// no selection, find matching tag
var tag = require('htmlMatcher').tag(info.content, editor.getCaretPos());
if (tag) { // found pair
range = tag.outerRange;
}
}
return genericCommentToggle(editor, '<!--', '-->', range);
}
|
javascript
|
{
"resource": ""
}
|
q59941
|
toggleCSSComment
|
validation
|
function toggleCSSComment(editor) {
/** @type Range */
var range = require('range').create(editor.getSelectionRange());
var info = require('editorUtils').outputInfo(editor);
if (!range.length()) {
// no selection, try to get current rule
/** @type CSSRule */
var rule = require('cssEditTree').parseFromPosition(info.content, editor.getCaretPos());
if (rule) {
var property = cssItemFromPosition(rule, editor.getCaretPos());
range = property
? property.range(true)
: require('range').create(rule.nameRange(true).start, rule.source);
}
}
if (!range.length()) {
// still no selection, get current line
range = require('range').create(editor.getCurrentLineRange());
require('utils').narrowToNonSpace(info.content, range);
}
return genericCommentToggle(editor, '/*', '*/', range);
}
|
javascript
|
{
"resource": ""
}
|
q59942
|
genericCommentToggle
|
validation
|
function genericCommentToggle(editor, commentStart, commentEnd, range) {
var editorUtils = require('editorUtils');
var content = editorUtils.outputInfo(editor).content;
var caretPos = editor.getCaretPos();
var newContent = null;
var utils = require('utils');
/**
* Remove comment markers from string
* @param {Sting} str
* @return {String}
*/
function removeComment(str) {
return str
.replace(new RegExp('^' + utils.escapeForRegexp(commentStart) + '\\s*'), function(str){
caretPos -= str.length;
return '';
}).replace(new RegExp('\\s*' + utils.escapeForRegexp(commentEnd) + '$'), '');
}
// first, we need to make sure that this substring is not inside
// comment
var commentRange = searchComment(content, caretPos, commentStart, commentEnd);
if (commentRange && commentRange.overlap(range)) {
// we're inside comment, remove it
range = commentRange;
newContent = removeComment(range.substring(content));
} else {
// should add comment
// make sure that there's no comment inside selection
newContent = commentStart + ' ' +
range.substring(content)
.replace(new RegExp(utils.escapeForRegexp(commentStart) + '\\s*|\\s*' + utils.escapeForRegexp(commentEnd), 'g'), '') +
' ' + commentEnd;
// adjust caret position
caretPos += commentStart.length + 1;
}
// replace editor content
if (newContent !== null) {
newContent = utils.escapeText(newContent);
editor.setCaretPos(range.start);
editor.replaceContent(editorUtils.unindent(editor, newContent), range.start, range.end);
editor.setCaretPos(caretPos);
return true;
}
return false;
}
|
javascript
|
{
"resource": ""
}
|
q59943
|
removeComment
|
validation
|
function removeComment(str) {
return str
.replace(new RegExp('^' + utils.escapeForRegexp(commentStart) + '\\s*'), function(str){
caretPos -= str.length;
return '';
}).replace(new RegExp('\\s*' + utils.escapeForRegexp(commentEnd) + '$'), '');
}
|
javascript
|
{
"resource": ""
}
|
q59944
|
makePossibleRangesHTML
|
validation
|
function makePossibleRangesHTML(source, tokens, offset) {
offset = offset || 0;
var range = require('range');
var result = [];
var attrStart = -1, attrName = '', attrValue = '', attrValueRange, tagName;
_.each(tokens, function(tok) {
switch (tok.type) {
case 'tag':
tagName = source.substring(tok.start, tok.end);
if (/^<[\w\:\-]/.test(tagName)) {
// add tag name
result.push(range.create({
start: tok.start + 1,
end: tok.end
}));
}
break;
case 'attribute':
attrStart = tok.start;
attrName = source.substring(tok.start, tok.end);
break;
case 'string':
// attribute value
// push full attribute first
result.push(range.create(attrStart, tok.end - attrStart));
attrValueRange = range.create(tok);
attrValue = attrValueRange.substring(source);
// is this a quoted attribute?
if (isQuote(attrValue.charAt(0)))
attrValueRange.start++;
if (isQuote(attrValue.charAt(attrValue.length - 1)))
attrValueRange.end--;
result.push(attrValueRange);
if (attrName == 'class') {
result = result.concat(classNameRanges(attrValueRange.substring(source), attrValueRange.start));
}
break;
}
});
// offset ranges
_.each(result, function(r) {
r.shift(offset);
});
return _.chain(result)
.filter(function(item) { // remove empty
return !!item.length();
})
.uniq(false, function(item) { // remove duplicates
return item.toString();
})
.value();
}
|
javascript
|
{
"resource": ""
}
|
q59945
|
classNameRanges
|
validation
|
function classNameRanges(className, offset) {
offset = offset || 0;
var result = [];
/** @type StringStream */
var stream = require('stringStream').create(className);
var range = require('range');
// skip whitespace
stream.eatSpace();
stream.start = stream.pos;
var ch;
while (ch = stream.next()) {
if (/[\s\u00a0]/.test(ch)) {
result.push(range.create(stream.start + offset, stream.pos - stream.start - 1));
stream.eatSpace();
stream.start = stream.pos;
}
}
result.push(range.create(stream.start + offset, stream.pos - stream.start));
return result;
}
|
javascript
|
{
"resource": ""
}
|
q59946
|
makePossibleRangesCSS
|
validation
|
function makePossibleRangesCSS(property) {
// find all possible ranges, sorted by position and size
var valueRange = property.valueRange(true);
var result = [property.range(true), valueRange];
var stringStream = require('stringStream');
var cssEditTree = require('cssEditTree');
var range = require('range');
// locate parts of complex values.
// some examples:
// – 1px solid red: 3 parts
// – arial, sans-serif: enumeration, 2 parts
// – url(image.png): function value part
var value = property.value();
_.each(property.valueParts(), function(r) {
// add absolute range
var clone = r.clone();
result.push(clone.shift(valueRange.start));
/** @type StringStream */
var stream = stringStream.create(r.substring(value));
if (stream.match(/^[\w\-]+\(/, true)) {
// we have a function, find values in it.
// but first add function contents
stream.start = stream.pos;
stream.skipToPair('(', ')');
var fnBody = stream.current();
result.push(range.create(clone.start + stream.start, fnBody));
// find parts
_.each(cssEditTree.findParts(fnBody), function(part) {
result.push(range.create(clone.start + stream.start + part.start, part.substring(fnBody)));
});
}
});
// optimize result: remove empty ranges and duplicates
return _.chain(result)
.filter(function(item) {
return !!item.length();
})
.uniq(false, function(item) {
return item.toString();
})
.value();
}
|
javascript
|
{
"resource": ""
}
|
q59947
|
matchedRangeForCSSProperty
|
validation
|
function matchedRangeForCSSProperty(rule, selRange, isBackward) {
/** @type CSSProperty */
var property = null;
var possibleRanges, curRange = null, ix;
var list = rule.list();
var searchFn, nearestItemFn;
if (isBackward) {
list.reverse();
searchFn = function(p) {
return p.range(true).start <= selRange.start;
};
nearestItemFn = function(r) {
return r.start < selRange.start;
};
} else {
searchFn = function(p) {
return p.range(true).end >= selRange.end;
};
nearestItemFn = function(r) {
return r.end > selRange.start;
};
}
// search for nearest to selection CSS property
while (property = _.find(list, searchFn)) {
possibleRanges = makePossibleRangesCSS(property);
if (isBackward)
possibleRanges.reverse();
// check if any possible range is already selected
curRange = _.find(possibleRanges, function(r) {
return r.equal(selRange);
});
if (!curRange) {
// no selection, select nearest item
var matchedRanges = _.filter(possibleRanges, function(r) {
return r.inside(selRange.end);
});
if (matchedRanges.length > 1) {
curRange = matchedRanges[1];
break;
}
if (curRange = _.find(possibleRanges, nearestItemFn))
break;
} else {
ix = _.indexOf(possibleRanges, curRange);
if (ix != possibleRanges.length - 1) {
curRange = possibleRanges[ix + 1];
break;
}
}
curRange = null;
selRange.start = selRange.end = isBackward
? property.range(true).start - 1
: property.range(true).end + 1;
}
return curRange;
}
|
javascript
|
{
"resource": ""
}
|
q59948
|
matchPair
|
validation
|
function matchPair(editor, direction) {
direction = String((direction || 'out').toLowerCase());
var info = require('editorUtils').outputInfo(editor);
var range = require('range');
/** @type Range */
var sel = range.create(editor.getSelectionRange());
var content = info.content;
// validate previous match
if (lastMatch && !lastMatch.range.equal(sel)) {
lastMatch = null;
}
if (lastMatch && sel.length()) {
if (direction == 'in') {
// user has previously selected tag and wants to move inward
if (lastMatch.type == 'tag' && !lastMatch.close) {
// unary tag was selected, can't move inward
return false;
} else {
if (lastMatch.range.equal(lastMatch.outerRange)) {
lastMatch.range = lastMatch.innerRange;
} else {
var narrowed = require('utils').narrowToNonSpace(content, lastMatch.innerRange);
lastMatch = matcher.find(content, narrowed.start + 1);
if (lastMatch && lastMatch.range.equal(sel) && lastMatch.outerRange.equal(sel)) {
lastMatch.range = lastMatch.innerRange;
}
}
}
} else {
if (
!lastMatch.innerRange.equal(lastMatch.outerRange)
&& lastMatch.range.equal(lastMatch.innerRange)
&& sel.equal(lastMatch.range)) {
lastMatch.range = lastMatch.outerRange;
} else {
lastMatch = matcher.find(content, sel.start);
if (lastMatch && lastMatch.range.equal(sel) && lastMatch.innerRange.equal(sel)) {
lastMatch.range = lastMatch.outerRange;
}
}
}
} else {
lastMatch = matcher.find(content, sel.start);
}
if (lastMatch && !lastMatch.range.equal(sel)) {
editor.createSelection(lastMatch.range.start, lastMatch.range.end);
return true;
}
lastMatch = null;
return false;
}
|
javascript
|
{
"resource": ""
}
|
q59949
|
getReflectedCSSName
|
validation
|
function getReflectedCSSName(name) {
name = require('cssEditTree').baseName(name);
var vendorPrefix = '^(?:\\-\\w+\\-)?', m;
if (name == 'opacity' || name == 'filter') {
return new RegExp(vendorPrefix + '(?:opacity|filter)$');
} else if (m = name.match(/^border-radius-(top|bottom)(left|right)/)) {
// Mozilla-style border radius
return new RegExp(vendorPrefix + '(?:' + name + '|border-' + m[1] + '-' + m[2] + '-radius)$');
} else if (m = name.match(/^border-(top|bottom)-(left|right)-radius/)) {
return new RegExp(vendorPrefix + '(?:' + name + '|border-radius-' + m[1] + m[2] + ')$');
}
return new RegExp(vendorPrefix + name + '$');
}
|
javascript
|
{
"resource": ""
}
|
q59950
|
decodeFromBase64
|
validation
|
function decodeFromBase64(editor, data, pos) {
// ask user to enter path to file
var filePath = String(editor.prompt('Enter path to file (absolute or relative)'));
if (!filePath)
return false;
var file = require('file');
var absPath = file.createPath(editor.getFilePath(), filePath);
if (!absPath) {
throw "Can't save file";
}
file.save(absPath, require('base64').decode( data.replace(/^data\:.+?;.+?,/, '') ));
editor.replaceContent('$0' + filePath, pos, pos + data.length);
return true;
}
|
javascript
|
{
"resource": ""
}
|
q59951
|
updateImageSizeCSS
|
validation
|
function updateImageSizeCSS(editor) {
var offset = editor.getCaretPos();
// find tag from current caret position
var info = require('editorUtils').outputInfo(editor);
var cssRule = require('cssEditTree').parseFromPosition(info.content, offset, true);
if (cssRule) {
// check if there is property with image under caret
var prop = cssRule.itemFromPosition(offset, true), m;
if (prop && (m = /url\((["']?)(.+?)\1\)/i.exec(prop.value() || ''))) {
getImageSizeForSource(editor, m[2], function(size) {
if (size) {
var compoundData = cssRule.range(true);
cssRule.value('width', size.width + 'px');
cssRule.value('height', size.height + 'px', cssRule.indexOf('width') + 1);
require('actionUtils').compoundUpdate(editor, _.extend(compoundData, {
data: cssRule.toString(),
caret: offset
}));
}
});
}
}
}
|
javascript
|
{
"resource": ""
}
|
q59952
|
getImageSizeForSource
|
validation
|
function getImageSizeForSource(editor, src, callback) {
var fileContent;
var au = require('actionUtils');
if (src) {
// check if it is data:url
if (/^data:/.test(src)) {
fileContent = require('base64').decode( src.replace(/^data\:.+?;.+?,/, '') );
return callback(au.getImageSize(fileContent));
}
var file = require('file');
var absPath = file.locateFile(editor.getFilePath(), src);
if (absPath === null) {
throw "Can't find " + src + ' file';
}
file.read(absPath, function(err, content) {
if (err) {
throw 'Unable to read ' + absPath + ': ' + err;
}
content = String(content);
callback(au.getImageSize(content));
});
}
}
|
javascript
|
{
"resource": ""
}
|
q59953
|
isSingleProperty
|
validation
|
function isSingleProperty(snippet) {
var utils = require('utils');
snippet = utils.trim(snippet);
// check if it doesn't contain a comment and a newline
if (~snippet.indexOf('/*') || /[\n\r]/.test(snippet)) {
return false;
}
// check if it's a valid snippet definition
if (!/^[a-z0-9\-]+\s*\:/i.test(snippet)) {
return false;
}
snippet = require('tabStops').processText(snippet, {
replaceCarets: true,
tabstop: function() {
return 'value';
}
});
return snippet.split(':').length == 2;
}
|
javascript
|
{
"resource": ""
}
|
q59954
|
normalizeValue
|
validation
|
function normalizeValue(value) {
if (value.charAt(0) == '-' && !/^\-[\.\d]/.test(value)) {
value = value.replace(/^\-+/, '');
}
if (value.charAt(0) == '#') {
return normalizeHexColor(value);
}
return getKeyword(value);
}
|
javascript
|
{
"resource": ""
}
|
q59955
|
findPrefixes
|
validation
|
function findPrefixes(property, noAutofill) {
var result = [];
_.each(vendorPrefixes, function(obj, prefix) {
if (hasPrefix(property, prefix)) {
result.push(prefix);
}
});
if (!result.length && !noAutofill) {
// add all non-obsolete prefixes
_.each(vendorPrefixes, function(obj, prefix) {
if (!obj.obsolete)
result.push(prefix);
});
}
return result;
}
|
javascript
|
{
"resource": ""
}
|
q59956
|
parseList
|
validation
|
function parseList(list) {
var result = _.map((list || '').split(','), require('utils').trim);
return result.length ? result : null;
}
|
javascript
|
{
"resource": ""
}
|
q59957
|
validation
|
function(abbr, value, syntax) {
syntax = syntax || 'css';
var resources = require('resources');
var autoInsertPrefixes = prefs.get('css.autoInsertVendorPrefixes');
// check if snippet should be transformed to !important
var isImportant;
if (isImportant = /^(.+)\!$/.test(abbr)) {
abbr = RegExp.$1;
}
// check if we have abbreviated resource
var snippet = resources.findSnippet(syntax, abbr);
if (snippet && !autoInsertPrefixes) {
return transformSnippet(snippet, isImportant, syntax);
}
// no abbreviated resource, parse abbreviation
var prefixData = this.extractPrefixes(abbr);
var valuesData = this.extractValues(prefixData.property);
var abbrData = _.extend(prefixData, valuesData);
if (!snippet) {
snippet = resources.findSnippet(syntax, abbrData.property);
} else {
abbrData.values = null;
}
if (!snippet && prefs.get('css.fuzzySearch')) {
// let’s try fuzzy search
snippet = resources.fuzzyFindSnippet(syntax, abbrData.property, parseFloat(prefs.get('css.fuzzySearchMinScore')));
}
if (!snippet) {
snippet = abbrData.property + ':' + defaultValue;
} else if (!_.isString(snippet)) {
snippet = snippet.data;
}
if (!isSingleProperty(snippet)) {
return snippet;
}
var snippetObj = this.splitSnippet(snippet);
var result = [];
if (!value && abbrData.values) {
value = _.map(abbrData.values, function(val) {
return this.normalizeValue(val, snippetObj.name);
}, this).join(' ') + ';';
}
snippetObj.value = value || snippetObj.value;
var prefixes = abbrData.prefixes == 'all' || (!abbrData.prefixes && autoInsertPrefixes)
? findPrefixes(snippetObj.name, autoInsertPrefixes && abbrData.prefixes != 'all')
: abbrData.prefixes;
var names = [], propName;
_.each(prefixes, function(p) {
if (p in vendorPrefixes) {
propName = vendorPrefixes[p].transformName(snippetObj.name);
names.push(propName);
result.push(transformSnippet(propName + ':' + snippetObj.value,
isImportant, syntax));
}
});
// put the original property
result.push(transformSnippet(snippetObj.name + ':' + snippetObj.value, isImportant, syntax));
names.push(snippetObj.name);
if (prefs.get('css.alignVendor')) {
var pads = require('utils').getStringsPads(names);
result = _.map(result, function(prop, i) {
return pads[i] + prop;
});
}
return result;
}
|
javascript
|
{
"resource": ""
}
|
|
q59958
|
validation
|
function(snippet) {
var utils = require('utils');
snippet = utils.trim(snippet);
if (snippet.indexOf(':') == -1) {
return {
name: snippet,
value: defaultValue
};
}
var pair = snippet.split(':');
return {
name: utils.trim(pair.shift()),
// replace ${0} tabstop to produce valid vendor-prefixed values
// where possible
value: utils.trim(pair.join(':')).replace(/^(\$\{0\}|\$0)(\s*;?)$/, '${1}$2')
};
}
|
javascript
|
{
"resource": ""
}
|
|
q59959
|
parseLinearGradient
|
validation
|
function parseLinearGradient(gradient) {
var direction = defaultLinearDirections[0];
// extract tokens
/** @type StringStream */
var stream = require('stringStream').create(require('utils').trim(gradient));
var colorStops = [], ch;
while (ch = stream.next()) {
if (stream.peek() == ',') {
colorStops.push(stream.current());
stream.next();
stream.eatSpace();
stream.start = stream.pos;
} else if (ch == '(') { // color definition, like 'rgb(0,0,0)'
stream.skipTo(')');
}
}
// add last token
colorStops.push(stream.current());
colorStops = _.compact(_.map(colorStops, normalizeSpace));
if (!colorStops.length)
return null;
// let's see if the first color stop is actually a direction
if (reDeg.test(colorStops[0]) || reKeyword.test(colorStops[0])) {
direction = colorStops.shift();
}
return {
type: 'linear',
direction: direction,
colorStops: _.map(colorStops, parseColorStop)
};
}
|
javascript
|
{
"resource": ""
}
|
q59960
|
fillImpliedPositions
|
validation
|
function fillImpliedPositions(colorStops) {
var from = 0;
_.each(colorStops, function(cs, i) {
// make sure that first and last positions are defined
if (!i)
return cs.position = cs.position || 0;
if (i == colorStops.length - 1 && !('position' in cs))
cs.position = 1;
if ('position' in cs) {
var start = colorStops[from].position || 0;
var step = (cs.position - start) / (i - from);
_.each(colorStops.slice(from, i), function(cs2, j) {
cs2.position = start + step * j;
});
from = i;
}
});
}
|
javascript
|
{
"resource": ""
}
|
q59961
|
textualDirection
|
validation
|
function textualDirection(direction) {
var angle = parseFloat(direction);
if(!_.isNaN(angle)) {
switch(angle % 360) {
case 0: return 'left';
case 90: return 'bottom';
case 180: return 'right';
case 240: return 'top';
}
}
return direction;
}
|
javascript
|
{
"resource": ""
}
|
q59962
|
getPropertiesForGradient
|
validation
|
function getPropertiesForGradient(gradient, propertyName) {
var props = [];
var css = require('cssResolver');
if (prefs.get('css.gradient.fallback') && ~propertyName.toLowerCase().indexOf('background')) {
props.push({
name: 'background-color',
value: '${1:' + gradient.colorStops[0].color + '}'
});
}
_.each(prefs.getArray('css.gradient.prefixes'), function(prefix) {
var name = css.prefixed(propertyName, prefix);
if (prefix == 'webkit' && prefs.get('css.gradient.oldWebkit')) {
try {
props.push({
name: name,
value: module.oldWebkitLinearGradient(gradient)
});
} catch(e) {}
}
props.push({
name: name,
value: module.toString(gradient, prefix)
});
});
return props.sort(function(a, b) {
return b.name.length - a.name.length;
});
}
|
javascript
|
{
"resource": ""
}
|
q59963
|
findGradient
|
validation
|
function findGradient(cssProp) {
var value = cssProp.value();
var gradient = null;
var matchedPart = _.find(cssProp.valueParts(), function(part) {
return gradient = module.parse(part.substring(value));
});
if (matchedPart && gradient) {
return {
gradient: gradient,
valueRange: matchedPart
};
}
return null;
}
|
javascript
|
{
"resource": ""
}
|
q59964
|
expandGradientOutsideValue
|
validation
|
function expandGradientOutsideValue(editor, syntax) {
var propertyName = prefs.get('css.gradient.defaultProperty');
if (!propertyName)
return false;
// assuming that gradient definition is written on new line,
// do a simplified parsing
var content = String(editor.getContent());
/** @type Range */
var lineRange = require('range').create(editor.getCurrentLineRange());
// get line content and adjust range with padding
var line = lineRange.substring(content)
.replace(/^\s+/, function(pad) {
lineRange.start += pad.length;
return '';
})
.replace(/\s+$/, function(pad) {
lineRange.end -= pad.length;
return '';
});
var css = require('cssResolver');
var gradient = module.parse(line);
if (gradient) {
var props = getPropertiesForGradient(gradient, propertyName);
props.push({
name: propertyName,
value: module.toString(gradient) + '${2}'
});
var sep = css.getSyntaxPreference('valueSeparator', syntax);
var end = css.getSyntaxPreference('propertyEnd', syntax);
if (require('preferences').get('css.alignVendor')) {
var pads = require('utils').getStringsPads(_.map(props, function(prop) {
return prop.value.substring(0, prop.value.indexOf('('));
}));
_.each(props, function(prop, i) {
prop.value = pads[i] + prop.value;
});
}
props = _.map(props, function(item) {
return item.name + sep + item.value + end;
});
editor.replaceContent(props.join('\n'), lineRange.start, lineRange.end);
return true;
}
return false;
}
|
javascript
|
{
"resource": ""
}
|
q59965
|
findGradientFromPosition
|
validation
|
function findGradientFromPosition(content, pos) {
var cssProp = null;
/** @type EditContainer */
var cssRule = require('cssEditTree').parseFromPosition(content, pos, true);
if (cssRule) {
cssProp = cssRule.itemFromPosition(pos, true);
if (!cssProp) {
// in case user just started writing CSS property
// and didn't include semicolon–try another approach
cssProp = _.find(cssRule.list(), function(elem) {
return elem.range(true).end == pos;
});
}
}
return {
rule: cssRule,
property: cssProp
};
}
|
javascript
|
{
"resource": ""
}
|
q59966
|
validation
|
function(gradient) {
var result = null;
require('utils').trim(gradient).replace(/^([\w\-]+)\((.+?)\)$/, function(str, type, definition) {
// remove vendor prefix
type = type.toLowerCase().replace(/^\-[a-z]+\-/, '');
if (type == 'linear-gradient' || type == 'lg') {
result = parseLinearGradient(definition);
return '';
}
return str;
});
return result;
}
|
javascript
|
{
"resource": ""
}
|
|
q59967
|
validation
|
function(gradient) {
if (_.isString(gradient))
gradient = this.parse(gradient);
if (!gradient)
return null;
var colorStops = _.map(gradient.colorStops, _.clone);
// normalize color-stops position
_.each(colorStops, function(cs) {
if (!('position' in cs)) // implied position
return;
if (~cs.position.indexOf('.') || cs.unit == '%') {
cs.position = parseFloat(cs.position) / (cs.unit == '%' ? 100 : 1);
} else {
throw "Can't convert color stop '" + (cs.position + (cs.unit || '')) + "'";
}
});
fillImpliedPositions(colorStops);
// transform color-stops into string representation
colorStops = _.map(colorStops, function(cs, i) {
if (!cs.position && !i)
return 'from(' + cs.color + ')';
if (cs.position == 1 && i == colorStops.length - 1)
return 'to(' + cs.color + ')';
return 'color-stop(' + (cs.position.toFixed(2).replace(/\.?0+$/, '')) + ', ' + cs.color + ')';
});
return '-webkit-gradient(linear, '
+ oldWebkitDirection(gradient.direction)
+ ', '
+ colorStops.join(', ')
+ ')';
}
|
javascript
|
{
"resource": ""
}
|
|
q59968
|
validation
|
function(gradient, prefix) {
if (gradient.type == 'linear') {
var fn = (prefix ? '-' + prefix + '-' : '') + 'linear-gradient';
// transform color-stops
var colorStops = _.map(gradient.colorStops, function(cs) {
return cs.color + ('position' in cs
? ' ' + cs.position + (cs.unit || '')
: '');
});
if (gradient.direction
&& (!prefs.get('css.gradient.omitDefaultDirection')
|| !_.include(defaultLinearDirections, gradient.direction))) {
colorStops.unshift(gradient.direction);
}
return fn + '(' + colorStops.join(', ') + ')';
}
}
|
javascript
|
{
"resource": ""
}
|
|
q59969
|
validation
|
function(name, collection) {
if (!elementTypes[collection])
elementTypes[collection] = [];
var col = this.getCollection(collection);
if (!_.include(col, name))
col.push(name);
}
|
javascript
|
{
"resource": ""
}
|
|
q59970
|
validation
|
function(name, collection) {
if (collection in elementTypes) {
elementTypes[collection] = _.without(this.getCollection(collection), name);
}
}
|
javascript
|
{
"resource": ""
}
|
|
q59971
|
processClassName
|
validation
|
function processClassName(name, item) {
name = transformClassName(name, item, 'element');
name = transformClassName(name, item, 'modifier');
// expand class name
// possible values:
// * block__element
// * block__element_modifier
// * block__element_modifier1_modifier2
// * block_modifier
var block = '', element = '', modifier = '';
var separators = getSeparators();
if (~name.indexOf(separators.element)) {
var blockElem = name.split(separators.element);
var elemModifiers = blockElem[1].split(separators.modifier);
block = blockElem[0];
element = elemModifiers.shift();
modifier = elemModifiers.join(separators.modifier);
} else if (~name.indexOf(separators.modifier)) {
var blockModifiers = name.split(separators.modifier);
block = blockModifiers.shift();
modifier = blockModifiers.join(separators.modifier);
}
if (block || element || modifier) {
if (!block) {
block = item.__bem.block;
}
// inherit parent bem element, if exists
// if (item.parent && item.parent.__bem && item.parent.__bem.element)
// element = item.parent.__bem.element + separators.element + element;
// produce multiple classes
var prefix = block;
var result = [];
if (element) {
prefix += separators.element + element;
result.push(prefix);
} else {
result.push(prefix);
}
if (modifier) {
result.push(prefix + separators.modifier + modifier);
}
item.__bem.block = block;
item.__bem.element = element;
item.__bem.modifier = modifier;
return result;
}
// ...otherwise, return processed or original class name
return name;
}
|
javascript
|
{
"resource": ""
}
|
q59972
|
getIndentation
|
validation
|
function getIndentation(node) {
if (_.include(prefs.getArray('format.noIndentTags') || [], node.name())) {
return '';
}
return require('resources').getVariable('indentation');
}
|
javascript
|
{
"resource": ""
}
|
q59973
|
shouldBreakInsideInline
|
validation
|
function shouldBreakInsideInline(node, profile) {
var abbrUtils = require('abbreviationUtils');
var hasBlockElems = _.any(node.children, function(child) {
if (abbrUtils.isSnippet(child))
return false;
return !abbrUtils.isInline(child);
});
if (!hasBlockElems) {
return shouldFormatInline(node, profile);
}
return true;
}
|
javascript
|
{
"resource": ""
}
|
q59974
|
makeAttributesString
|
validation
|
function makeAttributesString(tag, profile) {
var attrs = '';
var otherAttrs = [];
var attrQuote = profile.attributeQuote();
var cursor = profile.cursor();
_.each(tag.attributeList(), function(a) {
var attrName = profile.attributeName(a.name);
switch (attrName.toLowerCase()) {
// use short notation for ID and CLASS attributes
case 'id':
attrs += '#' + (a.value || cursor);
break;
case 'class':
attrs += '.' + transformClassName(a.value || cursor);
break;
// process other attributes
default:
otherAttrs.push(':' +attrName + ' => ' + attrQuote + (a.value || cursor) + attrQuote);
}
});
if (otherAttrs.length)
attrs += '{' + otherAttrs.join(', ') + '}';
return attrs;
}
|
javascript
|
{
"resource": ""
}
|
q59975
|
makeAttributesString
|
validation
|
function makeAttributesString(node, profile) {
var attrQuote = profile.attributeQuote();
var cursor = profile.cursor();
return _.map(node.attributeList(), function(a) {
var attrName = profile.attributeName(a.name);
return ' ' + attrName + '=' + attrQuote + (a.value || cursor) + attrQuote;
}).join('');
}
|
javascript
|
{
"resource": ""
}
|
q59976
|
validation
|
function(lang, data) {
if (_.isString(data)) {
data = {words: _.compact(data.split(' '))};
} else if (_.isArray(data)) {
data = {words: data};
}
langs[lang] = data;
}
|
javascript
|
{
"resource": ""
}
|
|
q59977
|
validation
|
function (err, res) {
if (err) return sender.emit('transmissionError', err, data.channelURI);
sender.emit('transmitted', res, data.channelURI);
}
|
javascript
|
{
"resource": ""
}
|
|
q59978
|
sanitize
|
validation
|
function sanitize(sender, data) {
data = _.defaults({}, {
client_id: sender.client_id, client_secret: sender.client_secret
}, data);
return _.reduce(data, function (acc, value, key) {
if (! _.isUndefined(value)) {
acc[key] = value;
}
return acc;
}, {});
}
|
javascript
|
{
"resource": ""
}
|
q59979
|
getMissingProps
|
validation
|
function getMissingProps(data) {
var containsKey = _.partial(_.contains, _.keys(data));
return _.filter(required, function (req) {
return !containsKey(req);
});
}
|
javascript
|
{
"resource": ""
}
|
q59980
|
sendRequiredErrors
|
validation
|
function sendRequiredErrors(sender, missingProps) {
_.forEach(missingProps, function (prop) {
sender.emit('error', prop + ' is missing');
});
}
|
javascript
|
{
"resource": ""
}
|
q59981
|
Sender
|
validation
|
function Sender(options) {
EventEmitter.call(this);
_.extend(this, _.defaults(options || {}, {
retries: 4
}));
}
|
javascript
|
{
"resource": ""
}
|
q59982
|
appendChild
|
validation
|
function appendChild(parent, childrens) {
if (childrens.length === undefined) childrens = [childrens];
var docFrag = document.createDocumentFragment(); //we used for loop instead of forEach because childrens can be array like object
for (var i = 0, ln = childrens.length; i < ln; i++) {
docFrag.appendChild(childrens[i]);
}
parent.appendChild(docFrag);
}
|
javascript
|
{
"resource": ""
}
|
q59983
|
getLogicalPartitions
|
validation
|
function getLogicalPartitions(disk, index, offset, extendedPartitionOffset, limit) {
return __awaiter(this, void 0, void 0, function* () {
if (extendedPartitionOffset === undefined) {
extendedPartitionOffset = offset;
}
if (limit === undefined) {
limit = Infinity;
}
const result = [];
if (limit <= 0) {
return result;
}
const buf = yield readFromDisk(disk, offset, MBR_SIZE);
for (const p of getPartitionsFromMBRBuf(buf)) {
if (!p.extended) {
result.push(mbrPartitionDict(p, offset, index));
}
else if (limit > 0) {
const logicalPartitions = yield getLogicalPartitions(disk, index + 1, extendedPartitionOffset + p.byteOffset(), extendedPartitionOffset, limit - 1);
result.push(...logicalPartitions);
return result;
}
}
return result;
});
}
|
javascript
|
{
"resource": ""
}
|
q59984
|
processTemplate
|
validation
|
function processTemplate(template, variables) {
for (let variableName of Object.keys(variables)) {
let value = variables[variableName];
template = replaceVariable(template, variableName, value);
}
template = evaluateConditions(template, variables);
return template;
}
|
javascript
|
{
"resource": ""
}
|
q59985
|
replaceVariable
|
validation
|
function replaceVariable(template, name, value) {
let key = `{${name}}`;
let reg = new RegExp(helper.escapeRegExp(key), 'g');
let encodedReg = new RegExp(helper.escapeRegExp(`{${name}|json}`), 'g');
let encodedValue = JSON.stringify(value).replace(/<\/script/gi, '<\\/script');
return template.replace(reg, value).replace(encodedReg, encodedValue);
}
|
javascript
|
{
"resource": ""
}
|
q59986
|
evaluateConditions
|
validation
|
function evaluateConditions(template, variables) {
let source;
do {
source = template;
template = processSimpleConditions(template, variables);
template = processIfElseConditions(template, variables);
} while (source !== template);
return template;
}
|
javascript
|
{
"resource": ""
}
|
q59987
|
processCondition
|
validation
|
function processCondition(template, variables, matcher) {
// eslint-disable-next-line no-constant-condition
while (true) {
let matchedCondition = template.match(matcher);
if (!matchedCondition) {
break;
}
let fragment = matchedCondition[0];
let conditionCode = matchedCondition[1];
let testResult = evaluateCondition(conditionCode, variables);
let replaceWith = testResult
? matchedCondition[2]
: matchedCondition[3] || '';
template = template.replace(fragment, replaceWith);
}
return template;
}
|
javascript
|
{
"resource": ""
}
|
q59988
|
evaluateCondition
|
validation
|
function evaluateCondition(conditionCode, variables) {
let trimmedCondition = conditionCode.trim();
if ($Debug) {
if (!/^!?('[^']*'|"[^"]*")$/.test(trimmedCondition)) {
throw new Error('Invalid expected value: ' + trimmedCondition);
}
}
let negate = trimmedCondition.charAt(0) === '!';
let expectedValue = trimmedCondition.slice(negate ? 2 : 1, -1);
return negate
? expectedValue !== variables.$Env
: expectedValue === variables.$Env;
}
|
javascript
|
{
"resource": ""
}
|
q59989
|
defaultKeyGenerator
|
validation
|
function defaultKeyGenerator(request) {
let protocol = request.protocol;
let host = request.get('Host');
let url = request.originalUrl;
return protocol + ':' + host + url;
}
|
javascript
|
{
"resource": ""
}
|
q59990
|
getOrdersStatistics
|
validation
|
function getOrdersStatistics (metricKeys = ['item_sold_minecraft', 'prepaid_card_redeemed_minecraft']) {
return fetch(`${CORE_API}/orders/statistics`, {
method: 'POST',
body: JSON.stringify({metricKeys}),
headers: {
'user-agent': USER_AGENT,
'content-type': 'application/json',
'accept': 'application/json'
}
})
.then(handleErrors)
.then(res => res.json())
}
|
javascript
|
{
"resource": ""
}
|
q59991
|
signout
|
validation
|
function signout ({username, password}) {
return fetch(`${YGGDRASIL_API}/signout`, {
method: 'POST',
body: JSON.stringify({
username,
password
}),
headers: {
'user-agent': USER_AGENT,
'content-type': 'application/json',
'accept': 'application/json'
}
})
.then(handleErrors)
.then(res => null)
}
|
javascript
|
{
"resource": ""
}
|
q59992
|
lookupProfiles
|
validation
|
function lookupProfiles (names, agent = 'minecraft') {
return fetch(`${CORE_API}/profiles/${agent}`, {
method: 'POST',
body: JSON.stringify(names),
headers: {
'user-agent': USER_AGENT,
'content-type': 'application/json',
'accept': 'application/json'
}
})
.then(handleErrors)
.then(res => res.json())
}
|
javascript
|
{
"resource": ""
}
|
q59993
|
getSession
|
validation
|
function getSession (profileId) {
return fetch(`${SESSION_API}/session/minecraft/profile/${profileId}`, {
headers: {
'user-agent': USER_AGENT,
'accept': 'application/json'
}
})
.then(handleErrors)
.then(res => {
if (res.status === 204) throw new Error('no such profile')
return res.json()
})
.then(({id, name, properties}) => {
const {timestamp, textures} = JSON.parse(Base64.decode(properties[0].value))
const {SKIN, CAPE} = textures
return {
id,
name,
timestamp,
skin: SKIN && SKIN.url,
cape: CAPE && CAPE.url,
isSlim: SKIN && SKIN.metadata && SKIN.metadata.model === 'slim'
}
})
}
|
javascript
|
{
"resource": ""
}
|
q59994
|
uploadSkin
|
validation
|
function uploadSkin ({accessToken}, profileId, file, isSlim = false) {
const form = new FormData()
form.append('model', isSlim ? 'slim' : '')
form.append('file', file)
return fetch(`${CORE_API}/user/profile/${profileId}/skin`, {
method: 'PUT',
body: form,
headers: {
'user-agent': USER_AGENT,
'authorization': `Bearer ${accessToken}`
}
})
.then(handleErrors)
.then(res => null)
}
|
javascript
|
{
"resource": ""
}
|
q59995
|
getUser
|
validation
|
function getUser ({accessToken}) {
return fetch(`${CORE_API}/user`, {
headers: {
'user-agent': USER_AGENT,
'authorization': `Bearer ${accessToken}`,
'accept': 'application/json'
}
})
.then(handleErrors)
.then(res => res.json())
}
|
javascript
|
{
"resource": ""
}
|
q59996
|
invalidate
|
validation
|
function invalidate ({accessToken, clientToken}) {
return fetch(`${YGGDRASIL_API}/invalidate`, {
method: 'POST',
body: JSON.stringify({
accessToken,
clientToken
}),
headers: {
'user-agent': USER_AGENT,
'content-type': 'application/json'
}
})
.then(handleErrors)
.then(res => null)
}
|
javascript
|
{
"resource": ""
}
|
q59997
|
getBlockedServers
|
validation
|
function getBlockedServers () {
return fetch(`${SESSION_API}/blockedservers`, {
headers: {
'user-agent': USER_AGENT
}
})
.then(handleErrors)
.then(res => res.text())
.then(text => text.split('\n').slice(0, -1))
}
|
javascript
|
{
"resource": ""
}
|
q59998
|
status
|
validation
|
function status () {
return fetch(`${STATUS_API}/check`, {
headers: {
'user-agent': USER_AGENT,
'accept': 'application/json'
}
})
.then(handleErrors) // NOTE I wonder how /check can fail
.then(res => res.json())
.then((sites) => sites.reduce((acc, val) => {
const hostname = Object.keys(val)[0]
acc.push({
hostname,
color: val[hostname],
isAvailable: val[hostname] === 'green' || val[hostname] === 'yellow',
hasIssues: val[hostname] === 'yellow' || val[hostname] === 'red'
})
return acc
}, []))
}
|
javascript
|
{
"resource": ""
}
|
q59999
|
getProfileHistory
|
validation
|
function getProfileHistory (profileId) {
// BASE/user/profile/:id/names also seems to provide the same endpoint
return fetch(`${CORE_API}/user/profiles/${profileId}/names`, {
headers: {
'user-agent': USER_AGENT,
'accept': 'application/json'
}
})
.then(handleErrors)
.then(res => {
if (res.status === 204) throw new Error(`no such profile: ${profileId}`)
return res.json()
})
}
|
javascript
|
{
"resource": ""
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.