@x0k/json-schema-merge 1.0.0

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.
Files changed (39) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +181 -0
  3. package/dist/index.d.ts +1 -0
  4. package/dist/index.js +1 -0
  5. package/dist/lib/array.d.ts +19 -0
  6. package/dist/lib/array.js +133 -0
  7. package/dist/lib/function.d.ts +1 -0
  8. package/dist/lib/function.js +3 -0
  9. package/dist/lib/json-schema/compare/compare.d.ts +9 -0
  10. package/dist/lib/json-schema/compare/compare.js +205 -0
  11. package/dist/lib/json-schema/compare/index.d.ts +1 -0
  12. package/dist/lib/json-schema/compare/index.js +1 -0
  13. package/dist/lib/json-schema/index.d.ts +5 -0
  14. package/dist/lib/json-schema/index.js +5 -0
  15. package/dist/lib/json-schema/json-schema.d.ts +37 -0
  16. package/dist/lib/json-schema/json-schema.js +56 -0
  17. package/dist/lib/json-schema/merge/all-of-merge.d.ts +3 -0
  18. package/dist/lib/json-schema/merge/all-of-merge.js +29 -0
  19. package/dist/lib/json-schema/merge/index.d.ts +3 -0
  20. package/dist/lib/json-schema/merge/index.js +3 -0
  21. package/dist/lib/json-schema/merge/merge.d.ts +91 -0
  22. package/dist/lib/json-schema/merge/merge.js +554 -0
  23. package/dist/lib/json-schema/merge/patterns.d.ts +2 -0
  24. package/dist/lib/json-schema/merge/patterns.js +6 -0
  25. package/dist/lib/json-schema/transform.d.ts +4 -0
  26. package/dist/lib/json-schema/transform.js +72 -0
  27. package/dist/lib/json-schema/traverse.d.ts +26 -0
  28. package/dist/lib/json-schema/traverse.js +1 -0
  29. package/dist/lib/math.d.ts +2 -0
  30. package/dist/lib/math.js +2 -0
  31. package/dist/lib/memoize.d.ts +7 -0
  32. package/dist/lib/memoize.js +11 -0
  33. package/dist/lib/object.d.ts +2 -0
  34. package/dist/lib/object.js +12 -0
  35. package/dist/lib/ord.d.ts +9 -0
  36. package/dist/lib/ord.js +7 -0
  37. package/dist/lib/traverser.d.ts +4 -0
  38. package/dist/lib/traverser.js +1 -0
  39. package/package.json +59 -0
@@ -0,0 +1,11 @@
1
+ export function memoize(cache, func) {
2
+ return (arg) => {
3
+ if (cache.has(arg)) {
4
+ return cache.get(arg);
5
+ }
6
+ const ret = func(arg);
7
+ cache.set(arg, ret);
8
+ return ret;
9
+ };
10
+ }
11
+ export const weakMemoize = memoize;
@@ -0,0 +1,2 @@
1
+ export declare function isObject(value: unknown): value is object;
2
+ export declare function isRecordEmpty<R extends Record<string, any>>(rec: R | Record<string, never>): rec is Record<string, never>;
@@ -0,0 +1,12 @@
1
+ export function isObject(value) {
2
+ return value !== null && typeof value === "object";
3
+ }
4
+ const objProto = Object.prototype;
5
+ export function isRecordEmpty(rec) {
6
+ for (const key in rec) {
7
+ if (objProto.hasOwnProperty.call(rec, key)) {
8
+ return false;
9
+ }
10
+ }
11
+ return true;
12
+ }
@@ -0,0 +1,9 @@
1
+ export type Comparator<T> = (a: T, b: T) => number;
2
+ export interface ComparableTypes {
3
+ number: number;
4
+ string: string;
5
+ boolean: boolean;
6
+ bigint: bigint;
7
+ }
8
+ export type Comparable = ComparableTypes[keyof ComparableTypes];
9
+ export declare function ascComparator<T extends Comparable>(a: T, b: T): 0 | 1 | -1;
@@ -0,0 +1,7 @@
1
+ export function ascComparator(a, b) {
2
+ if (a < b)
3
+ return -1;
4
+ if (a > b)
5
+ return 1;
6
+ return 0;
7
+ }
@@ -0,0 +1,4 @@
1
+ export interface Visitor<Node, Context, R> {
2
+ onEnter?: (node: Node, ctx: Context) => Generator<R>;
3
+ onLeave?: (node: Node, ctx: Context) => Generator<R>;
4
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@x0k/json-schema-merge",
3
+ "version": "1.0.0",
4
+ "description": "A minimal JSON Schema merging library.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "homepage": "https://github.com/x0k/json-schema-merge#readme",
8
+ "bugs": {
9
+ "url": "https://github.com/x0k/json-schema-merge/issues"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/x0k/json-schema-merge.git"
14
+ },
15
+ "author": "Roman Krasilnikov",
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "main": "./dist/index.js",
20
+ "module": "./dist/index.js",
21
+ "types": "./dist/index.d.ts",
22
+ "exports": {
23
+ ".": "./dist/index.js",
24
+ "./package.json": "./package.json",
25
+ "./lib/*": "./dist/lib/*.js"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "devDependencies": {
31
+ "@changesets/changelog-github": "^0.5.1",
32
+ "@changesets/cli": "^2.29.7",
33
+ "@types/json-schema-compare": "^0.2.4",
34
+ "@types/json-schema-merge-allof": "^0.6.5",
35
+ "ajv": "^8.17.1",
36
+ "allof-merge": "^0.6.7",
37
+ "json-schema-compare": "^0.2.2",
38
+ "json-schema-merge-allof": "^0.8.1",
39
+ "prettier": "^3.6.2",
40
+ "publint": "^0.3.13",
41
+ "tsdown": "^0.15.6",
42
+ "typescript": "^5.9.3",
43
+ "vitest": "^3.2.4"
44
+ },
45
+ "dependencies": {
46
+ "@types/json-schema": "^7.0.15"
47
+ },
48
+ "scripts": {
49
+ "build": "tsc && publint",
50
+ "test": "vitest run --exclude '.direnv/**'",
51
+ "bench": "vitest bench --exclude '.direnv/**'",
52
+ "typecheck": "tsc --noEmit",
53
+ "format": "prettier --write .",
54
+ "lint": "prettier --check .",
55
+ "check": "npm run lint && npm run typecheck && npm run test",
56
+ "ci:build": "npm run check && npm run build",
57
+ "ci:version": "changeset version && pnpm install --no-frozen-lockfile"
58
+ }
59
+ }