Regular expression for matching hex color values from string.
Installations
npm install hex-color-regex
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
8.0.0
NPM Version
5.0.0
Score
99.9
Supply Chain
99.5
Quality
75.2
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
Download Statistics
Total Downloads
1,407,054,310
Last Day
385,227
Last Week
1,729,553
Last Month
8,286,537
Last Year
128,458,917
GitHub Statistics
33 Stars
40 Commits
6 Forks
12 Watching
1 Branches
12 Contributors
Bundle Size
332.00 B
Minified
228.00 B
Minified + Gzipped
Package Meta Information
Latest Version
1.1.0
Package Id
hex-color-regex@1.1.0
Size
6.13 kB
NPM Version
5.0.0
Node Version
8.0.0
Publised On
03 Jun 2017
Total Downloads
Cumulative downloads
Total Downloads
1,407,054,310
Last day
-4.9%
385,227
Compared to previous day
Last week
-20.7%
1,729,553
Compared to previous week
Last month
2.7%
8,286,537
Compared to previous month
Last year
-32.6%
128,458,917
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
1
hex-color-regex
The best regular expression (regex) for matching hex color values from string.
Install
npm i hex-color-regex --save
npm test
Usage
For more use-cases see the tests
[opts]
{Object} passstrict: true
for strict modereturn
{RegExp}
Example
1var hexColorRegex = require('hex-color-regex') 2 3hexColorRegex().test('#f3f}') //=> true 4hexColorRegex({strict: true}).test('#f3f}') //=> false 5 6hexColorRegex().test('foo #f3f bar') //=> true 7hexColorRegex({strict: true}).test('foo #f3f bar') //=> false 8 9hexColorRegex().test('#a54f2c}') //=> true 10hexColorRegex({strict: true}).test('#a54f2c}') //=> false 11 12hexColorRegex().test('foo #a54f2c bar') //=> true 13hexColorRegex({strict: true}).test('foo #a54f2c bar') //=> false 14 15hexColorRegex().test('#ffff') //=> false 16hexColorRegex().test('ffff') //=> false 17 18hexColorRegex().test('#fff') //=> true 19hexColorRegex().test('fff') //=> false 20 21hexColorRegex().test('#4g1') //=> false 22hexColorRegex().test('4g1') //=> false 23hexColorRegex().test('#zY1') //=> false 24hexColorRegex().test('zY1') //=> false 25hexColorRegex().test('#7f68ZY') //=> false 26hexColorRegex().test('7f68ZY') //=> false 27hexColorRegex().test('ffffff') //=> false 28 29hexColorRegex().test('#afebe3') //=> true 30hexColorRegex().test('#AFEBE3') //=> true 31hexColorRegex().test('#3cb371') //=> true 32hexColorRegex().test('#3CB371') //=> true 33hexColorRegex().test('#556b2f') //=> true 34hexColorRegex().test('#556B2F') //=> true 35hexColorRegex().test('#708090') //=> true 36hexColorRegex().test('#7b68ee') //=> true 37hexColorRegex().test('#7B68EE') //=> true 38hexColorRegex().test('#eeeeee') //=> true 39hexColorRegex().test('#ffffff') //=> true 40hexColorRegex().test('#111111') //=> true 41 42hexColorRegex().test('#afe') //=> true 43hexColorRegex().test('#AF3') //=> true 44hexColorRegex().test('#3cb') //=> true 45hexColorRegex().test('#3CB') //=> true 46hexColorRegex().test('#b2f') //=> true 47hexColorRegex().test('#5B2') //=> true 48hexColorRegex().test('#708') //=> true 49hexColorRegex().test('#68e') //=> true 50hexColorRegex().test('#7AF') //=> true 51hexColorRegex().test('#777') //=> true 52hexColorRegex().test('#FFF') //=> true 53hexColorRegex().test('#fff') //=> true
Matching groups
match[0]
hex value with hash -#f3f3f3
match[1]
hex value without the hash -f3f3f3
Example
1hexColorRegex().exec('foo #fff bar') 2//=> [ '#fff', 'fff', index: 4, input: 'foo #fff bar' ] 3 4hexColorRegex({strict: true}).exec('foo #fff bar') 5//=> null 6 7hexColorRegex().exec('foo #f3f3f3 bar') 8//=> [ '#f3f3f3', 'f3f3f3', index: 4, input: 'foo #f3f3f3 bar' ] 9 10hexColorRegex({strict: true}).exec('foo #f3f3f3 bar') 11//=> null
Related
- benz: Compose your control flow with absolute elegance. Support async/await, callbacks, thunks, generators, promises, observables, child… more
- is-hexcolor: Check that given value is valid hex color, using
hex-color-regex
- the best regex for… more - is-ansi: Check that given string contain ANSI color codes, without CLI
- is-missing: Check that given
name
oruser/repo
exists in npm registry or in github as user… more - is-kindof: Check type of given javascript value. Support promises, generators, streams, and native types. Thin wrapper… more
- is-typeof-error: Check that given value is any type of error and instanceof Error
- is-async-function: Check that given function is async (callback) function or not. Trying to guess that based… more
- kind-error: Correct inheriting from
Error
. Supports constructing from an object of properties - focused on assertion. - kind-of-extra: Extends
kind-of
type check utility with support for promises, generators, streams and errors. Like `kindof(Promise.resolve(1))… more - vez: Middleware composition at new level. Ultimate alternative to
ware
,plugins
,koa-compose
andcomposition
packages. Allows… more
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.
Charlike Make Reagent
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE.md:0
- Info: FSF or OSI recognized license: MIT License: LICENSE.md:0
Reason
1 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-jv35-xqg7-f92r
Reason
Found 3/28 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 5 are checked with a SAST tool
Score
3
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to hex-color-regex
@types/hex-color-regex
TypeScript definitions for hex-color-regex
color-regex
Color regex. Easily check the format of any color. Use diverse color helpers available to verify any color.
is-hexcolor
Check that given value is valid hex color, using `hex-color-regex` - the best regex for matching hex color values
hexa-color-regex
regex for the future spec of hexa (hex with alpha)