Skip to content

Commit e2e032d

Browse files
committedFeb 2, 2015
Initial commit
0 parents  commit e2e032d

File tree

8 files changed

+180
-0
lines changed

8 files changed

+180
-0
lines changed
 

‎.editorconfig

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

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

‎.travis.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
language: node_js
2+
3+
node_js:
4+
- 0.10
5+
- 0.11

‎LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 John Otander
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

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# rgba-regex
2+
3+
[![Build Status](https://secure.travis-ci.org/regexps/rgba-regex.png?branch=master)](https://travis-ci.org/regexps/rgba-regex)
4+
5+
Regex for matching RGBA color strings.
6+
7+
## Installation
8+
9+
```bash
10+
npm install --save rgba-regex
11+
```
12+
13+
## Usage
14+
15+
```javascript
16+
var rgbaRegex = require('rgba-regex');
17+
18+
rgbaRegex({ exact: true }).test('rgba(12, 34, 56, .8)'); // => true
19+
rgbaRegex({ exact: true }).test('unicorns'); // -> false
20+
rgbaRegex({ exact: true }).test('rgba(,,,)'); // => false
21+
22+
rgbaRegex().exec('rgba(12, 34, 56, .8)');
23+
// => [
24+
// '12',
25+
// '34',
26+
// '56',
27+
// '.8'
28+
// index: 0,
29+
// input: 'rgba(12,34,56, .8)'
30+
// ]
31+
32+
'rgba(12, 34, 56, .8) cats and dogs'.match(rgbaRegex());
33+
// = ['rgba(12, 34, 56, .8)']
34+
```
35+
36+
## License
37+
38+
MIT
39+
40+
## Contributing
41+
42+
1. Fork it
43+
2. Create your feature branch (`git checkout -b my-new-feature`)
44+
3. Commit your changes (`git commit -am 'Add some feature'`)
45+
4. Push to the branch (`git push origin my-new-feature`)
46+
5. Create new Pull Request
47+
48+
Crafted with <3 by John Otander ([@4lpine](https://twitter.com/4lpine)).
49+
50+
***
51+
52+
> This package was initially generated with [yeoman](http://yeoman.io) and the [p generator](https://github.com/johnotander/generator-p.git).

‎index.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
module.exports = function rgbaRegex(options) {
4+
options = options || {};
5+
6+
return options.exact ?
7+
/^rgba\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3}),\s*(\d*(?:\.\d+)?)\)$/ :
8+
/rgba\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3}),\s*(\d*(?:\.\d+)?)\)/ig;
9+
}

‎package.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "rgba-regex",
3+
"description": "Regex for matching RGBA color strings.",
4+
"author": "John Otander",
5+
"version": "0.0.1",
6+
"main": "index.js",
7+
"directories": {
8+
"test": "test"
9+
},
10+
"scripts": {
11+
"test": "mocha test"
12+
},
13+
"repository": {
14+
"type": "git",
15+
"url": "https://github.com/johnotander/rgba-regex.git"
16+
},
17+
"keywords": [
18+
19+
],
20+
"license": "MIT",
21+
"bugs": {
22+
"url": "https://github.com/johnotander/rgba-regex/issues"
23+
},
24+
"homepage": "https://github.com/johnotander/rgba-regex",
25+
"dependencies": {},
26+
"devDependencies": {
27+
"mocha": "*"
28+
}
29+
}

‎test/test.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
var assert = require('assert');
2+
var rgbaRegex = require('..');
3+
4+
var rgbaStrings = [
5+
'rgba(12,34,56, 1)',
6+
'rgba(255, 255, 255, .9)',
7+
'rgba(1, 1,1, 0.2)'
8+
];
9+
10+
var inexactRgbaStrings = [
11+
'rgba(,,,)',
12+
'rGba(12,34,56,1)',
13+
'rgba(12, 34, 200,1) ',
14+
' rgba(12,34,56,1)',
15+
'rgba(1,2,,)'
16+
];
17+
18+
describe('rgba-regex', function() {
19+
20+
describe('exact: true', function() {
21+
22+
it('should return a regex that matches exact rgba strings', function() {
23+
rgbaStrings.forEach(function(rgba) {
24+
assert.ok(rgbaRegex({ exact: true }).test(rgba));
25+
});
26+
});
27+
28+
it('should return a regex that does not match invalid rgba strings', function() {
29+
inexactRgbaStrings.forEach(function(invalidRgba) {
30+
assert.ok(!rgbaRegex({ exact: true }).test(invalidRgba));
31+
});
32+
});
33+
});
34+
35+
describe('g', function() {
36+
37+
it('should match rgba strings', function() {
38+
assert.deepEqual(
39+
rgbaStrings.join('foobar').match(rgbaRegex()),
40+
rgbaStrings
41+
)
42+
});
43+
44+
it('should not match non rgba strings', function() {
45+
assert.deepEqual(
46+
inexactRgbaStrings.join('foobar').match(rgbaRegex()),
47+
['rGba(12,34,56,1)', 'rgba(12, 34, 200,1)', 'rgba(12,34,56,1)']
48+
);
49+
});
50+
});
51+
});

0 commit comments

Comments
 (0)
Please sign in to comment.