Skip to content

Commit 458e489

Browse files
yocontraphated
authored andcommitted
New: First implementation
0 parents  commit 458e489

File tree

8 files changed

+179
-0
lines changed

8 files changed

+179
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.DS_Store
2+
*.log
3+
node_modules
4+
build
5+
*.node
6+
components

.npmignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.DS_Store
2+
*.log
3+
node_modules
4+
build
5+
*.node
6+
components

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
language: node_js
2+
node_js:
3+
- "0.7"
4+
- "0.8"
5+
- "0.9"
6+
- "0.10"
7+
after_script:
8+
- npm run coveralls

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2014 Fractal <[email protected]>
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# replace-ext [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Dependency Status][david-image]][david-url]
2+
3+
4+
## Information
5+
6+
<table>
7+
<tr>
8+
<td>Package</td><td>replace-ext</td>
9+
</tr>
10+
<tr>
11+
<td>Description</td>
12+
<td>Replaces a file extension with another one</td>
13+
</tr>
14+
<tr>
15+
<td>Node Version</td>
16+
<td>>= 0.4</td>
17+
</tr>
18+
</table>
19+
20+
## Usage
21+
22+
```javascript
23+
var replaceExt = require('replace-ext');
24+
25+
var path = '/some/dir/file.js';
26+
var npath = replaceExt(path, '.coffee');
27+
28+
console.log(npath); // /some/dir/file.coffee
29+
```
30+
31+
[npm-url]: https://npmjs.org/package/replace-ext
32+
[npm-image]: https://badge.fury.io/js/replace-ext.png
33+
34+
[travis-url]: https://travis-ci.org/wearefractal/replace-ext
35+
[travis-image]: https://travis-ci.org/wearefractal/replace-ext.png?branch=master
36+
37+
[coveralls-url]: https://coveralls.io/r/wearefractal/replace-ext
38+
[coveralls-image]: https://coveralls.io/repos/wearefractal/replace-ext/badge.png
39+
40+
[depstat-url]: https://david-dm.org/wearefractal/replace-ext
41+
[depstat-image]: https://david-dm.org/wearefractal/replace-ext.png
42+
43+
[david-url]: https://david-dm.org/wearefractal/replace-ext
44+
[david-image]: https://david-dm.org/wearefractal/replace-ext.png?theme=shields.io

index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var path = require('path');
2+
3+
module.exports = function(npath, ext) {
4+
if (typeof npath !== 'string') return npath;
5+
if (npath.length === 0) return npath;
6+
7+
var nFileName = path.basename(npath, path.extname(npath))+ext;
8+
return path.join(path.dirname(npath), nFileName);
9+
};

package.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name":"replace-ext",
3+
"description":"Replaces a file extension with another one",
4+
"version":"0.0.0",
5+
"homepage":"http://github.com/wearefractal/replace-ext",
6+
"repository":"git://github.com/wearefractal/replace-ext.git",
7+
"author":"Fractal <[email protected]> (http://wearefractal.com/)",
8+
"main":"./index.js",
9+
10+
"dependencies":{
11+
12+
},
13+
"devDependencies": {
14+
"mocha": "~1.17.0",
15+
"should": "~3.1.0",
16+
"mocha-lcov-reporter": "~0.0.1",
17+
"coveralls": "~2.6.1",
18+
"istanbul": "~0.2.3",
19+
"rimraf": "~2.2.5",
20+
"jshint": "~2.4.1"
21+
},
22+
"scripts": {
23+
"test": "mocha --reporter spec && jshint",
24+
"coveralls": "istanbul cover _mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage"
25+
},
26+
"engines": {
27+
"node": ">= 0.4"
28+
},
29+
"licenses":[
30+
{
31+
"type":"MIT",
32+
"url":"http://github.com/wearefractal/replace-ext/raw/master/LICENSE"
33+
}
34+
]
35+
}

test/main.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
var replaceExt = require('../');
2+
var path = require('path');
3+
var should = require('should');
4+
require('mocha');
5+
6+
describe('replace-ext', function() {
7+
it('should return a valid replaced extension on nested', function(done) {
8+
var fname = path.join(__dirname, './fixtures/test.coffee');
9+
var expected = path.join(__dirname, './fixtures/test.js');
10+
var nu = replaceExt(fname, '.js');
11+
should.exist(nu);
12+
nu.should.equal(expected);
13+
done();
14+
});
15+
16+
it('should return a valid replaced extension on flat', function(done) {
17+
var fname = 'test.coffee';
18+
var expected = 'test.js';
19+
var nu = replaceExt(fname, '.js');
20+
should.exist(nu);
21+
nu.should.equal(expected);
22+
done();
23+
});
24+
25+
it('should not return a valid replaced extension on empty string', function(done) {
26+
var fname = '';
27+
var expected = '';
28+
var nu = replaceExt(fname, '.js');
29+
should.exist(nu);
30+
nu.should.equal(expected);
31+
done();
32+
});
33+
34+
it('should return a valid removed extension on nested', function(done) {
35+
var fname = path.join(__dirname, './fixtures/test.coffee');
36+
var expected = path.join(__dirname, './fixtures/test');
37+
var nu = replaceExt(fname, '');
38+
should.exist(nu);
39+
nu.should.equal(expected);
40+
done();
41+
});
42+
43+
it('should return a valid added extension on nested', function(done) {
44+
var fname = path.join(__dirname, './fixtures/test');
45+
var expected = path.join(__dirname, './fixtures/test.js');
46+
var nu = replaceExt(fname, '.js');
47+
should.exist(nu);
48+
nu.should.equal(expected);
49+
done();
50+
});
51+
});

0 commit comments

Comments
 (0)