url-or-path
Advanced tools
Comparing version 2.1.0 to 2.2.0
19
index.js
import {fileURLToPath, pathToFileURL} from 'node:url' | ||
const isUrlInstance = (urlOrPath) => urlOrPath instanceof URL | ||
const isUrlString = (urlOrPath) => | ||
typeof urlOrPath === 'string' && urlOrPath.startsWith('file://') | ||
/** @typedef {URL | string} UrlOrPath */ | ||
/** @type {(value: unknown) => value is URL} */ | ||
const isUrlInstance = (value) => value instanceof URL | ||
/** @type {(value: unknown) => value is string} */ | ||
const isUrlString = (value) => | ||
typeof value === 'string' && value.startsWith('file://') | ||
/** @type {(value: unknown) => value is UrlOrPath} */ | ||
const isUrl = (urlOrPath) => isUrlInstance(urlOrPath) || isUrlString(urlOrPath) | ||
/** @type {(urlOrPath: UrlOrPath) => URL} */ | ||
const toUrl = (urlOrPath) => { | ||
@@ -21,8 +26,11 @@ if (isUrlInstance(urlOrPath)) { | ||
/** @type {(urlOrPath: UrlOrPath) => string} */ | ||
const toPath = (urlOrPath) => | ||
isUrl(urlOrPath) ? fileURLToPath(urlOrPath) : urlOrPath | ||
/** @type {(url: URL) => URL} */ | ||
const addSlash = (url) => | ||
url.href.endsWith('/') ? url : new URL(`${url.href}/`) | ||
/** @type {(urlOrPath: UrlOrPath) => URL} */ | ||
const toDirectory = (urlOrPath) => addSlash(toUrl(urlOrPath)) | ||
@@ -32,8 +40,11 @@ | ||
isUrl, | ||
isUrl as isURL, | ||
isUrlInstance, | ||
isUrlInstance as isURLInstance, | ||
isUrlString, | ||
toDirectory, | ||
isUrlString as isURLString, | ||
toUrl, | ||
toUrl as toURL, | ||
toPath, | ||
toDirectory, | ||
} |
{ | ||
"name": "url-or-path", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Convert between file URL and path.", | ||
@@ -30,3 +30,3 @@ "homepage": "https://github.com/fisker/url-or-path#readme", | ||
"format:eslint": "yarn lint:eslint --fix", | ||
"format:markdown": "yarn lint:markdown --fix", | ||
"format:markdown": "markdownlint-cli2-fix \"**/*.md\"", | ||
"format:package-json": "sort-package-json \"package.json\" \"packages/*/package.json\"", | ||
@@ -36,3 +36,3 @@ "format:prettier": "yarn lint:prettier --write", | ||
"lint:eslint": "eslint \"**/*.{js,mjs,cjs,vue}\"", | ||
"lint:markdown": "markdownlint \"**/*.md\" --ignore \"**/node_modules/**\"", | ||
"lint:markdown": "markdownlint2 \"**/*.md\"", | ||
"lint:package-json": "yarn run format:package-json --check", | ||
@@ -55,17 +55,17 @@ "lint:prettier": "prettier \"**/*.{css,html,js,cjs,mjs,json,less,md,scss,ts,vue,yaml,yml}\" --check", | ||
"devDependencies": { | ||
"@fisker/eslint-config": "10.0.12", | ||
"@fisker/eslint-config-ava": "2.0.5", | ||
"@fisker/husky-config": "4.1.2", | ||
"@fisker/lint-staged-config": "3.1.4", | ||
"@fisker/prettier-config": "5.0.5", | ||
"ava": "4.0.1", | ||
"c8": "7.11.0", | ||
"del-cli": "4.0.1", | ||
"eslint": "8.8.0", | ||
"husky": "7.0.4", | ||
"lint-staged": "12.3.3", | ||
"markdownlint-cli": "0.31.1", | ||
"@fisker/eslint-config": "12.0.0", | ||
"@fisker/eslint-config-ava": "2.0.6", | ||
"@fisker/husky-config": "4.1.3", | ||
"@fisker/lint-staged-config": "3.3.1", | ||
"@fisker/prettier-config": "5.1.1", | ||
"ava": "5.3.1", | ||
"c8": "8.0.1", | ||
"del-cli": "5.1.0", | ||
"eslint": "8.53.0", | ||
"husky": "8.0.3", | ||
"lint-staged": "15.1.0", | ||
"markdownlint-cli2": "0.10.0", | ||
"npm-run-all": "4.1.5", | ||
"prettier": "2.5.1", | ||
"sort-package-json": "1.54.0" | ||
"prettier": "3.1.0", | ||
"sort-package-json": "2.6.0" | ||
}, | ||
@@ -72,0 +72,0 @@ "publishConfig": { |
@@ -8,3 +8,3 @@ # url-or-path | ||
[github_actions_badge]: https://img.shields.io/github/workflow/status/fisker/url-or-path/CI/main?style=flat-square | ||
[github_actions_badge]: https://img.shields.io/github/actions/workflow/status/fisker/url-or-path/continuous-integration.yml?barnach=main&style=flat-square | ||
[github_actions_link]: https://github.com/fisker/url-or-path/actions?query=branch%3Amain | ||
@@ -58,12 +58,12 @@ [coveralls_badge]: https://img.shields.io/coveralls/github/fisker/url-or-path/main?style=flat-square | ||
### `isUrl(object)` | ||
### `isUrl(value)`(alias `isURL`) | ||
Check if `object` is a `URL` instance of `file://` string. | ||
Check if `value` is a `URL` instance or a string starts with `file://`. | ||
### `isUrlInstance(object)` | ||
### `isUrlInstance(value)`(alias `isURLInstance`) | ||
Check if `object` is a `URL` instance. | ||
Check if `value` is a `URL` instance. | ||
### `isUrlString(object)` | ||
### `isUrlString(value)`(alias `isURLString`) | ||
Check if `object` is a `file://` string | ||
Check if `value` is a string starts with `file://`. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6420
39