@juisy/utils 3.0.0-beta.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 (95) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +51 -0
  3. package/dist/assert/argsert.d.ts +92 -0
  4. package/dist/assert/argsert.js +45 -0
  5. package/dist/assert/assert.d.ts +457 -0
  6. package/dist/assert/assert.js +100 -0
  7. package/dist/constructor/apply-mixins.d.ts +15 -0
  8. package/dist/constructor/apply-mixins.js +23 -0
  9. package/dist/constructor/get-constructor-name.d.ts +19 -0
  10. package/dist/constructor/get-constructor-name.js +18 -0
  11. package/dist/date/date-format.d.ts +18 -0
  12. package/dist/date/date-format.js +15 -0
  13. package/dist/date/get-date-range.d.ts +38 -0
  14. package/dist/date/get-date-range.js +32 -0
  15. package/dist/date/get-duration-between-times.d.ts +13 -0
  16. package/dist/date/get-duration-between-times.js +20 -0
  17. package/dist/date/get-duration-between.d.ts +12 -0
  18. package/dist/date/get-duration-between.js +16 -0
  19. package/dist/date/get-i18n-timezone-value.d.ts +19 -0
  20. package/dist/date/get-i18n-timezone-value.js +27 -0
  21. package/dist/date/get-next-date-for-time.d.ts +10 -0
  22. package/dist/date/get-next-date-for-time.js +16 -0
  23. package/dist/date/get-utc-offset.d.ts +10 -0
  24. package/dist/date/get-utc-offset.js +15 -0
  25. package/dist/fs/get-file-urls.d.ts +12 -0
  26. package/dist/fs/get-file-urls.js +13 -0
  27. package/dist/fs/get-files-sync.d.ts +19 -0
  28. package/dist/fs/get-files-sync.js +23 -0
  29. package/dist/fs/get-files.d.ts +23 -0
  30. package/dist/fs/get-files.js +21 -0
  31. package/dist/fs/get-root-dir.d.ts +15 -0
  32. package/dist/fs/get-root-dir.js +12 -0
  33. package/dist/fs/is-directory.d.ts +13 -0
  34. package/dist/fs/is-directory.js +17 -0
  35. package/dist/fs/is-file.d.ts +13 -0
  36. package/dist/fs/is-file.js +17 -0
  37. package/dist/is/is-def.d.ts +20 -0
  38. package/dist/is/is-def.js +10 -0
  39. package/dist/is/is-valid-css-color.d.ts +11 -0
  40. package/dist/is/is-valid-css-color.js +10 -0
  41. package/dist/is/is.d.ts +456 -0
  42. package/dist/is/is.js +102 -0
  43. package/dist/misc/compose.d.ts +18 -0
  44. package/dist/misc/compose.js +31 -0
  45. package/dist/misc/detect-browser.d.ts +19 -0
  46. package/dist/misc/detect-browser.js +12 -0
  47. package/dist/misc/type-check.d.ts +19 -0
  48. package/dist/misc/type-check.js +39 -0
  49. package/dist/object/deep-merge.d.ts +21 -0
  50. package/dist/object/deep-merge.js +10 -0
  51. package/dist/object/deep-parse.d.ts +18 -0
  52. package/dist/object/deep-parse.js +15 -0
  53. package/dist/object/get.d.ts +24 -0
  54. package/dist/object/get.js +12 -0
  55. package/dist/path/is-posix.d.ts +17 -0
  56. package/dist/path/is-posix.js +12 -0
  57. package/dist/path/is-same-as.d.ts +21 -0
  58. package/dist/path/is-same-as.js +13 -0
  59. package/dist/path/is-win32.d.ts +17 -0
  60. package/dist/path/is-win32.js +10 -0
  61. package/dist/path/normalize.d.ts +16 -0
  62. package/dist/path/normalize.js +22 -0
  63. package/dist/path/resolve-abs-from-root.d.ts +14 -0
  64. package/dist/path/resolve-abs-from-root.js +17 -0
  65. package/dist/path/resolve-rel-from-root.d.ts +14 -0
  66. package/dist/path/resolve-rel-from-root.js +13 -0
  67. package/dist/path/resolve-rel.d.ts +21 -0
  68. package/dist/path/resolve-rel.js +16 -0
  69. package/dist/path/to-os-format.d.ts +12 -0
  70. package/dist/path/to-os-format.js +14 -0
  71. package/dist/path/to-posix.d.ts +16 -0
  72. package/dist/path/to-posix.js +12 -0
  73. package/dist/path/to-win32.d.ts +16 -0
  74. package/dist/path/to-win32.js +12 -0
  75. package/dist/random/random-alpha-numeric.d.ts +22 -0
  76. package/dist/random/random-alpha-numeric.js +12 -0
  77. package/dist/random/random-number.d.ts +23 -0
  78. package/dist/random/random-number.js +12 -0
  79. package/dist/string/camelcase.d.ts +22 -0
  80. package/dist/string/camelcase.js +12 -0
  81. package/dist/string/capitalize.d.ts +23 -0
  82. package/dist/string/capitalize.js +18 -0
  83. package/dist/string/constantcase.d.ts +16 -0
  84. package/dist/string/constantcase.js +12 -0
  85. package/dist/string/kebabcase.d.ts +22 -0
  86. package/dist/string/kebabcase.js +12 -0
  87. package/dist/string/lowercase.d.ts +22 -0
  88. package/dist/string/lowercase.js +12 -0
  89. package/dist/string/pascalcase.d.ts +16 -0
  90. package/dist/string/pascalcase.js +13 -0
  91. package/dist/string/snakecase.d.ts +22 -0
  92. package/dist/string/snakecase.js +12 -0
  93. package/dist/string/uppercase.d.ts +22 -0
  94. package/dist/string/uppercase.js +12 -0
  95. package/package.json +123 -0
