-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: improved implementation with tests (#3)
Co-authored-by: Daniel Roe <daniel@roe.dev> Co-authored-by: Pooya Parsa <pyapar@gmail.com>
- Loading branch information
Showing
12 changed files
with
1,211 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
{ | ||
"extends": [ | ||
"@nuxtjs/eslint-config-typescript" | ||
] | ||
], | ||
"rules": { | ||
"no-unused-expressions": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ node_modules | |
coverage | ||
dist | ||
types | ||
.nyc_output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,10 @@ | ||
// Reference https://nodejs.org/api/path.html | ||
import path from 'path' | ||
|
||
// Force posix contants | ||
export const sep = '/' | ||
export const delimiter = ':' | ||
|
||
// Export platforms as is | ||
export const win32 = path.win32 | ||
export const posix = path.posix | ||
|
||
// extname | ||
export const extname: typeof path.extname = function (p) { | ||
return path.posix.extname(normalizeWindowsPath(p)) | ||
} | ||
|
||
// normalize | ||
export const normalize: typeof path.normalize = function (p) { | ||
return path.posix.normalize(normalizeWindowsPath(p)) | ||
} | ||
|
||
// join | ||
export const join: typeof path.join = function (...args) { | ||
return path.posix.join.apply(path.posix.join, args.map(arg => normalizeWindowsPath(arg))) | ||
} | ||
|
||
// relative | ||
export const relative: typeof path.relative = function (from, to) { | ||
return path.posix.relative(normalizeWindowsPath(from), normalizeWindowsPath(to)) | ||
} | ||
|
||
// dirname | ||
export const dirname: typeof path.dirname = function (p) { | ||
return path.posix.dirname(normalizeWindowsPath(p)) | ||
} | ||
|
||
// resolve | ||
// TODO: Find a way to use path.posix for consistant behavior | ||
export const resolve: typeof path.resolve = function (...args) { | ||
return path.resolve.apply(path.resolve, args.map(arg => normalizeWindowsPath(arg))) | ||
} | ||
|
||
// format | ||
export const format: typeof path.format = function (p) { | ||
return normalizeWindowsPath(path.posix.format(p)) | ||
} | ||
|
||
// basename | ||
export const basename: typeof path.basename = function (p, ext) { | ||
return path.posix.basename(normalizeWindowsPath(p), ext) | ||
} | ||
|
||
// parse | ||
export const parse: typeof path.parse = function (p) { | ||
return path.posix.parse(normalizeWindowsPath(p)) | ||
} | ||
|
||
// toNamespacedPath | ||
export const toNamespacedPath: typeof path.toNamespacedPath = function (p) { | ||
return p | ||
} | ||
|
||
// isAbsolute | ||
const _IS_ABSOLUTE_RE = /^\/|^\\|^[a-zA-Z]:[/\\]/ | ||
export const isAbsolute: typeof path.isAbsolute = function (p) { | ||
return _IS_ABSOLUTE_RE.test(p) | ||
} | ||
|
||
// Util to normalize windows paths to posix | ||
export function normalizeWindowsPath (input: string = '') { | ||
if (!input.includes('\\')) { | ||
return input | ||
} | ||
return input.replace(/\\/g, '/') | ||
} | ||
import * as _path from './path' | ||
export * from './path' | ||
|
||
// Default export | ||
export default { | ||
win32, | ||
posix, | ||
sep, | ||
delimiter, | ||
resolve, | ||
normalize, | ||
isAbsolute, | ||
join, | ||
relative, | ||
toNamespacedPath, | ||
dirname, | ||
basename, | ||
extname, | ||
format, | ||
parse | ||
} as typeof path | ||
..._path | ||
} as Omit<typeof path, 'win32' | 'posix'> |
Oops, something went wrong.