@poppinss/utils 7.1.0 → 7.1.1

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/README.md CHANGED
@@ -556,6 +556,16 @@ const values = ['1_foo_bar', '12_foo_bar'].sort(naturalSort)
556
556
  // Default sorting: ['1_foo_bar', '12_foo_bar']
557
557
  ```
558
558
 
559
+ The default comparator uses the English locale. Use `createNaturalSort` to sort with a different locale.
560
+
561
+ ```ts
562
+ import { createNaturalSort } from '@poppinss/utils'
563
+
564
+ const naturalSort = createNaturalSort({ locale: 'cs' })
565
+ const values = ['children', 'groups'].sort(naturalSort)
566
+ // ['groups', 'children']
567
+ ```
568
+
559
569
  ## getGitWorktree
560
570
 
561
571
  Returns information about the linked Git worktree containing the current working directory. The method returns `null` when called from the primary worktree, outside a Git repository, or when Git is unavailable.
package/build/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export { compose } from './src/compose.js';
3
3
  export { flatten } from './src/flatten.js';
4
4
  export { unique } from './src/unique.js';
5
5
  export { safeEqual } from './src/safe_equal.js';
6
- export { naturalSort } from './src/natural_sort.js';
6
+ export { naturalSort, createNaturalSort } from './src/natural_sort.js';
7
7
  export { isScriptFile } from './src/is_script_file.js';
8
8
  export { importDefault } from './src/import_default.js';
9
9
  export { MessageBuilder } from './src/message_builder.js';
package/build/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { n as safeParse, t as safeStringify } from "./main-B9qlOEvt.js";
2
- import { n as naturalSort, t as isScriptFile } from "./is_script_file-D0Om5zlQ.js";
2
+ import { n as createNaturalSort, r as naturalSort, t as isScriptFile } from "./is_script_file-DECAVJWd.js";
3
3
  import { RuntimeException } from "./modules/exception.js";
4
4
  import { flattie } from "flattie";
5
5
  import { Buffer } from "node:buffer";
@@ -381,4 +381,4 @@ async function getGitWorktree(cwd = process.cwd()) {
381
381
  }
382
382
  }
383
383
  //#endregion
384
- export { ImportsBag, MessageBuilder, Secret, compose, defineStaticProperty, detectAIAgent, flatten, getGitWorktree, importDefault, isRunningInAIAgent, isScriptFile, naturalSort, safeEqual, unique };
384
+ export { ImportsBag, MessageBuilder, Secret, compose, createNaturalSort, defineStaticProperty, detectAIAgent, flatten, getGitWorktree, importDefault, isRunningInAIAgent, isScriptFile, naturalSort, safeEqual, unique };
@@ -1,16 +1,22 @@
1
1
  import { extname } from "node:path";
2
2
  //#region src/natural_sort.ts
3
- let collator;
4
3
  /**
5
- * Perform natural sorting with "Array.sort()" method
4
+ * Create a natural sort comparator for a specific locale
6
5
  */
7
- function naturalSort(current, next) {
8
- collator ??= new Intl.Collator(void 0, {
9
- numeric: true,
10
- sensitivity: "base"
11
- });
12
- return collator.compare(current, next);
6
+ function createNaturalSort({ locale }) {
7
+ let collator;
8
+ return function naturalSort(current, next) {
9
+ collator ??= new Intl.Collator(locale, {
10
+ numeric: true,
11
+ sensitivity: "base"
12
+ });
13
+ return collator.compare(current, next);
14
+ };
13
15
  }
16
+ /**
17
+ * Perform natural sorting with "Array.sort()" method
18
+ */
19
+ const naturalSort = createNaturalSort({ locale: "en" });
14
20
  //#endregion
15
21
  //#region src/is_script_file.ts
16
22
  const JS_MODULES = [
@@ -30,4 +36,4 @@ function isScriptFile(filePath) {
30
36
  return false;
31
37
  }
32
38
  //#endregion
33
- export { naturalSort as n, isScriptFile as t };
39
+ export { createNaturalSort as n, naturalSort as r, isScriptFile as t };
@@ -1,4 +1,4 @@
1
- import { n as naturalSort, t as isScriptFile } from "../../is_script_file-D0Om5zlQ.js";
1
+ import { r as naturalSort, t as isScriptFile } from "../../is_script_file-DECAVJWd.js";
2
2
  import { extname, join, relative, sep } from "node:path";
3
3
  import string from "@poppinss/string";
4
4
  import lodash from "@poppinss/utils/lodash";
@@ -1,4 +1,10 @@
1
+ /**
2
+ * Create a natural sort comparator for a specific locale
3
+ */
4
+ export declare function createNaturalSort({ locale }: {
5
+ locale: Intl.LocalesArgument;
6
+ }): (current: string, next: string) => number;
1
7
  /**
2
8
  * Perform natural sorting with "Array.sort()" method
3
9
  */
4
- export declare function naturalSort(current: string, next: string): number;
10
+ export declare const naturalSort: (current: string, next: string) => number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@poppinss/utils",
3
- "version": "7.1.0",
3
+ "version": "7.1.1",
4
4
  "description": "Handy utilities for repetitive work",
5
5
  "main": "build/index.js",
6
6
  "type": "module",