aboutsummaryrefslogtreecommitdiff
path: root/node_modules/stringify-object
diff options
context:
space:
mode:
authorruki <waruqi@gmail.com>2018-11-08 00:38:48 +0800
committerruki <waruqi@gmail.com>2018-11-07 21:53:09 +0800
commit26105034da4fcce7ac883c899d781f016559310d (patch)
treec459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/stringify-object
parent2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff)
downloadxmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz
xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip
switch to vuepress
Diffstat (limited to 'node_modules/stringify-object')
-rw-r--r--node_modules/stringify-object/LICENSE22
-rw-r--r--node_modules/stringify-object/index.js131
-rw-r--r--node_modules/stringify-object/package.json40
-rw-r--r--node_modules/stringify-object/readme.md155
4 files changed, 348 insertions, 0 deletions
diff --git a/node_modules/stringify-object/LICENSE b/node_modules/stringify-object/LICENSE
new file mode 100644
index 00000000..ff642e65
--- /dev/null
+++ b/node_modules/stringify-object/LICENSE
@@ -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.
diff --git a/node_modules/stringify-object/index.js b/node_modules/stringify-object/index.js
new file mode 100644
index 00000000..beed5e3a
--- /dev/null
+++ b/node_modules/stringify-object/index.js
@@ -0,0 +1,131 @@
+'use strict';
+const isRegexp = require('is-regexp');
+const isObj = require('is-obj');
+const getOwnEnumPropSymbols = require('get-own-enumerable-property-symbols').default;
+
+module.exports = (val, opts, pad) => {
+ const seen = [];
+
+ return (function stringify(val, opts, pad) {
+ opts = opts || {};
+ opts.indent = opts.indent || '\t';
+ pad = pad || '';
+
+ let tokens;
+
+ if (opts.inlineCharacterLimit === undefined) {
+ tokens = {
+ newLine: '\n',
+ newLineOrSpace: '\n',
+ pad,
+ indent: pad + opts.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 (opts.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 <= opts.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 + opts.indent);
+ };
+
+ if (seen.indexOf(val) !== -1) {
+ return '"[Circular]"';
+ }
+
+ if (val === null ||
+ val === undefined ||
+ typeof val === 'number' ||
+ typeof val === 'boolean' ||
+ typeof val === 'function' ||
+ typeof val === 'symbol' ||
+ isRegexp(val)) {
+ return String(val);
+ }
+
+ if (val instanceof Date) {
+ return `new Date('${val.toISOString()}')`;
+ }
+
+ if (Array.isArray(val)) {
+ if (val.length === 0) {
+ return '[]';
+ }
+
+ seen.push(val);
+
+ const ret = '[' + tokens.newLine + val.map((el, i) => {
+ const eol = val.length - 1 === i ? tokens.newLine : ',' + tokens.newLineOrSpace;
+ let value = stringify(el, opts, pad + opts.indent);
+ if (opts.transform) {
+ value = opts.transform(val, i, value);
+ }
+ return tokens.indent + value + eol;
+ }).join('') + tokens.pad + ']';
+
+ seen.pop();
+
+ return expandWhiteSpace(ret);
+ }
+
+ if (isObj(val)) {
+ let objKeys = Object.keys(val).concat(getOwnEnumPropSymbols(val));
+
+ if (opts.filter) {
+ objKeys = objKeys.filter(el => opts.filter(val, el));
+ }
+
+ if (objKeys.length === 0) {
+ return '{}';
+ }
+
+ seen.push(val);
+
+ const ret = '{' + tokens.newLine + objKeys.map((el, i) => {
+ const eol = objKeys.length - 1 === i ? tokens.newLine : ',' + tokens.newLineOrSpace;
+ const isSymbol = typeof el === 'symbol';
+ const isClassic = !isSymbol && /^[a-z$_][a-z$_0-9]*$/i.test(el);
+ const key = isSymbol || isClassic ? el : stringify(el, opts);
+ let value = stringify(val[el], opts, pad + opts.indent);
+ if (opts.transform) {
+ value = opts.transform(val, el, value);
+ }
+ return tokens.indent + String(key) + ': ' + value + eol;
+ }).join('') + tokens.pad + '}';
+
+ seen.pop();
+
+ return expandWhiteSpace(ret);
+ }
+
+ val = String(val).replace(/[\r\n]/g, x => x === '\n' ? '\\n' : '\\r');
+
+ if (opts.singleQuotes === false) {
+ val = val.replace(/"/g, '\\"');
+ return `"${val}"`;
+ }
+
+ val = val.replace(/\\?'/g, '\\\'');
+ return `'${val}'`;
+ })(val, opts, pad);
+};
diff --git a/node_modules/stringify-object/package.json b/node_modules/stringify-object/package.json
new file mode 100644
index 00000000..74d638c0
--- /dev/null
+++ b/node_modules/stringify-object/package.json
@@ -0,0 +1,40 @@
+{
+ "name": "stringify-object",
+ "version": "3.3.0",
+ "description": "Stringify an object/array like JSON.stringify just without all the double-quotes",
+ "license": "BSD-2-Clause",
+ "repository": "yeoman/stringify-object",
+ "author": {
+ "name": "Sindre Sorhus",
+ "email": "sindresorhus@gmail.com",
+ "url": "sindresorhus.com"
+ },
+ "engines": {
+ "node": ">=4"
+ },
+ "scripts": {
+ "test": "xo && ava"
+ },
+ "files": [
+ "index.js"
+ ],
+ "keywords": [
+ "object",
+ "stringify",
+ "pretty",
+ "print",
+ "dump",
+ "format",
+ "type",
+ "json"
+ ],
+ "dependencies": {
+ "get-own-enumerable-property-symbols": "^3.0.0",
+ "is-obj": "^1.0.1",
+ "is-regexp": "^1.0.0"
+ },
+ "devDependencies": {
+ "ava": "*",
+ "xo": "*"
+ }
+}
diff --git a/node_modules/stringify-object/readme.md b/node_modules/stringify-object/readme.md
new file mode 100644
index 00000000..d4d6c3d7
--- /dev/null
+++ b/node_modules/stringify-object/readme.md
@@ -0,0 +1,155 @@
+# stringify-object [![Build Status](https://secure.travis-ci.org/yeoman/stringify-object.svg?branch=master)](http://travis-ci.org/yeoman/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
+
+```
+$ npm install stringify-object
+```
+
+
+## Usage
+
+```js
+const stringifyObject = require('stringify-object');
+
+const obj = {
+ foo: 'bar',
+ 'arr': [1, 2, 3],
+ nested: { hello: "world" }
+};
+
+const pretty = stringifyObject(obj, {
+ 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]"`.
+
+#### input
+
+Type: `Object` `Array`
+
+#### options
+
+##### indent
+
+Type: `string`<br>
+Default: `\t`
+
+Preferred indentation.
+
+##### singleQuotes
+
+Type: `boolean`<br>
+Default: `true`
+
+Set to false to get double-quoted strings.
+
+##### filter(obj, prop)
+
+Type: `Function`
+
+Expected to return a `boolean` of whether to include the property `prop` of the object `obj` in the output.
+
+##### transform(obj, prop, originalResult)
+
+Type: `Function`<br>
+Default: `undefined`
+
+Expected to return a `string` that transforms the string that resulted from stringifying `obj[prop]`. 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
+const obj = {
+ user: 'becky',
+ password: 'secret'
+}
+
+const pretty = stringifyObject(obj, {
+ transform: (obj, prop, originalResult) => {
+ if (prop === 'password') {
+ return originalResult.replace(/\w/g, '*');
+ } else {
+ 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
+const obj = {
+ foo: 'bar',
+ 'arr': [1, 2, 3],
+ nested: { hello: "world" }
+};
+
+const pretty = stringifyObject(obj, {
+ 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.
+
+
+## License
+
+BSD-2-Clause © Yeoman team