fat-json 0.0.5 → 0.0.7

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 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.5",
3
+ "version": "0.0.7",
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": "./src/index.d.mts",
15
+ "types": "./index.d.mts",
16
16
  "author": {
17
17
  "name": "Jonathan Perry for Sequence Media Limited",
18
18
  "email": "sequencemedia@sequencemedia.net",
@@ -30,14 +30,14 @@
30
30
  "test": "mocha test --recursive"
31
31
  },
32
32
  "devDependencies": {
33
- "@sequencemedia/eslint-config-standard": "^0.2.83",
34
- "@sequencemedia/eslint-config-typescript": "^0.1.142",
33
+ "@sequencemedia/eslint-config-standard": "^0.2.84",
34
+ "@sequencemedia/eslint-config-typescript": "^0.1.143",
35
35
  "@types/chai": "^5.2.2",
36
36
  "@types/mocha": "^10.0.10",
37
- "@types/node": "^24.5.1",
37
+ "@types/node": "^24.5.2",
38
38
  "@types/sinon": "^17.0.4",
39
39
  "chai": "^6.0.1",
40
- "eslint": "^9.35.0",
40
+ "eslint": "^9.36.0",
41
41
  "globals": "^16.4.0",
42
42
  "husky": "^9.1.7",
43
43
  "mocha": "^11.7.2",
@@ -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"
@@ -1,4 +1,4 @@
1
- type ValueType = FatJsonTypes.ValueType
1
+ export type ValueType = FatJsonTypes.ValueType
2
2
 
3
3
  declare const BIG_INT: RegExp
4
4
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @typedef {FatJsonTypes.ValueType} ValueType
2
+ * @typedef {import('#types').ValueType} ValueType
3
3
  */
4
4
 
5
5
  export const BIG_INT = /^(\d+)n$/
package/src/index.d.mts CHANGED
@@ -1,9 +1,11 @@
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
- }
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
@@ -1,6 +1,7 @@
1
1
  /**
2
- * @typedef {FatJsonTypes.ValueType} ValueType
2
+ * @typedef {import('#types').ValueType} ValueType
3
3
  */
4
+
4
5
  import getPath from './replacer/index.mjs'
5
6
  import genPath from './reviver/index.mjs'
6
7
 
@@ -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
@@ -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 {unknown} value
13
- * @param {any} context
21
+ * @param {ValueType} value
22
+ * @param {ArrayLiteralType | ObjectLiteralType} context
14
23
  * @returns {string}
15
24
  */
16
25
  export default function getPath (key, value, context) {
@@ -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 default function genPath (key: PropertyKey, value: ValueType, context: ArrayLiteralType | ObjectLiteralType): IterableIterator<{ key: PropertyKey; value: ValueType; path: string; context: ArrayLiteralType | ObjectLiteralType }>
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>
@@ -1,8 +1,10 @@
1
1
  /**
2
- * @typedef {FatJsonTypes.ArrayLiteralType} ArrayLiteralType
3
- * @typedef {FatJsonTypes.ObjectLiteralType} ObjectLiteralType
4
- * @typedef {FatJsonTypes.ValueType} ValueType
5
- * @typedef {FatJsonTypes.WeakMapType} WeakMapType
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 {any[]} context
18
+ * @param {ArrayLiteralType} context
17
19
  * @param {string} contextPath
18
- * @returns {IterableIterator<{ key: PropertyKey; value: unknown; path: string; context: any }>}
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 {any} context
42
+ * @param {ObjectLiteralType} context
41
43
  * @param {string} contextPath
42
- * @returns {IterableIterator<{ key: PropertyKey; value: unknown; path: string; context: any }>}
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 {unknown} value
66
- * @param {any | any[]} context
67
- * @returns {IterableIterator<{ key: PropertyKey; value: unknown; path: string; context: any }>}
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
+ }