WIP: bootstrap and partial real Solana watcher implementation
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
|
||||
var _super_prop_base = require("./_super_prop_base.cjs");
|
||||
|
||||
function _get(target, property, receiver) {
|
||||
if (typeof Reflect !== "undefined" && Reflect.get) exports._ = _get = Reflect.get;
|
||||
else {
|
||||
exports._ = _get = function get(target, property, receiver) {
|
||||
var base = _super_prop_base._(target, property);
|
||||
|
||||
if (!base) return;
|
||||
|
||||
var desc = Object.getOwnPropertyDescriptor(base, property);
|
||||
|
||||
if (desc.get) return desc.get.call(receiver || target);
|
||||
|
||||
return desc.value;
|
||||
};
|
||||
}
|
||||
|
||||
return _get(target, property, receiver || target);
|
||||
}
|
||||
exports._ = _get;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Blake2s hash function. Focuses on 8-bit to 32-bit platforms. blake2b for 64-bit, but in JS it is slower.
|
||||
* @module
|
||||
* @deprecated
|
||||
*/
|
||||
import { G1s as G1s_n, G2s as G2s_n } from "./_blake.js";
|
||||
import { SHA256_IV } from "./_md.js";
|
||||
import { BLAKE2s as B2S, blake2s as b2s, compress as compress_n } from "./blake2.js";
|
||||
/** @deprecated Use import from `noble/hashes/blake2` module */
|
||||
export const B2S_IV = SHA256_IV;
|
||||
/** @deprecated Use import from `noble/hashes/blake2` module */
|
||||
export const G1s = G1s_n;
|
||||
/** @deprecated Use import from `noble/hashes/blake2` module */
|
||||
export const G2s = G2s_n;
|
||||
/** @deprecated Use import from `noble/hashes/blake2` module */
|
||||
export const compress = compress_n;
|
||||
/** @deprecated Use import from `noble/hashes/blake2` module */
|
||||
export const BLAKE2s = B2S;
|
||||
/** @deprecated Use import from `noble/hashes/blake2` module */
|
||||
export const blake2s = b2s;
|
||||
//# sourceMappingURL=blake2s.js.map
|
||||
@@ -0,0 +1,17 @@
|
||||
import * as core from "../core/index.cjs";
|
||||
import * as schemas from "./schemas.cjs";
|
||||
export interface ZodCoercedString<T = unknown> extends schemas._ZodString<core.$ZodStringInternals<T>> {
|
||||
}
|
||||
export declare function string<T = unknown>(params?: string | core.$ZodStringParams): ZodCoercedString<T>;
|
||||
export interface ZodCoercedNumber<T = unknown> extends schemas._ZodNumber<core.$ZodNumberInternals<T>> {
|
||||
}
|
||||
export declare function number<T = unknown>(params?: string | core.$ZodNumberParams): ZodCoercedNumber<T>;
|
||||
export interface ZodCoercedBoolean<T = unknown> extends schemas._ZodBoolean<core.$ZodBooleanInternals<T>> {
|
||||
}
|
||||
export declare function boolean<T = unknown>(params?: string | core.$ZodBooleanParams): ZodCoercedBoolean<T>;
|
||||
export interface ZodCoercedBigInt<T = unknown> extends schemas._ZodBigInt<core.$ZodBigIntInternals<T>> {
|
||||
}
|
||||
export declare function bigint<T = unknown>(params?: string | core.$ZodBigIntParams): ZodCoercedBigInt<T>;
|
||||
export interface ZodCoercedDate<T = unknown> extends schemas._ZodDate<core.$ZodDateInternals<T>> {
|
||||
}
|
||||
export declare function date<T = unknown>(params?: string | core.$ZodDateParams): ZodCoercedDate<T>;
|
||||
@@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
// THIS CODE WAS AUTOMATICALLY GENERATED
|
||||
// DO NOT EDIT THIS CODE BY HAND
|
||||
// RUN THE FOLLOWING COMMAND FROM THE WORKSPACE ROOT TO REGENERATE:
|
||||
// npx nx generate-lib repo
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.es2017_intl = void 0;
|
||||
const base_config_1 = require("./base-config");
|
||||
exports.es2017_intl = {
|
||||
libs: [],
|
||||
variables: [['Intl', base_config_1.TYPE_VALUE]],
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"main": "../../cjs/_overload_yield.cjs",
|
||||
"module": "../../esm/_overload_yield.js"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
'use strict'
|
||||
|
||||
const fs = require('node:fs')
|
||||
const path = require('node:path')
|
||||
let { version } = require('../package.json')
|
||||
|
||||
let passedVersion = process.argv[2]
|
||||
|
||||
if (passedVersion) {
|
||||
passedVersion = passedVersion.trim().replace(/^v/, '')
|
||||
if (version !== passedVersion) {
|
||||
console.log(`Syncing version from ${version} to ${passedVersion}`)
|
||||
version = passedVersion
|
||||
const packageJson = require('../package.json')
|
||||
packageJson.version = version
|
||||
fs.writeFileSync(path.resolve('./package.json'), JSON.stringify(packageJson, null, 2) + '\n', { encoding: 'utf-8' })
|
||||
}
|
||||
}
|
||||
|
||||
const metaContent = `'use strict'
|
||||
|
||||
module.exports = { version: '${version}' }
|
||||
`
|
||||
|
||||
fs.writeFileSync(path.resolve('./lib/meta.js'), metaContent, { encoding: 'utf-8' })
|
||||
@@ -0,0 +1,202 @@
|
||||
/**
|
||||
* @fileoverview Traverser to traverse AST trees.
|
||||
* @author Nicholas C. Zakas
|
||||
* @author Toru Nagashima
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const vk = require("eslint-visitor-keys");
|
||||
const debug = require("debug")("eslint:traverser");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Do nothing.
|
||||
* @returns {void}
|
||||
*/
|
||||
function noop() {
|
||||
// do nothing.
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the given value is an ASTNode or not.
|
||||
* @param {any} x The value to check.
|
||||
* @returns {boolean} `true` if the value is an ASTNode.
|
||||
*/
|
||||
function isNode(x) {
|
||||
return x !== null && typeof x === "object" && typeof x.type === "string";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the visitor keys of a given node.
|
||||
* @param {Object} visitorKeys The map of visitor keys.
|
||||
* @param {ASTNode} node The node to get their visitor keys.
|
||||
* @returns {string[]} The visitor keys of the node.
|
||||
*/
|
||||
function getVisitorKeys(visitorKeys, node) {
|
||||
let keys = visitorKeys[node.type];
|
||||
|
||||
if (!keys) {
|
||||
keys = vk.getKeys(node);
|
||||
debug(
|
||||
'Unknown node type "%s": Estimated visitor keys %j',
|
||||
node.type,
|
||||
keys,
|
||||
);
|
||||
}
|
||||
|
||||
return keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* The traverser class to traverse AST trees.
|
||||
*/
|
||||
class Traverser {
|
||||
constructor() {
|
||||
this._current = null;
|
||||
this._parents = [];
|
||||
this._skipped = false;
|
||||
this._broken = false;
|
||||
this._visitorKeys = null;
|
||||
this._enter = null;
|
||||
this._leave = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives current node.
|
||||
* @returns {ASTNode} The current node.
|
||||
*/
|
||||
current() {
|
||||
return this._current;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives a copy of the ancestor nodes.
|
||||
* @returns {ASTNode[]} The ancestor nodes.
|
||||
*/
|
||||
parents() {
|
||||
return this._parents.slice(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Break the current traversal.
|
||||
* @returns {void}
|
||||
*/
|
||||
break() {
|
||||
this._broken = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Skip child nodes for the current traversal.
|
||||
* @returns {void}
|
||||
*/
|
||||
skip() {
|
||||
this._skipped = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Traverse the given AST tree.
|
||||
* @param {ASTNode} node The root node to traverse.
|
||||
* @param {Object} options The option object.
|
||||
* @param {Object} [options.visitorKeys=DEFAULT_VISITOR_KEYS] The keys of each node types to traverse child nodes. Default is `./default-visitor-keys.json`.
|
||||
* @param {Function} [options.enter=noop] The callback function which is called on entering each node.
|
||||
* @param {Function} [options.leave=noop] The callback function which is called on leaving each node.
|
||||
* @returns {void}
|
||||
*/
|
||||
traverse(node, options) {
|
||||
this._current = null;
|
||||
this._parents = [];
|
||||
this._skipped = false;
|
||||
this._broken = false;
|
||||
this._visitorKeys = options.visitorKeys || vk.KEYS;
|
||||
this._enter = options.enter || noop;
|
||||
this._leave = options.leave || noop;
|
||||
this._traverse(node, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Traverse the given AST tree recursively.
|
||||
* @param {ASTNode} node The current node.
|
||||
* @param {ASTNode|null} parent The parent node.
|
||||
* @returns {void}
|
||||
* @private
|
||||
*/
|
||||
_traverse(node, parent) {
|
||||
if (!isNode(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._current = node;
|
||||
this._skipped = false;
|
||||
this._enter(node, parent);
|
||||
|
||||
if (!this._skipped && !this._broken) {
|
||||
const keys = getVisitorKeys(this._visitorKeys, node);
|
||||
|
||||
if (keys.length >= 1) {
|
||||
this._parents.push(node);
|
||||
for (let i = 0; i < keys.length && !this._broken; ++i) {
|
||||
const child = node[keys[i]];
|
||||
|
||||
if (Array.isArray(child)) {
|
||||
for (
|
||||
let j = 0;
|
||||
j < child.length && !this._broken;
|
||||
++j
|
||||
) {
|
||||
this._traverse(child[j], node);
|
||||
}
|
||||
} else {
|
||||
this._traverse(child, node);
|
||||
}
|
||||
}
|
||||
this._parents.pop();
|
||||
}
|
||||
}
|
||||
|
||||
if (!this._broken) {
|
||||
this._leave(node, parent);
|
||||
}
|
||||
|
||||
this._current = parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the keys to use for traversal.
|
||||
* @param {ASTNode} node The node to read keys from.
|
||||
* @returns {string[]} An array of keys to visit on the node.
|
||||
* @private
|
||||
*/
|
||||
static getKeys(node) {
|
||||
return vk.getKeys(node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Traverse the given AST tree.
|
||||
* @param {ASTNode} node The root node to traverse.
|
||||
* @param {Object} options The option object.
|
||||
* @param {Object} [options.visitorKeys=DEFAULT_VISITOR_KEYS] The keys of each node types to traverse child nodes. Default is `./default-visitor-keys.json`.
|
||||
* @param {Function} [options.enter=noop] The callback function which is called on entering each node.
|
||||
* @param {Function} [options.leave=noop] The callback function which is called on leaving each node.
|
||||
* @returns {void}
|
||||
*/
|
||||
static traverse(node, options) {
|
||||
new Traverser().traverse(node, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* The default visitor keys.
|
||||
* @type {Object}
|
||||
*/
|
||||
static get DEFAULT_VISITOR_KEYS() {
|
||||
return vk.KEYS;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Traverser;
|
||||
@@ -0,0 +1,22 @@
|
||||
import { E as Environment } from './chunks/environment.d.CrsxCzP1.js';
|
||||
export { a as EnvironmentReturn, V as VmEnvironmentReturn } from './chunks/environment.d.CrsxCzP1.js';
|
||||
import '@vitest/utils';
|
||||
|
||||
declare const environments: {
|
||||
"node": Environment;
|
||||
"jsdom": Environment;
|
||||
"happy-dom": Environment;
|
||||
"edge-runtime": Environment;
|
||||
};
|
||||
|
||||
interface PopulateOptions {
|
||||
bindFunctions?: boolean;
|
||||
additionalKeys?: string[];
|
||||
}
|
||||
declare function populateGlobal(global: any, win: any, options?: PopulateOptions): {
|
||||
keys: Set<string>;
|
||||
skipKeys: string[];
|
||||
originals: Map<string | symbol, any>;
|
||||
};
|
||||
|
||||
export { Environment, environments as builtinEnvironments, populateGlobal };
|
||||
@@ -0,0 +1,7 @@
|
||||
// Code generated by Herebyfile.mjs generate:enums from internal/checker/types.go. DO NOT EDIT.
|
||||
export var SignatureKind;
|
||||
(function (SignatureKind) {
|
||||
SignatureKind[SignatureKind["Call"] = 0] = "Call";
|
||||
SignatureKind[SignatureKind["Construct"] = 1] = "Construct";
|
||||
})(SignatureKind || (SignatureKind = {}));
|
||||
//# sourceMappingURL=signatureKind.enum.js.map
|
||||
@@ -0,0 +1,132 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = default_1;
|
||||
const util = __importStar(require("../core/util.cjs"));
|
||||
const error = () => {
|
||||
const Sizable = {
|
||||
string: { unit: "simvol", verb: "olmalıdır" },
|
||||
file: { unit: "bayt", verb: "olmalıdır" },
|
||||
array: { unit: "element", verb: "olmalıdır" },
|
||||
set: { unit: "element", verb: "olmalıdır" },
|
||||
};
|
||||
function getSizing(origin) {
|
||||
return Sizable[origin] ?? null;
|
||||
}
|
||||
const FormatDictionary = {
|
||||
regex: "input",
|
||||
email: "email address",
|
||||
url: "URL",
|
||||
emoji: "emoji",
|
||||
uuid: "UUID",
|
||||
uuidv4: "UUIDv4",
|
||||
uuidv6: "UUIDv6",
|
||||
nanoid: "nanoid",
|
||||
guid: "GUID",
|
||||
cuid: "cuid",
|
||||
cuid2: "cuid2",
|
||||
ulid: "ULID",
|
||||
xid: "XID",
|
||||
ksuid: "KSUID",
|
||||
datetime: "ISO datetime",
|
||||
date: "ISO date",
|
||||
time: "ISO time",
|
||||
duration: "ISO duration",
|
||||
ipv4: "IPv4 address",
|
||||
ipv6: "IPv6 address",
|
||||
cidrv4: "IPv4 range",
|
||||
cidrv6: "IPv6 range",
|
||||
base64: "base64-encoded string",
|
||||
base64url: "base64url-encoded string",
|
||||
json_string: "JSON string",
|
||||
e164: "E.164 number",
|
||||
jwt: "JWT",
|
||||
template_literal: "input",
|
||||
};
|
||||
const TypeDictionary = {
|
||||
nan: "NaN",
|
||||
};
|
||||
return (issue) => {
|
||||
switch (issue.code) {
|
||||
case "invalid_type": {
|
||||
const expected = TypeDictionary[issue.expected] ?? issue.expected;
|
||||
const receivedType = util.parsedType(issue.input);
|
||||
const received = TypeDictionary[receivedType] ?? receivedType;
|
||||
if (/^[A-Z]/.test(issue.expected)) {
|
||||
return `Yanlış dəyər: gözlənilən instanceof ${issue.expected}, daxil olan ${received}`;
|
||||
}
|
||||
return `Yanlış dəyər: gözlənilən ${expected}, daxil olan ${received}`;
|
||||
}
|
||||
case "invalid_value":
|
||||
if (issue.values.length === 1)
|
||||
return `Yanlış dəyər: gözlənilən ${util.stringifyPrimitive(issue.values[0])}`;
|
||||
return `Yanlış seçim: aşağıdakılardan biri olmalıdır: ${util.joinValues(issue.values, "|")}`;
|
||||
case "too_big": {
|
||||
const adj = issue.inclusive ? "<=" : "<";
|
||||
const sizing = getSizing(issue.origin);
|
||||
if (sizing)
|
||||
return `Çox böyük: gözlənilən ${issue.origin ?? "dəyər"} ${adj}${issue.maximum.toString()} ${sizing.unit ?? "element"}`;
|
||||
return `Çox böyük: gözlənilən ${issue.origin ?? "dəyər"} ${adj}${issue.maximum.toString()}`;
|
||||
}
|
||||
case "too_small": {
|
||||
const adj = issue.inclusive ? ">=" : ">";
|
||||
const sizing = getSizing(issue.origin);
|
||||
if (sizing)
|
||||
return `Çox kiçik: gözlənilən ${issue.origin} ${adj}${issue.minimum.toString()} ${sizing.unit}`;
|
||||
return `Çox kiçik: gözlənilən ${issue.origin} ${adj}${issue.minimum.toString()}`;
|
||||
}
|
||||
case "invalid_format": {
|
||||
const _issue = issue;
|
||||
if (_issue.format === "starts_with")
|
||||
return `Yanlış mətn: "${_issue.prefix}" ilə başlamalıdır`;
|
||||
if (_issue.format === "ends_with")
|
||||
return `Yanlış mətn: "${_issue.suffix}" ilə bitməlidir`;
|
||||
if (_issue.format === "includes")
|
||||
return `Yanlış mətn: "${_issue.includes}" daxil olmalıdır`;
|
||||
if (_issue.format === "regex")
|
||||
return `Yanlış mətn: ${_issue.pattern} şablonuna uyğun olmalıdır`;
|
||||
return `Yanlış ${FormatDictionary[_issue.format] ?? issue.format}`;
|
||||
}
|
||||
case "not_multiple_of":
|
||||
return `Yanlış ədəd: ${issue.divisor} ilə bölünə bilən olmalıdır`;
|
||||
case "unrecognized_keys":
|
||||
return `Tanınmayan açar${issue.keys.length > 1 ? "lar" : ""}: ${util.joinValues(issue.keys, ", ")}`;
|
||||
case "invalid_key":
|
||||
return `${issue.origin} daxilində yanlış açar`;
|
||||
case "invalid_union":
|
||||
return "Yanlış dəyər";
|
||||
case "invalid_element":
|
||||
return `${issue.origin} daxilində yanlış dəyər`;
|
||||
default:
|
||||
return `Yanlış dəyər`;
|
||||
}
|
||||
};
|
||||
};
|
||||
function default_1() {
|
||||
return {
|
||||
localeError: error(),
|
||||
};
|
||||
}
|
||||
module.exports = exports.default;
|
||||
@@ -0,0 +1,505 @@
|
||||
"use strict";
|
||||
// This rule was feature-frozen before we enabled no-property-in-node.
|
||||
/* eslint-disable eslint-plugin/no-property-in-node */
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const scope_manager_1 = require("@typescript-eslint/scope-manager");
|
||||
const utils_1 = require("@typescript-eslint/utils");
|
||||
const util_1 = require("../util");
|
||||
const naming_convention_utils_1 = require("./naming-convention-utils");
|
||||
// This essentially mirrors ESLint's `camelcase` rule
|
||||
// note that that rule ignores leading and trailing underscores and only checks those in the middle of a variable name
|
||||
const defaultCamelCaseAllTheThingsConfig = [
|
||||
{
|
||||
format: ['camelCase'],
|
||||
leadingUnderscore: 'allow',
|
||||
selector: 'default',
|
||||
trailingUnderscore: 'allow',
|
||||
},
|
||||
{
|
||||
format: ['camelCase', 'PascalCase'],
|
||||
selector: 'import',
|
||||
},
|
||||
{
|
||||
format: ['camelCase', 'UPPER_CASE'],
|
||||
leadingUnderscore: 'allow',
|
||||
selector: 'variable',
|
||||
trailingUnderscore: 'allow',
|
||||
},
|
||||
{
|
||||
format: ['PascalCase'],
|
||||
selector: 'typeLike',
|
||||
},
|
||||
];
|
||||
exports.default = (0, util_1.createRule)({
|
||||
name: 'naming-convention',
|
||||
meta: {
|
||||
type: 'suggestion',
|
||||
docs: {
|
||||
description: 'Enforce naming conventions for everything across a codebase',
|
||||
// technically only requires type checking if the user uses "type" modifiers
|
||||
frozen: true,
|
||||
requiresTypeChecking: true,
|
||||
},
|
||||
messages: {
|
||||
doesNotMatchFormat: '{{type}} name `{{name}}` must match one of the following formats: {{formats}}',
|
||||
doesNotMatchFormatTrimmed: '{{type}} name `{{name}}` trimmed as `{{processedName}}` must match one of the following formats: {{formats}}',
|
||||
missingAffix: '{{type}} name `{{name}}` must have one of the following {{position}}es: {{affixes}}',
|
||||
missingUnderscore: '{{type}} name `{{name}}` must have {{count}} {{position}} underscore(s).',
|
||||
satisfyCustom: '{{type}} name `{{name}}` must {{regexMatch}} the RegExp: {{regex}}',
|
||||
unexpectedUnderscore: '{{type}} name `{{name}}` must not have a {{position}} underscore.',
|
||||
},
|
||||
schema: naming_convention_utils_1.SCHEMA,
|
||||
},
|
||||
defaultOptions: defaultCamelCaseAllTheThingsConfig,
|
||||
create(contextWithoutDefaults) {
|
||||
const context = contextWithoutDefaults.options.length > 0
|
||||
? contextWithoutDefaults
|
||||
: // only apply the defaults when the user provides no config
|
||||
Object.setPrototypeOf({
|
||||
options: defaultCamelCaseAllTheThingsConfig,
|
||||
}, contextWithoutDefaults);
|
||||
const validators = (0, naming_convention_utils_1.parseOptions)(context);
|
||||
const compilerOptions = (0, util_1.getParserServices)(context, true).program?.getCompilerOptions() ?? {};
|
||||
function handleMember(validator, node, modifiers) {
|
||||
const key = node.key;
|
||||
if (requiresQuoting(key, compilerOptions.target)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.requiresQuotes);
|
||||
}
|
||||
validator(key, modifiers);
|
||||
}
|
||||
function getMemberModifiers(node) {
|
||||
const modifiers = new Set();
|
||||
if ('key' in node && node.key.type === utils_1.AST_NODE_TYPES.PrivateIdentifier) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers['#private']);
|
||||
}
|
||||
else if (node.accessibility) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers[node.accessibility]);
|
||||
}
|
||||
else {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.public);
|
||||
}
|
||||
if (node.static) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.static);
|
||||
}
|
||||
if ('readonly' in node && node.readonly) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.readonly);
|
||||
}
|
||||
if ('override' in node && node.override) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.override);
|
||||
}
|
||||
if (node.type === utils_1.AST_NODE_TYPES.TSAbstractPropertyDefinition ||
|
||||
node.type === utils_1.AST_NODE_TYPES.TSAbstractMethodDefinition ||
|
||||
node.type === utils_1.AST_NODE_TYPES.TSAbstractAccessorProperty) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.abstract);
|
||||
}
|
||||
return modifiers;
|
||||
}
|
||||
const { unusedVariables } = (0, util_1.collectVariables)(context);
|
||||
function isUnused(name, initialScope) {
|
||||
let variable = null;
|
||||
let scope = initialScope;
|
||||
while (scope) {
|
||||
variable = scope.set.get(name) ?? null;
|
||||
if (variable) {
|
||||
break;
|
||||
}
|
||||
scope = scope.upper;
|
||||
}
|
||||
if (!variable) {
|
||||
return false;
|
||||
}
|
||||
return unusedVariables.has(variable);
|
||||
}
|
||||
function isDestructured(id) {
|
||||
return (
|
||||
// `const { x }`
|
||||
// does not match `const { x: y }`
|
||||
(id.parent.type === utils_1.AST_NODE_TYPES.Property && id.parent.shorthand) ||
|
||||
// `const { x = 2 }`
|
||||
// does not match const `{ x: y = 2 }`
|
||||
(id.parent.type === utils_1.AST_NODE_TYPES.AssignmentPattern &&
|
||||
id.parent.parent.type === utils_1.AST_NODE_TYPES.Property &&
|
||||
id.parent.parent.shorthand));
|
||||
}
|
||||
function isAsyncMemberOrProperty(propertyOrMemberNode) {
|
||||
return Boolean('value' in propertyOrMemberNode &&
|
||||
propertyOrMemberNode.value &&
|
||||
'async' in propertyOrMemberNode.value &&
|
||||
propertyOrMemberNode.value.async);
|
||||
}
|
||||
function isAsyncVariableIdentifier(id) {
|
||||
return Boolean(('async' in id.parent && id.parent.async) ||
|
||||
('init' in id.parent &&
|
||||
id.parent.init &&
|
||||
'async' in id.parent.init &&
|
||||
id.parent.init.async));
|
||||
}
|
||||
const selectors = {
|
||||
// #region import
|
||||
'FunctionDeclaration, TSDeclareFunction, FunctionExpression': {
|
||||
handler: (node, validator) => {
|
||||
if (node.id == null) {
|
||||
return;
|
||||
}
|
||||
const modifiers = new Set();
|
||||
// functions create their own nested scope
|
||||
const scope = context.sourceCode.getScope(node).upper;
|
||||
if (isGlobal(scope)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.global);
|
||||
}
|
||||
if (isExported(node, node.id.name, scope)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.exported);
|
||||
}
|
||||
if (isUnused(node.id.name, scope)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.unused);
|
||||
}
|
||||
if (node.async) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.async);
|
||||
}
|
||||
validator(node.id, modifiers);
|
||||
},
|
||||
validator: validators.function,
|
||||
},
|
||||
// #endregion
|
||||
// #region variable
|
||||
'ImportDefaultSpecifier, ImportNamespaceSpecifier, ImportSpecifier': {
|
||||
handler: (node, validator) => {
|
||||
const modifiers = new Set();
|
||||
switch (node.type) {
|
||||
case utils_1.AST_NODE_TYPES.ImportDefaultSpecifier:
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.default);
|
||||
break;
|
||||
case utils_1.AST_NODE_TYPES.ImportNamespaceSpecifier:
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.namespace);
|
||||
break;
|
||||
case utils_1.AST_NODE_TYPES.ImportSpecifier:
|
||||
// Handle `import { default as Foo }`
|
||||
if (node.imported.type === utils_1.AST_NODE_TYPES.Identifier &&
|
||||
node.imported.name !== 'default') {
|
||||
return;
|
||||
}
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.default);
|
||||
break;
|
||||
}
|
||||
validator(node.local, modifiers);
|
||||
},
|
||||
validator: validators.import,
|
||||
},
|
||||
// #endregion
|
||||
// #region function
|
||||
VariableDeclarator: {
|
||||
handler: (node, validator) => {
|
||||
const identifiers = getIdentifiersFromPattern(node.id);
|
||||
const baseModifiers = new Set();
|
||||
const parent = node.parent;
|
||||
if (parent.kind === 'const') {
|
||||
baseModifiers.add(naming_convention_utils_1.Modifiers.const);
|
||||
}
|
||||
if (isGlobal(context.sourceCode.getScope(node))) {
|
||||
baseModifiers.add(naming_convention_utils_1.Modifiers.global);
|
||||
}
|
||||
identifiers.forEach(id => {
|
||||
const modifiers = new Set(baseModifiers);
|
||||
if (isDestructured(id)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.destructured);
|
||||
}
|
||||
const scope = context.sourceCode.getScope(id);
|
||||
if (isExported(parent, id.name, scope)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.exported);
|
||||
}
|
||||
if (isUnused(id.name, scope)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.unused);
|
||||
}
|
||||
if (isAsyncVariableIdentifier(id)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.async);
|
||||
}
|
||||
validator(id, modifiers);
|
||||
});
|
||||
},
|
||||
validator: validators.variable,
|
||||
},
|
||||
// #endregion function
|
||||
// #region parameter
|
||||
':matches(PropertyDefinition, TSAbstractPropertyDefinition)[computed = false][value.type != "ArrowFunctionExpression"][value.type != "FunctionExpression"][value.type != "TSEmptyBodyFunctionExpression"]': {
|
||||
handler: (node, validator) => {
|
||||
const modifiers = getMemberModifiers(node);
|
||||
handleMember(validator, node, modifiers);
|
||||
},
|
||||
validator: validators.classProperty,
|
||||
},
|
||||
// #endregion parameter
|
||||
// #region parameterProperty
|
||||
':not(ObjectPattern) > Property[computed = false][kind = "init"][value.type != "ArrowFunctionExpression"][value.type != "FunctionExpression"][value.type != "TSEmptyBodyFunctionExpression"]': {
|
||||
handler: (node, validator) => {
|
||||
const modifiers = new Set([naming_convention_utils_1.Modifiers.public]);
|
||||
handleMember(validator, node, modifiers);
|
||||
},
|
||||
validator: validators.objectLiteralProperty,
|
||||
},
|
||||
// #endregion parameterProperty
|
||||
// #region property
|
||||
[[
|
||||
':matches(PropertyDefinition, TSAbstractPropertyDefinition)[computed = false][value.type = "ArrowFunctionExpression"]',
|
||||
':matches(PropertyDefinition, TSAbstractPropertyDefinition)[computed = false][value.type = "FunctionExpression"]',
|
||||
':matches(PropertyDefinition, TSAbstractPropertyDefinition)[computed = false][value.type = "TSEmptyBodyFunctionExpression"]',
|
||||
':matches(MethodDefinition, TSAbstractMethodDefinition)[computed = false][kind = "method"]',
|
||||
].join(', ')]: {
|
||||
handler: (node, validator) => {
|
||||
const modifiers = getMemberModifiers(node);
|
||||
if (isAsyncMemberOrProperty(node)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.async);
|
||||
}
|
||||
handleMember(validator, node, modifiers);
|
||||
},
|
||||
validator: validators.classMethod,
|
||||
},
|
||||
[[
|
||||
'MethodDefinition[computed = false]:matches([kind = "get"], [kind = "set"])',
|
||||
'TSAbstractMethodDefinition[computed = false]:matches([kind="get"], [kind="set"])',
|
||||
].join(', ')]: {
|
||||
handler: (node, validator) => {
|
||||
const modifiers = getMemberModifiers(node);
|
||||
handleMember(validator, node, modifiers);
|
||||
},
|
||||
validator: validators.classicAccessor,
|
||||
},
|
||||
[[
|
||||
'Property[computed = false][kind = "init"][value.type = "ArrowFunctionExpression"]',
|
||||
'Property[computed = false][kind = "init"][value.type = "FunctionExpression"]',
|
||||
'Property[computed = false][kind = "init"][value.type = "TSEmptyBodyFunctionExpression"]',
|
||||
].join(', ')]: {
|
||||
handler: (node, validator) => {
|
||||
const modifiers = new Set([naming_convention_utils_1.Modifiers.public]);
|
||||
if (isAsyncMemberOrProperty(node)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.async);
|
||||
}
|
||||
handleMember(validator, node, modifiers);
|
||||
},
|
||||
validator: validators.objectLiteralMethod,
|
||||
},
|
||||
// #endregion property
|
||||
// #region method
|
||||
[[
|
||||
'TSMethodSignature[computed = false]',
|
||||
'TSPropertySignature[computed = false][typeAnnotation.typeAnnotation.type = "TSFunctionType"]',
|
||||
].join(', ')]: {
|
||||
handler: (node, validator) => {
|
||||
const modifiers = new Set([naming_convention_utils_1.Modifiers.public]);
|
||||
handleMember(validator, node, modifiers);
|
||||
},
|
||||
validator: validators.typeMethod,
|
||||
},
|
||||
[[
|
||||
utils_1.AST_NODE_TYPES.AccessorProperty,
|
||||
utils_1.AST_NODE_TYPES.TSAbstractAccessorProperty,
|
||||
].join(', ')]: {
|
||||
handler: (node, validator) => {
|
||||
const modifiers = getMemberModifiers(node);
|
||||
handleMember(validator, node, modifiers);
|
||||
},
|
||||
validator: validators.autoAccessor,
|
||||
},
|
||||
'FunctionDeclaration, TSDeclareFunction, TSEmptyBodyFunctionExpression, FunctionExpression, ArrowFunctionExpression': {
|
||||
handler: (node, validator) => {
|
||||
node.params.forEach(param => {
|
||||
if (param.type === utils_1.AST_NODE_TYPES.TSParameterProperty) {
|
||||
return;
|
||||
}
|
||||
const identifiers = getIdentifiersFromPattern(param);
|
||||
identifiers.forEach(i => {
|
||||
const modifiers = new Set();
|
||||
if (isDestructured(i)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.destructured);
|
||||
}
|
||||
if (isUnused(i.name, context.sourceCode.getScope(i))) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.unused);
|
||||
}
|
||||
validator(i, modifiers);
|
||||
});
|
||||
});
|
||||
},
|
||||
validator: validators.parameter,
|
||||
},
|
||||
// #endregion method
|
||||
// #region accessor
|
||||
'Property[computed = false]:matches([kind = "get"], [kind = "set"])': {
|
||||
handler: (node, validator) => {
|
||||
const modifiers = new Set([naming_convention_utils_1.Modifiers.public]);
|
||||
handleMember(validator, node, modifiers);
|
||||
},
|
||||
validator: validators.classicAccessor,
|
||||
},
|
||||
TSParameterProperty: {
|
||||
handler: (node, validator) => {
|
||||
const modifiers = getMemberModifiers(node);
|
||||
const identifiers = getIdentifiersFromPattern(node.parameter);
|
||||
identifiers.forEach(i => {
|
||||
validator(i, modifiers);
|
||||
});
|
||||
},
|
||||
validator: validators.parameterProperty,
|
||||
},
|
||||
// #endregion accessor
|
||||
// #region autoAccessor
|
||||
'TSPropertySignature[computed = false][typeAnnotation.typeAnnotation.type != "TSFunctionType"]': {
|
||||
handler: (node, validator) => {
|
||||
const modifiers = new Set([naming_convention_utils_1.Modifiers.public]);
|
||||
if (node.readonly) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.readonly);
|
||||
}
|
||||
handleMember(validator, node, modifiers);
|
||||
},
|
||||
validator: validators.typeProperty,
|
||||
},
|
||||
// #endregion autoAccessor
|
||||
// #region enumMember
|
||||
// computed is optional, so can't do [computed = false]
|
||||
'ClassDeclaration, ClassExpression': {
|
||||
handler: (node, validator) => {
|
||||
const id = node.id;
|
||||
if (id == null) {
|
||||
return;
|
||||
}
|
||||
const modifiers = new Set();
|
||||
// classes create their own nested scope
|
||||
const scope = context.sourceCode.getScope(node).upper;
|
||||
if (node.abstract) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.abstract);
|
||||
}
|
||||
if (isExported(node, id.name, scope)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.exported);
|
||||
}
|
||||
if (isUnused(id.name, scope)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.unused);
|
||||
}
|
||||
validator(id, modifiers);
|
||||
},
|
||||
validator: validators.class,
|
||||
},
|
||||
// #endregion enumMember
|
||||
// #region class
|
||||
TSEnumDeclaration: {
|
||||
handler: (node, validator) => {
|
||||
const modifiers = new Set();
|
||||
// enums create their own nested scope
|
||||
const scope = context.sourceCode.getScope(node).upper;
|
||||
if (isExported(node, node.id.name, scope)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.exported);
|
||||
}
|
||||
if (isUnused(node.id.name, scope)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.unused);
|
||||
}
|
||||
validator(node.id, modifiers);
|
||||
},
|
||||
validator: validators.enum,
|
||||
},
|
||||
// #endregion class
|
||||
// #region interface
|
||||
TSEnumMember: {
|
||||
handler: (node, validator) => {
|
||||
const id = node.id;
|
||||
const modifiers = new Set();
|
||||
if (requiresQuoting(id, compilerOptions.target)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.requiresQuotes);
|
||||
}
|
||||
validator(id, modifiers);
|
||||
},
|
||||
validator: validators.enumMember,
|
||||
},
|
||||
// #endregion interface
|
||||
// #region typeAlias
|
||||
TSInterfaceDeclaration: {
|
||||
handler: (node, validator) => {
|
||||
const modifiers = new Set();
|
||||
const scope = context.sourceCode.getScope(node);
|
||||
if (isExported(node, node.id.name, scope)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.exported);
|
||||
}
|
||||
if (isUnused(node.id.name, scope)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.unused);
|
||||
}
|
||||
validator(node.id, modifiers);
|
||||
},
|
||||
validator: validators.interface,
|
||||
},
|
||||
// #endregion typeAlias
|
||||
// #region enum
|
||||
TSTypeAliasDeclaration: {
|
||||
handler: (node, validator) => {
|
||||
const modifiers = new Set();
|
||||
const scope = context.sourceCode.getScope(node);
|
||||
if (isExported(node, node.id.name, scope)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.exported);
|
||||
}
|
||||
if (isUnused(node.id.name, scope)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.unused);
|
||||
}
|
||||
validator(node.id, modifiers);
|
||||
},
|
||||
validator: validators.typeAlias,
|
||||
},
|
||||
// #endregion enum
|
||||
// #region typeParameter
|
||||
'TSTypeParameterDeclaration > TSTypeParameter': {
|
||||
handler: (node, validator) => {
|
||||
const modifiers = new Set();
|
||||
const scope = context.sourceCode.getScope(node);
|
||||
if (isUnused(node.name.name, scope)) {
|
||||
modifiers.add(naming_convention_utils_1.Modifiers.unused);
|
||||
}
|
||||
validator(node.name, modifiers);
|
||||
},
|
||||
validator: validators.typeParameter,
|
||||
},
|
||||
// #endregion typeParameter
|
||||
};
|
||||
return Object.fromEntries(Object.entries(selectors).map(([selector, { handler, validator }]) => {
|
||||
return [
|
||||
selector,
|
||||
(node) => {
|
||||
handler(node, validator);
|
||||
},
|
||||
];
|
||||
}));
|
||||
},
|
||||
});
|
||||
function getIdentifiersFromPattern(pattern) {
|
||||
const identifiers = [];
|
||||
const visitor = new scope_manager_1.PatternVisitor({}, pattern, id => identifiers.push(id));
|
||||
visitor.visit(pattern);
|
||||
return identifiers;
|
||||
}
|
||||
function isExported(node, name, scope) {
|
||||
if (node?.parent?.type === utils_1.AST_NODE_TYPES.ExportDefaultDeclaration ||
|
||||
node?.parent?.type === utils_1.AST_NODE_TYPES.ExportNamedDeclaration) {
|
||||
return true;
|
||||
}
|
||||
if (scope == null) {
|
||||
return false;
|
||||
}
|
||||
const variable = scope.set.get(name);
|
||||
if (variable) {
|
||||
for (const ref of variable.references) {
|
||||
const refParent = ref.identifier.parent;
|
||||
if (refParent.type === utils_1.AST_NODE_TYPES.ExportDefaultDeclaration ||
|
||||
refParent.type === utils_1.AST_NODE_TYPES.ExportSpecifier) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function isGlobal(scope) {
|
||||
if (scope == null) {
|
||||
return false;
|
||||
}
|
||||
return (scope.type === utils_1.TSESLint.Scope.ScopeType.global ||
|
||||
scope.type === utils_1.TSESLint.Scope.ScopeType.module);
|
||||
}
|
||||
function requiresQuoting(node, target) {
|
||||
const name = node.type === utils_1.AST_NODE_TYPES.Identifier ||
|
||||
node.type === utils_1.AST_NODE_TYPES.PrivateIdentifier
|
||||
? node.name
|
||||
: `${node.value}`;
|
||||
return (0, util_1.requiresQuoting)(name, target);
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* @author Toru Nagashima <https://github.com/mysticatea>
|
||||
* See LICENSE file in root directory for full license.
|
||||
*/
|
||||
import KEYS from "./visitor-keys.js";
|
||||
|
||||
/**
|
||||
* @typedef {import('./visitor-keys.js').VisitorKeys} VisitorKeys
|
||||
*/
|
||||
|
||||
// List to ignore keys.
|
||||
const KEY_BLACKLIST = new Set([
|
||||
"parent",
|
||||
"leadingComments",
|
||||
"trailingComments"
|
||||
]);
|
||||
|
||||
/**
|
||||
* Check whether a given key should be used or not.
|
||||
* @param {string} key The key to check.
|
||||
* @returns {boolean} `true` if the key should be used.
|
||||
*/
|
||||
function filterKey(key) {
|
||||
return !KEY_BLACKLIST.has(key) && key[0] !== "_";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get visitor keys of a given node.
|
||||
* @param {object} node The AST node to get keys.
|
||||
* @returns {readonly string[]} Visitor keys of the node.
|
||||
*/
|
||||
export function getKeys(node) {
|
||||
return Object.keys(node).filter(filterKey);
|
||||
}
|
||||
|
||||
// Disable valid-jsdoc rule because it reports syntax error on the type of @returns.
|
||||
// eslint-disable-next-line valid-jsdoc
|
||||
/**
|
||||
* Make the union set with `KEYS` and given keys.
|
||||
* @param {VisitorKeys} additionalKeys The additional keys.
|
||||
* @returns {VisitorKeys} The union set.
|
||||
*/
|
||||
export function unionWith(additionalKeys) {
|
||||
const retv = /** @type {{
|
||||
[type: string]: ReadonlyArray<string>
|
||||
}} */ (Object.assign({}, KEYS));
|
||||
|
||||
for (const type of Object.keys(additionalKeys)) {
|
||||
if (Object.prototype.hasOwnProperty.call(retv, type)) {
|
||||
const keys = new Set(additionalKeys[type]);
|
||||
|
||||
for (const key of retv[type]) {
|
||||
keys.add(key);
|
||||
}
|
||||
|
||||
retv[type] = Object.freeze(Array.from(keys));
|
||||
} else {
|
||||
retv[type] = Object.freeze(Array.from(additionalKeys[type]));
|
||||
}
|
||||
}
|
||||
|
||||
return Object.freeze(retv);
|
||||
}
|
||||
|
||||
export { KEYS };
|
||||
@@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
const http = require('http');
|
||||
const utils = require('../utils');
|
||||
|
||||
/**
|
||||
* Constructor for a Jayson HTTP server
|
||||
* @class ServerHttp
|
||||
* @extends require('http').Server
|
||||
* @param {Server} server Server instance
|
||||
* @param {Object} [options] Options for this instance
|
||||
* @return {ServerHttp}
|
||||
*/
|
||||
const ServerHttp = function(server, options) {
|
||||
if(!(this instanceof ServerHttp)) {
|
||||
return new ServerHttp(server, options);
|
||||
}
|
||||
|
||||
this.options = utils.merge(server.options, options || {});
|
||||
|
||||
const listener = utils.getHttpListener(this, server);
|
||||
http.Server.call(this, listener);
|
||||
};
|
||||
require('util').inherits(ServerHttp, http.Server);
|
||||
|
||||
module.exports = ServerHttp;
|
||||
@@ -0,0 +1,72 @@
|
||||
{
|
||||
"name": "process-warning",
|
||||
"version": "5.1.0",
|
||||
"description": "A small utility for creating warnings and emitting them.",
|
||||
"main": "index.js",
|
||||
"type": "commonjs",
|
||||
"types": "types/index.d.ts",
|
||||
"scripts": {
|
||||
"lint": "eslint",
|
||||
"lint:fix": "eslint --fix",
|
||||
"test": "npm run test:unit && npm run test:jest && npm run test:typescript",
|
||||
"test:jest": "jest jest.test.js",
|
||||
"test:unit": "c8 --100 node --test",
|
||||
"test:typescript": "tstyche"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/fastify/process-warning.git"
|
||||
},
|
||||
"keywords": [
|
||||
"fastify",
|
||||
"error",
|
||||
"warning",
|
||||
"utility",
|
||||
"plugin",
|
||||
"emit",
|
||||
"once"
|
||||
],
|
||||
"author": "Tomas Della Vedova",
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Matteo Collina",
|
||||
"email": "hello@matteocollina.com"
|
||||
},
|
||||
{
|
||||
"name": "Manuel Spigolon",
|
||||
"email": "behemoth89@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "James Sumners",
|
||||
"url": "https://james.sumners.info"
|
||||
},
|
||||
{
|
||||
"name": "Frazer Smith",
|
||||
"email": "frazer.dev@icloud.com",
|
||||
"url": "https://github.com/fdawgs"
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/fastify/fastify-warning/issues"
|
||||
},
|
||||
"homepage": "https://github.com/fastify/fastify-warning#readme",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/fastify"
|
||||
},
|
||||
{
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/fastify"
|
||||
}
|
||||
],
|
||||
"devDependencies": {
|
||||
"benchmark": "^2.1.4",
|
||||
"c8": "^12.0.0",
|
||||
"eslint": "^9.17.0",
|
||||
"jest": "^30.0.3",
|
||||
"neostandard": "^0.13.0",
|
||||
"tstyche": "^7.0.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
declare namespace Intl {
|
||||
// http://cldr.unicode.org/index/cldr-spec/plural-rules#TOC-Determining-Plural-Categories
|
||||
type LDMLPluralRule = "zero" | "one" | "two" | "few" | "many" | "other";
|
||||
type PluralRuleType = "cardinal" | "ordinal";
|
||||
|
||||
interface PluralRulesOptions {
|
||||
localeMatcher?: "lookup" | "best fit" | undefined;
|
||||
type?: PluralRuleType | undefined;
|
||||
minimumIntegerDigits?: number | undefined;
|
||||
minimumFractionDigits?: number | undefined;
|
||||
maximumFractionDigits?: number | undefined;
|
||||
minimumSignificantDigits?: number | undefined;
|
||||
maximumSignificantDigits?: number | undefined;
|
||||
}
|
||||
|
||||
interface ResolvedPluralRulesOptions {
|
||||
locale: string;
|
||||
pluralCategories: LDMLPluralRule[];
|
||||
type: PluralRuleType;
|
||||
minimumIntegerDigits: number;
|
||||
minimumFractionDigits: number;
|
||||
maximumFractionDigits: number;
|
||||
minimumSignificantDigits?: number;
|
||||
maximumSignificantDigits?: number;
|
||||
}
|
||||
|
||||
interface PluralRules {
|
||||
resolvedOptions(): ResolvedPluralRulesOptions;
|
||||
select(n: number): LDMLPluralRule;
|
||||
}
|
||||
|
||||
interface PluralRulesConstructor {
|
||||
new (locales?: string | readonly string[], options?: PluralRulesOptions): PluralRules;
|
||||
(locales?: string | readonly string[], options?: PluralRulesOptions): PluralRules;
|
||||
supportedLocalesOf(locales: string | readonly string[], options?: { localeMatcher?: "lookup" | "best fit"; }): string[];
|
||||
}
|
||||
|
||||
const PluralRules: PluralRulesConstructor;
|
||||
|
||||
interface NumberFormatPartTypeRegistry {
|
||||
literal: never;
|
||||
nan: never;
|
||||
infinity: never;
|
||||
percent: never;
|
||||
integer: never;
|
||||
group: never;
|
||||
decimal: never;
|
||||
fraction: never;
|
||||
plusSign: never;
|
||||
minusSign: never;
|
||||
percentSign: never;
|
||||
currency: never;
|
||||
}
|
||||
|
||||
type NumberFormatPartTypes = keyof NumberFormatPartTypeRegistry;
|
||||
|
||||
interface NumberFormatPart {
|
||||
type: NumberFormatPartTypes;
|
||||
value: string;
|
||||
}
|
||||
|
||||
interface NumberFormat {
|
||||
formatToParts(number?: number | bigint): NumberFormatPart[];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"for + if": {
|
||||
"name": "for + if",
|
||||
"browser": "Firefox 54.0.0 (Windows 7 0.0.0)",
|
||||
"suite": "itar-long",
|
||||
"hz": 14666.732983263433,
|
||||
"success": true,
|
||||
"fastest": true,
|
||||
"rme": 0.017720925761977167,
|
||||
"rhz": 1,
|
||||
"sampleSize": 206
|
||||
},
|
||||
"while + if": {
|
||||
"name": "while + if",
|
||||
"browser": "Firefox 54.0.0 (Windows 7 0.0.0)",
|
||||
"suite": "itar-long",
|
||||
"hz": 14304.32478751105,
|
||||
"success": true,
|
||||
"fastest": false,
|
||||
"rme": 0.019517232560753738,
|
||||
"rhz": 0.9752904620159148,
|
||||
"sampleSize": 206
|
||||
},
|
||||
"array join": {
|
||||
"name": "array join",
|
||||
"browser": "Firefox 54.0.0 (Windows 7 0.0.0)",
|
||||
"suite": "itar-long",
|
||||
"hz": 14128.325816957695,
|
||||
"success": true,
|
||||
"fastest": false,
|
||||
"rme": 0.02191559968248959,
|
||||
"rhz": 0.9632905864639297,
|
||||
"sampleSize": 212
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,410 @@
|
||||
# buffer [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url]
|
||||
|
||||
[travis-image]: https://img.shields.io/travis/feross/buffer/master.svg
|
||||
[travis-url]: https://travis-ci.org/feross/buffer
|
||||
[npm-image]: https://img.shields.io/npm/v/buffer.svg
|
||||
[npm-url]: https://npmjs.org/package/buffer
|
||||
[downloads-image]: https://img.shields.io/npm/dm/buffer.svg
|
||||
[downloads-url]: https://npmjs.org/package/buffer
|
||||
[standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg
|
||||
[standard-url]: https://standardjs.com
|
||||
|
||||
#### The buffer module from [node.js](https://nodejs.org/), for the browser.
|
||||
|
||||
[![saucelabs][saucelabs-image]][saucelabs-url]
|
||||
|
||||
[saucelabs-image]: https://saucelabs.com/browser-matrix/buffer.svg
|
||||
[saucelabs-url]: https://saucelabs.com/u/buffer
|
||||
|
||||
With [browserify](http://browserify.org), simply `require('buffer')` or use the `Buffer` global and you will get this module.
|
||||
|
||||
The goal is to provide an API that is 100% identical to
|
||||
[node's Buffer API](https://nodejs.org/api/buffer.html). Read the
|
||||
[official docs](https://nodejs.org/api/buffer.html) for the full list of properties,
|
||||
instance methods, and class methods that are supported.
|
||||
|
||||
## features
|
||||
|
||||
- Manipulate binary data like a boss, in all browsers!
|
||||
- Super fast. Backed by Typed Arrays (`Uint8Array`/`ArrayBuffer`, not `Object`)
|
||||
- Extremely small bundle size (**6.75KB minified + gzipped**, 51.9KB with comments)
|
||||
- Excellent browser support (Chrome, Firefox, Edge, Safari 11+, iOS 11+, Android, etc.)
|
||||
- Preserves Node API exactly, with one minor difference (see below)
|
||||
- Square-bracket `buf[4]` notation works!
|
||||
- Does not modify any browser prototypes or put anything on `window`
|
||||
- Comprehensive test suite (including all buffer tests from node.js core)
|
||||
|
||||
## install
|
||||
|
||||
To use this module directly (without browserify), install it:
|
||||
|
||||
```bash
|
||||
npm install buffer
|
||||
```
|
||||
|
||||
This module was previously called **native-buffer-browserify**, but please use **buffer**
|
||||
from now on.
|
||||
|
||||
If you do not use a bundler, you can use the [standalone script](https://bundle.run/buffer).
|
||||
|
||||
## usage
|
||||
|
||||
The module's API is identical to node's `Buffer` API. Read the
|
||||
[official docs](https://nodejs.org/api/buffer.html) for the full list of properties,
|
||||
instance methods, and class methods that are supported.
|
||||
|
||||
As mentioned above, `require('buffer')` or use the `Buffer` global with
|
||||
[browserify](http://browserify.org) and this module will automatically be included
|
||||
in your bundle. Almost any npm module will work in the browser, even if it assumes that
|
||||
the node `Buffer` API will be available.
|
||||
|
||||
To depend on this module explicitly (without browserify), require it like this:
|
||||
|
||||
```js
|
||||
var Buffer = require('buffer/').Buffer // note: the trailing slash is important!
|
||||
```
|
||||
|
||||
To require this module explicitly, use `require('buffer/')` which tells the node.js module
|
||||
lookup algorithm (also used by browserify) to use the **npm module** named `buffer`
|
||||
instead of the **node.js core** module named `buffer`!
|
||||
|
||||
|
||||
## how does it work?
|
||||
|
||||
The Buffer constructor returns instances of `Uint8Array` that have their prototype
|
||||
changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of `Uint8Array`,
|
||||
so the returned instances will have all the node `Buffer` methods and the
|
||||
`Uint8Array` methods. Square bracket notation works as expected -- it returns a
|
||||
single octet.
|
||||
|
||||
The `Uint8Array` prototype remains unmodified.
|
||||
|
||||
|
||||
## tracking the latest node api
|
||||
|
||||
This module tracks the Buffer API in the latest (unstable) version of node.js. The Buffer
|
||||
API is considered **stable** in the
|
||||
[node stability index](https://nodejs.org/docs/latest/api/documentation.html#documentation_stability_index),
|
||||
so it is unlikely that there will ever be breaking changes.
|
||||
Nonetheless, when/if the Buffer API changes in node, this module's API will change
|
||||
accordingly.
|
||||
|
||||
## related packages
|
||||
|
||||
- [`buffer-reverse`](https://www.npmjs.com/package/buffer-reverse) - Reverse a buffer
|
||||
- [`buffer-xor`](https://www.npmjs.com/package/buffer-xor) - Bitwise xor a buffer
|
||||
- [`is-buffer`](https://www.npmjs.com/package/is-buffer) - Determine if an object is a Buffer without including the whole `Buffer` package
|
||||
|
||||
## conversion packages
|
||||
|
||||
### convert typed array to buffer
|
||||
|
||||
Use [`typedarray-to-buffer`](https://www.npmjs.com/package/typedarray-to-buffer) to convert any kind of typed array to a `Buffer`. Does not perform a copy, so it's super fast.
|
||||
|
||||
### convert buffer to typed array
|
||||
|
||||
`Buffer` is a subclass of `Uint8Array` (which is a typed array). So there is no need to explicitly convert to typed array. Just use the buffer as a `Uint8Array`.
|
||||
|
||||
### convert blob to buffer
|
||||
|
||||
Use [`blob-to-buffer`](https://www.npmjs.com/package/blob-to-buffer) to convert a `Blob` to a `Buffer`.
|
||||
|
||||
### convert buffer to blob
|
||||
|
||||
To convert a `Buffer` to a `Blob`, use the `Blob` constructor:
|
||||
|
||||
```js
|
||||
var blob = new Blob([ buffer ])
|
||||
```
|
||||
|
||||
Optionally, specify a mimetype:
|
||||
|
||||
```js
|
||||
var blob = new Blob([ buffer ], { type: 'text/html' })
|
||||
```
|
||||
|
||||
### convert arraybuffer to buffer
|
||||
|
||||
To convert an `ArrayBuffer` to a `Buffer`, use the `Buffer.from` function. Does not perform a copy, so it's super fast.
|
||||
|
||||
```js
|
||||
var buffer = Buffer.from(arrayBuffer)
|
||||
```
|
||||
|
||||
### convert buffer to arraybuffer
|
||||
|
||||
To convert a `Buffer` to an `ArrayBuffer`, use the `.buffer` property (which is present on all `Uint8Array` objects):
|
||||
|
||||
```js
|
||||
var arrayBuffer = buffer.buffer.slice(
|
||||
buffer.byteOffset, buffer.byteOffset + buffer.byteLength
|
||||
)
|
||||
```
|
||||
|
||||
Alternatively, use the [`to-arraybuffer`](https://www.npmjs.com/package/to-arraybuffer) module.
|
||||
|
||||
## performance
|
||||
|
||||
See perf tests in `/perf`.
|
||||
|
||||
`BrowserBuffer` is the browser `buffer` module (this repo). `Uint8Array` is included as a
|
||||
sanity check (since `BrowserBuffer` uses `Uint8Array` under the hood, `Uint8Array` will
|
||||
always be at least a bit faster). Finally, `NodeBuffer` is the node.js buffer module,
|
||||
which is included to compare against.
|
||||
|
||||
NOTE: Performance has improved since these benchmarks were taken. PR welcome to update the README.
|
||||
|
||||
### Chrome 38
|
||||
|
||||
| Method | Operations | Accuracy | Sampled | Fastest |
|
||||
|:-------|:-----------|:---------|:--------|:-------:|
|
||||
| BrowserBuffer#bracket-notation | 11,457,464 ops/sec | ±0.86% | 66 | ✓ |
|
||||
| Uint8Array#bracket-notation | 10,824,332 ops/sec | ±0.74% | 65 | |
|
||||
| | | | |
|
||||
| BrowserBuffer#concat | 450,532 ops/sec | ±0.76% | 68 | |
|
||||
| Uint8Array#concat | 1,368,911 ops/sec | ±1.50% | 62 | ✓ |
|
||||
| | | | |
|
||||
| BrowserBuffer#copy(16000) | 903,001 ops/sec | ±0.96% | 67 | |
|
||||
| Uint8Array#copy(16000) | 1,422,441 ops/sec | ±1.04% | 66 | ✓ |
|
||||
| | | | |
|
||||
| BrowserBuffer#copy(16) | 11,431,358 ops/sec | ±0.46% | 69 | |
|
||||
| Uint8Array#copy(16) | 13,944,163 ops/sec | ±1.12% | 68 | ✓ |
|
||||
| | | | |
|
||||
| BrowserBuffer#new(16000) | 106,329 ops/sec | ±6.70% | 44 | |
|
||||
| Uint8Array#new(16000) | 131,001 ops/sec | ±2.85% | 31 | ✓ |
|
||||
| | | | |
|
||||
| BrowserBuffer#new(16) | 1,554,491 ops/sec | ±1.60% | 65 | |
|
||||
| Uint8Array#new(16) | 6,623,930 ops/sec | ±1.66% | 65 | ✓ |
|
||||
| | | | |
|
||||
| BrowserBuffer#readDoubleBE | 112,830 ops/sec | ±0.51% | 69 | ✓ |
|
||||
| DataView#getFloat64 | 93,500 ops/sec | ±0.57% | 68 | |
|
||||
| | | | |
|
||||
| BrowserBuffer#readFloatBE | 146,678 ops/sec | ±0.95% | 68 | ✓ |
|
||||
| DataView#getFloat32 | 99,311 ops/sec | ±0.41% | 67 | |
|
||||
| | | | |
|
||||
| BrowserBuffer#readUInt32LE | 843,214 ops/sec | ±0.70% | 69 | ✓ |
|
||||
| DataView#getUint32 | 103,024 ops/sec | ±0.64% | 67 | |
|
||||
| | | | |
|
||||
| BrowserBuffer#slice | 1,013,941 ops/sec | ±0.75% | 67 | |
|
||||
| Uint8Array#subarray | 1,903,928 ops/sec | ±0.53% | 67 | ✓ |
|
||||
| | | | |
|
||||
| BrowserBuffer#writeFloatBE | 61,387 ops/sec | ±0.90% | 67 | |
|
||||
| DataView#setFloat32 | 141,249 ops/sec | ±0.40% | 66 | ✓ |
|
||||
|
||||
|
||||
### Firefox 33
|
||||
|
||||
| Method | Operations | Accuracy | Sampled | Fastest |
|
||||
|:-------|:-----------|:---------|:--------|:-------:|
|
||||
| BrowserBuffer#bracket-notation | 20,800,421 ops/sec | ±1.84% | 60 | |
|
||||
| Uint8Array#bracket-notation | 20,826,235 ops/sec | ±2.02% | 61 | ✓ |
|
||||
| | | | |
|
||||
| BrowserBuffer#concat | 153,076 ops/sec | ±2.32% | 61 | |
|
||||
| Uint8Array#concat | 1,255,674 ops/sec | ±8.65% | 52 | ✓ |
|
||||
| | | | |
|
||||
| BrowserBuffer#copy(16000) | 1,105,312 ops/sec | ±1.16% | 63 | |
|
||||
| Uint8Array#copy(16000) | 1,615,911 ops/sec | ±0.55% | 66 | ✓ |
|
||||
| | | | |
|
||||
| BrowserBuffer#copy(16) | 16,357,599 ops/sec | ±0.73% | 68 | |
|
||||
| Uint8Array#copy(16) | 31,436,281 ops/sec | ±1.05% | 68 | ✓ |
|
||||
| | | | |
|
||||
| BrowserBuffer#new(16000) | 52,995 ops/sec | ±6.01% | 35 | |
|
||||
| Uint8Array#new(16000) | 87,686 ops/sec | ±5.68% | 45 | ✓ |
|
||||
| | | | |
|
||||
| BrowserBuffer#new(16) | 252,031 ops/sec | ±1.61% | 66 | |
|
||||
| Uint8Array#new(16) | 8,477,026 ops/sec | ±0.49% | 68 | ✓ |
|
||||
| | | | |
|
||||
| BrowserBuffer#readDoubleBE | 99,871 ops/sec | ±0.41% | 69 | |
|
||||
| DataView#getFloat64 | 285,663 ops/sec | ±0.70% | 68 | ✓ |
|
||||
| | | | |
|
||||
| BrowserBuffer#readFloatBE | 115,540 ops/sec | ±0.42% | 69 | |
|
||||
| DataView#getFloat32 | 288,722 ops/sec | ±0.82% | 68 | ✓ |
|
||||
| | | | |
|
||||
| BrowserBuffer#readUInt32LE | 633,926 ops/sec | ±1.08% | 67 | ✓ |
|
||||
| DataView#getUint32 | 294,808 ops/sec | ±0.79% | 64 | |
|
||||
| | | | |
|
||||
| BrowserBuffer#slice | 349,425 ops/sec | ±0.46% | 69 | |
|
||||
| Uint8Array#subarray | 5,965,819 ops/sec | ±0.60% | 65 | ✓ |
|
||||
| | | | |
|
||||
| BrowserBuffer#writeFloatBE | 59,980 ops/sec | ±0.41% | 67 | |
|
||||
| DataView#setFloat32 | 317,634 ops/sec | ±0.63% | 68 | ✓ |
|
||||
|
||||
### Safari 8
|
||||
|
||||
| Method | Operations | Accuracy | Sampled | Fastest |
|
||||
|:-------|:-----------|:---------|:--------|:-------:|
|
||||
| BrowserBuffer#bracket-notation | 10,279,729 ops/sec | ±2.25% | 56 | ✓ |
|
||||
| Uint8Array#bracket-notation | 10,030,767 ops/sec | ±2.23% | 59 | |
|
||||
| | | | |
|
||||
| BrowserBuffer#concat | 144,138 ops/sec | ±1.38% | 65 | |
|
||||
| Uint8Array#concat | 4,950,764 ops/sec | ±1.70% | 63 | ✓ |
|
||||
| | | | |
|
||||
| BrowserBuffer#copy(16000) | 1,058,548 ops/sec | ±1.51% | 64 | |
|
||||
| Uint8Array#copy(16000) | 1,409,666 ops/sec | ±1.17% | 65 | ✓ |
|
||||
| | | | |
|
||||
| BrowserBuffer#copy(16) | 6,282,529 ops/sec | ±1.88% | 58 | |
|
||||
| Uint8Array#copy(16) | 11,907,128 ops/sec | ±2.87% | 58 | ✓ |
|
||||
| | | | |
|
||||
| BrowserBuffer#new(16000) | 101,663 ops/sec | ±3.89% | 57 | |
|
||||
| Uint8Array#new(16000) | 22,050,818 ops/sec | ±6.51% | 46 | ✓ |
|
||||
| | | | |
|
||||
| BrowserBuffer#new(16) | 176,072 ops/sec | ±2.13% | 64 | |
|
||||
| Uint8Array#new(16) | 24,385,731 ops/sec | ±5.01% | 51 | ✓ |
|
||||
| | | | |
|
||||
| BrowserBuffer#readDoubleBE | 41,341 ops/sec | ±1.06% | 67 | |
|
||||
| DataView#getFloat64 | 322,280 ops/sec | ±0.84% | 68 | ✓ |
|
||||
| | | | |
|
||||
| BrowserBuffer#readFloatBE | 46,141 ops/sec | ±1.06% | 65 | |
|
||||
| DataView#getFloat32 | 337,025 ops/sec | ±0.43% | 69 | ✓ |
|
||||
| | | | |
|
||||
| BrowserBuffer#readUInt32LE | 151,551 ops/sec | ±1.02% | 66 | |
|
||||
| DataView#getUint32 | 308,278 ops/sec | ±0.94% | 67 | ✓ |
|
||||
| | | | |
|
||||
| BrowserBuffer#slice | 197,365 ops/sec | ±0.95% | 66 | |
|
||||
| Uint8Array#subarray | 9,558,024 ops/sec | ±3.08% | 58 | ✓ |
|
||||
| | | | |
|
||||
| BrowserBuffer#writeFloatBE | 17,518 ops/sec | ±1.03% | 63 | |
|
||||
| DataView#setFloat32 | 319,751 ops/sec | ±0.48% | 68 | ✓ |
|
||||
|
||||
|
||||
### Node 0.11.14
|
||||
|
||||
| Method | Operations | Accuracy | Sampled | Fastest |
|
||||
|:-------|:-----------|:---------|:--------|:-------:|
|
||||
| BrowserBuffer#bracket-notation | 10,489,828 ops/sec | ±3.25% | 90 | |
|
||||
| Uint8Array#bracket-notation | 10,534,884 ops/sec | ±0.81% | 92 | ✓ |
|
||||
| NodeBuffer#bracket-notation | 10,389,910 ops/sec | ±0.97% | 87 | |
|
||||
| | | | |
|
||||
| BrowserBuffer#concat | 487,830 ops/sec | ±2.58% | 88 | |
|
||||
| Uint8Array#concat | 1,814,327 ops/sec | ±1.28% | 88 | ✓ |
|
||||
| NodeBuffer#concat | 1,636,523 ops/sec | ±1.88% | 73 | |
|
||||
| | | | |
|
||||
| BrowserBuffer#copy(16000) | 1,073,665 ops/sec | ±0.77% | 90 | |
|
||||
| Uint8Array#copy(16000) | 1,348,517 ops/sec | ±0.84% | 89 | ✓ |
|
||||
| NodeBuffer#copy(16000) | 1,289,533 ops/sec | ±0.82% | 93 | |
|
||||
| | | | |
|
||||
| BrowserBuffer#copy(16) | 12,782,706 ops/sec | ±0.74% | 85 | |
|
||||
| Uint8Array#copy(16) | 14,180,427 ops/sec | ±0.93% | 92 | ✓ |
|
||||
| NodeBuffer#copy(16) | 11,083,134 ops/sec | ±1.06% | 89 | |
|
||||
| | | | |
|
||||
| BrowserBuffer#new(16000) | 141,678 ops/sec | ±3.30% | 67 | |
|
||||
| Uint8Array#new(16000) | 161,491 ops/sec | ±2.96% | 60 | |
|
||||
| NodeBuffer#new(16000) | 292,699 ops/sec | ±3.20% | 55 | ✓ |
|
||||
| | | | |
|
||||
| BrowserBuffer#new(16) | 1,655,466 ops/sec | ±2.41% | 82 | |
|
||||
| Uint8Array#new(16) | 14,399,926 ops/sec | ±0.91% | 94 | ✓ |
|
||||
| NodeBuffer#new(16) | 3,894,696 ops/sec | ±0.88% | 92 | |
|
||||
| | | | |
|
||||
| BrowserBuffer#readDoubleBE | 109,582 ops/sec | ±0.75% | 93 | ✓ |
|
||||
| DataView#getFloat64 | 91,235 ops/sec | ±0.81% | 90 | |
|
||||
| NodeBuffer#readDoubleBE | 88,593 ops/sec | ±0.96% | 81 | |
|
||||
| | | | |
|
||||
| BrowserBuffer#readFloatBE | 139,854 ops/sec | ±1.03% | 85 | ✓ |
|
||||
| DataView#getFloat32 | 98,744 ops/sec | ±0.80% | 89 | |
|
||||
| NodeBuffer#readFloatBE | 92,769 ops/sec | ±0.94% | 93 | |
|
||||
| | | | |
|
||||
| BrowserBuffer#readUInt32LE | 710,861 ops/sec | ±0.82% | 92 | |
|
||||
| DataView#getUint32 | 117,893 ops/sec | ±0.84% | 91 | |
|
||||
| NodeBuffer#readUInt32LE | 851,412 ops/sec | ±0.72% | 93 | ✓ |
|
||||
| | | | |
|
||||
| BrowserBuffer#slice | 1,673,877 ops/sec | ±0.73% | 94 | |
|
||||
| Uint8Array#subarray | 6,919,243 ops/sec | ±0.67% | 90 | ✓ |
|
||||
| NodeBuffer#slice | 4,617,604 ops/sec | ±0.79% | 93 | |
|
||||
| | | | |
|
||||
| BrowserBuffer#writeFloatBE | 66,011 ops/sec | ±0.75% | 93 | |
|
||||
| DataView#setFloat32 | 127,760 ops/sec | ±0.72% | 93 | ✓ |
|
||||
| NodeBuffer#writeFloatBE | 103,352 ops/sec | ±0.83% | 93 | |
|
||||
|
||||
### iojs 1.8.1
|
||||
|
||||
| Method | Operations | Accuracy | Sampled | Fastest |
|
||||
|:-------|:-----------|:---------|:--------|:-------:|
|
||||
| BrowserBuffer#bracket-notation | 10,990,488 ops/sec | ±1.11% | 91 | |
|
||||
| Uint8Array#bracket-notation | 11,268,757 ops/sec | ±0.65% | 97 | |
|
||||
| NodeBuffer#bracket-notation | 11,353,260 ops/sec | ±0.83% | 94 | ✓ |
|
||||
| | | | |
|
||||
| BrowserBuffer#concat | 378,954 ops/sec | ±0.74% | 94 | |
|
||||
| Uint8Array#concat | 1,358,288 ops/sec | ±0.97% | 87 | |
|
||||
| NodeBuffer#concat | 1,934,050 ops/sec | ±1.11% | 78 | ✓ |
|
||||
| | | | |
|
||||
| BrowserBuffer#copy(16000) | 894,538 ops/sec | ±0.56% | 84 | |
|
||||
| Uint8Array#copy(16000) | 1,442,656 ops/sec | ±0.71% | 96 | |
|
||||
| NodeBuffer#copy(16000) | 1,457,898 ops/sec | ±0.53% | 92 | ✓ |
|
||||
| | | | |
|
||||
| BrowserBuffer#copy(16) | 12,870,457 ops/sec | ±0.67% | 95 | |
|
||||
| Uint8Array#copy(16) | 16,643,989 ops/sec | ±0.61% | 93 | ✓ |
|
||||
| NodeBuffer#copy(16) | 14,885,848 ops/sec | ±0.74% | 94 | |
|
||||
| | | | |
|
||||
| BrowserBuffer#new(16000) | 109,264 ops/sec | ±4.21% | 63 | |
|
||||
| Uint8Array#new(16000) | 138,916 ops/sec | ±1.87% | 61 | |
|
||||
| NodeBuffer#new(16000) | 281,449 ops/sec | ±3.58% | 51 | ✓ |
|
||||
| | | | |
|
||||
| BrowserBuffer#new(16) | 1,362,935 ops/sec | ±0.56% | 99 | |
|
||||
| Uint8Array#new(16) | 6,193,090 ops/sec | ±0.64% | 95 | ✓ |
|
||||
| NodeBuffer#new(16) | 4,745,425 ops/sec | ±1.56% | 90 | |
|
||||
| | | | |
|
||||
| BrowserBuffer#readDoubleBE | 118,127 ops/sec | ±0.59% | 93 | ✓ |
|
||||
| DataView#getFloat64 | 107,332 ops/sec | ±0.65% | 91 | |
|
||||
| NodeBuffer#readDoubleBE | 116,274 ops/sec | ±0.94% | 95 | |
|
||||
| | | | |
|
||||
| BrowserBuffer#readFloatBE | 150,326 ops/sec | ±0.58% | 95 | ✓ |
|
||||
| DataView#getFloat32 | 110,541 ops/sec | ±0.57% | 98 | |
|
||||
| NodeBuffer#readFloatBE | 121,599 ops/sec | ±0.60% | 87 | |
|
||||
| | | | |
|
||||
| BrowserBuffer#readUInt32LE | 814,147 ops/sec | ±0.62% | 93 | |
|
||||
| DataView#getUint32 | 137,592 ops/sec | ±0.64% | 90 | |
|
||||
| NodeBuffer#readUInt32LE | 931,650 ops/sec | ±0.71% | 96 | ✓ |
|
||||
| | | | |
|
||||
| BrowserBuffer#slice | 878,590 ops/sec | ±0.68% | 93 | |
|
||||
| Uint8Array#subarray | 2,843,308 ops/sec | ±1.02% | 90 | |
|
||||
| NodeBuffer#slice | 4,998,316 ops/sec | ±0.68% | 90 | ✓ |
|
||||
| | | | |
|
||||
| BrowserBuffer#writeFloatBE | 65,927 ops/sec | ±0.74% | 93 | |
|
||||
| DataView#setFloat32 | 139,823 ops/sec | ±0.97% | 89 | ✓ |
|
||||
| NodeBuffer#writeFloatBE | 135,763 ops/sec | ±0.65% | 96 | |
|
||||
| | | | |
|
||||
|
||||
## Testing the project
|
||||
|
||||
First, install the project:
|
||||
|
||||
npm install
|
||||
|
||||
Then, to run tests in Node.js, run:
|
||||
|
||||
npm run test-node
|
||||
|
||||
To test locally in a browser, you can run:
|
||||
|
||||
npm run test-browser-es5-local # For ES5 browsers that don't support ES6
|
||||
npm run test-browser-es6-local # For ES6 compliant browsers
|
||||
|
||||
This will print out a URL that you can then open in a browser to run the tests, using [airtap](https://www.npmjs.com/package/airtap).
|
||||
|
||||
To run automated browser tests using Saucelabs, ensure that your `SAUCE_USERNAME` and `SAUCE_ACCESS_KEY` environment variables are set, then run:
|
||||
|
||||
npm test
|
||||
|
||||
This is what's run in Travis, to check against various browsers. The list of browsers is kept in the `bin/airtap-es5.yml` and `bin/airtap-es6.yml` files.
|
||||
|
||||
## JavaScript Standard Style
|
||||
|
||||
This module uses [JavaScript Standard Style](https://github.com/feross/standard).
|
||||
|
||||
[](https://github.com/feross/standard)
|
||||
|
||||
To test that the code conforms to the style, `npm install` and run:
|
||||
|
||||
./node_modules/.bin/standard
|
||||
|
||||
## credit
|
||||
|
||||
This was originally forked from [buffer-browserify](https://github.com/toots/buffer-browserify).
|
||||
|
||||
## Security Policies and Procedures
|
||||
|
||||
The `buffer` team and community take all security bugs in `buffer` seriously. Please see our [security policies and procedures](https://github.com/feross/security) document to learn how to report issues.
|
||||
|
||||
## license
|
||||
|
||||
MIT. Copyright (C) [Feross Aboukhadijeh](http://feross.org), and other contributors. Originally forked from an MIT-licensed module by Romain Beauxis.
|
||||
@@ -0,0 +1,494 @@
|
||||
'use strict'
|
||||
|
||||
let CssSyntaxError = require('./css-syntax-error')
|
||||
let Stringifier = require('./stringifier')
|
||||
let stringify = require('./stringify')
|
||||
let { isClean, my } = require('./symbols')
|
||||
|
||||
function cloneNode(obj, parent) {
|
||||
let cloned = new obj.constructor()
|
||||
// An explicit stack instead of recursive calls to survive deeply
|
||||
// nested trees. Each entry is [source, its clone, clone's parent].
|
||||
let stack = [[obj, cloned, parent]]
|
||||
|
||||
while (stack.length > 0) {
|
||||
let [source, target, targetParent] = stack.pop()
|
||||
for (let i in source) {
|
||||
if (!Object.prototype.hasOwnProperty.call(source, i)) {
|
||||
/* c8 ignore next 2 */
|
||||
continue
|
||||
}
|
||||
if (i === 'proxyCache') continue
|
||||
let value = source[i]
|
||||
let type = typeof value
|
||||
|
||||
if (i === 'parent' && type === 'object') {
|
||||
if (targetParent) target[i] = targetParent
|
||||
} else if (i === 'source') {
|
||||
target[i] = value
|
||||
} else if (Array.isArray(value)) {
|
||||
let children = []
|
||||
target[i] = children
|
||||
for (let j of value) {
|
||||
let childClone = new j.constructor()
|
||||
children.push(childClone)
|
||||
stack.push([j, childClone, target])
|
||||
}
|
||||
} else {
|
||||
if (type === 'object' && value !== null) {
|
||||
let valueClone = new value.constructor()
|
||||
stack.push([value, valueClone, undefined])
|
||||
value = valueClone
|
||||
}
|
||||
target[i] = value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return cloned
|
||||
}
|
||||
|
||||
function sourceOffset(inputCSS, position) {
|
||||
// Not all custom syntaxes support `offset` in `source.start` and `source.end`
|
||||
if (position && typeof position.offset !== 'undefined') {
|
||||
return position.offset
|
||||
}
|
||||
|
||||
let column = 1
|
||||
let line = 1
|
||||
let offset = 0
|
||||
|
||||
for (let i = 0; i < inputCSS.length; i++) {
|
||||
if (line === position.line && column === position.column) {
|
||||
offset = i
|
||||
break
|
||||
}
|
||||
|
||||
if (inputCSS[i] === '\n') {
|
||||
column = 1
|
||||
line += 1
|
||||
} else {
|
||||
column += 1
|
||||
}
|
||||
}
|
||||
|
||||
return offset
|
||||
}
|
||||
|
||||
class Node {
|
||||
get proxyOf() {
|
||||
return this
|
||||
}
|
||||
|
||||
constructor(defaults = {}) {
|
||||
this.raws = {}
|
||||
this[isClean] = false
|
||||
this[my] = true
|
||||
|
||||
for (let name of Object.keys(defaults)) {
|
||||
if (name === '__proto__') continue
|
||||
if (name === 'nodes') {
|
||||
this.nodes = []
|
||||
for (let node of defaults[name]) {
|
||||
// Clone only nodes that already belong to another tree, so passing a
|
||||
// freshly created (parent-less) node adopts that instance instead of
|
||||
// a copy and keeps the caller's reference usable. See #1987.
|
||||
if (typeof node.clone === 'function' && node.parent) {
|
||||
this.append(node.clone())
|
||||
} else {
|
||||
this.append(node)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this[name] = defaults[name]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addToError(error) {
|
||||
error.postcssNode = this
|
||||
if (error.stack && this.source && /\n\s{4}at /.test(error.stack)) {
|
||||
let s = this.source
|
||||
error.stack = error.stack.replace(
|
||||
/\n\s{4}at /,
|
||||
`$&${s.input.from}:${s.start.line}:${s.start.column}$&`
|
||||
)
|
||||
}
|
||||
return error
|
||||
}
|
||||
|
||||
after(add) {
|
||||
this.parent.insertAfter(this, add)
|
||||
return this
|
||||
}
|
||||
|
||||
assign(overrides = {}) {
|
||||
for (let name in overrides) {
|
||||
this[name] = overrides[name]
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
before(add) {
|
||||
this.parent.insertBefore(this, add)
|
||||
return this
|
||||
}
|
||||
|
||||
cleanRaws(keepBetween) {
|
||||
delete this.raws.before
|
||||
delete this.raws.after
|
||||
if (!keepBetween) delete this.raws.between
|
||||
}
|
||||
|
||||
clone(overrides = {}) {
|
||||
let cloned = cloneNode(this)
|
||||
for (let name in overrides) {
|
||||
cloned[name] = overrides[name]
|
||||
}
|
||||
return cloned
|
||||
}
|
||||
|
||||
cloneAfter(overrides = {}) {
|
||||
let cloned = this.clone(overrides)
|
||||
this.parent.insertAfter(this, cloned)
|
||||
return cloned
|
||||
}
|
||||
|
||||
cloneBefore(overrides = {}) {
|
||||
let cloned = this.clone(overrides)
|
||||
this.parent.insertBefore(this, cloned)
|
||||
return cloned
|
||||
}
|
||||
|
||||
error(message, opts = {}) {
|
||||
if (this.source) {
|
||||
let { end, start } = this.rangeBy(opts)
|
||||
return this.source.input.error(
|
||||
message,
|
||||
{ column: start.column, line: start.line },
|
||||
{ column: end.column, line: end.line },
|
||||
opts
|
||||
)
|
||||
}
|
||||
return new CssSyntaxError(message)
|
||||
}
|
||||
|
||||
getProxyProcessor() {
|
||||
return {
|
||||
get(node, prop) {
|
||||
if (prop === 'proxyOf') {
|
||||
return node
|
||||
} else if (prop === 'root') {
|
||||
return () => node.root().toProxy()
|
||||
} else {
|
||||
return node[prop]
|
||||
}
|
||||
},
|
||||
|
||||
set(node, prop, value) {
|
||||
if (node[prop] === value) return true
|
||||
node[prop] = value
|
||||
if (
|
||||
prop === 'prop' ||
|
||||
prop === 'value' ||
|
||||
prop === 'name' ||
|
||||
prop === 'params' ||
|
||||
prop === 'important' ||
|
||||
/* c8 ignore next */
|
||||
prop === 'text'
|
||||
) {
|
||||
node.markDirty()
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* c8 ignore next 3 */
|
||||
markClean() {
|
||||
this[isClean] = true
|
||||
}
|
||||
|
||||
markDirty() {
|
||||
if (this[isClean]) {
|
||||
this[isClean] = false
|
||||
let next = this
|
||||
while ((next = next.parent)) {
|
||||
next[isClean] = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
next() {
|
||||
if (!this.parent) return undefined
|
||||
let index = this.parent.index(this)
|
||||
return this.parent.nodes[index + 1]
|
||||
}
|
||||
|
||||
positionBy(opts = {}) {
|
||||
let inputString =
|
||||
'document' in this.source.input
|
||||
? this.source.input.document
|
||||
: this.source.input.css
|
||||
let pos = {
|
||||
column: this.source.start.column,
|
||||
line: this.source.start.line,
|
||||
offset: sourceOffset(inputString, this.source.start)
|
||||
}
|
||||
if (opts.index) {
|
||||
pos = this.positionInside(opts.index)
|
||||
} else if (opts.word) {
|
||||
let stringRepresentation = inputString.slice(
|
||||
sourceOffset(inputString, this.source.start),
|
||||
sourceOffset(inputString, this.source.end)
|
||||
)
|
||||
let index = stringRepresentation.indexOf(opts.word)
|
||||
if (index !== -1) pos = this.positionInside(index)
|
||||
}
|
||||
return pos
|
||||
}
|
||||
|
||||
positionInside(index) {
|
||||
let column = this.source.start.column
|
||||
let line = this.source.start.line
|
||||
let inputString =
|
||||
'document' in this.source.input
|
||||
? this.source.input.document
|
||||
: this.source.input.css
|
||||
let offset = sourceOffset(inputString, this.source.start)
|
||||
let end = offset + index
|
||||
|
||||
for (let i = offset; i < end; i++) {
|
||||
if (inputString[i] === '\n') {
|
||||
column = 1
|
||||
line += 1
|
||||
} else {
|
||||
column += 1
|
||||
}
|
||||
}
|
||||
|
||||
return { column, line, offset: end }
|
||||
}
|
||||
|
||||
prev() {
|
||||
if (!this.parent) return undefined
|
||||
let index = this.parent.index(this)
|
||||
return this.parent.nodes[index - 1]
|
||||
}
|
||||
|
||||
rangeBy(opts = {}) {
|
||||
let inputString =
|
||||
'document' in this.source.input
|
||||
? this.source.input.document
|
||||
: this.source.input.css
|
||||
let start = {
|
||||
column: this.source.start.column,
|
||||
line: this.source.start.line,
|
||||
offset: sourceOffset(inputString, this.source.start)
|
||||
}
|
||||
let end = this.source.end
|
||||
? {
|
||||
column: this.source.end.column + 1,
|
||||
line: this.source.end.line,
|
||||
offset:
|
||||
typeof this.source.end.offset === 'number'
|
||||
? // `source.end.offset` is exclusive, so we don't need to add 1
|
||||
this.source.end.offset
|
||||
: // Since line/column in this.source.end is inclusive,
|
||||
// the `sourceOffset(... , this.source.end)` returns an inclusive offset.
|
||||
// So, we add 1 to convert it to exclusive.
|
||||
sourceOffset(inputString, this.source.end) + 1
|
||||
}
|
||||
: {
|
||||
column: start.column + 1,
|
||||
line: start.line,
|
||||
offset: start.offset + 1
|
||||
}
|
||||
|
||||
if (opts.word) {
|
||||
let stringRepresentation = inputString.slice(
|
||||
sourceOffset(inputString, this.source.start),
|
||||
sourceOffset(inputString, this.source.end)
|
||||
)
|
||||
let index = stringRepresentation.indexOf(opts.word)
|
||||
if (index !== -1) {
|
||||
start = this.positionInside(index)
|
||||
end = this.positionInside(index + opts.word.length)
|
||||
}
|
||||
} else {
|
||||
if (opts.start) {
|
||||
start = {
|
||||
column: opts.start.column,
|
||||
line: opts.start.line,
|
||||
offset: sourceOffset(inputString, opts.start)
|
||||
}
|
||||
} else if (typeof opts.index === 'number') {
|
||||
start = this.positionInside(opts.index)
|
||||
}
|
||||
|
||||
if (opts.end) {
|
||||
end = {
|
||||
column: opts.end.column,
|
||||
line: opts.end.line,
|
||||
offset: sourceOffset(inputString, opts.end)
|
||||
}
|
||||
} else if (typeof opts.endIndex === 'number') {
|
||||
end = this.positionInside(opts.endIndex)
|
||||
} else if (typeof opts.index === 'number') {
|
||||
end = this.positionInside(opts.index + 1)
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
end.line < start.line ||
|
||||
(end.line === start.line && end.column <= start.column)
|
||||
) {
|
||||
end = {
|
||||
column: start.column + 1,
|
||||
line: start.line,
|
||||
offset: start.offset + 1
|
||||
}
|
||||
}
|
||||
|
||||
return { end, start }
|
||||
}
|
||||
|
||||
raw(prop, defaultType) {
|
||||
let str = new Stringifier()
|
||||
return str.raw(this, prop, defaultType)
|
||||
}
|
||||
|
||||
remove() {
|
||||
if (this.parent) {
|
||||
this.parent.removeChild(this)
|
||||
}
|
||||
this.parent = undefined
|
||||
return this
|
||||
}
|
||||
|
||||
replaceWith(...nodes) {
|
||||
if (this.parent) {
|
||||
let bookmark = this
|
||||
let foundSelf = false
|
||||
for (let node of nodes) {
|
||||
if (node === this) {
|
||||
foundSelf = true
|
||||
} else if (foundSelf) {
|
||||
this.parent.insertAfter(bookmark, node)
|
||||
bookmark = node
|
||||
} else {
|
||||
this.parent.insertBefore(bookmark, node)
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundSelf) {
|
||||
this.remove()
|
||||
}
|
||||
}
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
root() {
|
||||
let result = this
|
||||
while (result.parent && result.parent.type !== 'document') {
|
||||
result = result.parent
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
toJSON(_, inputs) {
|
||||
let emitInputs = inputs == null
|
||||
inputs = inputs || new Map()
|
||||
|
||||
// A worklist instead of recursive `toJSON()` calls to survive deeply
|
||||
// nested trees. Each entry converts one node and writes the result
|
||||
// into the already converted parent by [holder, key].
|
||||
let holderOfRoot = []
|
||||
let queue = [[this, holderOfRoot, 0]]
|
||||
|
||||
for (let step = 0; step < queue.length; step++) {
|
||||
let [node, holder, key] = queue[step]
|
||||
let fixed = {}
|
||||
holder[key] = fixed
|
||||
|
||||
for (let name in node) {
|
||||
if (!Object.prototype.hasOwnProperty.call(node, name)) {
|
||||
/* c8 ignore next 2 */
|
||||
continue
|
||||
}
|
||||
if (name === 'parent' || name === 'proxyCache') continue
|
||||
let value = node[name]
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
let fixedArray = []
|
||||
fixed[name] = fixedArray
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
let item = value[i]
|
||||
if (typeof item === 'object' && item.toJSON) {
|
||||
if (item.toJSON === Node.prototype.toJSON) {
|
||||
queue.push([item, fixedArray, i])
|
||||
} else {
|
||||
fixedArray[i] = item.toJSON(null, inputs)
|
||||
}
|
||||
} else {
|
||||
fixedArray[i] = item
|
||||
}
|
||||
}
|
||||
} else if (typeof value === 'object' && value.toJSON) {
|
||||
if (value.toJSON === Node.prototype.toJSON) {
|
||||
queue.push([value, fixed, name])
|
||||
} else {
|
||||
fixed[name] = value.toJSON(null, inputs)
|
||||
}
|
||||
} else if (name === 'source') {
|
||||
if (value == null) continue
|
||||
let inputId = inputs.get(value.input)
|
||||
if (inputId == null) {
|
||||
inputId = inputs.size
|
||||
inputs.set(value.input, inputId)
|
||||
}
|
||||
fixed[name] = {
|
||||
end: value.end,
|
||||
inputId,
|
||||
start: value.start
|
||||
}
|
||||
} else {
|
||||
fixed[name] = value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let fixed = holderOfRoot[0]
|
||||
if (emitInputs) {
|
||||
fixed.inputs = [...inputs.keys()].map(input => input.toJSON())
|
||||
}
|
||||
|
||||
return fixed
|
||||
}
|
||||
|
||||
toProxy() {
|
||||
if (!this.proxyCache) {
|
||||
this.proxyCache = new Proxy(this, this.getProxyProcessor())
|
||||
}
|
||||
return this.proxyCache
|
||||
}
|
||||
|
||||
toString(stringifier = stringify) {
|
||||
if (stringifier.stringify) stringifier = stringifier.stringify
|
||||
let result = ''
|
||||
stringifier(this, i => {
|
||||
result += i
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
warn(result, text, opts = {}) {
|
||||
let data = { node: this }
|
||||
for (let i in opts) data[i] = opts[i]
|
||||
return result.warn(text, data)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Node
|
||||
Node.default = Node
|
||||
@@ -0,0 +1,85 @@
|
||||
{
|
||||
"name": "flatted",
|
||||
"version": "3.4.4",
|
||||
"description": "A super light and fast circular JSON parser.",
|
||||
"unpkg": "min.js",
|
||||
"main": "./cjs/index.js",
|
||||
"scripts": {
|
||||
"build": "npm run cjs && npm run rollup:esm && npm run rollup:es && npm run rollup:babel && npm run min && npm run test && npm run size",
|
||||
"cjs": "ascjs esm cjs",
|
||||
"rollup:es": "rollup --config rollup/es.config.js && sed -i.bck 's/^var /self./' es.js && rm -rf es.js.bck",
|
||||
"rollup:esm": "rollup --config rollup/esm.config.js",
|
||||
"rollup:babel": "rollup --config rollup/babel.config.js && sed -i.bck 's/^var /self./' index.js && rm -rf index.js.bck",
|
||||
"min": "terser index.js -c -m -o min.js",
|
||||
"size": "cat index.js | wc -c;cat min.js | wc -c;gzip -c9 min.js | wc -c;cat min.js | brotli | wc -c; cat es.js | brotli | wc -c; cat esm.js | brotli | wc -c",
|
||||
"test": "c8 node test/index.js",
|
||||
"test:php": "php php/test.php",
|
||||
"test:py": "python python/test.py",
|
||||
"ts": "tsc -p .",
|
||||
"coverage": "mkdir -p ./coverage; c8 report --reporter=text-lcov > ./coverage/lcov.info"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/WebReflection/flatted.git"
|
||||
},
|
||||
"files": [
|
||||
"LICENSE",
|
||||
"README.md",
|
||||
"cjs/",
|
||||
"es.js",
|
||||
"esm.js",
|
||||
"esm/",
|
||||
"index.js",
|
||||
"min.js",
|
||||
"php/flatted.php",
|
||||
"python/flatted.py",
|
||||
"golang/pkg/flatted/flatted.go",
|
||||
"types/"
|
||||
],
|
||||
"keywords": [
|
||||
"circular",
|
||||
"JSON",
|
||||
"fast",
|
||||
"parser",
|
||||
"minimal"
|
||||
],
|
||||
"author": "Andrea Giammarchi",
|
||||
"license": "ISC",
|
||||
"bugs": {
|
||||
"url": "https://github.com/WebReflection/flatted/issues"
|
||||
},
|
||||
"homepage": "https://github.com/WebReflection/flatted#readme",
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.29.0",
|
||||
"@babel/preset-env": "^7.29.2",
|
||||
"@rollup/plugin-babel": "^7.0.0",
|
||||
"@rollup/plugin-terser": "^1.0.0",
|
||||
"@ungap/structured-clone": "^1.3.0",
|
||||
"ascjs": "^6.0.3",
|
||||
"c8": "^11.0.0",
|
||||
"circular-json": "^0.5.9",
|
||||
"circular-json-es6": "^2.0.2",
|
||||
"flatted-view": "^0.1.6",
|
||||
"jsan": "^3.1.14",
|
||||
"rollup": "^4.60.1",
|
||||
"terser": "^5.46.1",
|
||||
"typescript": "^5.9.3"
|
||||
},
|
||||
"overrides": {
|
||||
"c8": {
|
||||
"yargs": "^18.0.0"
|
||||
}
|
||||
},
|
||||
"module": "./esm/index.js",
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./types/index.d.ts",
|
||||
"import": "./esm/index.js",
|
||||
"default": "./cjs/index.js"
|
||||
},
|
||||
"./esm": "./esm.js",
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"types": "./types/index.d.ts"
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
{
|
||||
"name": "@types/chai",
|
||||
"version": "5.2.3",
|
||||
"description": "TypeScript definitions for chai",
|
||||
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/chai",
|
||||
"license": "MIT",
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Bart van der Schoor",
|
||||
"githubUsername": "Bartvds",
|
||||
"url": "https://github.com/Bartvds"
|
||||
},
|
||||
{
|
||||
"name": "Andrew Brown",
|
||||
"githubUsername": "AGBrown",
|
||||
"url": "https://github.com/AGBrown"
|
||||
},
|
||||
{
|
||||
"name": "Olivier Chevet",
|
||||
"githubUsername": "olivr70",
|
||||
"url": "https://github.com/olivr70"
|
||||
},
|
||||
{
|
||||
"name": "Matt Wistrand",
|
||||
"githubUsername": "mwistrand",
|
||||
"url": "https://github.com/mwistrand"
|
||||
},
|
||||
{
|
||||
"name": "Shaun Luttin",
|
||||
"githubUsername": "shaunluttin",
|
||||
"url": "https://github.com/shaunluttin"
|
||||
},
|
||||
{
|
||||
"name": "Satana Charuwichitratana",
|
||||
"githubUsername": "micksatana",
|
||||
"url": "https://github.com/micksatana"
|
||||
},
|
||||
{
|
||||
"name": "Erik Schierboom",
|
||||
"githubUsername": "ErikSchierboom",
|
||||
"url": "https://github.com/ErikSchierboom"
|
||||
},
|
||||
{
|
||||
"name": "Bogdan Paranytsia",
|
||||
"githubUsername": "bparan",
|
||||
"url": "https://github.com/bparan"
|
||||
},
|
||||
{
|
||||
"name": "CXuesong",
|
||||
"githubUsername": "CXuesong",
|
||||
"url": "https://github.com/CXuesong"
|
||||
},
|
||||
{
|
||||
"name": "Joey Kilpatrick",
|
||||
"githubUsername": "joeykilpatrick",
|
||||
"url": "https://github.com/joeykilpatrick"
|
||||
}
|
||||
],
|
||||
"type": "module",
|
||||
"main": "",
|
||||
"types": "index.d.ts",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/DefinitelyTyped/DefinitelyTyped.git",
|
||||
"directory": "types/chai"
|
||||
},
|
||||
"scripts": {},
|
||||
"dependencies": {
|
||||
"@types/deep-eql": "*",
|
||||
"assertion-error": "^2.0.1"
|
||||
},
|
||||
"peerDependencies": {},
|
||||
"typesPublisherContentHash": "d9d83f1594f42010e624e46e4c8cfeee284bdd04cb05eb0730aec14140f2a833",
|
||||
"typeScriptVersion": "5.2"
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = rng;
|
||||
// Unique ID creation requires a high quality random # generator. In the browser we therefore
|
||||
// require the crypto API and do not support built-in fallback to lower quality random number
|
||||
// generators (like Math.random()).
|
||||
let getRandomValues;
|
||||
const rnds8 = new Uint8Array(16);
|
||||
|
||||
function rng() {
|
||||
// lazy load so that environments that need to polyfill have a chance to do so
|
||||
if (!getRandomValues) {
|
||||
// getRandomValues needs to be invoked in a context where "this" is a Crypto implementation. Also,
|
||||
// find the complete implementation of crypto (msCrypto) on IE11.
|
||||
getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== 'undefined' && typeof msCrypto.getRandomValues === 'function' && msCrypto.getRandomValues.bind(msCrypto);
|
||||
|
||||
if (!getRandomValues) {
|
||||
throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
|
||||
}
|
||||
}
|
||||
|
||||
return getRandomValues(rnds8);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"scrypt.d.ts","sourceRoot":"","sources":["../src/scrypt.ts"],"names":[],"mappings":"AAOA,OAAO,EAGL,KAAK,QAAQ,EAGd,MAAM,YAAY,CAAC;AAuEpB,MAAM,MAAM,UAAU,GAAG;IACvB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;CACzC,CAAC;AAoFF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,GAAG,UAAU,CA0BvF;AAED;;;;GAIG;AACH,wBAAsB,WAAW,CAC/B,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,QAAQ,EACd,IAAI,EAAE,UAAU,GACf,OAAO,CAAC,UAAU,CAAC,CA2BrB"}
|
||||
@@ -0,0 +1,17 @@
|
||||
export type Options = [
|
||||
{
|
||||
allowConciseArrowFunctionExpressionsStartingWithVoid?: boolean;
|
||||
allowDirectConstAssertionInArrowFunctions?: boolean;
|
||||
allowedNames?: string[];
|
||||
allowExpressions?: boolean;
|
||||
allowFunctionsWithoutTypeParameters?: boolean;
|
||||
allowHigherOrderFunctions?: boolean;
|
||||
allowIIFEs?: boolean;
|
||||
allowTypedFunctionExpressions?: boolean;
|
||||
}
|
||||
];
|
||||
export type MessageIds = 'missingReturnType';
|
||||
declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<"missingReturnType", Options, import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
||||
name: string;
|
||||
};
|
||||
export default _default;
|
||||
@@ -0,0 +1,43 @@
|
||||
let random = async bytes => crypto.getRandomValues(new Uint8Array(bytes))
|
||||
|
||||
let customAlphabet = (alphabet, defaultSize = 21) => {
|
||||
let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
|
||||
|
||||
|
||||
|
||||
let step = -~((1.6 * mask * defaultSize) / alphabet.length)
|
||||
|
||||
return async (size = defaultSize) => {
|
||||
if (size <= 0) return ''
|
||||
let id = ''
|
||||
while (true) {
|
||||
let bytes = crypto.getRandomValues(new Uint8Array(step))
|
||||
let i = step | 0
|
||||
while (i--) {
|
||||
id += alphabet[bytes[i] & mask] || ''
|
||||
if (id.length === size) return id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let nanoid = async (size = 21) => {
|
||||
let id = ''
|
||||
let bytes = crypto.getRandomValues(new Uint8Array((size |= 0)))
|
||||
|
||||
while (size--) {
|
||||
let byte = bytes[size] & 63
|
||||
if (byte < 36) {
|
||||
id += byte.toString(36)
|
||||
} else if (byte < 62) {
|
||||
id += (byte - 26).toString(36).toUpperCase()
|
||||
} else if (byte < 63) {
|
||||
id += '_'
|
||||
} else {
|
||||
id += '-'
|
||||
}
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
export { nanoid, customAlphabet, random }
|
||||
@@ -0,0 +1,2 @@
|
||||
import type { LibDefinition } from '../variable';
|
||||
export declare const es2017_typedarrays: LibDefinition;
|
||||
Reference in New Issue
Block a user