Initial React project
This commit is contained in:
14
node_modules/flatted/README.md
generated
vendored
14
node_modules/flatted/README.md
generated
vendored
@@ -1,6 +1,6 @@
|
||||
# flatted
|
||||
|
||||
[](https://www.npmjs.com/package/flatted) [](https://coveralls.io/github/WebReflection/flatted?branch=main) [](https://opensource.org/licenses/ISC) 
|
||||
[](https://www.npmjs.com/package/flatted) [](https://coveralls.io/github/WebReflection/flatted?branch=main) [](https://travis-ci.com/WebReflection/flatted) [](https://opensource.org/licenses/ISC) 
|
||||
|
||||

|
||||
|
||||
@@ -12,13 +12,17 @@ Available also for **[PHP](./php/flatted.php)**.
|
||||
|
||||
Available also for **[Python](./python/flatted.py)**.
|
||||
|
||||
Available also for **[Go](./golang/README.md)**.
|
||||
|
||||
- - -
|
||||
|
||||
## ℹ️ JSON only values
|
||||
## Announcement 📣
|
||||
|
||||
If you need anything more complex than values JSON understands, there is a standard approach to recursion and more data-types than what JSON allows, and it's part of the [Structured Clone polyfill](https://github.com/ungap/structured-clone/#readme).
|
||||
There is a standard approach to recursion and more data-types than what JSON allows, and it's part of the [Structured Clone polyfill](https://github.com/ungap/structured-clone/#readme).
|
||||
|
||||
Beside acting as a polyfill, its `@ungap/structured-clone/json` export provides both `stringify` and `parse`, and it's been tested for being faster than *flatted*, but its produced output is also smaller than *flatted* in general.
|
||||
|
||||
The *@ungap/structured-clone* module is, in short, a drop in replacement for *flatted*, but it's not compatible with *flatted* specialized syntax.
|
||||
|
||||
However, if recursion, as well as more data-types, are what you are after, or interesting for your projects/use cases, consider switching to this new module whenever you can 👍
|
||||
|
||||
- - -
|
||||
|
||||
|
||||
31
node_modules/flatted/cjs/index.js
generated
vendored
31
node_modules/flatted/cjs/index.js
generated
vendored
@@ -22,7 +22,8 @@ const Primitives = (_, value) => (
|
||||
typeof value === primitive ? new Primitive(value) : value
|
||||
);
|
||||
|
||||
const resolver = (input, lazy, parsed, $) => output => {
|
||||
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];
|
||||
@@ -31,7 +32,7 @@ const resolver = (input, lazy, parsed, $) => output => {
|
||||
if (typeof tmp === object && !parsed.has(tmp)) {
|
||||
parsed.add(tmp);
|
||||
output[k] = ignore;
|
||||
lazy.push({ o: output, k, r: tmp });
|
||||
lazy.push({k, a: [input, parsed, tmp, $]});
|
||||
}
|
||||
else
|
||||
output[k] = $.call(output, k, tmp);
|
||||
@@ -39,6 +40,10 @@ const resolver = (input, lazy, parsed, $) => output => {
|
||||
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;
|
||||
};
|
||||
|
||||
@@ -56,24 +61,12 @@ const set = (known, input, value) => {
|
||||
*/
|
||||
const parse = (text, reviver) => {
|
||||
const input = $parse(text, Primitives).map(primitives);
|
||||
const value = input[0];
|
||||
const $ = reviver || noop;
|
||||
|
||||
let value = input[0];
|
||||
|
||||
if (typeof value === object && value) {
|
||||
const lazy = [];
|
||||
const revive = resolver(input, lazy, new Set, $);
|
||||
value = revive(value);
|
||||
|
||||
let i = 0;
|
||||
while (i < lazy.length) {
|
||||
// it could be a lazy.shift() but that's costly
|
||||
const {o, k, r} = lazy[i++];
|
||||
o[k] = $.call(o, k, revive(r));
|
||||
}
|
||||
}
|
||||
|
||||
return $.call({'': value}, '', value);
|
||||
const tmp = typeof value === object && value ?
|
||||
revive(input, new Set, value, $) :
|
||||
value;
|
||||
return $.call({'': tmp}, '', tmp);
|
||||
};
|
||||
exports.parse = parse;
|
||||
|
||||
|
||||
2
node_modules/flatted/es.js
generated
vendored
2
node_modules/flatted/es.js
generated
vendored
@@ -1 +1 @@
|
||||
self.Flatted=function(t){"use strict";const{parse:e,stringify:n}=JSON,{keys:r}=Object,o=String,s="string",c={},l="object",f=(t,e)=>e,i=t=>t instanceof o?o(t):t,a=(t,e)=>typeof e===s?new o(e):e,u=(t,e,n)=>{const r=o(e.push(n)-1);return t.set(n,r),r},p=(t,n)=>{const s=e(t,a).map(i),u=n||f;let p=s[0];if(typeof p===l&&p){const t=[],e=((t,e,n,s)=>f=>{for(let i=r(f),{length:a}=i,u=0;u<a;u++){const r=i[u],a=f[r];if(a instanceof o){const o=t[a];typeof o!==l||n.has(o)?f[r]=s.call(f,r,o):(n.add(o),f[r]=c,e.push({o:f,k:r,r:o}))}else f[r]!==c&&(f[r]=s.call(f,r,a))}return f})(s,t,new Set,u);p=e(p);let n=0;for(;n<t.length;){const{o:r,k:o,r:s}=t[n++];r[o]=u.call(r,o,e(s))}}return u.call({"":p},"",p)},g=(t,e,r)=>{const o=e&&typeof e===l?(t,n)=>""===t||-1<e.indexOf(t)?n:void 0:e||f,c=new Map,i=[],a=[];let p=+u(c,i,o.call({"":t},"",t)),g=!p;for(;p<i.length;)g=!0,a[p]=n(i[p++],h,r);return"["+a.join(",")+"]";function h(t,e){if(g)return g=!g,e;const n=o.call(this,t,e);switch(typeof n){case l:if(null===n)return n;case s:return c.get(n)||u(c,i,n)}return n}};return t.fromJSON=t=>p(n(t)),t.parse=p,t.stringify=g,t.toJSON=t=>e(g(t)),t}({});
|
||||
self.Flatted=function(t){"use strict";const{parse:e,stringify:n}=JSON,{keys:r}=Object,s=String,o="string",c={},l="object",a=(t,e)=>e,f=t=>t instanceof s?s(t):t,i=(t,e)=>typeof e===o?new s(e):e,u=(t,e,n,o)=>{const a=[];for(let f=r(n),{length:i}=f,u=0;u<i;u++){const r=f[u],i=n[r];if(i instanceof s){const s=t[i];typeof s!==l||e.has(s)?n[r]=o.call(n,r,s):(e.add(s),n[r]=c,a.push({k:r,a:[t,e,s,o]}))}else n[r]!==c&&(n[r]=o.call(n,r,i))}for(let{length:t}=a,e=0;e<t;e++){const{k:t,a:r}=a[e];n[t]=o.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},y=(t,n)=>{const r=e(t,i).map(f),s=r[0],o=n||a,c=typeof s===l&&s?u(r,new Set,s,o):s;return o.call({"":c},"",c)},g=(t,e,r)=>{const s=e&&typeof e===l?(t,n)=>""===t||-1<e.indexOf(t)?n:void 0:e||a,c=new Map,f=[],i=[];let u=+p(c,f,s.call({"":t},"",t)),y=!u;for(;u<f.length;)y=!0,i[u]=n(f[u++],g,r);return"["+i.join(",")+"]";function g(t,e){if(y)return y=!y,e;const n=s.call(this,t,e);switch(typeof n){case l:if(null===n)return n;case o:return c.get(n)||p(c,f,n)}return n}};return t.fromJSON=t=>y(n(t)),t.parse=y,t.stringify=g,t.toJSON=t=>e(g(t)),t}({});
|
||||
|
||||
2
node_modules/flatted/esm.js
generated
vendored
2
node_modules/flatted/esm.js
generated
vendored
@@ -1 +1 @@
|
||||
const{parse:t,stringify:e}=JSON,{keys:n}=Object,o=String,r="string",s={},c="object",l=(t,e)=>e,f=t=>t instanceof o?o(t):t,i=(t,e)=>typeof e===r?new o(e):e,a=(t,e,n)=>{const r=o(e.push(n)-1);return t.set(n,r),r},u=(e,r)=>{const a=t(e,i).map(f),u=r||l;let p=a[0];if(typeof p===c&&p){const t=[],e=((t,e,r,l)=>f=>{for(let i=n(f),{length:a}=i,u=0;u<a;u++){const n=i[u],a=f[n];if(a instanceof o){const o=t[a];typeof o!==c||r.has(o)?f[n]=l.call(f,n,o):(r.add(o),f[n]=s,e.push({o:f,k:n,r:o}))}else f[n]!==s&&(f[n]=l.call(f,n,a))}return f})(a,t,new Set,u);p=e(p);let r=0;for(;r<t.length;){const{o:n,k:o,r:s}=t[r++];n[o]=u.call(n,o,e(s))}}return u.call({"":p},"",p)},p=(t,n,o)=>{const s=n&&typeof n===c?(t,e)=>""===t||-1<n.indexOf(t)?e:void 0:n||l,f=new Map,i=[],u=[];let p=+a(f,i,s.call({"":t},"",t)),h=!p;for(;p<i.length;)h=!0,u[p]=e(i[p++],g,o);return"["+u.join(",")+"]";function g(t,e){if(h)return h=!h,e;const n=s.call(this,t,e);switch(typeof n){case c:if(null===n)return n;case r:return f.get(n)||a(f,i,n)}return n}},h=e=>t(p(e)),g=t=>u(e(t));export{g as fromJSON,u as parse,p as stringify,h as toJSON};
|
||||
const{parse:t,stringify:e}=JSON,{keys:n}=Object,l=String,o="string",r={},s="object",c=(t,e)=>e,a=t=>t instanceof l?l(t):t,f=(t,e)=>typeof e===o?new l(e):e,i=(t,e,o,c)=>{const a=[];for(let f=n(o),{length:i}=f,p=0;p<i;p++){const n=f[p],i=o[n];if(i instanceof l){const l=t[i];typeof l!==s||e.has(l)?o[n]=c.call(o,n,l):(e.add(l),o[n]=r,a.push({k:n,a:[t,e,l,c]}))}else o[n]!==r&&(o[n]=c.call(o,n,i))}for(let{length:t}=a,e=0;e<t;e++){const{k:t,a:n}=a[e];o[t]=c.call(o,t,i.apply(null,n))}return o},p=(t,e,n)=>{const o=l(e.push(n)-1);return t.set(n,o),o},u=(e,n)=>{const l=t(e,f).map(a),o=l[0],r=n||c,p=typeof o===s&&o?i(l,new Set,o,r):o;return r.call({"":p},"",p)},h=(t,n,l)=>{const r=n&&typeof n===s?(t,e)=>""===t||-1<n.indexOf(t)?e:void 0:n||c,a=new Map,f=[],i=[];let u=+p(a,f,r.call({"":t},"",t)),h=!u;for(;u<f.length;)h=!0,i[u]=e(f[u++],y,l);return"["+i.join(",")+"]";function y(t,e){if(h)return h=!h,e;const n=r.call(this,t,e);switch(typeof n){case s:if(null===n)return n;case o:return a.get(n)||p(a,f,n)}return n}},y=e=>t(h(e)),g=t=>u(e(t));export{g as fromJSON,u as parse,h as stringify,y as toJSON};
|
||||
|
||||
31
node_modules/flatted/esm/index.js
generated
vendored
31
node_modules/flatted/esm/index.js
generated
vendored
@@ -21,7 +21,8 @@ const Primitives = (_, value) => (
|
||||
typeof value === primitive ? new Primitive(value) : value
|
||||
);
|
||||
|
||||
const resolver = (input, lazy, parsed, $) => output => {
|
||||
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];
|
||||
@@ -30,7 +31,7 @@ const resolver = (input, lazy, parsed, $) => output => {
|
||||
if (typeof tmp === object && !parsed.has(tmp)) {
|
||||
parsed.add(tmp);
|
||||
output[k] = ignore;
|
||||
lazy.push({ o: output, k, r: tmp });
|
||||
lazy.push({k, a: [input, parsed, tmp, $]});
|
||||
}
|
||||
else
|
||||
output[k] = $.call(output, k, tmp);
|
||||
@@ -38,6 +39,10 @@ const resolver = (input, lazy, parsed, $) => output => {
|
||||
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;
|
||||
};
|
||||
|
||||
@@ -55,24 +60,12 @@ const set = (known, input, value) => {
|
||||
*/
|
||||
export const parse = (text, reviver) => {
|
||||
const input = $parse(text, Primitives).map(primitives);
|
||||
const value = input[0];
|
||||
const $ = reviver || noop;
|
||||
|
||||
let value = input[0];
|
||||
|
||||
if (typeof value === object && value) {
|
||||
const lazy = [];
|
||||
const revive = resolver(input, lazy, new Set, $);
|
||||
value = revive(value);
|
||||
|
||||
let i = 0;
|
||||
while (i < lazy.length) {
|
||||
// it could be a lazy.shift() but that's costly
|
||||
const {o, k, r} = lazy[i++];
|
||||
o[k] = $.call(o, k, revive(r));
|
||||
}
|
||||
}
|
||||
|
||||
return $.call({'': value}, '', value);
|
||||
const tmp = typeof value === object && value ?
|
||||
revive(input, new Set, value, $) :
|
||||
value;
|
||||
return $.call({'': tmp}, '', tmp);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
60
node_modules/flatted/golang/README.md
generated
vendored
60
node_modules/flatted/golang/README.md
generated
vendored
@@ -1,60 +0,0 @@
|
||||
# flatted (Go)
|
||||
|
||||
A super light and fast circular JSON parser.
|
||||
|
||||
## Usage
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/WebReflection/flatted/golang/pkg/flatted"
|
||||
)
|
||||
|
||||
type Group struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
Name string `json:"name"`
|
||||
Friend *User `json:"friend"`
|
||||
Group *Group `json:"group"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
group := &Group{Name: "Developers"}
|
||||
alice := &User{Name: "Alice", Group: group}
|
||||
bob := &User{Name: "Bob", Group: group}
|
||||
|
||||
alice.Friend = bob
|
||||
bob.Friend = alice // Circular reference
|
||||
|
||||
// Stringify Alice
|
||||
s, _ := flatted.Stringify(alice)
|
||||
fmt.Println(s)
|
||||
// Output: [{"name":"Alice","friend":"1","group":"2"},{"name":"Bob","friend":"0","group":"2"},{"name":"Developers"}]
|
||||
|
||||
// Flattening in action:
|
||||
// Index "0" is Alice, Index "1" is Bob, Index "2" is the shared Group.
|
||||
|
||||
// Parse back into a generic map structure
|
||||
res, _ := flatted.Parse(s)
|
||||
aliceMap := res.(map[string]any)
|
||||
fmt.Println(aliceMap["name"]) // Alice
|
||||
}
|
||||
```
|
||||
|
||||
## CLI
|
||||
|
||||
Build the binary using the provided Makefile:
|
||||
|
||||
```bash
|
||||
make build
|
||||
```
|
||||
|
||||
Then use it to parse flatted JSON from stdin:
|
||||
|
||||
```bash
|
||||
echo '[{"a":"1"},"b"]' | ./flatted
|
||||
```
|
||||
277
node_modules/flatted/golang/pkg/flatted/flatted.go
generated
vendored
277
node_modules/flatted/golang/pkg/flatted/flatted.go
generated
vendored
@@ -1,277 +0,0 @@
|
||||
package flatted
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// flattedIndex is a internal type used to distinguish between
|
||||
// actual strings and flatted indices during the reconstruction phase.
|
||||
type flattedIndex string
|
||||
|
||||
// Stringify converts a Go value into a specialized flatted JSON string.
|
||||
func Stringify(value any, replacer any, space any) (string, error) {
|
||||
knownKeys := []any{}
|
||||
knownValues := []string{}
|
||||
input := []any{}
|
||||
|
||||
index := func(v any) string {
|
||||
input = append(input, v)
|
||||
idx := strconv.Itoa(len(input) - 1)
|
||||
knownKeys = append(knownKeys, v)
|
||||
knownValues = append(knownValues, idx)
|
||||
return idx
|
||||
}
|
||||
|
||||
relate := func(v any) any {
|
||||
if v == nil {
|
||||
return nil
|
||||
}
|
||||
rv := reflect.ValueOf(v)
|
||||
kind := rv.Kind()
|
||||
if kind == reflect.String || kind == reflect.Slice || kind == reflect.Map || kind == reflect.Ptr {
|
||||
for i, k := range knownKeys {
|
||||
if kind == reflect.String {
|
||||
if k == v {
|
||||
return knownValues[i]
|
||||
}
|
||||
} else {
|
||||
rk := reflect.ValueOf(k)
|
||||
if rk.Kind() == kind && rk.Pointer() == rv.Pointer() {
|
||||
return knownValues[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
return index(v)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
transform := func(v any) any {
|
||||
rv := reflect.ValueOf(v)
|
||||
if !rv.IsValid() {
|
||||
return nil
|
||||
}
|
||||
if _, ok := v.(json.Marshaler); ok {
|
||||
return v
|
||||
}
|
||||
// Dereference pointers to process the underlying Slice, Map, or Array
|
||||
for rv.Kind() == reflect.Ptr && !rv.IsNil() {
|
||||
rv = rv.Elem()
|
||||
}
|
||||
switch rv.Kind() {
|
||||
case reflect.Slice, reflect.Array:
|
||||
res := make([]any, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
res[i] = relate(rv.Index(i).Interface())
|
||||
}
|
||||
return res
|
||||
case reflect.Map:
|
||||
res := make(map[string]any)
|
||||
keys := rv.MapKeys()
|
||||
sort.Slice(keys, func(i, j int) bool {
|
||||
return keys[i].String() < keys[j].String()
|
||||
})
|
||||
|
||||
whitelist, isWhitelist := replacer.([]string)
|
||||
for _, key := range keys {
|
||||
kStr := key.String()
|
||||
if isWhitelist {
|
||||
found := false
|
||||
for _, w := range whitelist {
|
||||
if w == kStr {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
continue
|
||||
}
|
||||
}
|
||||
res[kStr] = relate(rv.MapIndex(key).Interface())
|
||||
}
|
||||
return res
|
||||
case reflect.Struct:
|
||||
res := make(map[string]any)
|
||||
t := rv.Type()
|
||||
for i := 0; i < rv.NumField(); i++ {
|
||||
field := t.Field(i)
|
||||
if field.PkgPath != "" {
|
||||
continue
|
||||
}
|
||||
name := field.Name
|
||||
if tag := field.Tag.Get("json"); tag != "" {
|
||||
name = strings.Split(tag, ",")[0]
|
||||
}
|
||||
res[name] = relate(rv.Field(i).Interface())
|
||||
}
|
||||
return res
|
||||
default:
|
||||
return v
|
||||
}
|
||||
}
|
||||
|
||||
index(value)
|
||||
output := []any{}
|
||||
for i := 0; i < len(input); i++ {
|
||||
output = append(output, transform(input[i]))
|
||||
}
|
||||
|
||||
var b []byte
|
||||
var err error
|
||||
indent := ""
|
||||
if s, ok := space.(string); ok {
|
||||
indent = s
|
||||
} else if i, ok := space.(int); ok {
|
||||
indent = strings.Repeat(" ", i)
|
||||
}
|
||||
|
||||
if indent != "" {
|
||||
b, err = json.MarshalIndent(output, "", indent)
|
||||
} else {
|
||||
b, err = json.Marshal(output)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(b), nil
|
||||
}
|
||||
|
||||
// Parse converts a specialized flatted string into a Go value.
|
||||
func Parse(text string, reviver func(key string, value any) any) (any, error) {
|
||||
var jsonInput []any
|
||||
if err := json.Unmarshal([]byte(text), &jsonInput); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var wrap func(any) any
|
||||
wrap = func(v any) any {
|
||||
if s, ok := v.(string); ok {
|
||||
return flattedIndex(s)
|
||||
}
|
||||
if arr, ok := v.([]any); ok {
|
||||
for i, item := range arr {
|
||||
arr[i] = wrap(item)
|
||||
}
|
||||
return arr
|
||||
}
|
||||
if m, ok := v.(map[string]any); ok {
|
||||
for k, item := range m {
|
||||
m[k] = wrap(item)
|
||||
}
|
||||
return m
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
wrapped := make([]any, len(jsonInput))
|
||||
for i, v := range jsonInput {
|
||||
wrapped[i] = wrap(v)
|
||||
}
|
||||
|
||||
input := make([]any, len(wrapped))
|
||||
for i, v := range wrapped {
|
||||
if fi, ok := v.(flattedIndex); ok {
|
||||
input[i] = string(fi)
|
||||
} else {
|
||||
input[i] = v
|
||||
}
|
||||
}
|
||||
|
||||
if len(input) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
value := input[0]
|
||||
rv := reflect.ValueOf(value)
|
||||
if rv.IsValid() && (rv.Kind() == reflect.Slice || rv.Kind() == reflect.Map) {
|
||||
set := make(map[uintptr]bool)
|
||||
set[rv.Pointer()] = true
|
||||
res := loop(value, input, set)
|
||||
if reviver != nil {
|
||||
return revive("", res, reviver), nil
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
if reviver != nil {
|
||||
return reviver("", value), nil
|
||||
}
|
||||
return value, nil
|
||||
}
|
||||
|
||||
func revive(key string, value any, reviver func(k string, v any) any) any {
|
||||
if arr, ok := value.([]any); ok {
|
||||
for i, v := range arr {
|
||||
arr[i] = revive(strconv.Itoa(i), v, reviver)
|
||||
}
|
||||
} else if m, ok := value.(map[string]any); ok {
|
||||
keys := make([]string, 0, len(m))
|
||||
for k := range m {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
for _, k := range keys {
|
||||
m[k] = revive(k, m[k], reviver)
|
||||
}
|
||||
}
|
||||
return reviver(key, value)
|
||||
}
|
||||
|
||||
func loop(value any, input []any, set map[uintptr]bool) any {
|
||||
if arr, ok := value.([]any); ok {
|
||||
for i, v := range arr {
|
||||
if fi, ok := v.(flattedIndex); ok {
|
||||
idx, _ := strconv.Atoi(string(fi))
|
||||
arr[i] = ref(input[idx], input, set)
|
||||
}
|
||||
}
|
||||
return arr
|
||||
}
|
||||
if m, ok := value.(map[string]any); ok {
|
||||
for k, v := range m {
|
||||
if fi, ok := v.(flattedIndex); ok {
|
||||
idx, _ := strconv.Atoi(string(fi))
|
||||
m[k] = ref(input[idx], input, set)
|
||||
}
|
||||
}
|
||||
return m
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func ref(value any, input []any, set map[uintptr]bool) any {
|
||||
rv := reflect.ValueOf(value)
|
||||
if rv.IsValid() && (rv.Kind() == reflect.Slice || rv.Kind() == reflect.Map) {
|
||||
ptr := rv.Pointer()
|
||||
if !set[ptr] {
|
||||
set[ptr] = true
|
||||
return loop(value, input, set)
|
||||
}
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
// ToJSON converts a generic value into a JSON serializable object without losing recursion.
|
||||
func ToJSON(value any) (any, error) {
|
||||
s, err := Stringify(value, nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var res any
|
||||
err = json.Unmarshal([]byte(s), &res)
|
||||
return res, err
|
||||
}
|
||||
|
||||
// FromJSON converts a previously serialized object with recursion into a recursive one.
|
||||
func FromJSON(value any) (any, error) {
|
||||
b, err := json.Marshal(value)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return Parse(string(b), nil)
|
||||
}
|
||||
65
node_modules/flatted/index.js
generated
vendored
65
node_modules/flatted/index.js
generated
vendored
@@ -32,26 +32,30 @@ self.Flatted = (function (exports) {
|
||||
var Primitives = function Primitives(_, value) {
|
||||
return _typeof(value) === primitive ? new Primitive(value) : value;
|
||||
};
|
||||
var resolver = function resolver(input, lazy, parsed, $) {
|
||||
return function (output) {
|
||||
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({
|
||||
o: output,
|
||||
k: k,
|
||||
r: tmp
|
||||
});
|
||||
} else output[k] = $.call(output, k, tmp);
|
||||
} else if (output[k] !== ignore) output[k] = $.call(output, k, value);
|
||||
}
|
||||
return output;
|
||||
};
|
||||
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);
|
||||
@@ -67,25 +71,12 @@ self.Flatted = (function (exports) {
|
||||
*/
|
||||
var parse = function parse(text, reviver) {
|
||||
var input = $parse(text, Primitives).map(primitives);
|
||||
var $ = reviver || noop;
|
||||
var value = input[0];
|
||||
if (_typeof(value) === object && value) {
|
||||
var lazy = [];
|
||||
var revive = resolver(input, lazy, new Set(), $);
|
||||
value = revive(value);
|
||||
var i = 0;
|
||||
while (i < lazy.length) {
|
||||
// it could be a lazy.shift() but that's costly
|
||||
var _lazy$i = lazy[i++],
|
||||
o = _lazy$i.o,
|
||||
k = _lazy$i.k,
|
||||
r = _lazy$i.r;
|
||||
o[k] = $.call(o, k, revive(r));
|
||||
}
|
||||
}
|
||||
var $ = reviver || noop;
|
||||
var tmp = _typeof(value) === object && value ? _revive(input, new Set(), value, $) : value;
|
||||
return $.call({
|
||||
'': value
|
||||
}, '', value);
|
||||
'': tmp
|
||||
}, '', tmp);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
2
node_modules/flatted/min.js
generated
vendored
2
node_modules/flatted/min.js
generated
vendored
@@ -1 +1 @@
|
||||
self.Flatted=function(n){"use strict";function t(n){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},t(n)}var r=JSON.parse,e=JSON.stringify,o=Object.keys,u=String,f="string",i={},c="object",a=function(n,t){return t},l=function(n){return n instanceof u?u(n):n},s=function(n,r){return t(r)===f?new u(r):r},y=function(n,t,r){var e=u(t.push(r)-1);return n.set(r,e),e},p=function(n,e){var f=r(n,s).map(l),y=e||a,p=f[0];if(t(p)===c&&p){var v=[],S=function(n,r,e,f){return function(a){for(var l=o(a),s=l.length,y=0;y<s;y++){var p=l[y],v=a[p];if(v instanceof u){var S=n[v];t(S)!==c||e.has(S)?a[p]=f.call(a,p,S):(e.add(S),a[p]=i,r.push({o:a,k:p,r:S}))}else a[p]!==i&&(a[p]=f.call(a,p,v))}return a}}(f,v,new Set,y);p=S(p);for(var b=0;b<v.length;){var m=v[b++],g=m.o,h=m.k,O=m.r;g[h]=y.call(g,h,S(O))}}return y.call({"":p},"",p)},v=function(n,r,o){for(var u=r&&t(r)===c?function(n,t){return""===n||-1<r.indexOf(n)?t:void 0}:r||a,i=new Map,l=[],s=[],p=+y(i,l,u.call({"":n},"",n)),v=!p;p<l.length;)v=!0,s[p]=e(l[p++],S,o);return"["+s.join(",")+"]";function S(n,r){if(v)return v=!v,r;var e=u.call(this,n,r);switch(t(e)){case c:if(null===e)return e;case f:return i.get(e)||y(i,l,e)}return e}};return n.fromJSON=function(n){return p(e(n))},n.parse=p,n.stringify=v,n.toJSON=function(n){return r(v(n))},n}({});
|
||||
self.Flatted=function(n){"use strict";function t(n){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},t(n)}var r=JSON.parse,e=JSON.stringify,o=Object.keys,u=String,f="string",i={},c="object",a=function(n,t){return t},l=function(n){return n instanceof u?u(n):n},s=function(n,r){return t(r)===f?new u(r):r},y=function(n,r,e,f){for(var a=[],l=o(e),s=l.length,p=0;p<s;p++){var v=l[p],S=e[v];if(S instanceof u){var b=n[S];t(b)!==c||r.has(b)?e[v]=f.call(e,v,b):(r.add(b),e[v]=i,a.push({k:v,a:[n,r,b,f]}))}else e[v]!==i&&(e[v]=f.call(e,v,S))}for(var m=a.length,g=0;g<m;g++){var h=a[g],O=h.k,d=h.a;e[O]=f.call(e,O,y.apply(null,d))}return e},p=function(n,t,r){var e=u(t.push(r)-1);return n.set(r,e),e},v=function(n,e){var o=r(n,s).map(l),u=o[0],f=e||a,i=t(u)===c&&u?y(o,new Set,u,f):u;return f.call({"":i},"",i)},S=function(n,r,o){for(var u=r&&t(r)===c?function(n,t){return""===n||-1<r.indexOf(n)?t:void 0}:r||a,i=new Map,l=[],s=[],y=+p(i,l,u.call({"":n},"",n)),v=!y;y<l.length;)v=!0,s[y]=e(l[y++],S,o);return"["+s.join(",")+"]";function S(n,r){if(v)return v=!v,r;var e=u.call(this,n,r);switch(t(e)){case c:if(null===e)return e;case f:return i.get(e)||p(i,l,e)}return e}};return n.fromJSON=function(n){return v(e(n))},n.parse=v,n.stringify=S,n.toJSON=function(n){return r(S(n))},n}({});
|
||||
19
node_modules/flatted/package.json
generated
vendored
19
node_modules/flatted/package.json
generated
vendored
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "flatted",
|
||||
"version": "3.4.1",
|
||||
"version": "3.3.3",
|
||||
"description": "A super light and fast circular JSON parser.",
|
||||
"unpkg": "min.js",
|
||||
"main": "./cjs/index.js",
|
||||
@@ -33,7 +33,6 @@
|
||||
"min.js",
|
||||
"php/flatted.php",
|
||||
"python/flatted.py",
|
||||
"golang/pkg/flatted/flatted.go",
|
||||
"types/"
|
||||
],
|
||||
"keywords": [
|
||||
@@ -50,19 +49,19 @@
|
||||
},
|
||||
"homepage": "https://github.com/WebReflection/flatted#readme",
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.29.0",
|
||||
"@babel/preset-env": "^7.29.0",
|
||||
"@rollup/plugin-babel": "^7.0.0",
|
||||
"@rollup/plugin-terser": "^1.0.0",
|
||||
"@babel/core": "^7.26.9",
|
||||
"@babel/preset-env": "^7.26.9",
|
||||
"@rollup/plugin-babel": "^6.0.4",
|
||||
"@rollup/plugin-terser": "^0.4.4",
|
||||
"@ungap/structured-clone": "^1.3.0",
|
||||
"ascjs": "^6.0.3",
|
||||
"c8": "^11.0.0",
|
||||
"c8": "^10.1.3",
|
||||
"circular-json": "^0.5.9",
|
||||
"circular-json-es6": "^2.0.2",
|
||||
"jsan": "^3.1.14",
|
||||
"rollup": "^4.59.0",
|
||||
"terser": "^5.46.0",
|
||||
"typescript": "^5.9.3"
|
||||
"rollup": "^4.34.8",
|
||||
"terser": "^5.39.0",
|
||||
"typescript": "^5.7.3"
|
||||
},
|
||||
"module": "./esm/index.js",
|
||||
"type": "module",
|
||||
|
||||
59
node_modules/flatted/python/flatted.py
generated
vendored
59
node_modules/flatted/python/flatted.py
generated
vendored
@@ -25,13 +25,20 @@ class _String:
|
||||
def __init__(self, value):
|
||||
self.value = value
|
||||
|
||||
|
||||
def _array_keys(value):
|
||||
for i in range(len(value)):
|
||||
yield i
|
||||
keys = []
|
||||
i = 0
|
||||
for _ in value:
|
||||
keys.append(i)
|
||||
i += 1
|
||||
return keys
|
||||
|
||||
def _object_keys(value):
|
||||
keys = []
|
||||
for key in value:
|
||||
yield key
|
||||
keys.append(key)
|
||||
return keys
|
||||
|
||||
def _is_array(value):
|
||||
return isinstance(value, (list, tuple))
|
||||
@@ -49,6 +56,24 @@ def _index(known, input, value):
|
||||
known.value.append(index)
|
||||
return index
|
||||
|
||||
def _loop(keys, input, known, output):
|
||||
for key in keys:
|
||||
value = output[key]
|
||||
if isinstance(value, _String):
|
||||
_ref(key, input[int(value.value)], input, known, output)
|
||||
|
||||
return output
|
||||
|
||||
def _ref(key, value, input, known, output):
|
||||
if _is_array(value) and value not in known:
|
||||
known.append(value)
|
||||
value = _loop(_array_keys(value), input, known, value)
|
||||
elif _is_object(value) and value not in known:
|
||||
known.append(value)
|
||||
value = _loop(_object_keys(value), input, known, value)
|
||||
|
||||
output[key] = value
|
||||
|
||||
def _relate(known, input, value):
|
||||
if _is_string(value) or _is_array(value) or _is_object(value):
|
||||
try:
|
||||
@@ -58,22 +83,6 @@ def _relate(known, input, value):
|
||||
|
||||
return value
|
||||
|
||||
def _resolver(input, lazy, parsed):
|
||||
def resolver(output):
|
||||
keys = _array_keys(output) if _is_array(output) else _object_keys(output) if _is_object(output) else []
|
||||
for key in keys:
|
||||
value = output[key]
|
||||
if isinstance(value, _String):
|
||||
tmp = input[int(value.value)]
|
||||
output[key] = tmp
|
||||
if (_is_array(tmp) or _is_object(tmp)) and tmp not in parsed:
|
||||
parsed.append(tmp)
|
||||
lazy.append([output, key])
|
||||
|
||||
return output
|
||||
|
||||
return resolver
|
||||
|
||||
def _transform(known, input, value):
|
||||
if _is_array(value):
|
||||
output = []
|
||||
@@ -119,16 +128,12 @@ def parse(value, *args, **kwargs):
|
||||
input.append(value)
|
||||
|
||||
value = input[0]
|
||||
lazy = []
|
||||
revive = _resolver(input, lazy, [value])
|
||||
|
||||
value = revive(value)
|
||||
if _is_array(value):
|
||||
return _loop(_array_keys(value), input, [value], value)
|
||||
|
||||
i = 0
|
||||
while i < len(lazy):
|
||||
o, k = lazy[i]
|
||||
i += 1
|
||||
o[k] = revive(o[k])
|
||||
if _is_object(value):
|
||||
return _loop(_object_keys(value), input, [value], value)
|
||||
|
||||
return value
|
||||
|
||||
|
||||
Reference in New Issue
Block a user