code
stringlengths
24
2.07M
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
92
language
stringclasses
1 value
repo
stringlengths
5
64
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
builder = function () { return applyStyle.apply(builder, arguments); }
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
builder
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
get() { return self.level; }
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
get
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
set(level) { self.level = level; }
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
set
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
get() { return self.enabled; }
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
get
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
set(enabled) { self.enabled = enabled; }
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
set
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function applyStyle() { // Support varags, but simply cast to string in case there's only one arg const args = arguments; const argsLen = args.length; let str = String(arguments[0]); if (argsLen === 0) { return ''; } if (argsLen > 1) { // Don't slice `arguments`, it prevents V8 optimizations for (let a = 1; a < argsLen; a++) { str += ' ' + args[a]; } } if (!this.enabled || this.level <= 0 || !str) { return this._empty ? '' : str; } // Turns out that on Windows dimmed gray text becomes invisible in cmd.exe, // see https://github.com/chalk/chalk/issues/58 // If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop. const originalDim = ansiStyles$2.dim.open; if (isSimpleWindowsTerm && this.hasGrey) { ansiStyles$2.dim.open = ''; } for (const code of this._styles.slice().reverse()) { // Replace any instances already present with a re-opening code // otherwise only the part of the string until said closing code // will be colored, and the rest will simply be 'plain'. str = code.open + str.replace(code.closeRe, code.open) + code.close; // Close the styling before a linebreak and reopen // after next line to fix a bleed issue on macOS // https://github.com/chalk/chalk/pull/92 str = str.replace(/\r?\n/g, `${code.close}$&${code.open}`); } // Reset the original `dim` if we changed it to work around the Windows dimmed gray issue ansiStyles$2.dim.open = originalDim; return str; }
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
applyStyle
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function chalkTag(chalk, strings) { if (!Array.isArray(strings)) { // If chalk() was called by itself or with a string, // return the string itself as a string. return [].slice.call(arguments, 1).join(' '); } const args = [].slice.call(arguments, 2); const parts = [strings.raw[0]]; for (let i = 1; i < strings.length; i++) { parts.push(String(args[i - 1]).replace(/[{}\\]/g, '\\$&')); parts.push(String(strings.raw[i])); } return templates$2(chalk, parts.join('')); }
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
chalkTag
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
_interopRequireDefault
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
_getRequireWildcardCache
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
_interopRequireWildcard
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function getDefs(chalk) { return { keyword: chalk.cyan, capitalized: chalk.yellow, jsx_tag: chalk.yellow, punctuator: chalk.yellow, number: chalk.magenta, string: chalk.green, regex: chalk.magenta, comment: chalk.grey, invalid: chalk.white.bgRed.bold }; }
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
getDefs
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function getTokenType(match) { const [offset, text] = match.slice(-2); const token = (0, _jsTokens.matchToToken)(match); if (token.type === "name") { if (_esutils.default.keyword.isReservedWordES6(token.value)) { return "keyword"; } if (JSX_TAG.test(token.value) && (text[offset - 1] === "<" || text.substr(offset - 2, 2) == "</")) { return "jsx_tag"; } if (token.value[0] !== token.value[0].toLowerCase()) { return "capitalized"; } } if (token.type === "punctuator" && BRACKET.test(token.value)) { return "bracket"; } if (token.type === "invalid" && (token.value === "@" || token.value === "#")) { return "punctuator"; } return token.type; }
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
getTokenType
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function highlightTokens(defs, text) { return text.replace(_jsTokens.default, function (...args) { const type = getTokenType(args); const colorize = defs[type]; if (colorize) { return args[0].split(NEWLINE).map(str => colorize(str)).join("\n"); } else { return args[0]; } }); }
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
highlightTokens
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function shouldHighlight(options) { return _chalk.default.supportsColor || options.forceColor; }
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
shouldHighlight
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function getChalk(options) { let chalk = _chalk.default; if (options.forceColor) { chalk = new _chalk.default.constructor({ enabled: true, level: 1 }); } return chalk; }
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
getChalk
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function highlight(code, options = {}) { if (shouldHighlight(options)) { const chalk = getChalk(options); const defs = getDefs(chalk); return highlightTokens(defs, code); } else { return code; } }
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
highlight
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
_getRequireWildcardCache
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
_interopRequireWildcard
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function getDefs(chalk) { return { gutter: chalk.grey, marker: chalk.red.bold, message: chalk.red.bold }; }
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
getDefs
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function getMarkerLines(loc, source, opts) { const startLoc = Object.assign({ column: 0, line: -1 }, loc.start); const endLoc = Object.assign({}, startLoc, {}, loc.end); const { linesAbove = 2, linesBelow = 3 } = opts || {}; const startLine = startLoc.line; const startColumn = startLoc.column; const endLine = endLoc.line; const endColumn = endLoc.column; let start = Math.max(startLine - (linesAbove + 1), 0); let end = Math.min(source.length, endLine + linesBelow); if (startLine === -1) { start = 0; } if (endLine === -1) { end = source.length; } const lineDiff = endLine - startLine; const markerLines = {}; if (lineDiff) { for (let i = 0; i <= lineDiff; i++) { const lineNumber = i + startLine; if (!startColumn) { markerLines[lineNumber] = true; } else if (i === 0) { const sourceLength = source[lineNumber - 1].length; markerLines[lineNumber] = [startColumn, sourceLength - startColumn + 1]; } else if (i === lineDiff) { markerLines[lineNumber] = [0, endColumn]; } else { const sourceLength = source[lineNumber - i].length; markerLines[lineNumber] = [0, sourceLength]; } } } else { if (startColumn === endColumn) { if (startColumn) { markerLines[startLine] = [startColumn, 0]; } else { markerLines[startLine] = true; } } else { markerLines[startLine] = [startColumn, endColumn - startColumn]; } } return { start, end, markerLines }; }
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
getMarkerLines
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function codeFrameColumns(rawLines, loc, opts = {}) { const highlighted = (opts.highlightCode || opts.forceColor) && (0, _highlight.shouldHighlight)(opts); const chalk = (0, _highlight.getChalk)(opts); const defs = getDefs(chalk); const maybeHighlight = (chalkFn, string) => { return highlighted ? chalkFn(string) : string; }; const lines = rawLines.split(NEWLINE); const { start, end, markerLines } = getMarkerLines(loc, lines, opts); const hasColumns = loc.start && typeof loc.start.column === "number"; const numberMaxWidth = String(end).length; const highlightedLines = highlighted ? (0, _highlight.default)(rawLines, opts) : rawLines; let frame = highlightedLines.split(NEWLINE).slice(start, end).map((line, index) => { const number = start + 1 + index; const paddedNumber = ` ${number}`.slice(-numberMaxWidth); const gutter = ` ${paddedNumber} | `; const hasMarker = markerLines[number]; const lastMarkerLine = !markerLines[number + 1]; if (hasMarker) { let markerLine = ""; if (Array.isArray(hasMarker)) { const markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " "); const numberOfMarkers = hasMarker[1] || 1; markerLine = ["\n ", maybeHighlight(defs.gutter, gutter.replace(/\d/g, " ")), markerSpacing, maybeHighlight(defs.marker, "^").repeat(numberOfMarkers)].join(""); if (lastMarkerLine && opts.message) { markerLine += " " + maybeHighlight(defs.message, opts.message); } } return [maybeHighlight(defs.marker, ">"), maybeHighlight(defs.gutter, gutter), line, markerLine].join(""); } else { return ` ${maybeHighlight(defs.gutter, gutter)}${line}`; } }).join("\n"); if (opts.message && !hasColumns) { frame = `${" ".repeat(numberMaxWidth + 1)}${opts.message}\n${frame}`; } if (highlighted) { return chalk.reset(frame); } else { return frame; } }
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
codeFrameColumns
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
maybeHighlight = (chalkFn, string) => { return highlighted ? chalkFn(string) : string; }
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
maybeHighlight
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
maybeHighlight = (chalkFn, string) => { return highlighted ? chalkFn(string) : string; }
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
maybeHighlight
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function _default(rawLines, lineNumber, colNumber, opts = {}) { if (!deprecationWarningShown) { deprecationWarningShown = true; const message = "Passing lineNumber and colNumber is deprecated to @babel/code-frame. Please use `codeFrameColumns`."; if (process.emitWarning) { process.emitWarning(message, "DeprecationWarning"); } else { const deprecationError = new Error(message); deprecationError.name = "DeprecationWarning"; console.warn(new Error(message)); } } colNumber = Math.max(colNumber, 0); const location = { start: { column: colNumber, line: lineNumber } }; return codeFrameColumns(rawLines, location, opts); }
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
_default
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function getParsers(options) { const parsers = {}; for (const plugin of options.plugins) { if (!plugin.parsers) { continue; } for (const name of ownNames(plugin.parsers)) { Object.defineProperty(parsers, name, ownDescriptor(plugin.parsers, name)); } } return parsers; }
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
getParsers
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function resolveParser(opts, parsers) { parsers = parsers || getParsers(opts); if (typeof opts.parser === "function") { // Custom parser API always works with JavaScript. return { parse: opts.parser, astFormat: "estree", locStart: locStart$1, locEnd: locEnd$1 }; } if (typeof opts.parser === "string") { if (Object.prototype.hasOwnProperty.call(parsers, opts.parser)) { return parsers[opts.parser]; } /* istanbul ignore next */ { try { return { parse: require(path$2.resolve(process.cwd(), opts.parser)), astFormat: "estree", locStart: locStart$1, locEnd: locEnd$1 }; } catch (err) { /* istanbul ignore next */ throw new ConfigError$1(`Couldn't resolve parser "${opts.parser}"`); } } } }
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
resolveParser
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function parse(text, opts) { const parsers = getParsers(opts); // Create a new object {parserName: parseFn}. Uses defineProperty() to only call // the parsers getters when actually calling the parser `parse` function. const parsersForCustomParserApi = Object.keys(parsers).reduce((object, parserName) => Object.defineProperty(object, parserName, { enumerable: true, get() { return parsers[parserName].parse; } }), {}); const parser = resolveParser(opts, parsers); try { if (parser.preprocess) { text = parser.preprocess(text, opts); } return { text, ast: parser.parse(text, parsersForCustomParserApi, opts) }; } catch (error) { const { loc } = error; if (loc) { const codeFrame = lib$2; error.codeFrame = codeFrame.codeFrameColumns(text, loc, { highlightCode: true }); error.message += "\n" + error.codeFrame; throw error; } /* istanbul ignore next */ throw error.stack; } }
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
parse
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
get() { return parsers[parserName].parse; }
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
get
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function normalize$1(options, opts) { opts = opts || {}; const rawOptions = Object.assign({}, options); const supportOptions = getSupportInfo$1({ plugins: options.plugins, showUnreleased: true, showDeprecated: true }).options; const defaults = Object.assign(Object.assign({}, hiddenDefaults), fromPairs_1(supportOptions.filter(optionInfo => optionInfo.default !== undefined).map(option => [option.name, option.default]))); if (!rawOptions.parser) { if (!rawOptions.filepath) { const logger = opts.logger || console; logger.warn("No parser and no filepath given, using 'babel' the parser now " + "but this will throw an error in the future. " + "Please specify a parser or a filepath so one can be inferred."); rawOptions.parser = "babel"; } else { rawOptions.parser = inferParser(rawOptions.filepath, rawOptions.plugins); if (!rawOptions.parser) { throw new UndefinedParserError$1(`No parser could be inferred for file: ${rawOptions.filepath}`); } } } const parser = resolveParser$1(optionsNormalizer.normalizeApiOptions(rawOptions, [supportOptions.find(x => x.name === "parser")], { passThrough: true, logger: false })); rawOptions.astFormat = parser.astFormat; rawOptions.locEnd = parser.locEnd; rawOptions.locStart = parser.locStart; const plugin = getPlugin(rawOptions); rawOptions.printer = plugin.printers[rawOptions.astFormat]; const pluginDefaults = supportOptions.filter(optionInfo => optionInfo.pluginDefaults && optionInfo.pluginDefaults[plugin.name] !== undefined).reduce((reduced, optionInfo) => Object.assign(reduced, { [optionInfo.name]: optionInfo.pluginDefaults[plugin.name] }), {}); const mixedDefaults = Object.assign(Object.assign({}, defaults), pluginDefaults); Object.keys(mixedDefaults).forEach(k => { if (rawOptions[k] == null) { rawOptions[k] = mixedDefaults[k]; } }); if (rawOptions.parser === "json") { rawOptions.trailingComma = "none"; } return optionsNormalizer.normalizeApiOptions(rawOptions, supportOptions, Object.assign({ passThrough: Object.keys(hiddenDefaults) }, opts)); }
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
normalize$1
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function getPlugin(options) { const { astFormat } = options; if (!astFormat) { throw new Error("getPlugin() requires astFormat to be set"); } const printerPlugin = options.plugins.find(plugin => plugin.printers && plugin.printers[astFormat]); if (!printerPlugin) { throw new Error(`Couldn't find plugin for AST format "${astFormat}"`); } return printerPlugin; }
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
getPlugin
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function getInterpreter(filepath) { if (typeof filepath !== "string") { return ""; } let fd; try { fd = fs$3.openSync(filepath, "r"); } catch (err) { // istanbul ignore next return ""; } try { const liner = new readlines(fd); const firstLine = liner.next().toString("utf8"); // #!/bin/env node, #!/usr/bin/env node const m1 = firstLine.match(/^#!\/(?:usr\/)?bin\/env\s+(\S+)/); if (m1) { return m1[1]; } // #!/bin/node, #!/usr/bin/node, #!/usr/local/bin/node const m2 = firstLine.match(/^#!\/(?:usr\/(?:local\/)?)?bin\/(\S+)/); if (m2) { return m2[1]; } return ""; } catch (err) { // There are some weird cases where paths are missing, causing Jest // failures. It's unclear what these correspond to in the real world. return ""; } finally { try { // There are some weird cases where paths are missing, causing Jest // failures. It's unclear what these correspond to in the real world. fs$3.closeSync(fd); } catch (err) {// nop } } }
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
getInterpreter
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function inferParser(filepath, plugins) { const filename = path$2.basename(filepath).toLowerCase(); const languages = getSupportInfo$1({ plugins }).languages.filter(language => language.since !== null); // If the file has no extension, we can try to infer the language from the // interpreter in the shebang line, if any; but since this requires FS access, // do it last. let language = languages.find(language => language.extensions && language.extensions.some(extension => filename.endsWith(extension)) || language.filenames && language.filenames.find(name => name.toLowerCase() === filename)); if (!language && !filename.includes(".")) { const interpreter = getInterpreter(filepath); language = languages.find(language => language.interpreters && language.interpreters.includes(interpreter)); } return language && language.parsers[0]; }
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
inferParser
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function massageAST(ast, options, parent) { if (Array.isArray(ast)) { return ast.map(e => massageAST(e, options, parent)).filter(Boolean); } if (!ast || typeof ast !== "object") { return ast; } const newObj = {}; for (const key of Object.keys(ast)) { if (typeof ast[key] !== "function") { newObj[key] = massageAST(ast[key], options, ast); } } if (options.printer.massageAstNode) { const result = options.printer.massageAstNode(ast, newObj, parent); if (result === null) { return undefined; } if (result) { return result; } } return newObj; }
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
massageAST
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function align(n, contents) { return { type: "align", contents, n }; }
@param {number} n @param {Doc} contents @returns Doc
align
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function group(contents, opts) { opts = opts || {}; return { type: "group", id: opts.id, contents, break: !!opts.shouldBreak, expandedStates: opts.expandedStates }; }
@param {Doc} contents @param {object} [opts] - TBD ??? @returns Doc
group
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function conditionalGroup(states, opts) { return group(states[0], Object.assign(Object.assign({}, opts), {}, { expandedStates: states })); }
@param {Doc[]} states @param {object} [opts] - TBD ??? @returns Doc
conditionalGroup
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function ifBreak(breakContents, flatContents, opts) { opts = opts || {}; return { type: "if-break", breakContents, flatContents, groupId: opts.groupId }; }
@param {Doc} [breakContents] @param {Doc} [flatContents] @param {object} [opts] - TBD ??? @returns Doc
ifBreak
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function join(sep, arr) { const res = []; for (let i = 0; i < arr.length; i++) { if (i !== 0) { res.push(sep); } res.push(arr[i]); } return concat(res); }
@param {Doc} sep @param {Doc[]} arr @returns Doc
join
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function addAlignmentToDoc(doc, size, tabWidth) { let aligned = doc; if (size > 0) { // Use indent to add tabs for all the levels of tabs we need for (let i = 0; i < Math.floor(size / tabWidth); ++i) { aligned = indent(aligned); } // Use align for all the spaces that are needed aligned = align(size % tabWidth, aligned); // size is absolute from 0 and not relative to the current // indentation, so we use -Infinity to reset the indentation to 0 aligned = align(-Infinity, aligned); } return aligned; }
@param {Doc} doc @param {number} size @param {number} tabWidth
addAlignmentToDoc
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
ansiRegex = ({ onlyFirst = false } = {}) => { const pattern = ['[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)', '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))'].join('|'); return new RegExp(pattern, onlyFirst ? undefined : 'g'); }
@param {Doc} doc @param {number} size @param {number} tabWidth
ansiRegex
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
isFullwidthCodePoint = codePoint => { if (Number.isNaN(codePoint)) { return false; } // Code points are derived from: // http://www.unix.org/Public/UNIDATA/EastAsianWidth.txt if (codePoint >= 0x1100 && (codePoint <= 0x115F || // Hangul Jamo codePoint === 0x2329 || // LEFT-POINTING ANGLE BRACKET codePoint === 0x232A || // RIGHT-POINTING ANGLE BRACKET // CJK Radicals Supplement .. Enclosed CJK Letters and Months 0x2E80 <= codePoint && codePoint <= 0x3247 && codePoint !== 0x303F || // Enclosed CJK Letters and Months .. CJK Unified Ideographs Extension A 0x3250 <= codePoint && codePoint <= 0x4DBF || // CJK Unified Ideographs .. Yi Radicals 0x4E00 <= codePoint && codePoint <= 0xA4C6 || // Hangul Jamo Extended-A 0xA960 <= codePoint && codePoint <= 0xA97C || // Hangul Syllables 0xAC00 <= codePoint && codePoint <= 0xD7A3 || // CJK Compatibility Ideographs 0xF900 <= codePoint && codePoint <= 0xFAFF || // Vertical Forms 0xFE10 <= codePoint && codePoint <= 0xFE19 || // CJK Compatibility Forms .. Small Form Variants 0xFE30 <= codePoint && codePoint <= 0xFE6B || // Halfwidth and Fullwidth Forms 0xFF01 <= codePoint && codePoint <= 0xFF60 || 0xFFE0 <= codePoint && codePoint <= 0xFFE6 || // Kana Supplement 0x1B000 <= codePoint && codePoint <= 0x1B001 || // Enclosed Ideographic Supplement 0x1F200 <= codePoint && codePoint <= 0x1F251 || // CJK Unified Ideographs Extension B .. Tertiary Ideographic Plane 0x20000 <= codePoint && codePoint <= 0x3FFFD)) { return true; } return false; }
@param {Doc} doc @param {number} size @param {number} tabWidth
isFullwidthCodePoint
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
isFullwidthCodePoint = codePoint => { if (Number.isNaN(codePoint)) { return false; } // Code points are derived from: // http://www.unix.org/Public/UNIDATA/EastAsianWidth.txt if (codePoint >= 0x1100 && (codePoint <= 0x115F || // Hangul Jamo codePoint === 0x2329 || // LEFT-POINTING ANGLE BRACKET codePoint === 0x232A || // RIGHT-POINTING ANGLE BRACKET // CJK Radicals Supplement .. Enclosed CJK Letters and Months 0x2E80 <= codePoint && codePoint <= 0x3247 && codePoint !== 0x303F || // Enclosed CJK Letters and Months .. CJK Unified Ideographs Extension A 0x3250 <= codePoint && codePoint <= 0x4DBF || // CJK Unified Ideographs .. Yi Radicals 0x4E00 <= codePoint && codePoint <= 0xA4C6 || // Hangul Jamo Extended-A 0xA960 <= codePoint && codePoint <= 0xA97C || // Hangul Syllables 0xAC00 <= codePoint && codePoint <= 0xD7A3 || // CJK Compatibility Ideographs 0xF900 <= codePoint && codePoint <= 0xFAFF || // Vertical Forms 0xFE10 <= codePoint && codePoint <= 0xFE19 || // CJK Compatibility Forms .. Small Form Variants 0xFE30 <= codePoint && codePoint <= 0xFE6B || // Halfwidth and Fullwidth Forms 0xFF01 <= codePoint && codePoint <= 0xFF60 || 0xFFE0 <= codePoint && codePoint <= 0xFFE6 || // Kana Supplement 0x1B000 <= codePoint && codePoint <= 0x1B001 || // Enclosed Ideographic Supplement 0x1F200 <= codePoint && codePoint <= 0x1F251 || // CJK Unified Ideographs Extension B .. Tertiary Ideographic Plane 0x20000 <= codePoint && codePoint <= 0x3FFFD)) { return true; } return false; }
@param {Doc} doc @param {number} size @param {number} tabWidth
isFullwidthCodePoint
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
emojiRegex = function () { // https://mths.be/emoji return /\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F|\uD83D\uDC68(?:\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68\uD83C\uDFFB|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|[\u2695\u2696\u2708]\uFE0F|\uD83D[\uDC66\uDC67]|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708])\uFE0F|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C[\uDFFB-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)\uD83C\uDFFB|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])|\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)(?:\uD83C[\uDFFB\uDFFC])|\uD83D\uDC69(?:\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)(?:\uD83C[\uDFFB-\uDFFD])|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|(?:(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)\uFE0F|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD6-\uDDDD])(?:(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\u200D[\u2640\u2642])|\uD83C\uDFF4\u200D\u2620)\uFE0F|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF4\uD83C\uDDF2|\uD83C\uDDF6\uD83C\uDDE6|[#\*0-9]\uFE0F\u20E3|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83D\uDC69(?:\uD83C[\uDFFB-\uDFFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|\uD83C\uDDF0(?:\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF])|\uD83C\uDDED(?:\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA])|\uD83C\uDDE9(?:\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|\uD83C\uDDEC(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE])|\uD83C\uDDF8(?:\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF])|\uD83C\uDDEB(?:\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7])|\uD83C\uDDF5(?:\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE])|\uD83C\uDDFB(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA])|\uD83C\uDDF3(?:\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF])|\uD83C\uDDE8(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF])|\uD83C\uDDF1(?:\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE])|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDFC(?:\uD83C[\uDDEB\uDDF8])|\uD83C\uDDFA(?:\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF])|\uD83C\uDDEE(?:\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9])|\uD83C\uDDEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270A-\u270D]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC70\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDCAA\uDD74\uDD7A\uDD90\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD36\uDDB5\uDDB6\uDDBB\uDDD2-\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5\uDEEB\uDEEC\uDEF4-\uDEFA\uDFE0-\uDFEB]|\uD83E[\uDD0D-\uDD3A\uDD3C-\uDD45\uDD47-\uDD71\uDD73-\uDD76\uDD7A-\uDDA2\uDDA5-\uDDAA\uDDAE-\uDDCA\uDDCD-\uDDFF\uDE70-\uDE73\uDE78-\uDE7A\uDE80-\uDE82\uDE90-\uDE95])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFA\uDFE0-\uDFEB]|\uD83E[\uDD0D-\uDD3A\uDD3C-\uDD45\uDD47-\uDD71\uDD73-\uDD76\uDD7A-\uDDA2\uDDA5-\uDDAA\uDDAE-\uDDCA\uDDCD-\uDDFF\uDE70-\uDE73\uDE78-\uDE7A\uDE80-\uDE82\uDE90-\uDE95])\uFE0F|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g; }
@param {Doc} doc @param {number} size @param {number} tabWidth
emojiRegex
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
stringWidth = string => { string = string.replace(emojiRegex(), ' '); if (typeof string !== 'string' || string.length === 0) { return 0; } string = stripAnsi(string); let width = 0; for (let i = 0; i < string.length; i++) { const code = string.codePointAt(i); // Ignore control characters if (code <= 0x1F || code >= 0x7F && code <= 0x9F) { continue; } // Ignore combining characters if (code >= 0x300 && code <= 0x36F) { continue; } // Surrogates if (code > 0xFFFF) { i++; } width += isFullwidthCodePoint_1(code) ? 2 : 1; } return width; }
@param {Doc} doc @param {number} size @param {number} tabWidth
stringWidth
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
stringWidth = string => { string = string.replace(emojiRegex(), ' '); if (typeof string !== 'string' || string.length === 0) { return 0; } string = stripAnsi(string); let width = 0; for (let i = 0; i < string.length; i++) { const code = string.codePointAt(i); // Ignore control characters if (code <= 0x1F || code >= 0x7F && code <= 0x9F) { continue; } // Ignore combining characters if (code >= 0x300 && code <= 0x36F) { continue; } // Surrogates if (code > 0xFFFF) { i++; } width += isFullwidthCodePoint_1(code) ? 2 : 1; } return width; }
@param {Doc} doc @param {number} size @param {number} tabWidth
stringWidth
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function getPenultimate(arr) { if (arr.length > 1) { return arr[arr.length - 2]; } return null; }
@param {Doc} doc @param {number} size @param {number} tabWidth
getPenultimate
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function skip(chars) { return (text, index, opts) => { const backwards = opts && opts.backwards; // Allow `skip` functions to be threaded together without having // to check for failures (did someone say monads?). if (index === false) { return false; } const { length } = text; let cursor = index; while (cursor >= 0 && cursor < length) { const c = text.charAt(cursor); if (chars instanceof RegExp) { if (!chars.test(c)) { return cursor; } } else if (!chars.includes(c)) { return cursor; } backwards ? cursor-- : cursor++; } if (cursor === -1 || cursor === length) { // If we reached the beginning or end of the file, return the // out-of-bounds cursor. It's up to the caller to handle this // correctly. We don't want to indicate `false` though if it // actually skipped valid characters. return cursor; } return false; }; }
@param {string | RegExp} chars @returns {(text: string, index: number | false, opts?: SkipOptions) => number | false}
skip
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function skipInlineComment(text, index) { if (index === false) { return false; } if (text.charAt(index) === "/" && text.charAt(index + 1) === "*") { for (let i = index + 2; i < text.length; ++i) { if (text.charAt(i) === "*" && text.charAt(i + 1) === "/") { return i + 2; } } } return index; }
@param {string} text @param {number | false} index @returns {number | false}
skipInlineComment
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function skipTrailingComment(text, index) { if (index === false) { return false; } if (text.charAt(index) === "/" && text.charAt(index + 1) === "/") { return skipEverythingButNewLine(text, index); } return index; }
@param {string} text @param {number | false} index @returns {number | false}
skipTrailingComment
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function skipNewline(text, index, opts) { const backwards = opts && opts.backwards; if (index === false) { return false; } const atIndex = text.charAt(index); if (backwards) { if (text.charAt(index - 1) === "\r" && atIndex === "\n") { return index - 2; } if (atIndex === "\n" || atIndex === "\r" || atIndex === "\u2028" || atIndex === "\u2029") { return index - 1; } } else { if (atIndex === "\r" && text.charAt(index + 1) === "\n") { return index + 2; } if (atIndex === "\n" || atIndex === "\r" || atIndex === "\u2028" || atIndex === "\u2029") { return index + 1; } } return index; }
@param {string} text @param {number | false} index @param {SkipOptions=} opts @returns {number | false}
skipNewline
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function hasNewline(text, index, opts) { opts = opts || {}; const idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts); const idx2 = skipNewline(text, idx, opts); return idx !== idx2; }
@param {string} text @param {number} index @param {SkipOptions=} opts @returns {boolean}
hasNewline
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function hasNewlineInRange(text, start, end) { for (let i = start; i < end; ++i) { if (text.charAt(i) === "\n") { return true; } } return false; }
@param {string} text @param {number} start @param {number} end @returns {boolean}
hasNewlineInRange
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function isPreviousLineEmpty(text, node, locStart) { /** @type {number | false} */ let idx = locStart(node) - 1; idx = skipSpaces(text, idx, { backwards: true }); idx = skipNewline(text, idx, { backwards: true }); idx = skipSpaces(text, idx, { backwards: true }); const idx2 = skipNewline(text, idx, { backwards: true }); return idx !== idx2; }
@template N @param {string} text @param {N} node @param {(node: N) => number} locStart
isPreviousLineEmpty
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function isNextLineEmptyAfterIndex(text, index) { /** @type {number | false} */ let oldIdx = null; /** @type {number | false} */ let idx = index; while (idx !== oldIdx) { // We need to skip all the potential trailing inline comments oldIdx = idx; idx = skipToLineEnd(text, idx); idx = skipInlineComment(text, idx); idx = skipSpaces(text, idx); } idx = skipTrailingComment(text, idx); idx = skipNewline(text, idx); return idx !== false && hasNewline(text, idx); }
@param {string} text @param {number} index @returns {boolean}
isNextLineEmptyAfterIndex
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function isNextLineEmpty(text, node, locEnd) { return isNextLineEmptyAfterIndex(text, locEnd(node)); }
@template N @param {string} text @param {N} node @param {(node: N) => number} locEnd @returns {boolean}
isNextLineEmpty
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, idx) { /** @type {number | false} */ let oldIdx = null; /** @type {number | false} */ let nextIdx = idx; while (nextIdx !== oldIdx) { oldIdx = nextIdx; nextIdx = skipSpaces(text, nextIdx); nextIdx = skipInlineComment(text, nextIdx); nextIdx = skipTrailingComment(text, nextIdx); nextIdx = skipNewline(text, nextIdx); } return nextIdx; }
@param {string} text @param {number} idx @returns {number | false}
getNextNonSpaceNonCommentCharacterIndexWithStartIndex
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd) { return getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, locEnd(node)); }
@template N @param {string} text @param {N} node @param {(node: N) => number} locEnd @returns {number | false}
getNextNonSpaceNonCommentCharacterIndex
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function getNextNonSpaceNonCommentCharacter(text, node, locEnd) { return text.charAt( // @ts-ignore => TBD: can return false, should we define a fallback? getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd)); }
@template N @param {string} text @param {N} node @param {(node: N) => number} locEnd @returns {string}
getNextNonSpaceNonCommentCharacter
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function hasSpaces(text, index, opts) { opts = opts || {}; const idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts); return idx !== index; }
@param {string} text @param {number} index @param {SkipOptions=} opts @returns {boolean}
hasSpaces
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function setLocStart(node, index) { if (node.range) { node.range[0] = index; } else { node.start = index; } }
@param {{range?: [number, number], start?: number}} node @param {number} index
setLocStart
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function setLocEnd(node, index) { if (node.range) { node.range[1] = index; } else { node.end = index; } }
@param {{range?: [number, number], end?: number}} node @param {number} index
setLocEnd
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function getPrecedence(op) { return PRECEDENCE[op]; }
@param {{range?: [number, number], end?: number}} node @param {number} index
getPrecedence
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function shouldFlatten(parentOp, nodeOp) { if (getPrecedence(nodeOp) !== getPrecedence(parentOp)) { return false; } // ** is right-associative // x ** y ** z --> x ** (y ** z) if (parentOp === "**") { return false; } // x == y == z --> (x == y) == z if (equalityOperators[parentOp] && equalityOperators[nodeOp]) { return false; } // x * y % z --> (x * y) % z if (nodeOp === "%" && multiplicativeOperators[parentOp] || parentOp === "%" && multiplicativeOperators[nodeOp]) { return false; } // x * y / z --> (x * y) / z // x / y * z --> (x / y) * z if (nodeOp !== parentOp && multiplicativeOperators[nodeOp] && multiplicativeOperators[parentOp]) { return false; } // x << y << z --> (x << y) << z if (bitshiftOperators[parentOp] && bitshiftOperators[nodeOp]) { return false; } return true; }
@param {{range?: [number, number], end?: number}} node @param {number} index
shouldFlatten
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function isBitwiseOperator(operator) { return !!bitshiftOperators[operator] || operator === "|" || operator === "^" || operator === "&"; } // Tests if an expression starts with `{`, or (if forbidFunctionClassAndDoExpr
@param {{range?: [number, number], end?: number}} node @param {number} index
isBitwiseOperator
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function startsWithNoLookaheadToken(node, forbidFunctionClassAndDoExpr) { node = getLeftMost(node); switch (node.type) { case "FunctionExpression": case "ClassExpression": case "DoExpression": return forbidFunctionClassAndDoExpr; case "ObjectExpression": return true; case "MemberExpression": case "OptionalMemberExpression": return startsWithNoLookaheadToken(node.object, forbidFunctionClassAndDoExpr); case "TaggedTemplateExpression": if (node.tag.type === "FunctionExpression") { // IIFEs are always already parenthesized return false; } return startsWithNoLookaheadToken(node.tag, forbidFunctionClassAndDoExpr); case "CallExpression": case "OptionalCallExpression": if (node.callee.type === "FunctionExpression") { // IIFEs are always already parenthesized return false; } return startsWithNoLookaheadToken(node.callee, forbidFunctionClassAndDoExpr); case "ConditionalExpression": return startsWithNoLookaheadToken(node.test, forbidFunctionClassAndDoExpr); case "UpdateExpression": return !node.prefix && startsWithNoLookaheadToken(node.argument, forbidFunctionClassAndDoExpr); case "BindExpression": return node.object && startsWithNoLookaheadToken(node.object, forbidFunctionClassAndDoExpr); case "SequenceExpression": return startsWithNoLookaheadToken(node.expressions[0], forbidFunctionClassAndDoExpr); case "TSAsExpression": return startsWithNoLookaheadToken(node.expression, forbidFunctionClassAndDoExpr); default: return false; } }
@param {{range?: [number, number], end?: number}} node @param {number} index
startsWithNoLookaheadToken
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function getLeftMost(node) { if (node.left) { return getLeftMost(node.left); } return node; }
@param {{range?: [number, number], end?: number}} node @param {number} index
getLeftMost
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function getAlignmentSize(value, tabWidth, startIndex) { startIndex = startIndex || 0; let size = 0; for (let i = startIndex; i < value.length; ++i) { if (value[i] === "\t") { // Tabs behave in a way that they are aligned to the nearest // multiple of tabWidth: // 0 -> 4, 1 -> 4, 2 -> 4, 3 -> 4 // 4 -> 8, 5 -> 8, 6 -> 8, 7 -> 8 ... size = size + tabWidth - size % tabWidth; } else { size++; } } return size; }
@param {string} value @param {number} tabWidth @param {number=} startIndex @returns {number}
getAlignmentSize
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function getIndentSize(value, tabWidth) { const lastNewlineIndex = value.lastIndexOf("\n"); if (lastNewlineIndex === -1) { return 0; } return getAlignmentSize( // All the leading whitespaces value.slice(lastNewlineIndex + 1).match(/^[\t ]*/)[0], tabWidth); }
@param {string} value @param {number} tabWidth @returns {number}
getIndentSize
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function getPreferredQuote(raw, preferredQuote) { // `rawContent` is the string exactly like it appeared in the input source // code, without its enclosing quotes. const rawContent = raw.slice(1, -1); /** @type {{ quote: '"', regex: RegExp }} */ const double = { quote: '"', regex: /"/g }; /** @type {{ quote: "'", regex: RegExp }} */ const single = { quote: "'", regex: /'/g }; const preferred = preferredQuote === "'" ? single : double; const alternate = preferred === single ? double : single; let result = preferred.quote; // If `rawContent` contains at least one of the quote preferred for enclosing // the string, we might want to enclose with the alternate quote instead, to // minimize the number of escaped quotes. if (rawContent.includes(preferred.quote) || rawContent.includes(alternate.quote)) { const numPreferredQuotes = (rawContent.match(preferred.regex) || []).length; const numAlternateQuotes = (rawContent.match(alternate.regex) || []).length; result = numPreferredQuotes > numAlternateQuotes ? alternate.quote : preferred.quote; } return result; }
@param {string} raw @param {Quote} preferredQuote @returns {Quote}
getPreferredQuote
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function makeString(rawContent, enclosingQuote, unescapeUnnecessaryEscapes) { const otherQuote = enclosingQuote === '"' ? "'" : '"'; // Matches _any_ escape and unescaped quotes (both single and double). const regex = /\\([\S\s])|(["'])/g; // Escape and unescape single and double quotes as needed to be able to // enclose `rawContent` with `enclosingQuote`. const newContent = rawContent.replace(regex, (match, escaped, quote) => { // If we matched an escape, and the escaped character is a quote of the // other type than we intend to enclose the string with, there's no need for // it to be escaped, so return it _without_ the backslash. if (escaped === otherQuote) { return escaped; } // If we matched an unescaped quote and it is of the _same_ type as we // intend to enclose the string with, it must be escaped, so return it with // a backslash. if (quote === enclosingQuote) { return "\\" + quote; } if (quote) { return quote; } // Unescape any unnecessarily escaped character. // Adapted from https://github.com/eslint/eslint/blob/de0b4ad7bd820ade41b1f606008bea68683dc11a/lib/rules/no-useless-escape.js#L27 return unescapeUnnecessaryEscapes && /^[^\n\r"'0-7\\bfnrt-vx\u2028\u2029]$/.test(escaped) ? escaped : "\\" + escaped; }); return enclosingQuote + newContent + enclosingQuote; }
@param {string} rawContent @param {Quote} enclosingQuote @param {boolean=} unescapeUnnecessaryEscapes @returns {string}
makeString
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function printNumber(rawNumber) { return rawNumber.toLowerCase() // Remove unnecessary plus and zeroes from scientific notation. .replace(/^([+-]?[\d.]+e)(?:\+|(-))?0*(\d)/, "$1$2$3") // Remove unnecessary scientific notation (1e0). .replace(/^([+-]?[\d.]+)e[+-]?0+$/, "$1") // Make sure numbers always start with a digit. .replace(/^([+-])?\./, "$10.") // Remove extraneous trailing decimal zeroes. .replace(/(\.\d+?)0+(?=e|$)/, "$1") // Remove trailing dot. .replace(/\.(?=e|$)/, ""); }
@param {string} rawContent @param {Quote} enclosingQuote @param {boolean=} unescapeUnnecessaryEscapes @returns {string}
printNumber
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function getMaxContinuousCount(str, target) { const results = str.match(new RegExp(`(${escapeStringRegexp$2(target)})+`, "g")); if (results === null) { return 0; } return results.reduce((maxCount, result) => Math.max(maxCount, result.length / target.length), 0); }
@param {string} str @param {string} target @returns {number}
getMaxContinuousCount
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function getMinNotPresentContinuousCount(str, target) { const matches = str.match(new RegExp(`(${escapeStringRegexp$2(target)})+`, "g")); if (matches === null) { return 0; } const countPresent = new Map(); let max = 0; for (const match of matches) { const count = match.length / target.length; countPresent.set(count, true); if (count > max) { max = count; } } for (let i = 1; i < max; i++) { if (!countPresent.get(i)) { return i; } } return max + 1; }
@param {string} str @param {string} target @returns {number}
getMinNotPresentContinuousCount
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
match(...predicates) { let stackPointer = this.stack.length - 1; let name = null; let node = this.stack[stackPointer--]; for (const predicate of predicates) { if (node === undefined) { return false; } // skip index/array let number = null; if (typeof name === "number") { number = name; name = this.stack[stackPointer--]; node = this.stack[stackPointer--]; } if (predicate && !predicate(node, name, number)) { return false; } name = this.stack[stackPointer--]; node = this.stack[stackPointer--]; } return true; }
@param {...( | ((node: any, name: string | null, number: number | null) => boolean) | undefined )} predicates
match
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function printSubtree(path, print, options, printAstToDoc) { if (options.printer.embed && options.embeddedLanguageFormatting === "auto") { return options.printer.embed(path, print, (text, partialNextOptions) => textToDoc(text, partialNextOptions, options, printAstToDoc), options); } }
@param {...( | ((node: any, name: string | null, number: number | null) => boolean) | undefined )} predicates
printSubtree
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function textToDoc(text, partialNextOptions, parentOptions, printAstToDoc) { const nextOptions = normalize$2(Object.assign(Object.assign(Object.assign({}, parentOptions), partialNextOptions), {}, { parentParser: parentOptions.parser, embeddedInHtml: !!(parentOptions.embeddedInHtml || parentOptions.parser === "html" || parentOptions.parser === "vue" || parentOptions.parser === "angular" || parentOptions.parser === "lwc"), originalText: text }), { passThrough: true }); const result = parser.parse(text, nextOptions); const { ast } = result; text = result.text; const astComments = ast.comments; delete ast.comments; comments.attach(astComments, ast, text, nextOptions); return printAstToDoc(ast, nextOptions); }
@param {...( | ((node: any, name: string | null, number: number | null) => boolean) | undefined )} predicates
textToDoc
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
make_regex = (pattern, negative, ignorecase) => { const r = cache[pattern]; if (r) { return r; } const replacers = negative ? NEGATIVE_REPLACERS : POSITIVE_REPLACERS; const source = replacers.reduce((prev, current) => prev.replace(current[0], current[1].bind(pattern)), pattern); return cache[pattern] = ignorecase ? new RegExp(source, 'i') : new RegExp(source); }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
make_regex
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
make_regex = (pattern, negative, ignorecase) => { const r = cache[pattern]; if (r) { return r; } const replacers = negative ? NEGATIVE_REPLACERS : POSITIVE_REPLACERS; const source = replacers.reduce((prev, current) => prev.replace(current[0], current[1].bind(pattern)), pattern); return cache[pattern] = ignorecase ? new RegExp(source, 'i') : new RegExp(source); }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
make_regex
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
checkPattern = pattern => pattern && typeof pattern === 'string' && !REGEX_BLANK_LINE.test(pattern) // > A line starting with # serves as a comment. && pattern.indexOf('#') !== 0
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
checkPattern
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
checkPattern = pattern => pattern && typeof pattern === 'string' && !REGEX_BLANK_LINE.test(pattern) // > A line starting with # serves as a comment. && pattern.indexOf('#') !== 0
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
checkPattern
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
createRule = (pattern, ignorecase) => { const origin = pattern; let negative = false; // > An optional prefix "!" which negates the pattern; if (pattern.indexOf('!') === 0) { negative = true; pattern = pattern.substr(1); } pattern = pattern // > Put a backslash ("\") in front of the first "!" for patterns that // > begin with a literal "!", for example, `"\!important!.txt"`. .replace(REGEX_LEADING_EXCAPED_EXCLAMATION, '!') // > Put a backslash ("\") in front of the first hash for patterns that // > begin with a hash. .replace(REGEX_LEADING_EXCAPED_HASH, '#'); const regex = make_regex(pattern, negative, ignorecase); return { origin, pattern, negative, regex }; }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
createRule
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
createRule = (pattern, ignorecase) => { const origin = pattern; let negative = false; // > An optional prefix "!" which negates the pattern; if (pattern.indexOf('!') === 0) { negative = true; pattern = pattern.substr(1); } pattern = pattern // > Put a backslash ("\") in front of the first "!" for patterns that // > begin with a literal "!", for example, `"\!important!.txt"`. .replace(REGEX_LEADING_EXCAPED_EXCLAMATION, '!') // > Put a backslash ("\") in front of the first hash for patterns that // > begin with a hash. .replace(REGEX_LEADING_EXCAPED_HASH, '#'); const regex = make_regex(pattern, negative, ignorecase); return { origin, pattern, negative, regex }; }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
createRule
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
constructor({ ignorecase = true } = {}) { this._rules = []; this._ignorecase = ignorecase; define(this, KEY_IGNORE, true); this._initCache(); }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
constructor
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
_initCache() { this._cache = Object.create(null); }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
_initCache
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
add(pattern) { this._added = false; if (typeof pattern === 'string') { pattern = pattern.split(/\r?\n/g); } make_array(pattern).forEach(this._addPattern, this); // Some rules have just added to the ignore, // making the behavior changed. if (this._added) { this._initCache(); } return this; }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
add
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
addPattern(pattern) { return this.add(pattern); }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
addPattern
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
_addPattern(pattern) { // #32 if (pattern && pattern[KEY_IGNORE]) { this._rules = this._rules.concat(pattern._rules); this._added = true; return; } if (checkPattern(pattern)) { const rule = createRule(pattern, this._ignorecase); this._added = true; this._rules.push(rule); } }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
_addPattern
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
filter(paths) { return make_array(paths).filter(path => this._filter(path)); }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
filter
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
createFilter() { return path => this._filter(path); }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
createFilter
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
ignores(path) { return !this._filter(path); }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
ignores
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
_filter(path, slices) { if (!path) { return false; } if (path in this._cache) { return this._cache[path]; } if (!slices) { // path/to/a.js // ['path', 'to', 'a.js'] slices = path.split(SLASH); } slices.pop(); return this._cache[path] = slices.length // > It is not possible to re-include a file if a parent directory of // > that file is excluded. // If the path contains a parent directory, check the parent first ? this._filter(slices.join(SLASH) + SLASH, slices) && this._test(path) // Or only test the path : this._test(path); }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
_filter
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
_test(path) { // Explicitly define variable type by setting matched to `0` let matched = 0; this._rules.forEach(rule => { // if matched = true, then we only test negative rules // if matched = false, then we test non-negative rules if (!(matched ^ rule.negative)) { matched = rule.negative ^ rule.regex.test(path); } }); return !matched; }
// > A trailing `"/**"` matches everything inside. // #21: everything inside but it should not include the current folder : '\\/.+'], // intermediate wildcards [// Never replace escaped '*' // ignore rule '\*' will match the path '*' // 'abc.
_test
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function getFileContentOrNull(filename) { return new Promise((resolve, reject) => { fs$3.readFile(filename, "utf8", (error, data) => { if (error && error.code !== "ENOENT") { reject(createError(filename, error)); } else { resolve(error ? null : data); } }); }); }
@param {string} filename @returns {Promise<null | string>}
getFileContentOrNull
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function createError(filename, error) { return new Error(`Unable to read ${filename}: ${error.message}`); }
@param {string} filename @returns {null | string}
createError
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
async function createIgnorer(ignorePath, withNodeModules) { const ignoreContent = ignorePath ? await getFileContentOrNull_1(path$2.resolve(ignorePath)) : null; return _createIgnorer(ignoreContent, withNodeModules); }
@param {undefined | string} ignorePath @param {undefined | boolean} withNodeModules
createIgnorer
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function _createIgnorer(ignoreContent, withNodeModules) { const ignorer = ignore().add(ignoreContent || ""); if (!withNodeModules) { ignorer.add("node_modules"); } return ignorer; }
@param {null | string} ignoreContent @param {undefined | boolean} withNodeModules
_createIgnorer
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
concatMap = function (xs, fn) { var res = []; for (var i = 0; i < xs.length; i++) { var x = fn(xs[i], i); if (isArray(x)) res.push.apply(res, x);else res.push(x); } return res; }
@param {null | string} ignoreContent @param {undefined | boolean} withNodeModules
concatMap
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function balanced(a, b, str) { if (a instanceof RegExp) a = maybeMatch(a, str); if (b instanceof RegExp) b = maybeMatch(b, str); var r = range(a, b, str); return r && { start: r[0], end: r[1], pre: str.slice(0, r[0]), body: str.slice(r[0] + a.length, r[1]), post: str.slice(r[1] + b.length) }; }
@param {null | string} ignoreContent @param {undefined | boolean} withNodeModules
balanced
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function maybeMatch(reg, str) { var m = str.match(reg); return m ? m[0] : null; }
@param {null | string} ignoreContent @param {undefined | boolean} withNodeModules
maybeMatch
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0
function range(a, b, str) { var begs, beg, left, right, result; var ai = str.indexOf(a); var bi = str.indexOf(b, ai + 1); var i = ai; if (ai >= 0 && bi > 0) { begs = []; left = str.length; while (i >= 0 && !result) { if (i == ai) { begs.push(i); ai = str.indexOf(a, i + 1); } else if (begs.length == 1) { result = [begs.pop(), bi]; } else { beg = begs.pop(); if (beg < left) { left = beg; right = bi; } bi = str.indexOf(b, i + 1); } i = ai < bi && ai >= 0 ? ai : bi; } if (begs.length) { result = [left, right]; } } return result; }
@param {null | string} ignoreContent @param {undefined | boolean} withNodeModules
range
javascript
douyu/juno
assets/public/js/prettier/v2.0.5/index.js
https://github.com/douyu/juno/blob/master/assets/public/js/prettier/v2.0.5/index.js
Apache-2.0