xcraft-core-utils 4.14.0 → 4.14.2

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/.editorconfig CHANGED
@@ -1,9 +1,9 @@
1
- root = true
2
-
3
- [*.{js,jsx,json}]
4
- indent_style = space
5
- indent_size = 2
6
- charset = utf-8
7
- trim_trailing_whitespace = true
8
- insert_final_newline = true
9
- max_line_length = 80
1
+ root = true
2
+
3
+ [*.{js,jsx,json}]
4
+ indent_style = space
5
+ indent_size = 2
6
+ charset = utf-8
7
+ trim_trailing_whitespace = true
8
+ insert_final_newline = true
9
+ max_line_length = 80
package/.zou-flow CHANGED
@@ -1,2 +1,2 @@
1
- [update-version]
2
- package-json = package.json
1
+ [update-version]
2
+ package-json = package.json
package/README.md CHANGED
@@ -1,3 +1,3 @@
1
- # xcraft-core-utils
2
-
3
- Xcraft utils
1
+ # xcraft-core-utils
2
+
3
+ Xcraft utils
package/eslint.config.js CHANGED
@@ -1,65 +1,65 @@
1
- const js = require('@eslint/js');
2
- const globals = require('globals');
3
- const react = require('eslint-plugin-react');
4
- const jsdoc = require('eslint-plugin-jsdoc');
5
- const babel = require('@babel/eslint-plugin');
6
- const prettier = require('eslint-config-prettier');
7
- const babelParser = require('@babel/eslint-parser');
8
-
9
- module.exports = [
10
- js.configs.recommended,
11
- react.configs.flat.recommended,
12
- jsdoc.configs['flat/recommended'],
13
- prettier,
14
- {
15
- languageOptions: {
16
- parser: babelParser,
17
- parserOptions: {
18
- requireConfigFile: false, // Évite de devoir spécifier un fichier de configuration Babel
19
- babelOptions: {
20
- presets: ['@babel/preset-react'],
21
- },
22
- ecmaFeatures: {
23
- jsx: true,
24
- },
25
- },
26
- globals: {
27
- ...globals.browser,
28
- ...globals.node,
29
- ...globals.es2022,
30
- ...globals.mocha,
31
- },
32
- },
33
- plugins: {
34
- 'react': react,
35
- 'jsdoc': jsdoc,
36
- '@babel': babel,
37
- },
38
- rules: {
39
- 'eqeqeq': 'error',
40
- 'no-console': 'off',
41
- 'react/display-name': 'off',
42
- '@babel/no-unused-expressions': 'error', // Utilisation de règles spécifiques à Babel
43
- 'no-unused-vars': [
44
- 'error',
45
- {
46
- vars: 'all',
47
- args: 'none',
48
- ignoreRestSiblings: true,
49
- destructuredArrayIgnorePattern: '^_',
50
- },
51
- ],
52
- 'jsdoc/require-jsdoc': 'off',
53
- 'jsdoc/require-param-description': 'off',
54
- 'jsdoc/require-returns-description': 'off',
55
- },
56
- settings: {
57
- react: {
58
- version: 'detect',
59
- },
60
- jsdoc: {
61
- mode: 'typescript',
62
- },
63
- },
64
- },
65
- ];
1
+ const js = require('@eslint/js');
2
+ const globals = require('globals');
3
+ const react = require('eslint-plugin-react');
4
+ const jsdoc = require('eslint-plugin-jsdoc');
5
+ const babel = require('@babel/eslint-plugin');
6
+ const prettier = require('eslint-config-prettier');
7
+ const babelParser = require('@babel/eslint-parser');
8
+
9
+ module.exports = [
10
+ js.configs.recommended,
11
+ react.configs.flat.recommended,
12
+ jsdoc.configs['flat/recommended'],
13
+ prettier,
14
+ {
15
+ languageOptions: {
16
+ parser: babelParser,
17
+ parserOptions: {
18
+ requireConfigFile: false, // Évite de devoir spécifier un fichier de configuration Babel
19
+ babelOptions: {
20
+ presets: ['@babel/preset-react'],
21
+ },
22
+ ecmaFeatures: {
23
+ jsx: true,
24
+ },
25
+ },
26
+ globals: {
27
+ ...globals.browser,
28
+ ...globals.node,
29
+ ...globals.es2022,
30
+ ...globals.mocha,
31
+ },
32
+ },
33
+ plugins: {
34
+ 'react': react,
35
+ 'jsdoc': jsdoc,
36
+ '@babel': babel,
37
+ },
38
+ rules: {
39
+ 'eqeqeq': 'error',
40
+ 'no-console': 'off',
41
+ 'react/display-name': 'off',
42
+ '@babel/no-unused-expressions': 'error', // Utilisation de règles spécifiques à Babel
43
+ 'no-unused-vars': [
44
+ 'error',
45
+ {
46
+ vars: 'all',
47
+ args: 'none',
48
+ ignoreRestSiblings: true,
49
+ destructuredArrayIgnorePattern: '^_',
50
+ },
51
+ ],
52
+ 'jsdoc/require-jsdoc': 'off',
53
+ 'jsdoc/require-param-description': 'off',
54
+ 'jsdoc/require-returns-description': 'off',
55
+ },
56
+ settings: {
57
+ react: {
58
+ version: 'detect',
59
+ },
60
+ jsdoc: {
61
+ mode: 'typescript',
62
+ },
63
+ },
64
+ },
65
+ ];
package/index.js CHANGED
@@ -1,28 +1,28 @@
1
- 'use strict';
2
-
3
- exports.ArrayCollector = require('./lib/arrayCollector.js');
4
- exports.batch = require('./lib/batch.js');
5
- exports.Batcher = require('./lib/batcher.js');
6
- exports.crypto = require('./lib/crypto.js');
7
- exports.EventDebouncer = require('./lib/eventDebouncer.js');
8
- exports.files = require('./lib/files.js');
9
- exports.fileCrypto = require('./lib/file-crypto.js');
10
- exports.hash = require('./lib/hash.js');
11
- exports.js = require('./lib/js.js');
12
- exports.json = require('./lib/json.js');
13
- exports.locks = require('./lib/locks.js');
14
- exports.log = require('./lib/log.js');
15
- exports.MapAggregator = require('./lib/mapAggregator.js');
16
- exports.modules = require('./lib/modules.js');
17
- exports.os = require('./lib/os.js');
18
- exports.propTypes = require('./lib/prop-types.js');
19
- exports.reflect = require('./lib/reflect.js');
20
- exports.regex = require('./lib/regex.js');
21
- exports.RestAPI = require('./lib/rest.js');
22
- exports.string = require('./lib/string.js');
23
- exports.whereIs = require('./lib/whereIs.js');
24
- exports.yaml = require('./lib/yaml.js');
25
- exports.zippy = require('./lib/zippy.js');
26
- exports.RankedCache = require('./lib/ranked-cache.js');
27
- exports.JobQueue = require('./lib/job-queue.js');
28
- exports.CursorPump = require('./lib/cursorPump.js');
1
+ 'use strict';
2
+
3
+ exports.ArrayCollector = require('./lib/arrayCollector.js');
4
+ exports.batch = require('./lib/batch.js');
5
+ exports.Batcher = require('./lib/batcher.js');
6
+ exports.crypto = require('./lib/crypto.js');
7
+ exports.EventDebouncer = require('./lib/eventDebouncer.js');
8
+ exports.files = require('./lib/files.js');
9
+ exports.fileCrypto = require('./lib/file-crypto.js');
10
+ exports.hash = require('./lib/hash.js');
11
+ exports.js = require('./lib/js.js');
12
+ exports.json = require('./lib/json.js');
13
+ exports.locks = require('./lib/locks.js');
14
+ exports.log = require('./lib/log.js');
15
+ exports.MapAggregator = require('./lib/mapAggregator.js');
16
+ exports.modules = require('./lib/modules.js');
17
+ exports.os = require('./lib/os.js');
18
+ exports.propTypes = require('./lib/prop-types.js');
19
+ exports.reflect = require('./lib/reflect.js');
20
+ exports.regex = require('./lib/regex.js');
21
+ exports.RestAPI = require('./lib/rest.js');
22
+ exports.string = require('./lib/string.js');
23
+ exports.whereIs = require('./lib/whereIs.js');
24
+ exports.yaml = require('./lib/yaml.js');
25
+ exports.zippy = require('./lib/zippy.js');
26
+ exports.RankedCache = require('./lib/ranked-cache.js');
27
+ exports.JobQueue = require('./lib/job-queue.js');
28
+ exports.CursorPump = require('./lib/cursorPump.js');
package/lib/.babelrc CHANGED
@@ -1,8 +1,8 @@
1
- {
2
- "plugins": [
3
- "@babel/proposal-class-properties",
4
- "@babel/proposal-object-rest-spread",
5
- "@babel/proposal-function-bind",
6
- "@babel/transform-modules-commonjs"
7
- ]
8
- }
1
+ {
2
+ "plugins": [
3
+ "@babel/proposal-class-properties",
4
+ "@babel/proposal-object-rest-spread",
5
+ "@babel/proposal-function-bind",
6
+ "@babel/transform-modules-commonjs"
7
+ ]
8
+ }
@@ -1,37 +1,37 @@
1
- 'use strict';
2
-
3
- const {throttle} = require('lodash');
4
- const watt = require('gigawatts');
5
-
6
- class ArrayCollector {
7
- constructor(resp, wait = 20, onCollect, leading = true) {
8
- this.onCollect = watt(onCollect);
9
- this.entries = {};
10
- this.resp = resp;
11
- this.release = throttle(this._release, wait, {leading});
12
- }
13
-
14
- _release() {
15
- const copy = this.entries;
16
- this.entries = {};
17
- this.onCollect(copy, this.resp);
18
- }
19
-
20
- _addByKey(key, data) {
21
- if (!this.entries[key]) {
22
- this.entries[key] = [];
23
- }
24
- this.entries[key] = this.entries[key].concat(data);
25
- }
26
-
27
- grab(key, data) {
28
- this._addByKey(key, data);
29
- this.release();
30
- }
31
-
32
- cancel() {
33
- this.release.cancel();
34
- }
35
- }
36
-
37
- module.exports = ArrayCollector;
1
+ 'use strict';
2
+
3
+ const {throttle} = require('lodash');
4
+ const watt = require('gigawatts');
5
+
6
+ class ArrayCollector {
7
+ constructor(resp, wait = 20, onCollect, leading = true) {
8
+ this.onCollect = watt(onCollect);
9
+ this.entries = {};
10
+ this.resp = resp;
11
+ this.release = throttle(this._release, wait, {leading});
12
+ }
13
+
14
+ _release() {
15
+ const copy = this.entries;
16
+ this.entries = {};
17
+ this.onCollect(copy, this.resp);
18
+ }
19
+
20
+ _addByKey(key, data) {
21
+ if (!this.entries[key]) {
22
+ this.entries[key] = [];
23
+ }
24
+ this.entries[key] = this.entries[key].concat(data);
25
+ }
26
+
27
+ grab(key, data) {
28
+ this._addByKey(key, data);
29
+ this.release();
30
+ }
31
+
32
+ cancel() {
33
+ this.release.cancel();
34
+ }
35
+ }
36
+
37
+ module.exports = ArrayCollector;
package/lib/async.js CHANGED
@@ -1,34 +1,34 @@
1
- 'use strict';
2
-
3
- const watt = require('gigawatts');
4
-
5
- class Async {
6
- constructor() {
7
- watt.wrapAll(this);
8
- }
9
-
10
- /**
11
- * Reduce an array to a map with an async iteration.
12
- *
13
- * It's useful in the case where the main event loop must not
14
- * be blocked and the array is very large. The purpose of this
15
- * helper is only for task which be done with an usual sync
16
- * map reduce.
17
- * @yields
18
- * @param {*} keyFunc - Key for the item in the map.
19
- * @param {*} valueFunc - Value for the item in the map.
20
- * @param {*} list - The input array.
21
- * @returns {object} the map.
22
- */
23
- *mapReduce(keyFunc, valueFunc, list) {
24
- const state = {};
25
- for (const item of list) {
26
- state[keyFunc(item)] = yield new Promise((resolve) =>
27
- resolve(valueFunc(item))
28
- );
29
- }
30
- return state;
31
- }
32
- }
33
-
34
- module.exports = new Async();
1
+ 'use strict';
2
+
3
+ const watt = require('gigawatts');
4
+
5
+ class Async {
6
+ constructor() {
7
+ watt.wrapAll(this);
8
+ }
9
+
10
+ /**
11
+ * Reduce an array to a map with an async iteration.
12
+ *
13
+ * It's useful in the case where the main event loop must not
14
+ * be blocked and the array is very large. The purpose of this
15
+ * helper is only for task which be done with an usual sync
16
+ * map reduce.
17
+ * @yields
18
+ * @param {*} keyFunc - Key for the item in the map.
19
+ * @param {*} valueFunc - Value for the item in the map.
20
+ * @param {*} list - The input array.
21
+ * @returns {object} the map.
22
+ */
23
+ *mapReduce(keyFunc, valueFunc, list) {
24
+ const state = {};
25
+ for (const item of list) {
26
+ state[keyFunc(item)] = yield new Promise((resolve) =>
27
+ resolve(valueFunc(item))
28
+ );
29
+ }
30
+ return state;
31
+ }
32
+ }
33
+
34
+ module.exports = new Async();
package/lib/batch.js CHANGED
@@ -1,24 +1,24 @@
1
- 'use strict';
2
-
3
- const fs = require('fs');
4
- const path = require('path');
5
- const xFs = require('xcraft-core-fs');
6
-
7
- exports.run = function (filter, location, callbackAction) {
8
- var files = xFs.ls(location);
9
-
10
- files.forEach(function (file) {
11
- var fullPath = path.join(location, file);
12
- var st = fs.lstatSync(fullPath);
13
-
14
- if (st.isDirectory()) {
15
- exports.run(filter, fullPath, callbackAction);
16
- return;
17
- }
18
-
19
- if (!filter || filter.test(file)) {
20
- callbackAction(fullPath);
21
- return;
22
- }
23
- });
24
- };
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const xFs = require('xcraft-core-fs');
6
+
7
+ exports.run = function (filter, location, callbackAction) {
8
+ var files = xFs.ls(location);
9
+
10
+ files.forEach(function (file) {
11
+ var fullPath = path.join(location, file);
12
+ var st = fs.lstatSync(fullPath);
13
+
14
+ if (st.isDirectory()) {
15
+ exports.run(filter, fullPath, callbackAction);
16
+ return;
17
+ }
18
+
19
+ if (!filter || filter.test(file)) {
20
+ callbackAction(fullPath);
21
+ return;
22
+ }
23
+ });
24
+ };
package/lib/batcher.js CHANGED
@@ -1,56 +1,56 @@
1
- class Batcher {
2
- #call = false;
3
- #batch;
4
- #counter = 0;
5
- #timeout;
6
- #timer;
7
-
8
- #begin;
9
- #commit;
10
-
11
- constructor(begin, commit, batch = 500, timeout = 5000) {
12
- this.#begin = begin;
13
- this.#commit = commit;
14
- this.#batch = batch;
15
- this.#timeout = timeout;
16
- }
17
-
18
- #clear() {
19
- this.#counter = 0;
20
- this.#call = false;
21
- if (this.#timer) {
22
- clearTimeout(this.#timer);
23
- this.#timer = null;
24
- }
25
- }
26
-
27
- async start() {
28
- await this.#begin();
29
- this.#timer = setTimeout(() => {
30
- this.#call = true;
31
- }, this.#timeout);
32
- }
33
-
34
- async bump() {
35
- this.#counter++;
36
- if (this.#call || this.#counter % this.#batch === 0) {
37
- await this.stop();
38
- await this.start();
39
- }
40
- }
41
-
42
- async pump() {
43
- if (this.#call) {
44
- await this.stop();
45
- await this.start();
46
- }
47
- }
48
-
49
- async stop() {
50
- const batch = this.#counter;
51
- this.#clear();
52
- await this.#commit(batch);
53
- }
54
- }
55
-
56
- module.exports = Batcher;
1
+ class Batcher {
2
+ #call = false;
3
+ #batch;
4
+ #counter = 0;
5
+ #timeout;
6
+ #timer;
7
+
8
+ #begin;
9
+ #commit;
10
+
11
+ constructor(begin, commit, batch = 500, timeout = 5000) {
12
+ this.#begin = begin;
13
+ this.#commit = commit;
14
+ this.#batch = batch;
15
+ this.#timeout = timeout;
16
+ }
17
+
18
+ #clear() {
19
+ this.#counter = 0;
20
+ this.#call = false;
21
+ if (this.#timer) {
22
+ clearTimeout(this.#timer);
23
+ this.#timer = null;
24
+ }
25
+ }
26
+
27
+ async start() {
28
+ await this.#begin();
29
+ this.#timer = setTimeout(() => {
30
+ this.#call = true;
31
+ }, this.#timeout);
32
+ }
33
+
34
+ async bump() {
35
+ this.#counter++;
36
+ if (this.#call || this.#counter % this.#batch === 0) {
37
+ await this.stop();
38
+ await this.start();
39
+ }
40
+ }
41
+
42
+ async pump() {
43
+ if (this.#call) {
44
+ await this.stop();
45
+ await this.start();
46
+ }
47
+ }
48
+
49
+ async stop() {
50
+ const batch = this.#counter;
51
+ this.#clear();
52
+ await this.#commit(batch);
53
+ }
54
+ }
55
+
56
+ module.exports = Batcher;