@vbarbarosh/node-helpers 3.66.0 → 3.67.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 (48) hide show
  1. package/package.json +4 -2
  2. package/src/HeartbeatServer.js +99 -0
  3. package/src/array_group.js +11 -7
  4. package/src/array_index.js +3 -1
  5. package/src/array_max.js +8 -14
  6. package/src/array_max.test.js +8 -0
  7. package/src/array_min.js +8 -14
  8. package/src/array_min.test.js +8 -0
  9. package/src/array_sort.js +21 -12
  10. package/src/array_sort.test.js +78 -3
  11. package/src/array_sort_other.js +2 -2
  12. package/src/array_unique.js +9 -3
  13. package/src/array_unique_last.js +7 -14
  14. package/src/countdown.js +1 -1
  15. package/src/fcmp_default.js +12 -0
  16. package/src/fcmp_default_desc.js +12 -0
  17. package/src/fcmp_numbers.js +1 -1
  18. package/src/fcmp_tuples.js +15 -0
  19. package/src/fcmp_utf8_bin.js +13 -0
  20. package/src/fcmp_utf8_ci.js +7 -0
  21. package/src/fcmp_utf8_cs.js +7 -0
  22. package/src/fcmp_utf8_natural_ci.js +7 -0
  23. package/src/fcmp_utf8_natural_cs.js +7 -0
  24. package/src/fcmpx.js +120 -0
  25. package/src/fcmpx.test.js +158 -0
  26. package/src/format_date_fs.js +13 -0
  27. package/src/format_date_human.js +13 -0
  28. package/src/format_progress_bytes.js +6 -6
  29. package/src/format_progress_kilo.js +6 -6
  30. package/src/fs_list.js +16 -0
  31. package/src/fs_list_deep.js +20 -0
  32. package/src/fs_ls.js +3 -0
  33. package/src/fs_path_extname.js +14 -0
  34. package/src/fs_path_extname.test.js +22 -0
  35. package/src/now_fs.js +8 -0
  36. package/src/now_human.js +8 -0
  37. package/src/parallel.js +3 -3
  38. package/src/pid_exists.js +12 -0
  39. package/src/pid_kill_grace.js +28 -0
  40. package/src/ping_socket.js +32 -0
  41. package/src/plural.js +8 -2
  42. package/src/plural.test.js +5 -3
  43. package/src/sanitize_var_name.js +2 -2
  44. package/src/{camel_to_snake.js → str_camel_to_snake.js} +2 -2
  45. package/src/{camel_to_snake.test.js → str_camel_to_snake.test.js} +3 -3
  46. package/src/str_parse_kv.js +10 -0
  47. package/src/fcmp_strings.js +0 -6
  48. /package/src/{stream-parse-csv.js → stream_parse_csv.js} +0 -0
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "Vladimir Barbarosh <vladimir.barbarosh@gmail.com>",
3
3
  "license": "MIT",
4
4
  "name": "@vbarbarosh/node-helpers",
5
- "version": "3.66.0",
5
+ "version": "3.67.0",
6
6
  "description": "A set of helpers for JavaScript/Node.js",
7
7
  "unpkg": "dist/browser.js",
8
8
  "jsdelivr": "dist/browser.js",
@@ -28,7 +28,7 @@
28
28
  "url": "https://github.com/vbarbarosh/node-helpers/issues"
29
29
  },
30
30
  "peerDependencies": {
31
- "@vbarbarosh/type-helpers": "^0.1.0",
31
+ "@vbarbarosh/type-helpers": "^0.2.0",
32
32
  "axios": "^1.7.9",
33
33
  "bluebird": "^3.7.2",
34
34
  "csv-parse": "^5.6.0",
@@ -42,6 +42,7 @@
42
42
  "ssh2": "^1.16.0"
43
43
  },
44
44
  "devDependencies": {
45
+ "@vbarbarosh/tree": "^0.5.0",
45
46
  "copy-webpack-plugin": "^12.0.2",
46
47
  "express": "^4.21.2",
47
48
  "mocha": "^11.0.1",
@@ -50,6 +51,7 @@
50
51
  "redis-v3": "npm:redis@3",
51
52
  "redis-v4": "npm:redis@4",
52
53
  "throttle": "^1.0.3",
54
+ "tree-kill": "^1.2.2",
53
55
  "webpack": "^5.98.0",
54
56
  "webpack-cli": "^6.0.1"
55
57
  }
