Skip to content

Commit

Permalink
Merge pull request #33 from yucho/master
Browse files Browse the repository at this point in the history
Make `removeExt` ignore `maxSize`
  • Loading branch information
anodynos committed Sep 2, 2019
2 parents 611e986 + 43aea64 commit 1f264ed
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
12 changes: 10 additions & 2 deletions readme.md
Expand Up @@ -206,7 +206,7 @@ Trims a filename's extension.

It is ignoring `.min` & `.dev` as extensions, and considers exts with up to 8 chars.

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

✓ `'my/trimedExt.txt'` ---> `'my/trimedExt'`
✓ `'my/trimedExt.min'` ---> `'my/trimedExt.min'`
Expand All @@ -227,7 +227,15 @@ As in all upath functions, it be `.ext` or `ext`.
✓ `'removedExt.js'` ---> `'removedExt'`
✓ `'removedExt.txt.js'` ---> `'removedExt.txt'`
✓ `'notRemoved.txt'` ---> `'notRemoved.txt'`

It does not care about the length of exts.

`upath.removeExt(filename, '.longExt')` --returns-->

✓ `'removedExt.longExt'` ---> `'removedExt'`
✓ `'removedExt.txt.longExt'` ---> `'removedExt.txt'`
✓ `'notRemoved.txt'` ---> `'notRemoved.txt'`


#### `upath.changeExt(filename, [ext], [ignoreExts], [maxSize=7])`

Expand Down
2 changes: 1 addition & 1 deletion source/code/upath.coffee
Expand Up @@ -86,7 +86,7 @@ extraFunctions =
else
ext = if ext[0] is '.' then ext else '.' + ext
if upath.extname(filename) is ext
upath.trimExt filename
upath.trimExt filename, [], ext.length
else
filename

Expand Down
16 changes: 15 additions & 1 deletion source/spec/upath-spec.coffee
Expand Up @@ -358,7 +358,7 @@ describe "\n# upath v#{VERSION}", ->
describe """\n
It is ignoring `.min` & `.dev` as extensions, and considers exts with up to 8 chars.
`upath.removeExt(filename, ['min', '.dev'], 8)` --returns-->\n
`upath.trimExt(filename, ['min', '.dev'], 8)` --returns-->\n
""", ->
inputToExpected =
'my/trimedExt.txt': 'my/trimedExt'
Expand Down Expand Up @@ -388,6 +388,20 @@ describe "\n# upath v#{VERSION}", ->
runSpec inputToExpected, (input, expected)-> ->
equal upath.removeExt(input, '.js'), expected
equal upath.removeExt(input, 'js'), expected

describe """\n
It does not care about the length of exts.
`upath.removeExt(filename, '.longExt')` --returns-->\n
""", ->
inputToExpected =
'removedExt.longExt': 'removedExt'
'removedExt.txt.longExt': 'removedExt.txt'
'notRemoved.txt': 'notRemoved.txt'

runSpec inputToExpected, (input, expected)-> ->
equal upath.removeExt(input, '.longExt'), expected
equal upath.removeExt(input, 'longExt'), expected

describe """\n
#### `upath.changeExt(filename, [ext], [ignoreExts], [maxSize=7])`
Expand Down

0 comments on commit 1f264ed

Please sign in to comment.