_id
stringlengths 2
6
| title
stringlengths 0
58
| partition
stringclasses 3
values | text
stringlengths 52
373k
| language
stringclasses 1
value | meta_information
dict |
|---|---|---|---|---|---|
q7900
|
titlecase
|
train
|
function titlecase() {
return function(data, render) {
var text = render(data);
if (text.length === 0) {
return text;
}
return text[0].toUpperCase() + text.substring(1);
};
}
|
javascript
|
{
"resource": ""
}
|
q7901
|
generateHeading
|
train
|
function generateHeading() {
var mixin = {};
// If two char are provided, first one is used as upperline of the text.
_.each(['==', '=', '-', '~', '\''], function(char, idx) {
// Mustach lambda function takes no parameters and return a function
// whose signature is data, render.
// see https://mustache.github.io/mustache.5.html
mixin['h' + (idx + 1)] = function() {
return function(data, render) {
var text = render(data);
var length = _.last(text.split('\n')).length;
if (char.length === 2) {
text = repeatChar(char[1], length) + '\n' + text;
}
return text + '\n' + repeatChar(char[0], length);
};
};
});
return mixin;
}
|
javascript
|
{
"resource": ""
}
|
q7902
|
pre
|
train
|
function pre() {
return function(data, render) {
// remove first line if empty ; it happens because of
// the {{pre}} tag on one line.
logger.debug('empty line:', Boolean(data.match(/^\s+\n/, '')));
data = data.replace(/^\s+\n/, '');
// Find the first non-empty lines tabulation
var m = data.match(/^([ \r\t]+)[^\s]/m);
if (!m) {
return render(data);
}
var prefix = m[1];
// remove the prefix from the beginning of all lines before rendering
data = data.replace(new RegExp('^' + prefix, 'mg'), '');
var output = render(data);
output = output.replace(/\n/mg, '\n' + prefix);
// Depending what kind of content is on the first line, it might
// or might not keep the spacing...
// if the first does not contains the pattern, add it
if (data.substring(0, prefix.length) !== prefix) {
output = prefix + output;
}
return output;
};
}
|
javascript
|
{
"resource": ""
}
|
q7903
|
propsNode
|
train
|
function propsNode (node) {
var props = flatmap(Object.keys(node), function (key) {
if (key == 'type' || key == 'value' || key == 'children') {
return;
}
var value = node[key];
if (key == 'data') {
value = JSON.parse(JSON.stringify(value));
}
return {
type: 'Property',
key: {
type: 'Identifier',
name: key
},
value: literalNode(value)
};
});
return props.length && {
type: 'ObjectExpression',
properties: props
};
}
|
javascript
|
{
"resource": ""
}
|
q7904
|
literalNode
|
train
|
function literalNode (value) {
if (value === undefined) {
return {
type: 'Identifier',
name: 'undefined'
};
}
else if (typeof value == 'function') {
throw Error('Unist property contains a function');
}
else if (value === null || typeof value != 'object') {
return {
type: 'Literal',
value: value
};
}
else if (Array.isArray(value)) {
return {
type: 'ArrayExpression',
elements: value.map(literalNode)
};
}
else {
return {
type: 'ObjectExpression',
properties: Object.keys(value).map(function (key) {
return {
type: 'Property',
key: {
type: 'Identifier',
name: key
},
value: literalNode(value[key])
};
})
};
}
}
|
javascript
|
{
"resource": ""
}
|
q7905
|
train
|
function ( parent, child ) {
parent.then( function ( arg ) {
child.resolve( arg );
}, function ( e ) {
child.reject( e );
});
}
|
javascript
|
{
"resource": ""
}
|
|
q7906
|
train
|
function ( obj, arg, state ) {
if ( obj.state > promise.state.PENDING ) {
return;
}
obj.value = arg;
obj.state = state;
if ( !obj.deferred ) {
promise.delay( function () {
obj.process();
});
obj.deferred = true;
}
return obj;
}
|
javascript
|
{
"resource": ""
}
|
|
q7907
|
view
|
train
|
function view(name, model, cb) {
var basePath = path.join(path.dirname(__filename), '../views');
var render = function(err, files) {
if (err) {
cb(err);
}
cb(null, mustache.render(files[0], model, {
toctreeChildren: files[1],
func: files[2],
member: files[3],
constant: files[3],
typedef: files[5]
}));
};
async.parallel(_.map([
name,
'_toctree-children',
'_function',
'_member',
'_member',
'_typedef'
], function(p) {
return function(cb) {
fs.readFile(path.join(basePath, p + '.mustache'), 'utf-8', cb);
};
}), render);
}
|
javascript
|
{
"resource": ""
}
|
q7908
|
train
|
function ( obj, arg ) {
if ( !array.contains( obj, arg ) ) {
obj.push( arg );
}
return obj;
}
|
javascript
|
{
"resource": ""
}
|
|
q7909
|
train
|
function ( obj, arg ) {
var min = 0,
max = obj.length - 1,
idx, val;
while ( min <= max ) {
idx = Math.floor( ( min + max ) / 2 );
val = obj[idx];
if ( val < arg ) {
min = idx + 1;
}
else if ( val > arg ) {
max = idx - 1;
}
else {
return idx;
}
}
return -1;
}
|
javascript
|
{
"resource": ""
}
|
|
q7910
|
train
|
function ( obj, size ) {
var result = [],
nth = number.round( ( obj.length / size ), "up" ),
start = 0,
i = -1;
while ( ++i < nth ) {
start = i * size;
result.push( array.limit( obj, start, size ) );
}
return result;
}
|
javascript
|
{
"resource": ""
}
|
|
q7911
|
train
|
function ( obj, fn ) {
var result = [];
array.each( obj, function ( i ) {
result.push( fn( i ) );
});
return result;
}
|
javascript
|
{
"resource": ""
}
|
|
q7912
|
train
|
function ( obj, diff ) {
var result = [];
result = obj.filter( function ( i ) {
return !regex.null_undefined.test( i );
});
return !diff ? result : ( result.length < obj.length ? result : null );
}
|
javascript
|
{
"resource": ""
}
|
|
q7913
|
train
|
function ( array1, array2 ) {
var result = [];
array.each( array1, function ( i ) {
if ( !array.contains( array2, i ) ) {
array.add( result, i );
}
});
array.each( array2, function ( i ) {
if ( !array.contains( array1, i ) ) {
array.add( result, i );
}
});
return result;
}
|
javascript
|
{
"resource": ""
}
|
|
q7914
|
train
|
function ( obj, arg, start, offset ) {
var fn = typeof arg === "function",
l = obj.length,
i = !isNaN( start ) ? start : 0,
nth = !isNaN( offset ) ? i + offset : l - 1;
if ( nth > ( l - 1) ) {
nth = l - 1;
}
while ( i <= nth ) {
obj[i] = fn ? arg( obj[i] ) : arg;
i++;
}
return obj;
}
|
javascript
|
{
"resource": ""
}
|
|
q7915
|
train
|
function ( obj ) {
var result = [];
result = obj.reduce( function ( a, b ) {
return a.concat( b );
}, result );
return result;
}
|
javascript
|
{
"resource": ""
}
|
|
q7916
|
train
|
function ( obj ) {
var indexed = [];
utility.iterate( obj, function ( v ) {
indexed.push( v );
});
return indexed;
}
|
javascript
|
{
"resource": ""
}
|
|
q7917
|
train
|
function ( array1, array2 ) {
var a = array1.length > array2.length ? array1 : array2,
b = ( a === array1 ? array2 : array1 );
return a.filter( function ( key ) {
return array.contains( b, key );
});
}
|
javascript
|
{
"resource": ""
}
|
|
q7918
|
train
|
function ( obj, arg ) {
var n = obj.length - 1;
if ( arg >= ( n + 1 ) ) {
return obj;
}
else if ( isNaN( arg ) || arg === 1 ) {
return obj[n];
}
else {
return array.limit( obj, ( n - ( --arg ) ), n );
}
}
|
javascript
|
{
"resource": ""
}
|
|
q7919
|
train
|
function ( obj, start, offset ) {
var result = [],
i = start - 1,
nth = start + offset,
max = obj.length;
if ( max > 0 ) {
while ( ++i < nth && i < max ) {
result.push( obj[i] );
}
}
return result;
}
|
javascript
|
{
"resource": ""
}
|
|
q7920
|
train
|
function ( obj, arg ) {
array.each( arg, function ( i ) {
array.add( obj, i );
});
return obj;
}
|
javascript
|
{
"resource": ""
}
|
|
q7921
|
train
|
function ( obj1, obj2 ) {
var result;
result = obj1.map( function ( i, idx ) {
return [i, obj2[idx]];
});
return result;
}
|
javascript
|
{
"resource": ""
}
|
|
q7922
|
train
|
function ( obj ) {
var values = {},
count = 0,
nth = 0,
mode = [],
result;
// Counting values
array.each( obj, function ( i ) {
if ( !isNaN( values[i] ) ) {
values[i]++;
}
else {
values[i] = 1;
}
});
// Finding the highest occurring count
count = array.max( array.cast( values ) );
// Finding values that match the count
utility.iterate( values, function ( v, k ) {
if ( v === count ) {
mode.push( number.parse( k ) );
}
});
// Determining the result
nth = mode.length;
if ( nth > 0 ) {
result = nth === 1 ? mode[0] : mode;
}
return result;
}
|
javascript
|
{
"resource": ""
}
|
|
q7923
|
train
|
function ( obj, arg ) {
array.remove( obj, 0, obj.length );
array.each( arg, function ( i ) {
obj.push( i );
});
return obj;
}
|
javascript
|
{
"resource": ""
}
|
|
q7924
|
train
|
function ( obj, start, end ) {
if ( isNaN( start ) ) {
start = obj.index( start );
if ( start === -1 ) {
return obj;
}
}
else {
start = start || 0;
}
var length = obj.length,
remaining = obj.slice( ( end || start ) + 1 || length );
obj.length = start < 0 ? ( length + start ) : start;
obj.push.apply( obj, remaining );
return obj;
}
|
javascript
|
{
"resource": ""
}
|
|
q7925
|
train
|
function ( obj, fn ) {
var remove;
if ( typeof fn !== "function" ) {
throw new Error( label.error.invalidArguments );
}
remove = obj.filter( fn );
array.each( remove, function ( i ) {
array.remove( obj, array.index ( obj, i ) );
});
return obj;
}
|
javascript
|
{
"resource": ""
}
|
|
q7926
|
train
|
function ( obj, fn ) {
if ( typeof fn !== "function" ) {
throw new Error( label.error.invalidArguments );
}
var remove = [];
array.each( obj, function ( i ) {
if ( fn( i ) !== false ) {
remove.push( i );
}
else {
return false;
}
});
array.each( remove, function ( i ) {
array.remove( obj, array.index( obj, i) );
});
return obj;
}
|
javascript
|
{
"resource": ""
}
|
|
q7927
|
train
|
function ( obj, arg ) {
arg = arg || 1;
if ( arg < 1 ) {
arg = 1;
}
return array.limit( obj, arg, obj.length );
}
|
javascript
|
{
"resource": ""
}
|
|
q7928
|
train
|
function ( obj, arg ) {
var result = -1;
array.each( obj, function ( i, idx ) {
if ( i === arg ) {
result = idx;
}
});
return result;
}
|
javascript
|
{
"resource": ""
}
|
|
q7929
|
train
|
function ( obj, arg ) {
var nth = obj.length,
result;
if ( arg === 0 ) {
result = obj;
}
else {
if ( arg < 0 ) {
arg += nth;
}
else {
arg--;
}
result = array.limit( obj, arg, nth );
result = result.concat( array.limit( obj, 0, arg ) );
}
return result;
}
|
javascript
|
{
"resource": ""
}
|
|
q7930
|
train
|
function ( start, end, offset ) {
start = start || 0;
end = end || start;
offset = offset || 1;
var result = [],
n = -1,
nth = Math.max( 0, Math.ceil( ( end - start ) / offset ) );
while ( ++n < nth ) {
result[n] = start;
start += offset;
}
return result;
}
|
javascript
|
{
"resource": ""
}
|
|
q7931
|
train
|
function ( obj, divisor ) {
var result = [],
total = obj.length,
nth = Math.ceil( total / divisor ),
low = Math.floor( total / divisor ),
lower = Math.ceil( total / nth ),
lowered = false,
start = 0,
i = -1;
// Finding the fold
if ( number.diff( total, ( divisor * nth ) ) > nth ) {
lower = total - ( low * divisor ) + low - 1;
}
else if ( total % divisor > 0 && lower * nth >= total ) {
lower--;
}
while ( ++i < divisor ) {
if ( i > 0 ) {
start = start + nth;
}
if ( !lowered && lower < divisor && i === lower ) {
--nth;
lowered = true;
}
result.push( array.limit( obj, start, nth ) );
}
return result;
}
|
javascript
|
{
"resource": ""
}
|
|
q7932
|
train
|
function ( a, b ) {
var types = {a: typeof a, b: typeof b},
c, d, result;
if ( types.a === "number" && types.b === "number" ) {
result = a - b;
}
else {
c = a.toString();
d = b.toString();
if ( c < d ) {
result = -1;
}
else if ( c > d ) {
result = 1;
}
else if ( types.a === types.b ) {
result = 0;
}
else if ( types.a === "boolean" ) {
result = -1;
}
else {
result = 1;
}
}
return result;
}
|
javascript
|
{
"resource": ""
}
|
|
q7933
|
train
|
function ( obj ) {
var result = 0;
if ( obj.length > 0 ) {
result = obj.reduce( function ( prev, cur ) {
return prev + cur;
});
}
return result;
}
|
javascript
|
{
"resource": ""
}
|
|
q7934
|
train
|
function ( ar ) {
var obj = {},
i = ar.length;
while ( i-- ) {
obj[i.toString()] = ar[i];
}
return obj;
}
|
javascript
|
{
"resource": ""
}
|
|
q7935
|
train
|
function ( obj ) {
var result = [];
array.each( obj, function ( i ) {
array.add( result, i );
});
return result;
}
|
javascript
|
{
"resource": ""
}
|
|
q7936
|
train
|
function ( obj, args ) {
var result = [];
// Preparing args
if ( !(args instanceof Array) ) {
args = typeof args === "object" ? array.cast( args ) : [args];
}
array.each( args, function ( i, idx ) {
if ( !( i instanceof Array ) ) {
this[idx] = [i];
}
});
// Building result Array
array.each( obj, function ( i, idx ) {
result[idx] = [i];
array.each( args, function ( x ) {
result[idx].push( x[idx] || null );
});
});
return result;
}
|
javascript
|
{
"resource": ""
}
|
|
q7937
|
train
|
function () {
return utility.iterate( cache.items, function ( v, k ) {
if ( cache.expired( k ) ) {
cache.expire( k, true );
}
});
}
|
javascript
|
{
"resource": ""
}
|
|
q7938
|
train
|
function ( uri, silent ) {
silent = ( silent === true );
if ( cache.items[uri] !== undefined ) {
delete cache.items[uri];
if ( !silent ) {
observer.fire( uri, "beforeExpire, expire, afterExpire" );
}
return true;
}
else {
return false;
}
}
|
javascript
|
{
"resource": ""
}
|
|
q7939
|
train
|
function ( uri ) {
var item = cache.items[uri];
return item !== undefined && item.expires !== undefined && item.expires < new Date();
}
|
javascript
|
{
"resource": ""
}
|
|
q7940
|
train
|
function ( uri, property, value ) {
uri = utility.parse( uri ).href;
if ( cache.items[uri] === undefined ) {
cache.items[uri] = {};
cache.items[uri].permission = 0;
}
if ( property === "permission" ) {
cache.items[uri].permission |= value;
}
else if ( property === "!permission" ) {
cache.items[uri].permission &= ~value;
}
else {
cache.items[uri][property] = value;
}
return cache.items[uri];
}
|
javascript
|
{
"resource": ""
}
|
|
q7941
|
train
|
function ( uri, verb ) {
if ( string.isEmpty( uri ) || string.isEmpty( verb ) ) {
throw new Error( label.error.invalidArguments );
}
uri = utility.parse( uri ).href;
verb = verb.toLowerCase();
var result = false,
bit = 0;
if ( !cache.get( uri, false ) ) {
result = undefined;
}
else {
if ( regex.del.test( verb ) ) {
bit = 1;
}
else if ( regex.get_headers.test( verb ) ) {
bit = 4;
}
else if ( regex.put_post.test( verb ) ) {
bit = 2;
}
else if ( regex.patch.test( verb ) ) {
bit = 8;
}
result = Boolean( client.permissions( uri, verb ).bit & bit );
}
return result;
}
|
javascript
|
{
"resource": ""
}
|
|
q7942
|
train
|
function ( args ) {
var result = 0;
array.each( args, function ( verb ) {
verb = verb.toLowerCase();
if ( regex.get_headers.test( verb ) ) {
result |= 4;
}
else if ( regex.put_post.test( verb ) ) {
result |= 2;
}
else if ( regex.patch.test( verb ) ) {
result |= 8;
}
else if ( regex.del.test( verb ) ) {
result |= 1;
}
});
return result;
}
|
javascript
|
{
"resource": ""
}
|
|
q7943
|
train
|
function ( xhr, uri, type ) {
var headers = string.trim( xhr.getAllResponseHeaders() ).split( "\n" ),
items = {},
o = {},
allow = null,
expires = new Date(),
cors = client.cors( uri );
array.each( headers, function ( i ) {
var header, value;
value = i.replace( regex.header_value_replace, "" );
header = i.replace( regex.header_replace, "" );
header = string.unhyphenate( header, true ).replace( /\s+/g, "-" );
items[header] = value;
if ( allow === null ) {
if ( ( !cors && regex.allow.test( header) ) || ( cors && regex.allow_cors.test( header) ) ) {
allow = value;
}
}
});
if ( regex.no.test( items["Cache-Control"] ) ) {
// Do nothing
}
else if ( items["Cache-Control"] !== undefined && regex.number_present.test( items["Cache-Control"] ) ) {
expires = expires.setSeconds( expires.getSeconds() + number.parse( regex.number_present.exec( items["Cache-Control"] )[0], 10 ) );
}
else if ( items.Expires !== undefined ) {
expires = new Date( items.Expires );
}
else {
expires = expires.setSeconds( expires.getSeconds() + $.expires );
}
o.expires = expires;
o.headers = items;
o.permission = client.bit( allow !== null ? string.explode( allow ) : [type] );
if ( type === "get" ) {
cache.set( uri, "expires", o.expires );
cache.set( uri, "headers", o.headers );
cache.set( uri, "permission", o.permission );
}
return o;
}
|
javascript
|
{
"resource": ""
}
|
|
q7944
|
train
|
function ( xhr, type ) {
type = type || "";
var result, obj;
if ( ( regex.json_maybe.test( type ) || string.isEmpty( type ) ) && ( regex.json_wrap.test( xhr.responseText ) && Boolean( obj = json.decode( xhr.responseText, true ) ) ) ) {
result = obj;
}
else if ( regex.xml.test( type ) ) {
if ( type !== "text/xml" ) {
xhr.overrideMimeType( "text/xml" );
}
result = xhr.responseXML;
}
else if ( type === "text/plain" && regex.is_xml.test( xhr.responseText) && xml.valid( xhr.responseText ) ) {
result = xml.decode( xhr.responseText );
}
else {
result = xhr.responseText;
}
return result;
}
|
javascript
|
{
"resource": ""
}
|
|
q7945
|
train
|
function ( uri ) {
var cached = cache.get( uri, false ),
bit = !cached ? 0 : cached.permission,
result = {allows: [], bit: bit, map: {partial: 8, read: 4, write: 2, "delete": 1, unknown: 0}};
if ( bit & 1) {
result.allows.push( "DELETE" );
}
if ( bit & 2) {
result.allows.push( "POST" );
result.allows.push( "PUT" );
}
if ( bit & 4) {
result.allows.push( "GET" );
}
if ( bit & 8) {
result.allows.push( "PATCH" );
}
return result;
}
|
javascript
|
{
"resource": ""
}
|
|
q7946
|
train
|
function ( uri, success, failure, args ) {
var defer = deferred(),
callback = "callback", cbid, s;
if ( external === undefined ) {
if ( global.abaaso === undefined ) {
utility.define( "abaaso.callback", {}, global );
}
external = "abaaso";
}
if ( args instanceof Object && args.callback !== undefined ) {
callback = args.callback;
}
defer.then( function (arg ) {
if ( typeof success === "function") {
success( arg );
}
}, function ( e ) {
if ( typeof failure === "function") {
failure( e );
}
throw e;
});
do {
cbid = utility.genId().slice( 0, 10 );
}
while ( global.abaaso.callback[cbid] !== undefined );
uri = uri.replace( callback + "=?", callback + "=" + external + ".callback." + cbid );
global.abaaso.callback[cbid] = function ( arg ) {
clearTimeout( utility.timer[cbid] );
delete utility.timer[cbid];
delete global.abaaso.callback[cbid];
defer.resolve( arg );
element.destroy( s );
};
s = element.create( "script", {src: uri, type: "text/javascript"}, utility.$( "head" )[0] );
utility.defer( function () {
defer.reject( undefined );
}, 30000, cbid );
return defer;
}
|
javascript
|
{
"resource": ""
}
|
|
q7947
|
train
|
function ( arg, target, pos ) {
return element.create( "script", {type: "application/javascript", src: arg}, target || utility.$( "head" )[0], pos );
}
|
javascript
|
{
"resource": ""
}
|
|
q7948
|
train
|
function ( dest, ms ) {
var defer = deferred(),
start = client.scrollPos(),
t = 0;
ms = ( !isNaN( ms ) ? ms : 250 ) / 100;
utility.repeat( function () {
var pos = math.bezier( start[0], start[1], dest[0], dest[1], ++t / 100 );
window.scrollTo( pos[0], pos[1] );
if ( t === 100 ) {
defer.resolve( true );
return false;
}
}, ms, "scrolling" );
return defer;
}
|
javascript
|
{
"resource": ""
}
|
|
q7949
|
train
|
function ( arg, media ) {
return element.create( "link", {rel: "stylesheet", type: "text/css", href: arg, media: media || "print, screen"}, utility.$( "head" )[0] );
}
|
javascript
|
{
"resource": ""
}
|
|
q7950
|
train
|
function ( name, domain, secure, path, jar ) {
cookie.set( name, "", "-1s", domain, secure, path, jar );
return name;
}
|
javascript
|
{
"resource": ""
}
|
|
q7951
|
train
|
function ( jar ) {
var result = {};
if ( jar === undefined ) {
jar = server ? "" : document.cookie;
}
if ( !string.isEmpty( jar ) ) {
array.each( string.explode( jar, ";" ), function ( i ) {
var item = string.explode( i, "=" );
result[item[0]] = utility.coerce( item[1] );
} );
}
return result;
}
|
javascript
|
{
"resource": ""
}
|
|
q7952
|
train
|
function ( name, value, offset, domain, secure, path, jar ) {
value = ( value || "" ) + ";";
offset = offset || "";
domain = typeof domain === "string" ? ( " Domain=" + domain + ";" ) : "";
secure = ( secure === true ) ? " secure" : "";
path = typeof path === "string" ? ( " Path=" + path + ";" ) : "";
var expire = "",
span = null,
type = null,
types = ["d", "h", "m", "s"],
regex = new RegExp(),
i = types.length,
cookies;
if ( !string.isEmpty( offset ) ) {
while ( i-- ) {
utility.compile( regex, types[i] );
if ( regex.test( offset ) ) {
type = types[i];
span = number.parse( offset, 10 );
break;
}
}
if ( isNaN( span ) ) {
throw new Error( label.error.invalidArguments );
}
expire = new Date();
if ( type === "d" ) {
expire.setDate( expire.getDate() + span );
}
else if ( type === "h" ) {
expire.setHours( expire.getHours() + span );
}
else if ( type === "m" ) {
expire.setMinutes( expire.getMinutes() + span );
}
else if ( type === "s" ) {
expire.setSeconds( expire.getSeconds() + span );
}
}
if ( expire instanceof Date) {
expire = " Expires=" + expire.toUTCString() + ";";
}
if ( !server ) {
document.cookie = ( string.trim( name.toString() ) + "=" + value + expire + domain + path + secure );
}
else {
cookies = jar.getHeader( "Set-Cookie" ) || [];
cookies.push( ( string.trim( name.toString() ) + "=" + value + expire + domain + path + secure ).replace( /;$/, "" ) );
jar.setHeader( "Set-Cookie", cookies );
}
}
|
javascript
|
{
"resource": ""
}
|
|
q7953
|
train
|
function ( obj, recs, args ) {
utility.genId( obj );
// Decorating observer if not present in prototype chain
if ( typeof obj.fire !== "function" ) {
observer.decorate( obj );
}
// Creating store
obj.data = new DataStore( obj );
if ( args instanceof Object ) {
utility.merge( obj.data, args );
}
if ( recs !== null && typeof recs === "object" ) {
obj.data.batch( "set", recs );
}
return obj;
}
|
javascript
|
{
"resource": ""
}
|
|
q7954
|
train
|
function ( obj, key, value ) {
var target, result;
if ( regex.svg.test( obj.namespaceURI ) ) {
if ( value === undefined ) {
result = obj.getAttributeNS( obj.namespaceURI, key );
if ( result === null || string.isEmpty( result ) ) {
result = undefined;
}
else {
result = utility.coerce( result );
}
}
else {
obj.setAttributeNS( obj.namespaceURI, key, value );
}
}
else {
if ( typeof value === "string" ) {
value = string.trim( value );
}
if ( regex.checked_disabled.test( key ) && value === undefined ) {
return utility.coerce( obj[key] );
}
else if ( regex.checked_disabled.test( key ) && value !== undefined ) {
obj[key] = value;
}
else if ( obj.nodeName === "SELECT" && key === "selected" && value === undefined) {
return utility.$( "#" + obj.id + " option[selected=\"selected\"]" )[0] || utility.$( "#" + obj.id + " option" )[0];
}
else if ( obj.nodeName === "SELECT" && key === "selected" && value !== undefined ) {
target = utility.$( "#" + obj.id + " option[selected=\"selected\"]" )[0];
if ( target !== undefined ) {
target.selected = false;
target.removeAttribute( "selected" );
}
target = utility.$( "#" + obj.id + " option[value=\"" + value + "\"]" )[0];
target.selected = true;
target.setAttribute( "selected", "selected" );
}
else if ( value === undefined ) {
result = obj.getAttribute( key );
if ( result === null || string.isEmpty( result ) ) {
result = undefined;
}
else {
result = utility.coerce( result );
}
return result;
}
else {
obj.setAttribute( key, value );
}
}
return obj;
}
|
javascript
|
{
"resource": ""
}
|
|
q7955
|
train
|
function ( obj ) {
if ( typeof obj.reset === "function" ) {
obj.reset();
}
else if ( obj.value !== undefined ) {
element.update( obj, {innerHTML: "", value: ""} );
}
else {
element.update( obj, {innerHTML: ""} );
}
return obj;
}
|
javascript
|
{
"resource": ""
}
|
|
q7956
|
train
|
function ( type, args, target, pos ) {
var svg = false,
frag = false,
obj, uid, result;
// Removing potential HTML template formatting
type = type.replace( /\t|\n|\r/g, "" );
if ( target !== undefined ) {
svg = ( target.namespaceURI !== undefined && regex.svg.test( target.namespaceURI ) );
}
else {
target = document.body;
}
if ( args instanceof Object && args.id !== undefined && utility.$( "#" + args.id ) === undefined ) {
uid = args.id;
delete args.id;
}
else if ( !svg ) {
uid = utility.genId( undefined, true );
}
// String injection, create a frag and apply it
if ( regex.html.test( type ) ) {
frag = true;
obj = element.frag( type );
result = obj.childNodes.length === 1 ? obj.childNodes[0] : array.cast( obj.childNodes );
}
// Original syntax
else {
if ( !svg && !regex.svg.test( type ) ) {
obj = document.createElement( type );
}
else {
obj = document.createElementNS( "http://www.w3.org/2000/svg", type );
}
if ( uid !== undefined ) {
obj.id = uid;
}
if ( args instanceof Object ) {
element.update( obj, args );
}
}
if ( pos === undefined || pos === "last" ) {
target.appendChild( obj );
}
else if ( pos === "first" ) {
element.prependChild( target, obj );
}
else if ( pos === "after" ) {
pos = {};
pos.after = target;
target = target.parentNode;
target.insertBefore( obj, pos.after.nextSibling );
}
else if ( pos.after !== undefined ) {
target.insertBefore( obj, pos.after.nextSibling );
}
else if ( pos === "before" ) {
pos = {};
pos.before = target;
target = target.parentNode;
target.insertBefore( obj, pos.before );
}
else if ( pos.before !== undefined ) {
target.insertBefore( obj, pos.before );
}
else {
target.appendChild( obj );
}
return !frag ? obj : result;
}
|
javascript
|
{
"resource": ""
}
|
|
q7957
|
train
|
function ( obj, key, value ) {
key = string.toCamelCase( key );
if ( value !== undefined ) {
obj.style[key] = value;
return obj;
}
else {
return obj.style[key];
}
}
|
javascript
|
{
"resource": ""
}
|
|
q7958
|
train
|
function ( obj ) {
observer.remove( obj );
if ( obj.parentNode !== null ) {
obj.parentNode.removeChild( obj );
}
return undefined;
}
|
javascript
|
{
"resource": ""
}
|
|
q7959
|
train
|
function ( obj, arg ) {
var result = [];
utility.genId( obj, true );
array.each( string.explode( arg ), function ( i ) {
result = result.concat( utility.$( "#" + obj.id + " " + i ) );
});
return result;
}
|
javascript
|
{
"resource": ""
}
|
|
q7960
|
train
|
function ( arg ) {
var obj = document.createDocumentFragment();
if ( arg ) {
array.each( array.cast( element.create( "div", {innerHTML: arg}, obj ).childNodes ), function ( i ) {
obj.appendChild( i );
});
obj.removeChild( obj.childNodes[0] );
}
return obj;
}
|
javascript
|
{
"resource": ""
}
|
|
q7961
|
train
|
function ( obj, arg ) {
var result = element.find( obj, arg );
return ( !isNaN( result.length ) && result.length > 0 );
}
|
javascript
|
{
"resource": ""
}
|
|
q7962
|
train
|
function ( obj, arg ) {
if ( arg === undefined ) {
return obj.innerHTML;
}
else {
obj.innerHTML = arg;
return obj;
}
}
|
javascript
|
{
"resource": ""
}
|
|
q7963
|
train
|
function ( obj, arg ) {
if ( regex.selector_is.test( arg ) ) {
utility.id( obj );
return ( element.find( obj.parentNode, obj.nodeName.toLowerCase() + arg ).filter( function ( i ) {
return ( i.id === obj.id );
}).length === 1 );
}
else {
return new RegExp( arg, "i" ).test( obj.nodeName );
}
}
|
javascript
|
{
"resource": ""
}
|
|
q7964
|
train
|
function ( obj ) {
return obj.nodeName === "FORM" ? false : validate.test( {alphanum : obj.value || element.text( obj )} ).pass;
}
|
javascript
|
{
"resource": ""
}
|
|
q7965
|
train
|
function ( obj ) {
return obj.nodeName === "FORM" ? false : string.isDate( obj.value || element.text( obj ) );
}
|
javascript
|
{
"resource": ""
}
|
|
q7966
|
train
|
function ( obj ) {
return obj.nodeName === "FORM" ? false : string.isDomain( obj.value || element.text( obj ) );
}
|
javascript
|
{
"resource": ""
}
|
|
q7967
|
train
|
function ( obj ) {
return obj.nodeName === "FORM" ? false : string.isEmail( obj.value || element.text( obj ) );
}
|
javascript
|
{
"resource": ""
}
|
|
q7968
|
train
|
function ( obj ) {
return obj.nodeName === "FORM" ? false : string.isEmpty( obj.value || element.text( obj ) );
}
|
javascript
|
{
"resource": ""
}
|
|
q7969
|
train
|
function ( obj ) {
return obj.nodeName === "FORM" ? false : string.isIP( obj.value || element.text( obj ) );
}
|
javascript
|
{
"resource": ""
}
|
|
q7970
|
train
|
function ( obj ) {
return obj.nodeName === "FORM" ? false : string.isInt( obj.value || element.text( obj ) );
}
|
javascript
|
{
"resource": ""
}
|
|
q7971
|
train
|
function ( obj ) {
return obj.nodeName === "FORM" ? false : string.isNumber( obj.value || element.text( obj ) );
}
|
javascript
|
{
"resource": ""
}
|
|
q7972
|
train
|
function ( obj ) {
return obj.nodeName === "FORM" ? false : string.isPhone( obj.value || element.text( obj ) );
}
|
javascript
|
{
"resource": ""
}
|
|
q7973
|
train
|
function ( obj ) {
return obj.nodeName === "FORM" ? false : string.isUrl( obj.value || element.text( obj ) );
}
|
javascript
|
{
"resource": ""
}
|
|
q7974
|
train
|
function ( obj, arg, add ) {
add = ( add !== false );
arg = string.explode( arg, " " );
if ( add ) {
array.each( arg, function ( i ) {
obj.classList.add( i );
});
}
else {
array.each( arg, function ( i ) {
if ( i !== "*" ) {
obj.classList.remove( i );
}
else {
array.each( obj.classList, function ( x ) {
this.remove( x );
});
return false;
}
});
}
return obj;
}
|
javascript
|
{
"resource": ""
}
|
|
q7975
|
train
|
function ( obj ) {
obj = obj || document.body;
var left, top, right, bottom, height, width;
left = top = 0;
width = obj.offsetWidth;
height = obj.offsetHeight;
if ( obj.offsetParent ) {
top = obj.offsetTop;
left = obj.offsetLeft;
while ( obj = obj.offsetParent ) {
left += obj.offsetLeft;
top += obj.offsetTop;
}
right = document.body.offsetWidth - ( left + width );
bottom = document.body.offsetHeight - ( top + height );
}
else {
right = width;
bottom = height;
}
return [left, top, right, bottom];
}
|
javascript
|
{
"resource": ""
}
|
|
q7976
|
train
|
function ( obj, child ) {
return obj.childNodes.length === 0 ? obj.appendChild( child ) : obj.insertBefore( child, obj.childNodes[0] );
}
|
javascript
|
{
"resource": ""
}
|
|
q7977
|
train
|
function ( obj, key ) {
var target;
if ( regex.svg.test( obj.namespaceURI ) ) {
obj.removeAttributeNS( obj.namespaceURI, key );
}
else {
if ( obj.nodeName === "SELECT" && key === "selected") {
target = utility.$( "#" + obj.id + " option[selected=\"selected\"]" )[0];
if ( target !== undefined ) {
target.selected = false;
target.removeAttribute( "selected" );
}
}
else {
obj.removeAttribute( key );
}
}
return obj;
}
|
javascript
|
{
"resource": ""
}
|
|
q7978
|
train
|
function ( obj, ms ) {
return client.scroll( array.remove( element.position( obj ), 2, 3 ), ms );
}
|
javascript
|
{
"resource": ""
}
|
|
q7979
|
train
|
function ( obj, string, encode ) {
string = ( string === true );
encode = ( encode !== false );
var children = [],
registry = {},
result;
children = obj.nodeName === "FORM" ? ( obj.elements !== undefined ? array.cast( obj.elements ) : obj.find( "button, input, select, textarea" ) ) : [obj];
array.each( children, function ( i ) {
if ( i.nodeName === "FORM" ) {
utility.merge( registry, json.decode( element.serialize( i ) ) );
}
else if ( registry[i.name] === undefined ) {
registry[i.name] = element.val( i );
}
});
if ( !string ) {
result = json.encode( registry );
}
else {
result = "";
utility.iterate( registry, function ( v, k ) {
encode ? result += "&" + encodeURIComponent( k ) + "=" + encodeURIComponent( v ) : result += "&" + k + "=" + v;
});
result = result.replace( regex.and, "?" );
}
return result;
}
|
javascript
|
{
"resource": ""
}
|
|
q7980
|
train
|
function ( obj ) {
var parse = function ( arg ) {
return number.parse(arg, 10);
};
return {
height : obj.offsetHeight + parse( obj.style.paddingTop || 0 ) + parse( obj.style.paddingBottom || 0 ) + parse( obj.style.borderTop || 0 ) + parse( obj.style.borderBottom || 0 ),
width : obj.offsetWidth + parse( obj.style.paddingLeft || 0 ) + parse( obj.style.paddingRight || 0 ) + parse( obj.style.borderLeft || 0 ) + parse( obj.style.borderRight || 0 )
};
}
|
javascript
|
{
"resource": ""
}
|
|
q7981
|
train
|
function ( obj, args ) {
args = args || {};
utility.iterate( args, function ( v, k ) {
if ( regex.element_update.test( k ) ) {
obj[k] = v;
}
else if ( k === "class" ) {
!string.isEmpty( v ) ? element.klass( obj, v ) : element.klass( obj, "*", false );
}
else if ( k.indexOf( "data-" ) === 0 ) {
element.data( obj, k.replace( "data-", "" ), v );
}
else if ( k === "id" ) {
var o = observer.listeners;
if ( o[obj.id] !== undefined ) {
o[k] = o[obj.id];
delete o[obj.id];
}
}
else {
element.attr ( obj, k, v );
}
});
return obj;
}
|
javascript
|
{
"resource": ""
}
|
|
q7982
|
train
|
function ( obj, value ) {
var event = "input",
output;
if ( value === undefined ) {
if ( regex.radio_checkbox.test( obj.type ) ) {
if ( string.isEmpty( obj.name ) ) {
throw new Error( label.error.expectedProperty );
}
array.each( utility.$( "input[name='" + obj.name + "']" ), function ( i ) {
if ( i.checked ) {
output = i.value;
return false;
}
});
}
else if ( regex.select.test( obj.type ) ) {
output = obj.options[obj.selectedIndex].value;
}
else if ( "value" in obj ) {
output = obj.value;
}
else {
output = element.text( obj );
}
if ( output !== undefined ) {
output = utility.coerce( output );
}
if ( typeof output === "string" ) {
output = string.trim( output );
}
}
else {
value = value.toString();
if ( regex.radio_checkbox.test( obj.type ) ) {
event = "click";
array.each( utility.$( "input[name='" + obj.name + "']" ), function ( i ) {
if ( i.value === value ) {
i.checked = true;
output = i;
return false;
}
});
}
else if ( regex.select.test( obj.type ) ) {
event = "change";
array.each( element.find( obj, "> *" ), function ( i ) {
if ( i.value === value ) {
i.selected = true;
output = i;
return false;
}
});
}
else {
obj.value !== undefined ? obj.value = value : element.text( obj, value );
}
element.dispatch( obj, event );
output = obj;
}
return output;
}
|
javascript
|
{
"resource": ""
}
|
|
q7983
|
train
|
function ( obj ) {
return obj.nodeName === "FORM" ? validate.test( obj ) : !string.isEmpty( obj.value || element.text( obj ) );
}
|
javascript
|
{
"resource": ""
}
|
|
q7984
|
train
|
function ( arg, delimiter, header ) {
delimiter = delimiter || ",";
header = ( header !== false );
var obj = json.decode( arg, true ) || arg,
result = "",
prepare;
// Prepares input based on CSV rules
prepare = function ( input ) {
var output;
if ( input instanceof Array ) {
output = "\"" + input.toString() + "\"";
if ( regex.object_type.test( output ) ) {
output = "\"" + json.csv( input, delimiter ) + "\"";
}
}
else if ( input instanceof Object ) {
output = "\"" + json.csv( input, delimiter ) + "\"";
}
else if ( regex.csv_quote.test( input ) ) {
output = "\"" + input.replace( /"/g, "\"\"" ) + "\"";
}
else {
output = input;
}
return output;
};
if ( obj instanceof Array ) {
if ( obj[0] instanceof Object ) {
if ( header ) {
result = ( array.keys( obj[0] ).join( delimiter ) + "\n" );
}
result += obj.map( function ( i ) {
return json.csv( i, delimiter, false );
}).join( "\n" );
}
else {
result += ( prepare( obj, delimiter ) + "\n" );
}
}
else {
if ( header ) {
result = ( array.keys( obj ).join( delimiter ) + "\n" );
}
result += ( array.cast( obj ).map( prepare ).join( delimiter ) + "\n" );
}
return result.replace(/\n$/, "");
}
|
javascript
|
{
"resource": ""
}
|
|
q7985
|
train
|
function ( arg, silent ) {
try {
return JSON.parse( arg );
}
catch ( e ) {
if ( silent !== true ) {
utility.error( e, arguments, this );
}
return undefined;
}
}
|
javascript
|
{
"resource": ""
}
|
|
q7986
|
LRU
|
train
|
function LRU ( max ) {
this.cache = {};
this.max = max || 1000;
this.first = null;
this.last = null;
this.length = 0;
}
|
javascript
|
{
"resource": ""
}
|
q7987
|
train
|
function () {
var a = array.cast( arguments ),
t = a.pop(),
P = array.chunk( a, 2 ),
n = P.length,
c, S0, Q0, Q1, Q2, C0, C1, C2, C3;
if ( n < 2 || n > 4 ) {
throw new Error( label.error.invalidArguments );
}
// Setting variables
c = [];
S0 = 1 - t;
Q0 = math.sqr( S0 );
Q1 = 2 * S0 * t;
Q2 = math.sqr( t );
C0 = Math.pow( S0, 3 );
C1 = 3 * Q0 * t;
C2 = 3 * S0 * Q2;
C3 = Math.pow( t, 3 );
// Straight
if ( n === 2 ) {
c.push( ( S0 * P[0][0] ) + ( t * P[1][0] ) );
c.push( ( S0 * P[0][1] ) + ( t * P[1][1] ) );
}
// Quadratic
else if ( n === 3 ) {
c.push( ( Q0 * P[0][0] ) + ( Q1 * P[1][0] ) + ( Q2 + P[2][0] ) );
c.push( ( Q0 * P[0][1] ) + ( Q1 * P[1][1] ) + ( Q2 + P[2][1] ) );
}
// Cubic
else if ( n === 4 ) {
c.push( ( C0 * P[0][0] ) + ( C1 * P[1][0] ) + ( C2 * P[2][0] ) + ( C3 * P[3][0] ) );
c.push( ( C0 * P[0][1] ) + ( C1 * P[1][1] ) + ( C2 * P[2][1] ) + ( C3 * P[3][1] ) );
}
return c;
}
|
javascript
|
{
"resource": ""
}
|
|
q7988
|
train
|
function ( a, b ) {
return Math.sqrt( math.sqr( b[0] - a[0] ) + math.sqr( b[1] - a[1] ) );
}
|
javascript
|
{
"resource": ""
}
|
|
q7989
|
train
|
function ( target, arg ) {
try {
target.postMessage( arg, "*" );
}
catch ( e ) {
utility.error( e, arguments, this );
}
return target;
}
|
javascript
|
{
"resource": ""
}
|
|
q7990
|
train
|
function ( fn, state ) {
state = state || "all";
return observer.add( global, "message", fn, "message", global, state );
}
|
javascript
|
{
"resource": ""
}
|
|
q7991
|
train
|
function ( arg ) {
var type = typeof arg;
if ( type === "object" ) {
var v = document[mouse.view],
x = arg.pageX ? arg.pageX : ( v.scrollLeft + arg.clientX ),
y = arg.pageY ? arg.pageY : ( v.scrollTop + arg.clientY ),
c = false;
if ( mouse.pos.x !== x ) {
c = true;
}
$.mouse.prev.x = mouse.prev.x = number.parse( mouse.pos.x, 10 );
$.mouse.pos.x = mouse.pos.x = x;
$.mouse.diff.x = mouse.diff.x = mouse.pos.x - mouse.prev.x;
if ( mouse.pos.y !== y ) {
c = true;
}
$.mouse.prev.y = mouse.prev.y = number.parse( mouse.pos.y, 10 );
$.mouse.pos.y = mouse.pos.y = y;
$.mouse.diff.y = mouse.diff.y = mouse.pos.y - mouse.prev.y;
if ( c && $.mouse.log ) {
utility.log( [mouse.pos.x, mouse.pos.y, mouse.diff.x, mouse.diff.y] );
}
}
else if ( type === "boolean" ) {
arg ? observer.add( document, "mousemove", mouse.track, "tracking" ) : observer.remove( document, "mousemove", "tracking" );
$.mouse.enabled = mouse.enabled = arg;
}
return $.mouse;
}
|
javascript
|
{
"resource": ""
}
|
|
q7992
|
train
|
function ( num1, num2 ) {
if ( isNaN( num1 ) || isNaN( num2 ) ) {
throw new Error( label.error.expectedNumber );
}
return Math.abs( num1 - num2 );
}
|
javascript
|
{
"resource": ""
}
|
|
q7993
|
train
|
function ( arg, delimiter, every ) {
if ( isNaN( arg ) ) {
throw new Error( label.error.expectedNumber );
}
arg = arg.toString();
delimiter = delimiter || ",";
every = every || 3;
var d = arg.indexOf( "." ) > -1 ? "." + arg.replace( regex.number_format_1, "" ) : "",
a = arg.replace( regex.number_format_2, "" ).split( "" ).reverse(),
p = Math.floor( a.length / every ),
i = 1, n, b;
for ( b = 0; b < p; b++ ) {
n = i === 1 ? every : ( every * i ) + ( i === 2 ? 1 : ( i - 1 ) );
a.splice( n, 0, delimiter );
i++;
}
a = a.reverse().join( "" );
if ( a.charAt( 0 ) === delimiter ) {
a = a.substring( 1 );
}
return a + d;
}
|
javascript
|
{
"resource": ""
}
|
|
q7994
|
train
|
function ( arg, direction ) {
arg = number.parse( arg );
if ( direction === undefined || string.isEmpty( direction ) ) {
return number.parse( arg.toFixed( 0 ) );
}
else if ( regex.down.test( direction ) ) {
return ~~( arg );
}
else {
return Math.ceil( arg );
}
}
|
javascript
|
{
"resource": ""
}
|
|
q7995
|
train
|
function ( obj ) {
var methods = [
["fire", function () { return observer.fire.apply( observer, [this].concat( array.cast( arguments ) ) ); }],
["listeners", function ( event ) { return observer.list(this, event ); }],
["on", function ( event, listener, id, scope, standby ) { return observer.add( this, event, listener, id, scope, standby ); }],
["once", function ( event, listener, id, scope, standby ) { return observer.once( this, event, listener, id, scope, standby ); }],
["un", function ( event, id ) { return observer.remove( this, event, id ); }]
];
array.each( methods, function ( i ) {
utility.property( obj, i[0], {value: i[1], configurable: true, enumerable: true, writable: true} );
});
return obj;
}
|
javascript
|
{
"resource": ""
}
|
|
q7996
|
train
|
function ( obj, event ) {
var quit = false,
a = array.remove( array.cast( arguments ), 0, 1 ),
o, s, log, list;
if ( observer.ignore ) {
return obj;
}
o = observer.id( obj );
if ( o === undefined || event === undefined ) {
throw new Error( label.error.invalidArguments );
}
if ( observer.silent ) {
observer.queue.push( {obj: obj, event: event} );
}
else {
s = state.getCurrent();
log = $.logging;
array.each( string.explode( event ), function ( e ) {
if ( log ) {
utility.log(o + " firing " + e );
}
list = observer.list( obj, e, observer.alisteners );
if ( list.all !== undefined ) {
array.each( list.all, function ( i ) {
var result = i.fn.apply( i.scope, a );
if ( result === false ) {
quit = true;
return result;
}
});
}
if ( !quit && s !== "all" && list[s] !== undefined ) {
array.each( list[s], function ( i ) {
return i.fn.apply( i.scope, a );
});
}
});
}
return obj;
}
|
javascript
|
{
"resource": ""
}
|
|
q7997
|
train
|
function ( arg ) {
var id;
if ( arg === global ) {
id = "window";
}
else if ( !server && arg === document ) {
id = "document";
}
else if ( !server && arg === document.body ) {
id = "body";
}
else {
utility.genId( arg );
id = arg.id || ( typeof arg.toString === "function" ? arg.toString() : arg );
}
return id;
}
|
javascript
|
{
"resource": ""
}
|
|
q7998
|
train
|
function ( obj, event, target ) {
var l = target || observer.listeners,
o = observer.id( obj ),
r;
if ( l[o] === undefined && event === undefined ) {
r = {};
}
else if ( l[o] !== undefined && ( event === undefined || string.isEmpty( event ) ) ) {
r = l[o];
}
else if ( l[o] !== undefined && l[o][event] !== undefined ) {
r = l[o][event];
}
else {
r = {};
}
return r;
}
|
javascript
|
{
"resource": ""
}
|
|
q7999
|
train
|
function ( obj, event, fn, id, scope, st ) {
var uuid = id || utility.genId();
scope = scope || obj;
st = st || state.getCurrent();
if ( obj === undefined || event === null || event === undefined || typeof fn !== "function" ) {
throw new Error( label.error.invalidArguments );
}
observer.add( obj, event, function () {
fn.apply( scope, arguments );
observer.remove( obj, event, uuid, st );
}, uuid, scope, st);
return obj;
}
|
javascript
|
{
"resource": ""
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.