mirror of
https://github.com/LukeHagar/arbiter.git
synced 2025-12-09 20:37:50 +00:00
Saving all progress
This commit is contained in:
22
node_modules/stringify-object/LICENSE
generated
vendored
Normal file
22
node_modules/stringify-object/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
Copyright (c) 2015, Yeoman team
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
135
node_modules/stringify-object/index.js
generated
vendored
Normal file
135
node_modules/stringify-object/index.js
generated
vendored
Normal file
@@ -0,0 +1,135 @@
|
||||
import isRegexp from 'is-regexp';
|
||||
import isObject from 'is-obj';
|
||||
import getOwnEnumerableKeys from 'get-own-enumerable-keys';
|
||||
|
||||
export default function stringifyObject(input, options, pad) {
|
||||
const seen = [];
|
||||
|
||||
return (function stringify(input, options = {}, pad = '') {
|
||||
const indent = options.indent || '\t';
|
||||
|
||||
let tokens;
|
||||
if (options.inlineCharacterLimit === undefined) {
|
||||
tokens = {
|
||||
newline: '\n',
|
||||
newlineOrSpace: '\n',
|
||||
pad,
|
||||
indent: pad + indent,
|
||||
};
|
||||
} else {
|
||||
tokens = {
|
||||
newline: '@@__STRINGIFY_OBJECT_NEW_LINE__@@',
|
||||
newlineOrSpace: '@@__STRINGIFY_OBJECT_NEW_LINE_OR_SPACE__@@',
|
||||
pad: '@@__STRINGIFY_OBJECT_PAD__@@',
|
||||
indent: '@@__STRINGIFY_OBJECT_INDENT__@@',
|
||||
};
|
||||
}
|
||||
|
||||
const expandWhiteSpace = string => {
|
||||
if (options.inlineCharacterLimit === undefined) {
|
||||
return string;
|
||||
}
|
||||
|
||||
const oneLined = string
|
||||
.replace(new RegExp(tokens.newline, 'g'), '')
|
||||
.replace(new RegExp(tokens.newlineOrSpace, 'g'), ' ')
|
||||
.replace(new RegExp(tokens.pad + '|' + tokens.indent, 'g'), '');
|
||||
|
||||
if (oneLined.length <= options.inlineCharacterLimit) {
|
||||
return oneLined;
|
||||
}
|
||||
|
||||
return string
|
||||
.replace(new RegExp(tokens.newline + '|' + tokens.newlineOrSpace, 'g'), '\n')
|
||||
.replace(new RegExp(tokens.pad, 'g'), pad)
|
||||
.replace(new RegExp(tokens.indent, 'g'), pad + indent);
|
||||
};
|
||||
|
||||
if (seen.includes(input)) {
|
||||
return '"[Circular]"';
|
||||
}
|
||||
|
||||
if (
|
||||
input === null
|
||||
|| input === undefined
|
||||
|| typeof input === 'number'
|
||||
|| typeof input === 'boolean'
|
||||
|| typeof input === 'function'
|
||||
|| typeof input === 'symbol'
|
||||
|| isRegexp(input)
|
||||
) {
|
||||
return String(input);
|
||||
}
|
||||
|
||||
if (input instanceof Date) {
|
||||
return `new Date('${input.toISOString()}')`;
|
||||
}
|
||||
|
||||
if (Array.isArray(input)) {
|
||||
if (input.length === 0) {
|
||||
return '[]';
|
||||
}
|
||||
|
||||
seen.push(input);
|
||||
|
||||
const returnValue = '[' + tokens.newline + input.map((element, i) => {
|
||||
const eol = input.length - 1 === i ? tokens.newline : ',' + tokens.newlineOrSpace;
|
||||
|
||||
let value = stringify(element, options, pad + indent);
|
||||
if (options.transform) {
|
||||
value = options.transform(input, i, value);
|
||||
}
|
||||
|
||||
return tokens.indent + value + eol;
|
||||
}).join('') + tokens.pad + ']';
|
||||
|
||||
seen.pop();
|
||||
|
||||
return expandWhiteSpace(returnValue);
|
||||
}
|
||||
|
||||
if (isObject(input)) {
|
||||
let objectKeys = getOwnEnumerableKeys(input);
|
||||
|
||||
if (options.filter) {
|
||||
// eslint-disable-next-line unicorn/no-array-callback-reference, unicorn/no-array-method-this-argument
|
||||
objectKeys = objectKeys.filter(element => options.filter(input, element));
|
||||
}
|
||||
|
||||
if (objectKeys.length === 0) {
|
||||
return '{}';
|
||||
}
|
||||
|
||||
seen.push(input);
|
||||
|
||||
const returnValue = '{' + tokens.newline + objectKeys.map((element, index) => {
|
||||
const eol = objectKeys.length - 1 === index ? tokens.newline : ',' + tokens.newlineOrSpace;
|
||||
const isSymbol = typeof element === 'symbol';
|
||||
const isClassic = !isSymbol && /^[a-z$_][$\w]*$/i.test(element);
|
||||
const key = isSymbol || isClassic ? element : stringify(element, options);
|
||||
|
||||
let value = stringify(input[element], options, pad + indent);
|
||||
if (options.transform) {
|
||||
value = options.transform(input, element, value);
|
||||
}
|
||||
|
||||
return tokens.indent + String(key) + ': ' + value + eol;
|
||||
}).join('') + tokens.pad + '}';
|
||||
|
||||
seen.pop();
|
||||
|
||||
return expandWhiteSpace(returnValue);
|
||||
}
|
||||
|
||||
input = input.replace(/\\/g, '\\\\');
|
||||
input = String(input).replace(/[\r\n]/g, x => x === '\n' ? '\\n' : '\\r');
|
||||
|
||||
if (options.singleQuotes === false) {
|
||||
input = input.replace(/"/g, '\\"');
|
||||
return `"${input}"`;
|
||||
}
|
||||
|
||||
input = input.replace(/'/g, '\\\'');
|
||||
return `'${input}'`;
|
||||
})(input, options, pad);
|
||||
}
|
||||
48
node_modules/stringify-object/package.json
generated
vendored
Normal file
48
node_modules/stringify-object/package.json
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"name": "stringify-object",
|
||||
"version": "5.0.0",
|
||||
"description": "Stringify an object/array like JSON.stringify just without all the double-quotes",
|
||||
"license": "BSD-2-Clause",
|
||||
"repository": "yeoman/stringify-object",
|
||||
"funding": "https://github.com/yeoman/stringify-object?sponsor=1",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "https://sindresorhus.com"
|
||||
},
|
||||
"type": "module",
|
||||
"exports": "./index.js",
|
||||
"engines": {
|
||||
"node": ">=14.16"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"keywords": [
|
||||
"object",
|
||||
"stringify",
|
||||
"pretty",
|
||||
"print",
|
||||
"dump",
|
||||
"format",
|
||||
"type",
|
||||
"json"
|
||||
],
|
||||
"dependencies": {
|
||||
"get-own-enumerable-keys": "^1.0.0",
|
||||
"is-obj": "^3.0.0",
|
||||
"is-regexp": "^3.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "^5.1.1",
|
||||
"xo": "^0.53.1"
|
||||
},
|
||||
"xo": {
|
||||
"ignores": [
|
||||
"test/fixtures/*.js"
|
||||
]
|
||||
}
|
||||
}
|
||||
158
node_modules/stringify-object/readme.md
generated
vendored
Normal file
158
node_modules/stringify-object/readme.md
generated
vendored
Normal file
@@ -0,0 +1,158 @@
|
||||
# stringify-object
|
||||
|
||||
> Stringify an object/array like JSON.stringify just without all the double-quotes
|
||||
|
||||
Useful for when you want to get the string representation of an object in a formatted way.
|
||||
|
||||
It also handles circular references and lets you specify quote type.
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
npm install stringify-object
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import stringifyObject from 'stringify-object';
|
||||
|
||||
const object = {
|
||||
foo: 'bar',
|
||||
'arr': [1, 2, 3],
|
||||
nested: {
|
||||
hello: "world"
|
||||
}
|
||||
};
|
||||
|
||||
const pretty = stringifyObject(object, {
|
||||
indent: ' ',
|
||||
singleQuotes: false
|
||||
});
|
||||
|
||||
console.log(pretty);
|
||||
/*
|
||||
{
|
||||
foo: "bar",
|
||||
arr: [
|
||||
1,
|
||||
2,
|
||||
3
|
||||
],
|
||||
nested: {
|
||||
hello: "world"
|
||||
}
|
||||
}
|
||||
*/
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### stringifyObject(input, options?)
|
||||
|
||||
Circular references will be replaced with `"[Circular]"`.
|
||||
|
||||
Object keys are only quoted when necessary, for example, `{'foo-bar': true}`.
|
||||
|
||||
#### input
|
||||
|
||||
Type: `object | Array`
|
||||
|
||||
#### options
|
||||
|
||||
Type: `object`
|
||||
|
||||
##### indent
|
||||
|
||||
Type: `string`\
|
||||
Default: `\t`
|
||||
|
||||
Preferred indentation.
|
||||
|
||||
##### singleQuotes
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `true`
|
||||
|
||||
Set to false to get double-quoted strings.
|
||||
|
||||
##### filter(object, property)
|
||||
|
||||
Type: `Function`
|
||||
|
||||
Expected to return a `boolean` of whether to include the property `property` of the object `object` in the output.
|
||||
|
||||
##### transform(object, property, originalResult)
|
||||
|
||||
Type: `Function`\
|
||||
Default: `undefined`
|
||||
|
||||
Expected to return a `string` that transforms the string that resulted from stringifying `object[property]`. This can be used to detect special types of objects that need to be stringified in a particular way. The `transform` function might return an alternate string in this case, otherwise returning the `originalResult`.
|
||||
|
||||
Here's an example that uses the `transform` option to mask fields named "password":
|
||||
|
||||
```js
|
||||
import stringifyObject from 'stringify-object';
|
||||
|
||||
const object = {
|
||||
user: 'becky',
|
||||
password: 'secret'
|
||||
};
|
||||
|
||||
const pretty = stringifyObject(object, {
|
||||
transform: (object, property, originalResult) => {
|
||||
if (property === 'password') {
|
||||
return originalResult.replace(/\w/g, '*');
|
||||
}
|
||||
|
||||
return originalResult;
|
||||
}
|
||||
});
|
||||
|
||||
console.log(pretty);
|
||||
/*
|
||||
{
|
||||
user: 'becky',
|
||||
password: '******'
|
||||
}
|
||||
*/
|
||||
```
|
||||
|
||||
##### inlineCharacterLimit
|
||||
|
||||
Type: `number`
|
||||
|
||||
When set, will inline values up to `inlineCharacterLimit` length for the sake of more terse output.
|
||||
|
||||
For example, given the example at the top of the README:
|
||||
|
||||
```js
|
||||
import stringifyObject from 'stringify-object';
|
||||
|
||||
const object = {
|
||||
foo: 'bar',
|
||||
'arr': [1, 2, 3],
|
||||
nested: {
|
||||
hello: "world"
|
||||
}
|
||||
};
|
||||
|
||||
const pretty = stringifyObject(object, {
|
||||
indent: ' ',
|
||||
singleQuotes: false,
|
||||
inlineCharacterLimit: 12
|
||||
});
|
||||
|
||||
console.log(pretty);
|
||||
/*
|
||||
{
|
||||
foo: "bar",
|
||||
arr: [1, 2, 3],
|
||||
nested: {
|
||||
hello: "world"
|
||||
}
|
||||
}
|
||||
*/
|
||||
```
|
||||
|
||||
As you can see, `arr` was printed as a one-liner because its string was shorter than 12 characters.
|
||||
Reference in New Issue
Block a user