repo
stringlengths
5
67
path
stringlengths
4
116
func_name
stringlengths
0
58
original_string
stringlengths
52
373k
language
stringclasses
1 value
code
stringlengths
52
373k
code_tokens
sequence
docstring
stringlengths
4
11.8k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
86
226
partition
stringclasses
1 value
enketo/enketo-transformer
src/transformer.js
_transform
function _transform( xslStr, xmlDoc, xsltParams ) { const params = xsltParams || {}; return new Promise( ( resolve, reject ) => { libxslt.parse( xslStr, ( error, stylesheet ) => { if ( error ) { reject( error ); } else { stylesheet.apply( xmlDoc, params, ( error, result ) => { if ( error ) { reject( error ); } else { resolve( result ); } } ); } } ); } ); }
javascript
function _transform( xslStr, xmlDoc, xsltParams ) { const params = xsltParams || {}; return new Promise( ( resolve, reject ) => { libxslt.parse( xslStr, ( error, stylesheet ) => { if ( error ) { reject( error ); } else { stylesheet.apply( xmlDoc, params, ( error, result ) => { if ( error ) { reject( error ); } else { resolve( result ); } } ); } } ); } ); }
[ "function", "_transform", "(", "xslStr", ",", "xmlDoc", ",", "xsltParams", ")", "{", "const", "params", "=", "xsltParams", "||", "{", "}", ";", "return", "new", "Promise", "(", "(", "resolve", ",", "reject", ")", "=>", "{", "libxslt", ".", "parse", "(", "xslStr", ",", "(", "error", ",", "stylesheet", ")", "=>", "{", "if", "(", "error", ")", "{", "reject", "(", "error", ")", ";", "}", "else", "{", "stylesheet", ".", "apply", "(", "xmlDoc", ",", "params", ",", "(", "error", ",", "result", ")", "=>", "{", "if", "(", "error", ")", "{", "reject", "(", "error", ")", ";", "}", "else", "{", "resolve", "(", "result", ")", ";", "}", "}", ")", ";", "}", "}", ")", ";", "}", ")", ";", "}" ]
Performs a generic XSLT transformation @param {[type]} xslDoc libxmljs object of XSL stylesheet @param {[type]} xmlDoc libxmljs object of XML document @return {Promise} libxmljs result document object
[ "Performs", "a", "generic", "XSLT", "transformation" ]
58f65a71c7695fd12ace32c86b7a0f719cad6159
https://github.com/enketo/enketo-transformer/blob/58f65a71c7695fd12ace32c86b7a0f719cad6159/src/transformer.js#L74-L91
train
enketo/enketo-transformer
src/transformer.js
_parseXml
function _parseXml( xmlStr ) { let doc; return new Promise( ( resolve, reject ) => { try { doc = libxmljs.parseXml( xmlStr ); resolve( doc ); } catch ( e ) { reject( e ); } } ); }
javascript
function _parseXml( xmlStr ) { let doc; return new Promise( ( resolve, reject ) => { try { doc = libxmljs.parseXml( xmlStr ); resolve( doc ); } catch ( e ) { reject( e ); } } ); }
[ "function", "_parseXml", "(", "xmlStr", ")", "{", "let", "doc", ";", "return", "new", "Promise", "(", "(", "resolve", ",", "reject", ")", "=>", "{", "try", "{", "doc", "=", "libxmljs", ".", "parseXml", "(", "xmlStr", ")", ";", "resolve", "(", "doc", ")", ";", "}", "catch", "(", "e", ")", "{", "reject", "(", "e", ")", ";", "}", "}", ")", ";", "}" ]
Parses and XML string into a libxmljs object @param {string} xmlStr XML string @return {Promise} libxmljs result document object
[ "Parses", "and", "XML", "string", "into", "a", "libxmljs", "object" ]
58f65a71c7695fd12ace32c86b7a0f719cad6159
https://github.com/enketo/enketo-transformer/blob/58f65a71c7695fd12ace32c86b7a0f719cad6159/src/transformer.js#L99-L110
train
enketo/enketo-transformer
src/transformer.js
_replaceTheme
function _replaceTheme( doc, theme ) { const HAS_THEME = /(theme-)[^"'\s]+/; if ( !theme ) { return doc; } const formClassAttr = doc.root().get( '/root/form' ).attr( 'class' ); const formClassValue = formClassAttr.value(); if ( HAS_THEME.test( formClassValue ) ) { formClassAttr.value( formClassValue.replace( HAS_THEME, `$1${theme}` ) ); } else { formClassAttr.value( `${formClassValue} theme-${theme}` ); } return doc; }
javascript
function _replaceTheme( doc, theme ) { const HAS_THEME = /(theme-)[^"'\s]+/; if ( !theme ) { return doc; } const formClassAttr = doc.root().get( '/root/form' ).attr( 'class' ); const formClassValue = formClassAttr.value(); if ( HAS_THEME.test( formClassValue ) ) { formClassAttr.value( formClassValue.replace( HAS_THEME, `$1${theme}` ) ); } else { formClassAttr.value( `${formClassValue} theme-${theme}` ); } return doc; }
[ "function", "_replaceTheme", "(", "doc", ",", "theme", ")", "{", "const", "HAS_THEME", "=", "/", "(theme-)[^\"'\\s]+", "/", ";", "if", "(", "!", "theme", ")", "{", "return", "doc", ";", "}", "const", "formClassAttr", "=", "doc", ".", "root", "(", ")", ".", "get", "(", "'/root/form'", ")", ".", "attr", "(", "'class'", ")", ";", "const", "formClassValue", "=", "formClassAttr", ".", "value", "(", ")", ";", "if", "(", "HAS_THEME", ".", "test", "(", "formClassValue", ")", ")", "{", "formClassAttr", ".", "value", "(", "formClassValue", ".", "replace", "(", "HAS_THEME", ",", "`", "${", "theme", "}", "`", ")", ")", ";", "}", "else", "{", "formClassAttr", ".", "value", "(", "`", "${", "formClassValue", "}", "${", "theme", "}", "`", ")", ";", "}", "return", "doc", ";", "}" ]
Replaces the form-defined theme @param {[type]} doc libxmljs object @param {string} theme theme @return {[type]} libxmljs object
[ "Replaces", "the", "form", "-", "defined", "theme" ]
58f65a71c7695fd12ace32c86b7a0f719cad6159
https://github.com/enketo/enketo-transformer/blob/58f65a71c7695fd12ace32c86b7a0f719cad6159/src/transformer.js#L119-L136
train
enketo/enketo-transformer
src/transformer.js
_replaceMediaSources
function _replaceMediaSources( xmlDoc, mediaMap ) { if ( !mediaMap ) { return xmlDoc; } // iterate through each element with a src attribute xmlDoc.find( '//*[@src] | //a[@href]' ).forEach( mediaEl => { const attribute = ( mediaEl.name().toLowerCase() === 'a' ) ? 'href' : 'src'; const src = mediaEl.attr( attribute ).value(); const matches = src ? src.match( /jr:\/\/[\w-]+\/(.+)/ ) : null; const filename = matches && matches.length ? matches[ 1 ] : null; const replacement = filename ? mediaMap[ filename ] : null; if ( replacement ) { mediaEl.attr( attribute, replacement ); } } ); // add form logo <img> element if applicable const formLogo = mediaMap[ 'form_logo.png' ]; const formLogoEl = xmlDoc.get( '//*[@class="form-logo"]' ); if ( formLogo && formLogoEl ) { formLogoEl .node( 'img' ) .attr( 'src', formLogo ) .attr( 'alt', 'form logo' ); } return xmlDoc; }
javascript
function _replaceMediaSources( xmlDoc, mediaMap ) { if ( !mediaMap ) { return xmlDoc; } // iterate through each element with a src attribute xmlDoc.find( '//*[@src] | //a[@href]' ).forEach( mediaEl => { const attribute = ( mediaEl.name().toLowerCase() === 'a' ) ? 'href' : 'src'; const src = mediaEl.attr( attribute ).value(); const matches = src ? src.match( /jr:\/\/[\w-]+\/(.+)/ ) : null; const filename = matches && matches.length ? matches[ 1 ] : null; const replacement = filename ? mediaMap[ filename ] : null; if ( replacement ) { mediaEl.attr( attribute, replacement ); } } ); // add form logo <img> element if applicable const formLogo = mediaMap[ 'form_logo.png' ]; const formLogoEl = xmlDoc.get( '//*[@class="form-logo"]' ); if ( formLogo && formLogoEl ) { formLogoEl .node( 'img' ) .attr( 'src', formLogo ) .attr( 'alt', 'form logo' ); } return xmlDoc; }
[ "function", "_replaceMediaSources", "(", "xmlDoc", ",", "mediaMap", ")", "{", "if", "(", "!", "mediaMap", ")", "{", "return", "xmlDoc", ";", "}", "xmlDoc", ".", "find", "(", "'//*[@src] | //a[@href]'", ")", ".", "forEach", "(", "mediaEl", "=>", "{", "const", "attribute", "=", "(", "mediaEl", ".", "name", "(", ")", ".", "toLowerCase", "(", ")", "===", "'a'", ")", "?", "'href'", ":", "'src'", ";", "const", "src", "=", "mediaEl", ".", "attr", "(", "attribute", ")", ".", "value", "(", ")", ";", "const", "matches", "=", "src", "?", "src", ".", "match", "(", "/", "jr:\\/\\/[\\w-]+\\/(.+)", "/", ")", ":", "null", ";", "const", "filename", "=", "matches", "&&", "matches", ".", "length", "?", "matches", "[", "1", "]", ":", "null", ";", "const", "replacement", "=", "filename", "?", "mediaMap", "[", "filename", "]", ":", "null", ";", "if", "(", "replacement", ")", "{", "mediaEl", ".", "attr", "(", "attribute", ",", "replacement", ")", ";", "}", "}", ")", ";", "const", "formLogo", "=", "mediaMap", "[", "'form_logo.png'", "]", ";", "const", "formLogoEl", "=", "xmlDoc", ".", "get", "(", "'//*[@class=\"form-logo\"]'", ")", ";", "if", "(", "formLogo", "&&", "formLogoEl", ")", "{", "formLogoEl", ".", "node", "(", "'img'", ")", ".", "attr", "(", "'src'", ",", "formLogo", ")", ".", "attr", "(", "'alt'", ",", "'form logo'", ")", ";", "}", "return", "xmlDoc", ";", "}" ]
Replaces xformManifest urls with URLs according to an internal Enketo Express url format @param {[type]} xmlDoc libxmljs object @param {*} manifest json representation of XForm manifest @return {Promise} libxmljs object
[ "Replaces", "xformManifest", "urls", "with", "URLs", "according", "to", "an", "internal", "Enketo", "Express", "url", "format" ]
58f65a71c7695fd12ace32c86b7a0f719cad6159
https://github.com/enketo/enketo-transformer/blob/58f65a71c7695fd12ace32c86b7a0f719cad6159/src/transformer.js#L145-L173
train
enketo/enketo-transformer
src/transformer.js
_replaceLanguageTags
function _replaceLanguageTags( doc, survey ) { const map = {}; const languageElements = doc.find( '/root/form/select[@id="form-languages"]/option' ); // List of parsed language objects const languages = languageElements.map( el => { const lang = el.text(); return language.parse( lang, _getLanguageSampleText( doc, lang ) ); } ); // forms without itext and only one language, still need directionality info if ( languages.length === 0 ) { languages.push( language.parse( '', _getLanguageSampleText( doc, '' ) ) ); } // add or correct dir and value attributes, and amend textcontent of options in language selector languageElements.forEach( ( el, index ) => { const val = el.attr( 'value' ).value(); if ( val && val !== languages[ index ].tag ) { map[ val ] = languages[ index ].tag; } el.attr( { 'data-dir': languages[ index ].dir, 'value': languages[ index ].tag } ).text( languages[ index ].desc ); } ); // correct lang attributes languages.forEach( lang => { if ( lang.src === lang.tag ) { return; } doc.find( `/root/form//*[@lang="${lang.src}"]` ).forEach( el => { el.attr( { lang: lang.tag } ); } ); } ); // correct default lang attribute const langSelectorElement = doc.get( '/root/form/*[@data-default-lang]' ); if ( langSelectorElement ) { const defaultLang = langSelectorElement.attr( 'data-default-lang' ).value(); languages.some( lang => { if ( lang.src === defaultLang ) { langSelectorElement.attr( { 'data-default-lang': lang.tag } ); return true; } return false; } ); } survey.languageMap = map; return doc; }
javascript
function _replaceLanguageTags( doc, survey ) { const map = {}; const languageElements = doc.find( '/root/form/select[@id="form-languages"]/option' ); // List of parsed language objects const languages = languageElements.map( el => { const lang = el.text(); return language.parse( lang, _getLanguageSampleText( doc, lang ) ); } ); // forms without itext and only one language, still need directionality info if ( languages.length === 0 ) { languages.push( language.parse( '', _getLanguageSampleText( doc, '' ) ) ); } // add or correct dir and value attributes, and amend textcontent of options in language selector languageElements.forEach( ( el, index ) => { const val = el.attr( 'value' ).value(); if ( val && val !== languages[ index ].tag ) { map[ val ] = languages[ index ].tag; } el.attr( { 'data-dir': languages[ index ].dir, 'value': languages[ index ].tag } ).text( languages[ index ].desc ); } ); // correct lang attributes languages.forEach( lang => { if ( lang.src === lang.tag ) { return; } doc.find( `/root/form//*[@lang="${lang.src}"]` ).forEach( el => { el.attr( { lang: lang.tag } ); } ); } ); // correct default lang attribute const langSelectorElement = doc.get( '/root/form/*[@data-default-lang]' ); if ( langSelectorElement ) { const defaultLang = langSelectorElement.attr( 'data-default-lang' ).value(); languages.some( lang => { if ( lang.src === defaultLang ) { langSelectorElement.attr( { 'data-default-lang': lang.tag } ); return true; } return false; } ); } survey.languageMap = map; return doc; }
[ "function", "_replaceLanguageTags", "(", "doc", ",", "survey", ")", "{", "const", "map", "=", "{", "}", ";", "const", "languageElements", "=", "doc", ".", "find", "(", "'/root/form/select[@id=\"form-languages\"]/option'", ")", ";", "const", "languages", "=", "languageElements", ".", "map", "(", "el", "=>", "{", "const", "lang", "=", "el", ".", "text", "(", ")", ";", "return", "language", ".", "parse", "(", "lang", ",", "_getLanguageSampleText", "(", "doc", ",", "lang", ")", ")", ";", "}", ")", ";", "if", "(", "languages", ".", "length", "===", "0", ")", "{", "languages", ".", "push", "(", "language", ".", "parse", "(", "''", ",", "_getLanguageSampleText", "(", "doc", ",", "''", ")", ")", ")", ";", "}", "languageElements", ".", "forEach", "(", "(", "el", ",", "index", ")", "=>", "{", "const", "val", "=", "el", ".", "attr", "(", "'value'", ")", ".", "value", "(", ")", ";", "if", "(", "val", "&&", "val", "!==", "languages", "[", "index", "]", ".", "tag", ")", "{", "map", "[", "val", "]", "=", "languages", "[", "index", "]", ".", "tag", ";", "}", "el", ".", "attr", "(", "{", "'data-dir'", ":", "languages", "[", "index", "]", ".", "dir", ",", "'value'", ":", "languages", "[", "index", "]", ".", "tag", "}", ")", ".", "text", "(", "languages", "[", "index", "]", ".", "desc", ")", ";", "}", ")", ";", "languages", ".", "forEach", "(", "lang", "=>", "{", "if", "(", "lang", ".", "src", "===", "lang", ".", "tag", ")", "{", "return", ";", "}", "doc", ".", "find", "(", "`", "${", "lang", ".", "src", "}", "`", ")", ".", "forEach", "(", "el", "=>", "{", "el", ".", "attr", "(", "{", "lang", ":", "lang", ".", "tag", "}", ")", ";", "}", ")", ";", "}", ")", ";", "const", "langSelectorElement", "=", "doc", ".", "get", "(", "'/root/form/*[@data-default-lang]'", ")", ";", "if", "(", "langSelectorElement", ")", "{", "const", "defaultLang", "=", "langSelectorElement", ".", "attr", "(", "'data-default-lang'", ")", ".", "value", "(", ")", ";", "languages", ".", "some", "(", "lang", "=>", "{", "if", "(", "lang", ".", "src", "===", "defaultLang", ")", "{", "langSelectorElement", ".", "attr", "(", "{", "'data-default-lang'", ":", "lang", ".", "tag", "}", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}", ")", ";", "}", "survey", ".", "languageMap", "=", "map", ";", "return", "doc", ";", "}" ]
Replaces all lang attributes to the valid IANA tag if found. Also add the dir attribute to the languages in the language selector. @see http://www.w3.org/International/questions/qa-choosing-language-tags @param {[type]} doc libxmljs object @return {[type]} libxmljs object
[ "Replaces", "all", "lang", "attributes", "to", "the", "valid", "IANA", "tag", "if", "found", ".", "Also", "add", "the", "dir", "attribute", "to", "the", "languages", "in", "the", "language", "selector", "." ]
58f65a71c7695fd12ace32c86b7a0f719cad6159
https://github.com/enketo/enketo-transformer/blob/58f65a71c7695fd12ace32c86b7a0f719cad6159/src/transformer.js#L184-L241
train
enketo/enketo-transformer
src/transformer.js
_getLanguageSampleText
function _getLanguageSampleText( doc, lang ) { // First find non-empty text content of a hint with that lang attribute. // If not found, find any span with that lang attribute. const langSampleEl = doc.get( `/root/form//span[contains(@class, "or-hint") and @lang="${lang}" and normalize-space() and not(./text() = '-')]` ) || doc.get( `/root/form//span[@lang="${lang}" and normalize-space() and not(./text() = '-')]` ); return ( langSampleEl && langSampleEl.text().trim().length ) ? langSampleEl.text() : 'nothing'; }
javascript
function _getLanguageSampleText( doc, lang ) { // First find non-empty text content of a hint with that lang attribute. // If not found, find any span with that lang attribute. const langSampleEl = doc.get( `/root/form//span[contains(@class, "or-hint") and @lang="${lang}" and normalize-space() and not(./text() = '-')]` ) || doc.get( `/root/form//span[@lang="${lang}" and normalize-space() and not(./text() = '-')]` ); return ( langSampleEl && langSampleEl.text().trim().length ) ? langSampleEl.text() : 'nothing'; }
[ "function", "_getLanguageSampleText", "(", "doc", ",", "lang", ")", "{", "const", "langSampleEl", "=", "doc", ".", "get", "(", "`", "${", "lang", "}", "`", ")", "||", "doc", ".", "get", "(", "`", "${", "lang", "}", "`", ")", ";", "return", "(", "langSampleEl", "&&", "langSampleEl", ".", "text", "(", ")", ".", "trim", "(", ")", ".", "length", ")", "?", "langSampleEl", ".", "text", "(", ")", ":", "'nothing'", ";", "}" ]
Obtains a non-empty hint text or other text sample of a particular form language. @param {[type]} doc libxmljs object @param {string} lang language @return {string} the text sample
[ "Obtains", "a", "non", "-", "empty", "hint", "text", "or", "other", "text", "sample", "of", "a", "particular", "form", "language", "." ]
58f65a71c7695fd12ace32c86b7a0f719cad6159
https://github.com/enketo/enketo-transformer/blob/58f65a71c7695fd12ace32c86b7a0f719cad6159/src/transformer.js#L250-L257
train
enketo/enketo-transformer
src/transformer.js
_renderMarkdown
function _renderMarkdown( htmlDoc ) { const replacements = {}; // First turn all outputs into text so *<span class="or-output></span>* can be detected htmlDoc.find( '/root/form//span[contains(@class, "or-output")]' ).forEach( ( el, index ) => { const key = `---output-${index}`; const textNode = el.childNodes()[ 0 ].clone(); replacements[ key ] = el.toString(); textNode.text( key ); el.replace( textNode ); // Note that we end up in a situation where we likely have sibling text nodes... } ); // Now render markdown htmlDoc.find( '/root/form//span[contains(@class, "question-label") or contains(@class, "or-hint")]' ).forEach( ( el, index ) => { let key; /** * Using text() is done because: * a) We are certain that these <span>s do not contain other elements, other than formatting/markdown <span>s. * b) This avoids the need to merge any sibling text nodes that could have been created in the previous step. * * Note that text() will convert &gt; to > */ const original = el.text().replace( '<', '&lt;' ).replace( '>', '&gt;' ); const rendered = markdown.toHtml( original ); if ( original !== rendered ) { key = `$$$${index}`; replacements[ key ] = rendered; el.text( key ); } } ); // TODO: does this result in self-closing tags? let htmlStr = _docToString( htmlDoc ); // Now replace the placeholders with the rendered HTML // in reverse order so outputs are done last Object.keys( replacements ).reverse().forEach( key => { const replacement = replacements[ key ]; if ( replacement ) { htmlStr = htmlStr.replace( key, replacement ); } } ); return htmlStr; }
javascript
function _renderMarkdown( htmlDoc ) { const replacements = {}; // First turn all outputs into text so *<span class="or-output></span>* can be detected htmlDoc.find( '/root/form//span[contains(@class, "or-output")]' ).forEach( ( el, index ) => { const key = `---output-${index}`; const textNode = el.childNodes()[ 0 ].clone(); replacements[ key ] = el.toString(); textNode.text( key ); el.replace( textNode ); // Note that we end up in a situation where we likely have sibling text nodes... } ); // Now render markdown htmlDoc.find( '/root/form//span[contains(@class, "question-label") or contains(@class, "or-hint")]' ).forEach( ( el, index ) => { let key; /** * Using text() is done because: * a) We are certain that these <span>s do not contain other elements, other than formatting/markdown <span>s. * b) This avoids the need to merge any sibling text nodes that could have been created in the previous step. * * Note that text() will convert &gt; to > */ const original = el.text().replace( '<', '&lt;' ).replace( '>', '&gt;' ); const rendered = markdown.toHtml( original ); if ( original !== rendered ) { key = `$$$${index}`; replacements[ key ] = rendered; el.text( key ); } } ); // TODO: does this result in self-closing tags? let htmlStr = _docToString( htmlDoc ); // Now replace the placeholders with the rendered HTML // in reverse order so outputs are done last Object.keys( replacements ).reverse().forEach( key => { const replacement = replacements[ key ]; if ( replacement ) { htmlStr = htmlStr.replace( key, replacement ); } } ); return htmlStr; }
[ "function", "_renderMarkdown", "(", "htmlDoc", ")", "{", "const", "replacements", "=", "{", "}", ";", "htmlDoc", ".", "find", "(", "'/root/form//span[contains(@class, \"or-output\")]'", ")", ".", "forEach", "(", "(", "el", ",", "index", ")", "=>", "{", "const", "key", "=", "`", "${", "index", "}", "`", ";", "const", "textNode", "=", "el", ".", "childNodes", "(", ")", "[", "0", "]", ".", "clone", "(", ")", ";", "replacements", "[", "key", "]", "=", "el", ".", "toString", "(", ")", ";", "textNode", ".", "text", "(", "key", ")", ";", "el", ".", "replace", "(", "textNode", ")", ";", "}", ")", ";", "htmlDoc", ".", "find", "(", "'/root/form//span[contains(@class, \"question-label\") or contains(@class, \"or-hint\")]'", ")", ".", "forEach", "(", "(", "el", ",", "index", ")", "=>", "{", "let", "key", ";", "const", "original", "=", "el", ".", "text", "(", ")", ".", "replace", "(", "'<'", ",", "'&lt;'", ")", ".", "replace", "(", "'>'", ",", "'&gt;'", ")", ";", "const", "rendered", "=", "markdown", ".", "toHtml", "(", "original", ")", ";", "if", "(", "original", "!==", "rendered", ")", "{", "key", "=", "`", "${", "index", "}", "`", ";", "replacements", "[", "key", "]", "=", "rendered", ";", "el", ".", "text", "(", "key", ")", ";", "}", "}", ")", ";", "let", "htmlStr", "=", "_docToString", "(", "htmlDoc", ")", ";", "Object", ".", "keys", "(", "replacements", ")", ".", "reverse", "(", ")", ".", "forEach", "(", "key", "=>", "{", "const", "replacement", "=", "replacements", "[", "key", "]", ";", "if", "(", "replacement", ")", "{", "htmlStr", "=", "htmlStr", ".", "replace", "(", "key", ",", "replacement", ")", ";", "}", "}", ")", ";", "return", "htmlStr", ";", "}" ]
Converts a subset of Markdown in all textnode children of labels and hints into HTML @param {[type]} htmlDoc libxmljs object @return {[type]} libxmljs object
[ "Converts", "a", "subset", "of", "Markdown", "in", "all", "textnode", "children", "of", "labels", "and", "hints", "into", "HTML" ]
58f65a71c7695fd12ace32c86b7a0f719cad6159
https://github.com/enketo/enketo-transformer/blob/58f65a71c7695fd12ace32c86b7a0f719cad6159/src/transformer.js#L293-L338
train
enketo/enketo-transformer
src/transformer.js
_md5
function _md5( message ) { const hash = crypto.createHash( 'md5' ); hash.update( message ); return hash.digest( 'hex' ); }
javascript
function _md5( message ) { const hash = crypto.createHash( 'md5' ); hash.update( message ); return hash.digest( 'hex' ); }
[ "function", "_md5", "(", "message", ")", "{", "const", "hash", "=", "crypto", ".", "createHash", "(", "'md5'", ")", ";", "hash", ".", "update", "(", "message", ")", ";", "return", "hash", ".", "digest", "(", "'hex'", ")", ";", "}" ]
Calculate the md5 hash of a message. @param {string|Buffer} message The string or buffer @return {string} The hash
[ "Calculate", "the", "md5", "hash", "of", "a", "message", "." ]
58f65a71c7695fd12ace32c86b7a0f719cad6159
https://github.com/enketo/enketo-transformer/blob/58f65a71c7695fd12ace32c86b7a0f719cad6159/src/transformer.js#L363-L367
train
enketo/enketo-transformer
src/markdown.js
markdownToHtml
function markdownToHtml( text ) { // note: in JS $ matches end of line as well as end of string, and ^ both beginning of line and string const html = text // html encoding of < because libXMLJs Element.text() converts html entities .replace( /</gm, '&lt;' ) // html encoding of < because libXMLJs Element.text() converts html entities .replace( />/gm, '&gt;' ) // span .replace( /&lt;\s?span([^/\n]*)&gt;((?:(?!&lt;\/).)+)&lt;\/\s?span\s?&gt;/gm, _createSpan ) // sup .replace( /&lt;\s?sup([^/\n]*)&gt;((?:(?!&lt;\/).)+)&lt;\/\s?sup\s?&gt;/gm, _createSup ) // sub .replace( /&lt;\s?sub([^/\n]*)&gt;((?:(?!&lt;\/).)+)&lt;\/\s?sub\s?&gt;/gm, _createSub ) // "\" will be used as escape character for *, _ .replace( /&/gm, '&amp;' ) .replace( /\\\\/gm, '&92;' ) .replace( /\\\*/gm, '&42;' ) .replace( /\\_/gm, '&95;' ) .replace( /\\#/gm, '&35;' ) // strong .replace( /__(.*?)__/gm, '<strong>$1</strong>' ) .replace( /\*\*(.*?)\*\*/gm, '<strong>$1</strong>' ) // emphasis .replace( /_([^\s][^_\n]*)_/gm, '<em>$1</em>' ) .replace( /\*([^\s][^*\n]*)\*/gm, '<em>$1</em>' ) // links .replace( /\[([^\]]*)\]\(([^)]+)\)/gm, '<a href="$2" target="_blank">$1</a>' ) // headers .replace( /^\s*(#{1,6})\s?([^#][^\n]*)(\n|$)/gm, _createHeader ) // unordered lists .replace( /(\n(\*|\+|-) (.*))+$/gm, _createUnorderedList ) // ordered lists .replace( /(\n([0-9]+\.) (.*))+$/gm, _createOrderedList ) // reverting escape of special characters .replace( /&35;/gm, '#' ) .replace( /&95;/gm, '_' ) .replace( /&92;/gm, '\\' ) .replace( /&42;/gm, '*' ) .replace( /&amp;/gm, '&' ) // paragraphs .replace( /([^\n]+)\n{2,}/gm, _createParagraph ) // any remaining newline characters .replace( /([^\n]+)\n/gm, '$1<br>' ); return html; }
javascript
function markdownToHtml( text ) { // note: in JS $ matches end of line as well as end of string, and ^ both beginning of line and string const html = text // html encoding of < because libXMLJs Element.text() converts html entities .replace( /</gm, '&lt;' ) // html encoding of < because libXMLJs Element.text() converts html entities .replace( />/gm, '&gt;' ) // span .replace( /&lt;\s?span([^/\n]*)&gt;((?:(?!&lt;\/).)+)&lt;\/\s?span\s?&gt;/gm, _createSpan ) // sup .replace( /&lt;\s?sup([^/\n]*)&gt;((?:(?!&lt;\/).)+)&lt;\/\s?sup\s?&gt;/gm, _createSup ) // sub .replace( /&lt;\s?sub([^/\n]*)&gt;((?:(?!&lt;\/).)+)&lt;\/\s?sub\s?&gt;/gm, _createSub ) // "\" will be used as escape character for *, _ .replace( /&/gm, '&amp;' ) .replace( /\\\\/gm, '&92;' ) .replace( /\\\*/gm, '&42;' ) .replace( /\\_/gm, '&95;' ) .replace( /\\#/gm, '&35;' ) // strong .replace( /__(.*?)__/gm, '<strong>$1</strong>' ) .replace( /\*\*(.*?)\*\*/gm, '<strong>$1</strong>' ) // emphasis .replace( /_([^\s][^_\n]*)_/gm, '<em>$1</em>' ) .replace( /\*([^\s][^*\n]*)\*/gm, '<em>$1</em>' ) // links .replace( /\[([^\]]*)\]\(([^)]+)\)/gm, '<a href="$2" target="_blank">$1</a>' ) // headers .replace( /^\s*(#{1,6})\s?([^#][^\n]*)(\n|$)/gm, _createHeader ) // unordered lists .replace( /(\n(\*|\+|-) (.*))+$/gm, _createUnorderedList ) // ordered lists .replace( /(\n([0-9]+\.) (.*))+$/gm, _createOrderedList ) // reverting escape of special characters .replace( /&35;/gm, '#' ) .replace( /&95;/gm, '_' ) .replace( /&92;/gm, '\\' ) .replace( /&42;/gm, '*' ) .replace( /&amp;/gm, '&' ) // paragraphs .replace( /([^\n]+)\n{2,}/gm, _createParagraph ) // any remaining newline characters .replace( /([^\n]+)\n/gm, '$1<br>' ); return html; }
[ "function", "markdownToHtml", "(", "text", ")", "{", "const", "html", "=", "text", ".", "replace", "(", "/", "<", "/", "gm", ",", "'&lt;'", ")", ".", "replace", "(", "/", ">", "/", "gm", ",", "'&gt;'", ")", ".", "replace", "(", "/", "&lt;\\s?span([^/\\n]*)&gt;((?:(?!&lt;\\/).)+)&lt;\\/\\s?span\\s?&gt;", "/", "gm", ",", "_createSpan", ")", ".", "replace", "(", "/", "&lt;\\s?sup([^/\\n]*)&gt;((?:(?!&lt;\\/).)+)&lt;\\/\\s?sup\\s?&gt;", "/", "gm", ",", "_createSup", ")", ".", "replace", "(", "/", "&lt;\\s?sub([^/\\n]*)&gt;((?:(?!&lt;\\/).)+)&lt;\\/\\s?sub\\s?&gt;", "/", "gm", ",", "_createSub", ")", ".", "replace", "(", "/", "&", "/", "gm", ",", "'&amp;'", ")", ".", "replace", "(", "/", "\\\\\\\\", "/", "gm", ",", "'&92;'", ")", ".", "replace", "(", "/", "\\\\\\*", "/", "gm", ",", "'&42;'", ")", ".", "replace", "(", "/", "\\\\_", "/", "gm", ",", "'&95;'", ")", ".", "replace", "(", "/", "\\\\#", "/", "gm", ",", "'&35;'", ")", ".", "replace", "(", "/", "__(.*?)__", "/", "gm", ",", "'<strong>$1</strong>'", ")", ".", "replace", "(", "/", "\\*\\*(.*?)\\*\\*", "/", "gm", ",", "'<strong>$1</strong>'", ")", ".", "replace", "(", "/", "_([^\\s][^_\\n]*)_", "/", "gm", ",", "'<em>$1</em>'", ")", ".", "replace", "(", "/", "\\*([^\\s][^*\\n]*)\\*", "/", "gm", ",", "'<em>$1</em>'", ")", ".", "replace", "(", "/", "\\[([^\\]]*)\\]\\(([^)]+)\\)", "/", "gm", ",", "'<a href=\"$2\" target=\"_blank\">$1</a>'", ")", ".", "replace", "(", "/", "^\\s*(#{1,6})\\s?([^#][^\\n]*)(\\n|$)", "/", "gm", ",", "_createHeader", ")", ".", "replace", "(", "/", "(\\n(\\*|\\+|-) (.*))+$", "/", "gm", ",", "_createUnorderedList", ")", ".", "replace", "(", "/", "(\\n([0-9]+\\.) (.*))+$", "/", "gm", ",", "_createOrderedList", ")", ".", "replace", "(", "/", "&35;", "/", "gm", ",", "'#'", ")", ".", "replace", "(", "/", "&95;", "/", "gm", ",", "'_'", ")", ".", "replace", "(", "/", "&92;", "/", "gm", ",", "'\\\\'", ")", ".", "\\\\", "replace", ".", "(", "/", "&42;", "/", "gm", ",", "'*'", ")", "replace", ".", "(", "/", "&amp;", "/", "gm", ",", "'&'", ")", "replace", ".", "(", "/", "([^\\n]+)\\n{2,}", "/", "gm", ",", "_createParagraph", ")", "replace", ";", "(", "/", "([^\\n]+)\\n", "/", "gm", ",", "'$1<br>'", ")", "}" ]
Transforms XForm label and hint textnode content with a subset of Markdown into HTML Supported: - _, __, *, **, [](), #, ##, ###, ####, #####, - span tags and html-encoded span tags, - single-level unordered markdown lists and single-level ordered markdown lists - newline characters Also HTML encodes any unsupported HTML tags for safe use inside web-based clients @param {string} text text content of a textnode @return {string} transformed text content of a textnode
[ "Transforms", "XForm", "label", "and", "hint", "textnode", "content", "with", "a", "subset", "of", "Markdown", "into", "HTML" ]
58f65a71c7695fd12ace32c86b7a0f719cad6159
https://github.com/enketo/enketo-transformer/blob/58f65a71c7695fd12ace32c86b7a0f719cad6159/src/markdown.js#L15-L60
train
pimterry/raspivid-stream
index.js
getLiveStream
function getLiveStream(options) { return raspivid(Object.assign({ width: 960, height: 540, framerate: 20, profile: 'baseline', timeout: 0 }, options)) .pipe(new Splitter(NALseparator)) .pipe(new stream.Transform({ transform: function (chunk, encoding, callback) { const chunkWithSeparator = Buffer.concat([NALseparator, chunk]); const chunkType = chunk[0] & 0b11111; // Capture the first SPS & PPS frames, so we can send stream parameters on connect. if (chunkType === 7 || chunkType === 8) { headerData.addParameterFrame(chunkWithSeparator); } else { // The live stream only includes the non-parameter chunks this.push(chunkWithSeparator); // Keep track of the latest IDR chunk, so we can start clients off with a near-current image if (chunkType === 5) { headerData.idrFrame = chunkWithSeparator; } } callback(); }})); }
javascript
function getLiveStream(options) { return raspivid(Object.assign({ width: 960, height: 540, framerate: 20, profile: 'baseline', timeout: 0 }, options)) .pipe(new Splitter(NALseparator)) .pipe(new stream.Transform({ transform: function (chunk, encoding, callback) { const chunkWithSeparator = Buffer.concat([NALseparator, chunk]); const chunkType = chunk[0] & 0b11111; // Capture the first SPS & PPS frames, so we can send stream parameters on connect. if (chunkType === 7 || chunkType === 8) { headerData.addParameterFrame(chunkWithSeparator); } else { // The live stream only includes the non-parameter chunks this.push(chunkWithSeparator); // Keep track of the latest IDR chunk, so we can start clients off with a near-current image if (chunkType === 5) { headerData.idrFrame = chunkWithSeparator; } } callback(); }})); }
[ "function", "getLiveStream", "(", "options", ")", "{", "return", "raspivid", "(", "Object", ".", "assign", "(", "{", "width", ":", "960", ",", "height", ":", "540", ",", "framerate", ":", "20", ",", "profile", ":", "'baseline'", ",", "timeout", ":", "0", "}", ",", "options", ")", ")", ".", "pipe", "(", "new", "Splitter", "(", "NALseparator", ")", ")", ".", "pipe", "(", "new", "stream", ".", "Transform", "(", "{", "transform", ":", "function", "(", "chunk", ",", "encoding", ",", "callback", ")", "{", "const", "chunkWithSeparator", "=", "Buffer", ".", "concat", "(", "[", "NALseparator", ",", "chunk", "]", ")", ";", "const", "chunkType", "=", "chunk", "[", "0", "]", "&", "0b11111", ";", "if", "(", "chunkType", "===", "7", "||", "chunkType", "===", "8", ")", "{", "headerData", ".", "addParameterFrame", "(", "chunkWithSeparator", ")", ";", "}", "else", "{", "this", ".", "push", "(", "chunkWithSeparator", ")", ";", "if", "(", "chunkType", "===", "5", ")", "{", "headerData", ".", "idrFrame", "=", "chunkWithSeparator", ";", "}", "}", "callback", "(", ")", ";", "}", "}", ")", ")", ";", "}" ]
This returns the live stream only, without the parameter chunks
[ "This", "returns", "the", "live", "stream", "only", "without", "the", "parameter", "chunks" ]
f50c510188fa1860e6322c84ce96a652fbbad5bd
https://github.com/pimterry/raspivid-stream/blob/f50c510188fa1860e6322c84ce96a652fbbad5bd/index.js#L41-L70
train
enketo/enketo-transformer
src/api.js
_request
function _request( options ) { options.headers = options.headers || {}; options.headers[ 'X-OpenRosa-Version' ] = '1.0'; const method = options.method || 'get'; return new Promise( ( resolve, reject ) => { request[ method ]( options, ( error, response, body ) => { if ( error ) { console.log( `Error occurred when requesting ${options.url}`, error ); reject( error ); } else if ( response.statusCode === 401 ) { const error = new Error( 'Forbidden. Authorization Required.' ); error.status = response.statusCode; reject( error ); } else if ( response.statusCode < 200 || response.statusCode >= 300 ) { const error = new Error( `Request to ${options.url} failed.` ); error.status = response.statusCode; reject( error ); } else { console.log( `response of request to ${options.url} has status code: `, response.statusCode ); resolve( body ); } } ); } ); }
javascript
function _request( options ) { options.headers = options.headers || {}; options.headers[ 'X-OpenRosa-Version' ] = '1.0'; const method = options.method || 'get'; return new Promise( ( resolve, reject ) => { request[ method ]( options, ( error, response, body ) => { if ( error ) { console.log( `Error occurred when requesting ${options.url}`, error ); reject( error ); } else if ( response.statusCode === 401 ) { const error = new Error( 'Forbidden. Authorization Required.' ); error.status = response.statusCode; reject( error ); } else if ( response.statusCode < 200 || response.statusCode >= 300 ) { const error = new Error( `Request to ${options.url} failed.` ); error.status = response.statusCode; reject( error ); } else { console.log( `response of request to ${options.url} has status code: `, response.statusCode ); resolve( body ); } } ); } ); }
[ "function", "_request", "(", "options", ")", "{", "options", ".", "headers", "=", "options", ".", "headers", "||", "{", "}", ";", "options", ".", "headers", "[", "'X-OpenRosa-Version'", "]", "=", "'1.0'", ";", "const", "method", "=", "options", ".", "method", "||", "'get'", ";", "return", "new", "Promise", "(", "(", "resolve", ",", "reject", ")", "=>", "{", "request", "[", "method", "]", "(", "options", ",", "(", "error", ",", "response", ",", "body", ")", "=>", "{", "if", "(", "error", ")", "{", "console", ".", "log", "(", "`", "${", "options", ".", "url", "}", "`", ",", "error", ")", ";", "reject", "(", "error", ")", ";", "}", "else", "if", "(", "response", ".", "statusCode", "===", "401", ")", "{", "const", "error", "=", "new", "Error", "(", "'Forbidden. Authorization Required.'", ")", ";", "error", ".", "status", "=", "response", ".", "statusCode", ";", "reject", "(", "error", ")", ";", "}", "else", "if", "(", "response", ".", "statusCode", "<", "200", "||", "response", ".", "statusCode", ">=", "300", ")", "{", "const", "error", "=", "new", "Error", "(", "`", "${", "options", ".", "url", "}", "`", ")", ";", "error", ".", "status", "=", "response", ".", "statusCode", ";", "reject", "(", "error", ")", ";", "}", "else", "{", "console", ".", "log", "(", "`", "${", "options", ".", "url", "}", "`", ",", "response", ".", "statusCode", ")", ";", "resolve", "(", "body", ")", ";", "}", "}", ")", ";", "}", ")", ";", "}" ]
Sends a request to an OpenRosa server. Only for basic retrieval of public forms that do not require authentication. @param { {url: string, method: string} } options request options object @return { Promise }
[ "Sends", "a", "request", "to", "an", "OpenRosa", "server", ".", "Only", "for", "basic", "retrieval", "of", "public", "forms", "that", "do", "not", "require", "authentication", "." ]
58f65a71c7695fd12ace32c86b7a0f719cad6159
https://github.com/enketo/enketo-transformer/blob/58f65a71c7695fd12ace32c86b7a0f719cad6159/src/api.js#L80-L105
train
dylang/space-hogs
util/percentage.js
percentage
function percentage(num) { const MAX_CHARACTERS = 4; const relativePercentage = Math.ceil(num * 100 / (100 / MAX_CHARACTERS)); return `[${'▒'.repeat(relativePercentage)}${' '.repeat(MAX_CHARACTERS - relativePercentage)}]`; }
javascript
function percentage(num) { const MAX_CHARACTERS = 4; const relativePercentage = Math.ceil(num * 100 / (100 / MAX_CHARACTERS)); return `[${'▒'.repeat(relativePercentage)}${' '.repeat(MAX_CHARACTERS - relativePercentage)}]`; }
[ "function", "percentage", "(", "num", ")", "{", "const", "MAX_CHARACTERS", "=", "4", ";", "const", "relativePercentage", "=", "Math", ".", "ceil", "(", "num", "*", "100", "/", "(", "100", "/", "MAX_CHARACTERS", ")", ")", ";", "return", "`", "${", "'▒'.r", "r", "e", "peat(r", "e", "lativePercentage)}", "$", "{", "' ", "'.r", "r", "e", "peat(M", "A", "X_CHARACTERS -", "r", "lativePercentage)}", "]", "`", "}" ]
Nice way to show percentage. Not really necessary.
[ "Nice", "way", "to", "show", "percentage", ".", "Not", "really", "necessary", "." ]
53c5d0a245dc22c76602c8e4cfdc44f5f6c09311
https://github.com/dylang/space-hogs/blob/53c5d0a245dc22c76602c8e4cfdc44f5f6c09311/util/percentage.js#L4-L9
train
oe/truncate-html
dist/truncate.es.js
extend
function extend(obj, dft) { if (obj == null) { obj = {}; } for (var k in dft) { var v = dft[k]; if (obj[k] != null) { continue; } obj[k] = v; } return obj; }
javascript
function extend(obj, dft) { if (obj == null) { obj = {}; } for (var k in dft) { var v = dft[k]; if (obj[k] != null) { continue; } obj[k] = v; } return obj; }
[ "function", "extend", "(", "obj", ",", "dft", ")", "{", "if", "(", "obj", "==", "null", ")", "{", "obj", "=", "{", "}", ";", "}", "for", "(", "var", "k", "in", "dft", ")", "{", "var", "v", "=", "dft", "[", "k", "]", ";", "if", "(", "obj", "[", "k", "]", "!=", "null", ")", "{", "continue", ";", "}", "obj", "[", "k", "]", "=", "v", ";", "}", "return", "obj", ";", "}" ]
extend obj with dft
[ "extend", "obj", "with", "dft" ]
31bac538894b14db0b68488b9f62d898dd03652b
https://github.com/oe/truncate-html/blob/31bac538894b14db0b68488b9f62d898dd03652b/dist/truncate.es.js#L57-L69
train
oe/truncate-html
dist/truncate.es.js
isBlank
function isBlank(char) { return (char === ' ' || char === '\f' || char === '\n' || char === '\r' || char === '\t' || char === '\v' || char === '\u00A0' || char === '\u2028' || char === '\u2029'); }
javascript
function isBlank(char) { return (char === ' ' || char === '\f' || char === '\n' || char === '\r' || char === '\t' || char === '\v' || char === '\u00A0' || char === '\u2028' || char === '\u2029'); }
[ "function", "isBlank", "(", "char", ")", "{", "return", "(", "char", "===", "' '", "||", "char", "===", "'\\f'", "||", "\\f", "||", "char", "===", "'\\n'", "||", "\\n", "||", "char", "===", "'\\r'", "||", "\\r", "||", "char", "===", "'\\t'", "||", "\\t", ")", ";", "}" ]
test a char whether a whitespace char
[ "test", "a", "char", "whether", "a", "whitespace", "char" ]
31bac538894b14db0b68488b9f62d898dd03652b
https://github.com/oe/truncate-html/blob/31bac538894b14db0b68488b9f62d898dd03652b/dist/truncate.es.js#L71-L81
train
oe/truncate-html
dist/truncate.es.js
substr
function substr(astralSafeCharacterArray, len) { // var boundary, cutted, result var cutted = astralSafeCharacterArray.slice(0, len).join(''); if (!this.reserveLastWord) { return cutted; } var boundary = astralSafeCharacterArray.slice(len - 1, len + 1).join(''); // if truncate at word boundary, just return if (/\W/.test(boundary)) { return cutted; } if (this.reserveLastWord < 0) { var result = cutted.replace(/\w+$/, ''); // if the cutted is not the first and the only word // then return result, or return the whole word if (!(result.length === 0 && cutted.length === this.options.length)) { return result; } } // set max exceeded to 10 if this.reserveLastWord is true or > 0 var maxExceeded = this.reserveLastWord !== true && this.reserveLastWord > 0 ? this.reserveLastWord : 10; var mtc = astralSafeCharacterArray.slice(len).join('').match(/(\w+)/); var exceeded = mtc ? mtc[1] : ''; return cutted + exceeded.substr(0, maxExceeded); }
javascript
function substr(astralSafeCharacterArray, len) { // var boundary, cutted, result var cutted = astralSafeCharacterArray.slice(0, len).join(''); if (!this.reserveLastWord) { return cutted; } var boundary = astralSafeCharacterArray.slice(len - 1, len + 1).join(''); // if truncate at word boundary, just return if (/\W/.test(boundary)) { return cutted; } if (this.reserveLastWord < 0) { var result = cutted.replace(/\w+$/, ''); // if the cutted is not the first and the only word // then return result, or return the whole word if (!(result.length === 0 && cutted.length === this.options.length)) { return result; } } // set max exceeded to 10 if this.reserveLastWord is true or > 0 var maxExceeded = this.reserveLastWord !== true && this.reserveLastWord > 0 ? this.reserveLastWord : 10; var mtc = astralSafeCharacterArray.slice(len).join('').match(/(\w+)/); var exceeded = mtc ? mtc[1] : ''; return cutted + exceeded.substr(0, maxExceeded); }
[ "function", "substr", "(", "astralSafeCharacterArray", ",", "len", ")", "{", "var", "cutted", "=", "astralSafeCharacterArray", ".", "slice", "(", "0", ",", "len", ")", ".", "join", "(", "''", ")", ";", "if", "(", "!", "this", ".", "reserveLastWord", ")", "{", "return", "cutted", ";", "}", "var", "boundary", "=", "astralSafeCharacterArray", ".", "slice", "(", "len", "-", "1", ",", "len", "+", "1", ")", ".", "join", "(", "''", ")", ";", "if", "(", "/", "\\W", "/", ".", "test", "(", "boundary", ")", ")", "{", "return", "cutted", ";", "}", "if", "(", "this", ".", "reserveLastWord", "<", "0", ")", "{", "var", "result", "=", "cutted", ".", "replace", "(", "/", "\\w+$", "/", ",", "''", ")", ";", "if", "(", "!", "(", "result", ".", "length", "===", "0", "&&", "cutted", ".", "length", "===", "this", ".", "options", ".", "length", ")", ")", "{", "return", "result", ";", "}", "}", "var", "maxExceeded", "=", "this", ".", "reserveLastWord", "!==", "true", "&&", "this", ".", "reserveLastWord", ">", "0", "?", "this", ".", "reserveLastWord", ":", "10", ";", "var", "mtc", "=", "astralSafeCharacterArray", ".", "slice", "(", "len", ")", ".", "join", "(", "''", ")", ".", "match", "(", "/", "(\\w+)", "/", ")", ";", "var", "exceeded", "=", "mtc", "?", "mtc", "[", "1", "]", ":", "''", ";", "return", "cutted", "+", "exceeded", ".", "substr", "(", "0", ",", "maxExceeded", ")", ";", "}" ]
deal with cut string in the middle of a word
[ "deal", "with", "cut", "string", "in", "the", "middle", "of", "a", "word" ]
31bac538894b14db0b68488b9f62d898dd03652b
https://github.com/oe/truncate-html/blob/31bac538894b14db0b68488b9f62d898dd03652b/dist/truncate.es.js#L147-L173
train
oe/truncate-html
dist/truncate.es.js
isCheerioInstance
function isCheerioInstance(elem) { return elem && elem.contains && elem.html && elem.parseHTML && true; }
javascript
function isCheerioInstance(elem) { return elem && elem.contains && elem.html && elem.parseHTML && true; }
[ "function", "isCheerioInstance", "(", "elem", ")", "{", "return", "elem", "&&", "elem", ".", "contains", "&&", "elem", ".", "html", "&&", "elem", ".", "parseHTML", "&&", "true", ";", "}" ]
return true if elem is CheerioStatic
[ "return", "true", "if", "elem", "is", "CheerioStatic" ]
31bac538894b14db0b68488b9f62d898dd03652b
https://github.com/oe/truncate-html/blob/31bac538894b14db0b68488b9f62d898dd03652b/dist/truncate.es.js#L176-L181
train
iVis-at-Bilkent/cytoscape.js-autopan-on-drag
cytoscape-autopan-on-drag.js
getScratch
function getScratch (eleOrCy, name) { if (eleOrCy.scratch("_autopanOnDrag") === undefined) { eleOrCy.scratch("_autopanOnDrag", {}); } var scratchPad = eleOrCy.scratch("_autopanOnDrag"); return ( name === undefined ) ? scratchPad : scratchPad[name]; }
javascript
function getScratch (eleOrCy, name) { if (eleOrCy.scratch("_autopanOnDrag") === undefined) { eleOrCy.scratch("_autopanOnDrag", {}); } var scratchPad = eleOrCy.scratch("_autopanOnDrag"); return ( name === undefined ) ? scratchPad : scratchPad[name]; }
[ "function", "getScratch", "(", "eleOrCy", ",", "name", ")", "{", "if", "(", "eleOrCy", ".", "scratch", "(", "\"_autopanOnDrag\"", ")", "===", "undefined", ")", "{", "eleOrCy", ".", "scratch", "(", "\"_autopanOnDrag\"", ",", "{", "}", ")", ";", "}", "var", "scratchPad", "=", "eleOrCy", ".", "scratch", "(", "\"_autopanOnDrag\"", ")", ";", "return", "(", "name", "===", "undefined", ")", "?", "scratchPad", ":", "scratchPad", "[", "name", "]", ";", "}" ]
Get scratch pad reserved for this extension on the given element or the core if 'name' parameter is not set, if the 'name' parameter is set then return the related property in the scratch instead of the whole scratchpad
[ "Get", "scratch", "pad", "reserved", "for", "this", "extension", "on", "the", "given", "element", "or", "the", "core", "if", "name", "parameter", "is", "not", "set", "if", "the", "name", "parameter", "is", "set", "then", "return", "the", "related", "property", "in", "the", "scratch", "instead", "of", "the", "whole", "scratchpad" ]
0928cce76f187fa9c45b0163f99156e45d5457a8
https://github.com/iVis-at-Bilkent/cytoscape.js-autopan-on-drag/blob/0928cce76f187fa9c45b0163f99156e45d5457a8/cytoscape-autopan-on-drag.js#L32-L41
train
generate/generate-mocha
generator.js
filter
function filter(name, options) { return utils.through.obj(function(file, enc, next) { if (file.isNull()) { next(); return; } var basename = path.basename(file.history[0]); var stem = basename.slice(0, -3); if (basename === name || stem === name) { next(null, file); } else { next(); } }); }
javascript
function filter(name, options) { return utils.through.obj(function(file, enc, next) { if (file.isNull()) { next(); return; } var basename = path.basename(file.history[0]); var stem = basename.slice(0, -3); if (basename === name || stem === name) { next(null, file); } else { next(); } }); }
[ "function", "filter", "(", "name", ",", "options", ")", "{", "return", "utils", ".", "through", ".", "obj", "(", "function", "(", "file", ",", "enc", ",", "next", ")", "{", "if", "(", "file", ".", "isNull", "(", ")", ")", "{", "next", "(", ")", ";", "return", ";", "}", "var", "basename", "=", "path", ".", "basename", "(", "file", ".", "history", "[", "0", "]", ")", ";", "var", "stem", "=", "basename", ".", "slice", "(", "0", ",", "-", "3", ")", ";", "if", "(", "basename", "===", "name", "||", "stem", "===", "name", ")", "{", "next", "(", "null", ",", "file", ")", ";", "}", "else", "{", "next", "(", ")", ";", "}", "}", ")", ";", "}" ]
Filter files to be rendered
[ "Filter", "files", "to", "be", "rendered" ]
269dd1451f4c651e530ae9a47ffdffcd85a45128
https://github.com/generate/generate-mocha/blob/269dd1451f4c651e530ae9a47ffdffcd85a45128/generator.js#L270-L286
train
linnovate/mean-cli
lib/scaffold.js
write
function write(path, str) { fs.writeFile(path, str); console.log(chalk.cyan(' create:'), path); }
javascript
function write(path, str) { fs.writeFile(path, str); console.log(chalk.cyan(' create:'), path); }
[ "function", "write", "(", "path", ",", "str", ")", "{", "fs", ".", "writeFile", "(", "path", ",", "str", ")", ";", "console", ".", "log", "(", "chalk", ".", "cyan", "(", "' create:'", ")", ",", "path", ")", ";", "}" ]
echo str > path. @param {String} path @param {String} str
[ "echo", "str", ">", "path", "." ]
480e0228740e85abf466a9d85e691c299dddec44
https://github.com/linnovate/mean-cli/blob/480e0228740e85abf466a9d85e691c299dddec44/lib/scaffold.js#L35-L38
train
linnovate/mean-cli
lib/scaffold.js
readTemplate
function readTemplate(path) { var template = fs.readFileSync(__dirname + '/templates/' + path, 'utf8'); for (var index in data) { template = template.split('__' + index + '__').join(data[index]); } return template; }
javascript
function readTemplate(path) { var template = fs.readFileSync(__dirname + '/templates/' + path, 'utf8'); for (var index in data) { template = template.split('__' + index + '__').join(data[index]); } return template; }
[ "function", "readTemplate", "(", "path", ")", "{", "var", "template", "=", "fs", ".", "readFileSync", "(", "__dirname", "+", "'/templates/'", "+", "path", ",", "'utf8'", ")", ";", "for", "(", "var", "index", "in", "data", ")", "{", "template", "=", "template", ".", "split", "(", "'__'", "+", "index", "+", "'__'", ")", ".", "join", "(", "data", "[", "index", "]", ")", ";", "}", "return", "template", ";", "}" ]
Read template files @param {String} path
[ "Read", "template", "files" ]
480e0228740e85abf466a9d85e691c299dddec44
https://github.com/linnovate/mean-cli/blob/480e0228740e85abf466a9d85e691c299dddec44/lib/scaffold.js#L45-L51
train
linnovate/mean-cli
lib/scaffold.js
mkdir
function mkdir(path, fn) { shell.mkdir('-p', path); shell.chmod(755, path); console.log(chalk.cyan(' create:'), path); if (fn) fn(); }
javascript
function mkdir(path, fn) { shell.mkdir('-p', path); shell.chmod(755, path); console.log(chalk.cyan(' create:'), path); if (fn) fn(); }
[ "function", "mkdir", "(", "path", ",", "fn", ")", "{", "shell", ".", "mkdir", "(", "'-p'", ",", "path", ")", ";", "shell", ".", "chmod", "(", "755", ",", "path", ")", ";", "console", ".", "log", "(", "chalk", ".", "cyan", "(", "' create:'", ")", ",", "path", ")", ";", "if", "(", "fn", ")", "fn", "(", ")", ";", "}" ]
Mkdir -p. @param {String} path @param {Function} fn
[ "Mkdir", "-", "p", "." ]
480e0228740e85abf466a9d85e691c299dddec44
https://github.com/linnovate/mean-cli/blob/480e0228740e85abf466a9d85e691c299dddec44/lib/scaffold.js#L59-L64
train
cam-inc/riotx
index.js
function (store, evtName, handler) { var args = [], len = arguments.length - 3; while ( len-- > 0 ) args[ len ] = arguments[ len + 3 ]; this._riotx_change_handlers.push({ store: store, evtName: evtName, handler: handler }); args.unshift(handler); args.unshift(evtName); store.change.apply(store, args); }
javascript
function (store, evtName, handler) { var args = [], len = arguments.length - 3; while ( len-- > 0 ) args[ len ] = arguments[ len + 3 ]; this._riotx_change_handlers.push({ store: store, evtName: evtName, handler: handler }); args.unshift(handler); args.unshift(evtName); store.change.apply(store, args); }
[ "function", "(", "store", ",", "evtName", ",", "handler", ")", "{", "var", "args", "=", "[", "]", ",", "len", "=", "arguments", ".", "length", "-", "3", ";", "while", "(", "len", "--", ">", "0", ")", "args", "[", "len", "]", "=", "arguments", "[", "len", "+", "3", "]", ";", "this", ".", "_riotx_change_handlers", ".", "push", "(", "{", "store", ":", "store", ",", "evtName", ":", "evtName", ",", "handler", ":", "handler", "}", ")", ";", "args", ".", "unshift", "(", "handler", ")", ";", "args", ".", "unshift", "(", "evtName", ")", ";", "store", ".", "change", ".", "apply", "(", "store", ",", "args", ")", ";", "}" ]
add and keep event listener for store changes. through this function the event listeners will be unbinded automatically.
[ "add", "and", "keep", "event", "listener", "for", "store", "changes", ".", "through", "this", "function", "the", "event", "listeners", "will", "be", "unbinded", "automatically", "." ]
8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4
https://github.com/cam-inc/riotx/blob/8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4/index.js#L692-L704
train
cam-inc/riotx
index.js
function () { var this$1 = this; // the context of `this` will be equal to riot tag instant. this.on('unmount', function () { this$1.off('*'); forEach_1(this$1._riotx_change_handlers, function (obj) { obj.store.off(obj.evtName, obj.handler); }); delete this$1.riotx; delete this$1._riotx_change_handlers; delete this$1[settings.changeBindName]; }); if (settings.debug) { this.on('*', function (eventName) { debug('[riot.mixin]', eventName, this$1); }); } this._riotx_change_handlers = []; // let users set the name. this[settings.changeBindName] = riotxChange; }
javascript
function () { var this$1 = this; // the context of `this` will be equal to riot tag instant. this.on('unmount', function () { this$1.off('*'); forEach_1(this$1._riotx_change_handlers, function (obj) { obj.store.off(obj.evtName, obj.handler); }); delete this$1.riotx; delete this$1._riotx_change_handlers; delete this$1[settings.changeBindName]; }); if (settings.debug) { this.on('*', function (eventName) { debug('[riot.mixin]', eventName, this$1); }); } this._riotx_change_handlers = []; // let users set the name. this[settings.changeBindName] = riotxChange; }
[ "function", "(", ")", "{", "var", "this$1", "=", "this", ";", "this", ".", "on", "(", "'unmount'", ",", "function", "(", ")", "{", "this$1", ".", "off", "(", "'*'", ")", ";", "forEach_1", "(", "this$1", ".", "_riotx_change_handlers", ",", "function", "(", "obj", ")", "{", "obj", ".", "store", ".", "off", "(", "obj", ".", "evtName", ",", "obj", ".", "handler", ")", ";", "}", ")", ";", "delete", "this$1", ".", "riotx", ";", "delete", "this$1", ".", "_riotx_change_handlers", ";", "delete", "this$1", "[", "settings", ".", "changeBindName", "]", ";", "}", ")", ";", "if", "(", "settings", ".", "debug", ")", "{", "this", ".", "on", "(", "'*'", ",", "function", "(", "eventName", ")", "{", "debug", "(", "'[riot.mixin]'", ",", "eventName", ",", "this$1", ")", ";", "}", ")", ";", "}", "this", ".", "_riotx_change_handlers", "=", "[", "]", ";", "this", "[", "settings", ".", "changeBindName", "]", "=", "riotxChange", ";", "}" ]
intendedly use `function`. switch the context of `this` from `riotx` to `riot tag instance`.
[ "intendedly", "use", "function", ".", "switch", "the", "context", "of", "this", "from", "riotx", "to", "riot", "tag", "instance", "." ]
8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4
https://github.com/cam-inc/riotx/blob/8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4/index.js#L710-L734
train
kawanet/from-xml
bin/xml2json.cli.js
readFromStream
function readFromStream(stream, callback) { var buf = []; stream.on("data", onData); stream.on("end", onEnd); stream.on("error", onError); function onData(data) { buf.push(data); } function onEnd() { if (callback) callback(null, buf.join("")); callback = null; } function onError(err) { if (callback) callback(err); callback = null; } }
javascript
function readFromStream(stream, callback) { var buf = []; stream.on("data", onData); stream.on("end", onEnd); stream.on("error", onError); function onData(data) { buf.push(data); } function onEnd() { if (callback) callback(null, buf.join("")); callback = null; } function onError(err) { if (callback) callback(err); callback = null; } }
[ "function", "readFromStream", "(", "stream", ",", "callback", ")", "{", "var", "buf", "=", "[", "]", ";", "stream", ".", "on", "(", "\"data\"", ",", "onData", ")", ";", "stream", ".", "on", "(", "\"end\"", ",", "onEnd", ")", ";", "stream", ".", "on", "(", "\"error\"", ",", "onError", ")", ";", "function", "onData", "(", "data", ")", "{", "buf", ".", "push", "(", "data", ")", ";", "}", "function", "onEnd", "(", ")", "{", "if", "(", "callback", ")", "callback", "(", "null", ",", "buf", ".", "join", "(", "\"\"", ")", ")", ";", "callback", "=", "null", ";", "}", "function", "onError", "(", "err", ")", "{", "if", "(", "callback", ")", "callback", "(", "err", ")", ";", "callback", "=", "null", ";", "}", "}" ]
Read all data from stream @param stream {Stream} @param callback {Function} function(err, str) {...} @license MIT @see https://gist.github.com/kawanet/c6c998b00500fe05eb8dfd0ee80deacf
[ "Read", "all", "data", "from", "stream" ]
340eb403c530d52196aacc3c569ba78943a17ef2
https://github.com/kawanet/from-xml/blob/340eb403c530d52196aacc3c569ba78943a17ef2/bin/xml2json.cli.js#L45-L64
train
wkallhof/Hazel
app/themes/default/public/scripts/edit.js
function($scope) { this.$scope = $scope; this.$markdownInput = $scope.find(SELECTORS.MARKDOWN_INPUT); this.$form = $scope.find(SELECTORS.FORM); this.$titleInput = $scope.find(SELECTORS.TITLE_INPUT); this.$deleteButton = $scope.find(SELECTORS.DELETE); this.dropzone = new Dropzone(SELECTORS.DROPZONE); this.simplemde = new SimpleMDE(); this.bind(); }
javascript
function($scope) { this.$scope = $scope; this.$markdownInput = $scope.find(SELECTORS.MARKDOWN_INPUT); this.$form = $scope.find(SELECTORS.FORM); this.$titleInput = $scope.find(SELECTORS.TITLE_INPUT); this.$deleteButton = $scope.find(SELECTORS.DELETE); this.dropzone = new Dropzone(SELECTORS.DROPZONE); this.simplemde = new SimpleMDE(); this.bind(); }
[ "function", "(", "$scope", ")", "{", "this", ".", "$scope", "=", "$scope", ";", "this", ".", "$markdownInput", "=", "$scope", ".", "find", "(", "SELECTORS", ".", "MARKDOWN_INPUT", ")", ";", "this", ".", "$form", "=", "$scope", ".", "find", "(", "SELECTORS", ".", "FORM", ")", ";", "this", ".", "$titleInput", "=", "$scope", ".", "find", "(", "SELECTORS", ".", "TITLE_INPUT", ")", ";", "this", ".", "$deleteButton", "=", "$scope", ".", "find", "(", "SELECTORS", ".", "DELETE", ")", ";", "this", ".", "dropzone", "=", "new", "Dropzone", "(", "SELECTORS", ".", "DROPZONE", ")", ";", "this", ".", "simplemde", "=", "new", "SimpleMDE", "(", ")", ";", "this", ".", "bind", "(", ")", ";", "}" ]
Page View Class for the Document Edit page.
[ "Page", "View", "Class", "for", "the", "Document", "Edit", "page", "." ]
a4b4ebc3f513fe3d6107652e50ede955134cc961
https://github.com/wkallhof/Hazel/blob/a4b4ebc3f513fe3d6107652e50ede955134cc961/app/themes/default/public/scripts/edit.js#L12-L24
train
wkallhof/Hazel
app/themes/default/public/scripts/edit.js
function (file, responseText) { console.log(responseText); // console should show the ID you pointed to // read the upload path from the elements data-upload attribute. var uploadPath = $(this.dropzone.element).data("upload") + responseText; var linkToUploadedFile = "(" + uploadPath + ")"; if ( file.type.startsWith( "image/" ) ) { linkToUploadedFile = "![]" + linkToUploadedFile; } else { linkToUploadedFile = "[" + responseText + "]" + linkToUploadedFile; } this.simplemde.value(this.simplemde.value() + "\n" + linkToUploadedFile + "\n"); }
javascript
function (file, responseText) { console.log(responseText); // console should show the ID you pointed to // read the upload path from the elements data-upload attribute. var uploadPath = $(this.dropzone.element).data("upload") + responseText; var linkToUploadedFile = "(" + uploadPath + ")"; if ( file.type.startsWith( "image/" ) ) { linkToUploadedFile = "![]" + linkToUploadedFile; } else { linkToUploadedFile = "[" + responseText + "]" + linkToUploadedFile; } this.simplemde.value(this.simplemde.value() + "\n" + linkToUploadedFile + "\n"); }
[ "function", "(", "file", ",", "responseText", ")", "{", "console", ".", "log", "(", "responseText", ")", ";", "var", "uploadPath", "=", "$", "(", "this", ".", "dropzone", ".", "element", ")", ".", "data", "(", "\"upload\"", ")", "+", "responseText", ";", "var", "linkToUploadedFile", "=", "\"(\"", "+", "uploadPath", "+", "\")\"", ";", "if", "(", "file", ".", "type", ".", "startsWith", "(", "\"image/\"", ")", ")", "{", "linkToUploadedFile", "=", "\"![]\"", "+", "linkToUploadedFile", ";", "}", "else", "{", "linkToUploadedFile", "=", "\"[\"", "+", "responseText", "+", "\"]\"", "+", "linkToUploadedFile", ";", "}", "this", ".", "simplemde", ".", "value", "(", "this", ".", "simplemde", ".", "value", "(", ")", "+", "\"\\n\"", "+", "\\n", "+", "linkToUploadedFile", ")", ";", "}" ]
Handle the event when the user successfully uploads a file via Dropzone @prop file [string] @prop responseText [string]
[ "Handle", "the", "event", "when", "the", "user", "successfully", "uploads", "a", "file", "via", "Dropzone" ]
a4b4ebc3f513fe3d6107652e50ede955134cc961
https://github.com/wkallhof/Hazel/blob/a4b4ebc3f513fe3d6107652e50ede955134cc961/app/themes/default/public/scripts/edit.js#L38-L49
train
cam-inc/riotx
dist/amd.riotx+riot.js
add
function add(css, name) { if (name) { byName[name] = css; } else { remainder.push(css); } needsInject = true; }
javascript
function add(css, name) { if (name) { byName[name] = css; } else { remainder.push(css); } needsInject = true; }
[ "function", "add", "(", "css", ",", "name", ")", "{", "if", "(", "name", ")", "{", "byName", "[", "name", "]", "=", "css", ";", "}", "else", "{", "remainder", ".", "push", "(", "css", ")", ";", "}", "needsInject", "=", "true", ";", "}" ]
Save a tag style to be later injected into DOM @param { String } css - css string @param { String } name - if it's passed we will map the css to a tagname
[ "Save", "a", "tag", "style", "to", "be", "later", "injected", "into", "DOM" ]
8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4
https://github.com/cam-inc/riotx/blob/8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4/dist/amd.riotx+riot.js#L535-L539
train
cam-inc/riotx
dist/amd.riotx+riot.js
styleObjectToString
function styleObjectToString(style) { return Object.keys(style).reduce(function (acc, prop) { return (acc + " " + prop + ": " + (style[prop]) + ";") }, '') }
javascript
function styleObjectToString(style) { return Object.keys(style).reduce(function (acc, prop) { return (acc + " " + prop + ": " + (style[prop]) + ";") }, '') }
[ "function", "styleObjectToString", "(", "style", ")", "{", "return", "Object", ".", "keys", "(", "style", ")", ".", "reduce", "(", "function", "(", "acc", ",", "prop", ")", "{", "return", "(", "acc", "+", "\" \"", "+", "prop", "+", "\": \"", "+", "(", "style", "[", "prop", "]", ")", "+", "\";\"", ")", "}", ",", "''", ")", "}" ]
Convert a style object to a string @param { Object } style - style object we need to parse @returns { String } resulting css string @example styleObjectToString({ color: 'red', height: '10px'}) // => 'color: red; height: 10px'
[ "Convert", "a", "style", "object", "to", "a", "string" ]
8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4
https://github.com/cam-inc/riotx/blob/8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4/dist/amd.riotx+riot.js#L1393-L1397
train
cam-inc/riotx
dist/amd.riotx+riot.js
arrayishAdd
function arrayishAdd(obj, key, value, ensureArray, index) { var dest = obj[key]; var isArr = isArray(dest); var hasIndex = !isUndefined(index); if (dest && dest === value) { return } // if the key was never set, set it once if (!dest && ensureArray) { obj[key] = [value]; } else if (!dest) { obj[key] = value; } // if it was an array and not yet set else { if (isArr) { var oldIndex = dest.indexOf(value); // this item never changed its position if (oldIndex === index) { return } // remove the item from its old position if (oldIndex !== -1) { dest.splice(oldIndex, 1); } // move or add the item if (hasIndex) { dest.splice(index, 0, value); } else { dest.push(value); } } else { obj[key] = [dest, value]; } } }
javascript
function arrayishAdd(obj, key, value, ensureArray, index) { var dest = obj[key]; var isArr = isArray(dest); var hasIndex = !isUndefined(index); if (dest && dest === value) { return } // if the key was never set, set it once if (!dest && ensureArray) { obj[key] = [value]; } else if (!dest) { obj[key] = value; } // if it was an array and not yet set else { if (isArr) { var oldIndex = dest.indexOf(value); // this item never changed its position if (oldIndex === index) { return } // remove the item from its old position if (oldIndex !== -1) { dest.splice(oldIndex, 1); } // move or add the item if (hasIndex) { dest.splice(index, 0, value); } else { dest.push(value); } } else { obj[key] = [dest, value]; } } }
[ "function", "arrayishAdd", "(", "obj", ",", "key", ",", "value", ",", "ensureArray", ",", "index", ")", "{", "var", "dest", "=", "obj", "[", "key", "]", ";", "var", "isArr", "=", "isArray", "(", "dest", ")", ";", "var", "hasIndex", "=", "!", "isUndefined", "(", "index", ")", ";", "if", "(", "dest", "&&", "dest", "===", "value", ")", "{", "return", "}", "if", "(", "!", "dest", "&&", "ensureArray", ")", "{", "obj", "[", "key", "]", "=", "[", "value", "]", ";", "}", "else", "if", "(", "!", "dest", ")", "{", "obj", "[", "key", "]", "=", "value", ";", "}", "else", "{", "if", "(", "isArr", ")", "{", "var", "oldIndex", "=", "dest", ".", "indexOf", "(", "value", ")", ";", "if", "(", "oldIndex", "===", "index", ")", "{", "return", "}", "if", "(", "oldIndex", "!==", "-", "1", ")", "{", "dest", ".", "splice", "(", "oldIndex", ",", "1", ")", ";", "}", "if", "(", "hasIndex", ")", "{", "dest", ".", "splice", "(", "index", ",", "0", ",", "value", ")", ";", "}", "else", "{", "dest", ".", "push", "(", "value", ")", ";", "}", "}", "else", "{", "obj", "[", "key", "]", "=", "[", "dest", ",", "value", "]", ";", "}", "}", "}" ]
Set the property of an object for a given key. If something already exists there, then it becomes an array containing both the old and new value. @param { Object } obj - object on which to set the property @param { String } key - property name @param { Object } value - the value of the property to be set @param { Boolean } ensureArray - ensure that the property remains an array @param { Number } index - add the new item in a certain array position
[ "Set", "the", "property", "of", "an", "object", "for", "a", "given", "key", ".", "If", "something", "already", "exists", "there", "then", "it", "becomes", "an", "array", "containing", "both", "the", "old", "and", "new", "value", "." ]
8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4
https://github.com/cam-inc/riotx/blob/8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4/dist/amd.riotx+riot.js#L1631-L1657
train
cam-inc/riotx
dist/amd.riotx+riot.js
arrayishRemove
function arrayishRemove(obj, key, value, ensureArray) { if (isArray(obj[key])) { var index = obj[key].indexOf(value); if (index !== -1) { obj[key].splice(index, 1); } if (!obj[key].length) { delete obj[key]; } else if (obj[key].length === 1 && !ensureArray) { obj[key] = obj[key][0]; } } else if (obj[key] === value) { delete obj[key]; } // otherwise just delete the key }
javascript
function arrayishRemove(obj, key, value, ensureArray) { if (isArray(obj[key])) { var index = obj[key].indexOf(value); if (index !== -1) { obj[key].splice(index, 1); } if (!obj[key].length) { delete obj[key]; } else if (obj[key].length === 1 && !ensureArray) { obj[key] = obj[key][0]; } } else if (obj[key] === value) { delete obj[key]; } // otherwise just delete the key }
[ "function", "arrayishRemove", "(", "obj", ",", "key", ",", "value", ",", "ensureArray", ")", "{", "if", "(", "isArray", "(", "obj", "[", "key", "]", ")", ")", "{", "var", "index", "=", "obj", "[", "key", "]", ".", "indexOf", "(", "value", ")", ";", "if", "(", "index", "!==", "-", "1", ")", "{", "obj", "[", "key", "]", ".", "splice", "(", "index", ",", "1", ")", ";", "}", "if", "(", "!", "obj", "[", "key", "]", ".", "length", ")", "{", "delete", "obj", "[", "key", "]", ";", "}", "else", "if", "(", "obj", "[", "key", "]", ".", "length", "===", "1", "&&", "!", "ensureArray", ")", "{", "obj", "[", "key", "]", "=", "obj", "[", "key", "]", "[", "0", "]", ";", "}", "}", "else", "if", "(", "obj", "[", "key", "]", "===", "value", ")", "{", "delete", "obj", "[", "key", "]", ";", "}", "}" ]
Removes an item from an object at a given key. If the key points to an array, then the item is just removed from the array. @param { Object } obj - object on which to remove the property @param { String } key - property name @param { Object } value - the value of the property to be removed @param { Boolean } ensureArray - ensure that the property remains an array
[ "Removes", "an", "item", "from", "an", "object", "at", "a", "given", "key", ".", "If", "the", "key", "points", "to", "an", "array", "then", "the", "item", "is", "just", "removed", "from", "the", "array", "." ]
8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4
https://github.com/cam-inc/riotx/blob/8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4/dist/amd.riotx+riot.js#L1905-L1913
train
cam-inc/riotx
dist/amd.riotx+riot.js
makeReplaceVirtual
function makeReplaceVirtual(tag, ref) { var frag = createFragment(); makeVirtual.call(tag, frag); ref.parentNode.replaceChild(frag, ref); }
javascript
function makeReplaceVirtual(tag, ref) { var frag = createFragment(); makeVirtual.call(tag, frag); ref.parentNode.replaceChild(frag, ref); }
[ "function", "makeReplaceVirtual", "(", "tag", ",", "ref", ")", "{", "var", "frag", "=", "createFragment", "(", ")", ";", "makeVirtual", ".", "call", "(", "tag", ",", "frag", ")", ";", "ref", ".", "parentNode", ".", "replaceChild", "(", "frag", ",", "ref", ")", ";", "}" ]
makes a tag virtual and replaces a reference in the dom @this Tag @param { tag } the tag to make virtual @param { ref } the dom reference location
[ "makes", "a", "tag", "virtual", "and", "replaces", "a", "reference", "in", "the", "dom" ]
8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4
https://github.com/cam-inc/riotx/blob/8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4/dist/amd.riotx+riot.js#L1955-L1959
train
cam-inc/riotx
dist/amd.riotx+riot.js
normalizeAttrName
function normalizeAttrName(attrName) { if (!attrName) { return null } attrName = attrName.replace(ATTRS_PREFIX, ''); if (CASE_SENSITIVE_ATTRIBUTES[attrName]) { attrName = CASE_SENSITIVE_ATTRIBUTES[attrName]; } return attrName }
javascript
function normalizeAttrName(attrName) { if (!attrName) { return null } attrName = attrName.replace(ATTRS_PREFIX, ''); if (CASE_SENSITIVE_ATTRIBUTES[attrName]) { attrName = CASE_SENSITIVE_ATTRIBUTES[attrName]; } return attrName }
[ "function", "normalizeAttrName", "(", "attrName", ")", "{", "if", "(", "!", "attrName", ")", "{", "return", "null", "}", "attrName", "=", "attrName", ".", "replace", "(", "ATTRS_PREFIX", ",", "''", ")", ";", "if", "(", "CASE_SENSITIVE_ATTRIBUTES", "[", "attrName", "]", ")", "{", "attrName", "=", "CASE_SENSITIVE_ATTRIBUTES", "[", "attrName", "]", ";", "}", "return", "attrName", "}" ]
Nomalize any attribute removing the "riot-" prefix @param { String } attrName - original attribute name @returns { String } valid html attribute name
[ "Nomalize", "any", "attribute", "removing", "the", "riot", "-", "prefix" ]
8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4
https://github.com/cam-inc/riotx/blob/8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4/dist/amd.riotx+riot.js#L2030-L2035
train
cam-inc/riotx
dist/amd.riotx+riot.js
updateOpts
function updateOpts(isLoop, parent, isAnonymous, opts, instAttrs) { // isAnonymous `each` tags treat `dom` and `root` differently. In this case // (and only this case) we don't need to do updateOpts, because the regular parse // will update those attrs. Plus, isAnonymous tags don't need opts anyway if (isLoop && isAnonymous) { return } var ctx = isLoop ? inheritParentProps.call(this) : parent || this; each(instAttrs, function (attr) { if (attr.expr) { updateExpression.call(ctx, attr.expr); } // normalize the attribute names opts[toCamel(attr.name).replace(ATTRS_PREFIX, '')] = attr.expr ? attr.expr.value : attr.value; }); }
javascript
function updateOpts(isLoop, parent, isAnonymous, opts, instAttrs) { // isAnonymous `each` tags treat `dom` and `root` differently. In this case // (and only this case) we don't need to do updateOpts, because the regular parse // will update those attrs. Plus, isAnonymous tags don't need opts anyway if (isLoop && isAnonymous) { return } var ctx = isLoop ? inheritParentProps.call(this) : parent || this; each(instAttrs, function (attr) { if (attr.expr) { updateExpression.call(ctx, attr.expr); } // normalize the attribute names opts[toCamel(attr.name).replace(ATTRS_PREFIX, '')] = attr.expr ? attr.expr.value : attr.value; }); }
[ "function", "updateOpts", "(", "isLoop", ",", "parent", ",", "isAnonymous", ",", "opts", ",", "instAttrs", ")", "{", "if", "(", "isLoop", "&&", "isAnonymous", ")", "{", "return", "}", "var", "ctx", "=", "isLoop", "?", "inheritParentProps", ".", "call", "(", "this", ")", ":", "parent", "||", "this", ";", "each", "(", "instAttrs", ",", "function", "(", "attr", ")", "{", "if", "(", "attr", ".", "expr", ")", "{", "updateExpression", ".", "call", "(", "ctx", ",", "attr", ".", "expr", ")", ";", "}", "opts", "[", "toCamel", "(", "attr", ".", "name", ")", ".", "replace", "(", "ATTRS_PREFIX", ",", "''", ")", "]", "=", "attr", ".", "expr", "?", "attr", ".", "expr", ".", "value", ":", "attr", ".", "value", ";", "}", ")", ";", "}" ]
We need to update opts for this tag. That requires updating the expressions in any attributes on the tag, and then copying the result onto opts. @this Tag @param {Boolean} isLoop - is it a loop tag? @param { Tag } parent - parent tag node @param { Boolean } isAnonymous - is it a tag without any impl? (a tag not registered) @param { Object } opts - tag options @param { Array } instAttrs - tag attributes array
[ "We", "need", "to", "update", "opts", "for", "this", "tag", ".", "That", "requires", "updating", "the", "expressions", "in", "any", "attributes", "on", "the", "tag", "and", "then", "copying", "the", "result", "onto", "opts", "." ]
8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4
https://github.com/cam-inc/riotx/blob/8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4/dist/amd.riotx+riot.js#L2178-L2190
train
cam-inc/riotx
dist/amd.riotx+riot.js
componentUpdate
function componentUpdate(tag, data, expressions) { var __ = tag.__; var nextOpts = {}; var canTrigger = tag.isMounted && !__.skipAnonymous; // inherit properties from the parent tag if (__.isAnonymous && __.parent) { extend(tag, __.parent); } extend(tag, data); updateOpts.apply(tag, [__.isLoop, __.parent, __.isAnonymous, nextOpts, __.instAttrs]); if ( canTrigger && tag.isMounted && isFunction$1(tag.shouldUpdate) && !tag.shouldUpdate(data, nextOpts) ) { return tag } extend(tag.opts, nextOpts); if (canTrigger) { tag.trigger('update', data); } update.call(tag, expressions); if (canTrigger) { tag.trigger('updated'); } return tag }
javascript
function componentUpdate(tag, data, expressions) { var __ = tag.__; var nextOpts = {}; var canTrigger = tag.isMounted && !__.skipAnonymous; // inherit properties from the parent tag if (__.isAnonymous && __.parent) { extend(tag, __.parent); } extend(tag, data); updateOpts.apply(tag, [__.isLoop, __.parent, __.isAnonymous, nextOpts, __.instAttrs]); if ( canTrigger && tag.isMounted && isFunction$1(tag.shouldUpdate) && !tag.shouldUpdate(data, nextOpts) ) { return tag } extend(tag.opts, nextOpts); if (canTrigger) { tag.trigger('update', data); } update.call(tag, expressions); if (canTrigger) { tag.trigger('updated'); } return tag }
[ "function", "componentUpdate", "(", "tag", ",", "data", ",", "expressions", ")", "{", "var", "__", "=", "tag", ".", "__", ";", "var", "nextOpts", "=", "{", "}", ";", "var", "canTrigger", "=", "tag", ".", "isMounted", "&&", "!", "__", ".", "skipAnonymous", ";", "if", "(", "__", ".", "isAnonymous", "&&", "__", ".", "parent", ")", "{", "extend", "(", "tag", ",", "__", ".", "parent", ")", ";", "}", "extend", "(", "tag", ",", "data", ")", ";", "updateOpts", ".", "apply", "(", "tag", ",", "[", "__", ".", "isLoop", ",", "__", ".", "parent", ",", "__", ".", "isAnonymous", ",", "nextOpts", ",", "__", ".", "instAttrs", "]", ")", ";", "if", "(", "canTrigger", "&&", "tag", ".", "isMounted", "&&", "isFunction$1", "(", "tag", ".", "shouldUpdate", ")", "&&", "!", "tag", ".", "shouldUpdate", "(", "data", ",", "nextOpts", ")", ")", "{", "return", "tag", "}", "extend", "(", "tag", ".", "opts", ",", "nextOpts", ")", ";", "if", "(", "canTrigger", ")", "{", "tag", ".", "trigger", "(", "'update'", ",", "data", ")", ";", "}", "update", ".", "call", "(", "tag", ",", "expressions", ")", ";", "if", "(", "canTrigger", ")", "{", "tag", ".", "trigger", "(", "'updated'", ")", ";", "}", "return", "tag", "}" ]
Update the tag expressions and options @param { Tag } tag - tag object @param { * } data - data we want to use to extend the tag properties @param { Array } expressions - component expressions array @returns { Tag } the current tag instance
[ "Update", "the", "tag", "expressions", "and", "options" ]
8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4
https://github.com/cam-inc/riotx/blob/8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4/dist/amd.riotx+riot.js#L2199-L2225
train
cam-inc/riotx
dist/amd.riotx+riot.js
componentMixin
function componentMixin(tag$$1) { var mixins = [], len = arguments.length - 1; while ( len-- > 0 ) mixins[ len ] = arguments[ len + 1 ]; each(mixins, function (mix) { var instance; var obj; var props = []; // properties blacklisted and will not be bound to the tag instance var propsBlacklist = ['init', '__proto__']; mix = isString(mix) ? mixin(mix) : mix; // check if the mixin is a function if (isFunction$1(mix)) { // create the new mixin instance instance = new mix(); } else { instance = mix; } var proto = Object.getPrototypeOf(instance); // build multilevel prototype inheritance chain property list do { props = props.concat(Object.getOwnPropertyNames(obj || instance)); } while (obj = Object.getPrototypeOf(obj || instance)) // loop the keys in the function prototype or the all object keys each(props, function (key) { // bind methods to tag // allow mixins to override other properties/parent mixins if (!contains(propsBlacklist, key)) { // check for getters/setters var descriptor = getPropDescriptor(instance, key) || getPropDescriptor(proto, key); var hasGetterSetter = descriptor && (descriptor.get || descriptor.set); // apply method only if it does not already exist on the instance if (!tag$$1.hasOwnProperty(key) && hasGetterSetter) { Object.defineProperty(tag$$1, key, descriptor); } else { tag$$1[key] = isFunction$1(instance[key]) ? instance[key].bind(tag$$1) : instance[key]; } } }); // init method will be called automatically if (instance.init) { instance.init.bind(tag$$1)(tag$$1.opts); } }); return tag$$1 }
javascript
function componentMixin(tag$$1) { var mixins = [], len = arguments.length - 1; while ( len-- > 0 ) mixins[ len ] = arguments[ len + 1 ]; each(mixins, function (mix) { var instance; var obj; var props = []; // properties blacklisted and will not be bound to the tag instance var propsBlacklist = ['init', '__proto__']; mix = isString(mix) ? mixin(mix) : mix; // check if the mixin is a function if (isFunction$1(mix)) { // create the new mixin instance instance = new mix(); } else { instance = mix; } var proto = Object.getPrototypeOf(instance); // build multilevel prototype inheritance chain property list do { props = props.concat(Object.getOwnPropertyNames(obj || instance)); } while (obj = Object.getPrototypeOf(obj || instance)) // loop the keys in the function prototype or the all object keys each(props, function (key) { // bind methods to tag // allow mixins to override other properties/parent mixins if (!contains(propsBlacklist, key)) { // check for getters/setters var descriptor = getPropDescriptor(instance, key) || getPropDescriptor(proto, key); var hasGetterSetter = descriptor && (descriptor.get || descriptor.set); // apply method only if it does not already exist on the instance if (!tag$$1.hasOwnProperty(key) && hasGetterSetter) { Object.defineProperty(tag$$1, key, descriptor); } else { tag$$1[key] = isFunction$1(instance[key]) ? instance[key].bind(tag$$1) : instance[key]; } } }); // init method will be called automatically if (instance.init) { instance.init.bind(tag$$1)(tag$$1.opts); } }); return tag$$1 }
[ "function", "componentMixin", "(", "tag$$1", ")", "{", "var", "mixins", "=", "[", "]", ",", "len", "=", "arguments", ".", "length", "-", "1", ";", "while", "(", "len", "--", ">", "0", ")", "mixins", "[", "len", "]", "=", "arguments", "[", "len", "+", "1", "]", ";", "each", "(", "mixins", ",", "function", "(", "mix", ")", "{", "var", "instance", ";", "var", "obj", ";", "var", "props", "=", "[", "]", ";", "var", "propsBlacklist", "=", "[", "'init'", ",", "'__proto__'", "]", ";", "mix", "=", "isString", "(", "mix", ")", "?", "mixin", "(", "mix", ")", ":", "mix", ";", "if", "(", "isFunction$1", "(", "mix", ")", ")", "{", "instance", "=", "new", "mix", "(", ")", ";", "}", "else", "{", "instance", "=", "mix", ";", "}", "var", "proto", "=", "Object", ".", "getPrototypeOf", "(", "instance", ")", ";", "do", "{", "props", "=", "props", ".", "concat", "(", "Object", ".", "getOwnPropertyNames", "(", "obj", "||", "instance", ")", ")", ";", "}", "while", "(", "obj", "=", "Object", ".", "getPrototypeOf", "(", "obj", "||", "instance", ")", ")", "each", "(", "props", ",", "function", "(", "key", ")", "{", "if", "(", "!", "contains", "(", "propsBlacklist", ",", "key", ")", ")", "{", "var", "descriptor", "=", "getPropDescriptor", "(", "instance", ",", "key", ")", "||", "getPropDescriptor", "(", "proto", ",", "key", ")", ";", "var", "hasGetterSetter", "=", "descriptor", "&&", "(", "descriptor", ".", "get", "||", "descriptor", ".", "set", ")", ";", "if", "(", "!", "tag$$1", ".", "hasOwnProperty", "(", "key", ")", "&&", "hasGetterSetter", ")", "{", "Object", ".", "defineProperty", "(", "tag$$1", ",", "key", ",", "descriptor", ")", ";", "}", "else", "{", "tag$$1", "[", "key", "]", "=", "isFunction$1", "(", "instance", "[", "key", "]", ")", "?", "instance", "[", "key", "]", ".", "bind", "(", "tag$$1", ")", ":", "instance", "[", "key", "]", ";", "}", "}", "}", ")", ";", "if", "(", "instance", ".", "init", ")", "{", "instance", ".", "init", ".", "bind", "(", "tag$$1", ")", "(", "tag$$1", ".", "opts", ")", ";", "}", "}", ")", ";", "return", "tag$$1", "}" ]
Add a mixin to this tag @returns { Tag } the current tag instance
[ "Add", "a", "mixin", "to", "this", "tag" ]
8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4
https://github.com/cam-inc/riotx/blob/8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4/dist/amd.riotx+riot.js#L2468-L2520
train
cam-inc/riotx
dist/amd.riotx+riot.js
remove
function remove(tags, i) { tags.splice(i, 1); this.unmount(); arrayishRemove(this.parent, this, this.__.tagName, true); }
javascript
function remove(tags, i) { tags.splice(i, 1); this.unmount(); arrayishRemove(this.parent, this, this.__.tagName, true); }
[ "function", "remove", "(", "tags", ",", "i", ")", "{", "tags", ".", "splice", "(", "i", ",", "1", ")", ";", "this", ".", "unmount", "(", ")", ";", "arrayishRemove", "(", "this", ".", "parent", ",", "this", ",", "this", ".", "__", ".", "tagName", ",", "true", ")", ";", "}" ]
Remove a child tag @this Tag @param { Array } tags - tags collection @param { Number } i - index of the tag to remove
[ "Remove", "a", "child", "tag" ]
8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4
https://github.com/cam-inc/riotx/blob/8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4/dist/amd.riotx+riot.js#L2608-L2612
train
cam-inc/riotx
dist/amd.riotx+riot.js
move
function move(root, nextTag, isVirtual) { if (isVirtual) { moveVirtual.apply(this, [root, nextTag]); } else { safeInsert(root, this.root, nextTag.root); } }
javascript
function move(root, nextTag, isVirtual) { if (isVirtual) { moveVirtual.apply(this, [root, nextTag]); } else { safeInsert(root, this.root, nextTag.root); } }
[ "function", "move", "(", "root", ",", "nextTag", ",", "isVirtual", ")", "{", "if", "(", "isVirtual", ")", "{", "moveVirtual", ".", "apply", "(", "this", ",", "[", "root", ",", "nextTag", "]", ")", ";", "}", "else", "{", "safeInsert", "(", "root", ",", "this", ".", "root", ",", "nextTag", ".", "root", ")", ";", "}", "}" ]
Move a child tag @this Tag @param { HTMLElement } root - dom node containing all the loop children @param { Tag } nextTag - instance of the next tag preceding the one we want to move @param { Boolean } isVirtual - is it a virtual tag?
[ "Move", "a", "child", "tag" ]
8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4
https://github.com/cam-inc/riotx/blob/8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4/dist/amd.riotx+riot.js#L2634-L2639
train
cam-inc/riotx
dist/amd.riotx+riot.js
insert
function insert(root, nextTag, isVirtual) { if (isVirtual) { makeVirtual.apply(this, [root, nextTag]); } else { safeInsert(root, this.root, nextTag.root); } }
javascript
function insert(root, nextTag, isVirtual) { if (isVirtual) { makeVirtual.apply(this, [root, nextTag]); } else { safeInsert(root, this.root, nextTag.root); } }
[ "function", "insert", "(", "root", ",", "nextTag", ",", "isVirtual", ")", "{", "if", "(", "isVirtual", ")", "{", "makeVirtual", ".", "apply", "(", "this", ",", "[", "root", ",", "nextTag", "]", ")", ";", "}", "else", "{", "safeInsert", "(", "root", ",", "this", ".", "root", ",", "nextTag", ".", "root", ")", ";", "}", "}" ]
Insert and mount a child tag @this Tag @param { HTMLElement } root - dom node containing all the loop children @param { Tag } nextTag - instance of the next tag preceding the one we want to insert @param { Boolean } isVirtual - is it a virtual tag?
[ "Insert", "and", "mount", "a", "child", "tag" ]
8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4
https://github.com/cam-inc/riotx/blob/8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4/dist/amd.riotx+riot.js#L2648-L2653
train
cam-inc/riotx
dist/amd.riotx+riot.js
append
function append(root, isVirtual) { if (isVirtual) { makeVirtual.call(this, root); } else { root.appendChild(this.root); } }
javascript
function append(root, isVirtual) { if (isVirtual) { makeVirtual.call(this, root); } else { root.appendChild(this.root); } }
[ "function", "append", "(", "root", ",", "isVirtual", ")", "{", "if", "(", "isVirtual", ")", "{", "makeVirtual", ".", "call", "(", "this", ",", "root", ")", ";", "}", "else", "{", "root", ".", "appendChild", "(", "this", ".", "root", ")", ";", "}", "}" ]
Append a new tag into the DOM @this Tag @param { HTMLElement } root - dom node containing all the loop children @param { Boolean } isVirtual - is it a virtual tag?
[ "Append", "a", "new", "tag", "into", "the", "DOM" ]
8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4
https://github.com/cam-inc/riotx/blob/8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4/dist/amd.riotx+riot.js#L2661-L2666
train
cam-inc/riotx
dist/amd.riotx+riot.js
getItemId
function getItemId(keyAttr, originalItem, keyedItem, hasKeyAttrExpr) { if (keyAttr) { return hasKeyAttrExpr ? tmpl(keyAttr, keyedItem) : originalItem[keyAttr] } return originalItem }
javascript
function getItemId(keyAttr, originalItem, keyedItem, hasKeyAttrExpr) { if (keyAttr) { return hasKeyAttrExpr ? tmpl(keyAttr, keyedItem) : originalItem[keyAttr] } return originalItem }
[ "function", "getItemId", "(", "keyAttr", ",", "originalItem", ",", "keyedItem", ",", "hasKeyAttrExpr", ")", "{", "if", "(", "keyAttr", ")", "{", "return", "hasKeyAttrExpr", "?", "tmpl", "(", "keyAttr", ",", "keyedItem", ")", ":", "originalItem", "[", "keyAttr", "]", "}", "return", "originalItem", "}" ]
Return the value we want to use to lookup the postion of our items in the collection @param { String } keyAttr - lookup string or expression @param { * } originalItem - original item from the collection @param { Object } keyedItem - object created by riot via { item, i in collection } @param { Boolean } hasKeyAttrExpr - flag to check whether the key is an expression @returns { * } value that we will use to figure out the item position via collection.indexOf
[ "Return", "the", "value", "we", "want", "to", "use", "to", "lookup", "the", "postion", "of", "our", "items", "in", "the", "collection" ]
8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4
https://github.com/cam-inc/riotx/blob/8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4/dist/amd.riotx+riot.js#L2676-L2682
train
cam-inc/riotx
dist/amd.riotx+riot.js
createRefDirective
function createRefDirective(dom, tag, attrName, attrValue) { return create(RefExpr).init(dom, tag, attrName, attrValue) }
javascript
function createRefDirective(dom, tag, attrName, attrValue) { return create(RefExpr).init(dom, tag, attrName, attrValue) }
[ "function", "createRefDirective", "(", "dom", ",", "tag", ",", "attrName", ",", "attrValue", ")", "{", "return", "create", "(", "RefExpr", ")", ".", "init", "(", "dom", ",", "tag", ",", "attrName", ",", "attrValue", ")", "}" ]
Create a new ref directive @param { HTMLElement } dom - dom node having the ref attribute @param { Tag } context - tag instance where the DOM node is located @param { String } attrName - either 'ref' or 'data-ref' @param { String } attrValue - value of the ref attribute @returns { RefExpr } a new RefExpr object
[ "Create", "a", "new", "ref", "directive" ]
8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4
https://github.com/cam-inc/riotx/blob/8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4/dist/amd.riotx+riot.js#L2896-L2898
train
cam-inc/riotx
dist/amd.riotx+riot.js
createIfDirective
function createIfDirective(dom, tag, attr) { return create(IfExpr).init(dom, tag, attr) }
javascript
function createIfDirective(dom, tag, attr) { return create(IfExpr).init(dom, tag, attr) }
[ "function", "createIfDirective", "(", "dom", ",", "tag", ",", "attr", ")", "{", "return", "create", "(", "IfExpr", ")", ".", "init", "(", "dom", ",", "tag", ",", "attr", ")", "}" ]
Create a new if directive @param { HTMLElement } dom - if root dom node @param { Tag } context - tag instance where the DOM node is located @param { String } attr - if expression @returns { IFExpr } a new IfExpr object
[ "Create", "a", "new", "if", "directive" ]
8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4
https://github.com/cam-inc/riotx/blob/8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4/dist/amd.riotx+riot.js#L2954-L2956
train
cam-inc/riotx
dist/amd.riotx+riot.js
parseExpressions
function parseExpressions(root, mustIncludeRoot) { var this$1 = this; var expressions = []; walkNodes(root, function (dom) { var type = dom.nodeType; var attr; var tagImpl; if (!mustIncludeRoot && dom === root) { return } // text node if (type === 3 && dom.parentNode.tagName !== 'STYLE' && tmpl.hasExpr(dom.nodeValue)) { expressions.push({dom: dom, expr: dom.nodeValue}); } if (type !== 1) { return } var isVirtual = dom.tagName === 'VIRTUAL'; // loop. each does it's own thing (for now) if (attr = getAttribute(dom, LOOP_DIRECTIVE)) { if(isVirtual) { setAttribute(dom, 'loopVirtual', true); } // ignore here, handled in _each expressions.push(_each(dom, this$1, attr)); return false } // if-attrs become the new parent. Any following expressions (either on the current // element, or below it) become children of this expression. if (attr = getAttribute(dom, CONDITIONAL_DIRECTIVE)) { expressions.push(createIfDirective(dom, this$1, attr)); return false } if (attr = getAttribute(dom, IS_DIRECTIVE)) { if (tmpl.hasExpr(attr)) { expressions.push({ isRtag: true, expr: attr, dom: dom, attrs: [].slice.call(dom.attributes) }); return false } } // if this is a tag, stop traversing here. // we ignore the root, since parseExpressions is called while we're mounting that root tagImpl = get(dom); if(isVirtual) { if(getAttribute(dom, 'virtualized')) {dom.parentElement.removeChild(dom); } // tag created, remove from dom if(!tagImpl && !getAttribute(dom, 'virtualized') && !getAttribute(dom, 'loopVirtual')) // ok to create virtual tag { tagImpl = { tmpl: dom.outerHTML }; } } if (tagImpl && (dom !== root || mustIncludeRoot)) { if(isVirtual) { // handled in update if (getAttribute(dom, IS_DIRECTIVE)) { warn(("Virtual tags shouldn't be used together with the \"" + IS_DIRECTIVE + "\" attribute - https://github.com/riot/riot/issues/2511")); } // can not remove attribute like directives // so flag for removal after creation to prevent maximum stack error setAttribute(dom, 'virtualized', true); var tag = createTag( {tmpl: dom.outerHTML}, {root: dom, parent: this$1}, dom.innerHTML ); expressions.push(tag); // no return, anonymous tag, keep parsing } else { expressions.push( initChild( tagImpl, { root: dom, parent: this$1 }, dom.innerHTML, this$1 ) ); return false } } // attribute expressions parseAttributes.apply(this$1, [dom, dom.attributes, function (attr, expr) { if (!expr) { return } expressions.push(expr); }]); }); return expressions }
javascript
function parseExpressions(root, mustIncludeRoot) { var this$1 = this; var expressions = []; walkNodes(root, function (dom) { var type = dom.nodeType; var attr; var tagImpl; if (!mustIncludeRoot && dom === root) { return } // text node if (type === 3 && dom.parentNode.tagName !== 'STYLE' && tmpl.hasExpr(dom.nodeValue)) { expressions.push({dom: dom, expr: dom.nodeValue}); } if (type !== 1) { return } var isVirtual = dom.tagName === 'VIRTUAL'; // loop. each does it's own thing (for now) if (attr = getAttribute(dom, LOOP_DIRECTIVE)) { if(isVirtual) { setAttribute(dom, 'loopVirtual', true); } // ignore here, handled in _each expressions.push(_each(dom, this$1, attr)); return false } // if-attrs become the new parent. Any following expressions (either on the current // element, or below it) become children of this expression. if (attr = getAttribute(dom, CONDITIONAL_DIRECTIVE)) { expressions.push(createIfDirective(dom, this$1, attr)); return false } if (attr = getAttribute(dom, IS_DIRECTIVE)) { if (tmpl.hasExpr(attr)) { expressions.push({ isRtag: true, expr: attr, dom: dom, attrs: [].slice.call(dom.attributes) }); return false } } // if this is a tag, stop traversing here. // we ignore the root, since parseExpressions is called while we're mounting that root tagImpl = get(dom); if(isVirtual) { if(getAttribute(dom, 'virtualized')) {dom.parentElement.removeChild(dom); } // tag created, remove from dom if(!tagImpl && !getAttribute(dom, 'virtualized') && !getAttribute(dom, 'loopVirtual')) // ok to create virtual tag { tagImpl = { tmpl: dom.outerHTML }; } } if (tagImpl && (dom !== root || mustIncludeRoot)) { if(isVirtual) { // handled in update if (getAttribute(dom, IS_DIRECTIVE)) { warn(("Virtual tags shouldn't be used together with the \"" + IS_DIRECTIVE + "\" attribute - https://github.com/riot/riot/issues/2511")); } // can not remove attribute like directives // so flag for removal after creation to prevent maximum stack error setAttribute(dom, 'virtualized', true); var tag = createTag( {tmpl: dom.outerHTML}, {root: dom, parent: this$1}, dom.innerHTML ); expressions.push(tag); // no return, anonymous tag, keep parsing } else { expressions.push( initChild( tagImpl, { root: dom, parent: this$1 }, dom.innerHTML, this$1 ) ); return false } } // attribute expressions parseAttributes.apply(this$1, [dom, dom.attributes, function (attr, expr) { if (!expr) { return } expressions.push(expr); }]); }); return expressions }
[ "function", "parseExpressions", "(", "root", ",", "mustIncludeRoot", ")", "{", "var", "this$1", "=", "this", ";", "var", "expressions", "=", "[", "]", ";", "walkNodes", "(", "root", ",", "function", "(", "dom", ")", "{", "var", "type", "=", "dom", ".", "nodeType", ";", "var", "attr", ";", "var", "tagImpl", ";", "if", "(", "!", "mustIncludeRoot", "&&", "dom", "===", "root", ")", "{", "return", "}", "if", "(", "type", "===", "3", "&&", "dom", ".", "parentNode", ".", "tagName", "!==", "'STYLE'", "&&", "tmpl", ".", "hasExpr", "(", "dom", ".", "nodeValue", ")", ")", "{", "expressions", ".", "push", "(", "{", "dom", ":", "dom", ",", "expr", ":", "dom", ".", "nodeValue", "}", ")", ";", "}", "if", "(", "type", "!==", "1", ")", "{", "return", "}", "var", "isVirtual", "=", "dom", ".", "tagName", "===", "'VIRTUAL'", ";", "if", "(", "attr", "=", "getAttribute", "(", "dom", ",", "LOOP_DIRECTIVE", ")", ")", "{", "if", "(", "isVirtual", ")", "{", "setAttribute", "(", "dom", ",", "'loopVirtual'", ",", "true", ")", ";", "}", "expressions", ".", "push", "(", "_each", "(", "dom", ",", "this$1", ",", "attr", ")", ")", ";", "return", "false", "}", "if", "(", "attr", "=", "getAttribute", "(", "dom", ",", "CONDITIONAL_DIRECTIVE", ")", ")", "{", "expressions", ".", "push", "(", "createIfDirective", "(", "dom", ",", "this$1", ",", "attr", ")", ")", ";", "return", "false", "}", "if", "(", "attr", "=", "getAttribute", "(", "dom", ",", "IS_DIRECTIVE", ")", ")", "{", "if", "(", "tmpl", ".", "hasExpr", "(", "attr", ")", ")", "{", "expressions", ".", "push", "(", "{", "isRtag", ":", "true", ",", "expr", ":", "attr", ",", "dom", ":", "dom", ",", "attrs", ":", "[", "]", ".", "slice", ".", "call", "(", "dom", ".", "attributes", ")", "}", ")", ";", "return", "false", "}", "}", "tagImpl", "=", "get", "(", "dom", ")", ";", "if", "(", "isVirtual", ")", "{", "if", "(", "getAttribute", "(", "dom", ",", "'virtualized'", ")", ")", "{", "dom", ".", "parentElement", ".", "removeChild", "(", "dom", ")", ";", "}", "if", "(", "!", "tagImpl", "&&", "!", "getAttribute", "(", "dom", ",", "'virtualized'", ")", "&&", "!", "getAttribute", "(", "dom", ",", "'loopVirtual'", ")", ")", "{", "tagImpl", "=", "{", "tmpl", ":", "dom", ".", "outerHTML", "}", ";", "}", "}", "if", "(", "tagImpl", "&&", "(", "dom", "!==", "root", "||", "mustIncludeRoot", ")", ")", "{", "if", "(", "isVirtual", ")", "{", "if", "(", "getAttribute", "(", "dom", ",", "IS_DIRECTIVE", ")", ")", "{", "warn", "(", "(", "\"Virtual tags shouldn't be used together with the \\\"\"", "+", "\\\"", "+", "IS_DIRECTIVE", ")", ")", ";", "}", "\"\\\" attribute - https://github.com/riot/riot/issues/2511\"", "\\\"", "setAttribute", "(", "dom", ",", "'virtualized'", ",", "true", ")", ";", "}", "else", "var", "tag", "=", "createTag", "(", "{", "tmpl", ":", "dom", ".", "outerHTML", "}", ",", "{", "root", ":", "dom", ",", "parent", ":", "this$1", "}", ",", "dom", ".", "innerHTML", ")", ";", "}", "expressions", ".", "push", "(", "tag", ")", ";", "}", ")", ";", "{", "expressions", ".", "push", "(", "initChild", "(", "tagImpl", ",", "{", "root", ":", "dom", ",", "parent", ":", "this$1", "}", ",", "dom", ".", "innerHTML", ",", "this$1", ")", ")", ";", "return", "false", "}", "}" ]
Walk the tag DOM to detect the expressions to evaluate @this Tag @param { HTMLElement } root - root tag where we will start digging the expressions @param { Boolean } mustIncludeRoot - flag to decide whether the root must be parsed as well @returns { Array } all the expressions found
[ "Walk", "the", "tag", "DOM", "to", "detect", "the", "expressions", "to", "evaluate" ]
8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4
https://github.com/cam-inc/riotx/blob/8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4/dist/amd.riotx+riot.js#L2965-L3060
train
cam-inc/riotx
dist/amd.riotx+riot.js
setMountState
function setMountState(value) { var ref = this.__; var isAnonymous = ref.isAnonymous; define(this, 'isMounted', value); if (!isAnonymous) { if (value) { this.trigger('mount'); } else { this.trigger('unmount'); this.off('*'); this.__.wasCreated = false; } } }
javascript
function setMountState(value) { var ref = this.__; var isAnonymous = ref.isAnonymous; define(this, 'isMounted', value); if (!isAnonymous) { if (value) { this.trigger('mount'); } else { this.trigger('unmount'); this.off('*'); this.__.wasCreated = false; } } }
[ "function", "setMountState", "(", "value", ")", "{", "var", "ref", "=", "this", ".", "__", ";", "var", "isAnonymous", "=", "ref", ".", "isAnonymous", ";", "define", "(", "this", ",", "'isMounted'", ",", "value", ")", ";", "if", "(", "!", "isAnonymous", ")", "{", "if", "(", "value", ")", "{", "this", ".", "trigger", "(", "'mount'", ")", ";", "}", "else", "{", "this", ".", "trigger", "(", "'unmount'", ")", ";", "this", ".", "off", "(", "'*'", ")", ";", "this", ".", "__", ".", "wasCreated", "=", "false", ";", "}", "}", "}" ]
Manage the mount state of a tag triggering also the observable events @this Tag @param { Boolean } value - ..of the isMounted flag
[ "Manage", "the", "mount", "state", "of", "a", "tag", "triggering", "also", "the", "observable", "events" ]
8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4
https://github.com/cam-inc/riotx/blob/8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4/dist/amd.riotx+riot.js#L3095-L3109
train
cam-inc/riotx
dist/amd.riotx+riot.js
componentMount
function componentMount(tag$$1, dom, expressions, opts) { var __ = tag$$1.__; var root = __.root; root._tag = tag$$1; // keep a reference to the tag just created // Read all the attrs on this instance. This give us the info we need for updateOpts parseAttributes.apply(__.parent, [root, root.attributes, function (attr, expr) { if (!__.isAnonymous && RefExpr.isPrototypeOf(expr)) { expr.tag = tag$$1; } attr.expr = expr; __.instAttrs.push(attr); }]); // update the root adding custom attributes coming from the compiler walkAttributes(__.impl.attrs, function (k, v) { __.implAttrs.push({name: k, value: v}); }); parseAttributes.apply(tag$$1, [root, __.implAttrs, function (attr, expr) { if (expr) { expressions.push(expr); } else { setAttribute(root, attr.name, attr.value); } }]); // initialiation updateOpts.apply(tag$$1, [__.isLoop, __.parent, __.isAnonymous, opts, __.instAttrs]); // add global mixins var globalMixin = mixin(GLOBAL_MIXIN); if (globalMixin && !__.skipAnonymous) { for (var i in globalMixin) { if (globalMixin.hasOwnProperty(i)) { tag$$1.mixin(globalMixin[i]); } } } if (__.impl.fn) { __.impl.fn.call(tag$$1, opts); } if (!__.skipAnonymous) { tag$$1.trigger('before-mount'); } // parse layout after init. fn may calculate args for nested custom tags each(parseExpressions.apply(tag$$1, [dom, __.isAnonymous]), function (e) { return expressions.push(e); }); tag$$1.update(__.item); if (!__.isAnonymous && !__.isInline) { while (dom.firstChild) { root.appendChild(dom.firstChild); } } define(tag$$1, 'root', root); // if we need to wait that the parent "mount" or "updated" event gets triggered if (!__.skipAnonymous && tag$$1.parent) { var p = getImmediateCustomParent(tag$$1.parent); p.one(!p.isMounted ? 'mount' : 'updated', function () { setMountState.call(tag$$1, true); }); } else { // otherwise it's not a child tag we can trigger its mount event setMountState.call(tag$$1, true); } tag$$1.__.wasCreated = true; return tag$$1 }
javascript
function componentMount(tag$$1, dom, expressions, opts) { var __ = tag$$1.__; var root = __.root; root._tag = tag$$1; // keep a reference to the tag just created // Read all the attrs on this instance. This give us the info we need for updateOpts parseAttributes.apply(__.parent, [root, root.attributes, function (attr, expr) { if (!__.isAnonymous && RefExpr.isPrototypeOf(expr)) { expr.tag = tag$$1; } attr.expr = expr; __.instAttrs.push(attr); }]); // update the root adding custom attributes coming from the compiler walkAttributes(__.impl.attrs, function (k, v) { __.implAttrs.push({name: k, value: v}); }); parseAttributes.apply(tag$$1, [root, __.implAttrs, function (attr, expr) { if (expr) { expressions.push(expr); } else { setAttribute(root, attr.name, attr.value); } }]); // initialiation updateOpts.apply(tag$$1, [__.isLoop, __.parent, __.isAnonymous, opts, __.instAttrs]); // add global mixins var globalMixin = mixin(GLOBAL_MIXIN); if (globalMixin && !__.skipAnonymous) { for (var i in globalMixin) { if (globalMixin.hasOwnProperty(i)) { tag$$1.mixin(globalMixin[i]); } } } if (__.impl.fn) { __.impl.fn.call(tag$$1, opts); } if (!__.skipAnonymous) { tag$$1.trigger('before-mount'); } // parse layout after init. fn may calculate args for nested custom tags each(parseExpressions.apply(tag$$1, [dom, __.isAnonymous]), function (e) { return expressions.push(e); }); tag$$1.update(__.item); if (!__.isAnonymous && !__.isInline) { while (dom.firstChild) { root.appendChild(dom.firstChild); } } define(tag$$1, 'root', root); // if we need to wait that the parent "mount" or "updated" event gets triggered if (!__.skipAnonymous && tag$$1.parent) { var p = getImmediateCustomParent(tag$$1.parent); p.one(!p.isMounted ? 'mount' : 'updated', function () { setMountState.call(tag$$1, true); }); } else { // otherwise it's not a child tag we can trigger its mount event setMountState.call(tag$$1, true); } tag$$1.__.wasCreated = true; return tag$$1 }
[ "function", "componentMount", "(", "tag$$1", ",", "dom", ",", "expressions", ",", "opts", ")", "{", "var", "__", "=", "tag$$1", ".", "__", ";", "var", "root", "=", "__", ".", "root", ";", "root", ".", "_tag", "=", "tag$$1", ";", "parseAttributes", ".", "apply", "(", "__", ".", "parent", ",", "[", "root", ",", "root", ".", "attributes", ",", "function", "(", "attr", ",", "expr", ")", "{", "if", "(", "!", "__", ".", "isAnonymous", "&&", "RefExpr", ".", "isPrototypeOf", "(", "expr", ")", ")", "{", "expr", ".", "tag", "=", "tag$$1", ";", "}", "attr", ".", "expr", "=", "expr", ";", "__", ".", "instAttrs", ".", "push", "(", "attr", ")", ";", "}", "]", ")", ";", "walkAttributes", "(", "__", ".", "impl", ".", "attrs", ",", "function", "(", "k", ",", "v", ")", "{", "__", ".", "implAttrs", ".", "push", "(", "{", "name", ":", "k", ",", "value", ":", "v", "}", ")", ";", "}", ")", ";", "parseAttributes", ".", "apply", "(", "tag$$1", ",", "[", "root", ",", "__", ".", "implAttrs", ",", "function", "(", "attr", ",", "expr", ")", "{", "if", "(", "expr", ")", "{", "expressions", ".", "push", "(", "expr", ")", ";", "}", "else", "{", "setAttribute", "(", "root", ",", "attr", ".", "name", ",", "attr", ".", "value", ")", ";", "}", "}", "]", ")", ";", "updateOpts", ".", "apply", "(", "tag$$1", ",", "[", "__", ".", "isLoop", ",", "__", ".", "parent", ",", "__", ".", "isAnonymous", ",", "opts", ",", "__", ".", "instAttrs", "]", ")", ";", "var", "globalMixin", "=", "mixin", "(", "GLOBAL_MIXIN", ")", ";", "if", "(", "globalMixin", "&&", "!", "__", ".", "skipAnonymous", ")", "{", "for", "(", "var", "i", "in", "globalMixin", ")", "{", "if", "(", "globalMixin", ".", "hasOwnProperty", "(", "i", ")", ")", "{", "tag$$1", ".", "mixin", "(", "globalMixin", "[", "i", "]", ")", ";", "}", "}", "}", "if", "(", "__", ".", "impl", ".", "fn", ")", "{", "__", ".", "impl", ".", "fn", ".", "call", "(", "tag$$1", ",", "opts", ")", ";", "}", "if", "(", "!", "__", ".", "skipAnonymous", ")", "{", "tag$$1", ".", "trigger", "(", "'before-mount'", ")", ";", "}", "each", "(", "parseExpressions", ".", "apply", "(", "tag$$1", ",", "[", "dom", ",", "__", ".", "isAnonymous", "]", ")", ",", "function", "(", "e", ")", "{", "return", "expressions", ".", "push", "(", "e", ")", ";", "}", ")", ";", "tag$$1", ".", "update", "(", "__", ".", "item", ")", ";", "if", "(", "!", "__", ".", "isAnonymous", "&&", "!", "__", ".", "isInline", ")", "{", "while", "(", "dom", ".", "firstChild", ")", "{", "root", ".", "appendChild", "(", "dom", ".", "firstChild", ")", ";", "}", "}", "define", "(", "tag$$1", ",", "'root'", ",", "root", ")", ";", "if", "(", "!", "__", ".", "skipAnonymous", "&&", "tag$$1", ".", "parent", ")", "{", "var", "p", "=", "getImmediateCustomParent", "(", "tag$$1", ".", "parent", ")", ";", "p", ".", "one", "(", "!", "p", ".", "isMounted", "?", "'mount'", ":", "'updated'", ",", "function", "(", ")", "{", "setMountState", ".", "call", "(", "tag$$1", ",", "true", ")", ";", "}", ")", ";", "}", "else", "{", "setMountState", ".", "call", "(", "tag$$1", ",", "true", ")", ";", "}", "tag$$1", ".", "__", ".", "wasCreated", "=", "true", ";", "return", "tag$$1", "}" ]
Mount the current tag instance @returns { Tag } the current tag instance
[ "Mount", "the", "current", "tag", "instance" ]
8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4
https://github.com/cam-inc/riotx/blob/8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4/dist/amd.riotx+riot.js#L3115-L3177
train
cam-inc/riotx
dist/amd.riotx+riot.js
tagUnmount
function tagUnmount(tag, mustKeepRoot, expressions) { var __ = tag.__; var root = __.root; var tagIndex = __TAGS_CACHE.indexOf(tag); var p = root.parentNode; if (!__.skipAnonymous) { tag.trigger('before-unmount'); } // clear all attributes coming from the mounted tag walkAttributes(__.impl.attrs, function (name) { if (startsWith(name, ATTRS_PREFIX)) { name = name.slice(ATTRS_PREFIX.length); } removeAttribute(root, name); }); // remove all the event listeners tag.__.listeners.forEach(function (dom) { Object.keys(dom[RIOT_EVENTS_KEY]).forEach(function (eventName) { dom.removeEventListener(eventName, dom[RIOT_EVENTS_KEY][eventName]); }); }); // remove tag instance from the global tags cache collection if (tagIndex !== -1) { __TAGS_CACHE.splice(tagIndex, 1); } // clean up the parent tags object if (__.parent && !__.isAnonymous) { var ptag = getImmediateCustomParent(__.parent); if (__.isVirtual) { Object .keys(tag.tags) .forEach(function (tagName) { return arrayishRemove(ptag.tags, tagName, tag.tags[tagName]); }); } else { arrayishRemove(ptag.tags, __.tagName, tag); } } // unmount all the virtual directives if (tag.__.virts) { each(tag.__.virts, function (v) { if (v.parentNode) { v.parentNode.removeChild(v); } }); } // allow expressions to unmount themselves unmountAll(expressions); each(__.instAttrs, function (a) { return a.expr && a.expr.unmount && a.expr.unmount(); }); // clear the tag html if it's necessary if (mustKeepRoot) { setInnerHTML(root, ''); } // otherwise detach the root tag from the DOM else if (p) { p.removeChild(root); } // custom internal unmount function to avoid relying on the observable if (__.onUnmount) { __.onUnmount(); } // weird fix for a weird edge case #2409 and #2436 // some users might use your software not as you've expected // so I need to add these dirty hacks to mitigate unexpected issues if (!tag.isMounted) { setMountState.call(tag, true); } setMountState.call(tag, false); delete root._tag; return tag }
javascript
function tagUnmount(tag, mustKeepRoot, expressions) { var __ = tag.__; var root = __.root; var tagIndex = __TAGS_CACHE.indexOf(tag); var p = root.parentNode; if (!__.skipAnonymous) { tag.trigger('before-unmount'); } // clear all attributes coming from the mounted tag walkAttributes(__.impl.attrs, function (name) { if (startsWith(name, ATTRS_PREFIX)) { name = name.slice(ATTRS_PREFIX.length); } removeAttribute(root, name); }); // remove all the event listeners tag.__.listeners.forEach(function (dom) { Object.keys(dom[RIOT_EVENTS_KEY]).forEach(function (eventName) { dom.removeEventListener(eventName, dom[RIOT_EVENTS_KEY][eventName]); }); }); // remove tag instance from the global tags cache collection if (tagIndex !== -1) { __TAGS_CACHE.splice(tagIndex, 1); } // clean up the parent tags object if (__.parent && !__.isAnonymous) { var ptag = getImmediateCustomParent(__.parent); if (__.isVirtual) { Object .keys(tag.tags) .forEach(function (tagName) { return arrayishRemove(ptag.tags, tagName, tag.tags[tagName]); }); } else { arrayishRemove(ptag.tags, __.tagName, tag); } } // unmount all the virtual directives if (tag.__.virts) { each(tag.__.virts, function (v) { if (v.parentNode) { v.parentNode.removeChild(v); } }); } // allow expressions to unmount themselves unmountAll(expressions); each(__.instAttrs, function (a) { return a.expr && a.expr.unmount && a.expr.unmount(); }); // clear the tag html if it's necessary if (mustKeepRoot) { setInnerHTML(root, ''); } // otherwise detach the root tag from the DOM else if (p) { p.removeChild(root); } // custom internal unmount function to avoid relying on the observable if (__.onUnmount) { __.onUnmount(); } // weird fix for a weird edge case #2409 and #2436 // some users might use your software not as you've expected // so I need to add these dirty hacks to mitigate unexpected issues if (!tag.isMounted) { setMountState.call(tag, true); } setMountState.call(tag, false); delete root._tag; return tag }
[ "function", "tagUnmount", "(", "tag", ",", "mustKeepRoot", ",", "expressions", ")", "{", "var", "__", "=", "tag", ".", "__", ";", "var", "root", "=", "__", ".", "root", ";", "var", "tagIndex", "=", "__TAGS_CACHE", ".", "indexOf", "(", "tag", ")", ";", "var", "p", "=", "root", ".", "parentNode", ";", "if", "(", "!", "__", ".", "skipAnonymous", ")", "{", "tag", ".", "trigger", "(", "'before-unmount'", ")", ";", "}", "walkAttributes", "(", "__", ".", "impl", ".", "attrs", ",", "function", "(", "name", ")", "{", "if", "(", "startsWith", "(", "name", ",", "ATTRS_PREFIX", ")", ")", "{", "name", "=", "name", ".", "slice", "(", "ATTRS_PREFIX", ".", "length", ")", ";", "}", "removeAttribute", "(", "root", ",", "name", ")", ";", "}", ")", ";", "tag", ".", "__", ".", "listeners", ".", "forEach", "(", "function", "(", "dom", ")", "{", "Object", ".", "keys", "(", "dom", "[", "RIOT_EVENTS_KEY", "]", ")", ".", "forEach", "(", "function", "(", "eventName", ")", "{", "dom", ".", "removeEventListener", "(", "eventName", ",", "dom", "[", "RIOT_EVENTS_KEY", "]", "[", "eventName", "]", ")", ";", "}", ")", ";", "}", ")", ";", "if", "(", "tagIndex", "!==", "-", "1", ")", "{", "__TAGS_CACHE", ".", "splice", "(", "tagIndex", ",", "1", ")", ";", "}", "if", "(", "__", ".", "parent", "&&", "!", "__", ".", "isAnonymous", ")", "{", "var", "ptag", "=", "getImmediateCustomParent", "(", "__", ".", "parent", ")", ";", "if", "(", "__", ".", "isVirtual", ")", "{", "Object", ".", "keys", "(", "tag", ".", "tags", ")", ".", "forEach", "(", "function", "(", "tagName", ")", "{", "return", "arrayishRemove", "(", "ptag", ".", "tags", ",", "tagName", ",", "tag", ".", "tags", "[", "tagName", "]", ")", ";", "}", ")", ";", "}", "else", "{", "arrayishRemove", "(", "ptag", ".", "tags", ",", "__", ".", "tagName", ",", "tag", ")", ";", "}", "}", "if", "(", "tag", ".", "__", ".", "virts", ")", "{", "each", "(", "tag", ".", "__", ".", "virts", ",", "function", "(", "v", ")", "{", "if", "(", "v", ".", "parentNode", ")", "{", "v", ".", "parentNode", ".", "removeChild", "(", "v", ")", ";", "}", "}", ")", ";", "}", "unmountAll", "(", "expressions", ")", ";", "each", "(", "__", ".", "instAttrs", ",", "function", "(", "a", ")", "{", "return", "a", ".", "expr", "&&", "a", ".", "expr", ".", "unmount", "&&", "a", ".", "expr", ".", "unmount", "(", ")", ";", "}", ")", ";", "if", "(", "mustKeepRoot", ")", "{", "setInnerHTML", "(", "root", ",", "''", ")", ";", "}", "else", "if", "(", "p", ")", "{", "p", ".", "removeChild", "(", "root", ")", ";", "}", "if", "(", "__", ".", "onUnmount", ")", "{", "__", ".", "onUnmount", "(", ")", ";", "}", "if", "(", "!", "tag", ".", "isMounted", ")", "{", "setMountState", ".", "call", "(", "tag", ",", "true", ")", ";", "}", "setMountState", ".", "call", "(", "tag", ",", "false", ")", ";", "delete", "root", ".", "_tag", ";", "return", "tag", "}" ]
Unmount the tag instance @param { Boolean } mustKeepRoot - if it's true the root node will not be removed @returns { Tag } the current tag instance
[ "Unmount", "the", "tag", "instance" ]
8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4
https://github.com/cam-inc/riotx/blob/8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4/dist/amd.riotx+riot.js#L3184-L3252
train
cam-inc/riotx
dist/amd.riotx+riot.js
function () { var args = [], len = arguments.length; while ( len-- ) args[ len ] = arguments[ len ]; if (!settings$2.debug) { return; } args.unshift('DEBUG'); settings$2.logger.output.apply(null, args); }
javascript
function () { var args = [], len = arguments.length; while ( len-- ) args[ len ] = arguments[ len ]; if (!settings$2.debug) { return; } args.unshift('DEBUG'); settings$2.logger.output.apply(null, args); }
[ "function", "(", ")", "{", "var", "args", "=", "[", "]", ",", "len", "=", "arguments", ".", "length", ";", "while", "(", "len", "--", ")", "args", "[", "len", "]", "=", "arguments", "[", "len", "]", ";", "if", "(", "!", "settings$2", ".", "debug", ")", "{", "return", ";", "}", "args", ".", "unshift", "(", "'DEBUG'", ")", ";", "settings$2", ".", "logger", ".", "output", ".", "apply", "(", "null", ",", "args", ")", ";", "}" ]
console debug output @param {*} args
[ "console", "debug", "output" ]
8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4
https://github.com/cam-inc/riotx/blob/8fb6b71e7a65e9a589dfe02f1dc4876c47516ec4/dist/amd.riotx+riot.js#L3458-L3467
train
freiksenet/react-kinetic
src/KineticProperty.js
injectKineticProperties
function injectKineticProperties (kineticConfig, kineticHierarchy, kineticEvents) { for (var type in kineticHierarchy) { var parents = kineticHierarchy[type]; KineticProperty.getParents[type] = [type].concat(parents); for (var pi in parents) { var parent = parents[pi]; var existingChildren = KineticProperty.getChildren[parent] || []; existingChildren.push(type); KineticProperty.getChildren[parent] = existingChildren; } } for (var propI in kineticConfig) { var data = kineticConfig[propI]; var propName = data.propName; var propType = data.type; var defaultValue = data.defaultValue; var nodeType = data.nodeType; var children = [nodeType].concat( KineticProperty.getChildren[nodeType] || [] ); for (var ci in children) { var child = children[ci]; var existingProps = KineticProperty.getValidProps[child] || {}; existingProps[propName] = { type: propType, defaultValue: defaultValue }; KineticProperty.getValidProps[child] = existingProps; } } for (var eventName in kineticEvents) { KineticProperty.getEventName[eventName] = kineticEvents[eventName] + "." + "react"; } }
javascript
function injectKineticProperties (kineticConfig, kineticHierarchy, kineticEvents) { for (var type in kineticHierarchy) { var parents = kineticHierarchy[type]; KineticProperty.getParents[type] = [type].concat(parents); for (var pi in parents) { var parent = parents[pi]; var existingChildren = KineticProperty.getChildren[parent] || []; existingChildren.push(type); KineticProperty.getChildren[parent] = existingChildren; } } for (var propI in kineticConfig) { var data = kineticConfig[propI]; var propName = data.propName; var propType = data.type; var defaultValue = data.defaultValue; var nodeType = data.nodeType; var children = [nodeType].concat( KineticProperty.getChildren[nodeType] || [] ); for (var ci in children) { var child = children[ci]; var existingProps = KineticProperty.getValidProps[child] || {}; existingProps[propName] = { type: propType, defaultValue: defaultValue }; KineticProperty.getValidProps[child] = existingProps; } } for (var eventName in kineticEvents) { KineticProperty.getEventName[eventName] = kineticEvents[eventName] + "." + "react"; } }
[ "function", "injectKineticProperties", "(", "kineticConfig", ",", "kineticHierarchy", ",", "kineticEvents", ")", "{", "for", "(", "var", "type", "in", "kineticHierarchy", ")", "{", "var", "parents", "=", "kineticHierarchy", "[", "type", "]", ";", "KineticProperty", ".", "getParents", "[", "type", "]", "=", "[", "type", "]", ".", "concat", "(", "parents", ")", ";", "for", "(", "var", "pi", "in", "parents", ")", "{", "var", "parent", "=", "parents", "[", "pi", "]", ";", "var", "existingChildren", "=", "KineticProperty", ".", "getChildren", "[", "parent", "]", "||", "[", "]", ";", "existingChildren", ".", "push", "(", "type", ")", ";", "KineticProperty", ".", "getChildren", "[", "parent", "]", "=", "existingChildren", ";", "}", "}", "for", "(", "var", "propI", "in", "kineticConfig", ")", "{", "var", "data", "=", "kineticConfig", "[", "propI", "]", ";", "var", "propName", "=", "data", ".", "propName", ";", "var", "propType", "=", "data", ".", "type", ";", "var", "defaultValue", "=", "data", ".", "defaultValue", ";", "var", "nodeType", "=", "data", ".", "nodeType", ";", "var", "children", "=", "[", "nodeType", "]", ".", "concat", "(", "KineticProperty", ".", "getChildren", "[", "nodeType", "]", "||", "[", "]", ")", ";", "for", "(", "var", "ci", "in", "children", ")", "{", "var", "child", "=", "children", "[", "ci", "]", ";", "var", "existingProps", "=", "KineticProperty", ".", "getValidProps", "[", "child", "]", "||", "{", "}", ";", "existingProps", "[", "propName", "]", "=", "{", "type", ":", "propType", ",", "defaultValue", ":", "defaultValue", "}", ";", "KineticProperty", ".", "getValidProps", "[", "child", "]", "=", "existingProps", ";", "}", "}", "for", "(", "var", "eventName", "in", "kineticEvents", ")", "{", "KineticProperty", ".", "getEventName", "[", "eventName", "]", "=", "kineticEvents", "[", "eventName", "]", "+", "\".\"", "+", "\"react\"", ";", "}", "}" ]
Inject Kinetic property infos to KineticProperty. @param {object} kineticConfig should be an object with keys as property names and values as objects of 'type', 'defaultValue', 'nodeType'. @param {object} kineticHierarchy should be a object with nodeType as key and list of nodeType parents as values. @param {object} kineticEvents should be a object with React (onFoo) event props and kinetic (foo) events.
[ "Inject", "Kinetic", "property", "infos", "to", "KineticProperty", "." ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/src/KineticProperty.js#L15-L54
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function() { var d = 1 / (this.m[0] * this.m[3] - this.m[1] * this.m[2]); var m0 = this.m[3] * d; var m1 = -this.m[1] * d; var m2 = -this.m[2] * d; var m3 = this.m[0] * d; var m4 = d * (this.m[2] * this.m[5] - this.m[3] * this.m[4]); var m5 = d * (this.m[1] * this.m[4] - this.m[0] * this.m[5]); this.m[0] = m0; this.m[1] = m1; this.m[2] = m2; this.m[3] = m3; this.m[4] = m4; this.m[5] = m5; return this; }
javascript
function() { var d = 1 / (this.m[0] * this.m[3] - this.m[1] * this.m[2]); var m0 = this.m[3] * d; var m1 = -this.m[1] * d; var m2 = -this.m[2] * d; var m3 = this.m[0] * d; var m4 = d * (this.m[2] * this.m[5] - this.m[3] * this.m[4]); var m5 = d * (this.m[1] * this.m[4] - this.m[0] * this.m[5]); this.m[0] = m0; this.m[1] = m1; this.m[2] = m2; this.m[3] = m3; this.m[4] = m4; this.m[5] = m5; return this; }
[ "function", "(", ")", "{", "var", "d", "=", "1", "/", "(", "this", ".", "m", "[", "0", "]", "*", "this", ".", "m", "[", "3", "]", "-", "this", ".", "m", "[", "1", "]", "*", "this", ".", "m", "[", "2", "]", ")", ";", "var", "m0", "=", "this", ".", "m", "[", "3", "]", "*", "d", ";", "var", "m1", "=", "-", "this", ".", "m", "[", "1", "]", "*", "d", ";", "var", "m2", "=", "-", "this", ".", "m", "[", "2", "]", "*", "d", ";", "var", "m3", "=", "this", ".", "m", "[", "0", "]", "*", "d", ";", "var", "m4", "=", "d", "*", "(", "this", ".", "m", "[", "2", "]", "*", "this", ".", "m", "[", "5", "]", "-", "this", ".", "m", "[", "3", "]", "*", "this", ".", "m", "[", "4", "]", ")", ";", "var", "m5", "=", "d", "*", "(", "this", ".", "m", "[", "1", "]", "*", "this", ".", "m", "[", "4", "]", "-", "this", ".", "m", "[", "0", "]", "*", "this", ".", "m", "[", "5", "]", ")", ";", "this", ".", "m", "[", "0", "]", "=", "m0", ";", "this", ".", "m", "[", "1", "]", "=", "m1", ";", "this", ".", "m", "[", "2", "]", "=", "m2", ";", "this", ".", "m", "[", "3", "]", "=", "m3", ";", "this", ".", "m", "[", "4", "]", "=", "m4", ";", "this", ".", "m", "[", "5", "]", "=", "m5", ";", "return", "this", ";", "}" ]
Invert the matrix @method @memberof Kinetic.Transform.prototype @returns {Kinetic.Transform}
[ "Invert", "the", "matrix" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L789-L804
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function(x, y) { var m0 = this.m[0], m1 = this.m[1], m2 = this.m[2], m3 = this.m[3], m4 = this.m[4], m5 = this.m[5], yt = ((m0 * (y - m5)) - (m1 * (x - m4))) / ((m0 * m3) - (m1 * m2)), xt = (x - m4 - (m2 * yt)) / m0; return this.translate(xt, yt); }
javascript
function(x, y) { var m0 = this.m[0], m1 = this.m[1], m2 = this.m[2], m3 = this.m[3], m4 = this.m[4], m5 = this.m[5], yt = ((m0 * (y - m5)) - (m1 * (x - m4))) / ((m0 * m3) - (m1 * m2)), xt = (x - m4 - (m2 * yt)) / m0; return this.translate(xt, yt); }
[ "function", "(", "x", ",", "y", ")", "{", "var", "m0", "=", "this", ".", "m", "[", "0", "]", ",", "m1", "=", "this", ".", "m", "[", "1", "]", ",", "m2", "=", "this", ".", "m", "[", "2", "]", ",", "m3", "=", "this", ".", "m", "[", "3", "]", ",", "m4", "=", "this", ".", "m", "[", "4", "]", ",", "m5", "=", "this", ".", "m", "[", "5", "]", ",", "yt", "=", "(", "(", "m0", "*", "(", "y", "-", "m5", ")", ")", "-", "(", "m1", "*", "(", "x", "-", "m4", ")", ")", ")", "/", "(", "(", "m0", "*", "m3", ")", "-", "(", "m1", "*", "m2", ")", ")", ",", "xt", "=", "(", "x", "-", "m4", "-", "(", "m2", "*", "yt", ")", ")", "/", "m0", ";", "return", "this", ".", "translate", "(", "xt", ",", "yt", ")", ";", "}" ]
set to absolute position via translation @method @memberof Kinetic.Transform.prototype @returns {Kinetic.Transform} @author ericdrowell
[ "set", "to", "absolute", "position", "via", "translation" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L820-L831
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function() { var randColor = (Math.random() * 0xFFFFFF << 0).toString(16); while (randColor.length < 6) { randColor = ZERO + randColor; } return HASH + randColor; }
javascript
function() { var randColor = (Math.random() * 0xFFFFFF << 0).toString(16); while (randColor.length < 6) { randColor = ZERO + randColor; } return HASH + randColor; }
[ "function", "(", ")", "{", "var", "randColor", "=", "(", "Math", ".", "random", "(", ")", "*", "0xFFFFFF", "<<", "0", ")", ".", "toString", "(", "16", ")", ";", "while", "(", "randColor", ".", "length", "<", "6", ")", "{", "randColor", "=", "ZERO", "+", "randColor", ";", "}", "return", "HASH", "+", "randColor", ";", "}" ]
return random hex color @method @memberof Kinetic.Util.prototype
[ "return", "random", "hex", "color" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L1056-L1062
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function(color) { var rgb; // color string if (color in COLORS) { rgb = COLORS[color]; return { r: rgb[0], g: rgb[1], b: rgb[2] }; } // hex else if (color[0] === HASH) { return this._hexToRgb(color.substring(1)); } // rgb string else if (color.substr(0, 4) === RGB_PAREN) { rgb = RGB_REGEX.exec(color.replace(/ /g,'')); return { r: parseInt(rgb[1], 10), g: parseInt(rgb[2], 10), b: parseInt(rgb[3], 10) }; } // default else { return { r: 0, g: 0, b: 0 }; } }
javascript
function(color) { var rgb; // color string if (color in COLORS) { rgb = COLORS[color]; return { r: rgb[0], g: rgb[1], b: rgb[2] }; } // hex else if (color[0] === HASH) { return this._hexToRgb(color.substring(1)); } // rgb string else if (color.substr(0, 4) === RGB_PAREN) { rgb = RGB_REGEX.exec(color.replace(/ /g,'')); return { r: parseInt(rgb[1], 10), g: parseInt(rgb[2], 10), b: parseInt(rgb[3], 10) }; } // default else { return { r: 0, g: 0, b: 0 }; } }
[ "function", "(", "color", ")", "{", "var", "rgb", ";", "if", "(", "color", "in", "COLORS", ")", "{", "rgb", "=", "COLORS", "[", "color", "]", ";", "return", "{", "r", ":", "rgb", "[", "0", "]", ",", "g", ":", "rgb", "[", "1", "]", ",", "b", ":", "rgb", "[", "2", "]", "}", ";", "}", "else", "if", "(", "color", "[", "0", "]", "===", "HASH", ")", "{", "return", "this", ".", "_hexToRgb", "(", "color", ".", "substring", "(", "1", ")", ")", ";", "}", "else", "if", "(", "color", ".", "substr", "(", "0", ",", "4", ")", "===", "RGB_PAREN", ")", "{", "rgb", "=", "RGB_REGEX", ".", "exec", "(", "color", ".", "replace", "(", "/", " ", "/", "g", ",", "''", ")", ")", ";", "return", "{", "r", ":", "parseInt", "(", "rgb", "[", "1", "]", ",", "10", ")", ",", "g", ":", "parseInt", "(", "rgb", "[", "2", "]", ",", "10", ")", ",", "b", ":", "parseInt", "(", "rgb", "[", "3", "]", ",", "10", ")", "}", ";", "}", "else", "{", "return", "{", "r", ":", "0", ",", "g", ":", "0", ",", "b", ":", "0", "}", ";", "}", "}" ]
get RGB components of a color @method @memberof Kinetic.Util.prototype @param {String} color @example // each of the following examples return {r:0, g:0, b:255}<br> var rgb = Kinetic.Util.getRGB('blue');<br> var rgb = Kinetic.Util.getRGB('#0000ff');<br> var rgb = Kinetic.Util.getRGB('rgb(0,0,255)');
[ "get", "RGB", "components", "of", "a", "color" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L1087-L1119
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function(o1, o2) { var retObj = this._clone(o2); for(var key in o1) { if(this._isObject(o1[key])) { retObj[key] = this._merge(o1[key], retObj[key]); } else { retObj[key] = o1[key]; } } return retObj; }
javascript
function(o1, o2) { var retObj = this._clone(o2); for(var key in o1) { if(this._isObject(o1[key])) { retObj[key] = this._merge(o1[key], retObj[key]); } else { retObj[key] = o1[key]; } } return retObj; }
[ "function", "(", "o1", ",", "o2", ")", "{", "var", "retObj", "=", "this", ".", "_clone", "(", "o2", ")", ";", "for", "(", "var", "key", "in", "o1", ")", "{", "if", "(", "this", ".", "_isObject", "(", "o1", "[", "key", "]", ")", ")", "{", "retObj", "[", "key", "]", "=", "this", ".", "_merge", "(", "o1", "[", "key", "]", ",", "retObj", "[", "key", "]", ")", ";", "}", "else", "{", "retObj", "[", "key", "]", "=", "o1", "[", "key", "]", ";", "}", "}", "return", "retObj", ";", "}" ]
o1 takes precedence over o2
[ "o1", "takes", "precedence", "over", "o2" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L1121-L1132
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function(constructor, methods) { var key; for (key in methods) { constructor.prototype[key] = methods[key]; } }
javascript
function(constructor, methods) { var key; for (key in methods) { constructor.prototype[key] = methods[key]; } }
[ "function", "(", "constructor", ",", "methods", ")", "{", "var", "key", ";", "for", "(", "key", "in", "methods", ")", "{", "constructor", ".", "prototype", "[", "key", "]", "=", "methods", "[", "key", "]", ";", "}", "}" ]
adds methods to a constructor prototype @method @memberof Kinetic.Util.prototype @param {Function} constructor @param {Object} methods
[ "adds", "methods", "to", "a", "constructor", "prototype" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L1185-L1191
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function(mimeType, quality) { try { // If this call fails (due to browser bug, like in Firefox 3.6), // then revert to previous no-parameter image/png behavior return this._canvas.toDataURL(mimeType, quality); } catch(e) { try { return this._canvas.toDataURL(); } catch(err) { Kinetic.Util.warn('Unable to get data URL. ' + err.message); return ''; } } }
javascript
function(mimeType, quality) { try { // If this call fails (due to browser bug, like in Firefox 3.6), // then revert to previous no-parameter image/png behavior return this._canvas.toDataURL(mimeType, quality); } catch(e) { try { return this._canvas.toDataURL(); } catch(err) { Kinetic.Util.warn('Unable to get data URL. ' + err.message); return ''; } } }
[ "function", "(", "mimeType", ",", "quality", ")", "{", "try", "{", "return", "this", ".", "_canvas", ".", "toDataURL", "(", "mimeType", ",", "quality", ")", ";", "}", "catch", "(", "e", ")", "{", "try", "{", "return", "this", ".", "_canvas", ".", "toDataURL", "(", ")", ";", "}", "catch", "(", "err", ")", "{", "Kinetic", ".", "Util", ".", "warn", "(", "'Unable to get data URL. '", "+", "err", ".", "message", ")", ";", "return", "''", ";", "}", "}", "}" ]
to data url @method @memberof Kinetic.Canvas.prototype @param {String} mimeType @param {Number} quality between 0 and 1 for jpg mime types @returns {String} data url string
[ "to", "data", "url" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L1376-L1391
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function(shape) { var fillEnabled = shape.getFillEnabled(); if(fillEnabled) { this._fill(shape); } if(shape.getStrokeEnabled()) { this._stroke(shape); } }
javascript
function(shape) { var fillEnabled = shape.getFillEnabled(); if(fillEnabled) { this._fill(shape); } if(shape.getStrokeEnabled()) { this._stroke(shape); } }
[ "function", "(", "shape", ")", "{", "var", "fillEnabled", "=", "shape", ".", "getFillEnabled", "(", ")", ";", "if", "(", "fillEnabled", ")", "{", "this", ".", "_fill", "(", "shape", ")", ";", "}", "if", "(", "shape", ".", "getStrokeEnabled", "(", ")", ")", "{", "this", ".", "_stroke", "(", "shape", ")", ";", "}", "}" ]
fill then stroke @method @memberof Kinetic.Context.prototype @param {Kinetic.Shape} shape
[ "fill", "then", "stroke" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L1526-L1534
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function(relaxed) { var traceArr = this.traceArr, len = traceArr.length, str = '', n, trace, method, args; for (n=0; n<len; n++) { trace = traceArr[n]; method = trace.method; // methods if (method) { args = trace.args; str += method; if (relaxed) { str += DOUBLE_PAREN; } else { if (Kinetic.Util._isArray(args[0])) { str += OPEN_PAREN_BRACKET + args.join(COMMA) + CLOSE_BRACKET_PAREN; } else { str += OPEN_PAREN + args.join(COMMA) + CLOSE_PAREN; } } } // properties else { str += trace.property; if (!relaxed) { str += EQUALS + trace.val; } } str += SEMICOLON; } return str; }
javascript
function(relaxed) { var traceArr = this.traceArr, len = traceArr.length, str = '', n, trace, method, args; for (n=0; n<len; n++) { trace = traceArr[n]; method = trace.method; // methods if (method) { args = trace.args; str += method; if (relaxed) { str += DOUBLE_PAREN; } else { if (Kinetic.Util._isArray(args[0])) { str += OPEN_PAREN_BRACKET + args.join(COMMA) + CLOSE_BRACKET_PAREN; } else { str += OPEN_PAREN + args.join(COMMA) + CLOSE_PAREN; } } } // properties else { str += trace.property; if (!relaxed) { str += EQUALS + trace.val; } } str += SEMICOLON; } return str; }
[ "function", "(", "relaxed", ")", "{", "var", "traceArr", "=", "this", ".", "traceArr", ",", "len", "=", "traceArr", ".", "length", ",", "str", "=", "''", ",", "n", ",", "trace", ",", "method", ",", "args", ";", "for", "(", "n", "=", "0", ";", "n", "<", "len", ";", "n", "++", ")", "{", "trace", "=", "traceArr", "[", "n", "]", ";", "method", "=", "trace", ".", "method", ";", "if", "(", "method", ")", "{", "args", "=", "trace", ".", "args", ";", "str", "+=", "method", ";", "if", "(", "relaxed", ")", "{", "str", "+=", "DOUBLE_PAREN", ";", "}", "else", "{", "if", "(", "Kinetic", ".", "Util", ".", "_isArray", "(", "args", "[", "0", "]", ")", ")", "{", "str", "+=", "OPEN_PAREN_BRACKET", "+", "args", ".", "join", "(", "COMMA", ")", "+", "CLOSE_BRACKET_PAREN", ";", "}", "else", "{", "str", "+=", "OPEN_PAREN", "+", "args", ".", "join", "(", "COMMA", ")", "+", "CLOSE_PAREN", ";", "}", "}", "}", "else", "{", "str", "+=", "trace", ".", "property", ";", "if", "(", "!", "relaxed", ")", "{", "str", "+=", "EQUALS", "+", "trace", ".", "val", ";", "}", "}", "str", "+=", "SEMICOLON", ";", "}", "return", "str", ";", "}" ]
get context trace if trace is enabled @method @memberof Kinetic.Context.prototype @param {Boolean} relaxed if false, return strict context trace, which includes method names, method parameters properties, and property values. If true, return relaxed context trace, which only returns method names and properites. @returns {String}
[ "get", "context", "trace", "if", "trace", "is", "enabled" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L1544-L1582
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function() { var a = arguments; this._context.arc(a[0], a[1], a[2], a[3], a[4], a[5]); }
javascript
function() { var a = arguments; this._context.arc(a[0], a[1], a[2], a[3], a[4], a[5]); }
[ "function", "(", ")", "{", "var", "a", "=", "arguments", ";", "this", ".", "_context", ".", "arc", "(", "a", "[", "0", "]", ",", "a", "[", "1", "]", ",", "a", "[", "2", "]", ",", "a", "[", "3", "]", ",", "a", "[", "4", "]", ",", "a", "[", "5", "]", ")", ";", "}" ]
context pass through methods
[ "context", "pass", "through", "methods" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L1663-L1666
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function(methodName) { var origMethod = that[methodName], ret; that[methodName] = function() { args = _simplifyArray(Array.prototype.slice.call(arguments, 0)); ret = origMethod.apply(that, arguments); that._trace({ method: methodName, args: args }); return ret; }; }
javascript
function(methodName) { var origMethod = that[methodName], ret; that[methodName] = function() { args = _simplifyArray(Array.prototype.slice.call(arguments, 0)); ret = origMethod.apply(that, arguments); that._trace({ method: methodName, args: args }); return ret; }; }
[ "function", "(", "methodName", ")", "{", "var", "origMethod", "=", "that", "[", "methodName", "]", ",", "ret", ";", "that", "[", "methodName", "]", "=", "function", "(", ")", "{", "args", "=", "_simplifyArray", "(", "Array", ".", "prototype", ".", "slice", ".", "call", "(", "arguments", ",", "0", ")", ")", ";", "ret", "=", "origMethod", ".", "apply", "(", "that", ",", "arguments", ")", ";", "that", ".", "_trace", "(", "{", "method", ":", "methodName", ",", "args", ":", "args", "}", ")", ";", "return", "ret", ";", "}", ";", "}" ]
to prevent creating scope function at each loop
[ "to", "prevent", "creating", "scope", "function", "at", "each", "loop" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L1810-L1825
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function(evt) { var e = { target: this, type: evt.type, evt: evt }; this.fire(evt.type, e); }
javascript
function(evt) { var e = { target: this, type: evt.type, evt: evt }; this.fire(evt.type, e); }
[ "function", "(", "evt", ")", "{", "var", "e", "=", "{", "target", ":", "this", ",", "type", ":", "evt", ".", "type", ",", "evt", ":", "evt", "}", ";", "this", ".", "fire", "(", "evt", ".", "type", ",", "e", ")", ";", "}" ]
some event aliases for third party integration like HammerJS
[ "some", "event", "aliases", "for", "third", "party", "integration", "like", "HammerJS" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L2608-L2615
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function() { var parent = this.getParent(); if(parent && parent.children) { parent.children.splice(this.index, 1); parent._setChildrenIndices(); delete this.parent; } // every cached attr that is calculated via node tree // traversal must be cleared when removing a node this._clearSelfAndDescendantCache(STAGE); this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM); this._clearSelfAndDescendantCache(VISIBLE); this._clearSelfAndDescendantCache(LISTENING); this._clearSelfAndDescendantCache(ABSOLUTE_OPACITY); return this; }
javascript
function() { var parent = this.getParent(); if(parent && parent.children) { parent.children.splice(this.index, 1); parent._setChildrenIndices(); delete this.parent; } // every cached attr that is calculated via node tree // traversal must be cleared when removing a node this._clearSelfAndDescendantCache(STAGE); this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM); this._clearSelfAndDescendantCache(VISIBLE); this._clearSelfAndDescendantCache(LISTENING); this._clearSelfAndDescendantCache(ABSOLUTE_OPACITY); return this; }
[ "function", "(", ")", "{", "var", "parent", "=", "this", ".", "getParent", "(", ")", ";", "if", "(", "parent", "&&", "parent", ".", "children", ")", "{", "parent", ".", "children", ".", "splice", "(", "this", ".", "index", ",", "1", ")", ";", "parent", ".", "_setChildrenIndices", "(", ")", ";", "delete", "this", ".", "parent", ";", "}", "this", ".", "_clearSelfAndDescendantCache", "(", "STAGE", ")", ";", "this", ".", "_clearSelfAndDescendantCache", "(", "ABSOLUTE_TRANSFORM", ")", ";", "this", ".", "_clearSelfAndDescendantCache", "(", "VISIBLE", ")", ";", "this", ".", "_clearSelfAndDescendantCache", "(", "LISTENING", ")", ";", "this", ".", "_clearSelfAndDescendantCache", "(", "ABSOLUTE_OPACITY", ")", ";", "return", "this", ";", "}" ]
remove self from parent, but don't destroy @method @memberof Kinetic.Node.prototype @returns {Kinetic.Node} @example node.remove();
[ "remove", "self", "from", "parent", "but", "don", "t", "destroy" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L2630-L2648
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function(config) { var key, method; if(config) { for(key in config) { if (key === CHILDREN) { } else { method = SET + Kinetic.Util._capitalize(key); // use setter if available if(Kinetic.Util._isFunction(this[method])) { this[method](config[key]); } // otherwise set directly else { this._setAttr(key, config[key]); } } } } return this; }
javascript
function(config) { var key, method; if(config) { for(key in config) { if (key === CHILDREN) { } else { method = SET + Kinetic.Util._capitalize(key); // use setter if available if(Kinetic.Util._isFunction(this[method])) { this[method](config[key]); } // otherwise set directly else { this._setAttr(key, config[key]); } } } } return this; }
[ "function", "(", "config", ")", "{", "var", "key", ",", "method", ";", "if", "(", "config", ")", "{", "for", "(", "key", "in", "config", ")", "{", "if", "(", "key", "===", "CHILDREN", ")", "{", "}", "else", "{", "method", "=", "SET", "+", "Kinetic", ".", "Util", ".", "_capitalize", "(", "key", ")", ";", "if", "(", "Kinetic", ".", "Util", ".", "_isFunction", "(", "this", "[", "method", "]", ")", ")", "{", "this", "[", "method", "]", "(", "config", "[", "key", "]", ")", ";", "}", "else", "{", "this", ".", "_setAttr", "(", "key", ",", "config", "[", "key", "]", ")", ";", "}", "}", "}", "}", "return", "this", ";", "}" ]
set multiple attrs at once using an object literal @method @memberof Kinetic.Node.prototype @param {Object} config object containing key value pairs @returns {Kinetic.Node} @example node.setAttrs({<br> x: 5,<br> fill: 'red'<br> });<br>
[ "set", "multiple", "attrs", "at", "once", "using", "an", "object", "literal" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L2724-L2746
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function() { var depth = this.getDepth(), that = this, index = 0, nodes, len, n, child; function addChildren(children) { nodes = []; len = children.length; for(n = 0; n < len; n++) { child = children[n]; index++; if(child.nodeType !== SHAPE) { nodes = nodes.concat(child.getChildren().toArray()); } if(child._id === that._id) { n = len; } } if(nodes.length > 0 && nodes[0].getDepth() <= depth) { addChildren(nodes); } } if(that.nodeType !== UPPER_STAGE) { addChildren(that.getStage().getChildren()); } return index; }
javascript
function() { var depth = this.getDepth(), that = this, index = 0, nodes, len, n, child; function addChildren(children) { nodes = []; len = children.length; for(n = 0; n < len; n++) { child = children[n]; index++; if(child.nodeType !== SHAPE) { nodes = nodes.concat(child.getChildren().toArray()); } if(child._id === that._id) { n = len; } } if(nodes.length > 0 && nodes[0].getDepth() <= depth) { addChildren(nodes); } } if(that.nodeType !== UPPER_STAGE) { addChildren(that.getStage().getChildren()); } return index; }
[ "function", "(", ")", "{", "var", "depth", "=", "this", ".", "getDepth", "(", ")", ",", "that", "=", "this", ",", "index", "=", "0", ",", "nodes", ",", "len", ",", "n", ",", "child", ";", "function", "addChildren", "(", "children", ")", "{", "nodes", "=", "[", "]", ";", "len", "=", "children", ".", "length", ";", "for", "(", "n", "=", "0", ";", "n", "<", "len", ";", "n", "++", ")", "{", "child", "=", "children", "[", "n", "]", ";", "index", "++", ";", "if", "(", "child", ".", "nodeType", "!==", "SHAPE", ")", "{", "nodes", "=", "nodes", ".", "concat", "(", "child", ".", "getChildren", "(", ")", ".", "toArray", "(", ")", ")", ";", "}", "if", "(", "child", ".", "_id", "===", "that", ".", "_id", ")", "{", "n", "=", "len", ";", "}", "}", "if", "(", "nodes", ".", "length", ">", "0", "&&", "nodes", "[", "0", "]", ".", "getDepth", "(", ")", "<=", "depth", ")", "{", "addChildren", "(", "nodes", ")", ";", "}", "}", "if", "(", "that", ".", "nodeType", "!==", "UPPER_STAGE", ")", "{", "addChildren", "(", "that", ".", "getStage", "(", ")", ".", "getChildren", "(", ")", ")", ";", "}", "return", "index", ";", "}" ]
get absolute z-index which takes into account sibling and ancestor indices @method @memberof Kinetic.Node.prototype @returns {Integer}
[ "get", "absolute", "z", "-", "index", "which", "takes", "into", "account", "sibling", "and", "ancestor", "indices" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L2874-L2905
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function() { var absoluteMatrix = this.getAbsoluteTransform().getMatrix(), absoluteTransform = new Kinetic.Transform(), offset = this.offset(); // clone the matrix array absoluteTransform.m = absoluteMatrix.slice(); absoluteTransform.translate(offset.x, offset.y); return absoluteTransform.getTranslation(); }
javascript
function() { var absoluteMatrix = this.getAbsoluteTransform().getMatrix(), absoluteTransform = new Kinetic.Transform(), offset = this.offset(); // clone the matrix array absoluteTransform.m = absoluteMatrix.slice(); absoluteTransform.translate(offset.x, offset.y); return absoluteTransform.getTranslation(); }
[ "function", "(", ")", "{", "var", "absoluteMatrix", "=", "this", ".", "getAbsoluteTransform", "(", ")", ".", "getMatrix", "(", ")", ",", "absoluteTransform", "=", "new", "Kinetic", ".", "Transform", "(", ")", ",", "offset", "=", "this", ".", "offset", "(", ")", ";", "absoluteTransform", ".", "m", "=", "absoluteMatrix", ".", "slice", "(", ")", ";", "absoluteTransform", ".", "translate", "(", "offset", ".", "x", ",", "offset", ".", "y", ")", ";", "return", "absoluteTransform", ".", "getTranslation", "(", ")", ";", "}" ]
get absolute position relative to the top left corner of the stage container div @method @memberof Kinetic.Node.prototype @returns {Object}
[ "get", "absolute", "position", "relative", "to", "the", "top", "left", "corner", "of", "the", "stage", "container", "div" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L2941-L2951
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function(pos) { var origTrans = this._clearTransform(), it; // don't clear translation this.attrs.x = origTrans.x; this.attrs.y = origTrans.y; delete origTrans.x; delete origTrans.y; // unravel transform it = this.getAbsoluteTransform(); it.invert(); it.translate(pos.x, pos.y); pos = { x: this.attrs.x + it.getTranslation().x, y: this.attrs.y + it.getTranslation().y }; this.setPosition({x:pos.x, y:pos.y}); this._setTransform(origTrans); return this; }
javascript
function(pos) { var origTrans = this._clearTransform(), it; // don't clear translation this.attrs.x = origTrans.x; this.attrs.y = origTrans.y; delete origTrans.x; delete origTrans.y; // unravel transform it = this.getAbsoluteTransform(); it.invert(); it.translate(pos.x, pos.y); pos = { x: this.attrs.x + it.getTranslation().x, y: this.attrs.y + it.getTranslation().y }; this.setPosition({x:pos.x, y:pos.y}); this._setTransform(origTrans); return this; }
[ "function", "(", "pos", ")", "{", "var", "origTrans", "=", "this", ".", "_clearTransform", "(", ")", ",", "it", ";", "this", ".", "attrs", ".", "x", "=", "origTrans", ".", "x", ";", "this", ".", "attrs", ".", "y", "=", "origTrans", ".", "y", ";", "delete", "origTrans", ".", "x", ";", "delete", "origTrans", ".", "y", ";", "it", "=", "this", ".", "getAbsoluteTransform", "(", ")", ";", "it", ".", "invert", "(", ")", ";", "it", ".", "translate", "(", "pos", ".", "x", ",", "pos", ".", "y", ")", ";", "pos", "=", "{", "x", ":", "this", ".", "attrs", ".", "x", "+", "it", ".", "getTranslation", "(", ")", ".", "x", ",", "y", ":", "this", ".", "attrs", ".", "y", "+", "it", ".", "getTranslation", "(", ")", ".", "y", "}", ";", "this", ".", "setPosition", "(", "{", "x", ":", "pos", ".", "x", ",", "y", ":", "pos", ".", "y", "}", ")", ";", "this", ".", "_setTransform", "(", "origTrans", ")", ";", "return", "this", ";", "}" ]
set absolute position @method @memberof Kinetic.Node.prototype @param {Object} pos @param {Number} pos.x @param {Number} pos.y @returns {Kinetic.Node}
[ "set", "absolute", "position" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L2961-L2985
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function(change) { var changeX = change.x, changeY = change.y, x = this.getX(), y = this.getY(); if(changeX !== undefined) { x += changeX; } if(changeY !== undefined) { y += changeY; } this.setPosition({x:x, y:y}); return this; }
javascript
function(change) { var changeX = change.x, changeY = change.y, x = this.getX(), y = this.getY(); if(changeX !== undefined) { x += changeX; } if(changeY !== undefined) { y += changeY; } this.setPosition({x:x, y:y}); return this; }
[ "function", "(", "change", ")", "{", "var", "changeX", "=", "change", ".", "x", ",", "changeY", "=", "change", ".", "y", ",", "x", "=", "this", ".", "getX", "(", ")", ",", "y", "=", "this", ".", "getY", "(", ")", ";", "if", "(", "changeX", "!==", "undefined", ")", "{", "x", "+=", "changeX", ";", "}", "if", "(", "changeY", "!==", "undefined", ")", "{", "y", "+=", "changeY", ";", "}", "this", ".", "setPosition", "(", "{", "x", ":", "x", ",", "y", ":", "y", "}", ")", ";", "return", "this", ";", "}" ]
move node by an amount relative to its current position @method @memberof Kinetic.Node.prototype @param {Object} change @param {Number} change.x @param {Number} change.y @returns {Kinetic.Node} @example // move node in x direction by 1px and y direction by 2px<br> node.move({<br> x: 1,<br> y: 2)<br> });
[ "move", "node", "by", "an", "amount", "relative", "to", "its", "current", "position" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L3040-L3056
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function() { if (!this.parent) { Kinetic.Util.warn('Node has no parent. moveToTop function is ignored.'); return; } var index = this.index; this.parent.children.splice(index, 1); this.parent.children.push(this); this.parent._setChildrenIndices(); return true; }
javascript
function() { if (!this.parent) { Kinetic.Util.warn('Node has no parent. moveToTop function is ignored.'); return; } var index = this.index; this.parent.children.splice(index, 1); this.parent.children.push(this); this.parent._setChildrenIndices(); return true; }
[ "function", "(", ")", "{", "if", "(", "!", "this", ".", "parent", ")", "{", "Kinetic", ".", "Util", ".", "warn", "(", "'Node has no parent. moveToTop function is ignored.'", ")", ";", "return", ";", "}", "var", "index", "=", "this", ".", "index", ";", "this", ".", "parent", ".", "children", ".", "splice", "(", "index", ",", "1", ")", ";", "this", ".", "parent", ".", "children", ".", "push", "(", "this", ")", ";", "this", ".", "parent", ".", "_setChildrenIndices", "(", ")", ";", "return", "true", ";", "}" ]
move node to the top of its siblings @method @memberof Kinetic.Node.prototype @returns {Boolean}
[ "move", "node", "to", "the", "top", "of", "its", "siblings" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L3099-L3109
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function() { if (!this.parent) { Kinetic.Util.warn('Node has no parent. moveUp function is ignored.'); return; } var index = this.index, len = this.parent.getChildren().length; if(index < len - 1) { this.parent.children.splice(index, 1); this.parent.children.splice(index + 1, 0, this); this.parent._setChildrenIndices(); return true; } return false; }
javascript
function() { if (!this.parent) { Kinetic.Util.warn('Node has no parent. moveUp function is ignored.'); return; } var index = this.index, len = this.parent.getChildren().length; if(index < len - 1) { this.parent.children.splice(index, 1); this.parent.children.splice(index + 1, 0, this); this.parent._setChildrenIndices(); return true; } return false; }
[ "function", "(", ")", "{", "if", "(", "!", "this", ".", "parent", ")", "{", "Kinetic", ".", "Util", ".", "warn", "(", "'Node has no parent. moveUp function is ignored.'", ")", ";", "return", ";", "}", "var", "index", "=", "this", ".", "index", ",", "len", "=", "this", ".", "parent", ".", "getChildren", "(", ")", ".", "length", ";", "if", "(", "index", "<", "len", "-", "1", ")", "{", "this", ".", "parent", ".", "children", ".", "splice", "(", "index", ",", "1", ")", ";", "this", ".", "parent", ".", "children", ".", "splice", "(", "index", "+", "1", ",", "0", ",", "this", ")", ";", "this", ".", "parent", ".", "_setChildrenIndices", "(", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
move node up @method @memberof Kinetic.Node.prototype @returns {Boolean}
[ "move", "node", "up" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L3116-L3130
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function(zIndex) { if (!this.parent) { Kinetic.Util.warn('Node has no parent. zIndex parameter is ignored.'); return; } var index = this.index; this.parent.children.splice(index, 1); this.parent.children.splice(zIndex, 0, this); this.parent._setChildrenIndices(); return this; }
javascript
function(zIndex) { if (!this.parent) { Kinetic.Util.warn('Node has no parent. zIndex parameter is ignored.'); return; } var index = this.index; this.parent.children.splice(index, 1); this.parent.children.splice(zIndex, 0, this); this.parent._setChildrenIndices(); return this; }
[ "function", "(", "zIndex", ")", "{", "if", "(", "!", "this", ".", "parent", ")", "{", "Kinetic", ".", "Util", ".", "warn", "(", "'Node has no parent. zIndex parameter is ignored.'", ")", ";", "return", ";", "}", "var", "index", "=", "this", ".", "index", ";", "this", ".", "parent", ".", "children", ".", "splice", "(", "index", ",", "1", ")", ";", "this", ".", "parent", ".", "children", ".", "splice", "(", "zIndex", ",", "0", ",", "this", ")", ";", "this", ".", "parent", ".", "_setChildrenIndices", "(", ")", ";", "return", "this", ";", "}" ]
set zIndex relative to siblings @method @memberof Kinetic.Node.prototype @param {Integer} zIndex @returns {Kinetic.Node}
[ "set", "zIndex", "relative", "to", "siblings" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L3178-L3188
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function() { var type = Kinetic.Util, obj = {}, attrs = this.getAttrs(), key, val, getter, defaultValue; obj.attrs = {}; // serialize only attributes that are not function, image, DOM, or objects with methods for(key in attrs) { val = attrs[key]; if (!type._isFunction(val) && !type._isElement(val) && !(type._isObject(val) && type._hasMethods(val))) { getter = this[key]; // remove attr value so that we can extract the default value from the getter delete attrs[key]; defaultValue = getter ? getter.call(this) : null; // restore attr value attrs[key] = val; if (defaultValue !== val) { obj.attrs[key] = val; } } } obj.className = this.getClassName(); return obj; }
javascript
function() { var type = Kinetic.Util, obj = {}, attrs = this.getAttrs(), key, val, getter, defaultValue; obj.attrs = {}; // serialize only attributes that are not function, image, DOM, or objects with methods for(key in attrs) { val = attrs[key]; if (!type._isFunction(val) && !type._isElement(val) && !(type._isObject(val) && type._hasMethods(val))) { getter = this[key]; // remove attr value so that we can extract the default value from the getter delete attrs[key]; defaultValue = getter ? getter.call(this) : null; // restore attr value attrs[key] = val; if (defaultValue !== val) { obj.attrs[key] = val; } } } obj.className = this.getClassName(); return obj; }
[ "function", "(", ")", "{", "var", "type", "=", "Kinetic", ".", "Util", ",", "obj", "=", "{", "}", ",", "attrs", "=", "this", ".", "getAttrs", "(", ")", ",", "key", ",", "val", ",", "getter", ",", "defaultValue", ";", "obj", ".", "attrs", "=", "{", "}", ";", "for", "(", "key", "in", "attrs", ")", "{", "val", "=", "attrs", "[", "key", "]", ";", "if", "(", "!", "type", ".", "_isFunction", "(", "val", ")", "&&", "!", "type", ".", "_isElement", "(", "val", ")", "&&", "!", "(", "type", ".", "_isObject", "(", "val", ")", "&&", "type", ".", "_hasMethods", "(", "val", ")", ")", ")", "{", "getter", "=", "this", "[", "key", "]", ";", "delete", "attrs", "[", "key", "]", ";", "defaultValue", "=", "getter", "?", "getter", ".", "call", "(", "this", ")", ":", "null", ";", "attrs", "[", "key", "]", "=", "val", ";", "if", "(", "defaultValue", "!==", "val", ")", "{", "obj", ".", "attrs", "[", "key", "]", "=", "val", ";", "}", "}", "}", "obj", ".", "className", "=", "this", ".", "getClassName", "(", ")", ";", "return", "obj", ";", "}" ]
convert Node into an object for serialization. Returns an object. @method @memberof Kinetic.Node.prototype @returns {Object}
[ "convert", "Node", "into", "an", "object", "for", "serialization", ".", "Returns", "an", "object", "." ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L3226-L3252
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function(config) { Kinetic.Util._getImage(this.toDataURL(config), function(img) { config.callback(img); }); }
javascript
function(config) { Kinetic.Util._getImage(this.toDataURL(config), function(img) { config.callback(img); }); }
[ "function", "(", "config", ")", "{", "Kinetic", ".", "Util", ".", "_getImage", "(", "this", ".", "toDataURL", "(", "config", ")", ",", "function", "(", "img", ")", "{", "config", ".", "callback", "(", "img", ")", ";", "}", ")", ";", "}" ]
converts node into an image. Since the toImage method is asynchronous, a callback is required. toImage is most commonly used to cache complex drawings as an image so that they don't have to constantly be redrawn @method @memberof Kinetic.Node.prototype @param {Object} config @param {Function} config.callback function executed when the composite has completed @param {String} [config.mimeType] can be "image/png" or "image/jpeg". "image/png" is the default @param {Number} [config.x] x position of canvas section @param {Number} [config.y] y position of canvas section @param {Number} [config.width] width of canvas section @param {Number} [config.height] height of canvas section @param {Number} [config.quality] jpeg quality. If using an "image/jpeg" mimeType, you can specify the quality from 0 to 1, where 0 is very poor quality and 1 is very high quality @example var image = node.toImage({<br> callback: function(img) {<br> // do stuff with img<br> }<br> });
[ "converts", "node", "into", "an", "image", ".", "Since", "the", "toImage", "method", "is", "asynchronous", "a", "callback", "is", "required", ".", "toImage", "is", "most", "commonly", "used", "to", "cache", "complex", "drawings", "as", "an", "image", "so", "that", "they", "don", "t", "have", "to", "constantly", "be", "redrawn" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L3530-L3534
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function(layers) { var lays = []; // if passing in no layers if (!layers) { lays = []; } // if passing in an array of Layers // NOTE: layers could be an array or Kinetic.Collection. for simplicity, I'm just inspecting // the length property to check for both cases else if (layers.length > 0) { lays = layers; } // if passing in a Layer else { lays = [layers]; } this.layers = lays; }
javascript
function(layers) { var lays = []; // if passing in no layers if (!layers) { lays = []; } // if passing in an array of Layers // NOTE: layers could be an array or Kinetic.Collection. for simplicity, I'm just inspecting // the length property to check for both cases else if (layers.length > 0) { lays = layers; } // if passing in a Layer else { lays = [layers]; } this.layers = lays; }
[ "function", "(", "layers", ")", "{", "var", "lays", "=", "[", "]", ";", "if", "(", "!", "layers", ")", "{", "lays", "=", "[", "]", ";", "}", "else", "if", "(", "layers", ".", "length", ">", "0", ")", "{", "lays", "=", "layers", ";", "}", "else", "{", "lays", "=", "[", "layers", "]", ";", "}", "this", ".", "layers", "=", "lays", ";", "}" ]
set layers to be redrawn on each animation frame @method @memberof Kinetic.Animation.prototype @param {Kinetic.Layer|Array} [layers] layer(s) to be redrawn.&nbsp; Can be a layer, an array of layers, or null. Not specifying a node will result in no redraw.
[ "set", "layers", "to", "be", "redrawn", "on", "each", "animation", "frame" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L6039-L6057
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function(layer) { var layers = this.layers, len, n; if (layers) { len = layers.length; // don't add the layer if it already exists for (n = 0; n < len; n++) { if (layers[n]._id === layer._id) { return false; } } } else { this.layers = []; } this.layers.push(layer); return true; }
javascript
function(layer) { var layers = this.layers, len, n; if (layers) { len = layers.length; // don't add the layer if it already exists for (n = 0; n < len; n++) { if (layers[n]._id === layer._id) { return false; } } } else { this.layers = []; } this.layers.push(layer); return true; }
[ "function", "(", "layer", ")", "{", "var", "layers", "=", "this", ".", "layers", ",", "len", ",", "n", ";", "if", "(", "layers", ")", "{", "len", "=", "layers", ".", "length", ";", "for", "(", "n", "=", "0", ";", "n", "<", "len", ";", "n", "++", ")", "{", "if", "(", "layers", "[", "n", "]", ".", "_id", "===", "layer", ".", "_id", ")", "{", "return", "false", ";", "}", "}", "}", "else", "{", "this", ".", "layers", "=", "[", "]", ";", "}", "this", ".", "layers", ".", "push", "(", "layer", ")", ";", "return", "true", ";", "}" ]
add layer. Returns true if the layer was added, and false if it was not @method @memberof Kinetic.Animation.prototype @param {Kinetic.Layer} layer
[ "add", "layer", ".", "Returns", "true", "if", "the", "layer", "was", "added", "and", "false", "if", "it", "was", "not" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L6072-L6092
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function() { var a = Kinetic.Animation, animations = a.animations, len = animations.length, n; for(n = 0; n < len; n++) { if(animations[n].id === this.id) { return true; } } return false; }
javascript
function() { var a = Kinetic.Animation, animations = a.animations, len = animations.length, n; for(n = 0; n < len; n++) { if(animations[n].id === this.id) { return true; } } return false; }
[ "function", "(", ")", "{", "var", "a", "=", "Kinetic", ".", "Animation", ",", "animations", "=", "a", ".", "animations", ",", "len", "=", "animations", ".", "length", ",", "n", ";", "for", "(", "n", "=", "0", ";", "n", "<", "len", ";", "n", "++", ")", "{", "if", "(", "animations", "[", "n", "]", ".", "id", "===", "this", ".", "id", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
determine if animation is running or not. returns true or false @method @memberof Kinetic.Animation.prototype
[ "determine", "if", "animation", "is", "running", "or", "not", ".", "returns", "true", "or", "false" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L6098-L6110
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function(t, b, c, d) { return c - Kinetic.Easings.BounceEaseOut(d - t, 0, c, d) + b; }
javascript
function(t, b, c, d) { return c - Kinetic.Easings.BounceEaseOut(d - t, 0, c, d) + b; }
[ "function", "(", "t", ",", "b", ",", "c", ",", "d", ")", "{", "return", "c", "-", "Kinetic", ".", "Easings", ".", "BounceEaseOut", "(", "d", "-", "t", ",", "0", ",", "c", ",", "d", ")", "+", "b", ";", "}" ]
bounce ease in @function @memberof Kinetic.Easings
[ "bounce", "ease", "in" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L6778-L6780
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function(t, b, c, d) { if(t < d / 2) { return Kinetic.Easings.BounceEaseIn(t * 2, 0, c, d) * 0.5 + b; } else { return Kinetic.Easings.BounceEaseOut(t * 2 - d, 0, c, d) * 0.5 + c * 0.5 + b; } }
javascript
function(t, b, c, d) { if(t < d / 2) { return Kinetic.Easings.BounceEaseIn(t * 2, 0, c, d) * 0.5 + b; } else { return Kinetic.Easings.BounceEaseOut(t * 2 - d, 0, c, d) * 0.5 + c * 0.5 + b; } }
[ "function", "(", "t", ",", "b", ",", "c", ",", "d", ")", "{", "if", "(", "t", "<", "d", "/", "2", ")", "{", "return", "Kinetic", ".", "Easings", ".", "BounceEaseIn", "(", "t", "*", "2", ",", "0", ",", "c", ",", "d", ")", "*", "0.5", "+", "b", ";", "}", "else", "{", "return", "Kinetic", ".", "Easings", ".", "BounceEaseOut", "(", "t", "*", "2", "-", "d", ",", "0", ",", "c", ",", "d", ")", "*", "0.5", "+", "c", "*", "0.5", "+", "b", ";", "}", "}" ]
bounce ease in out @function @memberof Kinetic.Easings
[ "bounce", "ease", "in", "out" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L6786-L6793
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function() { var children = Kinetic.Collection.toCollection(this.children); var child; for (var i = 0; i < children.length; i++) { child = children[i]; // reset parent to prevent many _setChildrenIndices calls delete child.parent; child.index = 0; if (child.hasChildren()) { child.removeChildren(); } child.remove(); } children = null; this.children = new Kinetic.Collection(); return this; }
javascript
function() { var children = Kinetic.Collection.toCollection(this.children); var child; for (var i = 0; i < children.length; i++) { child = children[i]; // reset parent to prevent many _setChildrenIndices calls delete child.parent; child.index = 0; if (child.hasChildren()) { child.removeChildren(); } child.remove(); } children = null; this.children = new Kinetic.Collection(); return this; }
[ "function", "(", ")", "{", "var", "children", "=", "Kinetic", ".", "Collection", ".", "toCollection", "(", "this", ".", "children", ")", ";", "var", "child", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "children", ".", "length", ";", "i", "++", ")", "{", "child", "=", "children", "[", "i", "]", ";", "delete", "child", ".", "parent", ";", "child", ".", "index", "=", "0", ";", "if", "(", "child", ".", "hasChildren", "(", ")", ")", "{", "child", ".", "removeChildren", "(", ")", ";", "}", "child", ".", "remove", "(", ")", ";", "}", "children", "=", "null", ";", "this", ".", "children", "=", "new", "Kinetic", ".", "Collection", "(", ")", ";", "return", "this", ";", "}" ]
remove all children @method @memberof Kinetic.Container.prototype
[ "remove", "all", "children" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L7195-L7211
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function() { var children = Kinetic.Collection.toCollection(this.children); var child; for (var i = 0; i < children.length; i++) { child = children[i]; // reset parent to prevent many _setChildrenIndices calls delete child.parent; child.index = 0; child.destroy(); } children = null; this.children = new Kinetic.Collection(); return this; }
javascript
function() { var children = Kinetic.Collection.toCollection(this.children); var child; for (var i = 0; i < children.length; i++) { child = children[i]; // reset parent to prevent many _setChildrenIndices calls delete child.parent; child.index = 0; child.destroy(); } children = null; this.children = new Kinetic.Collection(); return this; }
[ "function", "(", ")", "{", "var", "children", "=", "Kinetic", ".", "Collection", ".", "toCollection", "(", "this", ".", "children", ")", ";", "var", "child", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "children", ".", "length", ";", "i", "++", ")", "{", "child", "=", "children", "[", "i", "]", ";", "delete", "child", ".", "parent", ";", "child", ".", "index", "=", "0", ";", "child", ".", "destroy", "(", ")", ";", "}", "children", "=", "null", ";", "this", ".", "children", "=", "new", "Kinetic", ".", "Collection", "(", ")", ";", "return", "this", ";", "}" ]
destroy all children @method @memberof Kinetic.Container.prototype
[ "destroy", "all", "children" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L7217-L7230
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function(child) { if (arguments.length > 1) { for (var i = 0; i < arguments.length; i++) { this.add(arguments[i]); } return; } if (child.getParent()) { child.moveTo(this); return; } var children = this.children; this._validateAdd(child); child.index = children.length; child.parent = this; children.push(child); this._fire('add', { child: child }); // chainable return this; }
javascript
function(child) { if (arguments.length > 1) { for (var i = 0; i < arguments.length; i++) { this.add(arguments[i]); } return; } if (child.getParent()) { child.moveTo(this); return; } var children = this.children; this._validateAdd(child); child.index = children.length; child.parent = this; children.push(child); this._fire('add', { child: child }); // chainable return this; }
[ "function", "(", "child", ")", "{", "if", "(", "arguments", ".", "length", ">", "1", ")", "{", "for", "(", "var", "i", "=", "0", ";", "i", "<", "arguments", ".", "length", ";", "i", "++", ")", "{", "this", ".", "add", "(", "arguments", "[", "i", "]", ")", ";", "}", "return", ";", "}", "if", "(", "child", ".", "getParent", "(", ")", ")", "{", "child", ".", "moveTo", "(", "this", ")", ";", "return", ";", "}", "var", "children", "=", "this", ".", "children", ";", "this", ".", "_validateAdd", "(", "child", ")", ";", "child", ".", "index", "=", "children", ".", "length", ";", "child", ".", "parent", "=", "this", ";", "children", ".", "push", "(", "child", ")", ";", "this", ".", "_fire", "(", "'add'", ",", "{", "child", ":", "child", "}", ")", ";", "return", "this", ";", "}" ]
Add node or nodes to container. @method @memberof Kinetic.Container.prototype @param {...Kinetic.Node} child @returns {Container} @example layer.add(shape1, shape2, shape3);
[ "Add", "node", "or", "nodes", "to", "container", "." ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L7240-L7262
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function(node) { var parent = node.getParent(); while(parent) { if(parent._id === this._id) { return true; } parent = parent.getParent(); } return false; }
javascript
function(node) { var parent = node.getParent(); while(parent) { if(parent._id === this._id) { return true; } parent = parent.getParent(); } return false; }
[ "function", "(", "node", ")", "{", "var", "parent", "=", "node", ".", "getParent", "(", ")", ";", "while", "(", "parent", ")", "{", "if", "(", "parent", ".", "_id", "===", "this", ".", "_id", ")", "{", "return", "true", ";", "}", "parent", "=", "parent", ".", "getParent", "(", ")", ";", "}", "return", "false", ";", "}" ]
determine if node is an ancestor of descendant @method @memberof Kinetic.Container.prototype @param {Kinetic.Node} node
[ "determine", "if", "node", "is", "an", "ancestor", "of", "descendant" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L7383-L7393
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function(alphaThreshold) { var threshold = alphaThreshold || 0, cachedCanvas = this._cache.canvas, sceneCanvas = this._getCachedSceneCanvas(), sceneContext = sceneCanvas.getContext(), hitCanvas = cachedCanvas.hit, hitContext = hitCanvas.getContext(), width = sceneCanvas.getWidth(), height = sceneCanvas.getHeight(), sceneImageData, sceneData, hitImageData, hitData, len, rgbColorKey, i, alpha; hitContext.clear(); try { sceneImageData = sceneContext.getImageData(0, 0, width, height); sceneData = sceneImageData.data; hitImageData = hitContext.getImageData(0, 0, width, height); hitData = hitImageData.data; len = sceneData.length; rgbColorKey = Kinetic.Util._hexToRgb(this.colorKey); // replace non transparent pixels with color key for(i = 0; i < len; i += 4) { alpha = sceneData[i + 3]; if (alpha > threshold) { hitData[i] = rgbColorKey.r; hitData[i + 1] = rgbColorKey.g; hitData[i + 2] = rgbColorKey.b; hitData[i + 3] = 255; } } hitContext.putImageData(hitImageData, 0, 0); } catch(e) { Kinetic.Util.warn('Unable to draw hit graph from cached scene canvas. ' + e.message); } return this; }
javascript
function(alphaThreshold) { var threshold = alphaThreshold || 0, cachedCanvas = this._cache.canvas, sceneCanvas = this._getCachedSceneCanvas(), sceneContext = sceneCanvas.getContext(), hitCanvas = cachedCanvas.hit, hitContext = hitCanvas.getContext(), width = sceneCanvas.getWidth(), height = sceneCanvas.getHeight(), sceneImageData, sceneData, hitImageData, hitData, len, rgbColorKey, i, alpha; hitContext.clear(); try { sceneImageData = sceneContext.getImageData(0, 0, width, height); sceneData = sceneImageData.data; hitImageData = hitContext.getImageData(0, 0, width, height); hitData = hitImageData.data; len = sceneData.length; rgbColorKey = Kinetic.Util._hexToRgb(this.colorKey); // replace non transparent pixels with color key for(i = 0; i < len; i += 4) { alpha = sceneData[i + 3]; if (alpha > threshold) { hitData[i] = rgbColorKey.r; hitData[i + 1] = rgbColorKey.g; hitData[i + 2] = rgbColorKey.b; hitData[i + 3] = 255; } } hitContext.putImageData(hitImageData, 0, 0); } catch(e) { Kinetic.Util.warn('Unable to draw hit graph from cached scene canvas. ' + e.message); } return this; }
[ "function", "(", "alphaThreshold", ")", "{", "var", "threshold", "=", "alphaThreshold", "||", "0", ",", "cachedCanvas", "=", "this", ".", "_cache", ".", "canvas", ",", "sceneCanvas", "=", "this", ".", "_getCachedSceneCanvas", "(", ")", ",", "sceneContext", "=", "sceneCanvas", ".", "getContext", "(", ")", ",", "hitCanvas", "=", "cachedCanvas", ".", "hit", ",", "hitContext", "=", "hitCanvas", ".", "getContext", "(", ")", ",", "width", "=", "sceneCanvas", ".", "getWidth", "(", ")", ",", "height", "=", "sceneCanvas", ".", "getHeight", "(", ")", ",", "sceneImageData", ",", "sceneData", ",", "hitImageData", ",", "hitData", ",", "len", ",", "rgbColorKey", ",", "i", ",", "alpha", ";", "hitContext", ".", "clear", "(", ")", ";", "try", "{", "sceneImageData", "=", "sceneContext", ".", "getImageData", "(", "0", ",", "0", ",", "width", ",", "height", ")", ";", "sceneData", "=", "sceneImageData", ".", "data", ";", "hitImageData", "=", "hitContext", ".", "getImageData", "(", "0", ",", "0", ",", "width", ",", "height", ")", ";", "hitData", "=", "hitImageData", ".", "data", ";", "len", "=", "sceneData", ".", "length", ";", "rgbColorKey", "=", "Kinetic", ".", "Util", ".", "_hexToRgb", "(", "this", ".", "colorKey", ")", ";", "for", "(", "i", "=", "0", ";", "i", "<", "len", ";", "i", "+=", "4", ")", "{", "alpha", "=", "sceneData", "[", "i", "+", "3", "]", ";", "if", "(", "alpha", ">", "threshold", ")", "{", "hitData", "[", "i", "]", "=", "rgbColorKey", ".", "r", ";", "hitData", "[", "i", "+", "1", "]", "=", "rgbColorKey", ".", "g", ";", "hitData", "[", "i", "+", "2", "]", "=", "rgbColorKey", ".", "b", ";", "hitData", "[", "i", "+", "3", "]", "=", "255", ";", "}", "}", "hitContext", ".", "putImageData", "(", "hitImageData", ",", "0", ",", "0", ")", ";", "}", "catch", "(", "e", ")", "{", "Kinetic", ".", "Util", ".", "warn", "(", "'Unable to draw hit graph from cached scene canvas. '", "+", "e", ".", "message", ")", ";", "}", "return", "this", ";", "}" ]
draw hit graph using the cached scene canvas @method @memberof Kinetic.Shape.prototype @param {Integer} alphaThreshold alpha channel threshold that determines whether or not a pixel should be drawn onto the hit graph. Must be a value between 0 and 255. The default is 0 @returns {Kinetic.Shape} @example shape.cache(); shape.drawHitFromCache();
[ "draw", "hit", "graph", "using", "the", "cached", "scene", "canvas" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L7822-L7861
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function(container) { if( typeof container === STRING) { var id = container; container = Kinetic.document.getElementById(container); if (!container) { throw 'Can not find container in document with id ' + id; } } this._setAttr(CONTAINER, container); return this; }
javascript
function(container) { if( typeof container === STRING) { var id = container; container = Kinetic.document.getElementById(container); if (!container) { throw 'Can not find container in document with id ' + id; } } this._setAttr(CONTAINER, container); return this; }
[ "function", "(", "container", ")", "{", "if", "(", "typeof", "container", "===", "STRING", ")", "{", "var", "id", "=", "container", ";", "container", "=", "Kinetic", ".", "document", ".", "getElementById", "(", "container", ")", ";", "if", "(", "!", "container", ")", "{", "throw", "'Can not find container in document with id '", "+", "id", ";", "}", "}", "this", ".", "_setAttr", "(", "CONTAINER", ",", "container", ")", ";", "return", "this", ";", "}" ]
set container dom element which contains the stage wrapper div element @method @memberof Kinetic.Stage.prototype @param {DomElement} container can pass in a dom element or id string
[ "set", "container", "dom", "element", "which", "contains", "the", "stage", "wrapper", "div", "element" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L9059-L9069
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function() { var layers = this.children, len = layers.length, n; for(n = 0; n < len; n++) { layers[n].clear(); } return this; }
javascript
function() { var layers = this.children, len = layers.length, n; for(n = 0; n < len; n++) { layers[n].clear(); } return this; }
[ "function", "(", ")", "{", "var", "layers", "=", "this", ".", "children", ",", "len", "=", "layers", ".", "length", ",", "n", ";", "for", "(", "n", "=", "0", ";", "n", "<", "len", ";", "n", "++", ")", "{", "layers", "[", "n", "]", ".", "clear", "(", ")", ";", "}", "return", "this", ";", "}" ]
clear all layers @method @memberof Kinetic.Stage.prototype
[ "clear", "all", "layers" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L9118-L9127
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function(config) { config = config || {}; var mimeType = config.mimeType || null, quality = config.quality || null, x = config.x || 0, y = config.y || 0, canvas = new Kinetic.SceneCanvas({ width: config.width || this.getWidth(), height: config.height || this.getHeight(), pixelRatio: 1 }), _context = canvas.getContext()._context, layers = this.children; if(x || y) { _context.translate(-1 * x, -1 * y); } function drawLayer(n) { var layer = layers[n], layerUrl = layer.toDataURL(), imageObj = new Kinetic.window.Image(); imageObj.onload = function() { _context.drawImage(imageObj, 0, 0); if(n < layers.length - 1) { drawLayer(n + 1); } else { config.callback(canvas.toDataURL(mimeType, quality)); } }; imageObj.src = layerUrl; } drawLayer(0); }
javascript
function(config) { config = config || {}; var mimeType = config.mimeType || null, quality = config.quality || null, x = config.x || 0, y = config.y || 0, canvas = new Kinetic.SceneCanvas({ width: config.width || this.getWidth(), height: config.height || this.getHeight(), pixelRatio: 1 }), _context = canvas.getContext()._context, layers = this.children; if(x || y) { _context.translate(-1 * x, -1 * y); } function drawLayer(n) { var layer = layers[n], layerUrl = layer.toDataURL(), imageObj = new Kinetic.window.Image(); imageObj.onload = function() { _context.drawImage(imageObj, 0, 0); if(n < layers.length - 1) { drawLayer(n + 1); } else { config.callback(canvas.toDataURL(mimeType, quality)); } }; imageObj.src = layerUrl; } drawLayer(0); }
[ "function", "(", "config", ")", "{", "config", "=", "config", "||", "{", "}", ";", "var", "mimeType", "=", "config", ".", "mimeType", "||", "null", ",", "quality", "=", "config", ".", "quality", "||", "null", ",", "x", "=", "config", ".", "x", "||", "0", ",", "y", "=", "config", ".", "y", "||", "0", ",", "canvas", "=", "new", "Kinetic", ".", "SceneCanvas", "(", "{", "width", ":", "config", ".", "width", "||", "this", ".", "getWidth", "(", ")", ",", "height", ":", "config", ".", "height", "||", "this", ".", "getHeight", "(", ")", ",", "pixelRatio", ":", "1", "}", ")", ",", "_context", "=", "canvas", ".", "getContext", "(", ")", ".", "_context", ",", "layers", "=", "this", ".", "children", ";", "if", "(", "x", "||", "y", ")", "{", "_context", ".", "translate", "(", "-", "1", "*", "x", ",", "-", "1", "*", "y", ")", ";", "}", "function", "drawLayer", "(", "n", ")", "{", "var", "layer", "=", "layers", "[", "n", "]", ",", "layerUrl", "=", "layer", ".", "toDataURL", "(", ")", ",", "imageObj", "=", "new", "Kinetic", ".", "window", ".", "Image", "(", ")", ";", "imageObj", ".", "onload", "=", "function", "(", ")", "{", "_context", ".", "drawImage", "(", "imageObj", ",", "0", ",", "0", ")", ";", "if", "(", "n", "<", "layers", ".", "length", "-", "1", ")", "{", "drawLayer", "(", "n", "+", "1", ")", ";", "}", "else", "{", "config", ".", "callback", "(", "canvas", ".", "toDataURL", "(", "mimeType", ",", "quality", ")", ")", ";", "}", "}", ";", "imageObj", ".", "src", "=", "layerUrl", ";", "}", "drawLayer", "(", "0", ")", ";", "}" ]
Creates a composite data URL and requires a callback because the composite is generated asynchronously. @method @memberof Kinetic.Stage.prototype @param {Object} config @param {Function} config.callback function executed when the composite has completed @param {String} [config.mimeType] can be "image/png" or "image/jpeg". "image/png" is the default @param {Number} [config.x] x position of canvas section @param {Number} [config.y] y position of canvas section @param {Number} [config.width] width of canvas section @param {Number} [config.height] height of canvas section @param {Number} [config.quality] jpeg quality. If using an "image/jpeg" mimeType, you can specify the quality from 0 to 1, where 0 is very poor quality and 1 is very high quality
[ "Creates", "a", "composite", "data", "URL", "and", "requires", "a", "callback", "because", "the", "composite", "is", "generated", "asynchronously", "." ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L9190-L9227
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function(config) { var cb = config.callback; config.callback = function(dataUrl) { Kinetic.Util._getImage(dataUrl, function(img) { cb(img); }); }; this.toDataURL(config); }
javascript
function(config) { var cb = config.callback; config.callback = function(dataUrl) { Kinetic.Util._getImage(dataUrl, function(img) { cb(img); }); }; this.toDataURL(config); }
[ "function", "(", "config", ")", "{", "var", "cb", "=", "config", ".", "callback", ";", "config", ".", "callback", "=", "function", "(", "dataUrl", ")", "{", "Kinetic", ".", "Util", ".", "_getImage", "(", "dataUrl", ",", "function", "(", "img", ")", "{", "cb", "(", "img", ")", ";", "}", ")", ";", "}", ";", "this", ".", "toDataURL", "(", "config", ")", ";", "}" ]
converts stage into an image. @method @memberof Kinetic.Stage.prototype @param {Object} config @param {Function} config.callback function executed when the composite has completed @param {String} [config.mimeType] can be "image/png" or "image/jpeg". "image/png" is the default @param {Number} [config.x] x position of canvas section @param {Number} [config.y] y position of canvas section @param {Number} [config.width] width of canvas section @param {Number} [config.height] height of canvas section @param {Number} [config.quality] jpeg quality. If using an "image/jpeg" mimeType, you can specify the quality from 0 to 1, where 0 is very poor quality and 1 is very high quality
[ "converts", "stage", "into", "an", "image", "." ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L9244-L9253
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function(layer) { if (arguments.length > 1) { for (var i = 0; i < arguments.length; i++) { this.add(arguments[i]); } return; } Kinetic.Container.prototype.add.call(this, layer); layer._setCanvasSize(this.width(), this.height()); // draw layer and append canvas to container layer.draw(); this.content.appendChild(layer.canvas._canvas); // chainable return this; }
javascript
function(layer) { if (arguments.length > 1) { for (var i = 0; i < arguments.length; i++) { this.add(arguments[i]); } return; } Kinetic.Container.prototype.add.call(this, layer); layer._setCanvasSize(this.width(), this.height()); // draw layer and append canvas to container layer.draw(); this.content.appendChild(layer.canvas._canvas); // chainable return this; }
[ "function", "(", "layer", ")", "{", "if", "(", "arguments", ".", "length", ">", "1", ")", "{", "for", "(", "var", "i", "=", "0", ";", "i", "<", "arguments", ".", "length", ";", "i", "++", ")", "{", "this", ".", "add", "(", "arguments", "[", "i", "]", ")", ";", "}", "return", ";", "}", "Kinetic", ".", "Container", ".", "prototype", ".", "add", ".", "call", "(", "this", ",", "layer", ")", ";", "layer", ".", "_setCanvasSize", "(", "this", ".", "width", "(", ")", ",", "this", ".", "height", "(", ")", ")", ";", "layer", ".", "draw", "(", ")", ";", "this", ".", "content", ".", "appendChild", "(", "layer", ".", "canvas", ".", "_canvas", ")", ";", "return", "this", ";", "}" ]
add layer or layers to stage @method @memberof Kinetic.Stage.prototype @param {...Kinetic.Layer} layer @example stage.add(layer1, layer2, layer3);
[ "add", "layer", "or", "layers", "to", "stage" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L9311-L9327
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function(index) { Kinetic.Node.prototype.setZIndex.call(this, index); var stage = this.getStage(); if(stage) { stage.content.removeChild(this.getCanvas()._canvas); if(index < stage.getChildren().length - 1) { stage.content.insertBefore(this.getCanvas()._canvas, stage.getChildren()[index + 1].getCanvas()._canvas); } else { stage.content.appendChild(this.getCanvas()._canvas); } } return this; }
javascript
function(index) { Kinetic.Node.prototype.setZIndex.call(this, index); var stage = this.getStage(); if(stage) { stage.content.removeChild(this.getCanvas()._canvas); if(index < stage.getChildren().length - 1) { stage.content.insertBefore(this.getCanvas()._canvas, stage.getChildren()[index + 1].getCanvas()._canvas); } else { stage.content.appendChild(this.getCanvas()._canvas); } } return this; }
[ "function", "(", "index", ")", "{", "Kinetic", ".", "Node", ".", "prototype", ".", "setZIndex", ".", "call", "(", "this", ",", "index", ")", ";", "var", "stage", "=", "this", ".", "getStage", "(", ")", ";", "if", "(", "stage", ")", "{", "stage", ".", "content", ".", "removeChild", "(", "this", ".", "getCanvas", "(", ")", ".", "_canvas", ")", ";", "if", "(", "index", "<", "stage", ".", "getChildren", "(", ")", ".", "length", "-", "1", ")", "{", "stage", ".", "content", ".", "insertBefore", "(", "this", ".", "getCanvas", "(", ")", ".", "_canvas", ",", "stage", ".", "getChildren", "(", ")", "[", "index", "+", "1", "]", ".", "getCanvas", "(", ")", ".", "_canvas", ")", ";", "}", "else", "{", "stage", ".", "content", ".", "appendChild", "(", "this", ".", "getCanvas", "(", ")", ".", "_canvas", ")", ";", "}", "}", "return", "this", ";", "}" ]
extend Node.prototype.setZIndex
[ "extend", "Node", ".", "prototype", ".", "setZIndex" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L9750-L9764
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function() { Kinetic.Node.prototype.moveToTop.call(this); var stage = this.getStage(); if(stage) { stage.content.removeChild(this.getCanvas()._canvas); stage.content.appendChild(this.getCanvas()._canvas); } }
javascript
function() { Kinetic.Node.prototype.moveToTop.call(this); var stage = this.getStage(); if(stage) { stage.content.removeChild(this.getCanvas()._canvas); stage.content.appendChild(this.getCanvas()._canvas); } }
[ "function", "(", ")", "{", "Kinetic", ".", "Node", ".", "prototype", ".", "moveToTop", ".", "call", "(", "this", ")", ";", "var", "stage", "=", "this", ".", "getStage", "(", ")", ";", "if", "(", "stage", ")", "{", "stage", ".", "content", ".", "removeChild", "(", "this", ".", "getCanvas", "(", ")", ".", "_canvas", ")", ";", "stage", ".", "content", ".", "appendChild", "(", "this", ".", "getCanvas", "(", ")", ".", "_canvas", ")", ";", "}", "}" ]
extend Node.prototype.moveToTop
[ "extend", "Node", ".", "prototype", ".", "moveToTop" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L9766-L9773
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function() { if(Kinetic.Node.prototype.moveDown.call(this)) { var stage = this.getStage(); if(stage) { var children = stage.getChildren(); stage.content.removeChild(this.getCanvas()._canvas); stage.content.insertBefore(this.getCanvas()._canvas, children[this.index + 1].getCanvas()._canvas); } } }
javascript
function() { if(Kinetic.Node.prototype.moveDown.call(this)) { var stage = this.getStage(); if(stage) { var children = stage.getChildren(); stage.content.removeChild(this.getCanvas()._canvas); stage.content.insertBefore(this.getCanvas()._canvas, children[this.index + 1].getCanvas()._canvas); } } }
[ "function", "(", ")", "{", "if", "(", "Kinetic", ".", "Node", ".", "prototype", ".", "moveDown", ".", "call", "(", "this", ")", ")", "{", "var", "stage", "=", "this", ".", "getStage", "(", ")", ";", "if", "(", "stage", ")", "{", "var", "children", "=", "stage", ".", "getChildren", "(", ")", ";", "stage", ".", "content", ".", "removeChild", "(", "this", ".", "getCanvas", "(", ")", ".", "_canvas", ")", ";", "stage", ".", "content", ".", "insertBefore", "(", "this", ".", "getCanvas", "(", ")", ".", "_canvas", ",", "children", "[", "this", ".", "index", "+", "1", "]", ".", "getCanvas", "(", ")", ".", "_canvas", ")", ";", "}", "}", "}" ]
extend Node.prototype.moveDown
[ "extend", "Node", ".", "prototype", ".", "moveDown" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L9791-L9800
train
freiksenet/react-kinetic
vendor/kinetic-v5.1.0.js
function() { return this.attrs.height === AUTO ? (this.getTextHeight() * this.textArr.length * this.getLineHeight()) + this.getPadding() * 2 : this.attrs.height; }
javascript
function() { return this.attrs.height === AUTO ? (this.getTextHeight() * this.textArr.length * this.getLineHeight()) + this.getPadding() * 2 : this.attrs.height; }
[ "function", "(", ")", "{", "return", "this", ".", "attrs", ".", "height", "===", "AUTO", "?", "(", "this", ".", "getTextHeight", "(", ")", "*", "this", ".", "textArr", ".", "length", "*", "this", ".", "getLineHeight", "(", ")", ")", "+", "this", ".", "getPadding", "(", ")", "*", "2", ":", "this", ".", "attrs", ".", "height", ";", "}" ]
get the height of the text area, which takes into account multi-line text, line heights, and padding @method @memberof Kinetic.Text.prototype @returns {Number}
[ "get", "the", "height", "of", "the", "text", "area", "which", "takes", "into", "account", "multi", "-", "line", "text", "line", "heights", "and", "padding" ]
de0db477141e26d9a07162ef096984bb3f068cec
https://github.com/freiksenet/react-kinetic/blob/de0db477141e26d9a07162ef096984bb3f068cec/vendor/kinetic-v5.1.0.js#L11700-L11702
train
polarch/JSAmbisonics
examples/hoa-panner-sofa2D.js
loadSample
function loadSample(url, doAfterLoading) { var fetchSound = new XMLHttpRequest(); // Load the Sound with XMLHttpRequest fetchSound.open("GET", url, true); // Path to Audio File fetchSound.responseType = "arraybuffer"; // Read as Binary Data fetchSound.onload = function() { context.decodeAudioData(fetchSound.response, doAfterLoading); } fetchSound.send(); }
javascript
function loadSample(url, doAfterLoading) { var fetchSound = new XMLHttpRequest(); // Load the Sound with XMLHttpRequest fetchSound.open("GET", url, true); // Path to Audio File fetchSound.responseType = "arraybuffer"; // Read as Binary Data fetchSound.onload = function() { context.decodeAudioData(fetchSound.response, doAfterLoading); } fetchSound.send(); }
[ "function", "loadSample", "(", "url", ",", "doAfterLoading", ")", "{", "var", "fetchSound", "=", "new", "XMLHttpRequest", "(", ")", ";", "fetchSound", ".", "open", "(", "\"GET\"", ",", "url", ",", "true", ")", ";", "fetchSound", ".", "responseType", "=", "\"arraybuffer\"", ";", "fetchSound", ".", "onload", "=", "function", "(", ")", "{", "context", ".", "decodeAudioData", "(", "fetchSound", ".", "response", ",", "doAfterLoading", ")", ";", "}", "fetchSound", ".", "send", "(", ")", ";", "}" ]
function to load samples
[ "function", "to", "load", "samples" ]
bd02150b5c7cb5446b212bb58970c096116c0027
https://github.com/polarch/JSAmbisonics/blob/bd02150b5c7cb5446b212bb58970c096116c0027/examples/hoa-panner-sofa2D.js#L67-L75
train
goFrendiAsgard/chimera-framework
lib/mongo.js
execute
function execute (configs, fn, ...args) { if ('verbose' in configs && configs.verbose) { const isoDate = (new Date()).toISOString() console.error(COLOR_FG_YELLOW + '[' + isoDate + '] Start mongo.execute: ' + JSON.stringify([configs, fn, args]) + COLOR_RESET) } const dbConfigs = util.getDeepCopiedObject(configs) const mongoUrl = 'mongoUrl' in dbConfigs ? dbConfigs.mongoUrl : '' const dbOption = 'dbOption' in dbConfigs ? dbConfigs.dbOption : {} const options = 'options' in dbConfigs ? dbConfigs.options : {} const collectionName = 'collectionName' in dbConfigs ? dbConfigs.collectionName : '' delete dbConfigs.mongoUrl delete dbConfigs.dbOption delete dbConfigs.collectionName let manager // wrap last argument in newCallback const callback = args[args.length - 1] const newCallback = (error, result) => { if ('verbose' in configs && configs.verbose) { const isoDate = (new Date()).toISOString() console.error(COLOR_FG_YELLOW + '[' + isoDate + '] Finish mongo.execute: ' + JSON.stringify([configs, fn, args]) + COLOR_RESET) } manager.close() callback(error, result) } args[args.length - 1] = newCallback manager = getCompleteManager(mongoUrl, dbOption, options, (error, manager) => { if (error) { return newCallback(error) } const collection = getCompleteCollection(manager, collectionName, dbConfigs) try { return collection[fn](...args) } catch (error) { return newCallback(error) } }) }
javascript
function execute (configs, fn, ...args) { if ('verbose' in configs && configs.verbose) { const isoDate = (new Date()).toISOString() console.error(COLOR_FG_YELLOW + '[' + isoDate + '] Start mongo.execute: ' + JSON.stringify([configs, fn, args]) + COLOR_RESET) } const dbConfigs = util.getDeepCopiedObject(configs) const mongoUrl = 'mongoUrl' in dbConfigs ? dbConfigs.mongoUrl : '' const dbOption = 'dbOption' in dbConfigs ? dbConfigs.dbOption : {} const options = 'options' in dbConfigs ? dbConfigs.options : {} const collectionName = 'collectionName' in dbConfigs ? dbConfigs.collectionName : '' delete dbConfigs.mongoUrl delete dbConfigs.dbOption delete dbConfigs.collectionName let manager // wrap last argument in newCallback const callback = args[args.length - 1] const newCallback = (error, result) => { if ('verbose' in configs && configs.verbose) { const isoDate = (new Date()).toISOString() console.error(COLOR_FG_YELLOW + '[' + isoDate + '] Finish mongo.execute: ' + JSON.stringify([configs, fn, args]) + COLOR_RESET) } manager.close() callback(error, result) } args[args.length - 1] = newCallback manager = getCompleteManager(mongoUrl, dbOption, options, (error, manager) => { if (error) { return newCallback(error) } const collection = getCompleteCollection(manager, collectionName, dbConfigs) try { return collection[fn](...args) } catch (error) { return newCallback(error) } }) }
[ "function", "execute", "(", "configs", ",", "fn", ",", "...", "args", ")", "{", "if", "(", "'verbose'", "in", "configs", "&&", "configs", ".", "verbose", ")", "{", "const", "isoDate", "=", "(", "new", "Date", "(", ")", ")", ".", "toISOString", "(", ")", "console", ".", "error", "(", "COLOR_FG_YELLOW", "+", "'['", "+", "isoDate", "+", "'] Start mongo.execute: '", "+", "JSON", ".", "stringify", "(", "[", "configs", ",", "fn", ",", "args", "]", ")", "+", "COLOR_RESET", ")", "}", "const", "dbConfigs", "=", "util", ".", "getDeepCopiedObject", "(", "configs", ")", "const", "mongoUrl", "=", "'mongoUrl'", "in", "dbConfigs", "?", "dbConfigs", ".", "mongoUrl", ":", "''", "const", "dbOption", "=", "'dbOption'", "in", "dbConfigs", "?", "dbConfigs", ".", "dbOption", ":", "{", "}", "const", "options", "=", "'options'", "in", "dbConfigs", "?", "dbConfigs", ".", "options", ":", "{", "}", "const", "collectionName", "=", "'collectionName'", "in", "dbConfigs", "?", "dbConfigs", ".", "collectionName", ":", "''", "delete", "dbConfigs", ".", "mongoUrl", "delete", "dbConfigs", ".", "dbOption", "delete", "dbConfigs", ".", "collectionName", "let", "manager", "const", "callback", "=", "args", "[", "args", ".", "length", "-", "1", "]", "const", "newCallback", "=", "(", "error", ",", "result", ")", "=>", "{", "if", "(", "'verbose'", "in", "configs", "&&", "configs", ".", "verbose", ")", "{", "const", "isoDate", "=", "(", "new", "Date", "(", ")", ")", ".", "toISOString", "(", ")", "console", ".", "error", "(", "COLOR_FG_YELLOW", "+", "'['", "+", "isoDate", "+", "'] Finish mongo.execute: '", "+", "JSON", ".", "stringify", "(", "[", "configs", ",", "fn", ",", "args", "]", ")", "+", "COLOR_RESET", ")", "}", "manager", ".", "close", "(", ")", "callback", "(", "error", ",", "result", ")", "}", "args", "[", "args", ".", "length", "-", "1", "]", "=", "newCallback", "manager", "=", "getCompleteManager", "(", "mongoUrl", ",", "dbOption", ",", "options", ",", "(", "error", ",", "manager", ")", "=>", "{", "if", "(", "error", ")", "{", "return", "newCallback", "(", "error", ")", "}", "const", "collection", "=", "getCompleteCollection", "(", "manager", ",", "collectionName", ",", "dbConfigs", ")", "try", "{", "return", "collection", "[", "fn", "]", "(", "...", "args", ")", "}", "catch", "(", "error", ")", "{", "return", "newCallback", "(", "error", ")", "}", "}", ")", "}" ]
run something and close the db manager afterward
[ "run", "something", "and", "close", "the", "db", "manager", "afterward" ]
cfa0c98af685de8696e30f507eba66a72e684b66
https://github.com/goFrendiAsgard/chimera-framework/blob/cfa0c98af685de8696e30f507eba66a72e684b66/lib/mongo.js#L22-L58
train
assemble/assemble-less
vendor/less-1.3.3/lib/less/tree/dimension.js
function (op, other) { return new(tree.Dimension) (tree.operate(op, this.value, other.value), this.unit || other.unit); }
javascript
function (op, other) { return new(tree.Dimension) (tree.operate(op, this.value, other.value), this.unit || other.unit); }
[ "function", "(", "op", ",", "other", ")", "{", "return", "new", "(", "tree", ".", "Dimension", ")", "(", "tree", ".", "operate", "(", "op", ",", "this", ".", "value", ",", "other", ".", "value", ")", ",", "this", ".", "unit", "||", "other", ".", "unit", ")", ";", "}" ]
In an operation between two Dimensions, we default to the first Dimension's unit, so `1px + 2em` will yield `3px`. In the future, we could implement some unit conversions such that `100cm + 10mm` would yield `101cm`.
[ "In", "an", "operation", "between", "two", "Dimensions", "we", "default", "to", "the", "first", "Dimension", "s", "unit", "so", "1px", "+", "2em", "will", "yield", "3px", ".", "In", "the", "future", "we", "could", "implement", "some", "unit", "conversions", "such", "that", "100cm", "+", "10mm", "would", "yield", "101cm", "." ]
529d24823b60cb77584a45a765c0291786163a75
https://github.com/assemble/assemble-less/blob/529d24823b60cb77584a45a765c0291786163a75/vendor/less-1.3.3/lib/less/tree/dimension.js#L27-L31
train
goFrendiAsgard/chimera-framework
lib/util.js
getPatchedObject
function getPatchedObject (obj, patcher, clone = true) { if (!patcher) { return obj } let newObj, newPatcher if (clone) { newObj = getDeepCopiedObject(obj) newPatcher = getDeepCopiedObject(patcher) } else { newObj = obj newPatcher = patcher } // patch const keys = Object.keys(newPatcher) for (let i = 0; i < keys.length; i++) { const key = keys[i] if ((key in newObj) && isRealObject(newObj[key]) && isRealObject(newPatcher[key])) { // recursive patch for if value type is newObject try { newObj[key] = getPatchedObject(newObj[key], newPatcher[key], false) } catch (error) { // do nothing, just skip } } else { // simple replacement if value type is not newObject newObj[key] = newPatcher[key] } } return newObj }
javascript
function getPatchedObject (obj, patcher, clone = true) { if (!patcher) { return obj } let newObj, newPatcher if (clone) { newObj = getDeepCopiedObject(obj) newPatcher = getDeepCopiedObject(patcher) } else { newObj = obj newPatcher = patcher } // patch const keys = Object.keys(newPatcher) for (let i = 0; i < keys.length; i++) { const key = keys[i] if ((key in newObj) && isRealObject(newObj[key]) && isRealObject(newPatcher[key])) { // recursive patch for if value type is newObject try { newObj[key] = getPatchedObject(newObj[key], newPatcher[key], false) } catch (error) { // do nothing, just skip } } else { // simple replacement if value type is not newObject newObj[key] = newPatcher[key] } } return newObj }
[ "function", "getPatchedObject", "(", "obj", ",", "patcher", ",", "clone", "=", "true", ")", "{", "if", "(", "!", "patcher", ")", "{", "return", "obj", "}", "let", "newObj", ",", "newPatcher", "if", "(", "clone", ")", "{", "newObj", "=", "getDeepCopiedObject", "(", "obj", ")", "newPatcher", "=", "getDeepCopiedObject", "(", "patcher", ")", "}", "else", "{", "newObj", "=", "obj", "newPatcher", "=", "patcher", "}", "const", "keys", "=", "Object", ".", "keys", "(", "newPatcher", ")", "for", "(", "let", "i", "=", "0", ";", "i", "<", "keys", ".", "length", ";", "i", "++", ")", "{", "const", "key", "=", "keys", "[", "i", "]", "if", "(", "(", "key", "in", "newObj", ")", "&&", "isRealObject", "(", "newObj", "[", "key", "]", ")", "&&", "isRealObject", "(", "newPatcher", "[", "key", "]", ")", ")", "{", "try", "{", "newObj", "[", "key", "]", "=", "getPatchedObject", "(", "newObj", "[", "key", "]", ",", "newPatcher", "[", "key", "]", ",", "false", ")", "}", "catch", "(", "error", ")", "{", "}", "}", "else", "{", "newObj", "[", "key", "]", "=", "newPatcher", "[", "key", "]", "}", "}", "return", "newObj", "}" ]
patch object with patcher
[ "patch", "object", "with", "patcher" ]
cfa0c98af685de8696e30f507eba66a72e684b66
https://github.com/goFrendiAsgard/chimera-framework/blob/cfa0c98af685de8696e30f507eba66a72e684b66/lib/util.js#L87-L116
train
EE/angular-ui-tree-filter
dist/angular-ui-tree-filter.js
visit
function visit(collection, pattern, address) { collection = collection || []; var foundSoFar = false; collection.forEach(function (collectionItem) { foundSoFar = foundSoFar || testForField(collectionItem, pattern, address); }); return foundSoFar; }
javascript
function visit(collection, pattern, address) { collection = collection || []; var foundSoFar = false; collection.forEach(function (collectionItem) { foundSoFar = foundSoFar || testForField(collectionItem, pattern, address); }); return foundSoFar; }
[ "function", "visit", "(", "collection", ",", "pattern", ",", "address", ")", "{", "collection", "=", "collection", "||", "[", "]", ";", "var", "foundSoFar", "=", "false", ";", "collection", ".", "forEach", "(", "function", "(", "collectionItem", ")", "{", "foundSoFar", "=", "foundSoFar", "||", "testForField", "(", "collectionItem", ",", "pattern", ",", "address", ")", ";", "}", ")", ";", "return", "foundSoFar", ";", "}" ]
Iterates through given collection if flag is not true and sets a flag to true on first match. @param {Array} collection @param {string} pattern @param {string} address @returns {boolean}
[ "Iterates", "through", "given", "collection", "if", "flag", "is", "not", "true", "and", "sets", "a", "flag", "to", "true", "on", "first", "match", "." ]
6a9772edd2a806df63ec6483826af66ad428cf73
https://github.com/EE/angular-ui-tree-filter/blob/6a9772edd2a806df63ec6483826af66ad428cf73/dist/angular-ui-tree-filter.js#L39-L48
train
EE/angular-ui-tree-filter
dist/angular-ui-tree-filter.js
resolveAddress
function resolveAddress(object, path) { var parts = path.split('.'); if (object === undefined) { return; } return parts.length < 2 ? object[parts[0]] : resolveAddress(object[parts[0]], parts.slice(1).join('.')); }
javascript
function resolveAddress(object, path) { var parts = path.split('.'); if (object === undefined) { return; } return parts.length < 2 ? object[parts[0]] : resolveAddress(object[parts[0]], parts.slice(1).join('.')); }
[ "function", "resolveAddress", "(", "object", ",", "path", ")", "{", "var", "parts", "=", "path", ".", "split", "(", "'.'", ")", ";", "if", "(", "object", "===", "undefined", ")", "{", "return", ";", "}", "return", "parts", ".", "length", "<", "2", "?", "object", "[", "parts", "[", "0", "]", "]", ":", "resolveAddress", "(", "object", "[", "parts", "[", "0", "]", "]", ",", "parts", ".", "slice", "(", "1", ")", ".", "join", "(", "'.'", ")", ")", ";", "}" ]
Resolves object value from dot-delimited address. @param object @param path @returns {*}
[ "Resolves", "object", "value", "from", "dot", "-", "delimited", "address", "." ]
6a9772edd2a806df63ec6483826af66ad428cf73
https://github.com/EE/angular-ui-tree-filter/blob/6a9772edd2a806df63ec6483826af66ad428cf73/dist/angular-ui-tree-filter.js#L57-L65
train
bfred-it/list-github-dir-content
index.js
api
async function api(endpoint, token) { token = token ? `&access_token=${token}` : ''; const response = await fetch(`https://api.github.com/repos/${endpoint}${token}`); return response.json(); }
javascript
async function api(endpoint, token) { token = token ? `&access_token=${token}` : ''; const response = await fetch(`https://api.github.com/repos/${endpoint}${token}`); return response.json(); }
[ "async", "function", "api", "(", "endpoint", ",", "token", ")", "{", "token", "=", "token", "?", "`", "${", "token", "}", "`", ":", "''", ";", "const", "response", "=", "await", "fetch", "(", "`", "${", "endpoint", "}", "${", "token", "}", "`", ")", ";", "return", "response", ".", "json", "(", ")", ";", "}" ]
Automatically excluded in browser bundles
[ "Automatically", "excluded", "in", "browser", "bundles" ]
f175f5b9498f32cc9e656d40109442d454436a58
https://github.com/bfred-it/list-github-dir-content/blob/f175f5b9498f32cc9e656d40109442d454436a58/index.js#L3-L7
train
pkoretic/pdf417-generator
lib/bcmath.js
bcadd
function bcadd(left_operand, right_operand, scale) { var first, second, result; if (typeof(scale) == 'undefined') { scale = libbcmath.scale; } scale = ((scale < 0) ? 0 : scale); // create objects first = libbcmath.bc_init_num(); second = libbcmath.bc_init_num(); result = libbcmath.bc_init_num(); first = libbcmath.php_str2num(left_operand.toString()); second = libbcmath.php_str2num(right_operand.toString()); // normalize arguments to same scale. if (first.n_scale > second.n_scale) second.setScale(first.n_scale); if (second.n_scale > first.n_scale) first.setScale(second.n_scale); result = libbcmath.bc_add(first, second, scale); if (result.n_scale > scale) { result.n_scale = scale; } return result.toString(); }
javascript
function bcadd(left_operand, right_operand, scale) { var first, second, result; if (typeof(scale) == 'undefined') { scale = libbcmath.scale; } scale = ((scale < 0) ? 0 : scale); // create objects first = libbcmath.bc_init_num(); second = libbcmath.bc_init_num(); result = libbcmath.bc_init_num(); first = libbcmath.php_str2num(left_operand.toString()); second = libbcmath.php_str2num(right_operand.toString()); // normalize arguments to same scale. if (first.n_scale > second.n_scale) second.setScale(first.n_scale); if (second.n_scale > first.n_scale) first.setScale(second.n_scale); result = libbcmath.bc_add(first, second, scale); if (result.n_scale > scale) { result.n_scale = scale; } return result.toString(); }
[ "function", "bcadd", "(", "left_operand", ",", "right_operand", ",", "scale", ")", "{", "var", "first", ",", "second", ",", "result", ";", "if", "(", "typeof", "(", "scale", ")", "==", "'undefined'", ")", "{", "scale", "=", "libbcmath", ".", "scale", ";", "}", "scale", "=", "(", "(", "scale", "<", "0", ")", "?", "0", ":", "scale", ")", ";", "first", "=", "libbcmath", ".", "bc_init_num", "(", ")", ";", "second", "=", "libbcmath", ".", "bc_init_num", "(", ")", ";", "result", "=", "libbcmath", ".", "bc_init_num", "(", ")", ";", "first", "=", "libbcmath", ".", "php_str2num", "(", "left_operand", ".", "toString", "(", ")", ")", ";", "second", "=", "libbcmath", ".", "php_str2num", "(", "right_operand", ".", "toString", "(", ")", ")", ";", "if", "(", "first", ".", "n_scale", ">", "second", ".", "n_scale", ")", "second", ".", "setScale", "(", "first", ".", "n_scale", ")", ";", "if", "(", "second", ".", "n_scale", ">", "first", ".", "n_scale", ")", "first", ".", "setScale", "(", "second", ".", "n_scale", ")", ";", "result", "=", "libbcmath", ".", "bc_add", "(", "first", ",", "second", ",", "scale", ")", ";", "if", "(", "result", ".", "n_scale", ">", "scale", ")", "{", "result", ".", "n_scale", "=", "scale", ";", "}", "return", "result", ".", "toString", "(", ")", ";", "}" ]
PHP Implementation of the libbcmath functions Designed to replicate the PHP functions exactly. Also includes new function: bcround bcadd - Add two arbitrary precision numbers Sums left_operand and right_operand. @param string left_operand The left operand, as a string @param string right_operand The right operand, as a string. @param int [scale] The optional parameter is used to set the number of digits after the decimal place in the result. You can also set the global scale for all functions by using bcscale() @return string
[ "PHP", "Implementation", "of", "the", "libbcmath", "functions" ]
bcb0af69d822446aa4e195019a35d0967626a13b
https://github.com/pkoretic/pdf417-generator/blob/bcb0af69d822446aa4e195019a35d0967626a13b/lib/bcmath.js#L21-L48
train
pkoretic/pdf417-generator
lib/bcmath.js
bcsub
function bcsub(left_operand, right_operand, scale) { var first, second, result; if (typeof(scale) == 'undefined') { scale = libbcmath.scale; } scale = ((scale < 0) ? 0 : scale); // create objects first = libbcmath.bc_init_num(); second = libbcmath.bc_init_num(); result = libbcmath.bc_init_num(); first = libbcmath.php_str2num(left_operand.toString()); second = libbcmath.php_str2num(right_operand.toString()); // normalize arguments to same scale. if (first.n_scale > second.n_scale) second.setScale(first.n_scale); if (second.n_scale > first.n_scale) first.setScale(second.n_scale); result = libbcmath.bc_sub(first, second, scale); if (result.n_scale > scale) { result.n_scale = scale; } return result.toString(); }
javascript
function bcsub(left_operand, right_operand, scale) { var first, second, result; if (typeof(scale) == 'undefined') { scale = libbcmath.scale; } scale = ((scale < 0) ? 0 : scale); // create objects first = libbcmath.bc_init_num(); second = libbcmath.bc_init_num(); result = libbcmath.bc_init_num(); first = libbcmath.php_str2num(left_operand.toString()); second = libbcmath.php_str2num(right_operand.toString()); // normalize arguments to same scale. if (first.n_scale > second.n_scale) second.setScale(first.n_scale); if (second.n_scale > first.n_scale) first.setScale(second.n_scale); result = libbcmath.bc_sub(first, second, scale); if (result.n_scale > scale) { result.n_scale = scale; } return result.toString(); }
[ "function", "bcsub", "(", "left_operand", ",", "right_operand", ",", "scale", ")", "{", "var", "first", ",", "second", ",", "result", ";", "if", "(", "typeof", "(", "scale", ")", "==", "'undefined'", ")", "{", "scale", "=", "libbcmath", ".", "scale", ";", "}", "scale", "=", "(", "(", "scale", "<", "0", ")", "?", "0", ":", "scale", ")", ";", "first", "=", "libbcmath", ".", "bc_init_num", "(", ")", ";", "second", "=", "libbcmath", ".", "bc_init_num", "(", ")", ";", "result", "=", "libbcmath", ".", "bc_init_num", "(", ")", ";", "first", "=", "libbcmath", ".", "php_str2num", "(", "left_operand", ".", "toString", "(", ")", ")", ";", "second", "=", "libbcmath", ".", "php_str2num", "(", "right_operand", ".", "toString", "(", ")", ")", ";", "if", "(", "first", ".", "n_scale", ">", "second", ".", "n_scale", ")", "second", ".", "setScale", "(", "first", ".", "n_scale", ")", ";", "if", "(", "second", ".", "n_scale", ">", "first", ".", "n_scale", ")", "first", ".", "setScale", "(", "second", ".", "n_scale", ")", ";", "result", "=", "libbcmath", ".", "bc_sub", "(", "first", ",", "second", ",", "scale", ")", ";", "if", "(", "result", ".", "n_scale", ">", "scale", ")", "{", "result", ".", "n_scale", "=", "scale", ";", "}", "return", "result", ".", "toString", "(", ")", ";", "}" ]
bcsub - Subtract one arbitrary precision number from another Returns difference between the left operand and the right operand. @param string left_operand The left operand, as a string @param string right_operand The right operand, as a string. @param int [scale] The optional parameter is used to set the number of digits after the decimal place in the result. You can also set the global scale for all functions by using bcscale() @return string
[ "bcsub", "-", "Subtract", "one", "arbitrary", "precision", "number", "from", "another", "Returns", "difference", "between", "the", "left", "operand", "and", "the", "right", "operand", "." ]
bcb0af69d822446aa4e195019a35d0967626a13b
https://github.com/pkoretic/pdf417-generator/blob/bcb0af69d822446aa4e195019a35d0967626a13b/lib/bcmath.js#L59-L87
train
pkoretic/pdf417-generator
lib/bcmath.js
bccomp
function bccomp(left_operand, right_operand, scale) { var first, second; //bc_num if (typeof(scale) == 'undefined') { scale = libbcmath.scale; } scale = ((scale < 0) ? 0 : scale); first = libbcmath.bc_init_num(); second = libbcmath.bc_init_num(); first = libbcmath.bc_str2num(left_operand.toString(), scale); // note bc_ not php_str2num second = libbcmath.bc_str2num(right_operand.toString(), scale); // note bc_ not php_str2num return libbcmath.bc_compare(first, second, scale); }
javascript
function bccomp(left_operand, right_operand, scale) { var first, second; //bc_num if (typeof(scale) == 'undefined') { scale = libbcmath.scale; } scale = ((scale < 0) ? 0 : scale); first = libbcmath.bc_init_num(); second = libbcmath.bc_init_num(); first = libbcmath.bc_str2num(left_operand.toString(), scale); // note bc_ not php_str2num second = libbcmath.bc_str2num(right_operand.toString(), scale); // note bc_ not php_str2num return libbcmath.bc_compare(first, second, scale); }
[ "function", "bccomp", "(", "left_operand", ",", "right_operand", ",", "scale", ")", "{", "var", "first", ",", "second", ";", "if", "(", "typeof", "(", "scale", ")", "==", "'undefined'", ")", "{", "scale", "=", "libbcmath", ".", "scale", ";", "}", "scale", "=", "(", "(", "scale", "<", "0", ")", "?", "0", ":", "scale", ")", ";", "first", "=", "libbcmath", ".", "bc_init_num", "(", ")", ";", "second", "=", "libbcmath", ".", "bc_init_num", "(", ")", ";", "first", "=", "libbcmath", ".", "bc_str2num", "(", "left_operand", ".", "toString", "(", ")", ",", "scale", ")", ";", "second", "=", "libbcmath", ".", "bc_str2num", "(", "right_operand", ".", "toString", "(", ")", ",", "scale", ")", ";", "return", "libbcmath", ".", "bc_compare", "(", "first", ",", "second", ",", "scale", ")", ";", "}" ]
bccomp - Compare two arbitrary precision numers @param string left_operand The left operand, as a string @param string right_operand The right operand, as a string. @param int [scale] The optional parameter is used to set the number of digits after the decimal place in the result. You can also set the global scale for all functions by using bcscale() @return int 0: Left/Right are equal, 1 if left > right, -1 otherwise
[ "bccomp", "-", "Compare", "two", "arbitrary", "precision", "numers" ]
bcb0af69d822446aa4e195019a35d0967626a13b
https://github.com/pkoretic/pdf417-generator/blob/bcb0af69d822446aa4e195019a35d0967626a13b/lib/bcmath.js#L97-L112
train