fat-json 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.mts +32 -0
- package/package.json +4 -3
- package/src/common/index.d.mts +1 -1
- package/src/common/index.mjs +1 -1
- package/src/index.d.mts +11 -9
- package/src/index.mjs +2 -1
- package/src/replacer/index.d.mts +3 -3
- package/src/replacer/index.mjs +11 -2
- package/src/reviver/index.d.mts +10 -4
- package/src/reviver/index.mjs +13 -11
- package/types/index.d.mts +9 -0
package/index.d.mts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
namespace FatJsonTypes {
|
|
3
|
+
export type ArrayLiteralType = unknown[] | never[]
|
|
4
|
+
export type ObjectLiteralType = Record<PropertyKey, unknown> | Record<PropertyKey, never>
|
|
5
|
+
export type ValueType = string | number | boolean | null | bigint | ArrayLiteralType | ObjectLiteralType | Buffer | undefined | object
|
|
6
|
+
|
|
7
|
+
export namespace PathTypes {
|
|
8
|
+
export interface ArrayPathDescriptor {
|
|
9
|
+
key: PropertyKey
|
|
10
|
+
value: ValueType
|
|
11
|
+
path: string
|
|
12
|
+
context: ArrayLiteralType
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ObjectPathDescriptor {
|
|
16
|
+
key: PropertyKey
|
|
17
|
+
value: ValueType
|
|
18
|
+
path: string
|
|
19
|
+
context: ObjectLiteralType
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface PathDescriptor {
|
|
23
|
+
key: PropertyKey
|
|
24
|
+
value: ValueType
|
|
25
|
+
path: string
|
|
26
|
+
context: ArrayLiteralType | ObjectLiteralType
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fat-json",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"JSON",
|
|
6
6
|
"stringify",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
],
|
|
13
13
|
"main": "./src/index.mjs",
|
|
14
14
|
"type": "module",
|
|
15
|
-
"types": "./
|
|
15
|
+
"types": "./index.d.mts",
|
|
16
16
|
"author": {
|
|
17
17
|
"name": "Jonathan Perry for Sequence Media Limited",
|
|
18
18
|
"email": "sequencemedia@sequencemedia.net",
|
|
@@ -47,7 +47,8 @@
|
|
|
47
47
|
"imports": {
|
|
48
48
|
"#common": "./src/common/index.mjs",
|
|
49
49
|
"#fat-json": "./src/index.mjs",
|
|
50
|
-
"#transformers": "./src/transformers/index.mjs"
|
|
50
|
+
"#transformers": "./src/transformers/index.mjs",
|
|
51
|
+
"#types": "./types/index.d.mts"
|
|
51
52
|
},
|
|
52
53
|
"exports": {
|
|
53
54
|
"./transformers": "./src/transformers/index.mjs"
|
package/src/common/index.d.mts
CHANGED
package/src/common/index.mjs
CHANGED
package/src/index.d.mts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export
|
|
1
|
+
export type ArrayLiteralType = FatJsonTypes.ArrayLiteralType
|
|
2
|
+
export type ObjectLiteralType = FatJsonTypes.ObjectLiteralType
|
|
3
|
+
export type ValueType = FatJsonTypes.ValueType
|
|
4
|
+
|
|
5
|
+
export function useReplacerWithType (replacer: (key: PropertyKey, value: ValueType, type?: string) => ValueType): (key: PropertyKey, value: ValueType) => ValueType
|
|
6
|
+
|
|
7
|
+
export function useReviverWithType (reviver: (key: PropertyKey, value: ValueType, type?: string) => ValueType): (key: PropertyKey, value: ValueType) => ValueType
|
|
8
|
+
|
|
9
|
+
export function useReplacerWithPath (replacer: (key: PropertyKey, value: ValueType, path?: string) => ValueType) : (key: PropertyKey, value: ValueType) => ValueType
|
|
10
|
+
|
|
11
|
+
export function useReviverWithPath (reviver: (key: PropertyKey, value: ValueType, path?: string) => ValueType): (key: PropertyKey, value: ValueType) => ValueType
|
package/src/index.mjs
CHANGED
package/src/replacer/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
type ArrayLiteralType = FatJsonTypes.ArrayLiteralType
|
|
2
|
-
type ObjectLiteralType = FatJsonTypes.ObjectLiteralType
|
|
3
|
-
type ValueType = FatJsonTypes.ValueType
|
|
1
|
+
export type ArrayLiteralType = FatJsonTypes.ArrayLiteralType
|
|
2
|
+
export type ObjectLiteralType = FatJsonTypes.ObjectLiteralType
|
|
3
|
+
export type ValueType = FatJsonTypes.ValueType
|
|
4
4
|
|
|
5
5
|
export default function getPath (key: PropertyKey, value: ValueType, context: ArrayLiteralType | ObjectLiteralType): string
|
package/src/replacer/index.mjs
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('#types').ArrayLiteralType} ArrayLiteralType
|
|
3
|
+
* @typedef {import('#types').ObjectLiteralType} ObjectLiteralType
|
|
4
|
+
* @typedef {import('#types').ValueType} ValueType
|
|
5
|
+
*/
|
|
6
|
+
|
|
1
7
|
import {
|
|
2
8
|
formatNumber,
|
|
3
9
|
formatString,
|
|
@@ -5,12 +11,15 @@ import {
|
|
|
5
11
|
isObject
|
|
6
12
|
} from '#common'
|
|
7
13
|
|
|
14
|
+
/**
|
|
15
|
+
* @type {WeakMap<WeakKey, ArrayLiteralType | ObjectLiteralType>}
|
|
16
|
+
*/
|
|
8
17
|
const MAP = new WeakMap()
|
|
9
18
|
|
|
10
19
|
/**
|
|
11
20
|
* @param {PropertyKey} key
|
|
12
|
-
* @param {
|
|
13
|
-
* @param {
|
|
21
|
+
* @param {ValueType} value
|
|
22
|
+
* @param {ArrayLiteralType | ObjectLiteralType} context
|
|
14
23
|
* @returns {string}
|
|
15
24
|
*/
|
|
16
25
|
export default function getPath (key, value, context) {
|
package/src/reviver/index.d.mts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
type ArrayLiteralType = FatJsonTypes.ArrayLiteralType
|
|
2
|
-
type ObjectLiteralType = FatJsonTypes.ObjectLiteralType
|
|
3
|
-
type ValueType = FatJsonTypes.ValueType
|
|
1
|
+
export type ArrayLiteralType = FatJsonTypes.ArrayLiteralType
|
|
2
|
+
export type ObjectLiteralType = FatJsonTypes.ObjectLiteralType
|
|
3
|
+
export type ValueType = FatJsonTypes.ValueType
|
|
4
4
|
|
|
5
|
-
export
|
|
5
|
+
export namespace PathTypes {
|
|
6
|
+
export type ArrayPathDescriptor = FatJsonTypes.PathTypes.ArrayPathDescriptor
|
|
7
|
+
export type ObjectPathDescriptor = FatJsonTypes.PathTypes.ObjectPathDescriptor
|
|
8
|
+
export type PathDescriptor = FatJsonTypes.PathTypes.PathDescriptor
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default function genPath (key: PropertyKey, value: ValueType, context: ArrayLiteralType | ObjectLiteralType): IterableIterator<PathTypes.PathDescriptor>
|
package/src/reviver/index.mjs
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @typedef {
|
|
3
|
-
* @typedef {
|
|
4
|
-
* @typedef {
|
|
5
|
-
* @typedef {
|
|
2
|
+
* @typedef {import('#types').ArrayLiteralType} ArrayLiteralType
|
|
3
|
+
* @typedef {import('#types').ObjectLiteralType} ObjectLiteralType
|
|
4
|
+
* @typedef {import('#types').ValueType} ValueType
|
|
5
|
+
* @typedef {import('#types').PathTypes.ArrayPathDescriptor} PathTypes.ArrayPathDescriptor
|
|
6
|
+
* @typedef {import('#types').PathTypes.ObjectPathDescriptor} PathTypes.ObjectPathDescriptor
|
|
7
|
+
* @typedef {import('#types').PathTypes.PathDescriptor} PathTypes.PathDescriptor
|
|
6
8
|
*/
|
|
7
9
|
|
|
8
10
|
import {
|
|
@@ -13,9 +15,9 @@ import {
|
|
|
13
15
|
} from '#common'
|
|
14
16
|
|
|
15
17
|
/**
|
|
16
|
-
* @param {
|
|
18
|
+
* @param {ArrayLiteralType} context
|
|
17
19
|
* @param {string} contextPath
|
|
18
|
-
* @returns {IterableIterator<
|
|
20
|
+
* @returns {IterableIterator<PathTypes.ArrayPathDescriptor>}
|
|
19
21
|
*/
|
|
20
22
|
function * genPathForArray (context, contextPath) {
|
|
21
23
|
for (const [key, value] of context.entries()) {
|
|
@@ -37,9 +39,9 @@ function * genPathForArray (context, contextPath) {
|
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
/**
|
|
40
|
-
* @param {
|
|
42
|
+
* @param {ObjectLiteralType} context
|
|
41
43
|
* @param {string} contextPath
|
|
42
|
-
* @returns {IterableIterator<
|
|
44
|
+
* @returns {IterableIterator<PathTypes.ObjectPathDescriptor>}
|
|
43
45
|
*/
|
|
44
46
|
function * genPathForObject (context, contextPath) {
|
|
45
47
|
for (const [key, value] of Object.entries(context)) {
|
|
@@ -62,9 +64,9 @@ function * genPathForObject (context, contextPath) {
|
|
|
62
64
|
|
|
63
65
|
/**
|
|
64
66
|
* @param {PropertyKey} key
|
|
65
|
-
* @param {
|
|
66
|
-
* @param {
|
|
67
|
-
* @returns {IterableIterator<
|
|
67
|
+
* @param {ValueType} value
|
|
68
|
+
* @param {ArrayLiteralType | ObjectLiteralType} context
|
|
69
|
+
* @returns {IterableIterator<PathTypes.PathDescriptor>}
|
|
68
70
|
*/
|
|
69
71
|
export default function * genPath (key, value, context) {
|
|
70
72
|
const valuePath = key
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type ArrayLiteralType = FatJsonTypes.ArrayLiteralType
|
|
2
|
+
export type ObjectLiteralType = FatJsonTypes.ObjectLiteralType
|
|
3
|
+
export type ValueType = FatJsonTypes.ValueType
|
|
4
|
+
|
|
5
|
+
export namespace PathTypes {
|
|
6
|
+
export type ArrayPathDescriptor = FatJsonTypes.PathTypes.ArrayPathDescriptor
|
|
7
|
+
export type ObjectPathDescriptor = FatJsonTypes.PathTypes.ObjectPathDescriptor
|
|
8
|
+
export type PathDescriptor = FatJsonTypes.PathTypes.PathDescriptor
|
|
9
|
+
}
|