upath
Advanced tools
Comparing version 1.2.0 to 2.0.0
/** | ||
* upath http://github.com/anodynos/upath/ | ||
* | ||
* A proxy to `path`, replacing `\` with `/` for all results & new methods to normalize & join keeping leading `./` and add, change, default, trim file extensions. | ||
* Version 1.2.0 - Compiled on 2019-09-02 23:33:57 | ||
* A proxy to `path`, replacing `\` with `/` for all results (supports UNC paths) & new methods to normalize & join keeping leading `./` and add, change, default, trim file extensions. | ||
* Version 2.0.0 - Compiled on 2020-10-06 21:12:20 | ||
* Repository git://github.com/anodynos/upath | ||
* Copyright(c) 2019 Angelos Pikoulas <agelos.pikoulas@gmail.com> | ||
* Copyright(c) 2020 Angelos Pikoulas <agelos.pikoulas@gmail.com> | ||
* License MIT | ||
@@ -14,3 +14,3 @@ */ | ||
var VERSION = '1.2.0'; // injected by urequire-rc-inject-version | ||
var VERSION = '2.0.0'; // injected by urequire-rc-inject-version | ||
@@ -34,8 +34,4 @@ var extraFn, extraFunctions, isFunction, isString, isValidExt, name, path, propName, propValue, toUnix, upath, slice = [].slice, indexOf = [].indexOf || function (item) { | ||
toUnix = function (p) { | ||
var double; | ||
p = p.replace(/\\/g, "/"); | ||
double = /\/\//; | ||
while (p.match(double)) { | ||
p = p.replace(double, "/"); | ||
} | ||
p = p.replace(/(?<!^)\/+/g, "/"); | ||
return p; | ||
@@ -73,12 +69,15 @@ }; | ||
normalizeSafe: function (p) { | ||
var result; | ||
p = toUnix(p); | ||
if (p.startsWith("./")) { | ||
if (p.startsWith("./..") || p === "./") { | ||
return upath.normalize(p); | ||
result = upath.normalize(p); | ||
if (p.startsWith("./") && !result.startsWith("./") && !result.startsWith("..")) { | ||
result = "./" + result; | ||
} else if (p.startsWith("//") && !result.startsWith("//")) { | ||
if (p.startsWith("//./")) { | ||
result = "//." + result; | ||
} else { | ||
return "./" + upath.normalize(p); | ||
result = "/" + result; | ||
} | ||
} else { | ||
return upath.normalize(p); | ||
} | ||
return result; | ||
}, | ||
@@ -94,7 +93,16 @@ normalizeTrim: function (p) { | ||
joinSafe: function () { | ||
var p, result; | ||
var p, p0, result; | ||
p = 1 <= arguments.length ? slice.call(arguments, 0) : []; | ||
result = upath.join.apply(null, p); | ||
if (p[0].startsWith("./") && !result.startsWith("./")) { | ||
result = "./" + result; | ||
if (p.length > 0) { | ||
p0 = toUnix(p[0]); | ||
if (p0.startsWith("./") && !result.startsWith("./") && !result.startsWith("..")) { | ||
result = "./" + result; | ||
} else if (p0.startsWith("//") && !result.startsWith("//")) { | ||
if (p0.startsWith("//./")) { | ||
result = "//." + result; | ||
} else { | ||
result = "/" + result; | ||
} | ||
} | ||
} | ||
@@ -131,3 +139,3 @@ return result; | ||
if (upath.extname(filename) === ext) { | ||
return upath.trimExt(filename); | ||
return upath.trimExt(filename, [], ext.length); | ||
} else { | ||
@@ -134,0 +142,0 @@ return filename; |
{ | ||
"name": "upath", | ||
"description": "A proxy to `path`, replacing `\\` with `/` for all results & new methods to normalize & join keeping leading `./` and add, change, default, trim file extensions.", | ||
"version": "1.2.0", | ||
"description": "A proxy to `path`, replacing `\\` with `/` for all results (supports UNC paths) & new methods to normalize & join keeping leading `./` and add, change, default, trim file extensions.", | ||
"version": "2.0.0", | ||
"homepage": "http://github.com/anodynos/upath/", | ||
@@ -21,3 +21,4 @@ "author": { | ||
"add extension", | ||
"default extension" | ||
"default extension", | ||
"UNC paths" | ||
], | ||
@@ -36,4 +37,4 @@ "repository": { | ||
"scripts": { | ||
"test": "grunt", | ||
"build": "grunt lib" | ||
"test": "npx grunt", | ||
"build": "npx grunt lib" | ||
}, | ||
@@ -54,3 +55,3 @@ "directories": { | ||
"grunt-urequire": "0.7.x", | ||
"lodash": "^4.17.15", | ||
"lodash": "^4.17.20", | ||
"mocha": "~3.4.2", | ||
@@ -57,0 +58,0 @@ "uberscore": "0.0.19", |
105
readme.md
@@ -1,2 +0,2 @@ | ||
# upath v1.2.0 | ||
# upath v2.0.0 | ||
@@ -24,5 +24,12 @@ [![Build Status](https://travis-ci.org/anodynos/upath.svg?branch=master)](https://travis-ci.org/anodynos/upath) | ||
* travis-ci tested in node versions 4 to 12 | ||
* travis-ci tested in node versions 8 to 14 (on linux) | ||
* Also tested on Windows / node@12.18.0 (without CI) | ||
History brief: | ||
* 1.x : Initial release and various features / fixes | ||
* 2.0.0 : Adding UNC paths support - see https://github.com/anodynos/upath/pull/38 | ||
## Why ? | ||
@@ -44,9 +51,9 @@ | ||
✓ `'c:/windows/nodejs/path'` ---> `'c:/windows/nodejs/path'` // equal to `path.normalize()` | ||
✓ `'c:/windows/../nodejs/path'` ---> `'c:/nodejs/path'` // equal to `path.normalize()` | ||
✓ `'c:\\windows\\nodejs\\path'` ---> `'c:/windows/nodejs/path'` // `path.normalize()` gives `'c:\windows\nodejs\path'` | ||
✓ `'c:\\windows\\..\\nodejs\\path'` ---> `'c:/nodejs/path'` // `path.normalize()` gives `'c:\windows\..\nodejs\path'` | ||
✓ `'//windows\\unix/mixed'` ---> `'/windows/unix/mixed'` // `path.normalize()` gives `'/windows\unix/mixed'` | ||
✓ `'\\windows//unix/mixed'` ---> `'/windows/unix/mixed'` // `path.normalize()` gives `'\windows/unix/mixed'` | ||
✓ `'////\\windows\\..\\unix/mixed/'` ---> `'/unix/mixed/'` // `path.normalize()` gives `'/\windows\..\unix/mixed/'` | ||
✓ `'c:/windows/nodejs/path'` ---> `'c:/windows/nodejs/path'` // equal to `path.normalize()` | ||
✓ `'c:/windows/../nodejs/path'` ---> `'c:/nodejs/path'` // equal to `path.normalize()` | ||
✓ `'c:\\windows\\nodejs\\path'` ---> `'c:/windows/nodejs/path'` // `path.normalize()` gives `'c:\windows\nodejs\path'` | ||
✓ `'c:\\windows\\..\\nodejs\\path'` ---> `'c:/nodejs/path'` // `path.normalize()` gives `'c:\windows\..\nodejs\path'` | ||
✓ `'/windows\\unix/mixed'` ---> `'/windows/unix/mixed'` // `path.normalize()` gives `'/windows\unix/mixed'` | ||
✓ `'\\windows//unix/mixed'` ---> `'/windows/unix/mixed'` // `path.normalize()` gives `'\windows/unix/mixed'` | ||
✓ `'\\windows\\..\\unix/mixed/'` ---> `'/unix/mixed/'` // `path.normalize()` gives `'\windows\..\unix/mixed/'` | ||
@@ -67,5 +74,8 @@ | ||
✓ `'c:\Windows\Directory\somefile.ext'` ---> `{ root: '', dir: 'c:/Windows/Directory', base: 'somefile.ext', ext: '.ext', name: 'somefile' }` | ||
// `path.parse()` gives `'{ root: '', dir: '', base: 'c:\\Windows\\Directory\\somefile.ext', ext: '.ext', name: 'c:\\Windows\\Directory\\somefile' }'` | ||
✓ `'/root/of/unix/somefile.ext'` ---> `{ root: '/', dir: '/root/of/unix', base: 'somefile.ext', ext: '.ext', name: 'somefile' }` // equal to `path.parse()` | ||
✓ `'c:\Windows\Directory\somefile.ext'` ---> `{ root: '', dir: 'c:/Windows/Directory', base: 'somefile.ext', ext: '.ext', name: 'somefile' | ||
}` | ||
// `path.parse()` gives `'{ root: '', dir: '', base: 'c:\\Windows\\Directory\\somefile.ext', ext: '.ext', name: 'c:\\Windows\\Directory\\somefile' | ||
}'` | ||
✓ `'/root/of/unix/somefile.ext'` ---> `{ root: '/', dir: '/root/of/unix', base: 'somefile.ext', ext: '.ext', name: 'somefile' | ||
}` // equal to `path.parse()` | ||
@@ -90,3 +100,3 @@ | ||
Exactly like `path.normalize(path)`, but it keeps the first meaningful `./`. | ||
Exactly like `path.normalize(path)`, but it keeps the first meaningful `./` or `//`. | ||
@@ -99,25 +109,33 @@ Note that the unix `/` is returned everywhere, so windows `\` is always converted to unix `/`. | ||
✓ `''` ---> `'.'` // equal to `path.normalize()` | ||
✓ `'.'` ---> `'.'` // equal to `path.normalize()` | ||
✓ `'./'` ---> `'./'` // equal to `path.normalize()` | ||
✓ `'.//'` ---> `'./'` // equal to `path.normalize()` | ||
✓ `'.\\'` ---> `'./'` // `path.normalize()` gives `'.\'` | ||
✓ `'.\\//'` ---> `'./'` // `path.normalize()` gives `'.\/'` | ||
✓ `'./..'` ---> `'..'` // equal to `path.normalize()` | ||
✓ `'.//..'` ---> `'..'` // equal to `path.normalize()` | ||
✓ `'./../'` ---> `'../'` // equal to `path.normalize()` | ||
✓ `'.\\..\\'` ---> `'../'` // `path.normalize()` gives `'.\..\'` | ||
✓ `'./../dep'` ---> `'../dep'` // equal to `path.normalize()` | ||
✓ `'../dep'` ---> `'../dep'` // equal to `path.normalize()` | ||
✓ `'../path/dep'` ---> `'../path/dep'` // equal to `path.normalize()` | ||
✓ `'../path/../dep'` ---> `'../dep'` // equal to `path.normalize()` | ||
✓ `'dep'` ---> `'dep'` // equal to `path.normalize()` | ||
✓ `'path//dep'` ---> `'path/dep'` // equal to `path.normalize()` | ||
✓ `'./dep'` ---> `'./dep'` // `path.normalize()` gives `'dep'` | ||
✓ `'./path/dep'` ---> `'./path/dep'` // `path.normalize()` gives `'path/dep'` | ||
✓ `'./path/../dep'` ---> `'./dep'` // `path.normalize()` gives `'dep'` | ||
✓ `'.//windows\\unix/mixed/'` ---> `'./windows/unix/mixed/'` // `path.normalize()` gives `'windows\unix/mixed/'` | ||
✓ `'..//windows\\unix/mixed'` ---> `'../windows/unix/mixed'` // `path.normalize()` gives `'../windows\unix/mixed'` | ||
✓ `'windows\\unix/mixed/'` ---> `'windows/unix/mixed/'` // `path.normalize()` gives `'windows\unix/mixed/'` | ||
✓ `'..//windows\\..\\unix/mixed'` ---> `'../unix/mixed'` // `path.normalize()` gives `'../windows\..\unix/mixed'` | ||
✓ `''` ---> `'.'` // equal to `path.normalize()` | ||
✓ `'.'` ---> `'.'` // equal to `path.normalize()` | ||
✓ `'./'` ---> `'./'` // equal to `path.normalize()` | ||
✓ `'.//'` ---> `'./'` // equal to `path.normalize()` | ||
✓ `'.\\'` ---> `'./'` // `path.normalize()` gives `'.\'` | ||
✓ `'.\\//'` ---> `'./'` // `path.normalize()` gives `'.\/'` | ||
✓ `'./..'` ---> `'..'` // equal to `path.normalize()` | ||
✓ `'.//..'` ---> `'..'` // equal to `path.normalize()` | ||
✓ `'./../'` ---> `'../'` // equal to `path.normalize()` | ||
✓ `'.\\..\\'` ---> `'../'` // `path.normalize()` gives `'.\..\'` | ||
✓ `'./../dep'` ---> `'../dep'` // equal to `path.normalize()` | ||
✓ `'../dep'` ---> `'../dep'` // equal to `path.normalize()` | ||
✓ `'../path/dep'` ---> `'../path/dep'` // equal to `path.normalize()` | ||
✓ `'../path/../dep'` ---> `'../dep'` // equal to `path.normalize()` | ||
✓ `'dep'` ---> `'dep'` // equal to `path.normalize()` | ||
✓ `'path//dep'` ---> `'path/dep'` // equal to `path.normalize()` | ||
✓ `'./dep'` ---> `'./dep'` // `path.normalize()` gives `'dep'` | ||
✓ `'./path/dep'` ---> `'./path/dep'` // `path.normalize()` gives `'path/dep'` | ||
✓ `'./path/../dep'` ---> `'./dep'` // `path.normalize()` gives `'dep'` | ||
✓ `'.//windows\\unix/mixed/'` ---> `'./windows/unix/mixed/'` // `path.normalize()` gives `'windows\unix/mixed/'` | ||
✓ `'..//windows\\unix/mixed'` ---> `'../windows/unix/mixed'` // `path.normalize()` gives `'../windows\unix/mixed'` | ||
✓ `'windows\\unix/mixed/'` ---> `'windows/unix/mixed/'` // `path.normalize()` gives `'windows\unix/mixed/'` | ||
✓ `'..//windows\\..\\unix/mixed'` ---> `'../unix/mixed'` // `path.normalize()` gives `'../windows\..\unix/mixed'` | ||
✓ `'\\\\server\\share\\file'` ---> `'//server/share/file'` // `path.normalize()` gives `'\\server\share\file'` | ||
✓ `'//server/share/file'` ---> `'//server/share/file'` // `path.normalize()` gives `'/server/share/file'` | ||
✓ `'\\\\?\\UNC\\server\\share\\file'` ---> `'//?/UNC/server/share/file'` // `path.normalize()` gives `'\\?\UNC\server\share\file'` | ||
✓ `'\\\\LOCALHOST\\c$\\temp\\file'` ---> `'//LOCALHOST/c$/temp/file'` // `path.normalize()` gives `'\\LOCALHOST\c$\temp\file'` | ||
✓ `'\\\\?\\c:\\temp\\file'` ---> `'//?/c:/temp/file'` // `path.normalize()` gives `'\\?\c:\temp\file'` | ||
✓ `'\\\\.\\c:\\temp\\file'` ---> `'//./c:/temp/file'` // `path.normalize()` gives `'\\.\c:\temp\file'` | ||
✓ `'//./c:/temp/file'` ---> `'//./c:/temp/file'` // `path.normalize()` gives `'/c:/temp/file'` | ||
✓ `'////\\.\\c:/temp\\//file'` ---> `'//./c:/temp/file'` // `path.normalize()` gives `'/\.\c:/temp\/file'` | ||
@@ -142,3 +160,3 @@ | ||
Exactly like `path.join()`, but it keeps the first meaningful `./`. | ||
Exactly like `path.join()`, but it keeps the first meaningful `./` or `//`. | ||
@@ -155,2 +173,6 @@ Note that the unix `/` is returned everywhere, so windows `\` is always converted to unix `/`. | ||
✓ `'../some/relative/destination', '..\\path'` ---> `'../some/relative/path'` // `path.join()` gives `'../some/relative/destination/..\path'` | ||
✓ `'\\\\server\\share\\file', '..\\path'` ---> `'//server/share/path'` // `path.join()` gives `'\\server\share\file/..\path'` | ||
✓ `'\\\\.\\c:\\temp\\file', '..\\path'` ---> `'//./c:/temp/path'` // `path.join()` gives `'\\.\c:\temp\file/..\path'` | ||
✓ `'//server/share/file', '../path'` ---> `'//server/share/path'` // `path.join()` gives `'/server/share/path'` | ||
✓ `'//./c:/temp/file', '../path'` ---> `'//./c:/temp/path'` // `path.join()` gives `'/c:/temp/path'` | ||
@@ -238,2 +260,3 @@ | ||
✓ `'notRemoved.txt'` ---> `'notRemoved.txt'` | ||
@@ -247,4 +270,4 @@ It does not care about the length of exts. | ||
✓ `'notRemoved.txt'` ---> `'notRemoved.txt'` | ||
#### `upath.changeExt(filename, [ext], [ignoreExts], [maxSize=7])` | ||
@@ -329,5 +352,5 @@ | ||
Copyright(c) 2014-2020 Angelos Pikoulas (agelos.pikoulas@gmail.com) | ||
Copyright(c) 2014-2019 Angelos Pikoulas (agelos.pikoulas@gmail.com) | ||
Permission is hereby granted, free of charge, to any person | ||
@@ -334,0 +357,0 @@ obtaining a copy of this software and associated documentation |
Sorry, the diff of this file is not supported yet
36731
399
366