Skip to content

Commit 892134c

Browse files
committed
first commit
0 parents  commit 892134c

11 files changed

+304
-0
lines changed

.editorconfig

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.md]
13+
trim_trailing_whitespace = false
14+
15+
[test/fixtures/*]
16+
insert_final_newline = false
17+
trim_trailing_whitespace = false

.gitattributes

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Enforce Unix newlines
2+
*.* text eol=lf
3+
*.css text eol=lf
4+
*.html text eol=lf
5+
*.js text eol=lf
6+
*.json text eol=lf
7+
*.less text eol=lf
8+
*.md text eol=lf
9+
*.yml text eol=lf
10+
11+
*.jpg binary
12+
*.gif binary
13+
*.png binary
14+
*.jpeg binary

.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
*.sublime-*
2+
_gh_pages
3+
actual
4+
bower_components
5+
node_modules
6+
npm-debug.log
7+
temp
8+
test/actual
9+
tmp
10+
TODO.md
11+
vendor

.jshintrc

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"asi": false,
3+
"boss": true,
4+
"curly": true,
5+
"eqeqeq": true,
6+
"eqnull": true,
7+
"esnext": true,
8+
"immed": true,
9+
"latedef": true,
10+
"laxcomma": false,
11+
"newcap": true,
12+
"noarg": true,
13+
"node": true,
14+
"sub": true,
15+
"undef": true,
16+
"unused": true,
17+
"mocha": true
18+
}

.npmignore

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
*.sublime-*
2+
_gh_pages
3+
actual
4+
bower_components
5+
node_modules
6+
npm-debug.log
7+
temp
8+
test/actual
9+
tmp
10+
TODO.md
11+
vendor
12+
*.DS_Store
13+
14+
# npmignore
15+
.*
16+
test.js
17+
test

.verb.md

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# {%= name %} {%= badge("fury") %}
2+
3+
> {%= description %}
4+
5+
{%= include("install-npm", {save: true}) %}
6+
7+
## Usage
8+
9+
The regex is returned as a function.
10+
11+
```js
12+
var regex = require('{%= name %}');
13+
14+
var match = 'abc/xyz.md'.match(regex());
15+
//=> match[0] = 'xyz.md'
16+
//=> match[1] = 'xyz'
17+
//=> match[2] = '.md'
18+
19+
var match = 'abc/xyz'.match(regex());
20+
//=> match[0] = 'xyz'
21+
//=> match[1] = 'xyz'
22+
//=> match[2] = ''
23+
24+
var match = 'abc/.gitignore'.match(regex());
25+
//=> match[0] = '.gitignore'
26+
//=> match[1] = ''
27+
//=> match[2] = '.gitignore'
28+
```
29+
30+
## Run tests
31+
32+
Install dev dependencies:
33+
34+
```bash
35+
node i -d && mocha
36+
```
37+
38+
## Contributing
39+
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue]({%= bugs.url %})
40+
41+
## Author
42+
{%= include("author") %}
43+
44+
## License
45+
{%= copyright() %}
46+
{%= license() %}
47+
48+
***
49+
50+
{%= include("footer") %}

LICENSE

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

README.md

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# filename-regex [![NPM version](https://badge.fury.io/js/filename-regex.svg)](http://badge.fury.io/js/filename-regex)
2+
3+
> Regular expression for matching file names, with or without extension.
4+
5+
## Install with [npm](npmjs.org)
6+
7+
```bash
8+
npm i filename-regex --save
9+
```
10+
11+
## Usage
12+
13+
The regex is returned as a function.
14+
15+
```js
16+
var regex = require('filename-regex');
17+
18+
var match = 'abc/xyz.md'.match(regex());
19+
//=> match[0] = 'xyz.md'
20+
//=> match[1] = 'xyz'
21+
//=> match[2] = '.md'
22+
23+
var match = 'abc/xyz'.match(regex());
24+
//=> match[0] = 'xyz'
25+
//=> match[1] = 'xyz'
26+
//=> match[2] = ''
27+
28+
var match = 'abc/.gitignore'.match(regex());
29+
//=> match[0] = '.gitignore'
30+
//=> match[1] = ''
31+
//=> match[2] = '.gitignore'
32+
```
33+
34+
## Run tests
35+
36+
Install dev dependencies:
37+
38+
```bash
39+
node i -d && mocha
40+
```
41+
42+
## Contributing
43+
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/regexps/filename-regex/issues)
44+
45+
## Author
46+
47+
**Jon Schlinkert**
48+
49+
+ [github/regexps](https://github.com/regexps)
50+
+ [twitter/regexps](http://twitter.com/regexps)
51+
52+
## License
53+
Copyright (c) 2014 Jon Schlinkert
54+
Released under the MIT license
55+
56+
***
57+
58+
_This file was generated by [verb](https://github.com/assemble/verb) on December 28, 2014._

index.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*!
2+
* filename-regex <https://github.com/regexps/filename-regex>
3+
*
4+
* Copyright (c) 2014 Jon Schlinkert, contributors.
5+
* Licensed under the MIT license.
6+
*/
7+
8+
'use strict';
9+
10+
module.exports = function filenameRegex() {
11+
return /([^\\\/]*?[^\\\/]*?)(\.([^\\\/]*)|$)$/;
12+
};

package.json

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"name": "filename-regex",
3+
"description": "Regular expression for matching file names, with or without extension.",
4+
"version": "0.1.0",
5+
"homepage": "https://github.com/regexps/filename-regex",
6+
"author": {
7+
"name": "Jon Schlinkert",
8+
"url": "https://github.com/jonschlinkert"
9+
},
10+
"repository": {
11+
"type": "git",
12+
"url": "git://github.com/regexps/filename-regex.git"
13+
},
14+
"bugs": {
15+
"url": "https://github.com/regexps/filename-regex/issues"
16+
},
17+
"license": {
18+
"type": "MIT",
19+
"url": "https://github.com/regexps/filename-regex/blob/master/LICENSE-MIT"
20+
},
21+
"main": "index.js",
22+
"engines": {
23+
"node": ">=0.10.0"
24+
},
25+
"scripts": {
26+
"test": "mocha -R spec"
27+
},
28+
"keywords": [
29+
"base",
30+
"basename",
31+
"expression",
32+
"file",
33+
"filename",
34+
"filepath",
35+
"fs",
36+
"match",
37+
"name",
38+
"path",
39+
"regex",
40+
"regexp",
41+
"regular",
42+
"test"
43+
]
44+
}

test.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*!
2+
* filename-regex <https://github.com/regexps/filename-regex>
3+
*
4+
* Copyright (c) 2014 Jon Schlinkert, contributors.
5+
* Licensed under the MIT License
6+
*/
7+
8+
'use strict';
9+
10+
var assert = require('assert');
11+
var re = require('./');
12+
13+
it('should match the last part of a file path:', function () {
14+
assert.equal(re().exec('xyz')[0], 'xyz');
15+
assert.equal(re().exec('a/xyz')[0], 'xyz');
16+
assert.equal(re().exec('a/b/c/d')[0], 'd');
17+
assert.equal(re().exec('a/b/c/xyz')[0], 'xyz');
18+
});
19+
20+
it('should match the parts in a filename:', function () {
21+
assert.equal(re().exec('abc/xyz.md')[0], 'xyz.md');
22+
assert.equal(re().exec('abc/xyz.md')[1], 'xyz');
23+
assert.equal(re().exec('abc/xyz.md')[2], '.md');
24+
});
25+
26+
it('should match a file extension:', function () {
27+
assert.equal(re().exec('.md')[1], '');
28+
assert.equal(re().exec('.md')[1], '');
29+
assert.equal(re().exec('.md')[2], '.md');
30+
});
31+
32+
it('should match a dotfile:', function () {
33+
assert.equal(re().exec('abc/.gitignore')[0], '.gitignore');
34+
assert.equal(re().exec('abc/.gitignore')[1], '');
35+
assert.equal(re().exec('abc/.gitignore')[2], '.gitignore');
36+
});
37+
38+
it('should match a path with dots in the dirname:', function () {
39+
assert.equal(re().exec('a/.b/abc.foo.min.js')[0], 'abc.foo.min.js');
40+
assert.equal(re().exec('a/.b/abc.foo.min.js')[1], 'abc');
41+
assert.equal(re().exec('a/.b/abc.foo.min.js')[2], '.foo.min.js');
42+
});

0 commit comments

Comments
 (0)