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 +1 -1
- package/README.md +4 -4
- package/package.json +39 -28
- package/src/index.js +4 -0
- package/src/jfather.js +11 -11
- package/types/index.d.ts +1 -0
package/LICENSE
CHANGED
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)
|
|
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.
|
|
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":
|
|
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": "
|
|
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
|
-
"@
|
|
53
|
-
"@
|
|
54
|
-
"@
|
|
55
|
-
"@
|
|
56
|
-
"@
|
|
57
|
-
"@
|
|
58
|
-
"
|
|
59
|
-
"
|
|
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.
|
|
62
|
-
"eslint-plugin-jsdoc": "
|
|
63
|
-
"eslint-plugin-mocha": "
|
|
64
|
-
"eslint-plugin-n": "17.
|
|
65
|
-
"eslint-plugin-no-unsanitized": "4.1.
|
|
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.
|
|
68
|
-
"eslint-plugin-unicorn": "
|
|
69
|
-
"globals": "
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
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
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 =
|
|
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
|
|
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 =
|
|
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 =
|
|
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 :
|
|
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 =
|
|
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
|
-
|
|
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
|
|
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 =
|
|
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
|
|
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 =
|
|
230
|
+
export const parse = (text, options) => {
|
|
231
231
|
return extend(JSON.parse(text), options);
|
|
232
232
|
};
|
package/types/index.d.ts
CHANGED