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.2 to 0.1.3

48

build/code/upath.js
/*!
* upath - version 0.1.2
* Compiled on 2014-10-29
* upath - version 0.1.3
* Compiled on 2014-10-30
* git://github.com/anodynos/upath

@@ -8,5 +8,5 @@ * Copyright(c) 2014 Agelos Pikoulas (agelos.pikoulas@gmail.com )

*/
var VERSION = '0.1.2'; //injected by grunt:concat
var VERSION = '0.1.3'; //injected by grunt:concat
// Generated by CoffeeScript 1.8.0
var extraFn, extraFunctions, fName, fn, name, path, upath, _,
var extraFn, extraFunctions, fName, fn, isValidExt, name, path, upath, _,
__slice = [].slice,

@@ -75,20 +75,30 @@ __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; };

},
trimExt: function(file) {
return file.slice(0, +((file.length - upath.extname(file).length) - 1) + 1 || 9e9);
trimExt: function(filename, ignoreExts, maxSize) {
var oldExt;
if (maxSize == null) {
maxSize = 7;
}
oldExt = upath.extname(filename);
if (isValidExt(oldExt, ignoreExts, maxSize)) {
return filename.slice(0, +((filename.length - oldExt.length) - 1) + 1 || 9e9);
} else {
return filename;
}
},
changeExt: function(file, ext) {
return upath.trimExt(file) + (!ext ? '' : ext[0] === '.' ? ext : '.' + ext);
changeExt: function(filename, ext, ignoreExts, maxSize) {
if (maxSize == null) {
maxSize = 7;
}
return upath.trimExt(filename, ignoreExts, maxSize) + (!ext ? '' : ext[0] === '.' ? ext : '.' + ext);
},
defaultExt: function(file, ext, ignoreExts, maxSize) {
defaultExt: function(filename, ext, ignoreExts, maxSize) {
var oldExt;
if (maxSize == null) {
maxSize = 6;
maxSize = 7;
}
oldExt = upath.extname(file);
if ((oldExt && (oldExt.length <= maxSize)) && (__indexOf.call(_.map(ignoreExts, function(e) {
return (e && (e[0] !== '.') ? '.' : '') + e;
}), oldExt) < 0)) {
return file;
oldExt = upath.extname(filename);
if (isValidExt(oldExt, ignoreExts, maxSize)) {
return filename;
} else {
return upath.addExt(file, ext);
return upath.addExt(filename, ext);
}

@@ -98,2 +108,8 @@ }

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) {

@@ -100,0 +116,0 @@ 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.2",
"version": "0.1.3",
"homepage": "http://github.com/anodynos/upath/",

@@ -6,0 +6,0 @@ "author": {

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

# upath v0.1.2
# upath v0.1.3

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

* Adds methods to add, trim, change, and default filename extensions.
* Adds **filename extensions** functions `addExt`, `trimExt`, `changeExt`, and `defaultExt`.
* Add a `normalizeSafe` method to preserve any meaningful leading `./` & a `normalizeTrim` which additionally trims any useless ending `/`.
* Add a `normalizeSafe` function to preserve any meaningful leading `./` & a `normalizeTrim` which additionally trims any useless ending `/`.
**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.**
## Why ?

@@ -53,3 +52,3 @@

## Added methods
## Added functions

@@ -102,11 +101,16 @@

## Added methods for *filename extension* manipulation.
## Added functions for *filename extension* manipulation.
**Happy notes:**
* All methods support `.ext` & `ext` - the dot `.` on the extension is always adjusted correctly.
In all functions you can:
* You can omit the `ext` param in all methods (or pass null/undefined) and the common sense thing will happen.
* use both `.ext` & `ext` - the dot `.` on the extension is always adjusted correctly.
* omit the `ext` param (pass null/undefined/empty string) and the common sense thing will happen.
* ignore specific extensions from being considered as valid ones (eg `.min`, `.dev` `.aLongExtIsNotAnExt` etc), hence no trimming or replacement takes place on them.
#### `upath.addExt(filename, [ext])`

@@ -136,6 +140,10 @@

#### `upath.trimExt(filename)`
#### `upath.trimExt(filename, [ignoreExts], [maxSize=7])`
Trims a filename's extension.
* Extensions are considered to be up to `maxSize` chars long, counting the dot (defaults to 7).
* An `Array` of `ignoreExts` (eg `['.min']`) prevents these from being considered as extension, thus are not trimmed.
##### Examples / specs

@@ -145,19 +153,37 @@

✓ `'my/trimedExt.txt'` ---> `'my/trimedExt`'
✓ `'my/trimedExt'` ---> `'my/trimedExt`'
✓ `'my/trimedExt.min.js'` ---> `'my/trimedExt.min`'
✓ `'../my/trimedExt.longExt'` ---> `'../my/trimedExt`'
✓ `'my/trimedExt.txt'` ---> `'my/trimedExt`'
✓ `'my/trimedExt'` ---> `'my/trimedExt`'
✓ `'my/trimedExt.min'` ---> `'my/trimedExt`'
✓ `'my/trimedExt.min.js'` ---> `'my/trimedExt.min`'
✓ `'../my/trimedExt.longExt'` ---> `'../my/trimedExt.longExt`'
#### `upath.changeExt(filename, [ext])`
It is ignoring `.min` & `.dev` as extensions, and considers exts with up to 8 chars.
Changes a filename's extension to `ext`. If it has no extension, it adds it.
`upath.trimExt(filename, ['min', '.dev'], 8)` --returns-->
✓ `'my/trimedExt.txt'` ---> `'my/trimedExt`'
✓ `'my/trimedExt.min'` ---> `'my/trimedExt.min`'
✓ `'my/trimedExt.dev'` ---> `'my/trimedExt.dev`'
✓ `'../my/trimedExt.longExt'` ---> `'../my/trimedExt`'
✓ `'../my/trimedExt.longRExt'` ---> `'../my/trimedExt.longRExt`'
#### `upath.changeExt(filename, [ext], [ignoreExts], [maxSize=7])`
Changes a filename's extension to `ext`. If it has no (valid) extension, it adds it.
* Valid extensions are considered to be up to `maxSize` chars long, counting the dot (defaults to 7).
* An `Array` of `ignoreExts` (eg `['.min']`) prevents these from being considered as extension, thus are not changed - the new extension is added instead.
##### Examples / specs
`upath.changeExt(filename, 'js')` --returns-->
`upath.changeExt(filename, '.js')` --returns-->
✓ `'my/module.coffee'` ---> `'my/module.js`'
✓ `'my/module'` ---> `'my/module.js`'
✓ `'file/withDot.'` ---> `'file/withDot.js`'
✓ `'my/module.min'` ---> `'my/module.js`'
✓ `'my/module.coffee'` ---> `'my/module.js`'
✓ `'my/module'` ---> `'my/module.js`'
✓ `'file/withDot.'` ---> `'file/withDot.js`'
✓ `'file/change.longExt'` ---> `'file/change.longExt.js`'

@@ -169,14 +195,27 @@

✓ `'my/module.coffee'` ---> `'my/module`'
✓ `'my/module'` ---> `'my/module`'
✓ `'file/withDot.'` ---> `'file/withDot`'
✓ `'my/module.min'` ---> `'my/module`'
✓ `'my/module.coffee'` ---> `'my/module`'
✓ `'my/module'` ---> `'my/module`'
✓ `'file/withDot.'` ---> `'file/withDot`'
✓ `'file/change.longExt'` ---> `'file/change.longExt`'
#### `upath.defaultExt(filename, [ext], [ignoreExts], [maxSize=6])`
It is ignoring `.min` & `.dev` as extensions, and considers exts with up to 8 chars.
`upath.changeExt(filename, 'js', ['min', '.dev'], 8)` --returns-->
✓ `'my/module.coffee'` ---> `'my/module.js`'
✓ `'file/notValidExt.min'` ---> `'file/notValidExt.min.js`'
✓ `'file/notValidExt.dev'` ---> `'file/notValidExt.dev.js`'
✓ `'file/change.longExt'` ---> `'file/change.js`'
✓ `'file/change.longRExt'` ---> `'file/change.longRExt.js`'
#### `upath.defaultExt(filename, [ext], [ignoreExts], [maxSize=7])`
Adds `.ext` to `filename`, only if it doesn't already have _any_ *old* extension.
* (Old) extensions are considered to be up to `maxSize` chars long, counting the dot (defaults to 6).
* (Old) extensions are considered to be up to `maxSize` chars long, counting the dot (defaults to 7).
* An `Array` of `ignoreExts` (eg [`.min`]) will force adding default `.ext` even if one of these is present.
* An `Array` of `ignoreExts` (eg `['.min']`) will force adding default `.ext` even if one of these is present.

@@ -203,5 +242,5 @@ ##### Examples / specs

It is ignoring `.min` & `.dev` as extensions, and considers exts with up to 8 chars (incl dot) as extensions.
It is ignoring `.min` & `.dev` as extensions, and considers exts with up to 8 chars.
`upath.defaultExt(filename, 'js', ['min', 'dev'], 8)` --returns-->
`upath.defaultExt(filename, 'js', ['min', '.dev'], 8)` --returns-->

@@ -215,3 +254,3 @@ ✓ `'fileWith/defaultExt'` ---> `'fileWith/defaultExt.js`'

65 passing (24ms)
80 passing (31ms)

@@ -218,0 +257,0 @@ # License

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