@@ -0,0 +1,99 @@
1
+ const EventEmitter = require('events');
2
+ const Promise = require('bluebird');
3
+ const fs = require('fs');
4
+ const fs_path_join = require('./fs_path_join');
5
+ const fs_rmf = require('./fs_rmf');
6
+ const net = require('net');
7
+ const now_fs = require('./now_fs');
8
+ const os = require('os');
9
+
10
+ class HeartbeatServer extends EventEmitter
11
+ {
12
+ #socket_path;
13
+ #last_ping = Date.now();
14
+ #interval_ms;
15
+ #promise;
16
+ #reject;
17
+ #timer;
18
+ #server;
19
+
20
+ constructor(interval_ms = 5000) {
21
+ super();
22
+ this.#interval_ms = interval_ms;
23
+ this.#init();
24
+ }
25
+
26
+ #init() {
27
+ const _this = this;
28
+
29
+ this.#timer = setInterval(() => this.#tick(), this.#interval_ms);
30
+
31
+ // Put socket on tmpfs to avoid slow disks.
32
+ this.#socket_path = fs.existsSync('/dev/shm')
33
+ ? fs_path_join('/dev/shm', `watchdog-${process.pid}-${now_fs()}.sock`)
34
+ : fs_path_join(os.tmpdir(), `watchdog-${process.pid}-${now_fs()}.sock`);
35
+
36
+ this.#promise = new Promise((resolve, reject) => {
37
+ this.#reject = reject;
38
+ });
39
+
40
+ this.#server = net.createServer(function (socket) {
41
+ socket.setEncoding('utf8');
42
+ socket.on('error', function (error) {
43
+ _this.#reject(new Error(`Client Socket Failed: ${error.message}`));
44
+ });
45
+ socket.on('end', function () {
46
+ _this.#last_ping = Date.now();
47
+ _this.emit('heartbeat');
48
+ });
49
+ socket.on('data', function () {
50
+ // Not really interested in any data
51
+ });
52
+ socket.end('OK');
53
+ });
54
+ this.#server.on('error', function (error) {
55
+ _this.#reject(new Error(`Server Failed: ${error.message}`));
56
+ });
57
+ this.#server.on('close', function () {
58
+ _this.#reject(new Error(`Server Closed`));
59
+ });
60
+ this.#server.listen(this.#socket_path, function () {
61
+ // started = true;
62
+ });
63
+ }
64
+
65
+ #tick() {
66
+ if (this.#last_ping + this.#interval_ms < Date.now()) {
67
+ clearInterval(this.#timer);
68
+ this.#timer = null;
69
+ this.#reject(new Error(`No heartbeat for the last ${this.#interval_ms}ms`));
70
+ }
71
+ }
72
+
73
+ get socket_path() {
74
+ return this.#socket_path;
75
+ }
76
+
77
+ promise() {
78
+ return this.#promise;
79
+ }
80
+
81
+ async dispose() {
82
+ if (this.#timer) {
83
+ clearInterval(this.#timer);
84
+ this.#timer = null;
85
+ }
86
+ try {
87
+ const _this = this;
88
+ await new Promise(function (resolve, reject) {
89
+ _this.#server.removeAllListeners();
90
+ _this.#server.close(error => error ? reject(error) : resolve());
91
+ });
92
+ }
93
+ finally {
94
+ await fs_rmf(this.#socket_path);
95
+ }
96
+ }
97
+ }
98
+
99
+ module.exports = HeartbeatServer;
@@ -1,15 +1,19 @@
1
- const array_group_map = require('./array_group_map');
2
-
3
1
  /**
4
- * Group items by common key and return an array of groups.
2
+ * Group items by a common key and return an array of groups.
5
3
  *
6
- * @param array
7
- * @param fn
8
- * @returns {unknown[]}
4
+ * @alternative Map.groupBy(items, fn)
9
5
  */
10
6
  function array_group(array, fn)
11
7
  {
12
- return Object.values(array_group_map(array, fn));
8
+ const map = new Map();
9
+ array.forEach(function (item) {
10
+ const key = fn(item);
11
+ if (!map.has(key)) {
12
+ map.set(key, {key, items: []});
13
+ }
14
+ map.get(key).items.push(item);
15
+ });
16
+ return map.values().toArray();
13
17
  }
14
18
 
15
19
  module.exports = array_group;
@@ -1,3 +1,5 @@
1
+ const identity = require('./identity');
2
+
1
3
  /**
2
4
  * Usage:
3
5
  * array_index(items, v => v.name)
@@ -5,7 +7,7 @@
5
7
  * Seems, there is a native way to do it:
6
8
  * Object.fromEntries(items.map(v => [v.name, v]));
7
9
  */
8
- function array_index(array, fn)
10
+ function array_index(array, fn = identity)
9
11
  {
10
12
  const out = {};
11
13
  array.forEach(v => out[fn(v)] = v);
package/src/array_max.js CHANGED
@@ -1,26 +1,20 @@
1
+ const identity = require('./identity');
2
+
1
3
  /**
2
- * Return first among maximum values.
3
- *
4
- * @param array
5
- * @param fn
4
+ * Returns the first element in the array with the maximal weight
6
5
  */
7
6
  function array_max(array, fn = identity)
8
7
  {
9
8
  let out = null;
10
- let out_value = null;
11
- array.forEach(function (item) {
12
- const item_value = fn(item);
13
- if (item_value > out_value || out_value === null) {
9
+ let max = null;
10
+ array.forEach(function (item, i) {
11
+ const weight = fn(item);
12
+ if (i === 0 || max < weight) {
13
+ max = weight;
14
14
  out = item;
15
- out_value = item_value;
16
15
  }
17
16
  });
18
17
  return out;
19
18
  }
20
19
 
21
- function identity(value)
22
- {
23
- return value;
24
- }
25
-
26
20
  module.exports = array_max;
@@ -9,4 +9,12 @@ describe('array_max', function () {
9
9
  assert.deepStrictEqual(array_max([1, 1, 2, 2, 3, 3, 1]), 3);
10
10
  assert.deepStrictEqual(array_max([{x:1},{x:2}], v => v.x), {x: 2});
11
11
  });
12
+ it('should handle strings', function () {
13
+ const items = [
14
+ {id: 1, time: '2025-08-08T05:03:13+00:00'},
15
+ {id: 2, time: '2025-08-07T05:03:13+00:00'},
16
+ {id: 3, time: '2025-08-06T05:03:13+00:00'},
17
+ ];
18
+ assert.deepStrictEqual(array_max(items, v => v.time), items[0]);
19
+ });
12
20
  });
package/src/array_min.js CHANGED
@@ -1,26 +1,20 @@
1
+ const identity = require('./identity');
2
+
1
3
  /**
2
- * Return first among minimum values.
3
- *
4
- * @param array
5
- * @param fn
4
+ * Returns the first element in the array with the minimal weight
6
5
  */
7
6
  function array_min(array, fn = identity)
8
7
  {
9
8
  let out = null;
10
- let out_value = null;
11
- array.forEach(function (item) {
12
- const item_value = fn(item);
13
- if (item_value < out_value || out_value === null) {
9
+ let min = null;
10
+ array.forEach(function (item, i) {
11
+ const weight = fn(item);
12
+ if (i === 0 || min > weight) {
13
+ min = weight;
14
14
  out = item;
15
- out_value = item_value;
16
15
  }
17
16
  });
18
17
  return out;
19
18
  }
20
19
 
21
- function identity(value)
22
- {
23
- return value;
24
- }
25
-
26
20
  module.exports = array_min;
@@ -9,4 +9,12 @@ describe('array_min', function () {
9
9
  assert.deepStrictEqual(array_min([1, 1, 2, 2, 3, 3, 1]), 1);
10
10
  assert.deepStrictEqual(array_min([{x:2},{x:1}], v => v.x), {x: 1});
11
11
  });
12
+ it('should handle strings', function () {
13
+ const items = [
14
+ {id: 1, time: '2025-08-08T05:03:13+00:00'},
15
+ {id: 2, time: '2025-08-07T05:03:13+00:00'},
16
+ {id: 3, time: '2025-08-06T05:03:13+00:00'},
17
+ ];
18
+ assert.deepStrictEqual(array_min(items, v => v.time), items[2]);
19
+ });
12
20
  });
package/src/array_sort.js CHANGED
@@ -1,23 +1,32 @@
1
- const fcmp_strings = require('./fcmp_strings');
1
+ const fcmp_default = require('./fcmp_default');
2
+ const fcmp_tuples = require('./fcmp_tuples');
2
3
 
3
4
  /**
4
- * Sort items in an `array`.
5
+ * Sorts an array in place by the result of applying `fn` to each item,
6
+ * using `fcmp` to compare the results.
5
7
  *
6
- * @param array
7
- * @param fn
8
- * @param fcmp
9
- * @returns {*}
8
+ * array_sort(items, v => [v.name])
9
+ * array_sort(items, v => [v.age, v.name])
10
10
  */
11
- function array_sort(array, fn = identity, fcmp = fcmp_strings)
11
+ function array_sort(array, mapper, fcmp = fcmp_default)
12
12
  {
13
+ const keys = new Map();
13
14
  return array.sort(function (a, b) {
14
- return fcmp(fn(a), fn(b));
15
+ if (!keys.has(a)) {
16
+ keys.set(a, mapper(a));
17
+ }
18
+ if (!keys.has(b)) {
19
+ keys.set(b, mapper(b));
20
+ }
21
+ return fcmp_tuples(keys.get(a), keys.get(b), fcmp);
15
22
  });
16
23
  }
17
24
 
18
- function identity(v)
19
- {
20
- return v;
21
- }
25
+ // function array_sort(array, fn = identity, fcmp = fcmp_default)
26
+ // {
27
+ // return array.sort(function (a, b) {
28
+ // return fcmp(fn(a), fn(b));
29
+ // });
30
+ // }
22
31
 
23
32
  module.exports = array_sort;
@@ -1,10 +1,85 @@
1
1
  const array_sort = require('./array_sort');
2
2
  const assert = require('assert');
3
+ const fs_path_extname = require('./fs_path_extname');
3
4
 
4
5
  describe('array_sort', function () {
5
6
  it('should handle basic input', function () {
6
- assert.deepStrictEqual(array_sort([5,4,3,2,1]), [1,2,3,4,5]);
7
- assert.deepStrictEqual(array_sort([5,4,3,2,1], v => v), [1,2,3,4,5]);
8
- assert.deepStrictEqual(array_sort([{id:5},{id:4},{id:3},{id:2},{id:1}], v => v.id), [{id:1},{id:2},{id:3},{id:4},{id:5}]);
7
+ assert.deepStrictEqual(array_sort([5,4,3,2,1], v => [v]), [1,2,3,4,5]);
8
+ assert.deepStrictEqual(array_sort([5,4,3,2,1], v => [v]), [1,2,3,4,5]);
9
+ assert.deepStrictEqual(array_sort([{id:5},{id:4},{id:3},{id:2},{id:1}], v => [v.id]), [{id:1},{id:2},{id:3},{id:4},{id:5}]);
10
+ });
11
+ it('should handle sort by priorities', function () {
12
+ assert.deepStrictEqual(array_sort([1,2,3,4,5], v => [[5].indexOf(v) >>> 0]), [5,1,2,3,4]);
13
+ assert.deepStrictEqual(array_sort([{id:1},{id:2},{id:3},{id:4},{id:5}], v => [[5].indexOf(v.id) >>> 0]), [{id:5},{id:1},{id:2},{id:3},{id:4}]);
14
+ });
15
+ it('should handle sort by priorities #2', function () {
16
+ const files = [
17
+ {name: 'README.md', size: 1024, type: 'file'},
18
+ {name: 'package.json', size: 860, type: 'file'},
19
+ {name: 'src', size: 0, type: 'dir'},
20
+ {name: 'src/index.js', size: 2048, type: 'file'},
21
+ {name: 'src/utils', size: 0, type: 'dir'},
22
+ {name: 'src/utils/helpers.js', size: 1536, type: 'file'},
23
+ {name: 'node_modules', size: 0, type: 'dir'},
24
+ {name: 'LICENSE', size: 1078, type: 'file'},
25
+ ];
26
+ const expected = [
27
+ {name: 'node_modules', size: 0, type: 'dir'},
28
+ {name: 'src', size: 0, type: 'dir'},
29
+ {name: 'src/utils', size: 0, type: 'dir'},
30
+ {name: 'LICENSE', size: 1078, type: 'file'},
31
+ {name: 'README.md', size: 1024, type: 'file'},
32
+ {name: 'package.json', size: 860, type: 'file'},
33
+ {name: 'src/index.js', size: 2048, type: 'file'},
34
+ {name: 'src/utils/helpers.js', size: 1536, type: 'file'},
35
+ ];
36
+ const actual = array_sort(files, v => [pri_start(v.type, ['dir']), v.name]);
37
+ assert.deepStrictEqual(actual, expected);
38
+ });
39
+ it('sort by name, directory first; .js, then .txt, then all the reset', function () {
40
+ const files = [
41
+ {name: 'docs', type: 'dir', size: 0},
42
+ {name: 'zeta.txt', type: 'file', size: 1200},
43
+ {name: 'alpha.js', type: 'file', size: 1500},
44
+ {name: 'src', type: 'dir', size: 0},
45
+ {name: 'readme.txt', type: 'file', size: 800},
46
+ {name: 'beta.js', type: 'file', size: 1600},
47
+ {name: 'build', type: 'dir', size: 0},
48
+ {name: 'build.foo.js', type: 'dir', size: 0},
49
+ {name: 'build.foo.md', type: 'dir', size: 0},
50
+ {name: 'build.foo.txt', type: 'dir', size: 0},
51
+ {name: 'notes.md', type: 'file', size: 400},
52
+ {name: 'zeta.js', type: 'file', size: 1000},
53
+ {name: 'config', type: 'dir', size: 0},
54
+ ];
55
+ const expected = [
56
+ {name: 'build.foo.js', type: 'dir', size: 0},
57
+ {name: 'build.foo.txt', type: 'dir', size: 0},
58
+ {name: 'build', type: 'dir', size: 0},
59
+ {name: 'build.foo.md', type: 'dir', size: 0},
60
+ {name: 'config', type: 'dir', size: 0},
61
+ {name: 'docs', type: 'dir', size: 0},
62
+ {name: 'src', type: 'dir', size: 0},
63
+ {name: 'alpha.js', type: 'file', size: 1500},
64
+ {name: 'beta.js', type: 'file', size: 1600},
65
+ {name: 'zeta.js', type: 'file', size: 1000},
66
+ {name: 'readme.txt', type: 'file', size: 800},
67
+ {name: 'zeta.txt', type: 'file', size: 1200},
68
+ {name: 'notes.md', type: 'file', size: 400},
69
+ ];
70
+ array_sort(files, v => [pri_start(v.type, ['dir']), pri_start(fs_path_extname(v.name), ['.js', '.txt']), v.name])
71
+ assert.deepStrictEqual(files, expected);
9
72
  });
10
73
  });
74
+
75
+ // priorities.indexOf(v) >>> 0
76
+ function pri_start(value, array)
77
+ {
78
+ const i = array.indexOf(value);
79
+ return i === -1 ? array.length : i;
80
+ }
81
+
82
+ function pri_end(value, array)
83
+ {
84
+ return array.indexOf(value);
85
+ }
@@ -1,4 +1,4 @@
1
- const fcmp_strings = require('./fcmp_strings');
1
+ const fcmp_default = require('./fcmp_default');
2
2
 
3
3
  /**
4
4
  * Sort items in an `array` at the same order as in `other`. Values which
@@ -10,7 +10,7 @@ const fcmp_strings = require('./fcmp_strings');
10
10
  * @param fcmp
11
11
  * @returns {*}
12
12
  */
13
- function array_sort_other(array, fn, other, fcmp = fcmp_strings)
13
+ function array_sort_other(array, fn, other, fcmp = fcmp_default)
14
14
  {
15
15
  const other_map = {};
16
16
  other.forEach((v,i) => other_map[v] = i + 1);
@@ -1,11 +1,17 @@
1
- function array_unique(values)
1
+ const identity = require('./identity');
2
+
3
+ /**
4
+ * Return unique values; if a value occurs multiple times, keep the first one.
5
+ */
6
+ function array_unique(values, fn = identity)
2
7
  {
3
8
  const set = new Set();
4
9
  return values.filter(function (item) {
5
- if (set.has(item)) {
10
+ const key = fn(item);
11
+ if (set.has(key)) {
6
12
  return false;
7
13
  }
8
- set.add(item);
14
+ set.add(key);
9
15
  return true;
10
16
  });
11
17
  }
@@ -1,28 +1,21 @@
1
+ const identity = require('./identity');
2
+
1
3
  /**
2
- * Return only unique values. If there are many values - prefer last one.
3
- *
4
- * @param array
5
- * @param fn
6
- * @returns {*[]}
4
+ * Return unique values; if a value occurs multiple times, keep the last one.
7
5
  */
8
6
  function array_unique_last(array, fn = identity)
9
7
  {
10
8
  const out = [];
11
- const taken = {};
9
+ const set = new Set();
12
10
  for (let i = array.length; --i >= 0; ) {
13
11
  const item = array[i];
14
- const pk = fn(item);
15
- if (!taken[pk]) {
16
- taken[pk] = true;
12
+ const key = fn(item);
13
+ if (!set.has(key)) {
14
+ set.add(key);
17
15
  out.push(item);
18
16
  }
19
17
  }
20
18
  return out.reverse();
21
19
  }
22
20
 
23
- function identity(value)
24
- {
25
- return value;
26
- }
27
-
28
21
  module.exports = array_unique_last;
package/src/countdown.js CHANGED
@@ -13,7 +13,7 @@ function countdown(ctx)
13
13
  let timer = null;
14
14
  return new Promise(function (resolve, reject) {
15
15
  ctx.value = ctx.fn ? Promise.method(ctx.fn).call() : Promise.resolve(ctx.value);
16
- ctx.timeout = ctx.timeout || 0;
16
+ ctx.timeout = ctx.timeout || 0; // ⚠️ Rename to timeout_ms
17
17
  ctx.time_now = new Date();
18
18
  ctx.time_begin = new Date();
19
19
  ctx.time_end = Date.now() + ctx.timeout;
@@ -0,0 +1,12 @@
1
+ function fcmp_default(a, b)
2
+ {
3
+ if (a < b) {
4
+ return -1;
5
+ }
6
+ if (a > b) {
7
+ return 1;
8
+ }
9
+ return 0;
10
+ }
11
+
12
+ module.exports = fcmp_default;
@@ -0,0 +1,12 @@
1
+ function fcmp_default_desc(b, a)
2
+ {
3
+ if (a < b) {
4
+ return -1;
5
+ }
6
+ if (a > b) {
7
+ return 1;
8
+ }
9
+ return 0;
10
+ }
11
+
12
+ module.exports = fcmp_default_desc;
@@ -1,6 +1,6 @@
1
1
  function fcmp_numbers(a, b)
2
2
  {
3
- return Number(a) - b;
3
+ return a - b;
4
4
  }
5
5
 
6
6
  module.exports = fcmp_numbers;
@@ -0,0 +1,15 @@
1
+ const fcmp_default = require('./fcmp_default');
2
+
3
+ function fcmp_tuples(a, b, fcmp = fcmp_default)
4
+ {
5
+ const end = Math.min(a.length, b.length);
6
+ for (let i = 0; i < end; ++i) {
7
+ const tmp = fcmp(a[i], b[i]);
8
+ if (tmp) {
9
+ return tmp;
10
+ }
11
+ }
12
+ return 0;
13
+ }
14
+
15
+ module.exports = fcmp_tuples;
@@ -0,0 +1,13 @@
1
+ // Strict binary (codepoint) comparison, like MySQL's utf8_bin collation
2
+ function fcmp_utf8_bin(a, b)
3
+ {
4
+ if (a < b) {
5
+ return -1;
6
+ }
7
+ if (a > b) {
8
+ return 1;
9
+ }
10
+ return 0;
11
+ }
12
+
13
+ module.exports = fcmp_utf8_bin;
@@ -0,0 +1,7 @@
1
+ // Locale-aware, case-insensitive, like utf8_ci or utf8mb4_ci
2
+ function fcmp_utf8_ci(a, b)
3
+ {
4
+ return a.localeCompare(b, undefined, {sensitivity: 'base'});
5
+ }
6
+
7
+ module.exports = fcmp_utf8_ci;
@@ -0,0 +1,7 @@
1
+ // Locale-aware, case-sensitive, like utf8_cs or utf8mb4_cs (but using system locale)
2
+ function fcmp_utf8_cs(a, b)
3
+ {
4
+ return a.localeCompare(b, undefined, {sensitivity: 'variant'});
5
+ }
6
+
7
+ module.exports = fcmp_utf8_cs;
@@ -0,0 +1,7 @@
1
+ // Natural sort (numeric), case-insensitive
2
+ function fcmp_utf8_natural_ci(a, b)
3
+ {
4
+ return a.localeCompare(b, undefined, {numeric: true, sensitivity: 'base'});
5
+ }
6
+
7
+ module.exports = fcmp_utf8_natural_ci;
@@ -0,0 +1,7 @@
1
+ // Natural sort (numeric), case-sensitive
2
+ function fcmp_utf8_natural_cs(a, b)
3
+ {
4
+ return a.localeCompare(b, undefined, {numeric: true, sensitivity: 'variant'});
5
+ }
6
+
7
+ module.exports = fcmp_utf8_natural_cs;