+27
| declare namespace path { | ||
| export const sep: '/' | '\\' | ||
| export const delimiter: ':' | ';' | ||
| export function basename(path: string, suffix?: string): string | ||
| export function dirname(path: string): string | ||
| export function extname(path: string): string | ||
| export function isAbsolute(path: string): boolean | ||
| export function join(...paths: string[]): string | ||
| export function normalize(path: string): string | ||
| export function relative(from: string, to: string): string | ||
| export function resolve(...args: string[]): string | ||
| export function toNamespacedPath(path: string): string | ||
| export const posix = path | ||
| export const win32 = path | ||
| } | ||
| export = path |
+0
-2
@@ -1,3 +0,1 @@ | ||
| /* global Bare */ | ||
| // This export SHOULD NOT be shortened in any way as having the full | ||
@@ -4,0 +2,0 @@ // `module.exports = require(...)` statement is crucial for synthesizing |
+21
-17
| const os = require('bare-os') | ||
| const { normalizeString } = require('./shared') | ||
| const { | ||
| CHAR_DOT, | ||
| CHAR_FORWARD_SLASH | ||
| } = require('./constants') | ||
| const { CHAR_DOT, CHAR_FORWARD_SLASH } = require('./constants') | ||
| function isPosixPathSeparator (code) { | ||
| function isPosixPathSeparator(code) { | ||
| return code === CHAR_FORWARD_SLASH | ||
@@ -19,3 +16,3 @@ } | ||
| exports.resolve = function resolve (...args) { | ||
| exports.resolve = function resolve(...args) { | ||
| let resolvedPath = '' | ||
@@ -44,3 +41,3 @@ let resolvedAbsolute = false | ||
| exports.normalize = function normalize (path) { | ||
| exports.normalize = function normalize(path) { | ||
| if (path.length === 0) return '.' | ||
@@ -63,7 +60,7 @@ | ||
| exports.isAbsolute = function isAbsolute (path) { | ||
| exports.isAbsolute = function isAbsolute(path) { | ||
| return path.length > 0 && path.charCodeAt(0) === CHAR_FORWARD_SLASH | ||
| } | ||
| exports.join = function join (...args) { | ||
| exports.join = function join(...args) { | ||
| if (args.length === 0) return '.' | ||
@@ -82,3 +79,3 @@ let joined | ||
| exports.relative = function relative (from, to) { | ||
| exports.relative = function relative(from, to) { | ||
| if (from === to) return '' | ||
@@ -97,3 +94,3 @@ | ||
| const length = (fromLen < toLen ? fromLen : toLen) | ||
| const length = fromLen < toLen ? fromLen : toLen | ||
| let lastCommonSep = -1 | ||
@@ -136,7 +133,7 @@ let i = 0 | ||
| exports.toNamespacedPath = function toNamespacedPath (path) { | ||
| exports.toNamespacedPath = function toNamespacedPath(path) { | ||
| return path | ||
| } | ||
| exports.dirname = function dirname (path) { | ||
| exports.dirname = function dirname(path) { | ||
| if (path.length === 0) return '.' | ||
@@ -162,3 +159,3 @@ const hasRoot = path.charCodeAt(0) === CHAR_FORWARD_SLASH | ||
| exports.basename = function basename (path, suffix) { | ||
| exports.basename = function basename(path, suffix) { | ||
| let start = 0 | ||
@@ -169,3 +166,5 @@ let end = -1 | ||
| if (suffix !== undefined && suffix.length > 0 && suffix.length <= path.length) { | ||
| if (suffix === path) { return '' } | ||
| if (suffix === path) { | ||
| return '' | ||
| } | ||
| let extIdx = suffix.length - 1 | ||
@@ -219,3 +218,3 @@ let firstNonSlashEnd = -1 | ||
| exports.extname = function extname (path) { | ||
| exports.extname = function extname(path) { | ||
| let startDot = -1 | ||
@@ -247,3 +246,8 @@ let startPart = 0 | ||
| if (startDot === -1 || end === -1 || preDotState === 0 || (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)) { | ||
| if ( | ||
| startDot === -1 || | ||
| end === -1 || | ||
| preDotState === 0 || | ||
| (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) | ||
| ) { | ||
| return '' | ||
@@ -250,0 +254,0 @@ } |
+15
-9
@@ -1,7 +0,9 @@ | ||
| const { | ||
| CHAR_DOT, | ||
| CHAR_FORWARD_SLASH | ||
| } = require('./constants') | ||
| const { CHAR_DOT, CHAR_FORWARD_SLASH } = require('./constants') | ||
| exports.normalizeString = function normalizeString (path, allowAboveRoot, separator, isPathSeparator) { | ||
| exports.normalizeString = function normalizeString( | ||
| path, | ||
| allowAboveRoot, | ||
| separator, | ||
| isPathSeparator | ||
| ) { | ||
| let res = '' | ||
@@ -22,5 +24,10 @@ let lastSegmentLength = 0 | ||
| if (isPathSeparator(code)) { | ||
| if (lastSlash === i - 1 || dots === 1) ; | ||
| if (lastSlash === i - 1 || dots === 1); | ||
| else if (dots === 2) { | ||
| if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== CHAR_DOT || res.charCodeAt(res.length - 2) !== CHAR_DOT) { | ||
| if ( | ||
| res.length < 2 || | ||
| lastSegmentLength !== 2 || | ||
| res.charCodeAt(res.length - 1) !== CHAR_DOT || | ||
| res.charCodeAt(res.length - 2) !== CHAR_DOT | ||
| ) { | ||
| if (res.length > 2) { | ||
@@ -33,4 +40,3 @@ const lastSlashIndex = res.lastIndexOf(separator) | ||
| res = res.substring(0, lastSlashIndex) | ||
| lastSegmentLength = | ||
| res.length - 1 - res.lastIndexOf(separator) | ||
| lastSegmentLength = res.length - 1 - res.lastIndexOf(separator) | ||
| } | ||
@@ -37,0 +43,0 @@ lastSlash = i |
+58
-24
@@ -16,9 +16,11 @@ const os = require('bare-os') | ||
| function isWindowsPathSeparator (code) { | ||
| function isWindowsPathSeparator(code) { | ||
| return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH | ||
| } | ||
| function isWindowsDeviceRoot (code) { | ||
| return (code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z) || | ||
| (code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z) | ||
| function isWindowsDeviceRoot(code) { | ||
| return ( | ||
| (code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z) || | ||
| (code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z) | ||
| ) | ||
| } | ||
@@ -32,3 +34,3 @@ | ||
| exports.resolve = function resolve (...args) { | ||
| exports.resolve = function resolve(...args) { | ||
| let resolvedDevice = '' | ||
@@ -49,3 +51,7 @@ let resolvedTail = '' | ||
| if (path === undefined || (path.substring(0, 2).toLowerCase() !== resolvedDevice.toLowerCase() && path.charCodeAt(2) === CHAR_BACKWARD_SLASH)) { | ||
| if ( | ||
| path === undefined || | ||
| (path.substring(0, 2).toLowerCase() !== resolvedDevice.toLowerCase() && | ||
| path.charCodeAt(2) === CHAR_BACKWARD_SLASH) | ||
| ) { | ||
| path = `${resolvedDevice}\\` | ||
@@ -106,3 +112,5 @@ } | ||
| if (resolvedDevice.length > 0) { | ||
| if (device.toLowerCase() !== resolvedDevice.toLowerCase()) { continue } | ||
| if (device.toLowerCase() !== resolvedDevice.toLowerCase()) { | ||
| continue | ||
| } | ||
| } else { | ||
@@ -114,3 +122,5 @@ resolvedDevice = device | ||
| if (resolvedAbsolute) { | ||
| if (resolvedDevice.length > 0) { break } | ||
| if (resolvedDevice.length > 0) { | ||
| break | ||
| } | ||
| } else { | ||
@@ -127,6 +137,8 @@ resolvedTail = `${path.substring(rootEnd)}\\${resolvedTail}` | ||
| return resolvedAbsolute ? `${resolvedDevice}\\${resolvedTail}` : `${resolvedDevice}${resolvedTail}` || '.' | ||
| return resolvedAbsolute | ||
| ? `${resolvedDevice}\\${resolvedTail}` | ||
| : `${resolvedDevice}${resolvedTail}` || '.' | ||
| } | ||
| exports.normalize = function normalize (path) { | ||
| exports.normalize = function normalize(path) { | ||
| const len = path.length | ||
@@ -184,3 +196,6 @@ if (len === 0) return '.' | ||
| let tail = rootEnd < len ? normalizeString(path.substring(rootEnd), !isAbsolute, '\\', isWindowsPathSeparator) : '' | ||
| let tail = | ||
| rootEnd < len | ||
| ? normalizeString(path.substring(rootEnd), !isAbsolute, '\\', isWindowsPathSeparator) | ||
| : '' | ||
| if (tail.length === 0 && !isAbsolute) { | ||
@@ -198,3 +213,3 @@ tail = '.' | ||
| exports.isAbsolute = function isAbsolute (path) { | ||
| exports.isAbsolute = function isAbsolute(path) { | ||
| const len = path.length | ||
@@ -205,6 +220,12 @@ if (len === 0) return false | ||
| return isWindowsPathSeparator(code) || (len > 2 && isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON && isWindowsPathSeparator(path.charCodeAt(2))) | ||
| return ( | ||
| isWindowsPathSeparator(code) || | ||
| (len > 2 && | ||
| isWindowsDeviceRoot(code) && | ||
| path.charCodeAt(1) === CHAR_COLON && | ||
| isWindowsPathSeparator(path.charCodeAt(2))) | ||
| ) | ||
| } | ||
| exports.join = function join (...args) { | ||
| exports.join = function join(...args) { | ||
| if (args.length === 0) return '.' | ||
@@ -253,3 +274,3 @@ | ||
| exports.relative = function relative (from, to) { | ||
| exports.relative = function relative(from, to) { | ||
| if (from === to) return '' | ||
@@ -338,3 +359,3 @@ | ||
| exports.toNamespacedPath = function toNamespacedPath (path) { | ||
| exports.toNamespacedPath = function toNamespacedPath(path) { | ||
| if (path.length === 0) return path | ||
@@ -355,4 +376,4 @@ | ||
| isWindowsDeviceRoot(resolvedPath.charCodeAt(0)) && | ||
| resolvedPath.charCodeAt(1) === CHAR_COLON && | ||
| resolvedPath.charCodeAt(2) === CHAR_BACKWARD_SLASH | ||
| resolvedPath.charCodeAt(1) === CHAR_COLON && | ||
| resolvedPath.charCodeAt(2) === CHAR_BACKWARD_SLASH | ||
| ) { | ||
@@ -365,3 +386,3 @@ return `\\\\?\\${resolvedPath}` | ||
| exports.dirname = function dirname (path) { | ||
| exports.dirname = function dirname(path) { | ||
| const len = path.length | ||
@@ -431,3 +452,3 @@ if (len === 0) return '.' | ||
| exports.basename = function basename (path, suffix) { | ||
| exports.basename = function basename(path, suffix) { | ||
| let start = 0 | ||
@@ -437,3 +458,7 @@ let end = -1 | ||
| if (path.length >= 2 && isWindowsDeviceRoot(path.charCodeAt(0)) && path.charCodeAt(1) === CHAR_COLON) { | ||
| if ( | ||
| path.length >= 2 && | ||
| isWindowsDeviceRoot(path.charCodeAt(0)) && | ||
| path.charCodeAt(1) === CHAR_COLON | ||
| ) { | ||
| start = 2 | ||
@@ -491,3 +516,3 @@ } | ||
| exports.extname = function extname (path) { | ||
| exports.extname = function extname(path) { | ||
| let start = 0 | ||
@@ -500,3 +525,7 @@ let startDot = -1 | ||
| if (path.length >= 2 && path.charCodeAt(1) === CHAR_COLON && isWindowsDeviceRoot(path.charCodeAt(0))) { | ||
| if ( | ||
| path.length >= 2 && | ||
| path.charCodeAt(1) === CHAR_COLON && | ||
| isWindowsDeviceRoot(path.charCodeAt(0)) | ||
| ) { | ||
| start = startPart = 2 | ||
@@ -526,3 +555,8 @@ } | ||
| if (startDot === -1 || end === -1 || preDotState === 0 || (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)) { | ||
| if ( | ||
| startDot === -1 || | ||
| end === -1 || | ||
| preDotState === 0 || | ||
| (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) | ||
| ) { | ||
| return '' | ||
@@ -529,0 +563,0 @@ } |
+12
-4
| { | ||
| "name": "bare-path", | ||
| "version": "3.0.0", | ||
| "version": "3.0.1", | ||
| "description": "Path manipulation library for JavaScript", | ||
| "exports": { | ||
| ".": "./index.js", | ||
| ".": { | ||
| "types": "./index.d.ts", | ||
| "default": "./index.js" | ||
| }, | ||
| "./package": "./package.json", | ||
@@ -13,2 +16,3 @@ "./posix": "./lib/posix.js", | ||
| "index.js", | ||
| "index.d.ts", | ||
| "lib", | ||
@@ -18,3 +22,5 @@ "NOTICE" | ||
| "scripts": { | ||
| "test": "standard && bare test.js" | ||
| "format": "prettier --write . && lunte --fix", | ||
| "lint": "prettier --check . && lunte", | ||
| "test": "brittle-bare --coverage test.js" | ||
| }, | ||
@@ -36,4 +42,6 @@ "repository": { | ||
| "brittle": "^3.3.2", | ||
| "standard": "^17.0.0" | ||
| "lunte": "^1.8.0", | ||
| "prettier": "^3.6.2", | ||
| "prettier-config-holepunch": "^2.0.0" | ||
| } | ||
| } |
+1
-1
@@ -11,3 +11,3 @@ # bare-path | ||
| ``` js | ||
| ```js | ||
| const path = require('bare-path') | ||
@@ -14,0 +14,0 @@ |
36508
3.1%10
11.11%800
7.96%4
100%