jfather 0.4.0 → 0.5.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.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024-2025 Sébastien Règne
3
+ Copyright (c) 2024-2026 Sébastien Règne
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  <!-- Utiliser du HTML (avec l'attribut "align" obsolète) pour faire flotter
4
4
  l'image à droite. -->
5
- <!-- markdownlint-disable-next-line no-inline-html-->
6
- <img src="asset/logo.svg" align="right" alt="">
5
+ <!-- markdownlint-disable-next-line no-inline-html -->
6
+ <img src="asset/logo.svg" align="right" width="100" height="100" alt="">
7
7
 
8
8
  [![npm][img-npm]][link-npm] [![build][img-build]][link-build]
9
9
  [![coverage][img-coverage]][link-coverage] [![semver][img-semver]][link-semver]
@@ -92,8 +92,8 @@ console.log(allIn);
92
92
  JFather is published on [npm][link-npm] (its CDN:
93
93
  [esm.sh](https://esm.sh/jfather),
94
94
  [jsDelivr](https://www.jsdelivr.com/package/npm/jfather),
95
- [UNPKG](https://unpkg.com/browse/jfather/)),
96
- [JSR](https://jsr.io/@regseb/jfather) and [Deno](https://deno.land/x/jfather).
95
+ [UNPKG](https://unpkg.com/browse/jfather/)) and
96
+ [JSR](https://jsr.io/@regseb/jfather).
97
97
 
98
98
  ```javascript
99
99
  // Node.js and Bun (after `npm install jfather`):
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jfather",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "JSON with merge, extend and override.",
5
5
  "keywords": [
6
6
  "jfather",
@@ -35,48 +35,59 @@
35
35
  },
36
36
  "main": "./src/index.js",
37
37
  "types": "./types/index.d.ts",
38
- "repository": "regseb/jfather",
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "git+https://github.com/regseb/jfather.git"
41
+ },
39
42
  "type": "module",
40
43
  "scripts": {
44
+ "prepare": "tsc --project .tsconfig_types.json",
41
45
  "lint": "metalint",
42
46
  "lint:fix": "metalint --fix",
43
47
  "lint:types": "tsc --project .tsconfig_lint.json",
44
48
  "test": "npm run test:coverage",
45
- "test:unit": "node --test",
49
+ "test:unit": "npm run test:unit:node",
50
+ "test:unit:node": "node --test --import ./test/polyfills/node.js 'test/unit/**/*.test.js'",
51
+ "test:unit:bun": "bun test --preload ./test/polyfills/bun.js test/unit/",
46
52
  "test:coverage": "stryker run",
47
53
  "jsdocs": "typedoc --tsconfig .tsconfig_jsdocs.json",
48
- "prepare": "tsc --project .tsconfig_types.json",
49
54
  "clean": "node .script/clean.js"
50
55
  },
51
56
  "devDependencies": {
52
- "@prantlf/jsonlint": "16.0.0",
53
- "@prettier/plugin-xml": "3.4.1",
54
- "@stryker-mutator/core": "8.7.1",
55
- "@stryker-mutator/tap-runner": "8.7.1",
56
- "@types/eslint-plugin-mocha": "10.4.0",
57
- "@types/node": "22.10.5",
58
- "eslint": "9.17.0",
59
- "eslint-plugin-array-func": "5.0.2",
57
+ "@biomejs/js-api": "4.0.0",
58
+ "@biomejs/wasm-nodejs": "2.3.11",
59
+ "@prantlf/jsonlint": "17.0.0",
60
+ "@prettier/plugin-xml": "3.4.2",
61
+ "@secretlint/secretlint-rule-github": "11.2.5",
62
+ "@secretlint/secretlint-rule-npm": "11.2.5",
63
+ "@stryker-mutator/core": "9.4.0",
64
+ "@stryker-mutator/tap-runner": "9.4.0",
65
+ "@types/bun": "1.3.5",
66
+ "@types/node": "25.0.3",
67
+ "eslint": "9.39.2",
68
+ "eslint-plugin-array-func": "5.1.0",
60
69
  "eslint-plugin-eslint-comments": "3.2.0",
61
- "eslint-plugin-import": "2.31.0",
62
- "eslint-plugin-jsdoc": "50.6.1",
63
- "eslint-plugin-mocha": "10.5.0",
64
- "eslint-plugin-n": "17.15.1",
65
- "eslint-plugin-no-unsanitized": "4.1.2",
70
+ "eslint-plugin-import": "2.32.0",
71
+ "eslint-plugin-jsdoc": "61.5.0",
72
+ "eslint-plugin-mocha": "11.2.0",
73
+ "eslint-plugin-n": "17.23.1",
74
+ "eslint-plugin-no-unsanitized": "4.1.4",
66
75
  "eslint-plugin-promise": "7.2.1",
67
- "eslint-plugin-regexp": "2.7.0",
68
- "eslint-plugin-unicorn": "56.0.1",
69
- "globals": "15.14.0",
70
- "markdownlint": "0.37.3",
71
- "metalint": "0.19.0",
72
- "npm-package-json-lint": "8.0.0",
73
- "prettier": "3.4.2",
74
- "publint": "0.2.12",
75
- "typedoc": "0.27.6",
76
- "typescript": "5.7.2",
76
+ "eslint-plugin-regexp": "2.10.0",
77
+ "eslint-plugin-unicorn": "62.0.0",
78
+ "globals": "17.0.0",
79
+ "jsr": "0.13.5",
80
+ "markdownlint": "0.40.0",
81
+ "metalint": "0.21.2",
82
+ "npm-package-json-lint": "9.1.0",
83
+ "prettier": "3.7.4",
84
+ "publint": "0.3.16",
85
+ "secretlint": "11.2.5",
86
+ "typedoc": "0.28.15",
87
+ "typescript": "5.9.3",
77
88
  "yaml-lint": "1.7.0"
78
89
  },
79
90
  "engines": {
80
- "node": ">=20.18"
91
+ "node": ">=20.18.0"
81
92
  }
82
93
  }
package/src/index.js CHANGED
@@ -6,4 +6,8 @@
6
6
 
7
7
  import { extend, load, merge, parse } from "./jfather.js";
8
8
 
9
+ /**
10
+ * @typedef {import('./jfather.js').Options} Options
11
+ */
12
+
9
13
  export default { extend, load, merge, parse };
package/src/jfather.js CHANGED
@@ -21,7 +21,7 @@
21
21
  * @param {Function} fn La fonction appliquée sur tous les objets.
22
22
  * @returns {any} Le retour de la fonction.
23
23
  */
24
- export const walk = function (obj, fn) {
24
+ export const walk = (obj, fn) => {
25
25
  if (Object === obj?.constructor) {
26
26
  return fn(
27
27
  Object.fromEntries(
@@ -45,7 +45,7 @@ export const walk = function (obj, fn) {
45
45
  * @param {Function} fn La fonction asynchrone appliquée sur tous les objets.
46
46
  * @returns {Promise<any>} Une promesse contenant le retour de la fonction.
47
47
  */
48
- export const walkAsync = async function (obj, fn) {
48
+ export const walkAsync = async (obj, fn) => {
49
49
  if (Object === obj?.constructor) {
50
50
  return await fn(
51
51
  Object.fromEntries(
@@ -72,7 +72,7 @@ export const walkAsync = async function (obj, fn) {
72
72
  * @param {any} obj Une variable quelconque.
73
73
  * @returns {any} Le clone de la variable d'entrée.
74
74
  */
75
- export const clone = function (obj) {
75
+ export const clone = (obj) => {
76
76
  return walk(obj, (/** @type {any} */ v) => v);
77
77
  };
78
78
 
@@ -84,7 +84,7 @@ export const clone = function (obj) {
84
84
  * @returns {any} L'élément extrait.
85
85
  * @throws {TypeError} Si le chemin est invalide.
86
86
  */
87
- export const query = function (obj, chain) {
87
+ export const query = (obj, chain) => {
88
88
  if ("" === chain) {
89
89
  return obj;
90
90
  }
@@ -93,7 +93,7 @@ export const query = function (obj, chain) {
93
93
  const sub = {
94
94
  obj,
95
95
  // Préfixer le chemin avec un point si nécessaire.
96
- chain: /^[.\[]/v.test(chain) ? chain : "." + chain,
96
+ chain: /^[.\[]/v.test(chain) ? chain : `.${chain}`,
97
97
  };
98
98
  while (0 !== sub.chain.length) {
99
99
  const result = re.exec(sub.chain);
@@ -117,7 +117,7 @@ export const query = function (obj, chain) {
117
117
  * @param {any} child L'objet enfant.
118
118
  * @returns {any} La fusion des deux objets.
119
119
  */
120
- export const merge = function (parent, child) {
120
+ export const merge = (parent, child) => {
121
121
  if (
122
122
  child === parent ||
123
123
  Object !== parent?.constructor ||
@@ -152,7 +152,7 @@ export const merge = function (parent, child) {
152
152
  // surcharges d'éléments.
153
153
  if (Array.isArray(overridden[key])) {
154
154
  const overelemRegex = new RegExp(
155
- `^\\$${key}\\[(?<index>\\d*)\\]$`,
155
+ String.raw`^\$${key}\[(?<index>\d*)\]$`,
156
156
  "v",
157
157
  );
158
158
  const overelems = Object.entries(child)
@@ -181,7 +181,7 @@ export const merge = function (parent, child) {
181
181
  * @returns {Promise<Record<string, any>>} Une promesse contenant l'objet
182
182
  * étendu.
183
183
  */
184
- export const inherit = async function (obj, options) {
184
+ export const inherit = async (obj, options) => {
185
185
  if (undefined === obj.$extends) {
186
186
  return obj;
187
187
  }
@@ -197,7 +197,7 @@ export const inherit = async function (obj, options) {
197
197
  * @param {Options} [options] Les options.
198
198
  * @returns {Promise<any>} Une promesse contenant l'objet étendu.
199
199
  */
200
- export const extend = function (obj, options) {
200
+ export const extend = (obj, options) => {
201
201
  return walkAsync(obj, (/** @type {any} */ v) => inherit(v, options));
202
202
  };
203
203
 
@@ -208,7 +208,7 @@ export const extend = function (obj, options) {
208
208
  * @param {Options} [options] Les options.
209
209
  * @returns {Promise<any>} Une promesse contenant l'objet.
210
210
  */
211
- export const load = async function (url, options) {
211
+ export const load = async (url, options) => {
212
212
  let json;
213
213
  if (undefined === options?.request) {
214
214
  const response = await fetch(url);
@@ -227,6 +227,6 @@ export const load = async function (url, options) {
227
227
  * @param {Options} [options] Les options.
228
228
  * @returns {Promise<any>} L'objet.
229
229
  */
230
- export const parse = function (text, options) {
230
+ export const parse = (text, options) => {
231
231
  return extend(JSON.parse(text), options);
232
232
  };
package/types/index.d.ts CHANGED
@@ -5,6 +5,7 @@ declare namespace _default {
5
5
  export { parse };
6
6
  }
7
7
  export default _default;
8
+ export type Options = import("./jfather.js").Options;
8
9
  import { extend } from "./jfather.js";
9
10
  import { load } from "./jfather.js";
10
11
  import { merge } from "./jfather.js";