atomic-fns 1.1.7 → 1.2.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 (46) hide show
  1. package/README.md +51 -12
  2. package/dist/collections/BTree.d.ts +11 -10
  3. package/dist/collections/BTree.js +58 -80
  4. package/dist/collections/Heap.js +1 -1
  5. package/dist/collections/LRUCache.d.ts +6 -3
  6. package/dist/collections/LRUCache.js +24 -11
  7. package/dist/collections/SortedMap.js +2 -2
  8. package/dist/collections/SortedTree.d.ts +2 -2
  9. package/dist/collections/SortedTree.js +3 -2
  10. package/dist/collections/SplayTree.d.ts +7 -5
  11. package/dist/collections/SplayTree.js +39 -26
  12. package/dist/collections/Trie.d.ts +1 -1
  13. package/dist/collections/Trie.js +26 -26
  14. package/dist/collections/deque.d.ts +1 -1
  15. package/dist/collections/deque.js +17 -10
  16. package/dist/collections/frozenset.js +4 -1
  17. package/dist/collections/index.d.ts +13 -32
  18. package/dist/collections/index.js +210 -82
  19. package/dist/decimal/index.d.ts +5 -2
  20. package/dist/decimal/index.js +63 -27
  21. package/dist/functools/index.d.ts +6 -30
  22. package/dist/functools/index.js +24 -56
  23. package/dist/globals/index.d.ts +3 -20
  24. package/dist/globals/index.js +23 -39
  25. package/dist/i18n/currency.d.ts +3 -0
  26. package/dist/i18n/currency.js +22 -7
  27. package/dist/i18n/date/index.d.ts +17 -10
  28. package/dist/i18n/date/index.js +79 -58
  29. package/dist/i18n/date/utils.d.ts +4 -5
  30. package/dist/i18n/date/utils.js +15 -113
  31. package/dist/i18n/duration.d.ts +11 -10
  32. package/dist/i18n/duration.js +38 -32
  33. package/dist/i18n/format.d.ts +5 -2
  34. package/dist/i18n/format.js +81 -209
  35. package/dist/i18n/index.d.ts +2 -1
  36. package/dist/itertools/index.d.ts +9 -13
  37. package/dist/itertools/index.js +38 -41
  38. package/dist/math/index.d.ts +10 -27
  39. package/dist/math/index.js +16 -33
  40. package/dist/operators/index.d.ts +1 -5
  41. package/dist/operators/index.js +60 -40
  42. package/dist/random/index.js +9 -6
  43. package/dist/string/index.d.ts +1 -1
  44. package/dist/string/index.js +2 -4
  45. package/dist/types.d.ts +3 -3
  46. package/package.json +16 -21
@@ -11,7 +11,8 @@ import { isObject } from '../globals/index.js';
11
11
  * @returns {number}
12
12
  */
13
13
  export function random(min = 0, max = 1) {
14
- return Math.random() * (max - min) + min;
14
+ const value = Math.random() * (max - min) + min;
15
+ return value === max ? min : value;
15
16
  }
16
17
  /**
17
18
  * Returns a random integer between a [min, max] value (inclusive).
@@ -20,7 +21,9 @@ export function random(min = 0, max = 1) {
20
21
  * @returns {number}
21
22
  */
22
23
  export function randomInt(min = 0, max = 1) {
23
- return Math.round(random(min, max));
24
+ const low = Math.ceil(Math.min(min, max));
25
+ const high = Math.floor(Math.max(min, max));
26
+ return low + Math.floor(random(0, high - low + 1));
24
27
  }
25
28
  /**
26
29
  * Returns the item at some random index in a sequence.
@@ -42,7 +45,7 @@ export function choice(arr) {
42
45
  export function sample(arr, size) {
43
46
  if (!arr?.length || arr.length < size)
44
47
  return [];
45
- return shuffle(arr.slice()).slice(-size);
48
+ return shuffle(arr.slice()).slice(0, size);
46
49
  }
47
50
  /**
48
51
  * Shuffles a collection elements in-place. Uses the Fisher-Yates algorithm for uniform shuffling. If collection is an Object it returns shuffled `Object.values()`.
@@ -53,11 +56,11 @@ export function sample(arr, size) {
53
56
  * @template T
54
57
  */
