id
int32
0
58k
repo
stringlengths
5
67
path
stringlengths
4
116
func_name
stringlengths
0
58
original_string
stringlengths
52
373k
language
stringclasses
1 value
code
stringlengths
52
373k
code_tokens
sequence
docstring
stringlengths
4
11.8k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
86
226
3,400
aws/aws-sdk-js
lib/polly/presigner.js
Signer
function Signer(options) { options = options || {}; this.options = options; this.service = options.service; this.bindServiceObject(options); this._operations = {}; }
javascript
function Signer(options) { options = options || {}; this.options = options; this.service = options.service; this.bindServiceObject(options); this._operations = {}; }
[ "function", "Signer", "(", "options", ")", "{", "options", "=", "options", "||", "{", "}", ";", "this", ".", "options", "=", "options", ";", "this", ".", "service", "=", "options", ".", "service", ";", "this", ".", "bindServiceObject", "(", "options", ")", ";", "this", ".", "_operations", "=", "{", "}", ";", "}" ]
Creates a presigner object with a set of configuration options. @option options params [map] An optional map of parameters to bind to every request sent by this service object. @option options service [AWS.Polly] An optional pre-configured instance of the AWS.Polly service object to use for requests. The object may bound parameters used by the presigner. @see AWS.Polly.constructor
[ "Creates", "a", "presigner", "object", "with", "a", "set", "of", "configuration", "options", "." ]
c23e5f0edd150f8885267e5f7c8a564f8e6e8562
https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/polly/presigner.js#L18-L24
3,401
aws/aws-sdk-js
scripts/lib/remove-event-stream-ops.js
removeEventStreamOperations
function removeEventStreamOperations(model) { var modifiedModel = false; // loop over all operations var operations = model.operations; var operationNames = Object.keys(operations); for (var i = 0; i < operationNames.length; i++) { var operationName = operationNames[i]; var operation = operations[operationName]; // check input and output shapes var inputShapeName = operation.input && operation.input.shape; var outputShapeName = operation.output && operation.output.shape; var requiresEventStream = false; if (inputShapeName && hasEventStream(model.shapes[inputShapeName], model)) { requiresEventStream = true; } if (requiresEventStream) { modifiedModel = true; // remove the operation from the model console.log('Removing ' + operationName + ' because it depends on event streams on input.'); delete model.operations[operationName]; } } return modifiedModel; }
javascript
function removeEventStreamOperations(model) { var modifiedModel = false; // loop over all operations var operations = model.operations; var operationNames = Object.keys(operations); for (var i = 0; i < operationNames.length; i++) { var operationName = operationNames[i]; var operation = operations[operationName]; // check input and output shapes var inputShapeName = operation.input && operation.input.shape; var outputShapeName = operation.output && operation.output.shape; var requiresEventStream = false; if (inputShapeName && hasEventStream(model.shapes[inputShapeName], model)) { requiresEventStream = true; } if (requiresEventStream) { modifiedModel = true; // remove the operation from the model console.log('Removing ' + operationName + ' because it depends on event streams on input.'); delete model.operations[operationName]; } } return modifiedModel; }
[ "function", "removeEventStreamOperations", "(", "model", ")", "{", "var", "modifiedModel", "=", "false", ";", "// loop over all operations", "var", "operations", "=", "model", ".", "operations", ";", "var", "operationNames", "=", "Object", ".", "keys", "(", "operations", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "operationNames", ".", "length", ";", "i", "++", ")", "{", "var", "operationName", "=", "operationNames", "[", "i", "]", ";", "var", "operation", "=", "operations", "[", "operationName", "]", ";", "// check input and output shapes", "var", "inputShapeName", "=", "operation", ".", "input", "&&", "operation", ".", "input", ".", "shape", ";", "var", "outputShapeName", "=", "operation", ".", "output", "&&", "operation", ".", "output", ".", "shape", ";", "var", "requiresEventStream", "=", "false", ";", "if", "(", "inputShapeName", "&&", "hasEventStream", "(", "model", ".", "shapes", "[", "inputShapeName", "]", ",", "model", ")", ")", "{", "requiresEventStream", "=", "true", ";", "}", "if", "(", "requiresEventStream", ")", "{", "modifiedModel", "=", "true", ";", "// remove the operation from the model", "console", ".", "log", "(", "'Removing '", "+", "operationName", "+", "' because it depends on event streams on input.'", ")", ";", "delete", "model", ".", "operations", "[", "operationName", "]", ";", "}", "}", "return", "modifiedModel", ";", "}" ]
Removes operations from the model if they require event streams. Specifically looks at input and output shapes. @param {Object} model - JSON parsed API model (*.normal.json)
[ "Removes", "operations", "from", "the", "model", "if", "they", "require", "event", "streams", ".", "Specifically", "looks", "at", "input", "and", "output", "shapes", "." ]
c23e5f0edd150f8885267e5f7c8a564f8e6e8562
https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/scripts/lib/remove-event-stream-ops.js#L6-L31
3,402
aws/aws-sdk-js
lib/publisher/string-to-buffer.js
stringToBuffer
function stringToBuffer(data) { return (typeof Buffer.from === 'function' && Buffer.from !== Uint8Array.from) ? Buffer.from(data) : new Buffer(data); }
javascript
function stringToBuffer(data) { return (typeof Buffer.from === 'function' && Buffer.from !== Uint8Array.from) ? Buffer.from(data) : new Buffer(data); }
[ "function", "stringToBuffer", "(", "data", ")", "{", "return", "(", "typeof", "Buffer", ".", "from", "===", "'function'", "&&", "Buffer", ".", "from", "!==", "Uint8Array", ".", "from", ")", "?", "Buffer", ".", "from", "(", "data", ")", ":", "new", "Buffer", "(", "data", ")", ";", "}" ]
Converts a UTF8 string into a Buffer. @param {string} data Some string to convert to a Buffer @returns {Buffer}
[ "Converts", "a", "UTF8", "string", "into", "a", "Buffer", "." ]
c23e5f0edd150f8885267e5f7c8a564f8e6e8562
https://github.com/aws/aws-sdk-js/blob/c23e5f0edd150f8885267e5f7c8a564f8e6e8562/lib/publisher/string-to-buffer.js#L6-L9
3,403
exceljs/exceljs
lib/doc/defined-names.js
vGrow
function vGrow(yy, edge) { const c = matrix.findCellAt(sheetName, yy, cell.col); if (!c || !c.mark) { return false; } range[edge] = yy; c.mark = false; return true; }
javascript
function vGrow(yy, edge) { const c = matrix.findCellAt(sheetName, yy, cell.col); if (!c || !c.mark) { return false; } range[edge] = yy; c.mark = false; return true; }
[ "function", "vGrow", "(", "yy", ",", "edge", ")", "{", "const", "c", "=", "matrix", ".", "findCellAt", "(", "sheetName", ",", "yy", ",", "cell", ".", "col", ")", ";", "if", "(", "!", "c", "||", "!", "c", ".", "mark", ")", "{", "return", "false", ";", "}", "range", "[", "edge", "]", "=", "yy", ";", "c", ".", "mark", "=", "false", ";", "return", "true", ";", "}" ]
grow vertical - only one col to worry about
[ "grow", "vertical", "-", "only", "one", "col", "to", "worry", "about" ]
c6ee7a14d5e0e5a07bf0e475aa4dd7b9a1e907f2
https://github.com/exceljs/exceljs/blob/c6ee7a14d5e0e5a07bf0e475aa4dd7b9a1e907f2/lib/doc/defined-names.js#L87-L93
3,404
exceljs/exceljs
lib/doc/defined-names.js
hGrow
function hGrow(xx, edge) { const cells = []; for (y = range.top; y <= range.bottom; y++) { const c = matrix.findCellAt(sheetName, y, xx); if (c && c.mark) { cells.push(c); } else { return false; } } range[edge] = xx; for (let i = 0; i < cells.length; i++) { cells[i].mark = false; } return true; }
javascript
function hGrow(xx, edge) { const cells = []; for (y = range.top; y <= range.bottom; y++) { const c = matrix.findCellAt(sheetName, y, xx); if (c && c.mark) { cells.push(c); } else { return false; } } range[edge] = xx; for (let i = 0; i < cells.length; i++) { cells[i].mark = false; } return true; }
[ "function", "hGrow", "(", "xx", ",", "edge", ")", "{", "const", "cells", "=", "[", "]", ";", "for", "(", "y", "=", "range", ".", "top", ";", "y", "<=", "range", ".", "bottom", ";", "y", "++", ")", "{", "const", "c", "=", "matrix", ".", "findCellAt", "(", "sheetName", ",", "y", ",", "xx", ")", ";", "if", "(", "c", "&&", "c", ".", "mark", ")", "{", "cells", ".", "push", "(", "c", ")", ";", "}", "else", "{", "return", "false", ";", "}", "}", "range", "[", "edge", "]", "=", "xx", ";", "for", "(", "let", "i", "=", "0", ";", "i", "<", "cells", ".", "length", ";", "i", "++", ")", "{", "cells", "[", "i", "]", ".", "mark", "=", "false", ";", "}", "return", "true", ";", "}" ]
grow horizontal - ensure all rows can grow
[ "grow", "horizontal", "-", "ensure", "all", "rows", "can", "grow" ]
c6ee7a14d5e0e5a07bf0e475aa4dd7b9a1e907f2
https://github.com/exceljs/exceljs/blob/c6ee7a14d5e0e5a07bf0e475aa4dd7b9a1e907f2/lib/doc/defined-names.js#L98-L113
3,405
exceljs/exceljs
lib/utils/stream-buf.js
function(size) { var buffers; // read min(buffer, size || infinity) if (size) { buffers = []; while (size && this.buffers.length && !this.buffers[0].eod) { var first = this.buffers[0]; var buffer = first.read(size); size -= buffer.length; buffers.push(buffer); if (first.eod && first.full) { this.buffers.shift(); } } return Buffer.concat(buffers); } buffers = this.buffers.map(buf => buf.toBuffer()) .filter(Boolean); this.buffers = []; return Buffer.concat(buffers); }
javascript
function(size) { var buffers; // read min(buffer, size || infinity) if (size) { buffers = []; while (size && this.buffers.length && !this.buffers[0].eod) { var first = this.buffers[0]; var buffer = first.read(size); size -= buffer.length; buffers.push(buffer); if (first.eod && first.full) { this.buffers.shift(); } } return Buffer.concat(buffers); } buffers = this.buffers.map(buf => buf.toBuffer()) .filter(Boolean); this.buffers = []; return Buffer.concat(buffers); }
[ "function", "(", "size", ")", "{", "var", "buffers", ";", "// read min(buffer, size || infinity)", "if", "(", "size", ")", "{", "buffers", "=", "[", "]", ";", "while", "(", "size", "&&", "this", ".", "buffers", ".", "length", "&&", "!", "this", ".", "buffers", "[", "0", "]", ".", "eod", ")", "{", "var", "first", "=", "this", ".", "buffers", "[", "0", "]", ";", "var", "buffer", "=", "first", ".", "read", "(", "size", ")", ";", "size", "-=", "buffer", ".", "length", ";", "buffers", ".", "push", "(", "buffer", ")", ";", "if", "(", "first", ".", "eod", "&&", "first", ".", "full", ")", "{", "this", ".", "buffers", ".", "shift", "(", ")", ";", "}", "}", "return", "Buffer", ".", "concat", "(", "buffers", ")", ";", "}", "buffers", "=", "this", ".", "buffers", ".", "map", "(", "buf", "=>", "buf", ".", "toBuffer", "(", ")", ")", ".", "filter", "(", "Boolean", ")", ";", "this", ".", "buffers", "=", "[", "]", ";", "return", "Buffer", ".", "concat", "(", "buffers", ")", ";", "}" ]
readable event readable - some data is now available event data - switch to flowing mode - feeds chunks to handler event end - no more data event close - optional, indicates upstream close event error - duh
[ "readable", "event", "readable", "-", "some", "data", "is", "now", "available", "event", "data", "-", "switch", "to", "flowing", "mode", "-", "feeds", "chunks", "to", "handler", "event", "end", "-", "no", "more", "data", "event", "close", "-", "optional", "indicates", "upstream", "close", "event", "error", "-", "duh" ]
c6ee7a14d5e0e5a07bf0e475aa4dd7b9a1e907f2
https://github.com/exceljs/exceljs/blob/c6ee7a14d5e0e5a07bf0e475aa4dd7b9a1e907f2/lib/utils/stream-buf.js#L291-L312
3,406
LLK/scratch-blocks
core/flyout_base.js
function() { var topBlocks = this.workspace_.getTopBlocks(false); for (var i = 0, block; block = topBlocks[i]; i++) { block.removeSelect(); } }
javascript
function() { var topBlocks = this.workspace_.getTopBlocks(false); for (var i = 0, block; block = topBlocks[i]; i++) { block.removeSelect(); } }
[ "function", "(", ")", "{", "var", "topBlocks", "=", "this", ".", "workspace_", ".", "getTopBlocks", "(", "false", ")", ";", "for", "(", "var", "i", "=", "0", ",", "block", ";", "block", "=", "topBlocks", "[", "i", "]", ";", "i", "++", ")", "{", "block", ".", "removeSelect", "(", ")", ";", "}", "}" ]
IE 11 is an incompetent browser that fails to fire mouseout events. When the mouse is over the background, deselect all blocks.
[ "IE", "11", "is", "an", "incompetent", "browser", "that", "fails", "to", "fire", "mouseout", "events", ".", "When", "the", "mouse", "is", "over", "the", "background", "deselect", "all", "blocks", "." ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/core/flyout_base.js#L563-L568
3,407
LLK/scratch-blocks
blocks_vertical/vertical_extensions.js
function(menuOptions) { // Add the edit option at the end. menuOptions.push(Blockly.Procedures.makeEditOption(this)); // Find the delete option and update its callback to be specific to // functions. for (var i = 0, option; option = menuOptions[i]; i++) { if (option.text == Blockly.Msg.DELETE_BLOCK) { var input = this.getInput('custom_block'); // this is the root block, not the shadow block. if (input && input.connection && input.connection.targetBlock()) { var procCode = input.connection.targetBlock().getProcCode(); } else { return; } var rootBlock = this; option.callback = function() { var didDelete = Blockly.Procedures.deleteProcedureDefCallback( procCode, rootBlock); if (!didDelete) { // TODO:(#1151) alert('To delete a block definition, first remove all uses of the block'); } }; } } // Find and remove the duplicate option for (var i = 0, option; option = menuOptions[i]; i++) { if (option.text == Blockly.Msg.DUPLICATE) { menuOptions.splice(i, 1); break; } } }
javascript
function(menuOptions) { // Add the edit option at the end. menuOptions.push(Blockly.Procedures.makeEditOption(this)); // Find the delete option and update its callback to be specific to // functions. for (var i = 0, option; option = menuOptions[i]; i++) { if (option.text == Blockly.Msg.DELETE_BLOCK) { var input = this.getInput('custom_block'); // this is the root block, not the shadow block. if (input && input.connection && input.connection.targetBlock()) { var procCode = input.connection.targetBlock().getProcCode(); } else { return; } var rootBlock = this; option.callback = function() { var didDelete = Blockly.Procedures.deleteProcedureDefCallback( procCode, rootBlock); if (!didDelete) { // TODO:(#1151) alert('To delete a block definition, first remove all uses of the block'); } }; } } // Find and remove the duplicate option for (var i = 0, option; option = menuOptions[i]; i++) { if (option.text == Blockly.Msg.DUPLICATE) { menuOptions.splice(i, 1); break; } } }
[ "function", "(", "menuOptions", ")", "{", "// Add the edit option at the end.", "menuOptions", ".", "push", "(", "Blockly", ".", "Procedures", ".", "makeEditOption", "(", "this", ")", ")", ";", "// Find the delete option and update its callback to be specific to", "// functions.", "for", "(", "var", "i", "=", "0", ",", "option", ";", "option", "=", "menuOptions", "[", "i", "]", ";", "i", "++", ")", "{", "if", "(", "option", ".", "text", "==", "Blockly", ".", "Msg", ".", "DELETE_BLOCK", ")", "{", "var", "input", "=", "this", ".", "getInput", "(", "'custom_block'", ")", ";", "// this is the root block, not the shadow block.", "if", "(", "input", "&&", "input", ".", "connection", "&&", "input", ".", "connection", ".", "targetBlock", "(", ")", ")", "{", "var", "procCode", "=", "input", ".", "connection", ".", "targetBlock", "(", ")", ".", "getProcCode", "(", ")", ";", "}", "else", "{", "return", ";", "}", "var", "rootBlock", "=", "this", ";", "option", ".", "callback", "=", "function", "(", ")", "{", "var", "didDelete", "=", "Blockly", ".", "Procedures", ".", "deleteProcedureDefCallback", "(", "procCode", ",", "rootBlock", ")", ";", "if", "(", "!", "didDelete", ")", "{", "// TODO:(#1151)", "alert", "(", "'To delete a block definition, first remove all uses of the block'", ")", ";", "}", "}", ";", "}", "}", "// Find and remove the duplicate option", "for", "(", "var", "i", "=", "0", ",", "option", ";", "option", "=", "menuOptions", "[", "i", "]", ";", "i", "++", ")", "{", "if", "(", "option", ".", "text", "==", "Blockly", ".", "Msg", ".", "DUPLICATE", ")", "{", "menuOptions", ".", "splice", "(", "i", ",", "1", ")", ";", "break", ";", "}", "}", "}" ]
Add the "edit" option and removes the "duplicate" option from the context menu. @param {!Array.<!Object>} menuOptions List of menu options to edit. @this Blockly.Block
[ "Add", "the", "edit", "option", "and", "removes", "the", "duplicate", "option", "from", "the", "context", "menu", "." ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/blocks_vertical/vertical_extensions.js#L159-L192
3,408
LLK/scratch-blocks
blocks_vertical/operators.js
function() { this.jsonInit({ "message0": Blockly.Msg.OPERATORS_MATHOP, "args0": [ { "type": "field_dropdown", "name": "OPERATOR", "options": [ [Blockly.Msg.OPERATORS_MATHOP_ABS, 'abs'], [Blockly.Msg.OPERATORS_MATHOP_FLOOR, 'floor'], [Blockly.Msg.OPERATORS_MATHOP_CEILING, 'ceiling'], [Blockly.Msg.OPERATORS_MATHOP_SQRT, 'sqrt'], [Blockly.Msg.OPERATORS_MATHOP_SIN, 'sin'], [Blockly.Msg.OPERATORS_MATHOP_COS, 'cos'], [Blockly.Msg.OPERATORS_MATHOP_TAN, 'tan'], [Blockly.Msg.OPERATORS_MATHOP_ASIN, 'asin'], [Blockly.Msg.OPERATORS_MATHOP_ACOS, 'acos'], [Blockly.Msg.OPERATORS_MATHOP_ATAN, 'atan'], [Blockly.Msg.OPERATORS_MATHOP_LN, 'ln'], [Blockly.Msg.OPERATORS_MATHOP_LOG, 'log'], [Blockly.Msg.OPERATORS_MATHOP_EEXP, 'e ^'], [Blockly.Msg.OPERATORS_MATHOP_10EXP, '10 ^'] ] }, { "type": "input_value", "name": "NUM" } ], "category": Blockly.Categories.operators, "extensions": ["colours_operators", "output_number"] }); }
javascript
function() { this.jsonInit({ "message0": Blockly.Msg.OPERATORS_MATHOP, "args0": [ { "type": "field_dropdown", "name": "OPERATOR", "options": [ [Blockly.Msg.OPERATORS_MATHOP_ABS, 'abs'], [Blockly.Msg.OPERATORS_MATHOP_FLOOR, 'floor'], [Blockly.Msg.OPERATORS_MATHOP_CEILING, 'ceiling'], [Blockly.Msg.OPERATORS_MATHOP_SQRT, 'sqrt'], [Blockly.Msg.OPERATORS_MATHOP_SIN, 'sin'], [Blockly.Msg.OPERATORS_MATHOP_COS, 'cos'], [Blockly.Msg.OPERATORS_MATHOP_TAN, 'tan'], [Blockly.Msg.OPERATORS_MATHOP_ASIN, 'asin'], [Blockly.Msg.OPERATORS_MATHOP_ACOS, 'acos'], [Blockly.Msg.OPERATORS_MATHOP_ATAN, 'atan'], [Blockly.Msg.OPERATORS_MATHOP_LN, 'ln'], [Blockly.Msg.OPERATORS_MATHOP_LOG, 'log'], [Blockly.Msg.OPERATORS_MATHOP_EEXP, 'e ^'], [Blockly.Msg.OPERATORS_MATHOP_10EXP, '10 ^'] ] }, { "type": "input_value", "name": "NUM" } ], "category": Blockly.Categories.operators, "extensions": ["colours_operators", "output_number"] }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "Blockly", ".", "Msg", ".", "OPERATORS_MATHOP", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"field_dropdown\"", ",", "\"name\"", ":", "\"OPERATOR\"", ",", "\"options\"", ":", "[", "[", "Blockly", ".", "Msg", ".", "OPERATORS_MATHOP_ABS", ",", "'abs'", "]", ",", "[", "Blockly", ".", "Msg", ".", "OPERATORS_MATHOP_FLOOR", ",", "'floor'", "]", ",", "[", "Blockly", ".", "Msg", ".", "OPERATORS_MATHOP_CEILING", ",", "'ceiling'", "]", ",", "[", "Blockly", ".", "Msg", ".", "OPERATORS_MATHOP_SQRT", ",", "'sqrt'", "]", ",", "[", "Blockly", ".", "Msg", ".", "OPERATORS_MATHOP_SIN", ",", "'sin'", "]", ",", "[", "Blockly", ".", "Msg", ".", "OPERATORS_MATHOP_COS", ",", "'cos'", "]", ",", "[", "Blockly", ".", "Msg", ".", "OPERATORS_MATHOP_TAN", ",", "'tan'", "]", ",", "[", "Blockly", ".", "Msg", ".", "OPERATORS_MATHOP_ASIN", ",", "'asin'", "]", ",", "[", "Blockly", ".", "Msg", ".", "OPERATORS_MATHOP_ACOS", ",", "'acos'", "]", ",", "[", "Blockly", ".", "Msg", ".", "OPERATORS_MATHOP_ATAN", ",", "'atan'", "]", ",", "[", "Blockly", ".", "Msg", ".", "OPERATORS_MATHOP_LN", ",", "'ln'", "]", ",", "[", "Blockly", ".", "Msg", ".", "OPERATORS_MATHOP_LOG", ",", "'log'", "]", ",", "[", "Blockly", ".", "Msg", ".", "OPERATORS_MATHOP_EEXP", ",", "'e ^'", "]", ",", "[", "Blockly", ".", "Msg", ".", "OPERATORS_MATHOP_10EXP", ",", "'10 ^'", "]", "]", "}", ",", "{", "\"type\"", ":", "\"input_value\"", ",", "\"name\"", ":", "\"NUM\"", "}", "]", ",", "\"category\"", ":", "Blockly", ".", "Categories", ".", "operators", ",", "\"extensions\"", ":", "[", "\"colours_operators\"", ",", "\"output_number\"", "]", "}", ")", ";", "}" ]
Block for "advanced" math ops on a number. @this Blockly.Block
[ "Block", "for", "advanced", "math", "ops", "on", "a", "number", "." ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/blocks_vertical/operators.js#L437-L469
3,409
LLK/scratch-blocks
blocks_common/colour.js
randomColour
function randomColour() { var num = Math.floor(Math.random() * Math.pow(2, 24)); return '#' + ('00000' + num.toString(16)).substr(-6); }
javascript
function randomColour() { var num = Math.floor(Math.random() * Math.pow(2, 24)); return '#' + ('00000' + num.toString(16)).substr(-6); }
[ "function", "randomColour", "(", ")", "{", "var", "num", "=", "Math", ".", "floor", "(", "Math", ".", "random", "(", ")", "*", "Math", ".", "pow", "(", "2", ",", "24", ")", ")", ";", "return", "'#'", "+", "(", "'00000'", "+", "num", ".", "toString", "(", "16", ")", ")", ".", "substr", "(", "-", "6", ")", ";", "}" ]
Pick a random colour. @return {string} #RRGGBB for random colour.
[ "Pick", "a", "random", "colour", "." ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/blocks_common/colour.js#L37-L40
3,410
LLK/scratch-blocks
blocks_vertical/looks.js
function() { this.jsonInit({ "message0": Blockly.Msg.LOOKS_CHANGEEFFECTBY, "args0": [ { "type": "field_dropdown", "name": "EFFECT", "options": [ [Blockly.Msg.LOOKS_EFFECT_COLOR, 'COLOR'], [Blockly.Msg.LOOKS_EFFECT_FISHEYE, 'FISHEYE'], [Blockly.Msg.LOOKS_EFFECT_WHIRL, 'WHIRL'], [Blockly.Msg.LOOKS_EFFECT_PIXELATE, 'PIXELATE'], [Blockly.Msg.LOOKS_EFFECT_MOSAIC, 'MOSAIC'], [Blockly.Msg.LOOKS_EFFECT_BRIGHTNESS, 'BRIGHTNESS'], [Blockly.Msg.LOOKS_EFFECT_GHOST, 'GHOST'] ] }, { "type": "input_value", "name": "CHANGE" } ], "category": Blockly.Categories.looks, "extensions": ["colours_looks", "shape_statement"] }); }
javascript
function() { this.jsonInit({ "message0": Blockly.Msg.LOOKS_CHANGEEFFECTBY, "args0": [ { "type": "field_dropdown", "name": "EFFECT", "options": [ [Blockly.Msg.LOOKS_EFFECT_COLOR, 'COLOR'], [Blockly.Msg.LOOKS_EFFECT_FISHEYE, 'FISHEYE'], [Blockly.Msg.LOOKS_EFFECT_WHIRL, 'WHIRL'], [Blockly.Msg.LOOKS_EFFECT_PIXELATE, 'PIXELATE'], [Blockly.Msg.LOOKS_EFFECT_MOSAIC, 'MOSAIC'], [Blockly.Msg.LOOKS_EFFECT_BRIGHTNESS, 'BRIGHTNESS'], [Blockly.Msg.LOOKS_EFFECT_GHOST, 'GHOST'] ] }, { "type": "input_value", "name": "CHANGE" } ], "category": Blockly.Categories.looks, "extensions": ["colours_looks", "shape_statement"] }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "Blockly", ".", "Msg", ".", "LOOKS_CHANGEEFFECTBY", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"field_dropdown\"", ",", "\"name\"", ":", "\"EFFECT\"", ",", "\"options\"", ":", "[", "[", "Blockly", ".", "Msg", ".", "LOOKS_EFFECT_COLOR", ",", "'COLOR'", "]", ",", "[", "Blockly", ".", "Msg", ".", "LOOKS_EFFECT_FISHEYE", ",", "'FISHEYE'", "]", ",", "[", "Blockly", ".", "Msg", ".", "LOOKS_EFFECT_WHIRL", ",", "'WHIRL'", "]", ",", "[", "Blockly", ".", "Msg", ".", "LOOKS_EFFECT_PIXELATE", ",", "'PIXELATE'", "]", ",", "[", "Blockly", ".", "Msg", ".", "LOOKS_EFFECT_MOSAIC", ",", "'MOSAIC'", "]", ",", "[", "Blockly", ".", "Msg", ".", "LOOKS_EFFECT_BRIGHTNESS", ",", "'BRIGHTNESS'", "]", ",", "[", "Blockly", ".", "Msg", ".", "LOOKS_EFFECT_GHOST", ",", "'GHOST'", "]", "]", "}", ",", "{", "\"type\"", ":", "\"input_value\"", ",", "\"name\"", ":", "\"CHANGE\"", "}", "]", ",", "\"category\"", ":", "Blockly", ".", "Categories", ".", "looks", ",", "\"extensions\"", ":", "[", "\"colours_looks\"", ",", "\"shape_statement\"", "]", "}", ")", ";", "}" ]
Block to change graphic effect. @this Blockly.Block
[ "Block", "to", "change", "graphic", "effect", "." ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/blocks_vertical/looks.js#L168-L193
3,411
LLK/scratch-blocks
blocks_vertical/looks.js
function() { this.jsonInit({ "message0": "%1", "args0": [ { "type": "field_dropdown", "name": "COSTUME", "options": [ ['costume1', 'COSTUME1'], ['costume2', 'COSTUME2'] ] } ], "colour": Blockly.Colours.looks.secondary, "colourSecondary": Blockly.Colours.looks.secondary, "colourTertiary": Blockly.Colours.looks.tertiary, "extensions": ["output_string"] }); }
javascript
function() { this.jsonInit({ "message0": "%1", "args0": [ { "type": "field_dropdown", "name": "COSTUME", "options": [ ['costume1', 'COSTUME1'], ['costume2', 'COSTUME2'] ] } ], "colour": Blockly.Colours.looks.secondary, "colourSecondary": Blockly.Colours.looks.secondary, "colourTertiary": Blockly.Colours.looks.tertiary, "extensions": ["output_string"] }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "\"%1\"", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"field_dropdown\"", ",", "\"name\"", ":", "\"COSTUME\"", ",", "\"options\"", ":", "[", "[", "'costume1'", ",", "'COSTUME1'", "]", ",", "[", "'costume2'", ",", "'COSTUME2'", "]", "]", "}", "]", ",", "\"colour\"", ":", "Blockly", ".", "Colours", ".", "looks", ".", "secondary", ",", "\"colourSecondary\"", ":", "Blockly", ".", "Colours", ".", "looks", ".", "secondary", ",", "\"colourTertiary\"", ":", "Blockly", ".", "Colours", ".", "looks", ".", "tertiary", ",", "\"extensions\"", ":", "[", "\"output_string\"", "]", "}", ")", ";", "}" ]
Costumes drop-down menu. @this Blockly.Block
[ "Costumes", "drop", "-", "down", "menu", "." ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/blocks_vertical/looks.js#L354-L372
3,412
LLK/scratch-blocks
blocks_vertical/looks.js
function() { this.jsonInit({ "message0": Blockly.Msg.LOOKS_BACKDROPNUMBERNAME, "args0": [ { "type": "field_dropdown", "name": "NUMBER_NAME", "options": [ [Blockly.Msg.LOOKS_NUMBERNAME_NUMBER, 'number'], [Blockly.Msg.LOOKS_NUMBERNAME_NAME, 'name'] ] } ], "category": Blockly.Categories.looks, "checkboxInFlyout": true, "extensions": ["colours_looks", "output_number"] }); }
javascript
function() { this.jsonInit({ "message0": Blockly.Msg.LOOKS_BACKDROPNUMBERNAME, "args0": [ { "type": "field_dropdown", "name": "NUMBER_NAME", "options": [ [Blockly.Msg.LOOKS_NUMBERNAME_NUMBER, 'number'], [Blockly.Msg.LOOKS_NUMBERNAME_NAME, 'name'] ] } ], "category": Blockly.Categories.looks, "checkboxInFlyout": true, "extensions": ["colours_looks", "output_number"] }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "Blockly", ".", "Msg", ".", "LOOKS_BACKDROPNUMBERNAME", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"field_dropdown\"", ",", "\"name\"", ":", "\"NUMBER_NAME\"", ",", "\"options\"", ":", "[", "[", "Blockly", ".", "Msg", ".", "LOOKS_NUMBERNAME_NUMBER", ",", "'number'", "]", ",", "[", "Blockly", ".", "Msg", ".", "LOOKS_NUMBERNAME_NAME", ",", "'name'", "]", "]", "}", "]", ",", "\"category\"", ":", "Blockly", ".", "Categories", ".", "looks", ",", "\"checkboxInFlyout\"", ":", "true", ",", "\"extensions\"", ":", "[", "\"colours_looks\"", ",", "\"output_number\"", "]", "}", ")", ";", "}" ]
Block to report backdrop's number or name @this Blockly.Block
[ "Block", "to", "report", "backdrop", "s", "number", "or", "name" ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/blocks_vertical/looks.js#L512-L529
3,413
LLK/scratch-blocks
blocks_vertical/event.js
function() { this.jsonInit({ "id": "event_whenflagclicked", "message0": Blockly.Msg.EVENT_WHENFLAGCLICKED, "args0": [ { "type": "field_image", "src": Blockly.mainWorkspace.options.pathToMedia + "green-flag.svg", "width": 24, "height": 24, "alt": "flag" } ], "category": Blockly.Categories.event, "extensions": ["colours_event", "shape_hat"] }); }
javascript
function() { this.jsonInit({ "id": "event_whenflagclicked", "message0": Blockly.Msg.EVENT_WHENFLAGCLICKED, "args0": [ { "type": "field_image", "src": Blockly.mainWorkspace.options.pathToMedia + "green-flag.svg", "width": 24, "height": 24, "alt": "flag" } ], "category": Blockly.Categories.event, "extensions": ["colours_event", "shape_hat"] }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"id\"", ":", "\"event_whenflagclicked\"", ",", "\"message0\"", ":", "Blockly", ".", "Msg", ".", "EVENT_WHENFLAGCLICKED", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"field_image\"", ",", "\"src\"", ":", "Blockly", ".", "mainWorkspace", ".", "options", ".", "pathToMedia", "+", "\"green-flag.svg\"", ",", "\"width\"", ":", "24", ",", "\"height\"", ":", "24", ",", "\"alt\"", ":", "\"flag\"", "}", "]", ",", "\"category\"", ":", "Blockly", ".", "Categories", ".", "event", ",", "\"extensions\"", ":", "[", "\"colours_event\"", ",", "\"shape_hat\"", "]", "}", ")", ";", "}" ]
Block for when flag clicked. @this Blockly.Block
[ "Block", "for", "when", "flag", "clicked", "." ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/blocks_vertical/event.js#L78-L94
3,414
LLK/scratch-blocks
blocks_vertical/event.js
function() { this.jsonInit({ "message0": "%1", "args0": [ { "type": "field_variable", "name": "BROADCAST_OPTION", "variableTypes":[Blockly.BROADCAST_MESSAGE_VARIABLE_TYPE], "variable": Blockly.Msg.DEFAULT_BROADCAST_MESSAGE_NAME } ], "colour": Blockly.Colours.event.secondary, "colourSecondary": Blockly.Colours.event.secondary, "colourTertiary": Blockly.Colours.event.tertiary, "extensions": ["output_string"] }); }
javascript
function() { this.jsonInit({ "message0": "%1", "args0": [ { "type": "field_variable", "name": "BROADCAST_OPTION", "variableTypes":[Blockly.BROADCAST_MESSAGE_VARIABLE_TYPE], "variable": Blockly.Msg.DEFAULT_BROADCAST_MESSAGE_NAME } ], "colour": Blockly.Colours.event.secondary, "colourSecondary": Blockly.Colours.event.secondary, "colourTertiary": Blockly.Colours.event.tertiary, "extensions": ["output_string"] }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "\"%1\"", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"field_variable\"", ",", "\"name\"", ":", "\"BROADCAST_OPTION\"", ",", "\"variableTypes\"", ":", "[", "Blockly", ".", "BROADCAST_MESSAGE_VARIABLE_TYPE", "]", ",", "\"variable\"", ":", "Blockly", ".", "Msg", ".", "DEFAULT_BROADCAST_MESSAGE_NAME", "}", "]", ",", "\"colour\"", ":", "Blockly", ".", "Colours", ".", "event", ".", "secondary", ",", "\"colourSecondary\"", ":", "Blockly", ".", "Colours", ".", "event", ".", "secondary", ",", "\"colourTertiary\"", ":", "Blockly", ".", "Colours", ".", "event", ".", "tertiary", ",", "\"extensions\"", ":", "[", "\"output_string\"", "]", "}", ")", ";", "}" ]
Broadcast drop-down menu. @this Blockly.Block
[ "Broadcast", "drop", "-", "down", "menu", "." ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/blocks_vertical/event.js#L205-L221
3,415
LLK/scratch-blocks
blocks_vertical/event.js
function() { this.jsonInit({ "id": "event_whenkeypressed", "message0": Blockly.Msg.EVENT_WHENKEYPRESSED, "args0": [ { "type": "field_dropdown", "name": "KEY_OPTION", "options": [ [Blockly.Msg.EVENT_WHENKEYPRESSED_SPACE, 'space'], [Blockly.Msg.EVENT_WHENKEYPRESSED_UP, 'up arrow'], [Blockly.Msg.EVENT_WHENKEYPRESSED_DOWN, 'down arrow'], [Blockly.Msg.EVENT_WHENKEYPRESSED_RIGHT, 'right arrow'], [Blockly.Msg.EVENT_WHENKEYPRESSED_LEFT, 'left arrow'], [Blockly.Msg.EVENT_WHENKEYPRESSED_ANY, 'any'], ['a', 'a'], ['b', 'b'], ['c', 'c'], ['d', 'd'], ['e', 'e'], ['f', 'f'], ['g', 'g'], ['h', 'h'], ['i', 'i'], ['j', 'j'], ['k', 'k'], ['l', 'l'], ['m', 'm'], ['n', 'n'], ['o', 'o'], ['p', 'p'], ['q', 'q'], ['r', 'r'], ['s', 's'], ['t', 't'], ['u', 'u'], ['v', 'v'], ['w', 'w'], ['x', 'x'], ['y', 'y'], ['z', 'z'], ['0', '0'], ['1', '1'], ['2', '2'], ['3', '3'], ['4', '4'], ['5', '5'], ['6', '6'], ['7', '7'], ['8', '8'], ['9', '9'] ] } ], "category": Blockly.Categories.event, "extensions": ["colours_event", "shape_hat"] }); }
javascript
function() { this.jsonInit({ "id": "event_whenkeypressed", "message0": Blockly.Msg.EVENT_WHENKEYPRESSED, "args0": [ { "type": "field_dropdown", "name": "KEY_OPTION", "options": [ [Blockly.Msg.EVENT_WHENKEYPRESSED_SPACE, 'space'], [Blockly.Msg.EVENT_WHENKEYPRESSED_UP, 'up arrow'], [Blockly.Msg.EVENT_WHENKEYPRESSED_DOWN, 'down arrow'], [Blockly.Msg.EVENT_WHENKEYPRESSED_RIGHT, 'right arrow'], [Blockly.Msg.EVENT_WHENKEYPRESSED_LEFT, 'left arrow'], [Blockly.Msg.EVENT_WHENKEYPRESSED_ANY, 'any'], ['a', 'a'], ['b', 'b'], ['c', 'c'], ['d', 'd'], ['e', 'e'], ['f', 'f'], ['g', 'g'], ['h', 'h'], ['i', 'i'], ['j', 'j'], ['k', 'k'], ['l', 'l'], ['m', 'm'], ['n', 'n'], ['o', 'o'], ['p', 'p'], ['q', 'q'], ['r', 'r'], ['s', 's'], ['t', 't'], ['u', 'u'], ['v', 'v'], ['w', 'w'], ['x', 'x'], ['y', 'y'], ['z', 'z'], ['0', '0'], ['1', '1'], ['2', '2'], ['3', '3'], ['4', '4'], ['5', '5'], ['6', '6'], ['7', '7'], ['8', '8'], ['9', '9'] ] } ], "category": Blockly.Categories.event, "extensions": ["colours_event", "shape_hat"] }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"id\"", ":", "\"event_whenkeypressed\"", ",", "\"message0\"", ":", "Blockly", ".", "Msg", ".", "EVENT_WHENKEYPRESSED", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"field_dropdown\"", ",", "\"name\"", ":", "\"KEY_OPTION\"", ",", "\"options\"", ":", "[", "[", "Blockly", ".", "Msg", ".", "EVENT_WHENKEYPRESSED_SPACE", ",", "'space'", "]", ",", "[", "Blockly", ".", "Msg", ".", "EVENT_WHENKEYPRESSED_UP", ",", "'up arrow'", "]", ",", "[", "Blockly", ".", "Msg", ".", "EVENT_WHENKEYPRESSED_DOWN", ",", "'down arrow'", "]", ",", "[", "Blockly", ".", "Msg", ".", "EVENT_WHENKEYPRESSED_RIGHT", ",", "'right arrow'", "]", ",", "[", "Blockly", ".", "Msg", ".", "EVENT_WHENKEYPRESSED_LEFT", ",", "'left arrow'", "]", ",", "[", "Blockly", ".", "Msg", ".", "EVENT_WHENKEYPRESSED_ANY", ",", "'any'", "]", ",", "[", "'a'", ",", "'a'", "]", ",", "[", "'b'", ",", "'b'", "]", ",", "[", "'c'", ",", "'c'", "]", ",", "[", "'d'", ",", "'d'", "]", ",", "[", "'e'", ",", "'e'", "]", ",", "[", "'f'", ",", "'f'", "]", ",", "[", "'g'", ",", "'g'", "]", ",", "[", "'h'", ",", "'h'", "]", ",", "[", "'i'", ",", "'i'", "]", ",", "[", "'j'", ",", "'j'", "]", ",", "[", "'k'", ",", "'k'", "]", ",", "[", "'l'", ",", "'l'", "]", ",", "[", "'m'", ",", "'m'", "]", ",", "[", "'n'", ",", "'n'", "]", ",", "[", "'o'", ",", "'o'", "]", ",", "[", "'p'", ",", "'p'", "]", ",", "[", "'q'", ",", "'q'", "]", ",", "[", "'r'", ",", "'r'", "]", ",", "[", "'s'", ",", "'s'", "]", ",", "[", "'t'", ",", "'t'", "]", ",", "[", "'u'", ",", "'u'", "]", ",", "[", "'v'", ",", "'v'", "]", ",", "[", "'w'", ",", "'w'", "]", ",", "[", "'x'", ",", "'x'", "]", ",", "[", "'y'", ",", "'y'", "]", ",", "[", "'z'", ",", "'z'", "]", ",", "[", "'0'", ",", "'0'", "]", ",", "[", "'1'", ",", "'1'", "]", ",", "[", "'2'", ",", "'2'", "]", ",", "[", "'3'", ",", "'3'", "]", ",", "[", "'4'", ",", "'4'", "]", ",", "[", "'5'", ",", "'5'", "]", ",", "[", "'6'", ",", "'6'", "]", ",", "[", "'7'", ",", "'7'", "]", ",", "[", "'8'", ",", "'8'", "]", ",", "[", "'9'", ",", "'9'", "]", "]", "}", "]", ",", "\"category\"", ":", "Blockly", ".", "Categories", ".", "event", ",", "\"extensions\"", ":", "[", "\"colours_event\"", ",", "\"shape_hat\"", "]", "}", ")", ";", "}" ]
Block to send a broadcast. @this Blockly.Block
[ "Block", "to", "send", "a", "broadcast", "." ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/blocks_vertical/event.js#L270-L327
3,416
LLK/scratch-blocks
blocks_vertical/sensing.js
function() { this.jsonInit({ "message0": "%1", "args0": [ { "type": "field_dropdown", "name": "KEY_OPTION", "options": [ [Blockly.Msg.EVENT_WHENKEYPRESSED_SPACE, 'space'], [Blockly.Msg.EVENT_WHENKEYPRESSED_UP, 'up arrow'], [Blockly.Msg.EVENT_WHENKEYPRESSED_DOWN, 'down arrow'], [Blockly.Msg.EVENT_WHENKEYPRESSED_RIGHT, 'right arrow'], [Blockly.Msg.EVENT_WHENKEYPRESSED_LEFT, 'left arrow'], [Blockly.Msg.EVENT_WHENKEYPRESSED_ANY, 'any'], ['a', 'a'], ['b', 'b'], ['c', 'c'], ['d', 'd'], ['e', 'e'], ['f', 'f'], ['g', 'g'], ['h', 'h'], ['i', 'i'], ['j', 'j'], ['k', 'k'], ['l', 'l'], ['m', 'm'], ['n', 'n'], ['o', 'o'], ['p', 'p'], ['q', 'q'], ['r', 'r'], ['s', 's'], ['t', 't'], ['u', 'u'], ['v', 'v'], ['w', 'w'], ['x', 'x'], ['y', 'y'], ['z', 'z'], ['0', '0'], ['1', '1'], ['2', '2'], ['3', '3'], ['4', '4'], ['5', '5'], ['6', '6'], ['7', '7'], ['8', '8'], ['9', '9'] ] } ], "extensions": ["colours_sensing", "output_string"] }); }
javascript
function() { this.jsonInit({ "message0": "%1", "args0": [ { "type": "field_dropdown", "name": "KEY_OPTION", "options": [ [Blockly.Msg.EVENT_WHENKEYPRESSED_SPACE, 'space'], [Blockly.Msg.EVENT_WHENKEYPRESSED_UP, 'up arrow'], [Blockly.Msg.EVENT_WHENKEYPRESSED_DOWN, 'down arrow'], [Blockly.Msg.EVENT_WHENKEYPRESSED_RIGHT, 'right arrow'], [Blockly.Msg.EVENT_WHENKEYPRESSED_LEFT, 'left arrow'], [Blockly.Msg.EVENT_WHENKEYPRESSED_ANY, 'any'], ['a', 'a'], ['b', 'b'], ['c', 'c'], ['d', 'd'], ['e', 'e'], ['f', 'f'], ['g', 'g'], ['h', 'h'], ['i', 'i'], ['j', 'j'], ['k', 'k'], ['l', 'l'], ['m', 'm'], ['n', 'n'], ['o', 'o'], ['p', 'p'], ['q', 'q'], ['r', 'r'], ['s', 's'], ['t', 't'], ['u', 'u'], ['v', 'v'], ['w', 'w'], ['x', 'x'], ['y', 'y'], ['z', 'z'], ['0', '0'], ['1', '1'], ['2', '2'], ['3', '3'], ['4', '4'], ['5', '5'], ['6', '6'], ['7', '7'], ['8', '8'], ['9', '9'] ] } ], "extensions": ["colours_sensing", "output_string"] }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "\"%1\"", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"field_dropdown\"", ",", "\"name\"", ":", "\"KEY_OPTION\"", ",", "\"options\"", ":", "[", "[", "Blockly", ".", "Msg", ".", "EVENT_WHENKEYPRESSED_SPACE", ",", "'space'", "]", ",", "[", "Blockly", ".", "Msg", ".", "EVENT_WHENKEYPRESSED_UP", ",", "'up arrow'", "]", ",", "[", "Blockly", ".", "Msg", ".", "EVENT_WHENKEYPRESSED_DOWN", ",", "'down arrow'", "]", ",", "[", "Blockly", ".", "Msg", ".", "EVENT_WHENKEYPRESSED_RIGHT", ",", "'right arrow'", "]", ",", "[", "Blockly", ".", "Msg", ".", "EVENT_WHENKEYPRESSED_LEFT", ",", "'left arrow'", "]", ",", "[", "Blockly", ".", "Msg", ".", "EVENT_WHENKEYPRESSED_ANY", ",", "'any'", "]", ",", "[", "'a'", ",", "'a'", "]", ",", "[", "'b'", ",", "'b'", "]", ",", "[", "'c'", ",", "'c'", "]", ",", "[", "'d'", ",", "'d'", "]", ",", "[", "'e'", ",", "'e'", "]", ",", "[", "'f'", ",", "'f'", "]", ",", "[", "'g'", ",", "'g'", "]", ",", "[", "'h'", ",", "'h'", "]", ",", "[", "'i'", ",", "'i'", "]", ",", "[", "'j'", ",", "'j'", "]", ",", "[", "'k'", ",", "'k'", "]", ",", "[", "'l'", ",", "'l'", "]", ",", "[", "'m'", ",", "'m'", "]", ",", "[", "'n'", ",", "'n'", "]", ",", "[", "'o'", ",", "'o'", "]", ",", "[", "'p'", ",", "'p'", "]", ",", "[", "'q'", ",", "'q'", "]", ",", "[", "'r'", ",", "'r'", "]", ",", "[", "'s'", ",", "'s'", "]", ",", "[", "'t'", ",", "'t'", "]", ",", "[", "'u'", ",", "'u'", "]", ",", "[", "'v'", ",", "'v'", "]", ",", "[", "'w'", ",", "'w'", "]", ",", "[", "'x'", ",", "'x'", "]", ",", "[", "'y'", ",", "'y'", "]", ",", "[", "'z'", ",", "'z'", "]", ",", "[", "'0'", ",", "'0'", "]", ",", "[", "'1'", ",", "'1'", "]", ",", "[", "'2'", ",", "'2'", "]", ",", "[", "'3'", ",", "'3'", "]", ",", "[", "'4'", ",", "'4'", "]", ",", "[", "'5'", ",", "'5'", "]", ",", "[", "'6'", ",", "'6'", "]", ",", "[", "'7'", ",", "'7'", "]", ",", "[", "'8'", ",", "'8'", "]", ",", "[", "'9'", ",", "'9'", "]", "]", "}", "]", ",", "\"extensions\"", ":", "[", "\"colours_sensing\"", ",", "\"output_string\"", "]", "}", ")", ";", "}" ]
Options for Keys @this Blockly.Block
[ "Options", "for", "Keys" ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/blocks_vertical/sensing.js#L220-L275
3,417
LLK/scratch-blocks
blocks_vertical/sensing.js
function() { this.jsonInit({ "message0": Blockly.Msg.SENSING_SETDRAGMODE, "args0": [ { "type": "field_dropdown", "name": "DRAG_MODE", "options": [ [Blockly.Msg.SENSING_SETDRAGMODE_DRAGGABLE, 'draggable'], [Blockly.Msg.SENSING_SETDRAGMODE_NOTDRAGGABLE, 'not draggable'] ] } ], "category": Blockly.Categories.sensing, "extensions": ["colours_sensing", "shape_statement"] }); }
javascript
function() { this.jsonInit({ "message0": Blockly.Msg.SENSING_SETDRAGMODE, "args0": [ { "type": "field_dropdown", "name": "DRAG_MODE", "options": [ [Blockly.Msg.SENSING_SETDRAGMODE_DRAGGABLE, 'draggable'], [Blockly.Msg.SENSING_SETDRAGMODE_NOTDRAGGABLE, 'not draggable'] ] } ], "category": Blockly.Categories.sensing, "extensions": ["colours_sensing", "shape_statement"] }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "Blockly", ".", "Msg", ".", "SENSING_SETDRAGMODE", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"field_dropdown\"", ",", "\"name\"", ":", "\"DRAG_MODE\"", ",", "\"options\"", ":", "[", "[", "Blockly", ".", "Msg", ".", "SENSING_SETDRAGMODE_DRAGGABLE", ",", "'draggable'", "]", ",", "[", "Blockly", ".", "Msg", ".", "SENSING_SETDRAGMODE_NOTDRAGGABLE", ",", "'not draggable'", "]", "]", "}", "]", ",", "\"category\"", ":", "Blockly", ".", "Categories", ".", "sensing", ",", "\"extensions\"", ":", "[", "\"colours_sensing\"", ",", "\"shape_statement\"", "]", "}", ")", ";", "}" ]
Block to set drag mode. @this Blockly.Block
[ "Block", "to", "set", "drag", "mode", "." ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/blocks_vertical/sensing.js#L325-L341
3,418
LLK/scratch-blocks
blocks_vertical/sensing.js
function() { this.jsonInit({ "message0": Blockly.Msg.SENSING_OF, "args0": [ { "type": "field_dropdown", "name": "PROPERTY", "options": [ [Blockly.Msg.SENSING_OF_XPOSITION, 'x position'], [Blockly.Msg.SENSING_OF_YPOSITION, 'y position'], [Blockly.Msg.SENSING_OF_DIRECTION, 'direction'], [Blockly.Msg.SENSING_OF_COSTUMENUMBER, 'costume #'], [Blockly.Msg.SENSING_OF_COSTUMENAME, 'costume name'], [Blockly.Msg.SENSING_OF_SIZE, 'size'], [Blockly.Msg.SENSING_OF_VOLUME, 'volume'], [Blockly.Msg.SENSING_OF_BACKDROPNUMBER, 'backdrop #'], [Blockly.Msg.SENSING_OF_BACKDROPNAME, 'backdrop name'] ] }, { "type": "input_value", "name": "OBJECT" } ], "output": true, "category": Blockly.Categories.sensing, "outputShape": Blockly.OUTPUT_SHAPE_ROUND, "extensions": ["colours_sensing"] }); }
javascript
function() { this.jsonInit({ "message0": Blockly.Msg.SENSING_OF, "args0": [ { "type": "field_dropdown", "name": "PROPERTY", "options": [ [Blockly.Msg.SENSING_OF_XPOSITION, 'x position'], [Blockly.Msg.SENSING_OF_YPOSITION, 'y position'], [Blockly.Msg.SENSING_OF_DIRECTION, 'direction'], [Blockly.Msg.SENSING_OF_COSTUMENUMBER, 'costume #'], [Blockly.Msg.SENSING_OF_COSTUMENAME, 'costume name'], [Blockly.Msg.SENSING_OF_SIZE, 'size'], [Blockly.Msg.SENSING_OF_VOLUME, 'volume'], [Blockly.Msg.SENSING_OF_BACKDROPNUMBER, 'backdrop #'], [Blockly.Msg.SENSING_OF_BACKDROPNAME, 'backdrop name'] ] }, { "type": "input_value", "name": "OBJECT" } ], "output": true, "category": Blockly.Categories.sensing, "outputShape": Blockly.OUTPUT_SHAPE_ROUND, "extensions": ["colours_sensing"] }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "Blockly", ".", "Msg", ".", "SENSING_OF", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"field_dropdown\"", ",", "\"name\"", ":", "\"PROPERTY\"", ",", "\"options\"", ":", "[", "[", "Blockly", ".", "Msg", ".", "SENSING_OF_XPOSITION", ",", "'x position'", "]", ",", "[", "Blockly", ".", "Msg", ".", "SENSING_OF_YPOSITION", ",", "'y position'", "]", ",", "[", "Blockly", ".", "Msg", ".", "SENSING_OF_DIRECTION", ",", "'direction'", "]", ",", "[", "Blockly", ".", "Msg", ".", "SENSING_OF_COSTUMENUMBER", ",", "'costume #'", "]", ",", "[", "Blockly", ".", "Msg", ".", "SENSING_OF_COSTUMENAME", ",", "'costume name'", "]", ",", "[", "Blockly", ".", "Msg", ".", "SENSING_OF_SIZE", ",", "'size'", "]", ",", "[", "Blockly", ".", "Msg", ".", "SENSING_OF_VOLUME", ",", "'volume'", "]", ",", "[", "Blockly", ".", "Msg", ".", "SENSING_OF_BACKDROPNUMBER", ",", "'backdrop #'", "]", ",", "[", "Blockly", ".", "Msg", ".", "SENSING_OF_BACKDROPNAME", ",", "'backdrop name'", "]", "]", "}", ",", "{", "\"type\"", ":", "\"input_value\"", ",", "\"name\"", ":", "\"OBJECT\"", "}", "]", ",", "\"output\"", ":", "true", ",", "\"category\"", ":", "Blockly", ".", "Categories", ".", "sensing", ",", "\"outputShape\"", ":", "Blockly", ".", "OUTPUT_SHAPE_ROUND", ",", "\"extensions\"", ":", "[", "\"colours_sensing\"", "]", "}", ")", ";", "}" ]
Block to report properties of sprites. @this Blockly.Block
[ "Block", "to", "report", "properties", "of", "sprites", "." ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/blocks_vertical/sensing.js#L434-L463
3,419
LLK/scratch-blocks
blocks_vertical/sensing.js
function() { this.jsonInit({ "message0": Blockly.Msg.SENSING_CURRENT, "args0": [ { "type": "field_dropdown", "name": "CURRENTMENU", "options": [ [Blockly.Msg.SENSING_CURRENT_YEAR, 'YEAR'], [Blockly.Msg.SENSING_CURRENT_MONTH, 'MONTH'], [Blockly.Msg.SENSING_CURRENT_DATE, 'DATE'], [Blockly.Msg.SENSING_CURRENT_DAYOFWEEK, 'DAYOFWEEK'], [Blockly.Msg.SENSING_CURRENT_HOUR, 'HOUR'], [Blockly.Msg.SENSING_CURRENT_MINUTE, 'MINUTE'], [Blockly.Msg.SENSING_CURRENT_SECOND, 'SECOND'] ] } ], "category": Blockly.Categories.sensing, "checkboxInFlyout": true, "extensions": ["colours_sensing", "output_number"] }); }
javascript
function() { this.jsonInit({ "message0": Blockly.Msg.SENSING_CURRENT, "args0": [ { "type": "field_dropdown", "name": "CURRENTMENU", "options": [ [Blockly.Msg.SENSING_CURRENT_YEAR, 'YEAR'], [Blockly.Msg.SENSING_CURRENT_MONTH, 'MONTH'], [Blockly.Msg.SENSING_CURRENT_DATE, 'DATE'], [Blockly.Msg.SENSING_CURRENT_DAYOFWEEK, 'DAYOFWEEK'], [Blockly.Msg.SENSING_CURRENT_HOUR, 'HOUR'], [Blockly.Msg.SENSING_CURRENT_MINUTE, 'MINUTE'], [Blockly.Msg.SENSING_CURRENT_SECOND, 'SECOND'] ] } ], "category": Blockly.Categories.sensing, "checkboxInFlyout": true, "extensions": ["colours_sensing", "output_number"] }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "Blockly", ".", "Msg", ".", "SENSING_CURRENT", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"field_dropdown\"", ",", "\"name\"", ":", "\"CURRENTMENU\"", ",", "\"options\"", ":", "[", "[", "Blockly", ".", "Msg", ".", "SENSING_CURRENT_YEAR", ",", "'YEAR'", "]", ",", "[", "Blockly", ".", "Msg", ".", "SENSING_CURRENT_MONTH", ",", "'MONTH'", "]", ",", "[", "Blockly", ".", "Msg", ".", "SENSING_CURRENT_DATE", ",", "'DATE'", "]", ",", "[", "Blockly", ".", "Msg", ".", "SENSING_CURRENT_DAYOFWEEK", ",", "'DAYOFWEEK'", "]", ",", "[", "Blockly", ".", "Msg", ".", "SENSING_CURRENT_HOUR", ",", "'HOUR'", "]", ",", "[", "Blockly", ".", "Msg", ".", "SENSING_CURRENT_MINUTE", ",", "'MINUTE'", "]", ",", "[", "Blockly", ".", "Msg", ".", "SENSING_CURRENT_SECOND", ",", "'SECOND'", "]", "]", "}", "]", ",", "\"category\"", ":", "Blockly", ".", "Categories", ".", "sensing", ",", "\"checkboxInFlyout\"", ":", "true", ",", "\"extensions\"", ":", "[", "\"colours_sensing\"", ",", "\"output_number\"", "]", "}", ")", ";", "}" ]
Block to Report the current option. @this Blockly.Block
[ "Block", "to", "Report", "the", "current", "option", "." ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/blocks_vertical/sensing.js#L471-L493
3,420
LLK/scratch-blocks
blocks_vertical/sound.js
function() { this.jsonInit({ "message0": "%1", "args0": [ { "type": "field_dropdown", "name": "SOUND_MENU", "options": [ ['1', '0'], ['2', '1'], ['3', '2'], ['4', '3'], ['5', '4'], ['6', '5'], ['7', '6'], ['8', '7'], ['9', '8'], ['10', '9'], ['call a function', function() { window.alert('function called!');} ] ] } ], "colour": Blockly.Colours.sounds.secondary, "colourSecondary": Blockly.Colours.sounds.secondary, "colourTertiary": Blockly.Colours.sounds.tertiary, "extensions": ["output_string"] }); }
javascript
function() { this.jsonInit({ "message0": "%1", "args0": [ { "type": "field_dropdown", "name": "SOUND_MENU", "options": [ ['1', '0'], ['2', '1'], ['3', '2'], ['4', '3'], ['5', '4'], ['6', '5'], ['7', '6'], ['8', '7'], ['9', '8'], ['10', '9'], ['call a function', function() { window.alert('function called!');} ] ] } ], "colour": Blockly.Colours.sounds.secondary, "colourSecondary": Blockly.Colours.sounds.secondary, "colourTertiary": Blockly.Colours.sounds.tertiary, "extensions": ["output_string"] }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "\"%1\"", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"field_dropdown\"", ",", "\"name\"", ":", "\"SOUND_MENU\"", ",", "\"options\"", ":", "[", "[", "'1'", ",", "'0'", "]", ",", "[", "'2'", ",", "'1'", "]", ",", "[", "'3'", ",", "'2'", "]", ",", "[", "'4'", ",", "'3'", "]", ",", "[", "'5'", ",", "'4'", "]", ",", "[", "'6'", ",", "'5'", "]", ",", "[", "'7'", ",", "'6'", "]", ",", "[", "'8'", ",", "'7'", "]", ",", "[", "'9'", ",", "'8'", "]", ",", "[", "'10'", ",", "'9'", "]", ",", "[", "'call a function'", ",", "function", "(", ")", "{", "window", ".", "alert", "(", "'function called!'", ")", ";", "}", "]", "]", "}", "]", ",", "\"colour\"", ":", "Blockly", ".", "Colours", ".", "sounds", ".", "secondary", ",", "\"colourSecondary\"", ":", "Blockly", ".", "Colours", ".", "sounds", ".", "secondary", ",", "\"colourTertiary\"", ":", "Blockly", ".", "Colours", ".", "sounds", ".", "tertiary", ",", "\"extensions\"", ":", "[", "\"output_string\"", "]", "}", ")", ";", "}" ]
Sound effects drop-down menu. @this Blockly.Block
[ "Sound", "effects", "drop", "-", "down", "menu", "." ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/blocks_vertical/sound.js#L35-L64
3,421
LLK/scratch-blocks
blocks_vertical/sound.js
function() { this.jsonInit({ "message0": Blockly.Msg.SOUND_SETEFFECTO, "args0": [ { "type": "field_dropdown", "name": "EFFECT", "options": [ [Blockly.Msg.SOUND_EFFECTS_PITCH, 'PITCH'], [Blockly.Msg.SOUND_EFFECTS_PAN, 'PAN'] ] }, { "type": "input_value", "name": "VALUE" } ], "category": Blockly.Categories.sound, "extensions": ["colours_sounds", "shape_statement"] }); }
javascript
function() { this.jsonInit({ "message0": Blockly.Msg.SOUND_SETEFFECTO, "args0": [ { "type": "field_dropdown", "name": "EFFECT", "options": [ [Blockly.Msg.SOUND_EFFECTS_PITCH, 'PITCH'], [Blockly.Msg.SOUND_EFFECTS_PAN, 'PAN'] ] }, { "type": "input_value", "name": "VALUE" } ], "category": Blockly.Categories.sound, "extensions": ["colours_sounds", "shape_statement"] }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "Blockly", ".", "Msg", ".", "SOUND_SETEFFECTO", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"field_dropdown\"", ",", "\"name\"", ":", "\"EFFECT\"", ",", "\"options\"", ":", "[", "[", "Blockly", ".", "Msg", ".", "SOUND_EFFECTS_PITCH", ",", "'PITCH'", "]", ",", "[", "Blockly", ".", "Msg", ".", "SOUND_EFFECTS_PAN", ",", "'PAN'", "]", "]", "}", ",", "{", "\"type\"", ":", "\"input_value\"", ",", "\"name\"", ":", "\"VALUE\"", "}", "]", ",", "\"category\"", ":", "Blockly", ".", "Categories", ".", "sound", ",", "\"extensions\"", ":", "[", "\"colours_sounds\"", ",", "\"shape_statement\"", "]", "}", ")", ";", "}" ]
Block to set the audio effect @this Blockly.Block
[ "Block", "to", "set", "the", "audio", "effect" ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/blocks_vertical/sound.js#L126-L146
3,422
LLK/scratch-blocks
blocks_vertical/sound.js
function() { this.jsonInit({ "message0": Blockly.Msg.SOUND_CHANGEEFFECTBY, "args0": [ { "type": "field_dropdown", "name": "EFFECT", "options": [ [Blockly.Msg.SOUND_EFFECTS_PITCH, 'PITCH'], [Blockly.Msg.SOUND_EFFECTS_PAN, 'PAN'] ] }, { "type": "input_value", "name": "VALUE" } ], "category": Blockly.Categories.sound, "extensions": ["colours_sounds", "shape_statement"] }); }
javascript
function() { this.jsonInit({ "message0": Blockly.Msg.SOUND_CHANGEEFFECTBY, "args0": [ { "type": "field_dropdown", "name": "EFFECT", "options": [ [Blockly.Msg.SOUND_EFFECTS_PITCH, 'PITCH'], [Blockly.Msg.SOUND_EFFECTS_PAN, 'PAN'] ] }, { "type": "input_value", "name": "VALUE" } ], "category": Blockly.Categories.sound, "extensions": ["colours_sounds", "shape_statement"] }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "Blockly", ".", "Msg", ".", "SOUND_CHANGEEFFECTBY", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"field_dropdown\"", ",", "\"name\"", ":", "\"EFFECT\"", ",", "\"options\"", ":", "[", "[", "Blockly", ".", "Msg", ".", "SOUND_EFFECTS_PITCH", ",", "'PITCH'", "]", ",", "[", "Blockly", ".", "Msg", ".", "SOUND_EFFECTS_PAN", ",", "'PAN'", "]", "]", "}", ",", "{", "\"type\"", ":", "\"input_value\"", ",", "\"name\"", ":", "\"VALUE\"", "}", "]", ",", "\"category\"", ":", "Blockly", ".", "Categories", ".", "sound", ",", "\"extensions\"", ":", "[", "\"colours_sounds\"", ",", "\"shape_statement\"", "]", "}", ")", ";", "}" ]
Block to change the audio effect @this Blockly.Block
[ "Block", "to", "change", "the", "audio", "effect" ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/blocks_vertical/sound.js#L155-L175
3,423
LLK/scratch-blocks
i18n/js_to_json.js
function (str) { str = str.split('Blockly.Msg.')[1].split(' '); return { key: str[0], value: str .splice(2, str.length) .join(' ') .slice(1, -2) // strip off initial ', and ending '; .replace(/\\'/g, "'") }; }
javascript
function (str) { str = str.split('Blockly.Msg.')[1].split(' '); return { key: str[0], value: str .splice(2, str.length) .join(' ') .slice(1, -2) // strip off initial ', and ending '; .replace(/\\'/g, "'") }; }
[ "function", "(", "str", ")", "{", "str", "=", "str", ".", "split", "(", "'Blockly.Msg.'", ")", "[", "1", "]", ".", "split", "(", "' '", ")", ";", "return", "{", "key", ":", "str", "[", "0", "]", ",", "value", ":", "str", ".", "splice", "(", "2", ",", "str", ".", "length", ")", ".", "join", "(", "' '", ")", ".", "slice", "(", "1", ",", "-", "2", ")", "// strip off initial ', and ending ';", ".", "replace", "(", "/", "\\\\'", "/", "g", ",", "\"'\"", ")", "}", ";", "}" ]
Extract key and value from message definition
[ "Extract", "key", "and", "value", "from", "message", "definition" ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/i18n/js_to_json.js#L22-L32
3,424
LLK/scratch-blocks
blocks_vertical/control.js
function() { this.jsonInit({ "type": "control_if_else", "message0": Blockly.Msg.CONTROL_IF, "message1": "%1", "message2": Blockly.Msg.CONTROL_ELSE, "message3": "%1", "args0": [ { "type": "input_value", "name": "CONDITION", "check": "Boolean" } ], "args1": [ { "type": "input_statement", "name": "SUBSTACK" } ], "args3": [ { "type": "input_statement", "name": "SUBSTACK2" } ], "category": Blockly.Categories.control, "extensions": ["colours_control", "shape_statement"] }); }
javascript
function() { this.jsonInit({ "type": "control_if_else", "message0": Blockly.Msg.CONTROL_IF, "message1": "%1", "message2": Blockly.Msg.CONTROL_ELSE, "message3": "%1", "args0": [ { "type": "input_value", "name": "CONDITION", "check": "Boolean" } ], "args1": [ { "type": "input_statement", "name": "SUBSTACK" } ], "args3": [ { "type": "input_statement", "name": "SUBSTACK2" } ], "category": Blockly.Categories.control, "extensions": ["colours_control", "shape_statement"] }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"type\"", ":", "\"control_if_else\"", ",", "\"message0\"", ":", "Blockly", ".", "Msg", ".", "CONTROL_IF", ",", "\"message1\"", ":", "\"%1\"", ",", "\"message2\"", ":", "Blockly", ".", "Msg", ".", "CONTROL_ELSE", ",", "\"message3\"", ":", "\"%1\"", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"input_value\"", ",", "\"name\"", ":", "\"CONDITION\"", ",", "\"check\"", ":", "\"Boolean\"", "}", "]", ",", "\"args1\"", ":", "[", "{", "\"type\"", ":", "\"input_statement\"", ",", "\"name\"", ":", "\"SUBSTACK\"", "}", "]", ",", "\"args3\"", ":", "[", "{", "\"type\"", ":", "\"input_statement\"", ",", "\"name\"", ":", "\"SUBSTACK2\"", "}", "]", ",", "\"category\"", ":", "Blockly", ".", "Categories", ".", "control", ",", "\"extensions\"", ":", "[", "\"colours_control\"", ",", "\"shape_statement\"", "]", "}", ")", ";", "}" ]
Block for if-else. @this Blockly.Block
[ "Block", "for", "if", "-", "else", "." ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/blocks_vertical/control.js#L140-L169
3,425
LLK/scratch-blocks
blocks_vertical/control.js
function() { var ALL_SCRIPTS = 'all'; var THIS_SCRIPT = 'this script'; var OTHER_SCRIPTS = 'other scripts in sprite'; var stopDropdown = new Blockly.FieldDropdown(function() { if (this.sourceBlock_ && this.sourceBlock_.nextConnection && this.sourceBlock_.nextConnection.isConnected()) { return [ [Blockly.Msg.CONTROL_STOP_OTHER, OTHER_SCRIPTS] ]; } return [[Blockly.Msg.CONTROL_STOP_ALL, ALL_SCRIPTS], [Blockly.Msg.CONTROL_STOP_THIS, THIS_SCRIPT], [Blockly.Msg.CONTROL_STOP_OTHER, OTHER_SCRIPTS] ]; }, function(option) { // Create an event group to keep field value and mutator in sync // Return null at the end because setValue is called here already. Blockly.Events.setGroup(true); var oldMutation = Blockly.Xml.domToText(this.sourceBlock_.mutationToDom()); this.sourceBlock_.setNextStatement(option == OTHER_SCRIPTS); var newMutation = Blockly.Xml.domToText(this.sourceBlock_.mutationToDom()); Blockly.Events.fire(new Blockly.Events.BlockChange(this.sourceBlock_, 'mutation', null, oldMutation, newMutation)); this.setValue(option); Blockly.Events.setGroup(false); return null; }); this.appendDummyInput() .appendField(Blockly.Msg.CONTROL_STOP) .appendField(stopDropdown, 'STOP_OPTION'); this.setCategory(Blockly.Categories.control); this.setColour(Blockly.Colours.control.primary, Blockly.Colours.control.secondary, Blockly.Colours.control.tertiary ); this.setPreviousStatement(true); }
javascript
function() { var ALL_SCRIPTS = 'all'; var THIS_SCRIPT = 'this script'; var OTHER_SCRIPTS = 'other scripts in sprite'; var stopDropdown = new Blockly.FieldDropdown(function() { if (this.sourceBlock_ && this.sourceBlock_.nextConnection && this.sourceBlock_.nextConnection.isConnected()) { return [ [Blockly.Msg.CONTROL_STOP_OTHER, OTHER_SCRIPTS] ]; } return [[Blockly.Msg.CONTROL_STOP_ALL, ALL_SCRIPTS], [Blockly.Msg.CONTROL_STOP_THIS, THIS_SCRIPT], [Blockly.Msg.CONTROL_STOP_OTHER, OTHER_SCRIPTS] ]; }, function(option) { // Create an event group to keep field value and mutator in sync // Return null at the end because setValue is called here already. Blockly.Events.setGroup(true); var oldMutation = Blockly.Xml.domToText(this.sourceBlock_.mutationToDom()); this.sourceBlock_.setNextStatement(option == OTHER_SCRIPTS); var newMutation = Blockly.Xml.domToText(this.sourceBlock_.mutationToDom()); Blockly.Events.fire(new Blockly.Events.BlockChange(this.sourceBlock_, 'mutation', null, oldMutation, newMutation)); this.setValue(option); Blockly.Events.setGroup(false); return null; }); this.appendDummyInput() .appendField(Blockly.Msg.CONTROL_STOP) .appendField(stopDropdown, 'STOP_OPTION'); this.setCategory(Blockly.Categories.control); this.setColour(Blockly.Colours.control.primary, Blockly.Colours.control.secondary, Blockly.Colours.control.tertiary ); this.setPreviousStatement(true); }
[ "function", "(", ")", "{", "var", "ALL_SCRIPTS", "=", "'all'", ";", "var", "THIS_SCRIPT", "=", "'this script'", ";", "var", "OTHER_SCRIPTS", "=", "'other scripts in sprite'", ";", "var", "stopDropdown", "=", "new", "Blockly", ".", "FieldDropdown", "(", "function", "(", ")", "{", "if", "(", "this", ".", "sourceBlock_", "&&", "this", ".", "sourceBlock_", ".", "nextConnection", "&&", "this", ".", "sourceBlock_", ".", "nextConnection", ".", "isConnected", "(", ")", ")", "{", "return", "[", "[", "Blockly", ".", "Msg", ".", "CONTROL_STOP_OTHER", ",", "OTHER_SCRIPTS", "]", "]", ";", "}", "return", "[", "[", "Blockly", ".", "Msg", ".", "CONTROL_STOP_ALL", ",", "ALL_SCRIPTS", "]", ",", "[", "Blockly", ".", "Msg", ".", "CONTROL_STOP_THIS", ",", "THIS_SCRIPT", "]", ",", "[", "Blockly", ".", "Msg", ".", "CONTROL_STOP_OTHER", ",", "OTHER_SCRIPTS", "]", "]", ";", "}", ",", "function", "(", "option", ")", "{", "// Create an event group to keep field value and mutator in sync", "// Return null at the end because setValue is called here already.", "Blockly", ".", "Events", ".", "setGroup", "(", "true", ")", ";", "var", "oldMutation", "=", "Blockly", ".", "Xml", ".", "domToText", "(", "this", ".", "sourceBlock_", ".", "mutationToDom", "(", ")", ")", ";", "this", ".", "sourceBlock_", ".", "setNextStatement", "(", "option", "==", "OTHER_SCRIPTS", ")", ";", "var", "newMutation", "=", "Blockly", ".", "Xml", ".", "domToText", "(", "this", ".", "sourceBlock_", ".", "mutationToDom", "(", ")", ")", ";", "Blockly", ".", "Events", ".", "fire", "(", "new", "Blockly", ".", "Events", ".", "BlockChange", "(", "this", ".", "sourceBlock_", ",", "'mutation'", ",", "null", ",", "oldMutation", ",", "newMutation", ")", ")", ";", "this", ".", "setValue", "(", "option", ")", ";", "Blockly", ".", "Events", ".", "setGroup", "(", "false", ")", ";", "return", "null", ";", "}", ")", ";", "this", ".", "appendDummyInput", "(", ")", ".", "appendField", "(", "Blockly", ".", "Msg", ".", "CONTROL_STOP", ")", ".", "appendField", "(", "stopDropdown", ",", "'STOP_OPTION'", ")", ";", "this", ".", "setCategory", "(", "Blockly", ".", "Categories", ".", "control", ")", ";", "this", ".", "setColour", "(", "Blockly", ".", "Colours", ".", "control", ".", "primary", ",", "Blockly", ".", "Colours", ".", "control", ".", "secondary", ",", "Blockly", ".", "Colours", ".", "control", ".", "tertiary", ")", ";", "this", ".", "setPreviousStatement", "(", "true", ")", ";", "}" ]
Block for stop all scripts. @this Blockly.Block
[ "Block", "for", "stop", "all", "scripts", "." ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/blocks_vertical/control.js#L177-L215
3,426
LLK/scratch-blocks
blocks_vertical/control.js
function() { this.jsonInit({ "message0": Blockly.Msg.CONTROL_REPEATUNTIL, "message1": "%1", "message2": "%1", "lastDummyAlign2": "RIGHT", "args0": [ { "type": "input_value", "name": "CONDITION", "check": "Boolean" } ], "args1": [ { "type": "input_statement", "name": "SUBSTACK" } ], "args2": [ { "type": "field_image", "src": Blockly.mainWorkspace.options.pathToMedia + "repeat.svg", "width": 24, "height": 24, "alt": "*", "flip_rtl": true } ], "category": Blockly.Categories.control, "extensions": ["colours_control", "shape_statement"] }); }
javascript
function() { this.jsonInit({ "message0": Blockly.Msg.CONTROL_REPEATUNTIL, "message1": "%1", "message2": "%1", "lastDummyAlign2": "RIGHT", "args0": [ { "type": "input_value", "name": "CONDITION", "check": "Boolean" } ], "args1": [ { "type": "input_statement", "name": "SUBSTACK" } ], "args2": [ { "type": "field_image", "src": Blockly.mainWorkspace.options.pathToMedia + "repeat.svg", "width": 24, "height": 24, "alt": "*", "flip_rtl": true } ], "category": Blockly.Categories.control, "extensions": ["colours_control", "shape_statement"] }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "Blockly", ".", "Msg", ".", "CONTROL_REPEATUNTIL", ",", "\"message1\"", ":", "\"%1\"", ",", "\"message2\"", ":", "\"%1\"", ",", "\"lastDummyAlign2\"", ":", "\"RIGHT\"", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"input_value\"", ",", "\"name\"", ":", "\"CONDITION\"", ",", "\"check\"", ":", "\"Boolean\"", "}", "]", ",", "\"args1\"", ":", "[", "{", "\"type\"", ":", "\"input_statement\"", ",", "\"name\"", ":", "\"SUBSTACK\"", "}", "]", ",", "\"args2\"", ":", "[", "{", "\"type\"", ":", "\"field_image\"", ",", "\"src\"", ":", "Blockly", ".", "mainWorkspace", ".", "options", ".", "pathToMedia", "+", "\"repeat.svg\"", ",", "\"width\"", ":", "24", ",", "\"height\"", ":", "24", ",", "\"alt\"", ":", "\"*\"", ",", "\"flip_rtl\"", ":", "true", "}", "]", ",", "\"category\"", ":", "Blockly", ".", "Categories", ".", "control", ",", "\"extensions\"", ":", "[", "\"colours_control\"", ",", "\"shape_statement\"", "]", "}", ")", ";", "}" ]
Block to repeat until a condition becomes true. @this Blockly.Block
[ "Block", "to", "repeat", "until", "a", "condition", "becomes", "true", "." ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/blocks_vertical/control.js#L274-L306
3,427
LLK/scratch-blocks
blocks_vertical/data.js
function() { this.jsonInit({ "message0": Blockly.Msg.DATA_SHOWVARIABLE, "args0": [ { "type": "field_variable", "name": "VARIABLE" } ], "previousStatement": null, "nextStatement": null, "category": Blockly.Categories.data, "colour": Blockly.Colours.data.primary, "colourSecondary": Blockly.Colours.data.secondary, "colourTertiary": Blockly.Colours.data.tertiary }); }
javascript
function() { this.jsonInit({ "message0": Blockly.Msg.DATA_SHOWVARIABLE, "args0": [ { "type": "field_variable", "name": "VARIABLE" } ], "previousStatement": null, "nextStatement": null, "category": Blockly.Categories.data, "colour": Blockly.Colours.data.primary, "colourSecondary": Blockly.Colours.data.secondary, "colourTertiary": Blockly.Colours.data.tertiary }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "Blockly", ".", "Msg", ".", "DATA_SHOWVARIABLE", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"field_variable\"", ",", "\"name\"", ":", "\"VARIABLE\"", "}", "]", ",", "\"previousStatement\"", ":", "null", ",", "\"nextStatement\"", ":", "null", ",", "\"category\"", ":", "Blockly", ".", "Categories", ".", "data", ",", "\"colour\"", ":", "Blockly", ".", "Colours", ".", "data", ".", "primary", ",", "\"colourSecondary\"", ":", "Blockly", ".", "Colours", ".", "data", ".", "secondary", ",", "\"colourTertiary\"", ":", "Blockly", ".", "Colours", ".", "data", ".", "tertiary", "}", ")", ";", "}" ]
Block to show a variable @this Blockly.Block
[ "Block", "to", "show", "a", "variable" ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/blocks_vertical/data.js#L109-L125
3,428
LLK/scratch-blocks
blocks_vertical/data.js
function() { this.jsonInit({ "message0": "%1", "args0": [ { "type": "field_numberdropdown", "name": "INDEX", "value": "1", "min": 1, "precision": 1, "options": [ ["1", "1"], [Blockly.Msg.DATA_INDEX_LAST, "last"], [Blockly.Msg.DATA_INDEX_ALL, "all"] ] } ], "category": Blockly.Categories.data, "extensions": ["colours_textfield", "output_string"] }); }
javascript
function() { this.jsonInit({ "message0": "%1", "args0": [ { "type": "field_numberdropdown", "name": "INDEX", "value": "1", "min": 1, "precision": 1, "options": [ ["1", "1"], [Blockly.Msg.DATA_INDEX_LAST, "last"], [Blockly.Msg.DATA_INDEX_ALL, "all"] ] } ], "category": Blockly.Categories.data, "extensions": ["colours_textfield", "output_string"] }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "\"%1\"", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"field_numberdropdown\"", ",", "\"name\"", ":", "\"INDEX\"", ",", "\"value\"", ":", "\"1\"", ",", "\"min\"", ":", "1", ",", "\"precision\"", ":", "1", ",", "\"options\"", ":", "[", "[", "\"1\"", ",", "\"1\"", "]", ",", "[", "Blockly", ".", "Msg", ".", "DATA_INDEX_LAST", ",", "\"last\"", "]", ",", "[", "Blockly", ".", "Msg", ".", "DATA_INDEX_ALL", ",", "\"all\"", "]", "]", "}", "]", ",", "\"category\"", ":", "Blockly", ".", "Categories", ".", "data", ",", "\"extensions\"", ":", "[", "\"colours_textfield\"", ",", "\"output_string\"", "]", "}", ")", ";", "}" ]
List index menu, with all option. @this Blockly.Block
[ "List", "index", "menu", "with", "all", "option", "." ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/blocks_vertical/data.js#L180-L200
3,429
LLK/scratch-blocks
blocks_vertical/data.js
function() { this.jsonInit({ "message0": "%1", "args0": [ { "type": "field_numberdropdown", "name": "INDEX", "value": "1", "min": 1, "precision": 1, "options": [ ["1", "1"], [Blockly.Msg.DATA_INDEX_LAST, "last"], [Blockly.Msg.DATA_INDEX_RANDOM, "random"] ] } ], "category": Blockly.Categories.data, "extensions": ["colours_textfield", "output_string"] }); }
javascript
function() { this.jsonInit({ "message0": "%1", "args0": [ { "type": "field_numberdropdown", "name": "INDEX", "value": "1", "min": 1, "precision": 1, "options": [ ["1", "1"], [Blockly.Msg.DATA_INDEX_LAST, "last"], [Blockly.Msg.DATA_INDEX_RANDOM, "random"] ] } ], "category": Blockly.Categories.data, "extensions": ["colours_textfield", "output_string"] }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "\"%1\"", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"field_numberdropdown\"", ",", "\"name\"", ":", "\"INDEX\"", ",", "\"value\"", ":", "\"1\"", ",", "\"min\"", ":", "1", ",", "\"precision\"", ":", "1", ",", "\"options\"", ":", "[", "[", "\"1\"", ",", "\"1\"", "]", ",", "[", "Blockly", ".", "Msg", ".", "DATA_INDEX_LAST", ",", "\"last\"", "]", ",", "[", "Blockly", ".", "Msg", ".", "DATA_INDEX_RANDOM", ",", "\"random\"", "]", "]", "}", "]", ",", "\"category\"", ":", "Blockly", ".", "Categories", ".", "data", ",", "\"extensions\"", ":", "[", "\"colours_textfield\"", ",", "\"output_string\"", "]", "}", ")", ";", "}" ]
List index menu, with random option. @this Blockly.Block
[ "List", "index", "menu", "with", "random", "option", "." ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/blocks_vertical/data.js#L208-L228
3,430
LLK/scratch-blocks
blocks_vertical/data.js
function() { this.jsonInit({ "message0": Blockly.Msg.DATA_ITEMOFLIST, "args0": [ { "type": "input_value", "name": "INDEX" }, { "type": "field_variable", "name": "LIST", "variableTypes": [Blockly.LIST_VARIABLE_TYPE] } ], "output": null, "category": Blockly.Categories.dataLists, "extensions": ["colours_data_lists"], "outputShape": Blockly.OUTPUT_SHAPE_ROUND }); }
javascript
function() { this.jsonInit({ "message0": Blockly.Msg.DATA_ITEMOFLIST, "args0": [ { "type": "input_value", "name": "INDEX" }, { "type": "field_variable", "name": "LIST", "variableTypes": [Blockly.LIST_VARIABLE_TYPE] } ], "output": null, "category": Blockly.Categories.dataLists, "extensions": ["colours_data_lists"], "outputShape": Blockly.OUTPUT_SHAPE_ROUND }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "Blockly", ".", "Msg", ".", "DATA_ITEMOFLIST", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"input_value\"", ",", "\"name\"", ":", "\"INDEX\"", "}", ",", "{", "\"type\"", ":", "\"field_variable\"", ",", "\"name\"", ":", "\"LIST\"", ",", "\"variableTypes\"", ":", "[", "Blockly", ".", "LIST_VARIABLE_TYPE", "]", "}", "]", ",", "\"output\"", ":", "null", ",", "\"category\"", ":", "Blockly", ".", "Categories", ".", "dataLists", ",", "\"extensions\"", ":", "[", "\"colours_data_lists\"", "]", ",", "\"outputShape\"", ":", "Blockly", ".", "OUTPUT_SHAPE_ROUND", "}", ")", ";", "}" ]
Block for reporting item of list. @this Blockly.Block
[ "Block", "for", "reporting", "item", "of", "list", "." ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/blocks_vertical/data.js#L365-L384
3,431
LLK/scratch-blocks
blocks_vertical/data.js
function(options) { var fieldName = 'VARIABLE'; if (this.isCollapsed()) { return; } var currentVarName = this.getField(fieldName).text_; if (!this.isInFlyout) { var variablesList = this.workspace.getVariablesOfType(''); variablesList.sort(function(a, b) { return Blockly.scratchBlocksUtils.compareStrings(a.name, b.name); }); for (var i = 0; i < variablesList.length; i++) { var varName = variablesList[i].name; if (varName == currentVarName) continue; var option = {enabled: true}; option.text = varName; option.callback = Blockly.Constants.Data.VARIABLE_OPTION_CALLBACK_FACTORY(this, variablesList[i].getId(), fieldName); options.push(option); } } else { var renameOption = { text: Blockly.Msg.RENAME_VARIABLE, enabled: true, callback: Blockly.Constants.Data.RENAME_OPTION_CALLBACK_FACTORY(this, fieldName) }; var deleteOption = { text: Blockly.Msg.DELETE_VARIABLE.replace('%1', currentVarName), enabled: true, callback: Blockly.Constants.Data.DELETE_OPTION_CALLBACK_FACTORY(this, fieldName) }; options.push(renameOption); options.push(deleteOption); } }
javascript
function(options) { var fieldName = 'VARIABLE'; if (this.isCollapsed()) { return; } var currentVarName = this.getField(fieldName).text_; if (!this.isInFlyout) { var variablesList = this.workspace.getVariablesOfType(''); variablesList.sort(function(a, b) { return Blockly.scratchBlocksUtils.compareStrings(a.name, b.name); }); for (var i = 0; i < variablesList.length; i++) { var varName = variablesList[i].name; if (varName == currentVarName) continue; var option = {enabled: true}; option.text = varName; option.callback = Blockly.Constants.Data.VARIABLE_OPTION_CALLBACK_FACTORY(this, variablesList[i].getId(), fieldName); options.push(option); } } else { var renameOption = { text: Blockly.Msg.RENAME_VARIABLE, enabled: true, callback: Blockly.Constants.Data.RENAME_OPTION_CALLBACK_FACTORY(this, fieldName) }; var deleteOption = { text: Blockly.Msg.DELETE_VARIABLE.replace('%1', currentVarName), enabled: true, callback: Blockly.Constants.Data.DELETE_OPTION_CALLBACK_FACTORY(this, fieldName) }; options.push(renameOption); options.push(deleteOption); } }
[ "function", "(", "options", ")", "{", "var", "fieldName", "=", "'VARIABLE'", ";", "if", "(", "this", ".", "isCollapsed", "(", ")", ")", "{", "return", ";", "}", "var", "currentVarName", "=", "this", ".", "getField", "(", "fieldName", ")", ".", "text_", ";", "if", "(", "!", "this", ".", "isInFlyout", ")", "{", "var", "variablesList", "=", "this", ".", "workspace", ".", "getVariablesOfType", "(", "''", ")", ";", "variablesList", ".", "sort", "(", "function", "(", "a", ",", "b", ")", "{", "return", "Blockly", ".", "scratchBlocksUtils", ".", "compareStrings", "(", "a", ".", "name", ",", "b", ".", "name", ")", ";", "}", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "variablesList", ".", "length", ";", "i", "++", ")", "{", "var", "varName", "=", "variablesList", "[", "i", "]", ".", "name", ";", "if", "(", "varName", "==", "currentVarName", ")", "continue", ";", "var", "option", "=", "{", "enabled", ":", "true", "}", ";", "option", ".", "text", "=", "varName", ";", "option", ".", "callback", "=", "Blockly", ".", "Constants", ".", "Data", ".", "VARIABLE_OPTION_CALLBACK_FACTORY", "(", "this", ",", "variablesList", "[", "i", "]", ".", "getId", "(", ")", ",", "fieldName", ")", ";", "options", ".", "push", "(", "option", ")", ";", "}", "}", "else", "{", "var", "renameOption", "=", "{", "text", ":", "Blockly", ".", "Msg", ".", "RENAME_VARIABLE", ",", "enabled", ":", "true", ",", "callback", ":", "Blockly", ".", "Constants", ".", "Data", ".", "RENAME_OPTION_CALLBACK_FACTORY", "(", "this", ",", "fieldName", ")", "}", ";", "var", "deleteOption", "=", "{", "text", ":", "Blockly", ".", "Msg", ".", "DELETE_VARIABLE", ".", "replace", "(", "'%1'", ",", "currentVarName", ")", ",", "enabled", ":", "true", ",", "callback", ":", "Blockly", ".", "Constants", ".", "Data", ".", "DELETE_OPTION_CALLBACK_FACTORY", "(", "this", ",", "fieldName", ")", "}", ";", "options", ".", "push", "(", "renameOption", ")", ";", "options", ".", "push", "(", "deleteOption", ")", ";", "}", "}" ]
Add context menu option to change the selected variable. @param {!Array} options List of menu options to add to. @this Blockly.Block
[ "Add", "context", "menu", "option", "to", "change", "the", "selected", "variable", "." ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/blocks_vertical/data.js#L516-L554
3,432
LLK/scratch-blocks
blocks_vertical/data.js
function(options) { var fieldName = 'LIST'; if (this.isCollapsed()) { return; } var currentVarName = this.getField(fieldName).text_; if (!this.isInFlyout) { var variablesList = this.workspace.getVariablesOfType('list'); for (var i = 0; i < variablesList.length; i++) { var varName = variablesList[i].name; if (varName == currentVarName) continue; var option = {enabled: true}; option.text = varName; option.callback = Blockly.Constants.Data.VARIABLE_OPTION_CALLBACK_FACTORY(this, variablesList[i].getId(), fieldName); options.push(option); } } else { var renameOption = { text: Blockly.Msg.RENAME_LIST, enabled: true, callback: Blockly.Constants.Data.RENAME_OPTION_CALLBACK_FACTORY(this, fieldName) }; var deleteOption = { text: Blockly.Msg.DELETE_LIST.replace('%1', currentVarName), enabled: true, callback: Blockly.Constants.Data.DELETE_OPTION_CALLBACK_FACTORY(this, fieldName) }; options.push(renameOption); options.push(deleteOption); } }
javascript
function(options) { var fieldName = 'LIST'; if (this.isCollapsed()) { return; } var currentVarName = this.getField(fieldName).text_; if (!this.isInFlyout) { var variablesList = this.workspace.getVariablesOfType('list'); for (var i = 0; i < variablesList.length; i++) { var varName = variablesList[i].name; if (varName == currentVarName) continue; var option = {enabled: true}; option.text = varName; option.callback = Blockly.Constants.Data.VARIABLE_OPTION_CALLBACK_FACTORY(this, variablesList[i].getId(), fieldName); options.push(option); } } else { var renameOption = { text: Blockly.Msg.RENAME_LIST, enabled: true, callback: Blockly.Constants.Data.RENAME_OPTION_CALLBACK_FACTORY(this, fieldName) }; var deleteOption = { text: Blockly.Msg.DELETE_LIST.replace('%1', currentVarName), enabled: true, callback: Blockly.Constants.Data.DELETE_OPTION_CALLBACK_FACTORY(this, fieldName) }; options.push(renameOption); options.push(deleteOption); } }
[ "function", "(", "options", ")", "{", "var", "fieldName", "=", "'LIST'", ";", "if", "(", "this", ".", "isCollapsed", "(", ")", ")", "{", "return", ";", "}", "var", "currentVarName", "=", "this", ".", "getField", "(", "fieldName", ")", ".", "text_", ";", "if", "(", "!", "this", ".", "isInFlyout", ")", "{", "var", "variablesList", "=", "this", ".", "workspace", ".", "getVariablesOfType", "(", "'list'", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "variablesList", ".", "length", ";", "i", "++", ")", "{", "var", "varName", "=", "variablesList", "[", "i", "]", ".", "name", ";", "if", "(", "varName", "==", "currentVarName", ")", "continue", ";", "var", "option", "=", "{", "enabled", ":", "true", "}", ";", "option", ".", "text", "=", "varName", ";", "option", ".", "callback", "=", "Blockly", ".", "Constants", ".", "Data", ".", "VARIABLE_OPTION_CALLBACK_FACTORY", "(", "this", ",", "variablesList", "[", "i", "]", ".", "getId", "(", ")", ",", "fieldName", ")", ";", "options", ".", "push", "(", "option", ")", ";", "}", "}", "else", "{", "var", "renameOption", "=", "{", "text", ":", "Blockly", ".", "Msg", ".", "RENAME_LIST", ",", "enabled", ":", "true", ",", "callback", ":", "Blockly", ".", "Constants", ".", "Data", ".", "RENAME_OPTION_CALLBACK_FACTORY", "(", "this", ",", "fieldName", ")", "}", ";", "var", "deleteOption", "=", "{", "text", ":", "Blockly", ".", "Msg", ".", "DELETE_LIST", ".", "replace", "(", "'%1'", ",", "currentVarName", ")", ",", "enabled", ":", "true", ",", "callback", ":", "Blockly", ".", "Constants", ".", "Data", ".", "DELETE_OPTION_CALLBACK_FACTORY", "(", "this", ",", "fieldName", ")", "}", ";", "options", ".", "push", "(", "renameOption", ")", ";", "options", ".", "push", "(", "deleteOption", ")", ";", "}", "}" ]
Add context menu option to change the selected list. @param {!Array} options List of menu options to add to. @this Blockly.Block
[ "Add", "context", "menu", "option", "to", "change", "the", "selected", "list", "." ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/blocks_vertical/data.js#L574-L610
3,433
LLK/scratch-blocks
core/connection_db.js
checkConnection_
function checkConnection_(yIndex) { var dx = currentX - db[yIndex].x_; var dy = currentY - db[yIndex].y_; var r = Math.sqrt(dx * dx + dy * dy); if (r <= maxRadius) { neighbours.push(db[yIndex]); } return dy < maxRadius; }
javascript
function checkConnection_(yIndex) { var dx = currentX - db[yIndex].x_; var dy = currentY - db[yIndex].y_; var r = Math.sqrt(dx * dx + dy * dy); if (r <= maxRadius) { neighbours.push(db[yIndex]); } return dy < maxRadius; }
[ "function", "checkConnection_", "(", "yIndex", ")", "{", "var", "dx", "=", "currentX", "-", "db", "[", "yIndex", "]", ".", "x_", ";", "var", "dy", "=", "currentY", "-", "db", "[", "yIndex", "]", ".", "y_", ";", "var", "r", "=", "Math", ".", "sqrt", "(", "dx", "*", "dx", "+", "dy", "*", "dy", ")", ";", "if", "(", "r", "<=", "maxRadius", ")", "{", "neighbours", ".", "push", "(", "db", "[", "yIndex", "]", ")", ";", "}", "return", "dy", "<", "maxRadius", ";", "}" ]
Computes if the current connection is within the allowed radius of another connection. This function is a closure and has access to outside variables. @param {number} yIndex The other connection's index in the database. @return {boolean} True if the current connection's vertical distance from the other connection is less than the allowed radius.
[ "Computes", "if", "the", "current", "connection", "is", "within", "the", "allowed", "radius", "of", "another", "connection", ".", "This", "function", "is", "a", "closure", "and", "has", "access", "to", "outside", "variables", "." ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/core/connection_db.js#L185-L193
3,434
LLK/scratch-blocks
blocks_vertical/motion.js
function() { this.jsonInit({ "message0": Blockly.Msg.MOTION_TURNRIGHT, "args0": [ { "type": "field_image", "src": Blockly.mainWorkspace.options.pathToMedia + "rotate-right.svg", "width": 24, "height": 24 }, { "type": "input_value", "name": "DEGREES" } ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); }
javascript
function() { this.jsonInit({ "message0": Blockly.Msg.MOTION_TURNRIGHT, "args0": [ { "type": "field_image", "src": Blockly.mainWorkspace.options.pathToMedia + "rotate-right.svg", "width": 24, "height": 24 }, { "type": "input_value", "name": "DEGREES" } ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "Blockly", ".", "Msg", ".", "MOTION_TURNRIGHT", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"field_image\"", ",", "\"src\"", ":", "Blockly", ".", "mainWorkspace", ".", "options", ".", "pathToMedia", "+", "\"rotate-right.svg\"", ",", "\"width\"", ":", "24", ",", "\"height\"", ":", "24", "}", ",", "{", "\"type\"", ":", "\"input_value\"", ",", "\"name\"", ":", "\"DEGREES\"", "}", "]", ",", "\"category\"", ":", "Blockly", ".", "Categories", ".", "motion", ",", "\"extensions\"", ":", "[", "\"colours_motion\"", ",", "\"shape_statement\"", "]", "}", ")", ";", "}" ]
Block to turn right. @this Blockly.Block
[ "Block", "to", "turn", "right", "." ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/blocks_vertical/motion.js#L56-L74
3,435
LLK/scratch-blocks
blocks_vertical/motion.js
function() { this.jsonInit({ "message0": "%1", "args0": [ { "type": "field_dropdown", "name": "TOWARDS", "options": [ [Blockly.Msg.MOTION_POINTTOWARDS_POINTER, '_mouse_'], [Blockly.Msg.MOTION_POINTTOWARDS_RANDOM, '_random_'] ] } ], "colour": Blockly.Colours.motion.secondary, "colourSecondary": Blockly.Colours.motion.secondary, "colourTertiary": Blockly.Colours.motion.tertiary, "extensions": ["output_string"] }); }
javascript
function() { this.jsonInit({ "message0": "%1", "args0": [ { "type": "field_dropdown", "name": "TOWARDS", "options": [ [Blockly.Msg.MOTION_POINTTOWARDS_POINTER, '_mouse_'], [Blockly.Msg.MOTION_POINTTOWARDS_RANDOM, '_random_'] ] } ], "colour": Blockly.Colours.motion.secondary, "colourSecondary": Blockly.Colours.motion.secondary, "colourTertiary": Blockly.Colours.motion.tertiary, "extensions": ["output_string"] }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "\"%1\"", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"field_dropdown\"", ",", "\"name\"", ":", "\"TOWARDS\"", ",", "\"options\"", ":", "[", "[", "Blockly", ".", "Msg", ".", "MOTION_POINTTOWARDS_POINTER", ",", "'_mouse_'", "]", ",", "[", "Blockly", ".", "Msg", ".", "MOTION_POINTTOWARDS_RANDOM", ",", "'_random_'", "]", "]", "}", "]", ",", "\"colour\"", ":", "Blockly", ".", "Colours", ".", "motion", ".", "secondary", ",", "\"colourSecondary\"", ":", "Blockly", ".", "Colours", ".", "motion", ".", "secondary", ",", "\"colourTertiary\"", ":", "Blockly", ".", "Colours", ".", "motion", ".", "tertiary", ",", "\"extensions\"", ":", "[", "\"output_string\"", "]", "}", ")", ";", "}" ]
Point towards drop-down menu. @this Blockly.Block
[ "Point", "towards", "drop", "-", "down", "menu", "." ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/blocks_vertical/motion.js#L128-L146
3,436
LLK/scratch-blocks
blocks_vertical/motion.js
function() { this.jsonInit({ "message0": "%1", "args0": [ { "type": "field_dropdown", "name": "TO", "options": [ [Blockly.Msg.MOTION_GOTO_POINTER, '_mouse_'], [Blockly.Msg.MOTION_GOTO_RANDOM, '_random_'] ] } ], "colour": Blockly.Colours.motion.secondary, "colourSecondary": Blockly.Colours.motion.secondary, "colourTertiary": Blockly.Colours.motion.tertiary, "extensions": ["output_string"] }); }
javascript
function() { this.jsonInit({ "message0": "%1", "args0": [ { "type": "field_dropdown", "name": "TO", "options": [ [Blockly.Msg.MOTION_GOTO_POINTER, '_mouse_'], [Blockly.Msg.MOTION_GOTO_RANDOM, '_random_'] ] } ], "colour": Blockly.Colours.motion.secondary, "colourSecondary": Blockly.Colours.motion.secondary, "colourTertiary": Blockly.Colours.motion.tertiary, "extensions": ["output_string"] }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "\"%1\"", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"field_dropdown\"", ",", "\"name\"", ":", "\"TO\"", ",", "\"options\"", ":", "[", "[", "Blockly", ".", "Msg", ".", "MOTION_GOTO_POINTER", ",", "'_mouse_'", "]", ",", "[", "Blockly", ".", "Msg", ".", "MOTION_GOTO_RANDOM", ",", "'_random_'", "]", "]", "}", "]", ",", "\"colour\"", ":", "Blockly", ".", "Colours", ".", "motion", ".", "secondary", ",", "\"colourSecondary\"", ":", "Blockly", ".", "Colours", ".", "motion", ".", "secondary", ",", "\"colourTertiary\"", ":", "Blockly", ".", "Colours", ".", "motion", ".", "tertiary", ",", "\"extensions\"", ":", "[", "\"output_string\"", "]", "}", ")", ";", "}" ]
Go to drop-down menu. @this Blockly.Block
[ "Go", "to", "drop", "-", "down", "menu", "." ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/blocks_vertical/motion.js#L174-L192
3,437
LLK/scratch-blocks
blocks_vertical/motion.js
function() { this.jsonInit({ "message0": "%1", "args0": [ { "type": "field_dropdown", "name": "TO", "options": [ [Blockly.Msg.MOTION_GLIDETO_POINTER, '_mouse_'], [Blockly.Msg.MOTION_GLIDETO_RANDOM, '_random_'] ] } ], "colour": Blockly.Colours.motion.secondary, "colourSecondary": Blockly.Colours.motion.secondary, "colourTertiary": Blockly.Colours.motion.tertiary, "extensions": ["output_string"] }); }
javascript
function() { this.jsonInit({ "message0": "%1", "args0": [ { "type": "field_dropdown", "name": "TO", "options": [ [Blockly.Msg.MOTION_GLIDETO_POINTER, '_mouse_'], [Blockly.Msg.MOTION_GLIDETO_RANDOM, '_random_'] ] } ], "colour": Blockly.Colours.motion.secondary, "colourSecondary": Blockly.Colours.motion.secondary, "colourTertiary": Blockly.Colours.motion.tertiary, "extensions": ["output_string"] }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "\"%1\"", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"field_dropdown\"", ",", "\"name\"", ":", "\"TO\"", ",", "\"options\"", ":", "[", "[", "Blockly", ".", "Msg", ".", "MOTION_GLIDETO_POINTER", ",", "'_mouse_'", "]", ",", "[", "Blockly", ".", "Msg", ".", "MOTION_GLIDETO_RANDOM", ",", "'_random_'", "]", "]", "}", "]", ",", "\"colour\"", ":", "Blockly", ".", "Colours", ".", "motion", ".", "secondary", ",", "\"colourSecondary\"", ":", "Blockly", ".", "Colours", ".", "motion", ".", "secondary", ",", "\"colourTertiary\"", ":", "Blockly", ".", "Colours", ".", "motion", ".", "tertiary", ",", "\"extensions\"", ":", "[", "\"output_string\"", "]", "}", ")", ";", "}" ]
Glide to drop-down menu @this Blockly.Block
[ "Glide", "to", "drop", "-", "down", "menu" ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/blocks_vertical/motion.js#L272-L290
3,438
LLK/scratch-blocks
blocks_vertical/motion.js
function() { this.jsonInit({ "message0": Blockly.Msg.MOTION_SETROTATIONSTYLE, "args0": [ { "type": "field_dropdown", "name": "STYLE", "options": [ [Blockly.Msg.MOTION_SETROTATIONSTYLE_LEFTRIGHT, 'left-right'], [Blockly.Msg.MOTION_SETROTATIONSTYLE_DONTROTATE, 'don\'t rotate'], [Blockly.Msg.MOTION_SETROTATIONSTYLE_ALLAROUND, 'all around'] ] } ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); }
javascript
function() { this.jsonInit({ "message0": Blockly.Msg.MOTION_SETROTATIONSTYLE, "args0": [ { "type": "field_dropdown", "name": "STYLE", "options": [ [Blockly.Msg.MOTION_SETROTATIONSTYLE_LEFTRIGHT, 'left-right'], [Blockly.Msg.MOTION_SETROTATIONSTYLE_DONTROTATE, 'don\'t rotate'], [Blockly.Msg.MOTION_SETROTATIONSTYLE_ALLAROUND, 'all around'] ] } ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "Blockly", ".", "Msg", ".", "MOTION_SETROTATIONSTYLE", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"field_dropdown\"", ",", "\"name\"", ":", "\"STYLE\"", ",", "\"options\"", ":", "[", "[", "Blockly", ".", "Msg", ".", "MOTION_SETROTATIONSTYLE_LEFTRIGHT", ",", "'left-right'", "]", ",", "[", "Blockly", ".", "Msg", ".", "MOTION_SETROTATIONSTYLE_DONTROTATE", ",", "'don\\'t rotate'", "]", ",", "[", "Blockly", ".", "Msg", ".", "MOTION_SETROTATIONSTYLE_ALLAROUND", ",", "'all around'", "]", "]", "}", "]", ",", "\"category\"", ":", "Blockly", ".", "Categories", ".", "motion", ",", "\"extensions\"", ":", "[", "\"colours_motion\"", ",", "\"shape_statement\"", "]", "}", ")", ";", "}" ]
Block to set rotation style. @this Blockly.Block
[ "Block", "to", "set", "rotation", "style", "." ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/blocks_vertical/motion.js#L416-L433
3,439
LLK/scratch-blocks
blocks_vertical/motion.js
function() { this.jsonInit({ "message0": Blockly.Msg.MOTION_ALIGNSCENE, "args0": [ { "type": "field_dropdown", "name": "ALIGNMENT", "options": [ [Blockly.Msg.MOTION_ALIGNSCENE_BOTTOMLEFT, 'bottom-left'], [Blockly.Msg.MOTION_ALIGNSCENE_BOTTOMRIGHT, 'bottom-right'], [Blockly.Msg.MOTION_ALIGNSCENE_MIDDLE, 'middle'], [Blockly.Msg.MOTION_ALIGNSCENE_TOPLEFT, 'top-left'], [Blockly.Msg.MOTION_ALIGNSCENE_TOPRIGHT, 'top-right'] ] } ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); }
javascript
function() { this.jsonInit({ "message0": Blockly.Msg.MOTION_ALIGNSCENE, "args0": [ { "type": "field_dropdown", "name": "ALIGNMENT", "options": [ [Blockly.Msg.MOTION_ALIGNSCENE_BOTTOMLEFT, 'bottom-left'], [Blockly.Msg.MOTION_ALIGNSCENE_BOTTOMRIGHT, 'bottom-right'], [Blockly.Msg.MOTION_ALIGNSCENE_MIDDLE, 'middle'], [Blockly.Msg.MOTION_ALIGNSCENE_TOPLEFT, 'top-left'], [Blockly.Msg.MOTION_ALIGNSCENE_TOPRIGHT, 'top-right'] ] } ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); }
[ "function", "(", ")", "{", "this", ".", "jsonInit", "(", "{", "\"message0\"", ":", "Blockly", ".", "Msg", ".", "MOTION_ALIGNSCENE", ",", "\"args0\"", ":", "[", "{", "\"type\"", ":", "\"field_dropdown\"", ",", "\"name\"", ":", "\"ALIGNMENT\"", ",", "\"options\"", ":", "[", "[", "Blockly", ".", "Msg", ".", "MOTION_ALIGNSCENE_BOTTOMLEFT", ",", "'bottom-left'", "]", ",", "[", "Blockly", ".", "Msg", ".", "MOTION_ALIGNSCENE_BOTTOMRIGHT", ",", "'bottom-right'", "]", ",", "[", "Blockly", ".", "Msg", ".", "MOTION_ALIGNSCENE_MIDDLE", ",", "'middle'", "]", ",", "[", "Blockly", ".", "Msg", ".", "MOTION_ALIGNSCENE_TOPLEFT", ",", "'top-left'", "]", ",", "[", "Blockly", ".", "Msg", ".", "MOTION_ALIGNSCENE_TOPRIGHT", ",", "'top-right'", "]", "]", "}", "]", ",", "\"category\"", ":", "Blockly", ".", "Categories", ".", "motion", ",", "\"extensions\"", ":", "[", "\"colours_motion\"", ",", "\"shape_statement\"", "]", "}", ")", ";", "}" ]
Block to change the stage's scrolling alignment. Does not actually do anything. This is an obsolete block that is implemented for compatibility with Scratch 2.0 projects. @this Blockly.Block
[ "Block", "to", "change", "the", "stage", "s", "scrolling", "alignment", ".", "Does", "not", "actually", "do", "anything", ".", "This", "is", "an", "obsolete", "block", "that", "is", "implemented", "for", "compatibility", "with", "Scratch", "2", ".", "0", "projects", "." ]
455b2a854435c0a67da1da92320ddc3ec3e2b799
https://github.com/LLK/scratch-blocks/blob/455b2a854435c0a67da1da92320ddc3ec3e2b799/blocks_vertical/motion.js#L532-L551
3,440
moment/luxon
src/interval.js
validateStartEnd
function validateStartEnd(start, end) { if (!start || !start.isValid) { return new Invalid("missing or invalid start"); } else if (!end || !end.isValid) { return new Invalid("missing or invalid end"); } else if (end < start) { return new Invalid( "end before start", `The end of an interval must be after its start, but you had start=${start.toISO()} and end=${end.toISO()}` ); } else { return null; } }
javascript
function validateStartEnd(start, end) { if (!start || !start.isValid) { return new Invalid("missing or invalid start"); } else if (!end || !end.isValid) { return new Invalid("missing or invalid end"); } else if (end < start) { return new Invalid( "end before start", `The end of an interval must be after its start, but you had start=${start.toISO()} and end=${end.toISO()}` ); } else { return null; } }
[ "function", "validateStartEnd", "(", "start", ",", "end", ")", "{", "if", "(", "!", "start", "||", "!", "start", ".", "isValid", ")", "{", "return", "new", "Invalid", "(", "\"missing or invalid start\"", ")", ";", "}", "else", "if", "(", "!", "end", "||", "!", "end", ".", "isValid", ")", "{", "return", "new", "Invalid", "(", "\"missing or invalid end\"", ")", ";", "}", "else", "if", "(", "end", "<", "start", ")", "{", "return", "new", "Invalid", "(", "\"end before start\"", ",", "`", "${", "start", ".", "toISO", "(", ")", "}", "${", "end", ".", "toISO", "(", ")", "}", "`", ")", ";", "}", "else", "{", "return", "null", ";", "}", "}" ]
checks if the start is equal to or before the end
[ "checks", "if", "the", "start", "is", "equal", "to", "or", "before", "the", "end" ]
236f2badea297ee73421aa39a83e06177c1be6d0
https://github.com/moment/luxon/blob/236f2badea297ee73421aa39a83e06177c1be6d0/src/interval.js#L10-L23
3,441
moment/luxon
src/duration.js
clone
function clone(dur, alts, clear = false) { // deep merge for vals const conf = { values: clear ? alts.values : Object.assign({}, dur.values, alts.values || {}), loc: dur.loc.clone(alts.loc), conversionAccuracy: alts.conversionAccuracy || dur.conversionAccuracy }; return new Duration(conf); }
javascript
function clone(dur, alts, clear = false) { // deep merge for vals const conf = { values: clear ? alts.values : Object.assign({}, dur.values, alts.values || {}), loc: dur.loc.clone(alts.loc), conversionAccuracy: alts.conversionAccuracy || dur.conversionAccuracy }; return new Duration(conf); }
[ "function", "clone", "(", "dur", ",", "alts", ",", "clear", "=", "false", ")", "{", "// deep merge for vals", "const", "conf", "=", "{", "values", ":", "clear", "?", "alts", ".", "values", ":", "Object", ".", "assign", "(", "{", "}", ",", "dur", ".", "values", ",", "alts", ".", "values", "||", "{", "}", ")", ",", "loc", ":", "dur", ".", "loc", ".", "clone", "(", "alts", ".", "loc", ")", ",", "conversionAccuracy", ":", "alts", ".", "conversionAccuracy", "||", "dur", ".", "conversionAccuracy", "}", ";", "return", "new", "Duration", "(", "conf", ")", ";", "}" ]
clone really means "create another instance just like this one, but with these changes"
[ "clone", "really", "means", "create", "another", "instance", "just", "like", "this", "one", "but", "with", "these", "changes" ]
236f2badea297ee73421aa39a83e06177c1be6d0
https://github.com/moment/luxon/blob/236f2badea297ee73421aa39a83e06177c1be6d0/src/duration.js#L110-L118
3,442
moment/luxon
src/datetime.js
possiblyCachedWeekData
function possiblyCachedWeekData(dt) { if (dt.weekData === null) { dt.weekData = gregorianToWeek(dt.c); } return dt.weekData; }
javascript
function possiblyCachedWeekData(dt) { if (dt.weekData === null) { dt.weekData = gregorianToWeek(dt.c); } return dt.weekData; }
[ "function", "possiblyCachedWeekData", "(", "dt", ")", "{", "if", "(", "dt", ".", "weekData", "===", "null", ")", "{", "dt", ".", "weekData", "=", "gregorianToWeek", "(", "dt", ".", "c", ")", ";", "}", "return", "dt", ".", "weekData", ";", "}" ]
we cache week data on the DT object and this intermediates the cache
[ "we", "cache", "week", "data", "on", "the", "DT", "object", "and", "this", "intermediates", "the", "cache" ]
236f2badea297ee73421aa39a83e06177c1be6d0
https://github.com/moment/luxon/blob/236f2badea297ee73421aa39a83e06177c1be6d0/src/datetime.js#L52-L57
3,443
moment/luxon
src/datetime.js
clone
function clone(inst, alts) { const current = { ts: inst.ts, zone: inst.zone, c: inst.c, o: inst.o, loc: inst.loc, invalid: inst.invalid }; return new DateTime(Object.assign({}, current, alts, { old: current })); }
javascript
function clone(inst, alts) { const current = { ts: inst.ts, zone: inst.zone, c: inst.c, o: inst.o, loc: inst.loc, invalid: inst.invalid }; return new DateTime(Object.assign({}, current, alts, { old: current })); }
[ "function", "clone", "(", "inst", ",", "alts", ")", "{", "const", "current", "=", "{", "ts", ":", "inst", ".", "ts", ",", "zone", ":", "inst", ".", "zone", ",", "c", ":", "inst", ".", "c", ",", "o", ":", "inst", ".", "o", ",", "loc", ":", "inst", ".", "loc", ",", "invalid", ":", "inst", ".", "invalid", "}", ";", "return", "new", "DateTime", "(", "Object", ".", "assign", "(", "{", "}", ",", "current", ",", "alts", ",", "{", "old", ":", "current", "}", ")", ")", ";", "}" ]
clone really means, "make a new object with these modifications". all "setters" really use this to create a new object while only changing some of the properties
[ "clone", "really", "means", "make", "a", "new", "object", "with", "these", "modifications", ".", "all", "setters", "really", "use", "this", "to", "create", "a", "new", "object", "while", "only", "changing", "some", "of", "the", "properties" ]
236f2badea297ee73421aa39a83e06177c1be6d0
https://github.com/moment/luxon/blob/236f2badea297ee73421aa39a83e06177c1be6d0/src/datetime.js#L61-L71
3,444
moment/luxon
src/datetime.js
tsToObj
function tsToObj(ts, offset) { ts += offset * 60 * 1000; const d = new Date(ts); return { year: d.getUTCFullYear(), month: d.getUTCMonth() + 1, day: d.getUTCDate(), hour: d.getUTCHours(), minute: d.getUTCMinutes(), second: d.getUTCSeconds(), millisecond: d.getUTCMilliseconds() }; }
javascript
function tsToObj(ts, offset) { ts += offset * 60 * 1000; const d = new Date(ts); return { year: d.getUTCFullYear(), month: d.getUTCMonth() + 1, day: d.getUTCDate(), hour: d.getUTCHours(), minute: d.getUTCMinutes(), second: d.getUTCSeconds(), millisecond: d.getUTCMilliseconds() }; }
[ "function", "tsToObj", "(", "ts", ",", "offset", ")", "{", "ts", "+=", "offset", "*", "60", "*", "1000", ";", "const", "d", "=", "new", "Date", "(", "ts", ")", ";", "return", "{", "year", ":", "d", ".", "getUTCFullYear", "(", ")", ",", "month", ":", "d", ".", "getUTCMonth", "(", ")", "+", "1", ",", "day", ":", "d", ".", "getUTCDate", "(", ")", ",", "hour", ":", "d", ".", "getUTCHours", "(", ")", ",", "minute", ":", "d", ".", "getUTCMinutes", "(", ")", ",", "second", ":", "d", ".", "getUTCSeconds", "(", ")", ",", "millisecond", ":", "d", ".", "getUTCMilliseconds", "(", ")", "}", ";", "}" ]
convert an epoch timestamp into a calendar object with the given offset
[ "convert", "an", "epoch", "timestamp", "into", "a", "calendar", "object", "with", "the", "given", "offset" ]
236f2badea297ee73421aa39a83e06177c1be6d0
https://github.com/moment/luxon/blob/236f2badea297ee73421aa39a83e06177c1be6d0/src/datetime.js#L101-L115
3,445
moment/luxon
src/datetime.js
adjustTime
function adjustTime(inst, dur) { const oPre = inst.o, year = inst.c.year + dur.years, month = inst.c.month + dur.months + dur.quarters * 3, c = Object.assign({}, inst.c, { year, month, day: Math.min(inst.c.day, daysInMonth(year, month)) + dur.days + dur.weeks * 7 }), millisToAdd = Duration.fromObject({ hours: dur.hours, minutes: dur.minutes, seconds: dur.seconds, milliseconds: dur.milliseconds }).as("milliseconds"), localTS = objToLocalTS(c); let [ts, o] = fixOffset(localTS, oPre, inst.zone); if (millisToAdd !== 0) { ts += millisToAdd; // that could have changed the offset by going over a DST, but we want to keep the ts the same o = inst.zone.offset(ts); } return { ts, o }; }
javascript
function adjustTime(inst, dur) { const oPre = inst.o, year = inst.c.year + dur.years, month = inst.c.month + dur.months + dur.quarters * 3, c = Object.assign({}, inst.c, { year, month, day: Math.min(inst.c.day, daysInMonth(year, month)) + dur.days + dur.weeks * 7 }), millisToAdd = Duration.fromObject({ hours: dur.hours, minutes: dur.minutes, seconds: dur.seconds, milliseconds: dur.milliseconds }).as("milliseconds"), localTS = objToLocalTS(c); let [ts, o] = fixOffset(localTS, oPre, inst.zone); if (millisToAdd !== 0) { ts += millisToAdd; // that could have changed the offset by going over a DST, but we want to keep the ts the same o = inst.zone.offset(ts); } return { ts, o }; }
[ "function", "adjustTime", "(", "inst", ",", "dur", ")", "{", "const", "oPre", "=", "inst", ".", "o", ",", "year", "=", "inst", ".", "c", ".", "year", "+", "dur", ".", "years", ",", "month", "=", "inst", ".", "c", ".", "month", "+", "dur", ".", "months", "+", "dur", ".", "quarters", "*", "3", ",", "c", "=", "Object", ".", "assign", "(", "{", "}", ",", "inst", ".", "c", ",", "{", "year", ",", "month", ",", "day", ":", "Math", ".", "min", "(", "inst", ".", "c", ".", "day", ",", "daysInMonth", "(", "year", ",", "month", ")", ")", "+", "dur", ".", "days", "+", "dur", ".", "weeks", "*", "7", "}", ")", ",", "millisToAdd", "=", "Duration", ".", "fromObject", "(", "{", "hours", ":", "dur", ".", "hours", ",", "minutes", ":", "dur", ".", "minutes", ",", "seconds", ":", "dur", ".", "seconds", ",", "milliseconds", ":", "dur", ".", "milliseconds", "}", ")", ".", "as", "(", "\"milliseconds\"", ")", ",", "localTS", "=", "objToLocalTS", "(", "c", ")", ";", "let", "[", "ts", ",", "o", "]", "=", "fixOffset", "(", "localTS", ",", "oPre", ",", "inst", ".", "zone", ")", ";", "if", "(", "millisToAdd", "!==", "0", ")", "{", "ts", "+=", "millisToAdd", ";", "// that could have changed the offset by going over a DST, but we want to keep the ts the same", "o", "=", "inst", ".", "zone", ".", "offset", "(", "ts", ")", ";", "}", "return", "{", "ts", ",", "o", "}", ";", "}" ]
create a new DT instance by adding a duration, adjusting for DSTs
[ "create", "a", "new", "DT", "instance", "by", "adding", "a", "duration", "adjusting", "for", "DSTs" ]
236f2badea297ee73421aa39a83e06177c1be6d0
https://github.com/moment/luxon/blob/236f2badea297ee73421aa39a83e06177c1be6d0/src/datetime.js#L123-L149
3,446
moment/luxon
src/datetime.js
parseDataToDateTime
function parseDataToDateTime(parsed, parsedZone, opts, format, text) { const { setZone, zone } = opts; if (parsed && Object.keys(parsed).length !== 0) { const interpretationZone = parsedZone || zone, inst = DateTime.fromObject( Object.assign(parsed, opts, { zone: interpretationZone, // setZone is a valid option in the calling methods, but not in fromObject setZone: undefined }) ); return setZone ? inst : inst.setZone(zone); } else { return DateTime.invalid( new Invalid("unparsable", `the input "${text}" can't be parsed as ${format}`) ); } }
javascript
function parseDataToDateTime(parsed, parsedZone, opts, format, text) { const { setZone, zone } = opts; if (parsed && Object.keys(parsed).length !== 0) { const interpretationZone = parsedZone || zone, inst = DateTime.fromObject( Object.assign(parsed, opts, { zone: interpretationZone, // setZone is a valid option in the calling methods, but not in fromObject setZone: undefined }) ); return setZone ? inst : inst.setZone(zone); } else { return DateTime.invalid( new Invalid("unparsable", `the input "${text}" can't be parsed as ${format}`) ); } }
[ "function", "parseDataToDateTime", "(", "parsed", ",", "parsedZone", ",", "opts", ",", "format", ",", "text", ")", "{", "const", "{", "setZone", ",", "zone", "}", "=", "opts", ";", "if", "(", "parsed", "&&", "Object", ".", "keys", "(", "parsed", ")", ".", "length", "!==", "0", ")", "{", "const", "interpretationZone", "=", "parsedZone", "||", "zone", ",", "inst", "=", "DateTime", ".", "fromObject", "(", "Object", ".", "assign", "(", "parsed", ",", "opts", ",", "{", "zone", ":", "interpretationZone", ",", "// setZone is a valid option in the calling methods, but not in fromObject", "setZone", ":", "undefined", "}", ")", ")", ";", "return", "setZone", "?", "inst", ":", "inst", ".", "setZone", "(", "zone", ")", ";", "}", "else", "{", "return", "DateTime", ".", "invalid", "(", "new", "Invalid", "(", "\"unparsable\"", ",", "`", "${", "text", "}", "${", "format", "}", "`", ")", ")", ";", "}", "}" ]
helper useful in turning the results of parsing into real dates by handling the zone options
[ "helper", "useful", "in", "turning", "the", "results", "of", "parsing", "into", "real", "dates", "by", "handling", "the", "zone", "options" ]
236f2badea297ee73421aa39a83e06177c1be6d0
https://github.com/moment/luxon/blob/236f2badea297ee73421aa39a83e06177c1be6d0/src/datetime.js#L153-L170
3,447
moment/luxon
src/datetime.js
normalizeUnit
function normalizeUnit(unit) { const normalized = { year: "year", years: "year", month: "month", months: "month", day: "day", days: "day", hour: "hour", hours: "hour", minute: "minute", minutes: "minute", second: "second", seconds: "second", millisecond: "millisecond", milliseconds: "millisecond", weekday: "weekday", weekdays: "weekday", weeknumber: "weekNumber", weeksnumber: "weekNumber", weeknumbers: "weekNumber", weekyear: "weekYear", weekyears: "weekYear", ordinal: "ordinal" }[unit.toLowerCase()]; if (!normalized) throw new InvalidUnitError(unit); return normalized; }
javascript
function normalizeUnit(unit) { const normalized = { year: "year", years: "year", month: "month", months: "month", day: "day", days: "day", hour: "hour", hours: "hour", minute: "minute", minutes: "minute", second: "second", seconds: "second", millisecond: "millisecond", milliseconds: "millisecond", weekday: "weekday", weekdays: "weekday", weeknumber: "weekNumber", weeksnumber: "weekNumber", weeknumbers: "weekNumber", weekyear: "weekYear", weekyears: "weekYear", ordinal: "ordinal" }[unit.toLowerCase()]; if (!normalized) throw new InvalidUnitError(unit); return normalized; }
[ "function", "normalizeUnit", "(", "unit", ")", "{", "const", "normalized", "=", "{", "year", ":", "\"year\"", ",", "years", ":", "\"year\"", ",", "month", ":", "\"month\"", ",", "months", ":", "\"month\"", ",", "day", ":", "\"day\"", ",", "days", ":", "\"day\"", ",", "hour", ":", "\"hour\"", ",", "hours", ":", "\"hour\"", ",", "minute", ":", "\"minute\"", ",", "minutes", ":", "\"minute\"", ",", "second", ":", "\"second\"", ",", "seconds", ":", "\"second\"", ",", "millisecond", ":", "\"millisecond\"", ",", "milliseconds", ":", "\"millisecond\"", ",", "weekday", ":", "\"weekday\"", ",", "weekdays", ":", "\"weekday\"", ",", "weeknumber", ":", "\"weekNumber\"", ",", "weeksnumber", ":", "\"weekNumber\"", ",", "weeknumbers", ":", "\"weekNumber\"", ",", "weekyear", ":", "\"weekYear\"", ",", "weekyears", ":", "\"weekYear\"", ",", "ordinal", ":", "\"ordinal\"", "}", "[", "unit", ".", "toLowerCase", "(", ")", "]", ";", "if", "(", "!", "normalized", ")", "throw", "new", "InvalidUnitError", "(", "unit", ")", ";", "return", "normalized", ";", "}" ]
standardize case and plurality in units
[ "standardize", "case", "and", "plurality", "in", "units" ]
236f2badea297ee73421aa39a83e06177c1be6d0
https://github.com/moment/luxon/blob/236f2badea297ee73421aa39a83e06177c1be6d0/src/datetime.js#L256-L285
3,448
KaTeX/KaTeX
dockers/texcmp/texcmp.js
execFile
function execFile(cmd, args, opts) { const deferred = Q.defer(); childProcess.execFile(cmd, args, opts, function(err, stdout, stderr) { if (err) { console.error("Error executing " + cmd + " " + args.join(" ")); console.error(stdout + stderr); err.stdout = stdout; err.stderr = stderr; deferred.reject(err); } else { deferred.resolve(stdout); } }); return deferred.promise; }
javascript
function execFile(cmd, args, opts) { const deferred = Q.defer(); childProcess.execFile(cmd, args, opts, function(err, stdout, stderr) { if (err) { console.error("Error executing " + cmd + " " + args.join(" ")); console.error(stdout + stderr); err.stdout = stdout; err.stderr = stderr; deferred.reject(err); } else { deferred.resolve(stdout); } }); return deferred.promise; }
[ "function", "execFile", "(", "cmd", ",", "args", ",", "opts", ")", "{", "const", "deferred", "=", "Q", ".", "defer", "(", ")", ";", "childProcess", ".", "execFile", "(", "cmd", ",", "args", ",", "opts", ",", "function", "(", "err", ",", "stdout", ",", "stderr", ")", "{", "if", "(", "err", ")", "{", "console", ".", "error", "(", "\"Error executing \"", "+", "cmd", "+", "\" \"", "+", "args", ".", "join", "(", "\" \"", ")", ")", ";", "console", ".", "error", "(", "stdout", "+", "stderr", ")", ";", "err", ".", "stdout", "=", "stdout", ";", "err", ".", "stderr", "=", "stderr", ";", "deferred", ".", "reject", "(", "err", ")", ";", "}", "else", "{", "deferred", ".", "resolve", "(", "stdout", ")", ";", "}", "}", ")", ";", "return", "deferred", ".", "promise", ";", "}" ]
Execute a given command, and return a promise to its output. Don't denodeify here, since fail branch needs access to stderr.
[ "Execute", "a", "given", "command", "and", "return", "a", "promise", "to", "its", "output", ".", "Don", "t", "denodeify", "here", "since", "fail", "branch", "needs", "access", "to", "stderr", "." ]
17bfb247b88070267f3e5c7b21fe4a360fdf49d9
https://github.com/KaTeX/KaTeX/blob/17bfb247b88070267f3e5c7b21fe4a360fdf49d9/dockers/texcmp/texcmp.js#L206-L220
3,449
KaTeX/KaTeX
dockers/texcmp/texcmp.js
readPNG
function readPNG(file) { const deferred = Q.defer(); const onerror = deferred.reject.bind(deferred); const stream = fs.createReadStream(file); stream.on("error", onerror); pngparse.parseStream(stream, function(err, image) { if (err) { console.log("Failed to load " + file); onerror(err); return; } deferred.resolve(image); }); return deferred.promise; }
javascript
function readPNG(file) { const deferred = Q.defer(); const onerror = deferred.reject.bind(deferred); const stream = fs.createReadStream(file); stream.on("error", onerror); pngparse.parseStream(stream, function(err, image) { if (err) { console.log("Failed to load " + file); onerror(err); return; } deferred.resolve(image); }); return deferred.promise; }
[ "function", "readPNG", "(", "file", ")", "{", "const", "deferred", "=", "Q", ".", "defer", "(", ")", ";", "const", "onerror", "=", "deferred", ".", "reject", ".", "bind", "(", "deferred", ")", ";", "const", "stream", "=", "fs", ".", "createReadStream", "(", "file", ")", ";", "stream", ".", "on", "(", "\"error\"", ",", "onerror", ")", ";", "pngparse", ".", "parseStream", "(", "stream", ",", "function", "(", "err", ",", "image", ")", "{", "if", "(", "err", ")", "{", "console", ".", "log", "(", "\"Failed to load \"", "+", "file", ")", ";", "onerror", "(", "err", ")", ";", "return", ";", "}", "deferred", ".", "resolve", "(", "image", ")", ";", "}", ")", ";", "return", "deferred", ".", "promise", ";", "}" ]
Read given file and parse it as a PNG file.
[ "Read", "given", "file", "and", "parse", "it", "as", "a", "PNG", "file", "." ]
17bfb247b88070267f3e5c7b21fe4a360fdf49d9
https://github.com/KaTeX/KaTeX/blob/17bfb247b88070267f3e5c7b21fe4a360fdf49d9/dockers/texcmp/texcmp.js#L223-L237
3,450
KaTeX/KaTeX
dockers/texcmp/texcmp.js
fftImage
function fftImage(image) { const real = createMatrix(); const imag = createMatrix(); let idx = 0; const nchan = image.channels; const alphachan = 1 - (nchan % 2); const colorchan = nchan - alphachan; for (let y = 0; y < image.height; ++y) { for (let x = 0; x < image.width; ++x) { let v = 0; for (let c = 0; c < colorchan; ++c) { v += 255 - image.data[idx++]; } for (let c = 0; c < alphachan; ++c) { v += image.data[idx++]; } real.set(y, x, v); } } fft(1, real, imag); return { real: real, imag: imag, width: image.width, height: image.height, }; }
javascript
function fftImage(image) { const real = createMatrix(); const imag = createMatrix(); let idx = 0; const nchan = image.channels; const alphachan = 1 - (nchan % 2); const colorchan = nchan - alphachan; for (let y = 0; y < image.height; ++y) { for (let x = 0; x < image.width; ++x) { let v = 0; for (let c = 0; c < colorchan; ++c) { v += 255 - image.data[idx++]; } for (let c = 0; c < alphachan; ++c) { v += image.data[idx++]; } real.set(y, x, v); } } fft(1, real, imag); return { real: real, imag: imag, width: image.width, height: image.height, }; }
[ "function", "fftImage", "(", "image", ")", "{", "const", "real", "=", "createMatrix", "(", ")", ";", "const", "imag", "=", "createMatrix", "(", ")", ";", "let", "idx", "=", "0", ";", "const", "nchan", "=", "image", ".", "channels", ";", "const", "alphachan", "=", "1", "-", "(", "nchan", "%", "2", ")", ";", "const", "colorchan", "=", "nchan", "-", "alphachan", ";", "for", "(", "let", "y", "=", "0", ";", "y", "<", "image", ".", "height", ";", "++", "y", ")", "{", "for", "(", "let", "x", "=", "0", ";", "x", "<", "image", ".", "width", ";", "++", "x", ")", "{", "let", "v", "=", "0", ";", "for", "(", "let", "c", "=", "0", ";", "c", "<", "colorchan", ";", "++", "c", ")", "{", "v", "+=", "255", "-", "image", ".", "data", "[", "idx", "++", "]", ";", "}", "for", "(", "let", "c", "=", "0", ";", "c", "<", "alphachan", ";", "++", "c", ")", "{", "v", "+=", "image", ".", "data", "[", "idx", "++", "]", ";", "}", "real", ".", "set", "(", "y", ",", "x", ",", "v", ")", ";", "}", "}", "fft", "(", "1", ",", "real", ",", "imag", ")", ";", "return", "{", "real", ":", "real", ",", "imag", ":", "imag", ",", "width", ":", "image", ".", "width", ",", "height", ":", "image", ".", "height", ",", "}", ";", "}" ]
Take a parsed image data structure and apply FFT transformation to it
[ "Take", "a", "parsed", "image", "data", "structure", "and", "apply", "FFT", "transformation", "to", "it" ]
17bfb247b88070267f3e5c7b21fe4a360fdf49d9
https://github.com/KaTeX/KaTeX/blob/17bfb247b88070267f3e5c7b21fe4a360fdf49d9/dockers/texcmp/texcmp.js#L240-L266
3,451
KaTeX/KaTeX
webpack.common.js
createConfig
function createConfig(target /*: Target */, dev /*: boolean */, minimize /*: boolean */) /*: Object */ { const cssLoaders /*: Array<Object> */ = [{loader: 'css-loader'}]; if (minimize) { cssLoaders[0].options = {importLoaders: 1}; cssLoaders.push({ loader: 'postcss-loader', options: {plugins: [require('cssnano')()]}, }); } const lessOptions = {modifyVars: { version: `"${version}"`, }}; // use only necessary fonts, overridable by environment variables let isCovered = false; for (const font of fonts) { const override = process.env[`USE_${font.toUpperCase()}`]; const useFont = override === "true" || override !== "false" && !isCovered; lessOptions.modifyVars[`use-${font}`] = useFont; const support = caniuse.feature(caniuse.features[font]).stats; isCovered = isCovered || useFont && browserslist.every(browser => { const [name, version] = browser.split(' '); return !support[name] || support[name][version] === 'y'; }); } return { mode: dev ? 'development' : 'production', context: __dirname, entry: { [target.name]: target.entry, }, output: { filename: minimize ? '[name].min.js' : '[name].js', library: target.library, libraryTarget: 'umd', libraryExport: 'default', // Enable output modules to be used in browser or Node. // See: https://github.com/webpack/webpack/issues/6522 globalObject: "(typeof self !== 'undefined' ? self : this)", path: path.resolve(__dirname, 'dist'), publicPath: dev ? '/' : '', }, module: { rules: [ { test: /\.js$/, exclude: /node_modules/, use: 'babel-loader', }, { test: /\.css$/, use: [ dev ? 'style-loader' : MiniCssExtractPlugin.loader, ...cssLoaders, ], }, { test: /\.less$/, use: [ dev ? 'style-loader' : MiniCssExtractPlugin.loader, ...cssLoaders, { loader: 'less-loader', options: lessOptions, }, ], }, { test: /\.(ttf|woff|woff2)$/, use: [{ loader: 'file-loader', options: { name: 'fonts/[name].[ext]', }, }], }, ], }, externals: 'katex', plugins: [ !dev && new MiniCssExtractPlugin({ filename: minimize ? '[name].min.css' : '[name].css', }), ].filter(Boolean), devtool: dev && 'inline-source-map', optimization: { minimize, minimizer: [ new TerserPlugin({ terserOptions: { output: { ascii_only: true, }, }, }), ], }, performance: { hints: false, }, }; }
javascript
function createConfig(target /*: Target */, dev /*: boolean */, minimize /*: boolean */) /*: Object */ { const cssLoaders /*: Array<Object> */ = [{loader: 'css-loader'}]; if (minimize) { cssLoaders[0].options = {importLoaders: 1}; cssLoaders.push({ loader: 'postcss-loader', options: {plugins: [require('cssnano')()]}, }); } const lessOptions = {modifyVars: { version: `"${version}"`, }}; // use only necessary fonts, overridable by environment variables let isCovered = false; for (const font of fonts) { const override = process.env[`USE_${font.toUpperCase()}`]; const useFont = override === "true" || override !== "false" && !isCovered; lessOptions.modifyVars[`use-${font}`] = useFont; const support = caniuse.feature(caniuse.features[font]).stats; isCovered = isCovered || useFont && browserslist.every(browser => { const [name, version] = browser.split(' '); return !support[name] || support[name][version] === 'y'; }); } return { mode: dev ? 'development' : 'production', context: __dirname, entry: { [target.name]: target.entry, }, output: { filename: minimize ? '[name].min.js' : '[name].js', library: target.library, libraryTarget: 'umd', libraryExport: 'default', // Enable output modules to be used in browser or Node. // See: https://github.com/webpack/webpack/issues/6522 globalObject: "(typeof self !== 'undefined' ? self : this)", path: path.resolve(__dirname, 'dist'), publicPath: dev ? '/' : '', }, module: { rules: [ { test: /\.js$/, exclude: /node_modules/, use: 'babel-loader', }, { test: /\.css$/, use: [ dev ? 'style-loader' : MiniCssExtractPlugin.loader, ...cssLoaders, ], }, { test: /\.less$/, use: [ dev ? 'style-loader' : MiniCssExtractPlugin.loader, ...cssLoaders, { loader: 'less-loader', options: lessOptions, }, ], }, { test: /\.(ttf|woff|woff2)$/, use: [{ loader: 'file-loader', options: { name: 'fonts/[name].[ext]', }, }], }, ], }, externals: 'katex', plugins: [ !dev && new MiniCssExtractPlugin({ filename: minimize ? '[name].min.css' : '[name].css', }), ].filter(Boolean), devtool: dev && 'inline-source-map', optimization: { minimize, minimizer: [ new TerserPlugin({ terserOptions: { output: { ascii_only: true, }, }, }), ], }, performance: { hints: false, }, }; }
[ "function", "createConfig", "(", "target", "/*: Target */", ",", "dev", "/*: boolean */", ",", "minimize", "/*: boolean */", ")", "/*: Object */", "{", "const", "cssLoaders", "/*: Array<Object> */", "=", "[", "{", "loader", ":", "'css-loader'", "}", "]", ";", "if", "(", "minimize", ")", "{", "cssLoaders", "[", "0", "]", ".", "options", "=", "{", "importLoaders", ":", "1", "}", ";", "cssLoaders", ".", "push", "(", "{", "loader", ":", "'postcss-loader'", ",", "options", ":", "{", "plugins", ":", "[", "require", "(", "'cssnano'", ")", "(", ")", "]", "}", ",", "}", ")", ";", "}", "const", "lessOptions", "=", "{", "modifyVars", ":", "{", "version", ":", "`", "${", "version", "}", "`", ",", "}", "}", ";", "// use only necessary fonts, overridable by environment variables", "let", "isCovered", "=", "false", ";", "for", "(", "const", "font", "of", "fonts", ")", "{", "const", "override", "=", "process", ".", "env", "[", "`", "${", "font", ".", "toUpperCase", "(", ")", "}", "`", "]", ";", "const", "useFont", "=", "override", "===", "\"true\"", "||", "override", "!==", "\"false\"", "&&", "!", "isCovered", ";", "lessOptions", ".", "modifyVars", "[", "`", "${", "font", "}", "`", "]", "=", "useFont", ";", "const", "support", "=", "caniuse", ".", "feature", "(", "caniuse", ".", "features", "[", "font", "]", ")", ".", "stats", ";", "isCovered", "=", "isCovered", "||", "useFont", "&&", "browserslist", ".", "every", "(", "browser", "=>", "{", "const", "[", "name", ",", "version", "]", "=", "browser", ".", "split", "(", "' '", ")", ";", "return", "!", "support", "[", "name", "]", "||", "support", "[", "name", "]", "[", "version", "]", "===", "'y'", ";", "}", ")", ";", "}", "return", "{", "mode", ":", "dev", "?", "'development'", ":", "'production'", ",", "context", ":", "__dirname", ",", "entry", ":", "{", "[", "target", ".", "name", "]", ":", "target", ".", "entry", ",", "}", ",", "output", ":", "{", "filename", ":", "minimize", "?", "'[name].min.js'", ":", "'[name].js'", ",", "library", ":", "target", ".", "library", ",", "libraryTarget", ":", "'umd'", ",", "libraryExport", ":", "'default'", ",", "// Enable output modules to be used in browser or Node.", "// See: https://github.com/webpack/webpack/issues/6522", "globalObject", ":", "\"(typeof self !== 'undefined' ? self : this)\"", ",", "path", ":", "path", ".", "resolve", "(", "__dirname", ",", "'dist'", ")", ",", "publicPath", ":", "dev", "?", "'/'", ":", "''", ",", "}", ",", "module", ":", "{", "rules", ":", "[", "{", "test", ":", "/", "\\.js$", "/", ",", "exclude", ":", "/", "node_modules", "/", ",", "use", ":", "'babel-loader'", ",", "}", ",", "{", "test", ":", "/", "\\.css$", "/", ",", "use", ":", "[", "dev", "?", "'style-loader'", ":", "MiniCssExtractPlugin", ".", "loader", ",", "...", "cssLoaders", ",", "]", ",", "}", ",", "{", "test", ":", "/", "\\.less$", "/", ",", "use", ":", "[", "dev", "?", "'style-loader'", ":", "MiniCssExtractPlugin", ".", "loader", ",", "...", "cssLoaders", ",", "{", "loader", ":", "'less-loader'", ",", "options", ":", "lessOptions", ",", "}", ",", "]", ",", "}", ",", "{", "test", ":", "/", "\\.(ttf|woff|woff2)$", "/", ",", "use", ":", "[", "{", "loader", ":", "'file-loader'", ",", "options", ":", "{", "name", ":", "'fonts/[name].[ext]'", ",", "}", ",", "}", "]", ",", "}", ",", "]", ",", "}", ",", "externals", ":", "'katex'", ",", "plugins", ":", "[", "!", "dev", "&&", "new", "MiniCssExtractPlugin", "(", "{", "filename", ":", "minimize", "?", "'[name].min.css'", ":", "'[name].css'", ",", "}", ")", ",", "]", ".", "filter", "(", "Boolean", ")", ",", "devtool", ":", "dev", "&&", "'inline-source-map'", ",", "optimization", ":", "{", "minimize", ",", "minimizer", ":", "[", "new", "TerserPlugin", "(", "{", "terserOptions", ":", "{", "output", ":", "{", "ascii_only", ":", "true", ",", "}", ",", "}", ",", "}", ")", ",", "]", ",", "}", ",", "performance", ":", "{", "hints", ":", "false", ",", "}", ",", "}", ";", "}" ]
Create a webpack config for given target
[ "Create", "a", "webpack", "config", "for", "given", "target" ]
17bfb247b88070267f3e5c7b21fe4a360fdf49d9
https://github.com/KaTeX/KaTeX/blob/17bfb247b88070267f3e5c7b21fe4a360fdf49d9/webpack.common.js#L53-L158
3,452
KaTeX/KaTeX
contrib/mhchem/mhchem.js
function (tokens, stateMachine) { // Recreate the argument string from KaTeX's array of tokens. var str = ""; var expectedLoc = tokens[tokens.length - 1].loc.start for (var i = tokens.length - 1; i >= 0; i--) { if(tokens[i].loc.start > expectedLoc) { // context.consumeArgs has eaten a space. str += " "; expectedLoc = tokens[i].loc.start; } str += tokens[i].text; expectedLoc += tokens[i].text.length; } var tex = texify.go(mhchemParser.go(str, stateMachine)); return tex; }
javascript
function (tokens, stateMachine) { // Recreate the argument string from KaTeX's array of tokens. var str = ""; var expectedLoc = tokens[tokens.length - 1].loc.start for (var i = tokens.length - 1; i >= 0; i--) { if(tokens[i].loc.start > expectedLoc) { // context.consumeArgs has eaten a space. str += " "; expectedLoc = tokens[i].loc.start; } str += tokens[i].text; expectedLoc += tokens[i].text.length; } var tex = texify.go(mhchemParser.go(str, stateMachine)); return tex; }
[ "function", "(", "tokens", ",", "stateMachine", ")", "{", "// Recreate the argument string from KaTeX's array of tokens.", "var", "str", "=", "\"\"", ";", "var", "expectedLoc", "=", "tokens", "[", "tokens", ".", "length", "-", "1", "]", ".", "loc", ".", "start", "for", "(", "var", "i", "=", "tokens", ".", "length", "-", "1", ";", "i", ">=", "0", ";", "i", "--", ")", "{", "if", "(", "tokens", "[", "i", "]", ".", "loc", ".", "start", ">", "expectedLoc", ")", "{", "// context.consumeArgs has eaten a space.", "str", "+=", "\" \"", ";", "expectedLoc", "=", "tokens", "[", "i", "]", ".", "loc", ".", "start", ";", "}", "str", "+=", "tokens", "[", "i", "]", ".", "text", ";", "expectedLoc", "+=", "tokens", "[", "i", "]", ".", "text", ".", "length", ";", "}", "var", "tex", "=", "texify", ".", "go", "(", "mhchemParser", ".", "go", "(", "str", ",", "stateMachine", ")", ")", ";", "return", "tex", ";", "}" ]
This is the main function for handing the \ce and \pu commands. It takes the argument to \ce or \pu and returns the corresponding TeX string.
[ "This", "is", "the", "main", "function", "for", "handing", "the", "\\", "ce", "and", "\\", "pu", "commands", ".", "It", "takes", "the", "argument", "to", "\\", "ce", "or", "\\", "pu", "and", "returns", "the", "corresponding", "TeX", "string", "." ]
17bfb247b88070267f3e5c7b21fe4a360fdf49d9
https://github.com/KaTeX/KaTeX/blob/17bfb247b88070267f3e5c7b21fe4a360fdf49d9/contrib/mhchem/mhchem.js#L77-L92
3,453
KaTeX/KaTeX
dockers/screenshotter/screenshotter.js
execFile
function execFile(cmd, args, opts) { return new Promise(function(resolve, reject) { childProcess.execFile(cmd, args, opts, function(err, stdout, stderr) { if (err) { console.error("Error executing " + cmd + " " + args.join(" ")); console.error(stdout + stderr); err.stdout = stdout; err.stderr = stderr; reject(err); } else { resolve(stdout); } }); }); }
javascript
function execFile(cmd, args, opts) { return new Promise(function(resolve, reject) { childProcess.execFile(cmd, args, opts, function(err, stdout, stderr) { if (err) { console.error("Error executing " + cmd + " " + args.join(" ")); console.error(stdout + stderr); err.stdout = stdout; err.stderr = stderr; reject(err); } else { resolve(stdout); } }); }); }
[ "function", "execFile", "(", "cmd", ",", "args", ",", "opts", ")", "{", "return", "new", "Promise", "(", "function", "(", "resolve", ",", "reject", ")", "{", "childProcess", ".", "execFile", "(", "cmd", ",", "args", ",", "opts", ",", "function", "(", "err", ",", "stdout", ",", "stderr", ")", "{", "if", "(", "err", ")", "{", "console", ".", "error", "(", "\"Error executing \"", "+", "cmd", "+", "\" \"", "+", "args", ".", "join", "(", "\" \"", ")", ")", ";", "console", ".", "error", "(", "stdout", "+", "stderr", ")", ";", "err", ".", "stdout", "=", "stdout", ";", "err", ".", "stderr", "=", "stderr", ";", "reject", "(", "err", ")", ";", "}", "else", "{", "resolve", "(", "stdout", ")", ";", "}", "}", ")", ";", "}", ")", ";", "}" ]
Execute a given command, and return a promise to its output.
[ "Execute", "a", "given", "command", "and", "return", "a", "promise", "to", "its", "output", "." ]
17bfb247b88070267f3e5c7b21fe4a360fdf49d9
https://github.com/KaTeX/KaTeX/blob/17bfb247b88070267f3e5c7b21fe4a360fdf49d9/dockers/screenshotter/screenshotter.js#L561-L575
3,454
mattdesl/canvas-sketch
examples/experimental/webgl-2d.js
getNormalizedPrimitive2D
function getNormalizedPrimitive2D ({ positions, cells, normals, uvs }, opt = {}) { // Default to assuming the positions are a unit circle/box/etc normals = normals ? expandVectorList(normals) : positions.map(p => vec3.normalize([], expandVector(p))); // Planar UV across bounding box of mesh uvs = uvs || get2DUV(positions); // Assume 2D primitives are centered in -1..1 space, recenter to 0..1 positions = opt.center ? recenter(positions) : positions; // Expand to 3D positions = expandVectorList(positions); return { positions, uvs, normals, cells }; }
javascript
function getNormalizedPrimitive2D ({ positions, cells, normals, uvs }, opt = {}) { // Default to assuming the positions are a unit circle/box/etc normals = normals ? expandVectorList(normals) : positions.map(p => vec3.normalize([], expandVector(p))); // Planar UV across bounding box of mesh uvs = uvs || get2DUV(positions); // Assume 2D primitives are centered in -1..1 space, recenter to 0..1 positions = opt.center ? recenter(positions) : positions; // Expand to 3D positions = expandVectorList(positions); return { positions, uvs, normals, cells }; }
[ "function", "getNormalizedPrimitive2D", "(", "{", "positions", ",", "cells", ",", "normals", ",", "uvs", "}", ",", "opt", "=", "{", "}", ")", "{", "// Default to assuming the positions are a unit circle/box/etc", "normals", "=", "normals", "?", "expandVectorList", "(", "normals", ")", ":", "positions", ".", "map", "(", "p", "=>", "vec3", ".", "normalize", "(", "[", "]", ",", "expandVector", "(", "p", ")", ")", ")", ";", "// Planar UV across bounding box of mesh", "uvs", "=", "uvs", "||", "get2DUV", "(", "positions", ")", ";", "// Assume 2D primitives are centered in -1..1 space, recenter to 0..1", "positions", "=", "opt", ".", "center", "?", "recenter", "(", "positions", ")", ":", "positions", ";", "// Expand to 3D", "positions", "=", "expandVectorList", "(", "positions", ")", ";", "return", "{", "positions", ",", "uvs", ",", "normals", ",", "cells", "}", ";", "}" ]
A unit 2D rectangle, circle, etc
[ "A", "unit", "2D", "rectangle", "circle", "etc" ]
4addd0fe3fc053065ca8597ab204e43587c52879
https://github.com/mattdesl/canvas-sketch/blob/4addd0fe3fc053065ca8597ab204e43587c52879/examples/experimental/webgl-2d.js#L177-L192
3,455
mattdesl/canvas-sketch
examples/experimental/webgl-2d.js
getNormalizedPrimitive3D
function getNormalizedPrimitive3D ({ positions, cells, normals, uvs }, opt = {}) { return { positions, uvs, normals, cells }; }
javascript
function getNormalizedPrimitive3D ({ positions, cells, normals, uvs }, opt = {}) { return { positions, uvs, normals, cells }; }
[ "function", "getNormalizedPrimitive3D", "(", "{", "positions", ",", "cells", ",", "normals", ",", "uvs", "}", ",", "opt", "=", "{", "}", ")", "{", "return", "{", "positions", ",", "uvs", ",", "normals", ",", "cells", "}", ";", "}" ]
A unit 3D sphere, torus, etc
[ "A", "unit", "3D", "sphere", "torus", "etc" ]
4addd0fe3fc053065ca8597ab204e43587c52879
https://github.com/mattdesl/canvas-sketch/blob/4addd0fe3fc053065ca8597ab204e43587c52879/examples/experimental/webgl-2d.js#L195-L202
3,456
google/draco
javascript/example/DRACOLoader.js
function(attributeName, skip) { var skipDequantization = true; if (typeof skip !== 'undefined') skipDequantization = skip; this.getAttributeOptions(attributeName).skipDequantization = skipDequantization; }
javascript
function(attributeName, skip) { var skipDequantization = true; if (typeof skip !== 'undefined') skipDequantization = skip; this.getAttributeOptions(attributeName).skipDequantization = skipDequantization; }
[ "function", "(", "attributeName", ",", "skip", ")", "{", "var", "skipDequantization", "=", "true", ";", "if", "(", "typeof", "skip", "!==", "'undefined'", ")", "skipDequantization", "=", "skip", ";", "this", ".", "getAttributeOptions", "(", "attributeName", ")", ".", "skipDequantization", "=", "skipDequantization", ";", "}" ]
Skips dequantization for a specific attribute. |attributeName| is the THREE.js name of the given attribute type. The only currently supported |attributeName| is 'position', more may be added in future.
[ "Skips", "dequantization", "for", "a", "specific", "attribute", ".", "|attributeName|", "is", "the", "THREE", ".", "js", "name", "of", "the", "given", "attribute", "type", ".", "The", "only", "currently", "supported", "|attributeName|", "is", "position", "more", "may", "be", "added", "in", "future", "." ]
785c9c4aa2b952236c29ad639901dbbaf216da38
https://github.com/google/draco/blob/785c9c4aa2b952236c29ad639901dbbaf216da38/javascript/example/DRACOLoader.js#L81-L87
3,457
google/draco
docs/assets/js/ASCIIMathML.js
initSymbols
function initSymbols() { var i; var symlen = AMsymbols.length; for (i=0; i<symlen; i++) { if (AMsymbols[i].tex) { AMsymbols.push({input:AMsymbols[i].tex, tag:AMsymbols[i].tag, output:AMsymbols[i].output, ttype:AMsymbols[i].ttype, acc:(AMsymbols[i].acc||false)}); } } refreshSymbols(); }
javascript
function initSymbols() { var i; var symlen = AMsymbols.length; for (i=0; i<symlen; i++) { if (AMsymbols[i].tex) { AMsymbols.push({input:AMsymbols[i].tex, tag:AMsymbols[i].tag, output:AMsymbols[i].output, ttype:AMsymbols[i].ttype, acc:(AMsymbols[i].acc||false)}); } } refreshSymbols(); }
[ "function", "initSymbols", "(", ")", "{", "var", "i", ";", "var", "symlen", "=", "AMsymbols", ".", "length", ";", "for", "(", "i", "=", "0", ";", "i", "<", "symlen", ";", "i", "++", ")", "{", "if", "(", "AMsymbols", "[", "i", "]", ".", "tex", ")", "{", "AMsymbols", ".", "push", "(", "{", "input", ":", "AMsymbols", "[", "i", "]", ".", "tex", ",", "tag", ":", "AMsymbols", "[", "i", "]", ".", "tag", ",", "output", ":", "AMsymbols", "[", "i", "]", ".", "output", ",", "ttype", ":", "AMsymbols", "[", "i", "]", ".", "ttype", ",", "acc", ":", "(", "AMsymbols", "[", "i", "]", ".", "acc", "||", "false", ")", "}", ")", ";", "}", "}", "refreshSymbols", "(", ")", ";", "}" ]
list of input symbols
[ "list", "of", "input", "symbols" ]
785c9c4aa2b952236c29ad639901dbbaf216da38
https://github.com/google/draco/blob/785c9c4aa2b952236c29ad639901dbbaf216da38/docs/assets/js/ASCIIMathML.js#L475-L486
3,458
material-components/material-components-web-react
scripts/release/cp-pkgs.js
cpTypes
function cpTypes(typeAsset) { const {dir, base} = path.parse(typeAsset); let destDir = dir.split('build/types/')[1]; destDir = destDir.split('/'); destDir.splice(2, 0, 'dist'); destDir = `${destDir.join('/')}/${base}`; addTsIgnore(typeAsset); return cpFile(typeAsset, destDir) .then(() => console.log(`cp ${typeAsset} -> ${destDir}`)); }
javascript
function cpTypes(typeAsset) { const {dir, base} = path.parse(typeAsset); let destDir = dir.split('build/types/')[1]; destDir = destDir.split('/'); destDir.splice(2, 0, 'dist'); destDir = `${destDir.join('/')}/${base}`; addTsIgnore(typeAsset); return cpFile(typeAsset, destDir) .then(() => console.log(`cp ${typeAsset} -> ${destDir}`)); }
[ "function", "cpTypes", "(", "typeAsset", ")", "{", "const", "{", "dir", ",", "base", "}", "=", "path", ".", "parse", "(", "typeAsset", ")", ";", "let", "destDir", "=", "dir", ".", "split", "(", "'build/types/'", ")", "[", "1", "]", ";", "destDir", "=", "destDir", ".", "split", "(", "'/'", ")", ";", "destDir", ".", "splice", "(", "2", ",", "0", ",", "'dist'", ")", ";", "destDir", "=", "`", "${", "destDir", ".", "join", "(", "'/'", ")", "}", "${", "base", "}", "`", ";", "addTsIgnore", "(", "typeAsset", ")", ";", "return", "cpFile", "(", "typeAsset", ",", "destDir", ")", ".", "then", "(", "(", ")", "=>", "console", ".", "log", "(", "`", "${", "typeAsset", "}", "${", "destDir", "}", "`", ")", ")", ";", "}" ]
takes assetPath, computes the destination file directory path and copies file into destination directory
[ "takes", "assetPath", "computes", "the", "destination", "file", "directory", "path", "and", "copies", "file", "into", "destination", "directory" ]
5ee9df0982d6cff893523c3e1e447b0f98bf8611
https://github.com/material-components/material-components-web-react/blob/5ee9df0982d6cff893523c3e1e447b0f98bf8611/scripts/release/cp-pkgs.js#L96-L105
3,459
jantimon/html-webpack-plugin
index.js
templateParametersGenerator
function templateParametersGenerator (compilation, assets, assetTags, options) { const xhtml = options.xhtml; assetTags.headTags.toString = function () { return this.map((assetTagObject) => htmlTagObjectToString(assetTagObject, xhtml)).join(''); }; assetTags.bodyTags.toString = function () { return this.map((assetTagObject) => htmlTagObjectToString(assetTagObject, xhtml)).join(''); }; return { compilation: compilation, webpackConfig: compilation.options, htmlWebpackPlugin: { tags: assetTags, files: assets, options: options } }; }
javascript
function templateParametersGenerator (compilation, assets, assetTags, options) { const xhtml = options.xhtml; assetTags.headTags.toString = function () { return this.map((assetTagObject) => htmlTagObjectToString(assetTagObject, xhtml)).join(''); }; assetTags.bodyTags.toString = function () { return this.map((assetTagObject) => htmlTagObjectToString(assetTagObject, xhtml)).join(''); }; return { compilation: compilation, webpackConfig: compilation.options, htmlWebpackPlugin: { tags: assetTags, files: assets, options: options } }; }
[ "function", "templateParametersGenerator", "(", "compilation", ",", "assets", ",", "assetTags", ",", "options", ")", "{", "const", "xhtml", "=", "options", ".", "xhtml", ";", "assetTags", ".", "headTags", ".", "toString", "=", "function", "(", ")", "{", "return", "this", ".", "map", "(", "(", "assetTagObject", ")", "=>", "htmlTagObjectToString", "(", "assetTagObject", ",", "xhtml", ")", ")", ".", "join", "(", "''", ")", ";", "}", ";", "assetTags", ".", "bodyTags", ".", "toString", "=", "function", "(", ")", "{", "return", "this", ".", "map", "(", "(", "assetTagObject", ")", "=>", "htmlTagObjectToString", "(", "assetTagObject", ",", "xhtml", ")", ")", ".", "join", "(", "''", ")", ";", "}", ";", "return", "{", "compilation", ":", "compilation", ",", "webpackConfig", ":", "compilation", ".", "options", ",", "htmlWebpackPlugin", ":", "{", "tags", ":", "assetTags", ",", "files", ":", "assets", ",", "options", ":", "options", "}", "}", ";", "}" ]
The default for options.templateParameter Generate the template parameters Generate the template parameters for the template function @param {WebpackCompilation} compilation @param {{ publicPath: string, js: Array<string>, css: Array<string>, manifest?: string, favicon?: string }} assets @param {{ headTags: HtmlTagObject[], bodyTags: HtmlTagObject[] }} assetTags @param {ProcessedHtmlWebpackOptions} options @returns {TemplateParameter}
[ "The", "default", "for", "options", ".", "templateParameter", "Generate", "the", "template", "parameters" ]
38db64ae8805de37d038e0ee0f6dfa2a26e2163a
https://github.com/jantimon/html-webpack-plugin/blob/38db64ae8805de37d038e0ee0f6dfa2a26e2163a/index.js#L958-L975
3,460
jantimon/html-webpack-plugin
lib/html-tags.js
createHtmlTagObject
function createHtmlTagObject (tagName, attributes, innerHTML) { return { tagName: tagName, voidTag: voidTags.indexOf(tagName) !== -1, attributes: attributes || {}, innerHTML: innerHTML }; }
javascript
function createHtmlTagObject (tagName, attributes, innerHTML) { return { tagName: tagName, voidTag: voidTags.indexOf(tagName) !== -1, attributes: attributes || {}, innerHTML: innerHTML }; }
[ "function", "createHtmlTagObject", "(", "tagName", ",", "attributes", ",", "innerHTML", ")", "{", "return", "{", "tagName", ":", "tagName", ",", "voidTag", ":", "voidTags", ".", "indexOf", "(", "tagName", ")", "!==", "-", "1", ",", "attributes", ":", "attributes", "||", "{", "}", ",", "innerHTML", ":", "innerHTML", "}", ";", "}" ]
Static helper to create a tag object to be get injected into the dom @param {string} tagName the name of the tage e.g. 'div' @param {{[attributeName: string]: string|boolean}} [attributes] tag attributes e.g. `{ 'class': 'example', disabled: true }` @param {string} [innerHTML] @returns {HtmlTagObject}
[ "Static", "helper", "to", "create", "a", "tag", "object", "to", "be", "get", "injected", "into", "the", "dom" ]
38db64ae8805de37d038e0ee0f6dfa2a26e2163a
https://github.com/jantimon/html-webpack-plugin/blob/38db64ae8805de37d038e0ee0f6dfa2a26e2163a/lib/html-tags.js#L59-L66
3,461
jantimon/html-webpack-plugin
lib/compiler.js
extractHelperFilesFromCompilation
function extractHelperFilesFromCompilation (mainCompilation, childCompilation, filename, childEntryChunks) { const helperAssetNames = childEntryChunks.map((entryChunk, index) => { return mainCompilation.mainTemplate.hooks.assetPath.call(filename, { hash: childCompilation.hash, chunk: entryChunk, name: `HtmlWebpackPlugin_${index}` }); }); helperAssetNames.forEach((helperFileName) => { delete mainCompilation.assets[helperFileName]; }); const helperContents = helperAssetNames.map((helperFileName) => { return childCompilation.assets[helperFileName].source(); }); return helperContents; }
javascript
function extractHelperFilesFromCompilation (mainCompilation, childCompilation, filename, childEntryChunks) { const helperAssetNames = childEntryChunks.map((entryChunk, index) => { return mainCompilation.mainTemplate.hooks.assetPath.call(filename, { hash: childCompilation.hash, chunk: entryChunk, name: `HtmlWebpackPlugin_${index}` }); }); helperAssetNames.forEach((helperFileName) => { delete mainCompilation.assets[helperFileName]; }); const helperContents = helperAssetNames.map((helperFileName) => { return childCompilation.assets[helperFileName].source(); }); return helperContents; }
[ "function", "extractHelperFilesFromCompilation", "(", "mainCompilation", ",", "childCompilation", ",", "filename", ",", "childEntryChunks", ")", "{", "const", "helperAssetNames", "=", "childEntryChunks", ".", "map", "(", "(", "entryChunk", ",", "index", ")", "=>", "{", "return", "mainCompilation", ".", "mainTemplate", ".", "hooks", ".", "assetPath", ".", "call", "(", "filename", ",", "{", "hash", ":", "childCompilation", ".", "hash", ",", "chunk", ":", "entryChunk", ",", "name", ":", "`", "${", "index", "}", "`", "}", ")", ";", "}", ")", ";", "helperAssetNames", ".", "forEach", "(", "(", "helperFileName", ")", "=>", "{", "delete", "mainCompilation", ".", "assets", "[", "helperFileName", "]", ";", "}", ")", ";", "const", "helperContents", "=", "helperAssetNames", ".", "map", "(", "(", "helperFileName", ")", "=>", "{", "return", "childCompilation", ".", "assets", "[", "helperFileName", "]", ".", "source", "(", ")", ";", "}", ")", ";", "return", "helperContents", ";", "}" ]
The webpack child compilation will create files as a side effect. This function will extract them and clean them up so they won't be written to disk. Returns the source code of the compiled templates as string @returns Array<string>
[ "The", "webpack", "child", "compilation", "will", "create", "files", "as", "a", "side", "effect", ".", "This", "function", "will", "extract", "them", "and", "clean", "them", "up", "so", "they", "won", "t", "be", "written", "to", "disk", "." ]
38db64ae8805de37d038e0ee0f6dfa2a26e2163a
https://github.com/jantimon/html-webpack-plugin/blob/38db64ae8805de37d038e0ee0f6dfa2a26e2163a/lib/compiler.js#L180-L198
3,462
jantimon/html-webpack-plugin
lib/compiler.js
getChildCompiler
function getChildCompiler (mainCompiler) { const cachedChildCompiler = childCompilerCache.get(mainCompiler); if (cachedChildCompiler) { return cachedChildCompiler; } const newCompiler = new HtmlWebpackChildCompiler(); childCompilerCache.set(mainCompiler, newCompiler); return newCompiler; }
javascript
function getChildCompiler (mainCompiler) { const cachedChildCompiler = childCompilerCache.get(mainCompiler); if (cachedChildCompiler) { return cachedChildCompiler; } const newCompiler = new HtmlWebpackChildCompiler(); childCompilerCache.set(mainCompiler, newCompiler); return newCompiler; }
[ "function", "getChildCompiler", "(", "mainCompiler", ")", "{", "const", "cachedChildCompiler", "=", "childCompilerCache", ".", "get", "(", "mainCompiler", ")", ";", "if", "(", "cachedChildCompiler", ")", "{", "return", "cachedChildCompiler", ";", "}", "const", "newCompiler", "=", "new", "HtmlWebpackChildCompiler", "(", ")", ";", "childCompilerCache", ".", "set", "(", "mainCompiler", ",", "newCompiler", ")", ";", "return", "newCompiler", ";", "}" ]
Get child compiler from cache or a new child compiler for the given mainCompilation @param {WebpackCompiler} mainCompiler
[ "Get", "child", "compiler", "from", "cache", "or", "a", "new", "child", "compiler", "for", "the", "given", "mainCompilation" ]
38db64ae8805de37d038e0ee0f6dfa2a26e2163a
https://github.com/jantimon/html-webpack-plugin/blob/38db64ae8805de37d038e0ee0f6dfa2a26e2163a/lib/compiler.js#L210-L218
3,463
jantimon/html-webpack-plugin
lib/compiler.js
clearCache
function clearCache (mainCompiler) { const childCompiler = getChildCompiler(mainCompiler); // If this childCompiler was already used // remove the entire childCompiler from the cache if (childCompiler.isCompiling() || childCompiler.didCompile()) { childCompilerCache.delete(mainCompiler); } }
javascript
function clearCache (mainCompiler) { const childCompiler = getChildCompiler(mainCompiler); // If this childCompiler was already used // remove the entire childCompiler from the cache if (childCompiler.isCompiling() || childCompiler.didCompile()) { childCompilerCache.delete(mainCompiler); } }
[ "function", "clearCache", "(", "mainCompiler", ")", "{", "const", "childCompiler", "=", "getChildCompiler", "(", "mainCompiler", ")", ";", "// If this childCompiler was already used", "// remove the entire childCompiler from the cache", "if", "(", "childCompiler", ".", "isCompiling", "(", ")", "||", "childCompiler", ".", "didCompile", "(", ")", ")", "{", "childCompilerCache", ".", "delete", "(", "mainCompiler", ")", ";", "}", "}" ]
Remove the childCompiler from the cache @param {WebpackCompiler} mainCompiler
[ "Remove", "the", "childCompiler", "from", "the", "cache" ]
38db64ae8805de37d038e0ee0f6dfa2a26e2163a
https://github.com/jantimon/html-webpack-plugin/blob/38db64ae8805de37d038e0ee0f6dfa2a26e2163a/lib/compiler.js#L225-L232
3,464
jantimon/html-webpack-plugin
lib/compiler.js
addTemplateToCompiler
function addTemplateToCompiler (mainCompiler, templatePath) { const childCompiler = getChildCompiler(mainCompiler); const isNew = childCompiler.addTemplate(templatePath); if (isNew) { clearCache(mainCompiler); } }
javascript
function addTemplateToCompiler (mainCompiler, templatePath) { const childCompiler = getChildCompiler(mainCompiler); const isNew = childCompiler.addTemplate(templatePath); if (isNew) { clearCache(mainCompiler); } }
[ "function", "addTemplateToCompiler", "(", "mainCompiler", ",", "templatePath", ")", "{", "const", "childCompiler", "=", "getChildCompiler", "(", "mainCompiler", ")", ";", "const", "isNew", "=", "childCompiler", ".", "addTemplate", "(", "templatePath", ")", ";", "if", "(", "isNew", ")", "{", "clearCache", "(", "mainCompiler", ")", ";", "}", "}" ]
Register a template for the current main compiler @param {WebpackCompiler} mainCompiler @param {string} templatePath
[ "Register", "a", "template", "for", "the", "current", "main", "compiler" ]
38db64ae8805de37d038e0ee0f6dfa2a26e2163a
https://github.com/jantimon/html-webpack-plugin/blob/38db64ae8805de37d038e0ee0f6dfa2a26e2163a/lib/compiler.js#L239-L245
3,465
jantimon/html-webpack-plugin
lib/compiler.js
compileTemplate
function compileTemplate (templatePath, outputFilename, mainCompilation) { const childCompiler = getChildCompiler(mainCompilation.compiler); return childCompiler.compileTemplates(mainCompilation).then((compiledTemplates) => { if (!compiledTemplates[templatePath]) console.log(Object.keys(compiledTemplates), templatePath); const compiledTemplate = compiledTemplates[templatePath]; // Replace [hash] placeholders in filename const outputName = mainCompilation.mainTemplate.hooks.assetPath.call(outputFilename, { hash: compiledTemplate.hash, chunk: compiledTemplate.entry }); return { // Hash of the template entry point hash: compiledTemplate.hash, // Output name outputName: outputName, // Compiled code content: compiledTemplate.content }; }); }
javascript
function compileTemplate (templatePath, outputFilename, mainCompilation) { const childCompiler = getChildCompiler(mainCompilation.compiler); return childCompiler.compileTemplates(mainCompilation).then((compiledTemplates) => { if (!compiledTemplates[templatePath]) console.log(Object.keys(compiledTemplates), templatePath); const compiledTemplate = compiledTemplates[templatePath]; // Replace [hash] placeholders in filename const outputName = mainCompilation.mainTemplate.hooks.assetPath.call(outputFilename, { hash: compiledTemplate.hash, chunk: compiledTemplate.entry }); return { // Hash of the template entry point hash: compiledTemplate.hash, // Output name outputName: outputName, // Compiled code content: compiledTemplate.content }; }); }
[ "function", "compileTemplate", "(", "templatePath", ",", "outputFilename", ",", "mainCompilation", ")", "{", "const", "childCompiler", "=", "getChildCompiler", "(", "mainCompilation", ".", "compiler", ")", ";", "return", "childCompiler", ".", "compileTemplates", "(", "mainCompilation", ")", ".", "then", "(", "(", "compiledTemplates", ")", "=>", "{", "if", "(", "!", "compiledTemplates", "[", "templatePath", "]", ")", "console", ".", "log", "(", "Object", ".", "keys", "(", "compiledTemplates", ")", ",", "templatePath", ")", ";", "const", "compiledTemplate", "=", "compiledTemplates", "[", "templatePath", "]", ";", "// Replace [hash] placeholders in filename", "const", "outputName", "=", "mainCompilation", ".", "mainTemplate", ".", "hooks", ".", "assetPath", ".", "call", "(", "outputFilename", ",", "{", "hash", ":", "compiledTemplate", ".", "hash", ",", "chunk", ":", "compiledTemplate", ".", "entry", "}", ")", ";", "return", "{", "// Hash of the template entry point", "hash", ":", "compiledTemplate", ".", "hash", ",", "// Output name", "outputName", ":", "outputName", ",", "// Compiled code", "content", ":", "compiledTemplate", ".", "content", "}", ";", "}", ")", ";", "}" ]
Starts the compilation for all templates. This has to be called once all templates where added. If this function is called multiple times it will use a cache inside the childCompiler @param {string} templatePath @param {string} outputFilename @param {WebpackCompilation} mainCompilation
[ "Starts", "the", "compilation", "for", "all", "templates", ".", "This", "has", "to", "be", "called", "once", "all", "templates", "where", "added", "." ]
38db64ae8805de37d038e0ee0f6dfa2a26e2163a
https://github.com/jantimon/html-webpack-plugin/blob/38db64ae8805de37d038e0ee0f6dfa2a26e2163a/lib/compiler.js#L258-L277
3,466
jantimon/html-webpack-plugin
lib/compiler.js
hasOutDatedTemplateCache
function hasOutDatedTemplateCache (mainCompilation) { const childCompiler = getChildCompiler(mainCompilation.compiler); /** * @type {WeakMap<HtmlWebpackChildCompiler, boolean>|undefined} */ let hasOutdatedChildCompilerDependenciesMap = hasOutdatedCompilationDependenciesMap.get(mainCompilation); // Create map for childCompiler if none exist if (!hasOutdatedChildCompilerDependenciesMap) { hasOutdatedChildCompilerDependenciesMap = new WeakMap(); hasOutdatedCompilationDependenciesMap.set(mainCompilation, hasOutdatedChildCompilerDependenciesMap); } // Try to get the `checkChildCompilerCache` result from cache let isOutdated = hasOutdatedChildCompilerDependenciesMap.get(childCompiler); if (isOutdated !== undefined) { return isOutdated; } // If `checkChildCompilerCache` has never been called for the given // `mainCompilation` and `childCompiler` combination call it: isOutdated = isChildCompilerCacheOutdated(mainCompilation, childCompiler); hasOutdatedChildCompilerDependenciesMap.set(childCompiler, isOutdated); return isOutdated; }
javascript
function hasOutDatedTemplateCache (mainCompilation) { const childCompiler = getChildCompiler(mainCompilation.compiler); /** * @type {WeakMap<HtmlWebpackChildCompiler, boolean>|undefined} */ let hasOutdatedChildCompilerDependenciesMap = hasOutdatedCompilationDependenciesMap.get(mainCompilation); // Create map for childCompiler if none exist if (!hasOutdatedChildCompilerDependenciesMap) { hasOutdatedChildCompilerDependenciesMap = new WeakMap(); hasOutdatedCompilationDependenciesMap.set(mainCompilation, hasOutdatedChildCompilerDependenciesMap); } // Try to get the `checkChildCompilerCache` result from cache let isOutdated = hasOutdatedChildCompilerDependenciesMap.get(childCompiler); if (isOutdated !== undefined) { return isOutdated; } // If `checkChildCompilerCache` has never been called for the given // `mainCompilation` and `childCompiler` combination call it: isOutdated = isChildCompilerCacheOutdated(mainCompilation, childCompiler); hasOutdatedChildCompilerDependenciesMap.set(childCompiler, isOutdated); return isOutdated; }
[ "function", "hasOutDatedTemplateCache", "(", "mainCompilation", ")", "{", "const", "childCompiler", "=", "getChildCompiler", "(", "mainCompilation", ".", "compiler", ")", ";", "/**\n * @type {WeakMap<HtmlWebpackChildCompiler, boolean>|undefined}\n */", "let", "hasOutdatedChildCompilerDependenciesMap", "=", "hasOutdatedCompilationDependenciesMap", ".", "get", "(", "mainCompilation", ")", ";", "// Create map for childCompiler if none exist", "if", "(", "!", "hasOutdatedChildCompilerDependenciesMap", ")", "{", "hasOutdatedChildCompilerDependenciesMap", "=", "new", "WeakMap", "(", ")", ";", "hasOutdatedCompilationDependenciesMap", ".", "set", "(", "mainCompilation", ",", "hasOutdatedChildCompilerDependenciesMap", ")", ";", "}", "// Try to get the `checkChildCompilerCache` result from cache", "let", "isOutdated", "=", "hasOutdatedChildCompilerDependenciesMap", ".", "get", "(", "childCompiler", ")", ";", "if", "(", "isOutdated", "!==", "undefined", ")", "{", "return", "isOutdated", ";", "}", "// If `checkChildCompilerCache` has never been called for the given", "// `mainCompilation` and `childCompiler` combination call it:", "isOutdated", "=", "isChildCompilerCacheOutdated", "(", "mainCompilation", ",", "childCompiler", ")", ";", "hasOutdatedChildCompilerDependenciesMap", ".", "set", "(", "childCompiler", ",", "isOutdated", ")", ";", "return", "isOutdated", ";", "}" ]
Returns `true` if the file dependencies of the current childCompiler for the given mainCompilation are outdated. Uses the `hasOutdatedCompilationDependenciesMap` cache if possible. @param {WebpackCompilation} mainCompilation @returns {boolean}
[ "Returns", "true", "if", "the", "file", "dependencies", "of", "the", "current", "childCompiler", "for", "the", "given", "mainCompilation", "are", "outdated", "." ]
38db64ae8805de37d038e0ee0f6dfa2a26e2163a
https://github.com/jantimon/html-webpack-plugin/blob/38db64ae8805de37d038e0ee0f6dfa2a26e2163a/lib/compiler.js#L303-L324
3,467
jantimon/html-webpack-plugin
lib/compiler.js
isChildCompilerCacheOutdated
function isChildCompilerCacheOutdated (mainCompilation, childCompiler) { // If the compilation was never run there is no invalid cache if (!childCompiler.compilationStartedTimestamp) { return false; } // Check if any dependent file was changed after the last compilation const fileTimestamps = mainCompilation.fileTimestamps; const isCacheOutOfDate = childCompiler.fileDependencies.some((fileDependency) => { const timestamp = fileTimestamps.get(fileDependency); // If the timestamp is not known the file is new // If the timestamp is larger then the file has changed // Otherwise the file is still the same return !timestamp || timestamp > childCompiler.compilationStartedTimestamp; }); return isCacheOutOfDate; }
javascript
function isChildCompilerCacheOutdated (mainCompilation, childCompiler) { // If the compilation was never run there is no invalid cache if (!childCompiler.compilationStartedTimestamp) { return false; } // Check if any dependent file was changed after the last compilation const fileTimestamps = mainCompilation.fileTimestamps; const isCacheOutOfDate = childCompiler.fileDependencies.some((fileDependency) => { const timestamp = fileTimestamps.get(fileDependency); // If the timestamp is not known the file is new // If the timestamp is larger then the file has changed // Otherwise the file is still the same return !timestamp || timestamp > childCompiler.compilationStartedTimestamp; }); return isCacheOutOfDate; }
[ "function", "isChildCompilerCacheOutdated", "(", "mainCompilation", ",", "childCompiler", ")", "{", "// If the compilation was never run there is no invalid cache", "if", "(", "!", "childCompiler", ".", "compilationStartedTimestamp", ")", "{", "return", "false", ";", "}", "// Check if any dependent file was changed after the last compilation", "const", "fileTimestamps", "=", "mainCompilation", ".", "fileTimestamps", ";", "const", "isCacheOutOfDate", "=", "childCompiler", ".", "fileDependencies", ".", "some", "(", "(", "fileDependency", ")", "=>", "{", "const", "timestamp", "=", "fileTimestamps", ".", "get", "(", "fileDependency", ")", ";", "// If the timestamp is not known the file is new", "// If the timestamp is larger then the file has changed", "// Otherwise the file is still the same", "return", "!", "timestamp", "||", "timestamp", ">", "childCompiler", ".", "compilationStartedTimestamp", ";", "}", ")", ";", "return", "isCacheOutOfDate", ";", "}" ]
Returns `true` if the file dependencies of the given childCompiler are outdated. @param {WebpackCompilation} mainCompilation @param {HtmlWebpackChildCompiler} childCompiler @returns {boolean}
[ "Returns", "true", "if", "the", "file", "dependencies", "of", "the", "given", "childCompiler", "are", "outdated", "." ]
38db64ae8805de37d038e0ee0f6dfa2a26e2163a
https://github.com/jantimon/html-webpack-plugin/blob/38db64ae8805de37d038e0ee0f6dfa2a26e2163a/lib/compiler.js#L333-L348
3,468
jantimon/html-webpack-plugin
lib/hooks.js
getHtmlWebpackPluginHooks
function getHtmlWebpackPluginHooks (compilation) { let hooks = htmlWebpackPluginHooksMap.get(compilation); // Setup the hooks only once if (hooks === undefined) { hooks = createHtmlWebpackPluginHooks(); htmlWebpackPluginHooksMap.set(compilation, hooks); } return hooks; }
javascript
function getHtmlWebpackPluginHooks (compilation) { let hooks = htmlWebpackPluginHooksMap.get(compilation); // Setup the hooks only once if (hooks === undefined) { hooks = createHtmlWebpackPluginHooks(); htmlWebpackPluginHooksMap.set(compilation, hooks); } return hooks; }
[ "function", "getHtmlWebpackPluginHooks", "(", "compilation", ")", "{", "let", "hooks", "=", "htmlWebpackPluginHooksMap", ".", "get", "(", "compilation", ")", ";", "// Setup the hooks only once", "if", "(", "hooks", "===", "undefined", ")", "{", "hooks", "=", "createHtmlWebpackPluginHooks", "(", ")", ";", "htmlWebpackPluginHooksMap", ".", "set", "(", "compilation", ",", "hooks", ")", ";", "}", "return", "hooks", ";", "}" ]
Returns all public hooks of the html webpack plugin for the given compilation @param {WebpackCompilation} compilation @returns {HtmlWebpackPluginHooks}
[ "Returns", "all", "public", "hooks", "of", "the", "html", "webpack", "plugin", "for", "the", "given", "compilation" ]
38db64ae8805de37d038e0ee0f6dfa2a26e2163a
https://github.com/jantimon/html-webpack-plugin/blob/38db64ae8805de37d038e0ee0f6dfa2a26e2163a/lib/hooks.js#L77-L85
3,469
jantimon/html-webpack-plugin
lib/hooks.js
createHtmlWebpackPluginHooks
function createHtmlWebpackPluginHooks () { return { beforeAssetTagGeneration: new AsyncSeriesWaterfallHook(['pluginArgs']), alterAssetTags: new AsyncSeriesWaterfallHook(['pluginArgs']), alterAssetTagGroups: new AsyncSeriesWaterfallHook(['pluginArgs']), afterTemplateExecution: new AsyncSeriesWaterfallHook(['pluginArgs']), beforeEmit: new AsyncSeriesWaterfallHook(['pluginArgs']), afterEmit: new AsyncSeriesWaterfallHook(['pluginArgs']) }; }
javascript
function createHtmlWebpackPluginHooks () { return { beforeAssetTagGeneration: new AsyncSeriesWaterfallHook(['pluginArgs']), alterAssetTags: new AsyncSeriesWaterfallHook(['pluginArgs']), alterAssetTagGroups: new AsyncSeriesWaterfallHook(['pluginArgs']), afterTemplateExecution: new AsyncSeriesWaterfallHook(['pluginArgs']), beforeEmit: new AsyncSeriesWaterfallHook(['pluginArgs']), afterEmit: new AsyncSeriesWaterfallHook(['pluginArgs']) }; }
[ "function", "createHtmlWebpackPluginHooks", "(", ")", "{", "return", "{", "beforeAssetTagGeneration", ":", "new", "AsyncSeriesWaterfallHook", "(", "[", "'pluginArgs'", "]", ")", ",", "alterAssetTags", ":", "new", "AsyncSeriesWaterfallHook", "(", "[", "'pluginArgs'", "]", ")", ",", "alterAssetTagGroups", ":", "new", "AsyncSeriesWaterfallHook", "(", "[", "'pluginArgs'", "]", ")", ",", "afterTemplateExecution", ":", "new", "AsyncSeriesWaterfallHook", "(", "[", "'pluginArgs'", "]", ")", ",", "beforeEmit", ":", "new", "AsyncSeriesWaterfallHook", "(", "[", "'pluginArgs'", "]", ")", ",", "afterEmit", ":", "new", "AsyncSeriesWaterfallHook", "(", "[", "'pluginArgs'", "]", ")", "}", ";", "}" ]
Add hooks to the webpack compilation object to allow foreign plugins to extend the HtmlWebpackPlugin @returns {HtmlWebpackPluginHooks}
[ "Add", "hooks", "to", "the", "webpack", "compilation", "object", "to", "allow", "foreign", "plugins", "to", "extend", "the", "HtmlWebpackPlugin" ]
38db64ae8805de37d038e0ee0f6dfa2a26e2163a
https://github.com/jantimon/html-webpack-plugin/blob/38db64ae8805de37d038e0ee0f6dfa2a26e2163a/lib/hooks.js#L93-L102
3,470
archriss/react-native-snap-carousel
example/src/utils/animations.js
scrollInterpolator1
function scrollInterpolator1 (index, carouselProps) { const range = [3, 2, 1, 0, -1]; const inputRange = getInputRangeFromIndexes(range, index, carouselProps); const outputRange = range; return { inputRange, outputRange }; }
javascript
function scrollInterpolator1 (index, carouselProps) { const range = [3, 2, 1, 0, -1]; const inputRange = getInputRangeFromIndexes(range, index, carouselProps); const outputRange = range; return { inputRange, outputRange }; }
[ "function", "scrollInterpolator1", "(", "index", ",", "carouselProps", ")", "{", "const", "range", "=", "[", "3", ",", "2", ",", "1", ",", "0", ",", "-", "1", "]", ";", "const", "inputRange", "=", "getInputRangeFromIndexes", "(", "range", ",", "index", ",", "carouselProps", ")", ";", "const", "outputRange", "=", "range", ";", "return", "{", "inputRange", ",", "outputRange", "}", ";", "}" ]
Photo album effect
[ "Photo", "album", "effect" ]
85980e5177a75d393a1b38480800753282148c50
https://github.com/archriss/react-native-snap-carousel/blob/85980e5177a75d393a1b38480800753282148c50/example/src/utils/animations.js#L4-L10
3,471
feross/simple-peer
index.js
flattenValues
function flattenValues (report) { if (Object.prototype.toString.call(report.values) === '[object Array]') { report.values.forEach(function (value) { Object.assign(report, value) }) } return report }
javascript
function flattenValues (report) { if (Object.prototype.toString.call(report.values) === '[object Array]') { report.values.forEach(function (value) { Object.assign(report, value) }) } return report }
[ "function", "flattenValues", "(", "report", ")", "{", "if", "(", "Object", ".", "prototype", ".", "toString", ".", "call", "(", "report", ".", "values", ")", "===", "'[object Array]'", ")", "{", "report", ".", "values", ".", "forEach", "(", "function", "(", "value", ")", "{", "Object", ".", "assign", "(", "report", ",", "value", ")", "}", ")", "}", "return", "report", "}" ]
statreports can come with a value array instead of properties
[ "statreports", "can", "come", "with", "a", "value", "array", "instead", "of", "properties" ]
3ed91bf631c4bf9c3b4bf5a85d004bb70d621707
https://github.com/feross/simple-peer/blob/3ed91bf631c4bf9c3b4bf5a85d004bb70d621707/index.js#L742-L749
3,472
marcuswestin/store.js
src/store-engine.js
function(key, optionalDefaultValue) { var data = this.storage.read(this._namespacePrefix + key) return this._deserialize(data, optionalDefaultValue) }
javascript
function(key, optionalDefaultValue) { var data = this.storage.read(this._namespacePrefix + key) return this._deserialize(data, optionalDefaultValue) }
[ "function", "(", "key", ",", "optionalDefaultValue", ")", "{", "var", "data", "=", "this", ".", "storage", ".", "read", "(", "this", ".", "_namespacePrefix", "+", "key", ")", "return", "this", ".", "_deserialize", "(", "data", ",", "optionalDefaultValue", ")", "}" ]
get returns the value of the given key. If that value is undefined, it returns optionalDefaultValue instead.
[ "get", "returns", "the", "value", "of", "the", "given", "key", ".", "If", "that", "value", "is", "undefined", "it", "returns", "optionalDefaultValue", "instead", "." ]
b8e22fea8738fc19da4d9e7dbf1cda6e5185c481
https://github.com/marcuswestin/store.js/blob/b8e22fea8738fc19da4d9e7dbf1cda6e5185c481/src/store-engine.js#L21-L24
3,473
marcuswestin/store.js
src/store-engine.js
function(callback) { var self = this this.storage.each(function(val, namespacedKey) { callback.call(self, self._deserialize(val), (namespacedKey || '').replace(self._namespaceRegexp, '')) }) }
javascript
function(callback) { var self = this this.storage.each(function(val, namespacedKey) { callback.call(self, self._deserialize(val), (namespacedKey || '').replace(self._namespaceRegexp, '')) }) }
[ "function", "(", "callback", ")", "{", "var", "self", "=", "this", "this", ".", "storage", ".", "each", "(", "function", "(", "val", ",", "namespacedKey", ")", "{", "callback", ".", "call", "(", "self", ",", "self", ".", "_deserialize", "(", "val", ")", ",", "(", "namespacedKey", "||", "''", ")", ".", "replace", "(", "self", ".", "_namespaceRegexp", ",", "''", ")", ")", "}", ")", "}" ]
each will call the given callback once for each key-value pair in this store.
[ "each", "will", "call", "the", "given", "callback", "once", "for", "each", "key", "-", "value", "pair", "in", "this", "store", "." ]
b8e22fea8738fc19da4d9e7dbf1cda6e5185c481
https://github.com/marcuswestin/store.js/blob/b8e22fea8738fc19da4d9e7dbf1cda6e5185c481/src/store-engine.js#L43-L48
3,474
marcuswestin/store.js
src/store-engine.js
super_fn
function super_fn() { if (!oldFn) { return } each(arguments, function(arg, i) { args[i] = arg }) return oldFn.apply(self, args) }
javascript
function super_fn() { if (!oldFn) { return } each(arguments, function(arg, i) { args[i] = arg }) return oldFn.apply(self, args) }
[ "function", "super_fn", "(", ")", "{", "if", "(", "!", "oldFn", ")", "{", "return", "}", "each", "(", "arguments", ",", "function", "(", "arg", ",", "i", ")", "{", "args", "[", "i", "]", "=", "arg", "}", ")", "return", "oldFn", ".", "apply", "(", "self", ",", "args", ")", "}" ]
super_fn calls the old function which was overwritten by this mixin.
[ "super_fn", "calls", "the", "old", "function", "which", "was", "overwritten", "by", "this", "mixin", "." ]
b8e22fea8738fc19da4d9e7dbf1cda6e5185c481
https://github.com/marcuswestin/store.js/blob/b8e22fea8738fc19da4d9e7dbf1cda6e5185c481/src/store-engine.js#L128-L134
3,475
marcuswestin/store.js
plugins/events.js
set
function set(super_fn, key, val) { var oldVal = this.get(key) super_fn() pubsub.fire(key, val, oldVal) }
javascript
function set(super_fn, key, val) { var oldVal = this.get(key) super_fn() pubsub.fire(key, val, oldVal) }
[ "function", "set", "(", "super_fn", ",", "key", ",", "val", ")", "{", "var", "oldVal", "=", "this", ".", "get", "(", "key", ")", "super_fn", "(", ")", "pubsub", ".", "fire", "(", "key", ",", "val", ",", "oldVal", ")", "}" ]
overwrite function to fire when appropriate
[ "overwrite", "function", "to", "fire", "when", "appropriate" ]
b8e22fea8738fc19da4d9e7dbf1cda6e5185c481
https://github.com/marcuswestin/store.js/blob/b8e22fea8738fc19da4d9e7dbf1cda6e5185c481/plugins/events.js#L34-L38
3,476
sparksuite/simplemde-markdown-editor
src/js/simplemde.js
fixShortcut
function fixShortcut(name) { if(isMac) { name = name.replace("Ctrl", "Cmd"); } else { name = name.replace("Cmd", "Ctrl"); } return name; }
javascript
function fixShortcut(name) { if(isMac) { name = name.replace("Ctrl", "Cmd"); } else { name = name.replace("Cmd", "Ctrl"); } return name; }
[ "function", "fixShortcut", "(", "name", ")", "{", "if", "(", "isMac", ")", "{", "name", "=", "name", ".", "replace", "(", "\"Ctrl\"", ",", "\"Cmd\"", ")", ";", "}", "else", "{", "name", "=", "name", ".", "replace", "(", "\"Cmd\"", ",", "\"Ctrl\"", ")", ";", "}", "return", "name", ";", "}" ]
Fix shortcut. Mac use Command, others use Ctrl.
[ "Fix", "shortcut", ".", "Mac", "use", "Command", "others", "use", "Ctrl", "." ]
6abda7ab68cc20f4aca870eb243747951b90ab04
https://github.com/sparksuite/simplemde-markdown-editor/blob/6abda7ab68cc20f4aca870eb243747951b90ab04/src/js/simplemde.js#L84-L91
3,477
sparksuite/simplemde-markdown-editor
src/js/simplemde.js
getState
function getState(cm, pos) { pos = pos || cm.getCursor("start"); var stat = cm.getTokenAt(pos); if(!stat.type) return {}; var types = stat.type.split(" "); var ret = {}, data, text; for(var i = 0; i < types.length; i++) { data = types[i]; if(data === "strong") { ret.bold = true; } else if(data === "variable-2") { text = cm.getLine(pos.line); if(/^\s*\d+\.\s/.test(text)) { ret["ordered-list"] = true; } else { ret["unordered-list"] = true; } } else if(data === "atom") { ret.quote = true; } else if(data === "em") { ret.italic = true; } else if(data === "quote") { ret.quote = true; } else if(data === "strikethrough") { ret.strikethrough = true; } else if(data === "comment") { ret.code = true; } else if(data === "link") { ret.link = true; } else if(data === "tag") { ret.image = true; } else if(data.match(/^header(\-[1-6])?$/)) { ret[data.replace("header", "heading")] = true; } } return ret; }
javascript
function getState(cm, pos) { pos = pos || cm.getCursor("start"); var stat = cm.getTokenAt(pos); if(!stat.type) return {}; var types = stat.type.split(" "); var ret = {}, data, text; for(var i = 0; i < types.length; i++) { data = types[i]; if(data === "strong") { ret.bold = true; } else if(data === "variable-2") { text = cm.getLine(pos.line); if(/^\s*\d+\.\s/.test(text)) { ret["ordered-list"] = true; } else { ret["unordered-list"] = true; } } else if(data === "atom") { ret.quote = true; } else if(data === "em") { ret.italic = true; } else if(data === "quote") { ret.quote = true; } else if(data === "strikethrough") { ret.strikethrough = true; } else if(data === "comment") { ret.code = true; } else if(data === "link") { ret.link = true; } else if(data === "tag") { ret.image = true; } else if(data.match(/^header(\-[1-6])?$/)) { ret[data.replace("header", "heading")] = true; } } return ret; }
[ "function", "getState", "(", "cm", ",", "pos", ")", "{", "pos", "=", "pos", "||", "cm", ".", "getCursor", "(", "\"start\"", ")", ";", "var", "stat", "=", "cm", ".", "getTokenAt", "(", "pos", ")", ";", "if", "(", "!", "stat", ".", "type", ")", "return", "{", "}", ";", "var", "types", "=", "stat", ".", "type", ".", "split", "(", "\" \"", ")", ";", "var", "ret", "=", "{", "}", ",", "data", ",", "text", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "types", ".", "length", ";", "i", "++", ")", "{", "data", "=", "types", "[", "i", "]", ";", "if", "(", "data", "===", "\"strong\"", ")", "{", "ret", ".", "bold", "=", "true", ";", "}", "else", "if", "(", "data", "===", "\"variable-2\"", ")", "{", "text", "=", "cm", ".", "getLine", "(", "pos", ".", "line", ")", ";", "if", "(", "/", "^\\s*\\d+\\.\\s", "/", ".", "test", "(", "text", ")", ")", "{", "ret", "[", "\"ordered-list\"", "]", "=", "true", ";", "}", "else", "{", "ret", "[", "\"unordered-list\"", "]", "=", "true", ";", "}", "}", "else", "if", "(", "data", "===", "\"atom\"", ")", "{", "ret", ".", "quote", "=", "true", ";", "}", "else", "if", "(", "data", "===", "\"em\"", ")", "{", "ret", ".", "italic", "=", "true", ";", "}", "else", "if", "(", "data", "===", "\"quote\"", ")", "{", "ret", ".", "quote", "=", "true", ";", "}", "else", "if", "(", "data", "===", "\"strikethrough\"", ")", "{", "ret", ".", "strikethrough", "=", "true", ";", "}", "else", "if", "(", "data", "===", "\"comment\"", ")", "{", "ret", ".", "code", "=", "true", ";", "}", "else", "if", "(", "data", "===", "\"link\"", ")", "{", "ret", ".", "link", "=", "true", ";", "}", "else", "if", "(", "data", "===", "\"tag\"", ")", "{", "ret", ".", "image", "=", "true", ";", "}", "else", "if", "(", "data", ".", "match", "(", "/", "^header(\\-[1-6])?$", "/", ")", ")", "{", "ret", "[", "data", ".", "replace", "(", "\"header\"", ",", "\"heading\"", ")", "]", "=", "true", ";", "}", "}", "return", "ret", ";", "}" ]
The state of CodeMirror at the given position.
[ "The", "state", "of", "CodeMirror", "at", "the", "given", "position", "." ]
6abda7ab68cc20f4aca870eb243747951b90ab04
https://github.com/sparksuite/simplemde-markdown-editor/blob/6abda7ab68cc20f4aca870eb243747951b90ab04/src/js/simplemde.js#L140-L179
3,478
sparksuite/simplemde-markdown-editor
src/js/simplemde.js
toggleCodeBlock
function toggleCodeBlock(editor) { var fenceCharsToInsert = editor.options.blockStyles.code; function fencing_line(line) { /* return true, if this is a ``` or ~~~ line */ if(typeof line !== "object") { throw "fencing_line() takes a 'line' object (not a line number, or line text). Got: " + typeof line + ": " + line; } return line.styles && line.styles[2] && line.styles[2].indexOf("formatting-code-block") !== -1; } function token_state(token) { // base goes an extra level deep when mode backdrops are used, e.g. spellchecker on return token.state.base.base || token.state.base; } function code_type(cm, line_num, line, firstTok, lastTok) { /* * Return "single", "indented", "fenced" or false * * cm and line_num are required. Others are optional for efficiency * To check in the middle of a line, pass in firstTok yourself. */ line = line || cm.getLineHandle(line_num); firstTok = firstTok || cm.getTokenAt({ line: line_num, ch: 1 }); lastTok = lastTok || (!!line.text && cm.getTokenAt({ line: line_num, ch: line.text.length - 1 })); var types = firstTok.type ? firstTok.type.split(" ") : []; if(lastTok && token_state(lastTok).indentedCode) { // have to check last char, since first chars of first line aren"t marked as indented return "indented"; } else if(types.indexOf("comment") === -1) { // has to be after "indented" check, since first chars of first indented line aren"t marked as such return false; } else if(token_state(firstTok).fencedChars || token_state(lastTok).fencedChars || fencing_line(line)) { return "fenced"; } else { return "single"; } } function insertFencingAtSelection(cm, cur_start, cur_end, fenceCharsToInsert) { var start_line_sel = cur_start.line + 1, end_line_sel = cur_end.line + 1, sel_multi = cur_start.line !== cur_end.line, repl_start = fenceCharsToInsert + "\n", repl_end = "\n" + fenceCharsToInsert; if(sel_multi) { end_line_sel++; } // handle last char including \n or not if(sel_multi && cur_end.ch === 0) { repl_end = fenceCharsToInsert + "\n"; end_line_sel--; } _replaceSelection(cm, false, [repl_start, repl_end]); cm.setSelection({ line: start_line_sel, ch: 0 }, { line: end_line_sel, ch: 0 }); } var cm = editor.codemirror, cur_start = cm.getCursor("start"), cur_end = cm.getCursor("end"), tok = cm.getTokenAt({ line: cur_start.line, ch: cur_start.ch || 1 }), // avoid ch 0 which is a cursor pos but not token line = cm.getLineHandle(cur_start.line), is_code = code_type(cm, cur_start.line, line, tok); var block_start, block_end, lineCount; if(is_code === "single") { // similar to some SimpleMDE _toggleBlock logic var start = line.text.slice(0, cur_start.ch).replace("`", ""), end = line.text.slice(cur_start.ch).replace("`", ""); cm.replaceRange(start + end, { line: cur_start.line, ch: 0 }, { line: cur_start.line, ch: 99999999999999 }); cur_start.ch--; if(cur_start !== cur_end) { cur_end.ch--; } cm.setSelection(cur_start, cur_end); cm.focus(); } else if(is_code === "fenced") { if(cur_start.line !== cur_end.line || cur_start.ch !== cur_end.ch) { // use selection // find the fenced line so we know what type it is (tilde, backticks, number of them) for(block_start = cur_start.line; block_start >= 0; block_start--) { line = cm.getLineHandle(block_start); if(fencing_line(line)) { break; } } var fencedTok = cm.getTokenAt({ line: block_start, ch: 1 }); var fence_chars = token_state(fencedTok).fencedChars; var start_text, start_line; var end_text, end_line; // check for selection going up against fenced lines, in which case we don't want to add more fencing if(fencing_line(cm.getLineHandle(cur_start.line))) { start_text = ""; start_line = cur_start.line; } else if(fencing_line(cm.getLineHandle(cur_start.line - 1))) { start_text = ""; start_line = cur_start.line - 1; } else { start_text = fence_chars + "\n"; start_line = cur_start.line; } if(fencing_line(cm.getLineHandle(cur_end.line))) { end_text = ""; end_line = cur_end.line; if(cur_end.ch === 0) { end_line += 1; } } else if(cur_end.ch !== 0 && fencing_line(cm.getLineHandle(cur_end.line + 1))) { end_text = ""; end_line = cur_end.line + 1; } else { end_text = fence_chars + "\n"; end_line = cur_end.line + 1; } if(cur_end.ch === 0) { // full last line selected, putting cursor at beginning of next end_line -= 1; } cm.operation(function() { // end line first, so that line numbers don't change cm.replaceRange(end_text, { line: end_line, ch: 0 }, { line: end_line + (end_text ? 0 : 1), ch: 0 }); cm.replaceRange(start_text, { line: start_line, ch: 0 }, { line: start_line + (start_text ? 0 : 1), ch: 0 }); }); cm.setSelection({ line: start_line + (start_text ? 1 : 0), ch: 0 }, { line: end_line + (start_text ? 1 : -1), ch: 0 }); cm.focus(); } else { // no selection, search for ends of this fenced block var search_from = cur_start.line; if(fencing_line(cm.getLineHandle(cur_start.line))) { // gets a little tricky if cursor is right on a fenced line if(code_type(cm, cur_start.line + 1) === "fenced") { block_start = cur_start.line; search_from = cur_start.line + 1; // for searching for "end" } else { block_end = cur_start.line; search_from = cur_start.line - 1; // for searching for "start" } } if(block_start === undefined) { for(block_start = search_from; block_start >= 0; block_start--) { line = cm.getLineHandle(block_start); if(fencing_line(line)) { break; } } } if(block_end === undefined) { lineCount = cm.lineCount(); for(block_end = search_from; block_end < lineCount; block_end++) { line = cm.getLineHandle(block_end); if(fencing_line(line)) { break; } } } cm.operation(function() { cm.replaceRange("", { line: block_start, ch: 0 }, { line: block_start + 1, ch: 0 }); cm.replaceRange("", { line: block_end - 1, ch: 0 }, { line: block_end, ch: 0 }); }); cm.focus(); } } else if(is_code === "indented") { if(cur_start.line !== cur_end.line || cur_start.ch !== cur_end.ch) { // use selection block_start = cur_start.line; block_end = cur_end.line; if(cur_end.ch === 0) { block_end--; } } else { // no selection, search for ends of this indented block for(block_start = cur_start.line; block_start >= 0; block_start--) { line = cm.getLineHandle(block_start); if(line.text.match(/^\s*$/)) { // empty or all whitespace - keep going continue; } else { if(code_type(cm, block_start, line) !== "indented") { block_start += 1; break; } } } lineCount = cm.lineCount(); for(block_end = cur_start.line; block_end < lineCount; block_end++) { line = cm.getLineHandle(block_end); if(line.text.match(/^\s*$/)) { // empty or all whitespace - keep going continue; } else { if(code_type(cm, block_end, line) !== "indented") { block_end -= 1; break; } } } } // if we are going to un-indent based on a selected set of lines, and the next line is indented too, we need to // insert a blank line so that the next line(s) continue to be indented code var next_line = cm.getLineHandle(block_end + 1), next_line_last_tok = next_line && cm.getTokenAt({ line: block_end + 1, ch: next_line.text.length - 1 }), next_line_indented = next_line_last_tok && token_state(next_line_last_tok).indentedCode; if(next_line_indented) { cm.replaceRange("\n", { line: block_end + 1, ch: 0 }); } for(var i = block_start; i <= block_end; i++) { cm.indentLine(i, "subtract"); // TODO: this doesn't get tracked in the history, so can't be undone :( } cm.focus(); } else { // insert code formatting var no_sel_and_starting_of_line = (cur_start.line === cur_end.line && cur_start.ch === cur_end.ch && cur_start.ch === 0); var sel_multi = cur_start.line !== cur_end.line; if(no_sel_and_starting_of_line || sel_multi) { insertFencingAtSelection(cm, cur_start, cur_end, fenceCharsToInsert); } else { _replaceSelection(cm, false, ["`", "`"]); } } }
javascript
function toggleCodeBlock(editor) { var fenceCharsToInsert = editor.options.blockStyles.code; function fencing_line(line) { /* return true, if this is a ``` or ~~~ line */ if(typeof line !== "object") { throw "fencing_line() takes a 'line' object (not a line number, or line text). Got: " + typeof line + ": " + line; } return line.styles && line.styles[2] && line.styles[2].indexOf("formatting-code-block") !== -1; } function token_state(token) { // base goes an extra level deep when mode backdrops are used, e.g. spellchecker on return token.state.base.base || token.state.base; } function code_type(cm, line_num, line, firstTok, lastTok) { /* * Return "single", "indented", "fenced" or false * * cm and line_num are required. Others are optional for efficiency * To check in the middle of a line, pass in firstTok yourself. */ line = line || cm.getLineHandle(line_num); firstTok = firstTok || cm.getTokenAt({ line: line_num, ch: 1 }); lastTok = lastTok || (!!line.text && cm.getTokenAt({ line: line_num, ch: line.text.length - 1 })); var types = firstTok.type ? firstTok.type.split(" ") : []; if(lastTok && token_state(lastTok).indentedCode) { // have to check last char, since first chars of first line aren"t marked as indented return "indented"; } else if(types.indexOf("comment") === -1) { // has to be after "indented" check, since first chars of first indented line aren"t marked as such return false; } else if(token_state(firstTok).fencedChars || token_state(lastTok).fencedChars || fencing_line(line)) { return "fenced"; } else { return "single"; } } function insertFencingAtSelection(cm, cur_start, cur_end, fenceCharsToInsert) { var start_line_sel = cur_start.line + 1, end_line_sel = cur_end.line + 1, sel_multi = cur_start.line !== cur_end.line, repl_start = fenceCharsToInsert + "\n", repl_end = "\n" + fenceCharsToInsert; if(sel_multi) { end_line_sel++; } // handle last char including \n or not if(sel_multi && cur_end.ch === 0) { repl_end = fenceCharsToInsert + "\n"; end_line_sel--; } _replaceSelection(cm, false, [repl_start, repl_end]); cm.setSelection({ line: start_line_sel, ch: 0 }, { line: end_line_sel, ch: 0 }); } var cm = editor.codemirror, cur_start = cm.getCursor("start"), cur_end = cm.getCursor("end"), tok = cm.getTokenAt({ line: cur_start.line, ch: cur_start.ch || 1 }), // avoid ch 0 which is a cursor pos but not token line = cm.getLineHandle(cur_start.line), is_code = code_type(cm, cur_start.line, line, tok); var block_start, block_end, lineCount; if(is_code === "single") { // similar to some SimpleMDE _toggleBlock logic var start = line.text.slice(0, cur_start.ch).replace("`", ""), end = line.text.slice(cur_start.ch).replace("`", ""); cm.replaceRange(start + end, { line: cur_start.line, ch: 0 }, { line: cur_start.line, ch: 99999999999999 }); cur_start.ch--; if(cur_start !== cur_end) { cur_end.ch--; } cm.setSelection(cur_start, cur_end); cm.focus(); } else if(is_code === "fenced") { if(cur_start.line !== cur_end.line || cur_start.ch !== cur_end.ch) { // use selection // find the fenced line so we know what type it is (tilde, backticks, number of them) for(block_start = cur_start.line; block_start >= 0; block_start--) { line = cm.getLineHandle(block_start); if(fencing_line(line)) { break; } } var fencedTok = cm.getTokenAt({ line: block_start, ch: 1 }); var fence_chars = token_state(fencedTok).fencedChars; var start_text, start_line; var end_text, end_line; // check for selection going up against fenced lines, in which case we don't want to add more fencing if(fencing_line(cm.getLineHandle(cur_start.line))) { start_text = ""; start_line = cur_start.line; } else if(fencing_line(cm.getLineHandle(cur_start.line - 1))) { start_text = ""; start_line = cur_start.line - 1; } else { start_text = fence_chars + "\n"; start_line = cur_start.line; } if(fencing_line(cm.getLineHandle(cur_end.line))) { end_text = ""; end_line = cur_end.line; if(cur_end.ch === 0) { end_line += 1; } } else if(cur_end.ch !== 0 && fencing_line(cm.getLineHandle(cur_end.line + 1))) { end_text = ""; end_line = cur_end.line + 1; } else { end_text = fence_chars + "\n"; end_line = cur_end.line + 1; } if(cur_end.ch === 0) { // full last line selected, putting cursor at beginning of next end_line -= 1; } cm.operation(function() { // end line first, so that line numbers don't change cm.replaceRange(end_text, { line: end_line, ch: 0 }, { line: end_line + (end_text ? 0 : 1), ch: 0 }); cm.replaceRange(start_text, { line: start_line, ch: 0 }, { line: start_line + (start_text ? 0 : 1), ch: 0 }); }); cm.setSelection({ line: start_line + (start_text ? 1 : 0), ch: 0 }, { line: end_line + (start_text ? 1 : -1), ch: 0 }); cm.focus(); } else { // no selection, search for ends of this fenced block var search_from = cur_start.line; if(fencing_line(cm.getLineHandle(cur_start.line))) { // gets a little tricky if cursor is right on a fenced line if(code_type(cm, cur_start.line + 1) === "fenced") { block_start = cur_start.line; search_from = cur_start.line + 1; // for searching for "end" } else { block_end = cur_start.line; search_from = cur_start.line - 1; // for searching for "start" } } if(block_start === undefined) { for(block_start = search_from; block_start >= 0; block_start--) { line = cm.getLineHandle(block_start); if(fencing_line(line)) { break; } } } if(block_end === undefined) { lineCount = cm.lineCount(); for(block_end = search_from; block_end < lineCount; block_end++) { line = cm.getLineHandle(block_end); if(fencing_line(line)) { break; } } } cm.operation(function() { cm.replaceRange("", { line: block_start, ch: 0 }, { line: block_start + 1, ch: 0 }); cm.replaceRange("", { line: block_end - 1, ch: 0 }, { line: block_end, ch: 0 }); }); cm.focus(); } } else if(is_code === "indented") { if(cur_start.line !== cur_end.line || cur_start.ch !== cur_end.ch) { // use selection block_start = cur_start.line; block_end = cur_end.line; if(cur_end.ch === 0) { block_end--; } } else { // no selection, search for ends of this indented block for(block_start = cur_start.line; block_start >= 0; block_start--) { line = cm.getLineHandle(block_start); if(line.text.match(/^\s*$/)) { // empty or all whitespace - keep going continue; } else { if(code_type(cm, block_start, line) !== "indented") { block_start += 1; break; } } } lineCount = cm.lineCount(); for(block_end = cur_start.line; block_end < lineCount; block_end++) { line = cm.getLineHandle(block_end); if(line.text.match(/^\s*$/)) { // empty or all whitespace - keep going continue; } else { if(code_type(cm, block_end, line) !== "indented") { block_end -= 1; break; } } } } // if we are going to un-indent based on a selected set of lines, and the next line is indented too, we need to // insert a blank line so that the next line(s) continue to be indented code var next_line = cm.getLineHandle(block_end + 1), next_line_last_tok = next_line && cm.getTokenAt({ line: block_end + 1, ch: next_line.text.length - 1 }), next_line_indented = next_line_last_tok && token_state(next_line_last_tok).indentedCode; if(next_line_indented) { cm.replaceRange("\n", { line: block_end + 1, ch: 0 }); } for(var i = block_start; i <= block_end; i++) { cm.indentLine(i, "subtract"); // TODO: this doesn't get tracked in the history, so can't be undone :( } cm.focus(); } else { // insert code formatting var no_sel_and_starting_of_line = (cur_start.line === cur_end.line && cur_start.ch === cur_end.ch && cur_start.ch === 0); var sel_multi = cur_start.line !== cur_end.line; if(no_sel_and_starting_of_line || sel_multi) { insertFencingAtSelection(cm, cur_start, cur_end, fenceCharsToInsert); } else { _replaceSelection(cm, false, ["`", "`"]); } } }
[ "function", "toggleCodeBlock", "(", "editor", ")", "{", "var", "fenceCharsToInsert", "=", "editor", ".", "options", ".", "blockStyles", ".", "code", ";", "function", "fencing_line", "(", "line", ")", "{", "/* return true, if this is a ``` or ~~~ line */", "if", "(", "typeof", "line", "!==", "\"object\"", ")", "{", "throw", "\"fencing_line() takes a 'line' object (not a line number, or line text). Got: \"", "+", "typeof", "line", "+", "\": \"", "+", "line", ";", "}", "return", "line", ".", "styles", "&&", "line", ".", "styles", "[", "2", "]", "&&", "line", ".", "styles", "[", "2", "]", ".", "indexOf", "(", "\"formatting-code-block\"", ")", "!==", "-", "1", ";", "}", "function", "token_state", "(", "token", ")", "{", "// base goes an extra level deep when mode backdrops are used, e.g. spellchecker on", "return", "token", ".", "state", ".", "base", ".", "base", "||", "token", ".", "state", ".", "base", ";", "}", "function", "code_type", "(", "cm", ",", "line_num", ",", "line", ",", "firstTok", ",", "lastTok", ")", "{", "/*\n\t\t * Return \"single\", \"indented\", \"fenced\" or false\n\t\t *\n\t\t * cm and line_num are required. Others are optional for efficiency\n\t\t * To check in the middle of a line, pass in firstTok yourself.\n\t\t */", "line", "=", "line", "||", "cm", ".", "getLineHandle", "(", "line_num", ")", ";", "firstTok", "=", "firstTok", "||", "cm", ".", "getTokenAt", "(", "{", "line", ":", "line_num", ",", "ch", ":", "1", "}", ")", ";", "lastTok", "=", "lastTok", "||", "(", "!", "!", "line", ".", "text", "&&", "cm", ".", "getTokenAt", "(", "{", "line", ":", "line_num", ",", "ch", ":", "line", ".", "text", ".", "length", "-", "1", "}", ")", ")", ";", "var", "types", "=", "firstTok", ".", "type", "?", "firstTok", ".", "type", ".", "split", "(", "\" \"", ")", ":", "[", "]", ";", "if", "(", "lastTok", "&&", "token_state", "(", "lastTok", ")", ".", "indentedCode", ")", "{", "// have to check last char, since first chars of first line aren\"t marked as indented", "return", "\"indented\"", ";", "}", "else", "if", "(", "types", ".", "indexOf", "(", "\"comment\"", ")", "===", "-", "1", ")", "{", "// has to be after \"indented\" check, since first chars of first indented line aren\"t marked as such", "return", "false", ";", "}", "else", "if", "(", "token_state", "(", "firstTok", ")", ".", "fencedChars", "||", "token_state", "(", "lastTok", ")", ".", "fencedChars", "||", "fencing_line", "(", "line", ")", ")", "{", "return", "\"fenced\"", ";", "}", "else", "{", "return", "\"single\"", ";", "}", "}", "function", "insertFencingAtSelection", "(", "cm", ",", "cur_start", ",", "cur_end", ",", "fenceCharsToInsert", ")", "{", "var", "start_line_sel", "=", "cur_start", ".", "line", "+", "1", ",", "end_line_sel", "=", "cur_end", ".", "line", "+", "1", ",", "sel_multi", "=", "cur_start", ".", "line", "!==", "cur_end", ".", "line", ",", "repl_start", "=", "fenceCharsToInsert", "+", "\"\\n\"", ",", "repl_end", "=", "\"\\n\"", "+", "fenceCharsToInsert", ";", "if", "(", "sel_multi", ")", "{", "end_line_sel", "++", ";", "}", "// handle last char including \\n or not", "if", "(", "sel_multi", "&&", "cur_end", ".", "ch", "===", "0", ")", "{", "repl_end", "=", "fenceCharsToInsert", "+", "\"\\n\"", ";", "end_line_sel", "--", ";", "}", "_replaceSelection", "(", "cm", ",", "false", ",", "[", "repl_start", ",", "repl_end", "]", ")", ";", "cm", ".", "setSelection", "(", "{", "line", ":", "start_line_sel", ",", "ch", ":", "0", "}", ",", "{", "line", ":", "end_line_sel", ",", "ch", ":", "0", "}", ")", ";", "}", "var", "cm", "=", "editor", ".", "codemirror", ",", "cur_start", "=", "cm", ".", "getCursor", "(", "\"start\"", ")", ",", "cur_end", "=", "cm", ".", "getCursor", "(", "\"end\"", ")", ",", "tok", "=", "cm", ".", "getTokenAt", "(", "{", "line", ":", "cur_start", ".", "line", ",", "ch", ":", "cur_start", ".", "ch", "||", "1", "}", ")", ",", "// avoid ch 0 which is a cursor pos but not token", "line", "=", "cm", ".", "getLineHandle", "(", "cur_start", ".", "line", ")", ",", "is_code", "=", "code_type", "(", "cm", ",", "cur_start", ".", "line", ",", "line", ",", "tok", ")", ";", "var", "block_start", ",", "block_end", ",", "lineCount", ";", "if", "(", "is_code", "===", "\"single\"", ")", "{", "// similar to some SimpleMDE _toggleBlock logic", "var", "start", "=", "line", ".", "text", ".", "slice", "(", "0", ",", "cur_start", ".", "ch", ")", ".", "replace", "(", "\"`\"", ",", "\"\"", ")", ",", "end", "=", "line", ".", "text", ".", "slice", "(", "cur_start", ".", "ch", ")", ".", "replace", "(", "\"`\"", ",", "\"\"", ")", ";", "cm", ".", "replaceRange", "(", "start", "+", "end", ",", "{", "line", ":", "cur_start", ".", "line", ",", "ch", ":", "0", "}", ",", "{", "line", ":", "cur_start", ".", "line", ",", "ch", ":", "99999999999999", "}", ")", ";", "cur_start", ".", "ch", "--", ";", "if", "(", "cur_start", "!==", "cur_end", ")", "{", "cur_end", ".", "ch", "--", ";", "}", "cm", ".", "setSelection", "(", "cur_start", ",", "cur_end", ")", ";", "cm", ".", "focus", "(", ")", ";", "}", "else", "if", "(", "is_code", "===", "\"fenced\"", ")", "{", "if", "(", "cur_start", ".", "line", "!==", "cur_end", ".", "line", "||", "cur_start", ".", "ch", "!==", "cur_end", ".", "ch", ")", "{", "// use selection", "// find the fenced line so we know what type it is (tilde, backticks, number of them)", "for", "(", "block_start", "=", "cur_start", ".", "line", ";", "block_start", ">=", "0", ";", "block_start", "--", ")", "{", "line", "=", "cm", ".", "getLineHandle", "(", "block_start", ")", ";", "if", "(", "fencing_line", "(", "line", ")", ")", "{", "break", ";", "}", "}", "var", "fencedTok", "=", "cm", ".", "getTokenAt", "(", "{", "line", ":", "block_start", ",", "ch", ":", "1", "}", ")", ";", "var", "fence_chars", "=", "token_state", "(", "fencedTok", ")", ".", "fencedChars", ";", "var", "start_text", ",", "start_line", ";", "var", "end_text", ",", "end_line", ";", "// check for selection going up against fenced lines, in which case we don't want to add more fencing", "if", "(", "fencing_line", "(", "cm", ".", "getLineHandle", "(", "cur_start", ".", "line", ")", ")", ")", "{", "start_text", "=", "\"\"", ";", "start_line", "=", "cur_start", ".", "line", ";", "}", "else", "if", "(", "fencing_line", "(", "cm", ".", "getLineHandle", "(", "cur_start", ".", "line", "-", "1", ")", ")", ")", "{", "start_text", "=", "\"\"", ";", "start_line", "=", "cur_start", ".", "line", "-", "1", ";", "}", "else", "{", "start_text", "=", "fence_chars", "+", "\"\\n\"", ";", "start_line", "=", "cur_start", ".", "line", ";", "}", "if", "(", "fencing_line", "(", "cm", ".", "getLineHandle", "(", "cur_end", ".", "line", ")", ")", ")", "{", "end_text", "=", "\"\"", ";", "end_line", "=", "cur_end", ".", "line", ";", "if", "(", "cur_end", ".", "ch", "===", "0", ")", "{", "end_line", "+=", "1", ";", "}", "}", "else", "if", "(", "cur_end", ".", "ch", "!==", "0", "&&", "fencing_line", "(", "cm", ".", "getLineHandle", "(", "cur_end", ".", "line", "+", "1", ")", ")", ")", "{", "end_text", "=", "\"\"", ";", "end_line", "=", "cur_end", ".", "line", "+", "1", ";", "}", "else", "{", "end_text", "=", "fence_chars", "+", "\"\\n\"", ";", "end_line", "=", "cur_end", ".", "line", "+", "1", ";", "}", "if", "(", "cur_end", ".", "ch", "===", "0", ")", "{", "// full last line selected, putting cursor at beginning of next", "end_line", "-=", "1", ";", "}", "cm", ".", "operation", "(", "function", "(", ")", "{", "// end line first, so that line numbers don't change", "cm", ".", "replaceRange", "(", "end_text", ",", "{", "line", ":", "end_line", ",", "ch", ":", "0", "}", ",", "{", "line", ":", "end_line", "+", "(", "end_text", "?", "0", ":", "1", ")", ",", "ch", ":", "0", "}", ")", ";", "cm", ".", "replaceRange", "(", "start_text", ",", "{", "line", ":", "start_line", ",", "ch", ":", "0", "}", ",", "{", "line", ":", "start_line", "+", "(", "start_text", "?", "0", ":", "1", ")", ",", "ch", ":", "0", "}", ")", ";", "}", ")", ";", "cm", ".", "setSelection", "(", "{", "line", ":", "start_line", "+", "(", "start_text", "?", "1", ":", "0", ")", ",", "ch", ":", "0", "}", ",", "{", "line", ":", "end_line", "+", "(", "start_text", "?", "1", ":", "-", "1", ")", ",", "ch", ":", "0", "}", ")", ";", "cm", ".", "focus", "(", ")", ";", "}", "else", "{", "// no selection, search for ends of this fenced block", "var", "search_from", "=", "cur_start", ".", "line", ";", "if", "(", "fencing_line", "(", "cm", ".", "getLineHandle", "(", "cur_start", ".", "line", ")", ")", ")", "{", "// gets a little tricky if cursor is right on a fenced line", "if", "(", "code_type", "(", "cm", ",", "cur_start", ".", "line", "+", "1", ")", "===", "\"fenced\"", ")", "{", "block_start", "=", "cur_start", ".", "line", ";", "search_from", "=", "cur_start", ".", "line", "+", "1", ";", "// for searching for \"end\"", "}", "else", "{", "block_end", "=", "cur_start", ".", "line", ";", "search_from", "=", "cur_start", ".", "line", "-", "1", ";", "// for searching for \"start\"", "}", "}", "if", "(", "block_start", "===", "undefined", ")", "{", "for", "(", "block_start", "=", "search_from", ";", "block_start", ">=", "0", ";", "block_start", "--", ")", "{", "line", "=", "cm", ".", "getLineHandle", "(", "block_start", ")", ";", "if", "(", "fencing_line", "(", "line", ")", ")", "{", "break", ";", "}", "}", "}", "if", "(", "block_end", "===", "undefined", ")", "{", "lineCount", "=", "cm", ".", "lineCount", "(", ")", ";", "for", "(", "block_end", "=", "search_from", ";", "block_end", "<", "lineCount", ";", "block_end", "++", ")", "{", "line", "=", "cm", ".", "getLineHandle", "(", "block_end", ")", ";", "if", "(", "fencing_line", "(", "line", ")", ")", "{", "break", ";", "}", "}", "}", "cm", ".", "operation", "(", "function", "(", ")", "{", "cm", ".", "replaceRange", "(", "\"\"", ",", "{", "line", ":", "block_start", ",", "ch", ":", "0", "}", ",", "{", "line", ":", "block_start", "+", "1", ",", "ch", ":", "0", "}", ")", ";", "cm", ".", "replaceRange", "(", "\"\"", ",", "{", "line", ":", "block_end", "-", "1", ",", "ch", ":", "0", "}", ",", "{", "line", ":", "block_end", ",", "ch", ":", "0", "}", ")", ";", "}", ")", ";", "cm", ".", "focus", "(", ")", ";", "}", "}", "else", "if", "(", "is_code", "===", "\"indented\"", ")", "{", "if", "(", "cur_start", ".", "line", "!==", "cur_end", ".", "line", "||", "cur_start", ".", "ch", "!==", "cur_end", ".", "ch", ")", "{", "// use selection", "block_start", "=", "cur_start", ".", "line", ";", "block_end", "=", "cur_end", ".", "line", ";", "if", "(", "cur_end", ".", "ch", "===", "0", ")", "{", "block_end", "--", ";", "}", "}", "else", "{", "// no selection, search for ends of this indented block", "for", "(", "block_start", "=", "cur_start", ".", "line", ";", "block_start", ">=", "0", ";", "block_start", "--", ")", "{", "line", "=", "cm", ".", "getLineHandle", "(", "block_start", ")", ";", "if", "(", "line", ".", "text", ".", "match", "(", "/", "^\\s*$", "/", ")", ")", "{", "// empty or all whitespace - keep going", "continue", ";", "}", "else", "{", "if", "(", "code_type", "(", "cm", ",", "block_start", ",", "line", ")", "!==", "\"indented\"", ")", "{", "block_start", "+=", "1", ";", "break", ";", "}", "}", "}", "lineCount", "=", "cm", ".", "lineCount", "(", ")", ";", "for", "(", "block_end", "=", "cur_start", ".", "line", ";", "block_end", "<", "lineCount", ";", "block_end", "++", ")", "{", "line", "=", "cm", ".", "getLineHandle", "(", "block_end", ")", ";", "if", "(", "line", ".", "text", ".", "match", "(", "/", "^\\s*$", "/", ")", ")", "{", "// empty or all whitespace - keep going", "continue", ";", "}", "else", "{", "if", "(", "code_type", "(", "cm", ",", "block_end", ",", "line", ")", "!==", "\"indented\"", ")", "{", "block_end", "-=", "1", ";", "break", ";", "}", "}", "}", "}", "// if we are going to un-indent based on a selected set of lines, and the next line is indented too, we need to", "// insert a blank line so that the next line(s) continue to be indented code", "var", "next_line", "=", "cm", ".", "getLineHandle", "(", "block_end", "+", "1", ")", ",", "next_line_last_tok", "=", "next_line", "&&", "cm", ".", "getTokenAt", "(", "{", "line", ":", "block_end", "+", "1", ",", "ch", ":", "next_line", ".", "text", ".", "length", "-", "1", "}", ")", ",", "next_line_indented", "=", "next_line_last_tok", "&&", "token_state", "(", "next_line_last_tok", ")", ".", "indentedCode", ";", "if", "(", "next_line_indented", ")", "{", "cm", ".", "replaceRange", "(", "\"\\n\"", ",", "{", "line", ":", "block_end", "+", "1", ",", "ch", ":", "0", "}", ")", ";", "}", "for", "(", "var", "i", "=", "block_start", ";", "i", "<=", "block_end", ";", "i", "++", ")", "{", "cm", ".", "indentLine", "(", "i", ",", "\"subtract\"", ")", ";", "// TODO: this doesn't get tracked in the history, so can't be undone :(", "}", "cm", ".", "focus", "(", ")", ";", "}", "else", "{", "// insert code formatting", "var", "no_sel_and_starting_of_line", "=", "(", "cur_start", ".", "line", "===", "cur_end", ".", "line", "&&", "cur_start", ".", "ch", "===", "cur_end", ".", "ch", "&&", "cur_start", ".", "ch", "===", "0", ")", ";", "var", "sel_multi", "=", "cur_start", ".", "line", "!==", "cur_end", ".", "line", ";", "if", "(", "no_sel_and_starting_of_line", "||", "sel_multi", ")", "{", "insertFencingAtSelection", "(", "cm", ",", "cur_start", ",", "cur_end", ",", "fenceCharsToInsert", ")", ";", "}", "else", "{", "_replaceSelection", "(", "cm", ",", "false", ",", "[", "\"`\"", ",", "\"`\"", "]", ")", ";", "}", "}", "}" ]
Action for toggling code block.
[ "Action", "for", "toggling", "code", "block", "." ]
6abda7ab68cc20f4aca870eb243747951b90ab04
https://github.com/sparksuite/simplemde-markdown-editor/blob/6abda7ab68cc20f4aca870eb243747951b90ab04/src/js/simplemde.js#L256-L537
3,479
sparksuite/simplemde-markdown-editor
src/js/simplemde.js
drawLink
function drawLink(editor) { var cm = editor.codemirror; var stat = getState(cm); var options = editor.options; var url = "http://"; if(options.promptURLs) { url = prompt(options.promptTexts.link); if(!url) { return false; } } _replaceSelection(cm, stat.link, options.insertTexts.link, url); }
javascript
function drawLink(editor) { var cm = editor.codemirror; var stat = getState(cm); var options = editor.options; var url = "http://"; if(options.promptURLs) { url = prompt(options.promptTexts.link); if(!url) { return false; } } _replaceSelection(cm, stat.link, options.insertTexts.link, url); }
[ "function", "drawLink", "(", "editor", ")", "{", "var", "cm", "=", "editor", ".", "codemirror", ";", "var", "stat", "=", "getState", "(", "cm", ")", ";", "var", "options", "=", "editor", ".", "options", ";", "var", "url", "=", "\"http://\"", ";", "if", "(", "options", ".", "promptURLs", ")", "{", "url", "=", "prompt", "(", "options", ".", "promptTexts", ".", "link", ")", ";", "if", "(", "!", "url", ")", "{", "return", "false", ";", "}", "}", "_replaceSelection", "(", "cm", ",", "stat", ".", "link", ",", "options", ".", "insertTexts", ".", "link", ",", "url", ")", ";", "}" ]
Action for drawing a link.
[ "Action", "for", "drawing", "a", "link", "." ]
6abda7ab68cc20f4aca870eb243747951b90ab04
https://github.com/sparksuite/simplemde-markdown-editor/blob/6abda7ab68cc20f4aca870eb243747951b90ab04/src/js/simplemde.js#L616-L628
3,480
sparksuite/simplemde-markdown-editor
src/js/simplemde.js
drawImage
function drawImage(editor) { var cm = editor.codemirror; var stat = getState(cm); var options = editor.options; var url = "http://"; if(options.promptURLs) { url = prompt(options.promptTexts.image); if(!url) { return false; } } _replaceSelection(cm, stat.image, options.insertTexts.image, url); }
javascript
function drawImage(editor) { var cm = editor.codemirror; var stat = getState(cm); var options = editor.options; var url = "http://"; if(options.promptURLs) { url = prompt(options.promptTexts.image); if(!url) { return false; } } _replaceSelection(cm, stat.image, options.insertTexts.image, url); }
[ "function", "drawImage", "(", "editor", ")", "{", "var", "cm", "=", "editor", ".", "codemirror", ";", "var", "stat", "=", "getState", "(", "cm", ")", ";", "var", "options", "=", "editor", ".", "options", ";", "var", "url", "=", "\"http://\"", ";", "if", "(", "options", ".", "promptURLs", ")", "{", "url", "=", "prompt", "(", "options", ".", "promptTexts", ".", "image", ")", ";", "if", "(", "!", "url", ")", "{", "return", "false", ";", "}", "}", "_replaceSelection", "(", "cm", ",", "stat", ".", "image", ",", "options", ".", "insertTexts", ".", "image", ",", "url", ")", ";", "}" ]
Action for drawing an img.
[ "Action", "for", "drawing", "an", "img", "." ]
6abda7ab68cc20f4aca870eb243747951b90ab04
https://github.com/sparksuite/simplemde-markdown-editor/blob/6abda7ab68cc20f4aca870eb243747951b90ab04/src/js/simplemde.js#L633-L645
3,481
sparksuite/simplemde-markdown-editor
src/js/simplemde.js
drawTable
function drawTable(editor) { var cm = editor.codemirror; var stat = getState(cm); var options = editor.options; _replaceSelection(cm, stat.table, options.insertTexts.table); }
javascript
function drawTable(editor) { var cm = editor.codemirror; var stat = getState(cm); var options = editor.options; _replaceSelection(cm, stat.table, options.insertTexts.table); }
[ "function", "drawTable", "(", "editor", ")", "{", "var", "cm", "=", "editor", ".", "codemirror", ";", "var", "stat", "=", "getState", "(", "cm", ")", ";", "var", "options", "=", "editor", ".", "options", ";", "_replaceSelection", "(", "cm", ",", "stat", ".", "table", ",", "options", ".", "insertTexts", ".", "table", ")", ";", "}" ]
Action for drawing a table.
[ "Action", "for", "drawing", "a", "table", "." ]
6abda7ab68cc20f4aca870eb243747951b90ab04
https://github.com/sparksuite/simplemde-markdown-editor/blob/6abda7ab68cc20f4aca870eb243747951b90ab04/src/js/simplemde.js#L650-L655
3,482
sparksuite/simplemde-markdown-editor
src/js/simplemde.js
drawHorizontalRule
function drawHorizontalRule(editor) { var cm = editor.codemirror; var stat = getState(cm); var options = editor.options; _replaceSelection(cm, stat.image, options.insertTexts.horizontalRule); }
javascript
function drawHorizontalRule(editor) { var cm = editor.codemirror; var stat = getState(cm); var options = editor.options; _replaceSelection(cm, stat.image, options.insertTexts.horizontalRule); }
[ "function", "drawHorizontalRule", "(", "editor", ")", "{", "var", "cm", "=", "editor", ".", "codemirror", ";", "var", "stat", "=", "getState", "(", "cm", ")", ";", "var", "options", "=", "editor", ".", "options", ";", "_replaceSelection", "(", "cm", ",", "stat", ".", "image", ",", "options", ".", "insertTexts", ".", "horizontalRule", ")", ";", "}" ]
Action for drawing a horizontal rule.
[ "Action", "for", "drawing", "a", "horizontal", "rule", "." ]
6abda7ab68cc20f4aca870eb243747951b90ab04
https://github.com/sparksuite/simplemde-markdown-editor/blob/6abda7ab68cc20f4aca870eb243747951b90ab04/src/js/simplemde.js#L660-L665
3,483
sparksuite/simplemde-markdown-editor
src/js/simplemde.js
togglePreview
function togglePreview(editor) { var cm = editor.codemirror; var wrapper = cm.getWrapperElement(); var toolbar_div = wrapper.previousSibling; var toolbar = editor.options.toolbar ? editor.toolbarElements.preview : false; var preview = wrapper.lastChild; if(!preview || !/editor-preview/.test(preview.className)) { preview = document.createElement("div"); preview.className = "editor-preview"; wrapper.appendChild(preview); } if(/editor-preview-active/.test(preview.className)) { preview.className = preview.className.replace( /\s*editor-preview-active\s*/g, "" ); if(toolbar) { toolbar.className = toolbar.className.replace(/\s*active\s*/g, ""); toolbar_div.className = toolbar_div.className.replace(/\s*disabled-for-preview*/g, ""); } } else { // When the preview button is clicked for the first time, // give some time for the transition from editor.css to fire and the view to slide from right to left, // instead of just appearing. setTimeout(function() { preview.className += " editor-preview-active"; }, 1); if(toolbar) { toolbar.className += " active"; toolbar_div.className += " disabled-for-preview"; } } preview.innerHTML = editor.options.previewRender(editor.value(), preview); // Turn off side by side if needed var sidebyside = cm.getWrapperElement().nextSibling; if(/editor-preview-active-side/.test(sidebyside.className)) toggleSideBySide(editor); }
javascript
function togglePreview(editor) { var cm = editor.codemirror; var wrapper = cm.getWrapperElement(); var toolbar_div = wrapper.previousSibling; var toolbar = editor.options.toolbar ? editor.toolbarElements.preview : false; var preview = wrapper.lastChild; if(!preview || !/editor-preview/.test(preview.className)) { preview = document.createElement("div"); preview.className = "editor-preview"; wrapper.appendChild(preview); } if(/editor-preview-active/.test(preview.className)) { preview.className = preview.className.replace( /\s*editor-preview-active\s*/g, "" ); if(toolbar) { toolbar.className = toolbar.className.replace(/\s*active\s*/g, ""); toolbar_div.className = toolbar_div.className.replace(/\s*disabled-for-preview*/g, ""); } } else { // When the preview button is clicked for the first time, // give some time for the transition from editor.css to fire and the view to slide from right to left, // instead of just appearing. setTimeout(function() { preview.className += " editor-preview-active"; }, 1); if(toolbar) { toolbar.className += " active"; toolbar_div.className += " disabled-for-preview"; } } preview.innerHTML = editor.options.previewRender(editor.value(), preview); // Turn off side by side if needed var sidebyside = cm.getWrapperElement().nextSibling; if(/editor-preview-active-side/.test(sidebyside.className)) toggleSideBySide(editor); }
[ "function", "togglePreview", "(", "editor", ")", "{", "var", "cm", "=", "editor", ".", "codemirror", ";", "var", "wrapper", "=", "cm", ".", "getWrapperElement", "(", ")", ";", "var", "toolbar_div", "=", "wrapper", ".", "previousSibling", ";", "var", "toolbar", "=", "editor", ".", "options", ".", "toolbar", "?", "editor", ".", "toolbarElements", ".", "preview", ":", "false", ";", "var", "preview", "=", "wrapper", ".", "lastChild", ";", "if", "(", "!", "preview", "||", "!", "/", "editor-preview", "/", ".", "test", "(", "preview", ".", "className", ")", ")", "{", "preview", "=", "document", ".", "createElement", "(", "\"div\"", ")", ";", "preview", ".", "className", "=", "\"editor-preview\"", ";", "wrapper", ".", "appendChild", "(", "preview", ")", ";", "}", "if", "(", "/", "editor-preview-active", "/", ".", "test", "(", "preview", ".", "className", ")", ")", "{", "preview", ".", "className", "=", "preview", ".", "className", ".", "replace", "(", "/", "\\s*editor-preview-active\\s*", "/", "g", ",", "\"\"", ")", ";", "if", "(", "toolbar", ")", "{", "toolbar", ".", "className", "=", "toolbar", ".", "className", ".", "replace", "(", "/", "\\s*active\\s*", "/", "g", ",", "\"\"", ")", ";", "toolbar_div", ".", "className", "=", "toolbar_div", ".", "className", ".", "replace", "(", "/", "\\s*disabled-for-preview*", "/", "g", ",", "\"\"", ")", ";", "}", "}", "else", "{", "// When the preview button is clicked for the first time,", "// give some time for the transition from editor.css to fire and the view to slide from right to left,", "// instead of just appearing.", "setTimeout", "(", "function", "(", ")", "{", "preview", ".", "className", "+=", "\" editor-preview-active\"", ";", "}", ",", "1", ")", ";", "if", "(", "toolbar", ")", "{", "toolbar", ".", "className", "+=", "\" active\"", ";", "toolbar_div", ".", "className", "+=", "\" disabled-for-preview\"", ";", "}", "}", "preview", ".", "innerHTML", "=", "editor", ".", "options", ".", "previewRender", "(", "editor", ".", "value", "(", ")", ",", "preview", ")", ";", "// Turn off side by side if needed", "var", "sidebyside", "=", "cm", ".", "getWrapperElement", "(", ")", ".", "nextSibling", ";", "if", "(", "/", "editor-preview-active-side", "/", ".", "test", "(", "sidebyside", ".", "className", ")", ")", "toggleSideBySide", "(", "editor", ")", ";", "}" ]
Preview action.
[ "Preview", "action", "." ]
6abda7ab68cc20f4aca870eb243747951b90ab04
https://github.com/sparksuite/simplemde-markdown-editor/blob/6abda7ab68cc20f4aca870eb243747951b90ab04/src/js/simplemde.js#L752-L789
3,484
sparksuite/simplemde-markdown-editor
src/js/simplemde.js
_mergeProperties
function _mergeProperties(target, source) { for(var property in source) { if(source.hasOwnProperty(property)) { if(source[property] instanceof Array) { target[property] = source[property].concat(target[property] instanceof Array ? target[property] : []); } else if( source[property] !== null && typeof source[property] === "object" && source[property].constructor === Object ) { target[property] = _mergeProperties(target[property] || {}, source[property]); } else { target[property] = source[property]; } } } return target; }
javascript
function _mergeProperties(target, source) { for(var property in source) { if(source.hasOwnProperty(property)) { if(source[property] instanceof Array) { target[property] = source[property].concat(target[property] instanceof Array ? target[property] : []); } else if( source[property] !== null && typeof source[property] === "object" && source[property].constructor === Object ) { target[property] = _mergeProperties(target[property] || {}, source[property]); } else { target[property] = source[property]; } } } return target; }
[ "function", "_mergeProperties", "(", "target", ",", "source", ")", "{", "for", "(", "var", "property", "in", "source", ")", "{", "if", "(", "source", ".", "hasOwnProperty", "(", "property", ")", ")", "{", "if", "(", "source", "[", "property", "]", "instanceof", "Array", ")", "{", "target", "[", "property", "]", "=", "source", "[", "property", "]", ".", "concat", "(", "target", "[", "property", "]", "instanceof", "Array", "?", "target", "[", "property", "]", ":", "[", "]", ")", ";", "}", "else", "if", "(", "source", "[", "property", "]", "!==", "null", "&&", "typeof", "source", "[", "property", "]", "===", "\"object\"", "&&", "source", "[", "property", "]", ".", "constructor", "===", "Object", ")", "{", "target", "[", "property", "]", "=", "_mergeProperties", "(", "target", "[", "property", "]", "||", "{", "}", ",", "source", "[", "property", "]", ")", ";", "}", "else", "{", "target", "[", "property", "]", "=", "source", "[", "property", "]", ";", "}", "}", "}", "return", "target", ";", "}" ]
Merge the properties of one object into another.
[ "Merge", "the", "properties", "of", "one", "object", "into", "another", "." ]
6abda7ab68cc20f4aca870eb243747951b90ab04
https://github.com/sparksuite/simplemde-markdown-editor/blob/6abda7ab68cc20f4aca870eb243747951b90ab04/src/js/simplemde.js#L1024-L1042
3,485
sparksuite/simplemde-markdown-editor
src/js/simplemde.js
extend
function extend(target) { for(var i = 1; i < arguments.length; i++) { target = _mergeProperties(target, arguments[i]); } return target; }
javascript
function extend(target) { for(var i = 1; i < arguments.length; i++) { target = _mergeProperties(target, arguments[i]); } return target; }
[ "function", "extend", "(", "target", ")", "{", "for", "(", "var", "i", "=", "1", ";", "i", "<", "arguments", ".", "length", ";", "i", "++", ")", "{", "target", "=", "_mergeProperties", "(", "target", ",", "arguments", "[", "i", "]", ")", ";", "}", "return", "target", ";", "}" ]
Merge an arbitrary number of objects into one.
[ "Merge", "an", "arbitrary", "number", "of", "objects", "into", "one", "." ]
6abda7ab68cc20f4aca870eb243747951b90ab04
https://github.com/sparksuite/simplemde-markdown-editor/blob/6abda7ab68cc20f4aca870eb243747951b90ab04/src/js/simplemde.js#L1045-L1051
3,486
sparksuite/simplemde-markdown-editor
src/js/simplemde.js
isLocalStorageAvailable
function isLocalStorageAvailable() { if(typeof localStorage === "object") { try { localStorage.setItem("smde_localStorage", 1); localStorage.removeItem("smde_localStorage"); } catch(e) { return false; } } else { return false; } return true; }
javascript
function isLocalStorageAvailable() { if(typeof localStorage === "object") { try { localStorage.setItem("smde_localStorage", 1); localStorage.removeItem("smde_localStorage"); } catch(e) { return false; } } else { return false; } return true; }
[ "function", "isLocalStorageAvailable", "(", ")", "{", "if", "(", "typeof", "localStorage", "===", "\"object\"", ")", "{", "try", "{", "localStorage", ".", "setItem", "(", "\"smde_localStorage\"", ",", "1", ")", ";", "localStorage", ".", "removeItem", "(", "\"smde_localStorage\"", ")", ";", "}", "catch", "(", "e", ")", "{", "return", "false", ";", "}", "}", "else", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Safari, in Private Browsing Mode, looks like it supports localStorage but all calls to setItem throw QuotaExceededError. We're going to detect this and set a variable accordingly.
[ "Safari", "in", "Private", "Browsing", "Mode", "looks", "like", "it", "supports", "localStorage", "but", "all", "calls", "to", "setItem", "throw", "QuotaExceededError", ".", "We", "re", "going", "to", "detect", "this", "and", "set", "a", "variable", "accordingly", "." ]
6abda7ab68cc20f4aca870eb243747951b90ab04
https://github.com/sparksuite/simplemde-markdown-editor/blob/6abda7ab68cc20f4aca870eb243747951b90ab04/src/js/simplemde.js#L1530-L1543
3,487
feathericons/feather
bin/build-sprite-string.js
buildSpriteString
function buildSpriteString(icons) { const symbols = Object.keys(icons) .map(icon => toSvgSymbol(icon, icons[icon])) .join(''); return `<svg xmlns="${DEFAULT_ATTRS.xmlns}"><defs>${symbols}</defs></svg>`; }
javascript
function buildSpriteString(icons) { const symbols = Object.keys(icons) .map(icon => toSvgSymbol(icon, icons[icon])) .join(''); return `<svg xmlns="${DEFAULT_ATTRS.xmlns}"><defs>${symbols}</defs></svg>`; }
[ "function", "buildSpriteString", "(", "icons", ")", "{", "const", "symbols", "=", "Object", ".", "keys", "(", "icons", ")", ".", "map", "(", "icon", "=>", "toSvgSymbol", "(", "icon", ",", "icons", "[", "icon", "]", ")", ")", ".", "join", "(", "''", ")", ";", "return", "`", "${", "DEFAULT_ATTRS", ".", "xmlns", "}", "${", "symbols", "}", "`", ";", "}" ]
Build an SVG sprite string containing SVG symbols. @param {Object} icons @returns {string}
[ "Build", "an", "SVG", "sprite", "string", "containing", "SVG", "symbols", "." ]
8f658193d25e943b196a2367319b5d9e85ee9f9f
https://github.com/feathericons/feather/blob/8f658193d25e943b196a2367319b5d9e85ee9f9f/bin/build-sprite-string.js#L8-L14
3,488
feathericons/feather
src/to-svg.js
toSvg
function toSvg(name, attrs = {}) { console.warn( 'feather.toSvg() is deprecated. Please use feather.icons[name].toSvg() instead.', ); if (!name) { throw new Error('The required `key` (icon name) parameter is missing.'); } if (!icons[name]) { throw new Error( `No icon matching '${ name }'. See the complete list of icons at https://feathericons.com`, ); } return icons[name].toSvg(attrs); }
javascript
function toSvg(name, attrs = {}) { console.warn( 'feather.toSvg() is deprecated. Please use feather.icons[name].toSvg() instead.', ); if (!name) { throw new Error('The required `key` (icon name) parameter is missing.'); } if (!icons[name]) { throw new Error( `No icon matching '${ name }'. See the complete list of icons at https://feathericons.com`, ); } return icons[name].toSvg(attrs); }
[ "function", "toSvg", "(", "name", ",", "attrs", "=", "{", "}", ")", "{", "console", ".", "warn", "(", "'feather.toSvg() is deprecated. Please use feather.icons[name].toSvg() instead.'", ",", ")", ";", "if", "(", "!", "name", ")", "{", "throw", "new", "Error", "(", "'The required `key` (icon name) parameter is missing.'", ")", ";", "}", "if", "(", "!", "icons", "[", "name", "]", ")", "{", "throw", "new", "Error", "(", "`", "${", "name", "}", "`", ",", ")", ";", "}", "return", "icons", "[", "name", "]", ".", "toSvg", "(", "attrs", ")", ";", "}" ]
Create an SVG string. @deprecated @param {string} name @param {Object} attrs @returns {string}
[ "Create", "an", "SVG", "string", "." ]
8f658193d25e943b196a2367319b5d9e85ee9f9f
https://github.com/feathericons/feather/blob/8f658193d25e943b196a2367319b5d9e85ee9f9f/src/to-svg.js#L10-L28
3,489
feathericons/feather
src/icon.js
attrsToString
function attrsToString(attrs) { return Object.keys(attrs) .map(key => `${key}="${attrs[key]}"`) .join(' '); }
javascript
function attrsToString(attrs) { return Object.keys(attrs) .map(key => `${key}="${attrs[key]}"`) .join(' '); }
[ "function", "attrsToString", "(", "attrs", ")", "{", "return", "Object", ".", "keys", "(", "attrs", ")", ".", "map", "(", "key", "=>", "`", "${", "key", "}", "${", "attrs", "[", "key", "]", "}", "`", ")", ".", "join", "(", "' '", ")", ";", "}" ]
Convert attributes object to string of HTML attributes. @param {Object} attrs @returns {string}
[ "Convert", "attributes", "object", "to", "string", "of", "HTML", "attributes", "." ]
8f658193d25e943b196a2367319b5d9e85ee9f9f
https://github.com/feathericons/feather/blob/8f658193d25e943b196a2367319b5d9e85ee9f9f/src/icon.js#L49-L53
3,490
feathericons/feather
src/replace.js
replace
function replace(attrs = {}) { if (typeof document === 'undefined') { throw new Error('`feather.replace()` only works in a browser environment.'); } const elementsToReplace = document.querySelectorAll('[data-feather]'); Array.from(elementsToReplace).forEach(element => replaceElement(element, attrs), ); }
javascript
function replace(attrs = {}) { if (typeof document === 'undefined') { throw new Error('`feather.replace()` only works in a browser environment.'); } const elementsToReplace = document.querySelectorAll('[data-feather]'); Array.from(elementsToReplace).forEach(element => replaceElement(element, attrs), ); }
[ "function", "replace", "(", "attrs", "=", "{", "}", ")", "{", "if", "(", "typeof", "document", "===", "'undefined'", ")", "{", "throw", "new", "Error", "(", "'`feather.replace()` only works in a browser environment.'", ")", ";", "}", "const", "elementsToReplace", "=", "document", ".", "querySelectorAll", "(", "'[data-feather]'", ")", ";", "Array", ".", "from", "(", "elementsToReplace", ")", ".", "forEach", "(", "element", "=>", "replaceElement", "(", "element", ",", "attrs", ")", ",", ")", ";", "}" ]
Replace all HTML elements that have a `data-feather` attribute with SVG markup corresponding to the element's `data-feather` attribute value. @param {Object} attrs
[ "Replace", "all", "HTML", "elements", "that", "have", "a", "data", "-", "feather", "attribute", "with", "SVG", "markup", "corresponding", "to", "the", "element", "s", "data", "-", "feather", "attribute", "value", "." ]
8f658193d25e943b196a2367319b5d9e85ee9f9f
https://github.com/feathericons/feather/blob/8f658193d25e943b196a2367319b5d9e85ee9f9f/src/replace.js#L11-L21
3,491
feathericons/feather
src/replace.js
replaceElement
function replaceElement(element, attrs = {}) { const elementAttrs = getAttrs(element); const name = elementAttrs['data-feather']; delete elementAttrs['data-feather']; const svgString = icons[name].toSvg({ ...attrs, ...elementAttrs, ...{ class: classnames(attrs.class, elementAttrs.class) }, }); const svgDocument = new DOMParser().parseFromString( svgString, 'image/svg+xml', ); const svgElement = svgDocument.querySelector('svg'); element.parentNode.replaceChild(svgElement, element); }
javascript
function replaceElement(element, attrs = {}) { const elementAttrs = getAttrs(element); const name = elementAttrs['data-feather']; delete elementAttrs['data-feather']; const svgString = icons[name].toSvg({ ...attrs, ...elementAttrs, ...{ class: classnames(attrs.class, elementAttrs.class) }, }); const svgDocument = new DOMParser().parseFromString( svgString, 'image/svg+xml', ); const svgElement = svgDocument.querySelector('svg'); element.parentNode.replaceChild(svgElement, element); }
[ "function", "replaceElement", "(", "element", ",", "attrs", "=", "{", "}", ")", "{", "const", "elementAttrs", "=", "getAttrs", "(", "element", ")", ";", "const", "name", "=", "elementAttrs", "[", "'data-feather'", "]", ";", "delete", "elementAttrs", "[", "'data-feather'", "]", ";", "const", "svgString", "=", "icons", "[", "name", "]", ".", "toSvg", "(", "{", "...", "attrs", ",", "...", "elementAttrs", ",", "...", "{", "class", ":", "classnames", "(", "attrs", ".", "class", ",", "elementAttrs", ".", "class", ")", "}", ",", "}", ")", ";", "const", "svgDocument", "=", "new", "DOMParser", "(", ")", ".", "parseFromString", "(", "svgString", ",", "'image/svg+xml'", ",", ")", ";", "const", "svgElement", "=", "svgDocument", ".", "querySelector", "(", "'svg'", ")", ";", "element", ".", "parentNode", ".", "replaceChild", "(", "svgElement", ",", "element", ")", ";", "}" ]
Replace a single HTML element with SVG markup corresponding to the element's `data-feather` attribute value. @param {HTMLElement} element @param {Object} attrs
[ "Replace", "a", "single", "HTML", "element", "with", "SVG", "markup", "corresponding", "to", "the", "element", "s", "data", "-", "feather", "attribute", "value", "." ]
8f658193d25e943b196a2367319b5d9e85ee9f9f
https://github.com/feathericons/feather/blob/8f658193d25e943b196a2367319b5d9e85ee9f9f/src/replace.js#L29-L46
3,492
feathericons/feather
src/replace.js
getAttrs
function getAttrs(element) { return Array.from(element.attributes).reduce((attrs, attr) => { attrs[attr.name] = attr.value; return attrs; }, {}); }
javascript
function getAttrs(element) { return Array.from(element.attributes).reduce((attrs, attr) => { attrs[attr.name] = attr.value; return attrs; }, {}); }
[ "function", "getAttrs", "(", "element", ")", "{", "return", "Array", ".", "from", "(", "element", ".", "attributes", ")", ".", "reduce", "(", "(", "attrs", ",", "attr", ")", "=>", "{", "attrs", "[", "attr", ".", "name", "]", "=", "attr", ".", "value", ";", "return", "attrs", ";", "}", ",", "{", "}", ")", ";", "}" ]
Get the attributes of an HTML element. @param {HTMLElement} element @returns {Object}
[ "Get", "the", "attributes", "of", "an", "HTML", "element", "." ]
8f658193d25e943b196a2367319b5d9e85ee9f9f
https://github.com/feathericons/feather/blob/8f658193d25e943b196a2367319b5d9e85ee9f9f/src/replace.js#L53-L58
3,493
feathericons/feather
bin/process-svg.js
processSvg
function processSvg(svg) { return ( optimize(svg) .then(setAttrs) .then(format) // remove semicolon inserted by prettier // because prettier thinks it's formatting JSX not HTML .then(svg => svg.replace(/;/g, '')) ); }
javascript
function processSvg(svg) { return ( optimize(svg) .then(setAttrs) .then(format) // remove semicolon inserted by prettier // because prettier thinks it's formatting JSX not HTML .then(svg => svg.replace(/;/g, '')) ); }
[ "function", "processSvg", "(", "svg", ")", "{", "return", "(", "optimize", "(", "svg", ")", ".", "then", "(", "setAttrs", ")", ".", "then", "(", "format", ")", "// remove semicolon inserted by prettier", "// because prettier thinks it's formatting JSX not HTML", ".", "then", "(", "svg", "=>", "svg", ".", "replace", "(", "/", ";", "/", "g", ",", "''", ")", ")", ")", ";", "}" ]
Process SVG string. @param {string} svg - An SVG string. @param {Promise<string>}
[ "Process", "SVG", "string", "." ]
8f658193d25e943b196a2367319b5d9e85ee9f9f
https://github.com/feathericons/feather/blob/8f658193d25e943b196a2367319b5d9e85ee9f9f/bin/process-svg.js#L12-L21
3,494
feathericons/feather
bin/process-svg.js
optimize
function optimize(svg) { const svgo = new Svgo({ plugins: [ { convertShapeToPath: false }, { mergePaths: false }, { removeAttrs: { attrs: '(fill|stroke.*)' } }, { removeTitle: true }, ], }); return new Promise(resolve => { svgo.optimize(svg, ({ data }) => resolve(data)); }); }
javascript
function optimize(svg) { const svgo = new Svgo({ plugins: [ { convertShapeToPath: false }, { mergePaths: false }, { removeAttrs: { attrs: '(fill|stroke.*)' } }, { removeTitle: true }, ], }); return new Promise(resolve => { svgo.optimize(svg, ({ data }) => resolve(data)); }); }
[ "function", "optimize", "(", "svg", ")", "{", "const", "svgo", "=", "new", "Svgo", "(", "{", "plugins", ":", "[", "{", "convertShapeToPath", ":", "false", "}", ",", "{", "mergePaths", ":", "false", "}", ",", "{", "removeAttrs", ":", "{", "attrs", ":", "'(fill|stroke.*)'", "}", "}", ",", "{", "removeTitle", ":", "true", "}", ",", "]", ",", "}", ")", ";", "return", "new", "Promise", "(", "resolve", "=>", "{", "svgo", ".", "optimize", "(", "svg", ",", "(", "{", "data", "}", ")", "=>", "resolve", "(", "data", ")", ")", ";", "}", ")", ";", "}" ]
Optimize SVG with `svgo`. @param {string} svg - An SVG string. @returns {Promise<string>}
[ "Optimize", "SVG", "with", "svgo", "." ]
8f658193d25e943b196a2367319b5d9e85ee9f9f
https://github.com/feathericons/feather/blob/8f658193d25e943b196a2367319b5d9e85ee9f9f/bin/process-svg.js#L28-L41
3,495
feathericons/feather
bin/process-svg.js
setAttrs
function setAttrs(svg) { const $ = cheerio.load(svg); Object.keys(DEFAULT_ATTRS).forEach(key => $('svg').attr(key, DEFAULT_ATTRS[key]), ); return $('body').html(); }
javascript
function setAttrs(svg) { const $ = cheerio.load(svg); Object.keys(DEFAULT_ATTRS).forEach(key => $('svg').attr(key, DEFAULT_ATTRS[key]), ); return $('body').html(); }
[ "function", "setAttrs", "(", "svg", ")", "{", "const", "$", "=", "cheerio", ".", "load", "(", "svg", ")", ";", "Object", ".", "keys", "(", "DEFAULT_ATTRS", ")", ".", "forEach", "(", "key", "=>", "$", "(", "'svg'", ")", ".", "attr", "(", "key", ",", "DEFAULT_ATTRS", "[", "key", "]", ")", ",", ")", ";", "return", "$", "(", "'body'", ")", ".", "html", "(", ")", ";", "}" ]
Set default attibutes on SVG. @param {string} svg - An SVG string. @returns {string}
[ "Set", "default", "attibutes", "on", "SVG", "." ]
8f658193d25e943b196a2367319b5d9e85ee9f9f
https://github.com/feathericons/feather/blob/8f658193d25e943b196a2367319b5d9e85ee9f9f/bin/process-svg.js#L48-L56
3,496
facebook/watchman
node/bser/index.js
nextPow2
function nextPow2(size) { return Math.pow(2, Math.ceil(Math.log(size) / Math.LN2)); }
javascript
function nextPow2(size) { return Math.pow(2, Math.ceil(Math.log(size) / Math.LN2)); }
[ "function", "nextPow2", "(", "size", ")", "{", "return", "Math", ".", "pow", "(", "2", ",", "Math", ".", "ceil", "(", "Math", ".", "log", "(", "size", ")", "/", "Math", ".", "LN2", ")", ")", ";", "}" ]
Find the next power-of-2 >= size
[ "Find", "the", "next", "power", "-", "of", "-", "2", ">", "=", "size" ]
8d576a2d3e1191c977f03f584993da63a3b8e5ec
https://github.com/facebook/watchman/blob/8d576a2d3e1191c977f03f584993da63a3b8e5ec/node/bser/index.js#L16-L18
3,497
facebook/watchman
node/bser/index.js
loadFromBuffer
function loadFromBuffer(input) { var buf = new BunserBuf(); var result = buf.append(input, true); if (buf.buf.readAvail()) { throw Error( 'excess data found after input buffer, use BunserBuf instead'); } if (typeof result === 'undefined') { throw Error( 'no bser found in string and no error raised!?'); } return result; }
javascript
function loadFromBuffer(input) { var buf = new BunserBuf(); var result = buf.append(input, true); if (buf.buf.readAvail()) { throw Error( 'excess data found after input buffer, use BunserBuf instead'); } if (typeof result === 'undefined') { throw Error( 'no bser found in string and no error raised!?'); } return result; }
[ "function", "loadFromBuffer", "(", "input", ")", "{", "var", "buf", "=", "new", "BunserBuf", "(", ")", ";", "var", "result", "=", "buf", ".", "append", "(", "input", ",", "true", ")", ";", "if", "(", "buf", ".", "buf", ".", "readAvail", "(", ")", ")", "{", "throw", "Error", "(", "'excess data found after input buffer, use BunserBuf instead'", ")", ";", "}", "if", "(", "typeof", "result", "===", "'undefined'", ")", "{", "throw", "Error", "(", "'no bser found in string and no error raised!?'", ")", ";", "}", "return", "result", ";", "}" ]
synchronously BSER decode a string and return the value
[ "synchronously", "BSER", "decode", "a", "string", "and", "return", "the", "value" ]
8d576a2d3e1191c977f03f584993da63a3b8e5ec
https://github.com/facebook/watchman/blob/8d576a2d3e1191c977f03f584993da63a3b8e5ec/node/bser/index.js#L435-L447
3,498
facebook/watchman
node/bser/index.js
byteswap64
function byteswap64(buf) { var swap = new Buffer(buf.length); for (var i = 0; i < buf.length; i++) { swap[i] = buf[buf.length -1 - i]; } return swap; }
javascript
function byteswap64(buf) { var swap = new Buffer(buf.length); for (var i = 0; i < buf.length; i++) { swap[i] = buf[buf.length -1 - i]; } return swap; }
[ "function", "byteswap64", "(", "buf", ")", "{", "var", "swap", "=", "new", "Buffer", "(", "buf", ".", "length", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "buf", ".", "length", ";", "i", "++", ")", "{", "swap", "[", "i", "]", "=", "buf", "[", "buf", ".", "length", "-", "1", "-", "i", "]", ";", "}", "return", "swap", ";", "}" ]
Byteswap an arbitrary buffer, flipping from one endian to the other, returning a new buffer with the resultant data
[ "Byteswap", "an", "arbitrary", "buffer", "flipping", "from", "one", "endian", "to", "the", "other", "returning", "a", "new", "buffer", "with", "the", "resultant", "data" ]
8d576a2d3e1191c977f03f584993da63a3b8e5ec
https://github.com/facebook/watchman/blob/8d576a2d3e1191c977f03f584993da63a3b8e5ec/node/bser/index.js#L452-L458
3,499
facebook/watchman
node/bser/index.js
dumpToBuffer
function dumpToBuffer(val) { var buf = new Accumulator(); // Build out the header buf.writeByte(0); buf.writeByte(1); // Reserve room for an int32 to hold our PDU length buf.writeByte(BSER_INT32); buf.writeInt(0, 4); // We'll come back and fill this in at the end dump_any(buf, val); // Compute PDU length var off = buf.writeOffset; var len = off - 7 /* the header length */; buf.writeOffset = 3; // The length value to fill in buf.writeInt(len, 4); // write the length in the space we reserved buf.writeOffset = off; return buf.buf.slice(0, off); }
javascript
function dumpToBuffer(val) { var buf = new Accumulator(); // Build out the header buf.writeByte(0); buf.writeByte(1); // Reserve room for an int32 to hold our PDU length buf.writeByte(BSER_INT32); buf.writeInt(0, 4); // We'll come back and fill this in at the end dump_any(buf, val); // Compute PDU length var off = buf.writeOffset; var len = off - 7 /* the header length */; buf.writeOffset = 3; // The length value to fill in buf.writeInt(len, 4); // write the length in the space we reserved buf.writeOffset = off; return buf.buf.slice(0, off); }
[ "function", "dumpToBuffer", "(", "val", ")", "{", "var", "buf", "=", "new", "Accumulator", "(", ")", ";", "// Build out the header", "buf", ".", "writeByte", "(", "0", ")", ";", "buf", ".", "writeByte", "(", "1", ")", ";", "// Reserve room for an int32 to hold our PDU length", "buf", ".", "writeByte", "(", "BSER_INT32", ")", ";", "buf", ".", "writeInt", "(", "0", ",", "4", ")", ";", "// We'll come back and fill this in at the end", "dump_any", "(", "buf", ",", "val", ")", ";", "// Compute PDU length", "var", "off", "=", "buf", ".", "writeOffset", ";", "var", "len", "=", "off", "-", "7", "/* the header length */", ";", "buf", ".", "writeOffset", "=", "3", ";", "// The length value to fill in", "buf", ".", "writeInt", "(", "len", ",", "4", ")", ";", "// write the length in the space we reserved", "buf", ".", "writeOffset", "=", "off", ";", "return", "buf", ".", "buf", ".", "slice", "(", "0", ",", "off", ")", ";", "}" ]
BSER encode value and return a buffer of the contents
[ "BSER", "encode", "value", "and", "return", "a", "buffer", "of", "the", "contents" ]
8d576a2d3e1191c977f03f584993da63a3b8e5ec
https://github.com/facebook/watchman/blob/8d576a2d3e1191c977f03f584993da63a3b8e5ec/node/bser/index.js#L566-L585