@stryke/path
Version:
A package containing various utilities that expand the functionality of NodeJs's built-in `path` module
88 lines (86 loc) • 2.53 kB
JavaScript
import { ABSOLUTE_PATH_REGEX, NPM_SCOPED_PACKAGE_REGEX } from "./regex.mjs";
import { slash } from "./slash.mjs";
//#region src/is-type.ts
/**
* Check if the path is an absolute path.
*
* @param path - The path to check
* @returns An indicator specifying if the path is an absolute path
*/
function isAbsolutePath(path) {
return ABSOLUTE_PATH_REGEX.test(slash(path));
}
/**
* Check if the path is an absolute path.
*
* @remarks
* This is an alias for {@link isAbsolutePath}.
*
* @param path - The path to check
* @returns An indicator specifying if the path is an absolute path
*/
function isAbsolute(path) {
return isAbsolutePath(path);
}
/**
* Check if the path is a relative path.
*
* @param path - The path to check
* @returns An indicator specifying if the path is a relative path
*/
function isRelativePath(path) {
return !isAbsolutePath(path);
}
/**
* Check if the path is a relative path.
*
* @remarks
* This is an alias for {@link isRelativePath}.
*
* @param path - The path to check
* @returns An indicator specifying if the path is a relative path
*/
function isRelative(path) {
return isRelativePath(path);
}
/**
* Check if the path is a npm package path.
*
* @remarks
* This only checks if the path matches the npm namespace scoped package naming convention such as `@scope/package-name`. This is an alias for {@link isNpmScopedPackage}.
*
* @example
* ```ts
* isNpmScopedPackage("@stryke/path"); // returns true
* isNpmScopedPackage("lodash"); // returns false
* isNpmNamespacePackage("./src/index.ts"); // returns false
* ```
*
* @param path - The path to check
* @returns An indicator specifying if the path is a npm package path
*/
function isNpmScopedPackagePath(path) {
return NPM_SCOPED_PACKAGE_REGEX.test(slash(path));
}
/**
* Check if the path is a npm package path.
*
* @remarks
* This only checks if the path matches the npm namespace scoped package naming convention such as `@scope/package-name`. This is an alias for {@link isNpmScopedPackagePath}.
*
* @example
* ```ts
* isNpmScopedPackagePath("@stryke/path"); // returns true
* isNpmScopedPackagePath("lodash"); // returns false
* isNpmScopedPackagePath("./src/index.ts"); // returns false
* ```
*
* @param path - The path to check
* @returns An indicator specifying if the path is a npm package path
*/
function isNpmScopedPackage(path) {
return isNpmScopedPackagePath(path);
}
//#endregion
export { isAbsolute, isAbsolutePath, isNpmScopedPackage, isNpmScopedPackagePath, isRelative, isRelativePath };
//# sourceMappingURL=is-type.mjs.map