diff options
Diffstat (limited to 'node_modules/write-json-file')
12 files changed, 0 insertions, 783 deletions
diff --git a/node_modules/write-json-file/index.js b/node_modules/write-json-file/index.js deleted file mode 100644 index cbd7e706a..000000000 --- a/node_modules/write-json-file/index.js +++ /dev/null @@ -1,73 +0,0 @@ -'use strict'; -const path = require('path'); -const fs = require('graceful-fs'); -const writeFileAtomic = require('write-file-atomic'); -const sortKeys = require('sort-keys'); -const makeDir = require('make-dir'); -const pify = require('pify'); -const detectIndent = require('detect-indent'); - -const init = (fn, fp, data, opts) => { - if (!fp) { - throw new TypeError('Expected a filepath'); - } - - if (data === undefined) { - throw new TypeError('Expected data to stringify'); - } - - opts = Object.assign({ - indent: '\t', - sortKeys: false - }, opts); - - if (opts.sortKeys) { - data = sortKeys(data, { - deep: true, - compare: typeof opts.sortKeys === 'function' && opts.sortKeys - }); - } - - return fn(fp, data, opts); -}; - -const readFile = fp => pify(fs.readFile)(fp, 'utf8').catch(() => {}); - -const main = (fp, data, opts) => { - return (opts.detectIndent ? readFile(fp) : Promise.resolve()) - .then(str => { - const indent = str ? detectIndent(str).indent : opts.indent; - const json = JSON.stringify(data, opts.replacer, indent); - - return pify(writeFileAtomic)(fp, `${json}\n`, {mode: opts.mode}); - }); -}; - -const mainSync = (fp, data, opts) => { - let indent = opts.indent; - - if (opts.detectIndent) { - try { - const file = fs.readFileSync(fp, 'utf8'); - indent = detectIndent(file).indent; - } catch (err) { - if (err.code !== 'ENOENT') { - throw err; - } - } - } - - const json = JSON.stringify(data, opts.replacer, indent); - - return writeFileAtomic.sync(fp, `${json}\n`, {mode: opts.mode}); -}; - -module.exports = (fp, data, opts) => { - return makeDir(path.dirname(fp), {fs}) - .then(() => init(main, fp, data, opts)); -}; - -module.exports.sync = (fp, data, opts) => { - makeDir.sync(path.dirname(fp), {fs}); - init(mainSync, fp, data, opts); -}; diff --git a/node_modules/write-json-file/license b/node_modules/write-json-file/license deleted file mode 100644 index e7af2f771..000000000 --- a/node_modules/write-json-file/license +++ /dev/null @@ -1,9 +0,0 @@ -MIT License - -Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com) - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/write-json-file/node_modules/detect-indent/index.js b/node_modules/write-json-file/node_modules/detect-indent/index.js deleted file mode 100644 index eda0b1b1a..000000000 --- a/node_modules/write-json-file/node_modules/detect-indent/index.js +++ /dev/null @@ -1,122 +0,0 @@ -'use strict'; - -// detect either spaces or tabs but not both to properly handle tabs -// for indentation and spaces for alignment -const INDENT_RE = /^(?:( )+|\t+)/; - -function getMostUsed(indents) { - let result = 0; - let maxUsed = 0; - let maxWeight = 0; - - for (const entry of indents) { - // TODO: use destructuring when targeting Node.js 6 - const key = entry[0]; - const val = entry[1]; - - const u = val[0]; - const w = val[1]; - - if (u > maxUsed || (u === maxUsed && w > maxWeight)) { - maxUsed = u; - maxWeight = w; - result = Number(key); - } - } - - return result; -} - -module.exports = str => { - if (typeof str !== 'string') { - throw new TypeError('Expected a string'); - } - - // used to see if tabs or spaces are the most used - let tabs = 0; - let spaces = 0; - - // remember the size of previous line's indentation - let prev = 0; - - // remember how many indents/unindents as occurred for a given size - // and how much lines follow a given indentation - // - // indents = { - // 3: [1, 0], - // 4: [1, 5], - // 5: [1, 0], - // 12: [1, 0], - // } - const indents = new Map(); - - // pointer to the array of last used indent - let current; - - // whether the last action was an indent (opposed to an unindent) - let isIndent; - - for (const line of str.split(/\n/g)) { - if (!line) { - // ignore empty lines - continue; - } - - let indent; - const matches = line.match(INDENT_RE); - - if (matches) { - indent = matches[0].length; - - if (matches[1]) { - spaces++; - } else { - tabs++; - } - } else { - indent = 0; - } - - const diff = indent - prev; - prev = indent; - - if (diff) { - // an indent or unindent has been detected - - isIndent = diff > 0; - - current = indents.get(isIndent ? diff : -diff); - - if (current) { - current[0]++; - } else { - current = [1, 0]; - indents.set(diff, current); - } - } else if (current) { - // if the last action was an indent, increment the weight - current[1] += Number(isIndent); - } - } - - const amount = getMostUsed(indents); - - let type; - let indent; - if (!amount) { - type = null; - indent = ''; - } else if (spaces >= tabs) { - type = 'space'; - indent = ' '.repeat(amount); - } else { - type = 'tab'; - indent = '\t'.repeat(amount); - } - - return { - amount, - type, - indent - }; -}; diff --git a/node_modules/write-json-file/node_modules/detect-indent/license b/node_modules/write-json-file/node_modules/detect-indent/license deleted file mode 100644 index 654d0bfe9..000000000 --- a/node_modules/write-json-file/node_modules/detect-indent/license +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/node_modules/write-json-file/node_modules/detect-indent/package.json b/node_modules/write-json-file/node_modules/detect-indent/package.json deleted file mode 100644 index 81c7edf31..000000000 --- a/node_modules/write-json-file/node_modules/detect-indent/package.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "name": "detect-indent", - "version": "5.0.0", - "description": "Detect the indentation of code", - "license": "MIT", - "repository": "sindresorhus/detect-indent", - "author": { - "name": "Sindre Sorhus", - "email": "sindresorhus@gmail.com", - "url": "sindresorhus.com" - }, - "engines": { - "node": ">=4" - }, - "scripts": { - "test": "xo && ava" - }, - "files": [ - "index.js" - ], - "keywords": [ - "indent", - "indentation", - "detect", - "infer", - "identify", - "code", - "string", - "text", - "source", - "space", - "tab" - ], - "devDependencies": { - "ava": "*", - "xo": "*" - }, - "xo": { - "esnext": true - } -} diff --git a/node_modules/write-json-file/node_modules/detect-indent/readme.md b/node_modules/write-json-file/node_modules/detect-indent/readme.md deleted file mode 100644 index 3aeb1badf..000000000 --- a/node_modules/write-json-file/node_modules/detect-indent/readme.md +++ /dev/null @@ -1,111 +0,0 @@ -# detect-indent [](https://travis-ci.org/sindresorhus/detect-indent) - -> Detect the indentation of code - -Pass in a string of any kind of text and get the indentation. - - -## Use cases - -- Persisting the indentation when modifying a file. -- Have new content match the existing indentation. -- Setting the right indentation in your editor. - - -## Install - -``` -$ npm install --save detect-indent -``` - - -## Usage - -Here we modify a JSON file while persisting the indentation: - -```js -const fs = require('fs'); -const detectIndent = require('detect-indent'); - -/* -{ - "ilove": "pizza" -} -*/ -const file = fs.readFileSync('foo.json', 'utf8'); - -// tries to detect the indentation and falls back to a default if it can't -const indent = detectIndent(file).indent || ' '; - -const json = JSON.parse(file); - -json.ilove = 'unicorns'; - -fs.writeFileSync('foo.json', JSON.stringify(json, null, indent)); -/* -{ - "ilove": "unicorns" -} -*/ -``` - - -## API - -Accepts a string and returns an object with stats about the indentation: - -* `amount` {number} - Amount of indentation, for example `2` -* `type` {string|null} - Type of indentation. Possible values are `tab`, `space` or `null` if no indentation is detected -* `indent` {string} - Actual indentation - - -## Algorithm - -The current algorithm looks for the most common difference between two consecutive non-empty lines. - -In the following example, even if the 4-space indentation is used 3 times whereas the 2-space one is used 2 times, it is detected as less used because there were only 2 differences with this value instead of 4 for the 2-space indentation: - -```css -html { - box-sizing: border-box; -} - -body { - background: gray; -} - -p { - line-height: 1.3em; - margin-top: 1em; - text-indent: 2em; -} -``` - -[Source.](https://medium.com/@heatherarthur/detecting-code-indentation-eff3ed0fb56b#3918) - -Furthermore, if there are more than one most used difference, the indentation with the most lines is selected. - -In the following example, the indentation is detected as 4-spaces: - -```css -body { - background: gray; -} - -p { - line-height: 1.3em; - margin-top: 1em; - text-indent: 2em; -} -``` - - -## Related - -- [detect-indent-cli](https://github.com/sindresorhus/detect-indent-cli) - CLI for this module -- [detect-newline](https://github.com/sindresorhus/detect-newline) - Detect the dominant newline character of a string - - -## License - -MIT © [Sindre Sorhus](https://sindresorhus.com) diff --git a/node_modules/write-json-file/node_modules/pify/index.js b/node_modules/write-json-file/node_modules/pify/index.js deleted file mode 100644 index 1dee43ad0..000000000 --- a/node_modules/write-json-file/node_modules/pify/index.js +++ /dev/null @@ -1,84 +0,0 @@ -'use strict'; - -const processFn = (fn, opts) => function () { - const P = opts.promiseModule; - const args = new Array(arguments.length); - - for (let i = 0; i < arguments.length; i++) { - args[i] = arguments[i]; - } - - return new P((resolve, reject) => { - if (opts.errorFirst) { - args.push(function (err, result) { - if (opts.multiArgs) { - const results = new Array(arguments.length - 1); - - for (let i = 1; i < arguments.length; i++) { - results[i - 1] = arguments[i]; - } - - if (err) { - results.unshift(err); - reject(results); - } else { - resolve(results); - } - } else if (err) { - reject(err); - } else { - resolve(result); - } - }); - } else { - args.push(function (result) { - if (opts.multiArgs) { - const results = new Array(arguments.length - 1); - - for (let i = 0; i < arguments.length; i++) { - results[i] = arguments[i]; - } - - resolve(results); - } else { - resolve(result); - } - }); - } - - fn.apply(this, args); - }); -}; - -module.exports = (obj, opts) => { - opts = Object.assign({ - exclude: [/.+(Sync|Stream)$/], - errorFirst: true, - promiseModule: Promise - }, opts); - - const filter = key => { - const match = pattern => typeof pattern === 'string' ? key === pattern : pattern.test(key); - return opts.include ? opts.include.some(match) : !opts.exclude.some(match); - }; - - let ret; - if (typeof obj === 'function') { - ret = function () { - if (opts.excludeMain) { - return obj.apply(this, arguments); - } - - return processFn(obj, opts).apply(this, arguments); - }; - } else { - ret = Object.create(Object.getPrototypeOf(obj)); - } - - for (const key in obj) { // eslint-disable-line guard-for-in - const x = obj[key]; - ret[key] = typeof x === 'function' && filter(key) ? processFn(x, opts) : x; - } - - return ret; -}; diff --git a/node_modules/write-json-file/node_modules/pify/license b/node_modules/write-json-file/node_modules/pify/license deleted file mode 100644 index e7af2f771..000000000 --- a/node_modules/write-json-file/node_modules/pify/license +++ /dev/null @@ -1,9 +0,0 @@ -MIT License - -Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com) - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/write-json-file/node_modules/pify/package.json b/node_modules/write-json-file/node_modules/pify/package.json deleted file mode 100644 index 468d85760..000000000 --- a/node_modules/write-json-file/node_modules/pify/package.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "name": "pify", - "version": "3.0.0", - "description": "Promisify a callback-style function", - "license": "MIT", - "repository": "sindresorhus/pify", - "author": { - "name": "Sindre Sorhus", - "email": "sindresorhus@gmail.com", - "url": "sindresorhus.com" - }, - "engines": { - "node": ">=4" - }, - "scripts": { - "test": "xo && ava && npm run optimization-test", - "optimization-test": "node --allow-natives-syntax optimization-test.js" - }, - "files": [ - "index.js" - ], - "keywords": [ - "promise", - "promises", - "promisify", - "all", - "denodify", - "denodeify", - "callback", - "cb", - "node", - "then", - "thenify", - "convert", - "transform", - "wrap", - "wrapper", - "bind", - "to", - "async", - "await", - "es2015", - "bluebird" - ], - "devDependencies": { - "ava": "*", - "pinkie-promise": "^2.0.0", - "v8-natives": "^1.0.0", - "xo": "*" - } -} diff --git a/node_modules/write-json-file/node_modules/pify/readme.md b/node_modules/write-json-file/node_modules/pify/readme.md deleted file mode 100644 index 376ca4e59..000000000 --- a/node_modules/write-json-file/node_modules/pify/readme.md +++ /dev/null @@ -1,131 +0,0 @@ -# pify [](https://travis-ci.org/sindresorhus/pify) - -> Promisify a callback-style function - - -## Install - -``` -$ npm install --save pify -``` - - -## Usage - -```js -const fs = require('fs'); -const pify = require('pify'); - -// Promisify a single function -pify(fs.readFile)('package.json', 'utf8').then(data => { - console.log(JSON.parse(data).name); - //=> 'pify' -}); - -// Promisify all methods in a module -pify(fs).readFile('package.json', 'utf8').then(data => { - console.log(JSON.parse(data).name); - //=> 'pify' -}); -``` - - -## API - -### pify(input, [options]) - -Returns a `Promise` wrapped version of the supplied function or module. - -#### input - -Type: `Function` `Object` - -Callback-style function or module whose methods you want to promisify. - -#### options - -##### multiArgs - -Type: `boolean`<br> -Default: `false` - -By default, the promisified function will only return the second argument from the callback, which works fine for most APIs. This option can be useful for modules like `request` that return multiple arguments. Turning this on will make it return an array of all arguments from the callback, excluding the error argument, instead of just the second argument. This also applies to rejections, where it returns an array of all the callback arguments, including the error. - -```js -const request = require('request'); -const pify = require('pify'); - -pify(request, {multiArgs: true})('https://sindresorhus.com').then(result => { - const [httpResponse, body] = result; -}); -``` - -##### include - -Type: `string[]` `RegExp[]` - -Methods in a module to promisify. Remaining methods will be left untouched. - -##### exclude - -Type: `string[]` `RegExp[]`<br> -Default: `[/.+(Sync|Stream)$/]` - -Methods in a module **not** to promisify. Methods with names ending with `'Sync'` are excluded by default. - -##### excludeMain - -Type: `boolean`<br> -Default: `false` - -If given module is a function itself, it will be promisified. Turn this option on if you want to promisify only methods of the module. - -```js -const pify = require('pify'); - -function fn() { - return true; -} - -fn.method = (data, callback) => { - setImmediate(() => { - callback(null, data); - }); -}; - -// Promisify methods but not `fn()` -const promiseFn = pify(fn, {excludeMain: true}); - -if (promiseFn()) { - promiseFn.method('hi').then(data => { - console.log(data); - }); -} -``` - -##### errorFirst - -Type: `boolean`<br> -Default: `true` - -Whether the callback has an error as the first argument. You'll want to set this to `false` if you're dealing with an API that doesn't have an error as the first argument, like `fs.exists()`, some browser APIs, Chrome Extension APIs, etc. - -##### promiseModule - -Type: `Function` - -Custom promise module to use instead of the native one. - -Check out [`pinkie-promise`](https://github.com/floatdrop/pinkie-promise) if you need a tiny promise polyfill. - - -## Related - -- [p-event](https://github.com/sindresorhus/p-event) - Promisify an event by waiting for it to be emitted -- [p-map](https://github.com/sindresorhus/p-map) - Map over promises concurrently -- [More…](https://github.com/sindresorhus/promise-fun) - - -## License - -MIT © [Sindre Sorhus](https://sindresorhus.com) diff --git a/node_modules/write-json-file/package.json b/node_modules/write-json-file/package.json deleted file mode 100644 index 169c7a888..000000000 --- a/node_modules/write-json-file/package.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "name": "write-json-file", - "version": "2.3.0", - "description": "Stringify and write JSON to a file atomically", - "license": "MIT", - "repository": "sindresorhus/write-json-file", - "author": { - "name": "Sindre Sorhus", - "email": "sindresorhus@gmail.com", - "url": "sindresorhus.com" - }, - "engines": { - "node": ">=4" - }, - "scripts": { - "test": "xo && ava" - }, - "files": [ - "index.js" - ], - "keywords": [ - "write", - "json", - "stringify", - "file", - "fs", - "graceful", - "stable", - "sort", - "newline", - "indent", - "atomic", - "atomically" - ], - "dependencies": { - "detect-indent": "^5.0.0", - "graceful-fs": "^4.1.2", - "make-dir": "^1.0.0", - "pify": "^3.0.0", - "sort-keys": "^2.0.0", - "write-file-atomic": "^2.0.0" - }, - "devDependencies": { - "ava": "*", - "tempfile": "^2.0.0", - "xo": "*" - } -} diff --git a/node_modules/write-json-file/readme.md b/node_modules/write-json-file/readme.md deleted file mode 100644 index c148f0529..000000000 --- a/node_modules/write-json-file/readme.md +++ /dev/null @@ -1,83 +0,0 @@ -# write-json-file [](https://travis-ci.org/sindresorhus/write-json-file) - -> Stringify and write JSON to a file [atomically](https://github.com/npm/write-file-atomic) - -Creates directories for you as needed. - - -## Install - -``` -$ npm install write-json-file -``` - - -## Usage - -```js -const writeJsonFile = require('write-json-file'); - -writeJsonFile('foo.json', {foo: true}).then(() => { - console.log('done'); -}); -``` - - -## API - -### writeJsonFile(filepath, data, [options]) - -Returns a `Promise`. - -### writeJsonFile.sync(filepath, data, [options]) - -#### options - -Type: `Object` - -##### indent - -Type: `string` `number`<br> -Default: `'\t'` - -Indentation as a string or number of spaces.<br> -Pass in `null` for no formatting. - -##### detectIndent - -Type: `boolean`<br> -Default: `false` - -Detect indentation automatically if the file exists. - -##### sortKeys - -Type: `boolean` `function`<br> -Default: `false` - -Sort the keys recursively.<br> -Optionally pass in a [`compare`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) function. - -##### replacer - -Type: `function` - -Passed into [`JSON.stringify`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter). - -##### mode - -Type: `number`<br> -Default: `0o666` - -[Mode](https://en.wikipedia.org/wiki/File_system_permissions#Numeric_notation) used when writing the file. - - -## Related - -- [load-json-file](https://github.com/sindresorhus/load-json-file) - Read and parse a JSON file -- [make-dir](https://github.com/sindresorhus/make-dir) - Make a directory and its parents if needed - - -## License - -MIT © [Sindre Sorhus](https://sindresorhus.com) |