@@ -0,0 +1,31 @@
1
+ /*!
2
+ * juisy v3.0.0-beta.0
3
+ * Copyright © 2022-Present Hervé Perchec
4
+ */
5
+
6
+ import isDef from '@juisy/utils/is/is-def';
7
+
8
+ function compose(funcs, args = []) {
9
+ return funcs.reduce(
10
+ (wrap, wrapped) => {
11
+ return function(...args2) {
12
+ let nextPayload = wrapped(...args2);
13
+ if (!isDef(nextPayload)) {
14
+ nextPayload = args2;
15
+ } else if (nextPayload instanceof Promise) {
16
+ return new Promise((resolve, reject) => {
17
+ nextPayload.then((payload) => {
18
+ resolve(wrap(...payload));
19
+ }).catch((error) => reject(error));
20
+ });
21
+ }
22
+ return wrap(...nextPayload);
23
+ };
24
+ },
25
+ // IMPORTANT: Initial value (accumulator): function that returns the received args
26
+ (..._args) => _args
27
+ // eslint-disable-line @typescript-eslint/no-explicit-any
28
+ )(...args);
29
+ }
30
+
31
+ export { compose, compose as default };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @module misc/detect-browser
3
+ * @importTarget ./misc/detect-browser
4
+ * @author Hervé Perchec
5
+ */
6
+ /**
7
+ * Detect the browser
8
+ *
9
+ * ::: tip See also
10
+ * [detect-browser-es](https://www.npmjs.com/package/detect-browser-es) package documentation
11
+ * :::
12
+ * @param userAgent - The user agent
13
+ * @returns The detected browser
14
+ * @envCompat Browser
15
+ * @example
16
+ * detectBrowser() // { name: 'firefox', type: 'browser' }
17
+ */
18
+ export declare function detectBrowser(userAgent?: string): import('detect-browser-es').BrowserInfo | import('detect-browser-es').ServerInfo | import('detect-browser-es').SearchBotDeviceInfo | import('detect-browser-es').BotInfo | import('detect-browser-es').ReactNativeInfo | import('detect-browser-es').JSDOMInfo | import('detect-browser-es').HappyDomInfo | import('detect-browser-es').WDIOBrowserRunnerInfo | null;
19
+ export default detectBrowser;
@@ -0,0 +1,12 @@
1
+ /*!
2
+ * juisy v3.0.0-beta.0
3
+ * Copyright © 2022-Present Hervé Perchec
4
+ */
5
+
6
+ import { detect } from 'detect-browser-es';
7
+
8
+ function detectBrowser(userAgent) {
9
+ return detect(userAgent);
10
+ }
11
+
12
+ export { detectBrowser as default, detectBrowser };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @module misc/type-check
3
+ * @importTarget ./misc/type-check
4
+ * @author Hervé Perchec
5
+ */
6
+ /**
7
+ * Check type of a variable
8
+ * @param type - The type to check. Can be array of types
9
+ * @param value - The value to check
10
+ * @returns Returns true if at least one type matches
11
+ * @envCompat Browser
12
+ * @envCompat Node
13
+ * @example
14
+ * typeCheck(String, 'John Doe') // true
15
+ * typeCheck(MyCustomClass, 1) // false
16
+ * typeCheck([String, Number], '1') // true
17
+ */
18
+ export declare function typeCheck(type: any | any[], value: any): boolean;
19
+ export default typeCheck;
@@ -0,0 +1,39 @@
1
+ /*!
2
+ * juisy v3.0.0-beta.0
3
+ * Copyright © 2022-Present Hervé Perchec
4
+ */
5
+
6
+ import { isPlainObject, isArray } from '@juisy/utils/is/is';
7
+ import getConstructorName from '@juisy/utils/constructor/get-constructor-name';
8
+
9
+ const simpleCheckRE = /^(String|Number|Boolean|Function|Symbol|BigInt)$/;
10
+ function typeCheck(type, value) {
11
+ const _check = (_type) => {
12
+ let valid;
13
+ const expectedType = getConstructorName(_type);
14
+ if (simpleCheckRE.test(expectedType)) {
15
+ const t = typeof value;
16
+ valid = t === expectedType.toLowerCase();
17
+ if (!valid && t === "object") {
18
+ valid = value instanceof _type;
19
+ }
20
+ } else if (expectedType === "Object") {
21
+ valid = isPlainObject(value);
22
+ } else if (expectedType === "Array") {
23
+ valid = isArray(value);
24
+ } else {
25
+ valid = value instanceof _type;
26
+ }
27
+ return valid;
28
+ };
29
+ if (type instanceof Array) {
30
+ for (const t of type) {
31
+ if (_check(t)) return true;
32
+ }
33
+ return false;
34
+ } else {
35
+ return _check(type);
36
+ }
37
+ }
38
+
39
+ export { typeCheck as default, typeCheck };
@@ -0,0 +1,21 @@
1
+ import { default as merge } from 'deepmerge';
2
+ /**
3
+ * Deep merge two Objects/Array
4
+ *
5
+ * ::: tip See also
6
+ * [deepmerge](https://github.com/TehShrike/deepmerge) package documentation
7
+ * :::
8
+ * @function
9
+ * @param x - The source
10
+ * @param y - The target
11
+ * @param options - deepmerge options
12
+ * @returns The result of merge
13
+ * @envCompat Browser
14
+ * @envCompat Node
15
+ * @example
16
+ * const x = { foo: 'bar', quux: 1 }
17
+ * const y = { foo: 'baz', other: [] }
18
+ * deepMerge(x, y) // { foo: 'baz', quux: 1, other: [] }
19
+ */
20
+ export declare const deepMerge: typeof merge;
21
+ export default deepMerge;
@@ -0,0 +1,10 @@
1
+ /*!
2
+ * juisy v3.0.0-beta.0
3
+ * Copyright © 2022-Present Hervé Perchec
4
+ */
5
+
6
+ import merge from 'deepmerge';
7
+
8
+ const deepMerge = merge;
9
+
10
+ export { deepMerge, deepMerge as default };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @module object/deep-parse
3
+ * @importTarget ./object/deep-parse
4
+ * @author Hervé Perchec
5
+ */
6
+ /**
7
+ * The {@link deepParse} function callback type
8
+ */
9
+ export type DeepParseCallback = (key: string, value: any, parent: object) => any;
10
+ /**
11
+ * Deep parse an object or array
12
+ * @param value - The value to parse
13
+ * @param cb - The callback to execute
14
+ * @envCompat Browser
15
+ * @envCompat Node
16
+ */
17
+ export declare const deepParse: (value: any, cb: DeepParseCallback) => void;
18
+ export default deepParse;
@@ -0,0 +1,15 @@
1
+ /*!
2
+ * juisy v3.0.0-beta.0
3
+ * Copyright © 2022-Present Hervé Perchec
4
+ */
5
+
6
+ const deepParse = (value, cb) => {
7
+ if (typeof value === "object") {
8
+ for (const key in value) {
9
+ cb(key, value[key], value);
10
+ deepParse(value[key], cb);
11
+ }
12
+ }
13
+ };
14
+
15
+ export { deepParse, deepParse as default };
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @module object/get
3
+ * @importTarget ./object/get
4
+ * @author Hervé Perchec
5
+ */
6
+ /**
7
+ * Get object property (lodash.get).
8
+ *
9
+ * ::: tip See also
10
+ * [lodash.get](https://www.npmjs.com/package/lodash.get) package documentation
11
+ * :::
12
+ * @param object - The object to query
13
+ * @param path - The path of the property to get
14
+ * @param defaultValue - The value returned for undefined resolved values
15
+ * @returns Returns the target property value
16
+ * @envCompat Browser
17
+ * @envCompat Node
18
+ * @example
19
+ * const object = { 'a': [{ 'b': { 'c': 3 } }] }
20
+ * get(object, 'a[0].b.c') // 3
21
+ * get(object, 'a[0].b.d', 'default') // 'default'
22
+ */
23
+ export declare function get(object: any, path: string | string[], defaultValue?: any): any;
24
+ export default get;
@@ -0,0 +1,12 @@
1
+ /*!
2
+ * juisy v3.0.0-beta.0
3
+ * Copyright © 2022-Present Hervé Perchec
4
+ */
5
+
6
+ import lodashGet from 'lodash.get';
7
+
8
+ function get(object, path, defaultValue = void 0) {
9
+ return lodashGet(object, path, defaultValue);
10
+ }
11
+
12
+ export { get as default, get };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @module path/is-posix
3
+ * @importTarget ./path/is-posix
4
+ * @author Hervé Perchec
5
+ */
6
+ /**
7
+ * Check if the given path is posix format
8
+ * @param val - The path to check
9
+ * @envCompat Browser
10
+ * @envCompat Node
11
+ * @example
12
+ * isPosix('a/posix/path') // => true
13
+ * isPosix('C:\\a\\win32\\absolute\\path') // => false
14
+ * isPosix('a/mixed\\path') // => false
15
+ */
16
+ export declare function isPosix(val: string): boolean;
17
+ export default isPosix;
@@ -0,0 +1,12 @@
1
+ /*!
2
+ * juisy v3.0.0-beta.0
3
+ * Copyright © 2022-Present Hervé Perchec
4
+ */
5
+
6
+ import isWin32 from '@juisy/utils/path/is-win32';
7
+
8
+ function isPosix(val) {
9
+ return !isWin32(val);
10
+ }
11
+
12
+ export { isPosix as default, isPosix };
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @module path/is-same-as
3
+ * @importTarget ./path/is-same-as
4
+ * @author Hervé Perchec
5
+ */
6
+ /**
7
+ * Util function to compare two file paths
8
+ * @param a - The first file path to compare
9
+ * @param b - The second file path to compare
10
+ * @returns True if the two paths are the same
11
+ * @envCompat Node
12
+ * @example
13
+ * isSameAs('src/index.ts', 'src\\index.ts') // true
14
+ * isSameAs('../src/index.ts', '..\\src\\index.ts') // true
15
+ * isSameAs('C:\\a\\Win32\\Absolute\\path\\', 'c:/a/Win32/Absolute/path') // true
16
+ * isSameAs('C:\\a\\Win32\\Absolute\\path\\', '/a/Win32/Absolute/path')// false
17
+ * isSameAs('/a/posix/absolute/path', '/a/posix/absolute/path/../../absolute/path') // true
18
+ * isSameAs('/a/posix/absolute/path', '/a/Posix/Absolute/path') // false
19
+ */
20
+ export declare function isSameAs(a: string, b: string): boolean;
21
+ export default isSameAs;
@@ -0,0 +1,13 @@
1
+ /*!
2
+ * juisy v3.0.0-beta.0
3
+ * Copyright © 2022-Present Hervé Perchec
4
+ */
5
+
6
+ import normalize from '@juisy/utils/path/normalize';
7
+ import toPosix from '@juisy/utils/path/to-posix';
8
+
9
+ function isSameAs(a, b) {
10
+ return normalize(toPosix(a)) === normalize(toPosix(b));
11
+ }
12
+
13
+ export { isSameAs as default, isSameAs };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @module path/is-win32
3
+ * @importTarget ./path/is-win32
4
+ * @author Hervé Perchec
5
+ */
6
+ /**
7
+ * Check if the given path is win32 format
8
+ * @param val - The path to check
9
+ * @envCompat Browser
10
+ * @envCompat Node
11
+ * @example
12
+ * isWin32('a/posix/path') // => false
13
+ * isWin32('C:\\a\\win32\\absolute\\path') // => true
14
+ * isWin32('a/mixed\\path') // => true
15
+ */
16
+ export declare function isWin32(val: string): boolean;
17
+ export default isWin32;
@@ -0,0 +1,10 @@
1
+ /*!
2
+ * juisy v3.0.0-beta.0
3
+ * Copyright © 2022-Present Hervé Perchec
4
+ */
5
+
6
+ function isWin32(val) {
7
+ return /^[a-zA-Z]:/.test(val) || val.includes("\\");
8
+ }
9
+
10
+ export { isWin32 as default, isWin32 };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @module path/normalize
3
+ * @importTarget ./path/normalize
4
+ * @author Hervé Perchec
5
+ */
6
+ /**
7
+ * Normalize a path depending on base format
8
+ * @param val - The path to normalize
9
+ * @envCompat Node
10
+ * @example
11
+ * normalize('a/Posix/path') // => 'a/Posix/path'
12
+ * normalize('C:\\a\\Win32\\Absolute\\path\\') // => 'c:\a\win32\absolute\path'
13
+ * normalize('a/Mixed\\Path') // => 'a\mixed\path'
14
+ */
15
+ export declare function normalize(val: string): string;
16
+ export default normalize;
@@ -0,0 +1,22 @@
1
+ /*!
2
+ * juisy v3.0.0-beta.0
3
+ * Copyright © 2022-Present Hervé Perchec
4
+ */
5
+
6
+ import path from 'node:path';
7
+ import isWin32 from '@juisy/utils/path/is-win32';
8
+
9
+ function normalize(val) {
10
+ let normalized;
11
+ if (isWin32(val)) {
12
+ normalized = path.win32.normalize(val).toLowerCase();
13
+ } else {
14
+ normalized = path.posix.normalize(val);
15
+ }
16
+ if ((normalized.endsWith("/") || normalized.endsWith("\\")) && normalized.length > 1) {
17
+ normalized = normalized.slice(0, -1);
18
+ }
19
+ return normalized;
20
+ }
21
+
22
+ export { normalize as default, normalize };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @module path/resolve-abs-from-root
3
+ * @importTarget ./path/resolve-abs-from-root
4
+ * @author Hervé Perchec
5
+ */
6
+ /**
7
+ * Util to resolve absolute file path from root directory
8
+ * @param to - The relative file path
9
+ * @param separator - (Optional) The separator type: can be `"posix"` or `"win32"`
10
+ * @returns The resolved absolute path from root directory
11
+ * @envCompat Node
12
+ */
13
+ export declare function resolveAbsFromRoot(to: string, separator?: 'posix' | 'win32'): string;
14
+ export default resolveAbsFromRoot;
@@ -0,0 +1,17 @@
1
+ /*!
2
+ * juisy v3.0.0-beta.0
3
+ * Copyright © 2022-Present Hervé Perchec
4
+ */
5
+
6
+ import path from 'node:path';
7
+ import getRootDir from '@juisy/utils/fs/get-root-dir';
8
+ import toPosix from '@juisy/utils/path/to-posix';
9
+ import toWin32 from '@juisy/utils/path/to-win32';
10
+ import toOsFormat from '@juisy/utils/path/to-os-format';
11
+
12
+ function resolveAbsFromRoot(to, separator) {
13
+ const absolutePath = path.join(getRootDir(), to);
14
+ return separator ? separator === "posix" ? toPosix(absolutePath) : toWin32(absolutePath) : toOsFormat(absolutePath);
15
+ }
16
+
17
+ export { resolveAbsFromRoot as default, resolveAbsFromRoot };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @module path/resolve-rel-from-root
3
+ * @importTarget ./path/resolve-rel-from-root
4
+ * @author Hervé Perchec
5
+ */
6
+ /**
7
+ * Util to resolve relative file path from root directory
8
+ * @param to - The absolute file path
9
+ * @param separator - (Optional) The separator type: can be `"posix"` or `"win32"`
10
+ * @returns The resolved relative path from root directory
11
+ * @envCompat Node
12
+ */
13
+ export declare function resolveRelFromRoot(to: string, separator?: 'posix' | 'win32'): string;
14
+ export default resolveRelFromRoot;
@@ -0,0 +1,13 @@
1
+ /*!
2
+ * juisy v3.0.0-beta.0
3
+ * Copyright © 2022-Present Hervé Perchec
4
+ */
5
+
6
+ import resolveRel from '@juisy/utils/path/resolve-rel';
7
+ import getRootDir from '@juisy/utils/fs/get-root-dir';
8
+
9
+ function resolveRelFromRoot(to, separator) {
10
+ return resolveRel(getRootDir(), to, separator);
11
+ }
12
+
13
+ export { resolveRelFromRoot as default, resolveRelFromRoot };
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @module path/resolve-rel
3
+ * @importTarget ./path/resolve-rel
4
+ * @author Hervé Perchec
5
+ */
6
+ /**
7
+ * Util to resolve a relative file path
8
+ * @param from - The "from" absolute file path
9
+ * @param to - The "to" absolute file path
10
+ * @param separator - (Optional) The separator type: can be `"posix"` or `"win32"`
11
+ * @returns The resolved relative path
12
+ * @envCompat Node
13
+ * @example
14
+ * const base = 'C:\\Users\\JohnDoe\\Documents\\Projects\\MyProject'
15
+ *
16
+ * resolveRel(base, 'C:\\Users\\JohnDoe\\Documents\\Projects\\MyProject\\src\\index.ts') // 'src\\index.ts'
17
+ * resolveRel('C:\\Users\\JohnDoe\\Documents\\Projects\\MyProject\\src\\index.ts', base) // '..\\..'
18
+ * resolveRel(base, 'C:\\Users\\JohnDoe\\Documents\\Projects\\MyProject\\src\\index.ts', 'posix') // 'src/index.ts'
19
+ */
20
+ export declare function resolveRel(from: string, to: string, separator?: 'posix' | 'win32'): string;
21
+ export default resolveRel;
@@ -0,0 +1,16 @@
1
+ /*!
2
+ * juisy v3.0.0-beta.0
3
+ * Copyright © 2022-Present Hervé Perchec
4
+ */
5
+
6
+ import path from 'node:path';
7
+ import toPosix from '@juisy/utils/path/to-posix';
8
+ import toWin32 from '@juisy/utils/path/to-win32';
9
+ import toOsFormat from '@juisy/utils/path/to-os-format';
10
+
11
+ function resolveRel(from, to, separator) {
12
+ const relativePath = path.relative(from, to);
13
+ return separator ? separator === "posix" ? toPosix(relativePath) : toWin32(relativePath) : toOsFormat(relativePath);
14
+ }
15
+
16
+ export { resolveRel as default, resolveRel };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @module path/to-os-format
3
+ * @importTarget ./path/to-os-format
4
+ * @author Hervé Perchec
5
+ */
6
+ /**
7
+ * Automatically convert a path to OS specific format
8
+ * @param val - The path to convert
9
+ * @envCompat Node
10
+ */
11
+ export declare function toOsFormat(val: string): string;
12
+ export default toOsFormat;
@@ -0,0 +1,14 @@
1
+ /*!
2
+ * juisy v3.0.0-beta.0
3
+ * Copyright © 2022-Present Hervé Perchec
4
+ */
5
+
6
+ import toWin32 from '@juisy/utils/path/to-win32';
7
+ import toPosix from '@juisy/utils/path/to-posix';
8
+
9
+ function toOsFormat(val) {
10
+ const platform = process.platform;
11
+ return platform === "win32" ? toWin32(val) : toPosix(val);
12
+ }
13
+
14
+ export { toOsFormat as default, toOsFormat };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @module path/to-posix
3
+ * @importTarget ./path/to-posix
4
+ * @author Hervé Perchec
5
+ */
6
+ /**
7
+ * Convert a path to posix format (with `/` separator)
8
+ * @param val - The path to convert
9
+ * @envCompat Node
10
+ * @example
11
+ * toPosix('a/posix/path') // 'a/posix/path'
12
+ * toPosix('C:\\a\\win32\\absolute\\path') // 'C:/a/win32/absolute/path'
13
+ * toPosix('a/mixed\\path') // 'a/mixed/path'
14
+ */
15
+ export declare function toPosix(val: string): string;
16
+ export default toPosix;
@@ -0,0 +1,12 @@
1
+ /*!
2
+ * juisy v3.0.0-beta.0
3
+ * Copyright © 2022-Present Hervé Perchec
4
+ */
5
+
6
+ import path from 'node:path';
7
+
8
+ function toPosix(val) {
9
+ return val.split(path.win32.sep).join(path.posix.sep);
10
+ }
11
+
12
+ export { toPosix as default, toPosix };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @module path/to-win32
3
+ * @importTarget ./path/to-win32
4
+ * @author Hervé Perchec
5
+ */
6
+ /**
7
+ * Convert a path to win32 format (with `\\` separator)
8
+ * @param val - The path to convert
9
+ * @envCompat Node
10
+ * @example
11
+ * toWin32('a/posix/path') // => 'a\posix\path'
12
+ * toWin32('C:\\a\\win32\\absolute\\path') // => 'C:\a\win32\absolute\path'
13
+ * toWin32('a/mixed\\path') // => 'a\mixed\path'
14
+ */
15
+ export declare function toWin32(val: string): string;
16
+ export default toWin32;
@@ -0,0 +1,12 @@
1
+ /*!
2
+ * juisy v3.0.0-beta.0
3
+ * Copyright © 2022-Present Hervé Perchec
4
+ */
5
+
6
+ import path from 'node:path';
7
+
8
+ function toWin32(val) {
9
+ return val.split(path.posix.sep).join(path.win32.sep);
10
+ }
11
+
12
+ export { toWin32 as default, toWin32 };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @module random/random-alpha-numeric
3
+ * @importTarget ./random/random-alpha-numeric
4
+ * @author Hervé Perchec
5
+ */
6
+ /**
7
+ * Generate random alphanumeric string based on lodash.samplesize function.
8
+ *
9
+ * ::: tip See also
10
+ * [lodash.samplesize](https://www.npmjs.com/package/lodash.samplesize) package documentation
11
+ * :::
12
+ * @param length - The length of returned random string
13
+ * @param charset - An array or string of characters
14
+ * @returns The created random string
15
+ * @envCompat Browser
16
+ * @envCompat Node
17
+ * @example
18
+ * randomAlphaNumeric(5) // => 'Gy85f'
19
+ * randomAlphaNumeric(5, 'ABCDE') // => 'AADBE'
20
+ */
21
+ export declare function randomAlphaNumeric(length: number, charset?: string | string[]): string;
22
+ export default randomAlphaNumeric;
@@ -0,0 +1,12 @@
1
+ /*!
2
+ * juisy v3.0.0-beta.0
3
+ * Copyright © 2022-Present Hervé Perchec
4
+ */
5
+
6
+ import samplesize from 'lodash.samplesize';
7
+
8
+ function randomAlphaNumeric(length, charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") {
9
+ return samplesize(charset, length).join("");
10
+ }
11
+
12
+ export { randomAlphaNumeric as default, randomAlphaNumeric };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @module random/random-number
3
+ * @importTarget ./random/random-number
4
+ * @author Hervé Perchec
5
+ */
6
+ /**
7
+ * Generate random number based on lodash.random function.
8
+ *
9
+ * ::: tip See also
10
+ * [lodash.random](https://www.npmjs.com/package/lodash.random) package documentation
11
+ * :::
12
+ * @param lower - The lower value
13
+ * @param upper - The upper value
14
+ * @param floating - If uses float numbers
15
+ * @returns The random number
16
+ * @envCompat Browser
17
+ * @envCompat Node
18
+ * @example
19
+ * randomNumber(0, 5) // 1
20
+ * randomNumber(0, 5, true) // 2.6
21
+ */
22
+ export declare function randomNumber(lower: number, upper: number, floating?: boolean): number;
23
+ export default randomNumber;
@@ -0,0 +1,12 @@
1
+ /*!
2
+ * juisy v3.0.0-beta.0
3
+ * Copyright © 2022-Present Hervé Perchec
4
+ */
5
+
6
+ import lodashRandom from 'lodash.random';
7
+
8
+ function randomNumber(lower, upper, floating) {
9
+ return lodashRandom(lower, upper, floating);
10
+ }
11
+
12
+ export { randomNumber as default, randomNumber };