55
58
  export function shuffle(arr, size) {
56
- if (!arr?.length)
57
- return arr;
58
59
  if (isObject(arr))
59
60
  arr = Object.values(arr);
60
- if (size == null)
61
+ if (!arr?.length)
62
+ return arr;
63
+ if (size == null || size >= arr.length)
61
64
  size = arr.length - 1;
62
65
  for (let i = 0; i <= size; i++) {
63
66
  const j = randomInt(i, size);
@@ -33,7 +33,7 @@ export declare function capitalize(s: string): string;
33
33
  /**
34
34
  * Split a string into an array of its words.
35
35
  * @param {string} s The string to split
36
- * @param {RegExp | string} [pattern] The pattern to match words
36
+ * @param {RegExp | string} [pattern] The separator to split on, instead of matching words
37
37
  * @returns {string[]} Returns the words array.
38
38
  * @example
39
39
  ```js
@@ -3,8 +3,7 @@
3
3
  *
4
4
  * @module string
5
5
  */
6
- const WORDS_REGEX = // eslint-disable-next-line no-control-regex
7
- /[A-Z\xc0-\xd6\xd8-\xde]?[a-z\xdf-\xf6\xf8-\xff]+(?:['’](?:d|ll|m|re|s|t|ve))?(?=[\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000]|[A-Z\xc0-\xd6\xd8-\xde]|$)|(?:[A-Z\xc0-\xd6\xd8-\xde]|[^\ud800-\udfff\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\d+\u2700-\u27bfa-z\xdf-\xf6\xf8-\xffA-Z\xc0-\xd6\xd8-\xde])+(?:['’](?:D|LL|M|RE|S|T|VE))?(?=[\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000]|[A-Z\xc0-\xd6\xd8-\xde](?:[a-z\xdf-\xf6\xf8-\xff]|[^\ud800-\udfff\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\d+\u2700-\u27bfa-z\xdf-\xf6\xf8-\xffA-Z\xc0-\xd6\xd8-\xde])|$)|[A-Z\xc0-\xd6\xd8-\xde]?(?:[a-z\xdf-\xf6\xf8-\xff]|[^\ud800-\udfff\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\d+\u2700-\u27bfa-z\xdf-\xf6\xf8-\xffA-Z\xc0-\xd6\xd8-\xde])+(?:['’](?:d|ll|m|re|s|t|ve))?|[A-Z\xc0-\xd6\xd8-\xde]+(?:['’](?:D|LL|M|RE|S|T|VE))?|\d*(?:1ST|2ND|3RD|(?![123])\dTH)(?=\b|[a-z_])|\d*(?:1st|2nd|3rd|(?![123])\dth)(?=\b|[A-Z_])|\d+|(?:[\u2700-\u27bf]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe2f\u20d0-\u20ff]|\ud83c[\udffb-\udfff])?(?:\u200d(?:[^\ud800-\udfff]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe2f\u20d0-\u20ff]|\ud83c[\udffb-\udfff])?)*/g;
6
+ const WORDS_REGEX = /[A-Z\xc0-\xd6\xd8-\xde]?[a-z\xdf-\xf6\xf8-\xff]+(?:['’](?:d|ll|m|re|s|t|ve))?(?=[\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000]|[A-Z\xc0-\xd6\xd8-\xde]|$)|(?:[A-Z\xc0-\xd6\xd8-\xde]|[^\ud800-\udfff\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\d+\u2700-\u27bfa-z\xdf-\xf6\xf8-\xffA-Z\xc0-\xd6\xd8-\xde])+(?:['’](?:D|LL|M|RE|S|T|VE))?(?=[\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000]|[A-Z\xc0-\xd6\xd8-\xde](?:[a-z\xdf-\xf6\xf8-\xff]|[^\ud800-\udfff\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\d+\u2700-\u27bfa-z\xdf-\xf6\xf8-\xffA-Z\xc0-\xd6\xd8-\xde])|$)|[A-Z\xc0-\xd6\xd8-\xde]?(?:[a-z\xdf-\xf6\xf8-\xff]|[^\ud800-\udfff\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\d+\u2700-\u27bfa-z\xdf-\xf6\xf8-\xffA-Z\xc0-\xd6\xd8-\xde])+(?:['’](?:d|ll|m|re|s|t|ve))?|[A-Z\xc0-\xd6\xd8-\xde]+(?:['’](?:D|LL|M|RE|S|T|VE))?|\d*(?:1ST|2ND|3RD|(?![123])\dTH)(?=\b|[a-z_])|\d*(?:1st|2nd|3rd|(?![123])\dth)(?=\b|[A-Z_])|\d+|(?:[\u2700-\u27bf]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe2f\u20d0-\u20ff]|\ud83c[\udffb-\udfff])?(?:\u200d(?:[^\ud800-\udfff]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe2f\u20d0-\u20ff]|\ud83c[\udffb-\udfff])?)*/g;
8
7
  /**
9
8
  * Converts only the first character of the given string to upper case. Note that the rest of the characters are preserved.
10
9
  * @param {string} s The string
@@ -39,7 +38,7 @@ export function capitalize(s) {
39
38
  /**
40
39
  * Split a string into an array of its words.
41
40
  * @param {string} s The string to split
42
- * @param {RegExp | string} [pattern] The pattern to match words
41
+ * @param {RegExp | string} [pattern] The separator to split on, instead of matching words
43
42
  * @returns {string[]} Returns the words array.
44
43
  * @example
45
44
  ```js
@@ -125,7 +124,6 @@ asciify('äÄçÇéÉêPHP-MySQLöÖÐþúÚ')
125
124
  ```
126
125
  */
