Socket
Socket
Sign inDemoInstall

upath

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

upath - npm Package Compare versions

Comparing version 0.1.4 to 0.1.5

109

build/code/upath.js

@@ -1,42 +0,45 @@

/*!
* upath - version 0.1.3
* Compiled on 2014-11-08
* git://github.com/anodynos/upath
* Copyright(c) 2014 Agelos Pikoulas (agelos.pikoulas@gmail.com )
* Licensed MIT http://www.opensource.org/licenses/mit-license.php
/**
* upath http://github.com/anodynos/upath/
*
* A proxy to `path`, replacing `\` with `/` for all results & methods to add, change, default, trim file extensions.
* Version 0.1.5 - Compiled on 2014-11-18 00:24:58
* Repository git://github.com/anodynos/upath
* Copyright(c) 2014 Agelos Pikoulas <agelos.pikoulas@gmail.com>
* License MIT http://www.opensource.org/licenses/mit-license.php
*/
var VERSION = '0.1.3'; //injected by grunt:concat
// Generated by CoffeeScript 1.8.0
var extraFn, extraFunctions, fName, fn, isValidExt, name, path, toUnix, upath, _,
__slice = [].slice,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
_ = require('lodash');
// Generated by uRequire v0.7.0-beta.11 target: 'lib' template: 'nodejs'
_.mixin((require('underscore.string')).exports());
var _ = require('lodash');
path = require('path');
var VERSION = '0.1.5'; // injected by urequire-rc-inject-version
var extraFn, extraFunctions, fName, fn, isValidExt, name, path, toUnix, upath, __slice = [].slice, __indexOf = [].indexOf || function (item) {
for (var i = 0, l = this.length; i < l; i++) {
if (i in this && this[i] === item)
return i;
}
return -1;
};
_.mixin(require("underscore.string").exports());
path = require("path");
upath = exports;
upath.VERSION = typeof VERSION !== "undefined" && VERSION !== null ? VERSION : 'NO-VERSION';
toUnix = function(p) {
upath.VERSION = typeof VERSION !== "undefined" && VERSION !== null ? VERSION : "NO-VERSION";
toUnix = function (p) {
var double;
p = p.replace(/\\/g, '/');
p = p.replace(/\\/g, "/");
double = /\/\//;
while (p.match(double)) {
p = p.replace(double, '/');
p = p.replace(double, "/");
}
return p;
};
for (fName in path) {
fn = path[fName];
if (_.isFunction(fn)) {
upath[fName] = (function(fName) {
return function() {
upath[fName] = function (fName) {
return function () {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
args = _.map(args, function(p) {
args = _.map(args, function (p) {
if (_.isString(p)) {

@@ -50,15 +53,14 @@ return toUnix(p);

};
})(fName);
}(fName);
}
}
extraFunctions = {
toUnix: toUnix,
normalizeSafe: function(p) {
normalizeSafe: function (p) {
p = toUnix(p);
if (_.startsWith(p, './')) {
if (_.startsWith(p, './..') || (p === './')) {
if (_.startsWith(p, "./")) {
if (_.startsWith(p, "./..") || p === "./") {
return upath.normalize(p);
} else {
return './' + upath.normalize(p);
return "./" + upath.normalize(p);
}

@@ -69,6 +71,6 @@ } else {

},
normalizeTrim: function(p) {
normalizeTrim: function (p) {
p = upath.normalizeSafe(p);
if (_.endsWith(p, '/')) {
return p.slice(0, +(p.length - 2) + 1 || 9e9);
if (_.endsWith(p, "/")) {
return p.slice(0, +(p.length - 2) + 1 || 9000000000);
} else {

@@ -78,13 +80,13 @@ return p;

},
addExt: function(file, ext) {
addExt: function (file, ext) {
if (!ext) {
return file;
} else {
if (ext[0] !== '.') {
ext = '.' + ext;
if (ext[0] !== ".") {
ext = "." + ext;
}
return file + (_.endsWith(file, ext) ? '' : ext);
return file + (_.endsWith(file, ext) ? "" : ext);
}
},
trimExt: function(filename, ignoreExts, maxSize) {
trimExt: function (filename, ignoreExts, maxSize) {
var oldExt;

@@ -96,3 +98,3 @@ if (maxSize == null) {

if (isValidExt(oldExt, ignoreExts, maxSize)) {
return filename.slice(0, +((filename.length - oldExt.length) - 1) + 1 || 9e9);
return filename.slice(0, +(filename.length - oldExt.length - 1) + 1 || 9000000000);
} else {

@@ -102,9 +104,21 @@ return filename;

},
changeExt: function(filename, ext, ignoreExts, maxSize) {
removeExt: function (filename, ext) {
if (!ext) {
return filename;
} else {
ext = ext[0] === "." ? ext : "." + ext;
if (upath.extname(filename) === ext) {
return upath.trimExt(filename);
} else {
return filename;
}
}
},
changeExt: function (filename, ext, ignoreExts, maxSize) {
if (maxSize == null) {
maxSize = 7;
}
return upath.trimExt(filename, ignoreExts, maxSize) + (!ext ? '' : ext[0] === '.' ? ext : '.' + ext);
return upath.trimExt(filename, ignoreExts, maxSize) + (!ext ? "" : ext[0] === "." ? ext : "." + ext);
},
defaultExt: function(filename, ext, ignoreExts, maxSize) {
defaultExt: function (filename, ext, ignoreExts, maxSize) {
var oldExt;

@@ -122,9 +136,7 @@ if (maxSize == null) {

};
isValidExt = function(ext, ignoreExts, maxSize) {
return (ext && (ext.length <= maxSize)) && (__indexOf.call(_.map(ignoreExts, function(e) {
return (e && (e[0] !== '.') ? '.' : '') + e;
}), ext) < 0);
isValidExt = function (ext, ignoreExts, maxSize) {
return ext && ext.length <= maxSize && __indexOf.call(_.map(ignoreExts, function (e) {
return (e && e[0] !== "." ? "." : "") + e;
}), ext) < 0;
};
for (name in extraFunctions) {

@@ -138,1 +150,2 @@ extraFn = extraFunctions[name];

}
{
"name": "upath",
"description": "A proxy to `path`, replacing `\\` with `/` for all results & methods to add, change, default, trim file extensions.",
"version": "0.1.4",
"version": "0.1.5",
"homepage": "http://github.com/anodynos/upath/",

@@ -54,11 +54,11 @@ "author": {

"chai": "^1.9.0",
"coffee-script": "^1.8.0",
"mocha": "^2.0.0",
"grunt": "0.4.x",
"grunt-contrib-clean": "0.4.x",
"grunt-contrib-concat": "0.1.x",
"grunt-shell": "~0.3.x",
"grunt": "0.4.5",
"grunt-contrib-watch": "~0.5.x",
"uberscore": "0.0.16"
"grunt-urequire": "0.7.x",
"urequire": "0.7.x",
"uberscore": "0.0.16",
"urequire-ab-specrunner": "^0.1.10",
"urequire-rc-inject-version": "^0.1.2"
}
}

@@ -1,2 +0,2 @@

# upath v0.1.4
# upath v0.1.5

@@ -10,7 +10,7 @@ [![Build Status](https://travis-ci.org/anodynos/upath.svg?branch=master)](https://travis-ci.org/anodynos/upath)

* Adds **filename extensions** functions `addExt`, `trimExt`, `changeExt`, and `defaultExt`.
* Adds **filename extensions** functions `addExt`, `trimExt`, `removeExt`, `changeExt`, and `defaultExt`.
* Add a `normalizeSafe` function to preserve any meaningful leading `./` & a `normalizeTrim` which additionally trims any useless ending `/`.
* Plus a helper `toUnix` that simply converts `` to `/` and consolidates duplicates.
* Plus a helper `toUnix` that simply converts `\` to `/` and consolidates duplicates.

@@ -37,7 +37,7 @@ **Useful note: these docs are actually auto generated from [specs](https://github.com/anodynos/upath/blob/master/source/spec/upath-spec.coffee), running on Linux.**

✓ `'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'` // `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/'`

@@ -51,3 +51,3 @@

✓ `'some/nodejs\\windows', '../path'` ---> `'some/nodejs/path'` // `path.join()` gives `'some/path'`
✓ `'some\\windows\\only', '..\\path'` ---> `'some/windows/path'` // `path.join()` gives `'some\windows\only/..\path'`
✓ `'some\\windows\\only', '..\\path'` ---> `'some/windows/path'` // `path.join()` gives `'some\windows\only/..\path'`

@@ -66,4 +66,4 @@

✓ `'.//windows\//unix//mixed////'` ---> `'./windows/unix/mixed/'`
✓ `'..///windows\..\\unix/mixed'` ---> `'../windows/../unix/mixed'`
✓ `'.//windows\//unix//mixed////'` ---> `'./windows/unix/mixed/'`
✓ `'..///windows\..\\unix/mixed'` ---> `'../windows/../unix/mixed'`

@@ -100,6 +100,6 @@

✓ `'./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'`
✓ `'.//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'`

@@ -119,3 +119,3 @@

✓ `'path//dep\\'` ---> `'path/dep'` // `upath.normalizeSafe()` gives `'path/dep/'`
✓ `'.//windows\\unix/mixed/'` ---> `'./windows/unix/mixed'` // `upath.normalizeSafe()` gives `'./windows/unix/mixed/'`
✓ `'.//windows\\unix/mixed/'` ---> `'./windows/unix/mixed'` // `upath.normalizeSafe()` gives `'./windows/unix/mixed/'`

@@ -182,3 +182,3 @@

`upath.trimExt(filename, ['min', '.dev'], 8)` --returns-->
`upath.removeExt(filename, ['min', '.dev'], 8)` --returns-->

@@ -192,2 +192,16 @@ ✓ `'my/trimedExt.txt'` ---> `'my/trimedExt'`

#### `upath.removeExt(filename, ext)`
Removes the specific `ext` extension from filename, if it has it. Otherwise it leaves it as is.
As in all upath functions, it be `.ext` or `ext`.
##### Examples / specs
`upath.removeExt(filename, '.js')` --returns-->
✓ `'removedExt.js'` ---> `'removedExt'`
✓ `'removedExt.txt.js'` ---> `'removedExt.txt'`
✓ `'notRemoved.txt'` ---> `'notRemoved.txt'`
#### `upath.changeExt(filename, [ext], [ignoreExts], [maxSize=7])`

@@ -272,3 +286,24 @@

Copyright(c) 2014 Agelos Pikoulas (agelos.pikoulas@gmail.com)
87 passing (37ms)
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc