File tree 7 files changed +64
-0
lines changed
7 files changed +64
-0
lines changed Original file line number Diff line number Diff line change
1
+ * text eol =lf
Original file line number Diff line number Diff line change
1
+ . *
2
+ * .log
3
+ spec.js
Original file line number Diff line number Diff line change
1
+ package-lock = false
2
+ access = public
Original file line number Diff line number Diff line change
1
+ # rmext [ ![ ] ( https://img.shields.io/npm/v/rmext.svg )] ( https://www.npmjs.com/package/rmext ) [ ![ ] ( https://img.shields.io/badge/source--000000.svg?logo=github&style=social )] ( https://github.com/omrilotan/mono/tree/master/packages/rmext )
2
+
3
+ ## ✂️ Remove file extension
4
+
5
+ ``` js
6
+ const rmext = require (' rmext' );
7
+
8
+ rmext (' /workspace/application/file.json' ); // '/workspace/application/file'
9
+ ```
Original file line number Diff line number Diff line change
1
+ const { extname } = require ( 'path' ) ;
2
+
3
+ /**
4
+ * Remove file extension
5
+ * @param {String } name
6
+ * @return {String }
7
+ */
8
+ module . exports = name => name . replace ( new RegExp ( extname ( name ) + '$' ) , '' ) ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " rmext" ,
3
+ "version" : " 0.0.1" ,
4
+ "description" : " ✂️ Remove file extension" ,
5
+ "keywords" : [
6
+ " remove" ,
7
+ " file" ,
8
+ " extension" ,
9
+ " extname"
10
+ ],
11
+ "author" : " omrilotan" ,
12
+ "license" : " MIT" ,
13
+ "repository" : {
14
+ "type" : " git" ,
15
+ "url" : " git+https://github.com/omrilotan/mono.git"
16
+ },
17
+ "homepage" : " https://omrilotan.com/mono/rmext/" ,
18
+ "main" : " index.js" ,
19
+ "scripts" : {
20
+ "test" : " cd ../../; npm t packages/rmext; cd -"
21
+ }
22
+ }
Original file line number Diff line number Diff line change
1
+ const rmext = require ( '.' ) ;
2
+
3
+ describe ( 'rmext' , ( ) => {
4
+ it ( 'Should remove extname from file path' , ( ) => {
5
+ expect ( rmext ( '/workspace/application/file.json' ) ) . to . equal ( '/workspace/application/file' ) ;
6
+ } ) ;
7
+ it ( 'Should remove extname from file URL' , ( ) => {
8
+ expect ( rmext ( 'https://www.website.com/directory/page.html' ) ) . to . equal ( 'https://www.website.com/directory/page' ) ;
9
+ } ) ;
10
+ it ( 'Should strip only last charecters from filename' , ( ) => {
11
+ expect ( rmext ( 'file.name.with.dots.extension' ) ) . to . equal ( 'file.name.with.dots' ) ;
12
+ } ) ;
13
+ it ( 'Should leave files with no extensions' , ( ) => {
14
+ expect ( rmext ( '/workspace/application/notes' ) ) . to . equal ( '/workspace/application/notes' ) ;
15
+ } ) ;
16
+ it ( 'Should leave dotfiles' , ( ) => {
17
+ expect ( rmext ( '/workspace/application/.gitignore' ) ) . to . equal ( '/workspace/application/.gitignore' ) ;
18
+ } ) ;
19
+ } ) ;
You can’t perform that action at this time.
0 commit comments