UNPKG

@stryke/path

Version:

A package containing various utilities that expand the functionality of NodeJs's built-in `path` module

93 lines (91 loc) 2.74 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const require_regex = require('./regex.cjs'); const require_slash = require('./slash.cjs'); //#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 require_regex.ABSOLUTE_PATH_REGEX.test(require_slash.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 require_regex.NPM_SCOPED_PACKAGE_REGEX.test(require_slash.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 exports.isAbsolute = isAbsolute; exports.isAbsolutePath = isAbsolutePath; exports.isNpmScopedPackage = isNpmScopedPackage; exports.isNpmScopedPackagePath = isNpmScopedPackagePath; exports.isRelative = isRelative; exports.isRelativePath = isRelativePath;