@juisy/utils 3.0.0-beta.2 → 3.0.0-beta.4
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/LICENSE +661 -661
- package/README.md +12 -10
- package/dist/assert/argsert.d.ts +23 -5
- package/dist/assert/argsert.js +50 -3
- package/dist/assert/assert.d.ts +31 -0
- package/dist/assert/assert.js +32 -2
- package/dist/blob/to-data-url.d.ts +14 -0
- package/dist/blob/to-data-url.js +23 -0
- package/dist/constructor/apply-mixins.js +1 -1
- package/dist/constructor/get-constructor-name.js +1 -1
- package/dist/date/date-format.d.ts +1 -1
- package/dist/date/date-format.js +3 -3
- package/dist/date/get-date-range.d.ts +1 -1
- package/dist/date/get-date-range.js +4 -4
- package/dist/date/get-duration-between-times.d.ts +2 -2
- package/dist/date/get-duration-between-times.js +4 -4
- package/dist/date/get-duration-between.d.ts +2 -2
- package/dist/date/get-duration-between.js +3 -3
- package/dist/date/get-i18n-timezone-value.d.ts +1 -1
- package/dist/date/get-i18n-timezone-value.js +2 -2
- package/dist/date/get-next-date-for-time.d.ts +1 -1
- package/dist/date/get-next-date-for-time.js +3 -3
- package/dist/date/get-utc-offset.d.ts +1 -1
- package/dist/date/get-utc-offset.js +3 -3
- package/dist/fs/get-file-urls.js +5 -3
- package/dist/fs/get-files-sync.js +1 -1
- package/dist/fs/get-files.js +1 -1
- package/dist/fs/get-root-dir.js +1 -1
- package/dist/fs/is-directory.js +1 -1
- package/dist/fs/is-file.js +1 -1
- package/dist/is/is-def.js +1 -1
- package/dist/is/is-valid-css-color.js +1 -1
- package/dist/is/is.js +1 -1
- package/dist/json/compile-pointer.d.ts +8 -5
- package/dist/json/compile-pointer.js +4 -3
- package/dist/json/escape-pointer-segment.d.ts +5 -1
- package/dist/json/escape-pointer-segment.js +1 -1
- package/dist/json/get-by-pointer.js +1 -1
- package/dist/json/has-value.js +1 -1
- package/dist/json/parse-pointer.d.ts +8 -5
- package/dist/json/parse-pointer.js +2 -2
- package/dist/json/remove-by-pointer.js +1 -1
- package/dist/json/set-by-pointer.js +1 -1
- package/dist/json/to-pointers-dictionary.js +1 -1
- package/dist/json/traverse.js +1 -1
- package/dist/json/unescape-pointer-segment.d.ts +5 -1
- package/dist/json/unescape-pointer-segment.js +1 -1
- package/dist/misc/compose.js +1 -1
- package/dist/misc/detect-browser.js +1 -1
- package/dist/misc/get-aspect-ratio.d.ts +18 -0
- package/dist/misc/get-aspect-ratio.js +13 -0
- package/dist/misc/type-check.js +1 -1
- package/dist/number/get-greatest-common-divider.d.ts +17 -0
- package/dist/number/get-greatest-common-divider.js +17 -0
- package/dist/number/get-least-common-multiple.d.ts +16 -0
- package/dist/number/get-least-common-multiple.js +19 -0
- package/dist/object/deep-merge.js +1 -1
- package/dist/object/deep-parse.js +1 -1
- package/dist/object/get.js +1 -1
- package/dist/path/is-absolute.d.ts +19 -0
- package/dist/path/is-absolute.js +13 -0
- package/dist/path/is-invalid.d.ts +42 -0
- package/dist/path/is-invalid.js +23 -0
- package/dist/path/is-posix.js +1 -1
- package/dist/path/is-relative.d.ts +19 -0
- package/dist/path/is-relative.js +12 -0
- package/dist/path/is-same-as.d.ts +1 -0
- package/dist/path/is-same-as.js +1 -1
- package/dist/path/is-valid.d.ts +16 -0
- package/dist/path/is-valid.js +12 -0
- package/dist/path/is-win32.js +1 -1
- package/dist/path/normalize.d.ts +1 -0
- package/dist/path/normalize.js +2 -2
- package/dist/path/resolve-abs-from-root.js +2 -2
- package/dist/path/resolve-rel-from-root.js +1 -1
- package/dist/path/resolve-rel.d.ts +1 -0
- package/dist/path/resolve-rel.js +4 -3
- package/dist/path/strip-extension.d.ts +1 -0
- package/dist/path/strip-extension.js +2 -2
- package/dist/path/to-os-format.d.ts +1 -0
- package/dist/path/to-os-format.js +2 -2
- package/dist/path/to-posix.d.ts +1 -0
- package/dist/path/to-posix.js +2 -2
- package/dist/path/to-win32.d.ts +1 -0
- package/dist/path/to-win32.js +2 -2
- package/dist/random/random-alpha-numeric.js +7 -2
- package/dist/random/random-number.js +1 -1
- package/dist/string/camelcase.js +1 -1
- package/dist/string/capitalize.js +1 -1
- package/dist/string/constantcase.d.ts +4 -4
- package/dist/string/constantcase.js +1 -1
- package/dist/string/kebabcase.js +1 -1
- package/dist/string/lowercase.js +1 -1
- package/dist/string/pascalcase.js +1 -1
- package/dist/string/snakecase.js +1 -1
- package/dist/string/uppercase.js +1 -1
- package/package.json +23 -5
- package/skills/juisy-utils/SKILL.md +55 -0
- package/skills/juisy-utils/references/deep-imports.md +38 -0
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* juisy v3.0.0-beta.
|
|
2
|
+
* juisy v3.0.0-beta.4
|
|
3
3
|
* Copyright © 2022-Present Hervé Perchec
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import argsert from '@juisy/utils/assert/argsert';
|
|
7
|
-
import escapePointerSegment from '@juisy/utils/json/escape-pointer-segment';
|
|
7
|
+
import { escapePointerSegment } from '@juisy/utils/json/escape-pointer-segment';
|
|
8
8
|
|
|
9
|
-
function compilePointer(segments, hash
|
|
9
|
+
function compilePointer(segments, hash) {
|
|
10
10
|
argsert(segments, "segments", [
|
|
11
11
|
argsert.array.ofType(argsert.any(argsert.string.nonBlank, argsert.number))
|
|
12
12
|
]);
|
|
13
|
+
if (typeof hash === "undefined") hash = false;
|
|
13
14
|
argsert(hash, "hash", ["boolean"]);
|
|
14
15
|
return `${hash ? "#" : ""}/${segments.map(String).map(escapePointerSegment).join("/")}`;
|
|
15
16
|
}
|
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
* @remarks Code widely inspired from [json-pointer](https://www.npmjs.com/package/json-pointer) library
|
|
5
5
|
* @author Hervé Perchec
|
|
6
6
|
*/
|
|
7
|
+
/**
|
|
8
|
+
* Escape a pointer segment in compliance with [RFC 6901](https://datatracker.ietf.org/doc/html/rfc6901#section-3)
|
|
9
|
+
*/
|
|
10
|
+
export type EscapePointerSegment<S extends string> = S extends `${infer Head}~${infer Tail}` ? `${Head}~0${EscapePointerSegment<Tail>}` : S extends `${infer Head}/${infer Tail}` ? `${Head}~1${EscapePointerSegment<Tail>}` : S;
|
|
7
11
|
/**
|
|
8
12
|
* Escapes a pointer segment in compliance with [RFC 6901](https://datatracker.ietf.org/doc/html/rfc6901#section-3).
|
|
9
13
|
* It replaces `/` & `~` by `~1` & `~0`.
|
|
@@ -14,5 +18,5 @@
|
|
|
14
18
|
* escapePointerSegment('a~b') // 'a~0b'
|
|
15
19
|
* escapePointerSegment('b/c') // 'b~1c'
|
|
16
20
|
*/
|
|
17
|
-
export declare function escapePointerSegment(unsafeString:
|
|
21
|
+
export declare function escapePointerSegment<S extends string>(unsafeString: S): EscapePointerSegment<S>;
|
|
18
22
|
export default escapePointerSegment;
|
package/dist/json/has-value.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { UnescapePointerSegment } from './unescape-pointer-segment';
|
|
2
|
+
type Trim<S extends string> = S extends ` ${infer Rest}` | `${infer Rest} ` ? Trim<Rest> : S;
|
|
3
|
+
type IsValidPointerSyntax<P extends string> = Trim<P> extends '' ? false : P extends `${string}//${string}` ? false : P extends `/${string}` | `#/${string}` ? true : false;
|
|
4
|
+
type StripPrefix<P extends string> = P extends `#/${infer Tail}` ? Tail : P extends `/${infer Tail}` ? Tail : P;
|
|
5
|
+
type ParsePointerSegments<P extends string> = P extends '' ? [] : P extends `${infer Head}/${infer Tail}` ? [UnescapePointerSegment<Head>, ...ParsePointerSegments<Tail>] : [UnescapePointerSegment<P>];
|
|
1
6
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @importTarget ./json/parse-pointer
|
|
4
|
-
* @remarks Code widely inspired from [json-pointer](https://www.npmjs.com/package/json-pointer) library
|
|
5
|
-
* @author Hervé Perchec
|
|
7
|
+
* Resolves segments from JSON pointer
|
|
6
8
|
*/
|
|
9
|
+
export type SegmentsFromJsonPointer<P extends string> = string extends P ? string[] : IsValidPointerSyntax<P> extends true ? ParsePointerSegments<StripPrefix<P>> : never;
|
|
7
10
|
/**
|
|
8
11
|
* Class for invalid JSON pointer error
|
|
9
12
|
*/
|
|
@@ -21,5 +24,5 @@ export declare class InvalidJSONPointerError extends Error {
|
|
|
21
24
|
* parsePointer('#/a/0/b~0c') // [ 'a', '0', 'b~c' ]
|
|
22
25
|
* parsePointer('a/0') // Error
|
|
23
26
|
*/
|
|
24
|
-
export declare function parsePointer(pointer:
|
|
27
|
+
export declare function parsePointer<const P extends string>(pointer: P): SegmentsFromJsonPointer<P>;
|
|
25
28
|
export default parsePointer;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* juisy v3.0.0-beta.
|
|
2
|
+
* juisy v3.0.0-beta.4
|
|
3
3
|
* Copyright © 2022-Present Hervé Perchec
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import argsert from '@juisy/utils/assert/argsert';
|
|
7
|
-
import unescapePointerSegment from '@juisy/utils/json/unescape-pointer-segment';
|
|
7
|
+
import { unescapePointerSegment } from '@juisy/utils/json/unescape-pointer-segment';
|
|
8
8
|
|
|
9
9
|
class InvalidJSONPointerError extends Error {
|
|
10
10
|
}
|
package/dist/json/traverse.js
CHANGED
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
* @remarks Code widely inspired from [json-pointer](https://www.npmjs.com/package/json-pointer) library
|
|
5
5
|
* @author Hervé Perchec
|
|
6
6
|
*/
|
|
7
|
+
/**
|
|
8
|
+
* Unescape a pointer segment in compliance with [RFC 6901](https://datatracker.ietf.org/doc/html/rfc6901#section-3)
|
|
9
|
+
*/
|
|
10
|
+
export type UnescapePointerSegment<S extends string> = S extends `${infer Head}~1${infer Tail}` ? `${UnescapePointerSegment<Head>}/${UnescapePointerSegment<Tail>}` : S extends `${infer Head}~0${infer Tail}` ? `${UnescapePointerSegment<Head>}~${UnescapePointerSegment<Tail>}` : S;
|
|
7
11
|
/**
|
|
8
12
|
* Unescapes a pointer segment in compliance with [RFC 6901](https://datatracker.ietf.org/doc/html/rfc6901#section-3).
|
|
9
13
|
* It replaces `~1` & `~0` by `/` & `~`.
|
|
@@ -14,5 +18,5 @@
|
|
|
14
18
|
* unescapePointerSegment('a~0b') // 'a~b'
|
|
15
19
|
* unescapePointerSegment('b~1c') // 'b/c'
|
|
16
20
|
*/
|
|
17
|
-
export declare function unescapePointerSegment(escaped:
|
|
21
|
+
export declare function unescapePointerSegment<S extends string>(escaped: S): UnescapePointerSegment<S>;
|
|
18
22
|
export default unescapePointerSegment;
|
package/dist/misc/compose.js
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module misc/get-aspect-ratio
|
|
3
|
+
* @importTarget ./misc/get-aspect-ratio
|
|
4
|
+
* @author Hervé Perchec
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Get the aspect ratio for the given width and height
|
|
8
|
+
* @param width - The width
|
|
9
|
+
* @param height - The height
|
|
10
|
+
* @envCompat Browser
|
|
11
|
+
* @envCompat Node
|
|
12
|
+
* @example
|
|
13
|
+
* getAspectRatio(1024, 768) // '4:3'
|
|
14
|
+
* getAspectRatio(1920, 1080) // '16:9'
|
|
15
|
+
* getAspectRatio(1080, 1920) // '9:16'
|
|
16
|
+
*/
|
|
17
|
+
export declare function getAspectRatio(width: number, height: number): string;
|
|
18
|
+
export default getAspectRatio;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* juisy v3.0.0-beta.4
|
|
3
|
+
* Copyright © 2022-Present Hervé Perchec
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import getGCD from '@juisy/utils/number/get-greatest-common-divider';
|
|
7
|
+
|
|
8
|
+
function getAspectRatio(width, height) {
|
|
9
|
+
const gcd = getGCD(width, height);
|
|
10
|
+
return `${width / gcd}:${height / gcd}`;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { getAspectRatio as default, getAspectRatio };
|
package/dist/misc/type-check.js
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module number/get-greatest-common-divider
|
|
3
|
+
* @importTarget ./number/get-greatest-common-divider
|
|
4
|
+
* @author Hervé Perchec
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Get the GCD (Greatest Common Divider) of the given integers
|
|
8
|
+
* @envCompat Browser
|
|
9
|
+
* @envCompat Node
|
|
10
|
+
* @example
|
|
11
|
+
* getGreatestCommonDivider(4, 2) // 2
|
|
12
|
+
* getGreatestCommonDivider(48, 18, 30) // 6
|
|
13
|
+
* getGreatestCommonDivider(100, 50, 25, 10) // 5
|
|
14
|
+
* getGreatestCommonDivider(12, 18, 24, 36, 48) // 6
|
|
15
|
+
*/
|
|
16
|
+
export declare function getGreatestCommonDivider(...numbers: number[]): number;
|
|
17
|
+
export default getGreatestCommonDivider;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* juisy v3.0.0-beta.4
|
|
3
|
+
* Copyright © 2022-Present Hervé Perchec
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import argsert from '@juisy/utils/assert/argsert';
|
|
7
|
+
|
|
8
|
+
function getGreatestCommonDivider(...numbers) {
|
|
9
|
+
if (numbers.length === 0) return 0;
|
|
10
|
+
argsert(numbers, `...numbers`, [argsert.array.ofType(argsert.number.integer)]);
|
|
11
|
+
const getGCD = (a, b) => b === 0 ? a : getGCD(b, a % b);
|
|
12
|
+
return numbers.reduce((accumulator, currentValue) => {
|
|
13
|
+
return getGCD(Math.abs(accumulator), Math.abs(currentValue));
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { getGreatestCommonDivider as default, getGreatestCommonDivider };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module number/get-least-common-multiple
|
|
3
|
+
* @importTarget ./number/get-least-common-multiple
|
|
4
|
+
* @author Hervé Perchec
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Get the LCM (Least Common Multiple) of the given integers
|
|
8
|
+
* @envCompat Browser
|
|
9
|
+
* @envCompat Node
|
|
10
|
+
* @example
|
|
11
|
+
* getLeastCommonMultiple(4, 5) // 20
|
|
12
|
+
* getLeastCommonMultiple(12, 15, 10) // 60
|
|
13
|
+
* getLeastCommonMultiple(3, 4, 5, 6) // 60
|
|
14
|
+
*/
|
|
15
|
+
export declare function getLeastCommonMultiple(...numbers: number[]): number;
|
|
16
|
+
export default getLeastCommonMultiple;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* juisy v3.0.0-beta.4
|
|
3
|
+
* Copyright © 2022-Present Hervé Perchec
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import getGCD from '@juisy/utils/number/get-greatest-common-divider';
|
|
7
|
+
|
|
8
|
+
function getLeastCommonMultiple(...numbers) {
|
|
9
|
+
if (numbers.length === 0) return 0;
|
|
10
|
+
const getLCM = (a, b) => {
|
|
11
|
+
if (a === 0 || b === 0) return 0;
|
|
12
|
+
return Math.abs(a * b) / getGCD(a, b);
|
|
13
|
+
};
|
|
14
|
+
return numbers.reduce((accumulator, currentValue) => {
|
|
15
|
+
return getLCM(accumulator, currentValue);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { getLeastCommonMultiple as default, getLeastCommonMultiple };
|
package/dist/object/get.js
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module path/is-absolute
|
|
3
|
+
* @importTarget ./path/is-absolute
|
|
4
|
+
* @author Hervé Perchec
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Check if the given path is absolute
|
|
8
|
+
* @param val - The path to check
|
|
9
|
+
* @envCompat Browser
|
|
10
|
+
* @envCompat Node
|
|
11
|
+
* @example
|
|
12
|
+
* isAbsolute('C:\\a\\win32\\absolute\\path') // true
|
|
13
|
+
* isAbsolute('/a/posix/absolute/path') // true
|
|
14
|
+
* isAbsolute('/a/mixed\\absolute/path') // true
|
|
15
|
+
* isAbsolute('..\\a\\relative\\..\\win32\\path') // false
|
|
16
|
+
* isAbsolute('../a/relative/../posix/path') // false
|
|
17
|
+
*/
|
|
18
|
+
export declare function isAbsolute(val: string): boolean;
|
|
19
|
+
export default isAbsolute;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* juisy v3.0.0-beta.4
|
|
3
|
+
* Copyright © 2022-Present Hervé Perchec
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import * as path from 'path-unified';
|
|
7
|
+
import isWin32 from '@juisy/utils/path/is-win32';
|
|
8
|
+
|
|
9
|
+
function isAbsolute(val) {
|
|
10
|
+
return isWin32(val) ? path.win32.isAbsolute(val) : path.posix.isAbsolute(val);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { isAbsolute as default, isAbsolute };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module path/is-invalid
|
|
3
|
+
* @importTarget ./path/is-invalid
|
|
4
|
+
* @remarks Implementation of [https://www.npmjs.com/package/is-invalid-path](https://www.npmjs.com/package/https://www.npmjs.com/package/is-invalid-path)
|
|
5
|
+
* library (by Jon Schlinkert) to work in Browser environment
|
|
6
|
+
* @author Hervé Perchec
|
|
7
|
+
*/
|
|
8
|
+
export interface IsInvalidOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Force the given path to be treated as Windows path.
|
|
11
|
+
* Default `false`.
|
|
12
|
+
*/
|
|
13
|
+
windows?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Allow Windows extended path length (32767).
|
|
16
|
+
* Default `false` (260).
|
|
17
|
+
*
|
|
18
|
+
* See also https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#maximum-path-length-limitation.
|
|
19
|
+
*/
|
|
20
|
+
winExtended?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Treat the given path as a filename, so returns `true`
|
|
23
|
+
* if the path has slashes or backslashes.
|
|
24
|
+
*/
|
|
25
|
+
file?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Returns `true` if the given string is invalid path.
|
|
29
|
+
* E.g. if the path has slashes and `options.file` is `true`,
|
|
30
|
+
* as slashes and backslashes are invalid in file names.
|
|
31
|
+
* @param val - The path to check
|
|
32
|
+
* @param options - {@link IsInvalidOptions}
|
|
33
|
+
* @envCompat Browser
|
|
34
|
+
* @envCompat Node
|
|
35
|
+
* @example
|
|
36
|
+
* isInvalid('a/posix/"invalid"/path') // true
|
|
37
|
+
* isInvalid('a/posix/invalid/filename', { file: true }) // true
|
|
38
|
+
* isInvalid('C:\\a\\win32\\valid\\path') // false
|
|
39
|
+
* isInvalid('a/mixed\\path') // false
|
|
40
|
+
*/
|
|
41
|
+
export declare function isInvalid(val: string, options?: IsInvalidOptions): boolean;
|
|
42
|
+
export default isInvalid;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* juisy v3.0.0-beta.4
|
|
3
|
+
* Copyright © 2022-Present Hervé Perchec
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import * as path from 'path-unified';
|
|
7
|
+
import isWin32 from '@juisy/utils/path/is-win32';
|
|
8
|
+
|
|
9
|
+
function isInvalid(val, options = {}) {
|
|
10
|
+
if (typeof val !== "string" || !val.trim().length) return true;
|
|
11
|
+
if (options.windows || isWin32(val)) {
|
|
12
|
+
const MAX_PATH = options.winExtended ? 32767 : 260;
|
|
13
|
+
if (val.length > MAX_PATH - 12) return true;
|
|
14
|
+
}
|
|
15
|
+
const rootPath = isWin32(val) ? val.match(/^[a-zA-Z]:/)?.[0] : path.parse(val).root;
|
|
16
|
+
if (rootPath) val = val.slice(rootPath.length);
|
|
17
|
+
if (options.file) {
|
|
18
|
+
return /[<>:"/\\|?*]/.test(val);
|
|
19
|
+
}
|
|
20
|
+
return /[<>:"|?*]/.test(val);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { isInvalid as default, isInvalid };
|
package/dist/path/is-posix.js
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module path/is-relative
|
|
3
|
+
* @importTarget ./path/is-relative
|
|
4
|
+
* @author Hervé Perchec
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Check if the given path is relative
|
|
8
|
+
* @param val - The path to check
|
|
9
|
+
* @envCompat Browser
|
|
10
|
+
* @envCompat Node
|
|
11
|
+
* @example
|
|
12
|
+
* isRelative('a/relative/posix/path') // true
|
|
13
|
+
* isRelative('..\\a\\relative\\..\\win32\\path') // true
|
|
14
|
+
* isRelative('../a/relative/../posix/path') // true
|
|
15
|
+
* isRelative('C:\\a\\win32\\absolute\\path') // false
|
|
16
|
+
* isRelative('/a/posix/absolute/path') // false
|
|
17
|
+
*/
|
|
18
|
+
export declare function isRelative(val: string): boolean;
|
|
19
|
+
export default isRelative;
|
package/dist/path/is-same-as.js
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IsInvalidOptions } from './is-invalid';
|
|
2
|
+
/**
|
|
3
|
+
* Returns `true` if the given string is valid path.
|
|
4
|
+
* Takes same options as {@link isInvalid}.
|
|
5
|
+
* @param val - The path to check
|
|
6
|
+
* @param options - {@link IsInvalidOptions}
|
|
7
|
+
* @envCompat Browser
|
|
8
|
+
* @envCompat Node
|
|
9
|
+
* @example
|
|
10
|
+
* isValid('C:\\a\\win32\\valid\\path') // true
|
|
11
|
+
* isValid('a/mixed\\path') // true
|
|
12
|
+
* isValid('a/posix/"invalid"/path') // false
|
|
13
|
+
* isValid('a/posix/invalid/filename', { file: true }) // false
|
|
14
|
+
*/
|
|
15
|
+
export declare function isValid(val: string, options?: IsInvalidOptions): boolean;
|
|
16
|
+
export default isValid;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* juisy v3.0.0-beta.4
|
|
3
|
+
* Copyright © 2022-Present Hervé Perchec
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { isInvalid } from '@juisy/utils/path/is-invalid';
|
|
7
|
+
|
|
8
|
+
function isValid(val, options) {
|
|
9
|
+
return !isInvalid(val, options);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { isValid as default, isValid };
|
package/dist/path/is-win32.js
CHANGED
package/dist/path/normalize.d.ts
CHANGED
package/dist/path/normalize.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* juisy v3.0.0-beta.
|
|
2
|
+
* juisy v3.0.0-beta.4
|
|
3
3
|
* Copyright © 2022-Present Hervé Perchec
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import path from '
|
|
6
|
+
import * as path from 'path-unified';
|
|
7
7
|
import getRootDir from '@juisy/utils/fs/get-root-dir';
|
|
8
8
|
import toPosix from '@juisy/utils/path/to-posix';
|
|
9
9
|
import toWin32 from '@juisy/utils/path/to-win32';
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* @param to - The "to" absolute file path
|
|
10
10
|
* @param separator - (Optional) The separator type: can be `"posix"` or `"win32"`
|
|
11
11
|
* @returns The resolved relative path
|
|
12
|
+
* @envCompat Browser
|
|
12
13
|
* @envCompat Node
|
|
13
14
|
* @example
|
|
14
15
|
* const base = 'C:\\Users\\JohnDoe\\Documents\\Projects\\MyProject'
|
package/dist/path/resolve-rel.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* juisy v3.0.0-beta.
|
|
2
|
+
* juisy v3.0.0-beta.4
|
|
3
3
|
* Copyright © 2022-Present Hervé Perchec
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import path from '
|
|
6
|
+
import * as path from 'path-unified';
|
|
7
|
+
import isWin32 from '@juisy/utils/path/is-win32';
|
|
7
8
|
import toPosix from '@juisy/utils/path/to-posix';
|
|
8
9
|
import toWin32 from '@juisy/utils/path/to-win32';
|
|
9
10
|
import toOsFormat from '@juisy/utils/path/to-os-format';
|
|
10
11
|
|
|
11
12
|
function resolveRel(from, to, separator) {
|
|
12
|
-
const relativePath = path.relative(from, to);
|
|
13
|
+
const relativePath = isWin32(from) || isWin32(to) ? path.win32.relative(from, to) : path.posix.relative(from, to);
|
|
13
14
|
return separator ? separator === "posix" ? toPosix(relativePath) : toWin32(relativePath) : toOsFormat(relativePath);
|
|
14
15
|
}
|
|
15
16
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* juisy v3.0.0-beta.
|
|
2
|
+
* juisy v3.0.0-beta.4
|
|
3
3
|
* Copyright © 2022-Present Hervé Perchec
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import path from '
|
|
6
|
+
import * as path from 'path-unified';
|
|
7
7
|
|
|
8
8
|
function stripExtension(value) {
|
|
9
9
|
return value.replace(new RegExp(path.extname(value) + "$"), "");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* juisy v3.0.0-beta.
|
|
2
|
+
* juisy v3.0.0-beta.4
|
|
3
3
|
* Copyright © 2022-Present Hervé Perchec
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -7,7 +7,7 @@ import toWin32 from '@juisy/utils/path/to-win32';
|
|
|
7
7
|
import toPosix from '@juisy/utils/path/to-posix';
|
|
8
8
|
|
|
9
9
|
function toOsFormat(val) {
|
|
10
|
-
const platform = process
|
|
10
|
+
const platform = process?.platform;
|
|
11
11
|
return platform === "win32" ? toWin32(val) : toPosix(val);
|
|
12
12
|
}
|
|
13
13
|
|