feat: Created a mini nodeJS server with NewMan for testing without PostMan GUI.

This will mimic a run in a CD/CI environment or docker container.
This commit is contained in:
Simon Priet
2021-09-08 14:01:19 +02:00
parent 5fbd7c88fa
commit e69a613a37
5610 changed files with 740417 additions and 3 deletions

8
node_modules/flatted/.github/FUNDING.yml generated vendored Normal file
View File

@@ -0,0 +1,8 @@
# These are supported funding model platforms
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # not working due missing www.
open_collective: #
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
custom: https://www.patreon.com/webreflection

15
node_modules/flatted/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,15 @@
ISC License
Copyright (c) 2018-2020, Andrea Giammarchi, @WebReflection
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.

71
node_modules/flatted/README.md generated vendored Normal file
View File

@@ -0,0 +1,71 @@
# flatted
[![Downloads](https://img.shields.io/npm/dm/flatted.svg)](https://www.npmjs.com/package/flatted) [![Coverage Status](https://coveralls.io/repos/github/WebReflection/flatted/badge.svg?branch=master)](https://coveralls.io/github/WebReflection/flatted?branch=master) [![Build Status](https://travis-ci.org/WebReflection/flatted.svg?branch=master)](https://travis-ci.org/WebReflection/flatted) [![License: ISC](https://img.shields.io/badge/License-ISC-yellow.svg)](https://opensource.org/licenses/ISC) ![WebReflection status](https://offline.report/status/webreflection.svg)
![snow flake](./flatted.jpg)
<sup>**Social Media Photo by [Matt Seymour](https://unsplash.com/@mattseymour) on [Unsplash](https://unsplash.com/)**</sup>
A super light (0.5K) and fast circular JSON parser, directly from the creator of [CircularJSON](https://github.com/WebReflection/circular-json/#circularjson).
Now available also for **[PHP](./php/flatted.php)**.
```js
npm i flatted
```
Usable via [CDN](https://unpkg.com/flatted) or as regular module.
```js
// ESM
import {parse, stringify} from 'flatted';
// CJS
const {parse, stringify} = require('flatted');
const a = [{}];
a[0].a = a;
a.push(a);
stringify(a); // [["1","0"],{"a":"0"}]
```
## Flatted VS JSON
As it is for every other specialized format capable of serializing and deserializing circular data, you should never `JSON.parse(Flatted.stringify(data))`, and you should never `Flatted.parse(JSON.stringify(data))`.
The only way this could work is to `Flatted.parse(Flatted.stringify(data))`, as it is also for _CircularJSON_ or any other, otherwise there's no granted data integrity.
Also please note this project serializes and deserializes only data compatible with JSON, so that sockets, or anything else with internal classes different from those allowed by JSON standard, won't be serialized and unserialized as expected.
### New in V1: Exact same JSON API
* Added a [reviver](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Syntax) parameter to `.parse(string, reviver)` and revive your own objects.
* Added a [replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Syntax) and a `space` parameter to `.stringify(object, replacer, space)` for feature parity with JSON signature.
### Compatibility
All ECMAScript engines compatible with `Map`, `Set`, `Object.keys`, and `Array.prototype.reduce` will work, even if polyfilled.
### How does it work ?
While stringifying, all Objects, including Arrays, and strings, are flattened out and replaced as unique index. `*`
Once parsed, all indexes will be replaced through the flattened collection.
<sup><sub>`*` represented as string to avoid conflicts with numbers</sub></sup>
```js
// logic example
var a = [{one: 1}, {two: '2'}];
a[0].a = a;
// a is the main object, will be at index '0'
// {one: 1} is the second object, index '1'
// {two: '2'} the third, in '2', and it has a string
// which will be found at index '3'
Flatted.stringify(a);
// [["1","2"],{"one":1,"a":"0"},{"two":"3"},"2"]
// a[one,two] {one: 1, a} {two: '2'} '2'
```

94
node_modules/flatted/SPECS.md generated vendored Normal file
View File

@@ -0,0 +1,94 @@
# Flatted Specifications
This document describes operations performed to produce, or parse, the flatted output.
## stringify(any) => flattedString
The output is always an `Array` that contains at index `0` the given value.
If the value is an `Array` or an `Object`, per each property value passed through the callback, return the value as is if it's not an `Array`, an `Object`, or a `string`.
In case it's an `Array`, an `Object`, or a `string`, return the index as `string`, associated through a `Map`.
Giving the following example:
```js
flatted.stringify('a'); // ["a"]
flatted.stringify(['a']); // [["1"],"a"]
flatted.stringify(['a', 1, 'b']); // [["1",1,"2"],"a","b"]
```
There is an `input` containing `[array, "a", "b"]`, where the `array` has indexes `"1"` and `"2"` as strings, indexes that point respectively at `"a"` and `"b"` within the input `[array, "a", "b"]`.
The exact same happens for objects.
```js
flatted.stringify('a'); // ["a"]
flatted.stringify({a: 'a'}); // [{"a":"1"},"a"]
flatted.stringify({a: 'a', n: 1, b: 'b'}); // [{"a":"1","n":1,"b":"2"},"a","b"]
```
Every object, string, or array, encountered during serialization will be stored once as stringified index.
```js
// per each property/value of the object/array
if (any == null || !/object|string/.test(typeof any))
return any;
if (!map.has(any)) {
const index = String(arr.length);
arr.push(any);
map.set(any, index);
}
return map.get(any);
```
This, performed before going through all properties, grants unique indexes per reference.
The stringified indexes ensure there won't be conflicts with regularly stored numbers.
## parse(flattedString) => any
Everything that is a `string` is wrapped as `new String`, but strings in the array, from index `1` on, is kept as regular `string`.
```js
const input = JSON.parse('[{"a":"1"},"b"]', Strings).map(strings);
// convert strings primitives into String instances
function Strings(key, value) {
return typeof value === 'string' ? new String(value) : value;
}
// converts String instances into strings primitives
function strings(value) {
return value instanceof String ? String(value) : value;
}
```
The `input` array will have a regular `string` at index `1`, but its object at index `0` will have an `instanceof String` as `.a` property.
That is the key to place back values from the rest of the array, so that per each property of the object at index `0`, if the value is an `instanceof` String, something not serializable via JSON, it means it can be used to retrieve the position of its value from the `input` array.
If such `value` is an object and it hasn't been parsed yet, add it as parsed and go through all its properties/values.
```js
// outside any loop ...
const parsed = new Set;
// ... per each property/value ...
if (value instanceof Primitive) {
const tmp = input[parseInt(value)];
if (typeof tmp === 'object' && !parsed.has(tmp)) {
parsed.add(tmp);
output[key] = tmp;
if (typeof tmp === 'object' && tmp != null) {
// perform this same logic per
// each nested property/value ...
}
} else {
output[key] = tmp;
}
} else
output[key] = tmp;
```
As summary, the whole logic is based on polluting the de-serialization with a kind of variable that is unexpected, hence secure to use as directive to retrieve an index with a value.
The usage of a `Map` and a `Set` to flag known references/strings as visited/stored makes **flatted** a rock solid, fast, and compact, solution.

94
node_modules/flatted/cjs/index.js generated vendored Normal file
View File

@@ -0,0 +1,94 @@
'use strict';
/*! (c) 2020 Andrea Giammarchi */
const {parse: $parse, stringify: $stringify} = JSON;
const {keys} = Object;
const Primitive = String; // it could be Number
const primitive = 'string'; // it could be 'number'
const ignore = {};
const object = 'object';
const noop = (_, value) => value;
const primitives = value => (
value instanceof Primitive ? Primitive(value) : value
);
const Primitives = (_, value) => (
typeof value === primitive ? new Primitive(value) : value
);
const revive = (input, parsed, output, $) => {
const lazy = [];
for (let ke = keys(output), {length} = ke, y = 0; y < length; y++) {
const k = ke[y];
const value = output[k];
if (value instanceof Primitive) {
const tmp = input[value];
if (typeof tmp === object && !parsed.has(tmp)) {
parsed.add(tmp);
output[k] = ignore;
lazy.push({k, a: [input, parsed, tmp, $]});
}
else
output[k] = $.call(output, k, tmp);
}
else if (output[k] !== ignore)
output[k] = $.call(output, k, value);
}
for (let {length} = lazy, i = 0; i < length; i++) {
const {k, a} = lazy[i];
output[k] = $.call(output, k, revive.apply(null, a));
}
return output;
};
const set = (known, input, value) => {
const index = Primitive(input.push(value) - 1);
known.set(value, index);
return index;
};
const parse = (text, reviver) => {
const input = $parse(text, Primitives).map(primitives);
const value = input[0];
const $ = reviver || noop;
const tmp = typeof value === object && value ?
revive(input, new Set, value, $) :
value;
return $.call({'': tmp}, '', tmp);
};
exports.parse = parse;
const stringify = (value, replacer, space) => {
const $ = replacer && typeof replacer === object ?
(k, v) => (k === '' || -1 < replacer.indexOf(k) ? v : void 0) :
(replacer || noop);
const known = new Map;
const input = [];
const output = [];
let i = +set(known, input, $.call({'': value}, '', value));
let firstRun = !i;
while (i < input.length) {
firstRun = true;
output[i] = $stringify(input[i++], replace, space);
}
return '[' + output.join(',') + ']';
function replace(key, value) {
if (firstRun) {
firstRun = !firstRun;
return value;
}
const after = $.call(this, key, value);
switch (typeof after) {
case object:
if (after === null) return after;
case primitive:
return known.get(after) || set(known, input, after);
}
return after;
}
};
exports.stringify = stringify;

1
node_modules/flatted/cjs/package.json generated vendored Normal file
View File

@@ -0,0 +1 @@
{"type":"commonjs"}

2
node_modules/flatted/es.js generated vendored Normal file
View File

@@ -0,0 +1,2 @@
self.Flatted=function(t){"use strict";
/*! (c) 2020 Andrea Giammarchi */const{parse:e,stringify:n}=JSON,{keys:r}=Object,s=String,c="string",l={},o="object",a=(t,e)=>e,i=t=>t instanceof s?s(t):t,f=(t,e)=>typeof e===c?new s(e):e,u=(t,e,n,c)=>{const a=[];for(let i=r(n),{length:f}=i,u=0;u<f;u++){const r=i[u],f=n[r];if(f instanceof s){const s=t[f];typeof s!==o||e.has(s)?n[r]=c.call(n,r,s):(e.add(s),n[r]=l,a.push({k:r,a:[t,e,s,c]}))}else n[r]!==l&&(n[r]=c.call(n,r,f))}for(let{length:t}=a,e=0;e<t;e++){const{k:t,a:r}=a[e];n[t]=c.call(n,t,u.apply(null,r))}return n},p=(t,e,n)=>{const r=s(e.push(n)-1);return t.set(n,r),r};return t.parse=(t,n)=>{const r=e(t,f).map(i),s=r[0],c=n||a,l=typeof s===o&&s?u(r,new Set,s,c):s;return c.call({"":l},"",l)},t.stringify=(t,e,r)=>{const s=e&&typeof e===o?(t,n)=>""===t||-1<e.indexOf(t)?n:void 0:e||a,l=new Map,i=[],f=[];let u=+p(l,i,s.call({"":t},"",t)),y=!u;for(;u<i.length;)y=!0,f[u]=n(i[u++],g,r);return"["+f.join(",")+"]";function g(t,e){if(y)return y=!y,e;const n=s.call(this,t,e);switch(typeof n){case o:if(null===n)return n;case c:return l.get(n)||p(l,i,n)}return n}},t}({});

91
node_modules/flatted/esm/index.js generated vendored Normal file
View File

@@ -0,0 +1,91 @@
/*! (c) 2020 Andrea Giammarchi */
const {parse: $parse, stringify: $stringify} = JSON;
const {keys} = Object;
const Primitive = String; // it could be Number
const primitive = 'string'; // it could be 'number'
const ignore = {};
const object = 'object';
const noop = (_, value) => value;
const primitives = value => (
value instanceof Primitive ? Primitive(value) : value
);
const Primitives = (_, value) => (
typeof value === primitive ? new Primitive(value) : value
);
const revive = (input, parsed, output, $) => {
const lazy = [];
for (let ke = keys(output), {length} = ke, y = 0; y < length; y++) {
const k = ke[y];
const value = output[k];
if (value instanceof Primitive) {
const tmp = input[value];
if (typeof tmp === object && !parsed.has(tmp)) {
parsed.add(tmp);
output[k] = ignore;
lazy.push({k, a: [input, parsed, tmp, $]});
}
else
output[k] = $.call(output, k, tmp);
}
else if (output[k] !== ignore)
output[k] = $.call(output, k, value);
}
for (let {length} = lazy, i = 0; i < length; i++) {
const {k, a} = lazy[i];
output[k] = $.call(output, k, revive.apply(null, a));
}
return output;
};
const set = (known, input, value) => {
const index = Primitive(input.push(value) - 1);
known.set(value, index);
return index;
};
export const parse = (text, reviver) => {
const input = $parse(text, Primitives).map(primitives);
const value = input[0];
const $ = reviver || noop;
const tmp = typeof value === object && value ?
revive(input, new Set, value, $) :
value;
return $.call({'': tmp}, '', tmp);
};
export const stringify = (value, replacer, space) => {
const $ = replacer && typeof replacer === object ?
(k, v) => (k === '' || -1 < replacer.indexOf(k) ? v : void 0) :
(replacer || noop);
const known = new Map;
const input = [];
const output = [];
let i = +set(known, input, $.call({'': value}, '', value));
let firstRun = !i;
while (i < input.length) {
firstRun = true;
output[i] = $stringify(input[i++], replace, space);
}
return '[' + output.join(',') + ']';
function replace(key, value) {
if (firstRun) {
firstRun = !firstRun;
return value;
}
const after = $.call(this, key, value);
switch (typeof after) {
case object:
if (after === null) return after;
case primitive:
return known.get(after) || set(known, input, after);
}
return after;
}
};

BIN
node_modules/flatted/flatted.jpg generated vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

119
node_modules/flatted/index.js generated vendored Normal file
View File

@@ -0,0 +1,119 @@
self.Flatted = (function (exports) {
'use strict';
/*! (c) 2020 Andrea Giammarchi */
var $parse = JSON.parse,
$stringify = JSON.stringify;
var keys = Object.keys;
var Primitive = String; // it could be Number
var primitive = 'string'; // it could be 'number'
var ignore = {};
var object = 'object';
var noop = function noop(_, value) {
return value;
};
var primitives = function primitives(value) {
return value instanceof Primitive ? Primitive(value) : value;
};
var Primitives = function Primitives(_, value) {
return typeof(value) === primitive ? new Primitive(value) : value;
};
var revive = function revive(input, parsed, output, $) {
var lazy = [];
for (var ke = keys(output), length = ke.length, y = 0; y < length; y++) {
var k = ke[y];
var value = output[k];
if (value instanceof Primitive) {
var tmp = input[value];
if (typeof(tmp) === object && !parsed.has(tmp)) {
parsed.add(tmp);
output[k] = ignore;
lazy.push({
k: k,
a: [input, parsed, tmp, $]
});
} else output[k] = $.call(output, k, tmp);
} else if (output[k] !== ignore) output[k] = $.call(output, k, value);
}
for (var _length = lazy.length, i = 0; i < _length; i++) {
var _lazy$i = lazy[i],
_k = _lazy$i.k,
a = _lazy$i.a;
output[_k] = $.call(output, _k, revive.apply(null, a));
}
return output;
};
var set = function set(known, input, value) {
var index = Primitive(input.push(value) - 1);
known.set(value, index);
return index;
};
var parse = function parse(text, reviver) {
var input = $parse(text, Primitives).map(primitives);
var value = input[0];
var $ = reviver || noop;
var tmp = typeof(value) === object && value ? revive(input, new Set(), value, $) : value;
return $.call({
'': tmp
}, '', tmp);
};
var stringify = function stringify(value, replacer, space) {
var $ = replacer && typeof(replacer) === object ? function (k, v) {
return k === '' || -1 < replacer.indexOf(k) ? v : void 0;
} : replacer || noop;
var known = new Map();
var input = [];
var output = [];
var i = +set(known, input, $.call({
'': value
}, '', value));
var firstRun = !i;
while (i < input.length) {
firstRun = true;
output[i] = $stringify(input[i++], replace, space);
}
return '[' + output.join(',') + ']';
function replace(key, value) {
if (firstRun) {
firstRun = !firstRun;
return value;
}
var after = $.call(this, key, value);
switch (typeof(after)) {
case object:
if (after === null) return after;
case primitive:
return known.get(after) || set(known, input, after);
}
return after;
}
};
exports.parse = parse;
exports.stringify = stringify;
return exports;
}({}));

2
node_modules/flatted/min.js generated vendored Normal file
View File

@@ -0,0 +1,2 @@
self.Flatted=function(n){"use strict";
/*! (c) 2020 Andrea Giammarchi */var t=JSON.parse,r=JSON.stringify,e=Object.keys,a=String,u="string",f={},i="object",c=function(n,t){return t},l=function(n){return n instanceof a?a(n):n},o=function(n,t){return typeof t===u?new a(t):t},s=function(n,t,r){var e=a(t.push(r)-1);return n.set(r,e),e};return n.parse=function(n,r){var u=t(n,o).map(l),s=u[0],p=r||c,v=typeof s===i&&s?function n(t,r,u,c){for(var l=[],o=e(u),s=o.length,p=0;p<s;p++){var v=o[p],y=u[v];if(y instanceof a){var g=t[y];typeof g!==i||r.has(g)?u[v]=c.call(u,v,g):(r.add(g),u[v]=f,l.push({k:v,a:[t,r,g,c]}))}else u[v]!==f&&(u[v]=c.call(u,v,y))}for(var h=l.length,d=0;d<h;d++){var w=l[d],O=w.k,S=w.a;u[O]=c.call(u,O,n.apply(null,S))}return u}(u,new Set,s,p):s;return p.call({"":v},"",v)},n.stringify=function(n,t,e){for(var a=t&&typeof t===i?function(n,r){return""===n||-1<t.indexOf(n)?r:void 0}:t||c,f=new Map,l=[],o=[],p=+s(f,l,a.call({"":n},"",n)),v=!p;p<l.length;)v=!0,o[p]=r(l[p++],y,e);return"["+o.join(",")+"]";function y(n,t){if(v)return v=!v,t;var r=a.call(this,n,t);switch(typeof r){case i:if(null===r)return r;case u:return f.get(r)||s(f,l,r)}return r}},n}({});

57
node_modules/flatted/package.json generated vendored Normal file
View File

@@ -0,0 +1,57 @@
{
"name": "flatted",
"version": "3.1.1",
"description": "A super light and fast circular JSON parser.",
"unpkg": "min.js",
"types": "types.d.ts",
"main": "./cjs/index.js",
"scripts": {
"build": "npm run cjs && 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:babel": "rollup --config rollup/babel.config.js && sed -i.bck 's/^var /self./' index.js && rm -rf index.js.bck && drop-babel-typeof index.js",
"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",
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"test": "nyc node test/index.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/WebReflection/flatted.git"
},
"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.11.6",
"@babel/preset-env": "^7.11.5",
"ascjs": "^4.0.1",
"circular-json": "^0.5.9",
"circular-json-es6": "^2.0.2",
"coveralls": "^3.1.0",
"drop-babel-typeof": "^1.0.3",
"jsan": "^3.1.13",
"nyc": "^15.1.0",
"rollup": "^2.26.11",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-terser": "^7.0.2",
"terser": "^5.3.0"
},
"module": "./esm/index.js",
"type": "module",
"exports": {
"import": "./esm/index.js",
"default": "./cjs/index.js"
}
}

174
node_modules/flatted/php/flatted.php generated vendored Normal file
View File

@@ -0,0 +1,174 @@
<?php
/*!
* ISC License
*
* Copyright (c) 2018-2020, Andrea Giammarchi, @WebReflection
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
class FlattedString {
public function __construct($value) {
$this->value = $value;
}
}
class Flatted {
// public utilities
public static function parse($json, $assoc = false, $depth = 512, $options = 0) {
$input = array_map(
'Flatted::asString',
array_map(
'Flatted::wrap',
json_decode($json, $assoc, $depth, $options)
)
);
$value = &$input[0];
$set = array();
$set[] = &$value;
if (is_array($value))
return Flatted::loop(false, array_keys($value), $input, $set, $value);
if (is_object($value))
return Flatted::loop(true, Flatted::keys($value), $input, $set, $value);
return $value;
}
public static function stringify($value, $options = 0, $depth = 512) {
$known = new stdClass;
$known->key = array();
$known->value = array();
$input = array();
$output = array();
$i = intval(Flatted::index($known, $input, $value));
while ($i < count($input)) {
$output[$i] = Flatted::transform($known, $input, $input[$i]);
$i++;
}
return json_encode($output, $options, $depth);
}
// private helpers
private static function asString(&$value) {
return $value instanceof FlattedString ? $value->value : $value;
}
private static function index(&$known, &$input, &$value) {
$input[] = &$value;
$index = strval(count($input) - 1);
$known->key[] = &$value;
$known->value[] = &$index;
return $index;
}
private static function keys(&$value) {
$obj = new ReflectionObject($value);
$props = $obj->getProperties();
$keys = array();
foreach ($props as $prop) {
$keys[] = $prop->getName();
}
return $keys;
}
private static function loop($obj, $keys, &$input, &$set, &$output) {
foreach ($keys as $key) {
$value = $obj ? $output->$key : $output[$key];
if ($value instanceof FlattedString) {
Flatted::ref($obj, $key, $input[$value->value], $input, $set, $output);
}
}
return $output;
}
private static function relate(&$known, &$input, &$value) {
if (is_string($value)) {
$key = array_search($value, $known->key, true);
if ($key !== false) {
return $known->value[$key];
}
return Flatted::index($known, $input, $value);
}
if (is_array($value)) {
$key = array_search($value, $known->key, true);
if ($key !== false) {
return $known->value[$key];
}
return Flatted::index($known, $input, $value);
}
if (is_object($value)) {
$key = array_search($value, $known->key, true);
if ($key !== false) {
return $known->value[$key];
}
return Flatted::index($known, $input, $value);
}
return $value;
}
private static function ref($obj, &$key, &$value, &$input, &$set, &$output) {
if (is_array($value) && !in_array($value, $set, true)) {
$set[] = $value;
$value = Flatted::loop(false, array_keys($value), $input, $set, $value);
}
elseif (is_object($value) && !in_array($value, $set, true)) {
$set[] = $value;
$value = Flatted::loop(true, Flatted::keys($value), $input, $set, $value);
}
if ($obj) {
$output->$key = &$value;
}
else {
$output[$key] = &$value;
}
}
private static function transform(&$known, &$input, &$value) {
if (is_array($value)) {
return array_map(
function (&$value) use(&$known, &$input) {
return Flatted::relate($known, $input, $value);
},
$value
);
}
if (is_object($value)) {
$object = new stdClass;
$keys = Flatted::keys($value);
foreach ($keys as $key) {
$object->$key = Flatted::relate($known, $input, $value->$key);
}
return $object;
}
return $value;
}
private static function wrap(&$value) {
if (is_string($value)) {
return new FlattedString($value);
}
if (is_array($value)) {
return array_map('Flatted::wrap', $value);
}
if (is_object($value)) {
$keys = Flatted::keys($value);
foreach ($keys as $key) {
$value->$key = self::wrap($value->$key);
}
return $value;
}
return $value;
}
}
?>

118
node_modules/flatted/php/test.php generated vendored Normal file
View File

@@ -0,0 +1,118 @@
<?php
error_reporting(E_ALL | E_STRICT);
require_once('flatted.php');
class console {
public static function assert($condition, $message) {
if (!$condition) {
echo $message."\n";
exit(1);
}
}
}
console::assert(Flatted::stringify([null, null]) === '[[null,null]]', 'multiple null failed');
$a = array();
$o = new stdClass;
console::assert(Flatted::stringify($a) === '[[]]', 'empty Array');
console::assert(Flatted::stringify($o) === '[{}]', 'empty Object');
$a[] = &$a;
$o->o = &$o;
console::assert(Flatted::stringify($a) === '[["0"]]', 'recursive Array');
console::assert(Flatted::stringify($o) === '[{"o":"0"}]', 'recursive Object');
$b = Flatted::parse(Flatted::stringify($a));
console::assert(is_array($b) && $b[0] === $b, 'restoring recursive Array');
$a[] = 1;
$a[] = 'two';
$a[] = true;
$o->one = 1;
$o->two = 'two';
$o->three = true;
console::assert(Flatted::stringify($a) === '[["0",1,"1",true],"two"]', 'values in Array');
console::assert(Flatted::stringify($o) === '[{"o":"0","one":1,"two":"1","three":true},"two"]', 'values in Object');
$a[] = &$o;
$o->a = &$a;
console::assert(Flatted::stringify($a) === '[["0",1,"1",true,"2"],"two",{"o":"2","one":1,"two":"1","three":true,"a":"0"}]', 'object in Array');
console::assert(Flatted::stringify($o) === '[{"o":"0","one":1,"two":"1","three":true,"a":"2"},"two",["2",1,"1",true,"0"]]', 'array in Object');
$a[] = array('test' => 'OK');
$a[] = [1, 2, 3];
$o->test = array('test' => 'OK');
$o->array = [1, 2, 3];
console::assert(Flatted::stringify($a) === '[["0",1,"1",true,"2","3","4"],"two",{"o":"2","one":1,"two":"1","three":true,"a":"0","test":"3","array":"4"},{"test":"5"},[1,2,3],"OK"]', 'objects in Array');
console::assert(Flatted::stringify($o) === '[{"o":"0","one":1,"two":"1","three":true,"a":"2","test":"3","array":"4"},"two",["2",1,"1",true,"0","3","4"],{"test":"5"},[1,2,3],"OK"]', 'objects in Object');
$a2 = Flatted::parse(Flatted::stringify($a));
$o2 = Flatted::parse(Flatted::stringify($o));
console::assert($a2[0] === $a2, 'parsed Array');
console::assert($o2->o === $o2, 'parsed Object');
console::assert(
$a2[1] === 1 &&
$a2[2] === 'two' &&
$a2[3] === true &&
$a2[4] instanceof stdClass &&
json_encode($a2[5]) === json_encode(array('test' => 'OK')) &&
json_encode($a2[6]) === json_encode([1, 2, 3]),
'array values are all OK'
);
console::assert($a2[4] === $a2[4]->o && $a2 === $a2[4]->o->a, 'array recursive values are OK');
console::assert(
$o2->one === 1 &&
$o2->two === 'two' &&
$o2->three === true &&
is_array($o2->a) &&
json_encode($o2->test) === json_encode(array('test' => 'OK')) &&
json_encode($o2->array) === json_encode([1, 2, 3]),
'object values are all OK'
);
console::assert($o2->a === $o2->a[0] && $o2 === $o2->a[4], 'object recursive values are OK');
console::assert(Flatted::parse(Flatted::stringify(1)) === 1, 'numbers can be parsed too');
console::assert(Flatted::parse(Flatted::stringify(false)) === false, 'booleans can be parsed too');
console::assert(Flatted::parse(Flatted::stringify(null)) === null, 'null can be parsed too');
console::assert(Flatted::parse(Flatted::stringify('test')) === 'test', 'strings can be parsed too');
$str = Flatted::parse('[{"prop":"1","a":"2","b":"3"},{"value":123},["4","5"],{"e":"6","t":"7","p":4},{},{"b":"8"},"f",{"a":"9"},["10"],"sup",{"a":1,"d":2,"c":"7","z":"11","h":1},{"g":2,"a":"7","b":"12","f":6},{"r":4,"u":"7","c":5}]');
console::assert(
$str->b->t->a === 'sup' &&
$str->a[1]->b[0]->c === $str->b->t,
'str is fine'
);
$oo = Flatted::parse('[{"a":"1","b":"0","c":"2"},{"aa":"3"},{"ca":"4","cb":"5","cc":"6","cd":"7","ce":"8","cf":"9"},{"aaa":"10"},{"caa":"4"},{"cba":"5"},{"cca":"2"},{"cda":"4"},"value2","value3","value1"]');
console::assert(
$oo->a->aa->aaa = 'value1'
&& $oo === $oo->b
&& $oo === $oo->b
&& $oo->c->ca->caa === $oo->c->ca
&& $oo->c->cb->cba === $oo->c->cb
&& $oo->c->cc->cca === $oo->c
&& $oo->c->cd->cda === $oo->c->ca->caa
&& $oo->c->ce === 'value2'
&& $oo->c->cf === 'value3',
'parse is correct'
);
echo "OK\n";
?>

52
node_modules/flatted/types.d.ts generated vendored Normal file
View File

@@ -0,0 +1,52 @@
interface Flatted {
/**
* Converts a JavaScript Object Notation (using Flatted encoding) string into an object.
* @param text A valid Flatted string.
* @param reviver A function that transforms the results. This function is called for each member of the object.
* If a member contains nested objects, the nested objects are transformed before the parent object is.
*/
parse(
text: string,
reviver?: (this: any, key: string, value: any) => any
): any;
/**
* Converts a JavaScript value to a JavaScript Object Notation (using Flatted encoding) string.
* @param value A JavaScript value, usually an object or array, to be converted.
* @param replacer A function that transforms the results.
* @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.
*/
stringify(
value: any,
replacer?: (this: any, key: string, value: any) => any,
space?: string | number
): string;
/**
* Converts a JavaScript value to a JavaScript Object Notation (using Flatted encoding) string.
* @param value A JavaScript value, usually an object or array, to be converted.
* @param replacer An array of strings and numbers that acts as an approved list for selecting the object properties that will be stringified.
* @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.
*/
stringify(
value: any,
replacer?: (number | string)[] | null,
space?: string | number
): string;
}
/**
* Fast and minimal circular JSON parser.
* logic example
```js
var a = [{one: 1}, {two: '2'}];
a[0].a = a;
// a is the main object, will be at index '0'
// {one: 1} is the second object, index '1'
// {two: '2'} the third, in '2', and it has a string
// which will be found at index '3'
Flatted.stringify(a);
// [["1","2"],{"one":1,"a":"0"},{"two":"3"},"2"]
// a[one,two] {one: 1, a} {two: '2'} '2'
```
*/
declare const Flatted: Flatted;
export = Flatted;