This commit is contained in:
lalBi94
2023-03-05 13:23:23 +01:00
commit 7bc56c09b5
14034 changed files with 1834369 additions and 0 deletions

8
node_modules/flat/.travis.yml generated vendored Normal file
View File

@@ -0,0 +1,8 @@
language: node_js
node_js:
- "6"
- "7"
- "8"
- "10"
- "12"
- "14"

12
node_modules/flat/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,12 @@
Copyright (c) 2014, Hugh Kennedy
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.
3. Neither the name of the nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
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 HOLDER 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.

236
node_modules/flat/README.md generated vendored Normal file
View File

@@ -0,0 +1,236 @@
# flat [![Build Status](https://secure.travis-ci.org/hughsk/flat.png?branch=master)](http://travis-ci.org/hughsk/flat)
Take a nested Javascript object and flatten it, or unflatten an object with
delimited keys.
## Installation
``` bash
$ npm install flat
```
## Methods
### flatten(original, options)
Flattens the object - it'll return an object one level deep, regardless of how
nested the original object was:
``` javascript
var flatten = require('flat')
flatten({
key1: {
keyA: 'valueI'
},
key2: {
keyB: 'valueII'
},
key3: { a: { b: { c: 2 } } }
})
// {
// 'key1.keyA': 'valueI',
// 'key2.keyB': 'valueII',
// 'key3.a.b.c': 2
// }
```
### unflatten(original, options)
Flattening is reversible too, you can call `flatten.unflatten()` on an object:
``` javascript
var unflatten = require('flat').unflatten
unflatten({
'three.levels.deep': 42,
'three.levels': {
nested: true
}
})
// {
// three: {
// levels: {
// deep: 42,
// nested: true
// }
// }
// }
```
## Options
### delimiter
Use a custom delimiter for (un)flattening your objects, instead of `.`.
### safe
When enabled, both `flat` and `unflatten` will preserve arrays and their
contents. This is disabled by default.
``` javascript
var flatten = require('flat')
flatten({
this: [
{ contains: 'arrays' },
{ preserving: {
them: 'for you'
}}
]
}, {
safe: true
})
// {
// 'this': [
// { contains: 'arrays' },
// { preserving: {
// them: 'for you'
// }}
// ]
// }
```
### object
When enabled, arrays will not be created automatically when calling unflatten, like so:
``` javascript
unflatten({
'hello.you.0': 'ipsum',
'hello.you.1': 'lorem',
'hello.other.world': 'foo'
}, { object: true })
// hello: {
// you: {
// 0: 'ipsum',
// 1: 'lorem',
// },
// other: { world: 'foo' }
// }
```
### overwrite
When enabled, existing keys in the unflattened object may be overwritten if they cannot hold a newly encountered nested value:
```javascript
unflatten({
'TRAVIS': 'true',
'TRAVIS.DIR': '/home/travis/build/kvz/environmental'
}, { overwrite: true })
// TRAVIS: {
// DIR: '/home/travis/build/kvz/environmental'
// }
```
Without `overwrite` set to `true`, the `TRAVIS` key would already have been set to a string, thus could not accept the nested `DIR` element.
This only makes sense on ordered arrays, and since we're overwriting data, should be used with care.
### maxDepth
Maximum number of nested objects to flatten.
``` javascript
var flatten = require('flat')
flatten({
key1: {
keyA: 'valueI'
},
key2: {
keyB: 'valueII'
},
key3: { a: { b: { c: 2 } } }
}, { maxDepth: 2 })
// {
// 'key1.keyA': 'valueI',
// 'key2.keyB': 'valueII',
// 'key3.a': { b: { c: 2 } }
// }
```
### transformKey
Transform each part of a flat key before and after flattening.
```javascript
var flatten = require('flat')
var unflatten = require('flat').unflatten
flatten({
key1: {
keyA: 'valueI'
},
key2: {
keyB: 'valueII'
},
key3: { a: { b: { c: 2 } } }
}, {
transformKey: function(key){
return '__' + key + '__';
}
})
// {
// '__key1__.__keyA__': 'valueI',
// '__key2__.__keyB__': 'valueII',
// '__key3__.__a__.__b__.__c__': 2
// }
unflatten({
'__key1__.__keyA__': 'valueI',
'__key2__.__keyB__': 'valueII',
'__key3__.__a__.__b__.__c__': 2
}, {
transformKey: function(key){
return key.substring(2, key.length - 2)
}
})
// {
// key1: {
// keyA: 'valueI'
// },
// key2: {
// keyB: 'valueII'
// },
// key3: { a: { b: { c: 2 } } }
// }
```
## Command Line Usage
`flat` is also available as a command line tool. You can run it with
[`npx`](https://ghub.io/npx):
```sh
npx flat foo.json
```
Or install the `flat` command globally:
```sh
npm i -g flat && flat foo.json
```
Accepts a filename as an argument:
```sh
flat foo.json
```
Also accepts JSON on stdin:
```sh
cat foo.json | flat
```

42
node_modules/flat/cli.js generated vendored Normal file
View File

@@ -0,0 +1,42 @@
#!/usr/bin/env node
const fs = require('fs')
const path = require('path')
const readline = require('readline')
const flat = require('./index')
const filepath = process.argv.slice(2)[0]
if (filepath) {
// Read from file
const file = path.resolve(process.cwd(), filepath)
fs.accessSync(file, fs.constants.R_OK) // allow to throw if not readable
out(require(file))
} else if (process.stdin.isTTY) {
usage(0)
} else {
// Read from newline-delimited STDIN
const lines = []
readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
})
.on('line', line => lines.push(line))
.on('close', () => out(JSON.parse(lines.join('\n'))))
}
function out (data) {
process.stdout.write(JSON.stringify(flat(data), null, 2))
}
function usage (code) {
console.log(`
Usage:
flat foo.json
cat foo.json | flat
`)
process.exit(code || 0)
}