127
126
  export function asciify(s) {
128
- // eslint-disable-next-line no-control-regex
129
127
  return s.replace(/[^\x00-\x7F]/g, '');
130
128
  }
131
129
  /**
package/dist/types.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * A generic function type with arbitrary arguments and return.
3
3
  */
4
- export declare type Function<TReturn = any> = (...args: any) => TReturn;
4
+ export type Function<TReturn = any> = (...args: any) => TReturn;
5
5
  /**
6
6
  * An iteratee function used for collection methods.
7
7
  * @see {@link collections.filter}
@@ -15,5 +15,5 @@ export declare type Function<TReturn = any> = (...args: any) => TReturn;
15
15
  * @see {@link collections.sortedUniq}
16
16
  * @see {@link collections.groupBy}
17
17
  */
18
- export declare type Iteratee<T = any, K = any, TResult = any> = (value: T, key?: K, arr?: any) => TResult;
19
- export declare type Predicate<T = any, TReturn = any> = (value: T) => TReturn;
18
+ export type Iteratee<T = any, K = any, TResult = any> = (value: T, key?: K, arr?: any) => TResult;
19
+ export type Predicate<T = any, TReturn = any> = (value: T) => TReturn;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "atomic-fns",
3
3
  "description": "Like Lodash, but for ESNext and with types. Stop shipping code built for browsers from 2015.",
4
- "version": "1.1.7",
4
+ "version": "1.2.0",
5
5
  "files": [
6
6
  "dist/*"
7
7
  ],
@@ -12,30 +12,25 @@
12
12
  "sideEffects": false,
13
13
  "scripts": {
14
14
  "preversion": "npm test",
15
- "version": "npm run build && npm run docs && git add -A dist",
15
+ "version": "npm run build",
16
16
  "postversion": "git push && git push --tags",
17
17
  "prepublishOnly": "npm run build",
18
- "test": "NODE_OPTIONS=--loader=ts-node/esm jasmine --config=jasmine.json",
19
- "tsc": "tsc -p . --declaration",
18
+ "test": "vitest run",
19
+ "tsc": "tsc -p . --declaration && node scripts/declaration-imports.ts",
20
20
  "tsc:w": "tsc -p . --declaration --watch",
21
- "lint": "eslint src/**/*.ts --fix",
22
- "build": "npm run lint && npm test && npm run tsc && npm run docs",
23
- "docs": "typedoc"
21
+ "lint": "biome check --diagnostic-level=error .",
22
+ "build": "npm run lint && npm test && npm run tsc",
23
+ "docs": "deno doc --html --name atomic-fns --output docs src/index.ts src/*/index.ts",
24
+ "check": "npm run lint && npm run tsc && npm test && npm run jsr",
25
+ "format": "biome format --write .",
26
+ "jsr": "deno publish --dry-run --allow-dirty --set-version $npm_package_version"
24
27
  },
25
28
  "devDependencies": {
26
- "@types/jasmine": "^4.3.0",
27
- "@typescript-eslint/eslint-plugin": "^5.39.0",
28
- "eslint": "^8.25.0",
29
- "eslint-config-prettier": "^8.5.0",
30
- "eslint-config-standard-with-typescript": "^23.0.0",
31
- "eslint-plugin-n": "^15.3.0",
32
- "eslint-plugin-prettier": "^4.2.1",
33
- "jasmine": "^4.4.0",
34
- "jasmine-spec-reporter": "^7.0.0",
35
- "prettier": "^2.7.1",
36
- "ts-node": "^10.9.1",
37
- "typedoc": "^0.23.16",
38
- "typescript": "^4.8.4"
29
+ "@biomejs/biome": "^2.6.5",
30
+ "@types/node": "^26.6.6",
31
+ "deno": "^2.9.6",
32
+ "typescript": "^7.0.2",
33
+ "vitest": "^5.1.0"
39
34
  },
40
35
  "repository": {
41
36
  "type": "git",
@@ -70,5 +65,5 @@
70
65
  "bugs": {
71
66
  "url": "https://github.com/adrian2x/atomic-fns/issues"
72
67
  },
73
- "homepage": "https://atomic-stack.github.io/atomic-fns/"
68
+ "homepage": "https://jsr.io/@atomic-stack/atomic-fns"
74
69
  }