158
node_modules/flat/index.js generated vendored Normal file
View File

@@ -0,0 +1,158 @@
module.exports = flatten
flatten.flatten = flatten
flatten.unflatten = unflatten
function isBuffer (obj) {
return obj &&
obj.constructor &&
(typeof obj.constructor.isBuffer === 'function') &&
obj.constructor.isBuffer(obj)
}
function keyIdentity (key) {
return key
}
function flatten (target, opts) {
opts = opts || {}
const delimiter = opts.delimiter || '.'
const maxDepth = opts.maxDepth
const transformKey = opts.transformKey || keyIdentity
const output = {}
function step (object, prev, currentDepth) {
currentDepth = currentDepth || 1
Object.keys(object).forEach(function (key) {
const value = object[key]
const isarray = opts.safe && Array.isArray(value)
const type = Object.prototype.toString.call(value)
const isbuffer = isBuffer(value)
const isobject = (
type === '[object Object]' ||
type === '[object Array]'
)
const newKey = prev
? prev + delimiter + transformKey(key)
: transformKey(key)
if (!isarray && !isbuffer && isobject && Object.keys(value).length &&
(!opts.maxDepth || currentDepth < maxDepth)) {
return step(value, newKey, currentDepth + 1)
}
output[newKey] = value
})
}
step(target)
return output
}
function unflatten (target, opts) {
opts = opts || {}
const delimiter = opts.delimiter || '.'
const overwrite = opts.overwrite || false
const transformKey = opts.transformKey || keyIdentity
const result = {}
const isbuffer = isBuffer(target)
if (isbuffer || Object.prototype.toString.call(target) !== '[object Object]') {
return target
}
// safely ensure that the key is
// an integer.
function getkey (key) {
const parsedKey = Number(key)
return (
isNaN(parsedKey) ||
key.indexOf('.') !== -1 ||
opts.object
) ? key
: parsedKey
}
function addKeys (keyPrefix, recipient, target) {
return Object.keys(target).reduce(function (result, key) {
result[keyPrefix + delimiter + key] = target[key]
return result
}, recipient)
}
function isEmpty (val) {
const type = Object.prototype.toString.call(val)
const isArray = type === '[object Array]'
const isObject = type === '[object Object]'
if (!val) {
return true
} else if (isArray) {
return !val.length
} else if (isObject) {
return !Object.keys(val).length
}
}
target = Object.keys(target).reduce(function (result, key) {
const type = Object.prototype.toString.call(target[key])
const isObject = (type === '[object Object]' || type === '[object Array]')
if (!isObject || isEmpty(target[key])) {
result[key] = target[key]
return result
} else {
return addKeys(
key,
result,
flatten(target[key], opts)
)
}
}, {})
Object.keys(target).forEach(function (key) {
const split = key.split(delimiter).map(transformKey)
let key1 = getkey(split.shift())
let key2 = getkey(split[0])
let recipient = result
while (key2 !== undefined) {
if (key1 === '__proto__') {
return
}
const type = Object.prototype.toString.call(recipient[key1])
const isobject = (
type === '[object Object]' ||
type === '[object Array]'
)
// do not write over falsey, non-undefined values if overwrite is false
if (!overwrite && !isobject && typeof recipient[key1] !== 'undefined') {
return
}
if ((overwrite && !isobject) || (!overwrite && recipient[key1] == null)) {
recipient[key1] = (
typeof key2 === 'number' &&
!opts.object ? [] : {}
)
}
recipient = recipient[key1]
if (split.length > 0) {
key1 = getkey(split.shift())
key2 = getkey(split[0])
}
}
// unflatten again for 'messy objects'
recipient[key1] = unflatten(target[key], opts)
})
return result
}

37
node_modules/flat/package.json generated vendored Normal file
View File

@@ -0,0 +1,37 @@
{
"name": "flat",
"version": "5.0.2",
"main": "index.js",
"bin": "cli.js",
"scripts": {
"test": "mocha -u tdd --reporter spec && standard cli.js index.js test/index.js"
},
"license": "BSD-3-Clause",
"description": "Take a nested Javascript object and flatten it, or unflatten an object with delimited keys",
"devDependencies": {
"mocha": "~8.1.1",
"standard": "^14.3.4"
},
"directories": {
"test": "test"
},
"dependencies": {},
"repository": {
"type": "git",
"url": "git://github.com/hughsk/flat.git"
},
"keywords": [
"flat",
"json",
"flatten",
"unflatten",
"split",
"object",
"nested"
],
"author": "Hugh Kennedy <hughskennedy@gmail.com> (http://hughskennedy.com)",
"bugs": {
"url": "https://github.com/hughsk/flat/issues"
},
"homepage": "https://github.com/hughsk/flat"
}

643
node_modules/flat/test/test.js generated vendored Normal file

File diff suppressed because it is too large Load Diff