Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/k4m4/hash-length-regex
Retrieve the regular expression of a hash of specified bit-length.
https://github.com/k4m4/hash-length-regex
bit-length hash length regex regex-matcher
Last synced: 7 days ago
JSON representation
Retrieve the regular expression of a hash of specified bit-length.
- Host: GitHub
- URL: https://github.com/k4m4/hash-length-regex
- Owner: k4m4
- License: mit
- Created: 2018-05-24T18:32:36.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T16:14:12.000Z (almost 2 years ago)
- Last Synced: 2023-02-27T17:35:39.072Z (over 1 year ago)
- Topics: bit-length, hash, length, regex, regex-matcher
- Language: JavaScript
- Size: 527 KB
- Stars: 5
- Watchers: 2
- Forks: 2
- Open Issues: 7
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# hash-length-regex [![Build Status](https://travis-ci.org/k4m4/hash-length-regex.svg?branch=master)](https://travis-ci.org/k4m4/hash-length-regex) [![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/xojs/xo)
> Retrieve the regular expression of a hash of specified bit-length.
## Install
```
~ ❯❯❯ npm install hash-length-regex
```## Usage
```js
const hashLengthRegex = require('hash-length-regex');hashLengthRegex(128).test('nodejsrocks 1abcb33beeb811dca15f0ac3e47b88d9');
//=> truehashLengthRegex(128, {exact: true}).test('nodejsrocks 1abcb33beeb811dca15f0ac3e47b88d9 foo');
//=> falsehashLengthRegex(256, {exact: true}).test('4696a780a2051b5a0f422970904da794adc1b499b2f4583e778e100a0bdd79cc');
//=> true'nodejsrocks 1abcb33beeb811dca15f0ac3e47b88d9 rainbow 897b47d80a717715378832539b4c1340'.match(hashLengthRegex(128));
//=> ['1abcb33beeb811dca15f0ac3e47b88d9', '897b47d80a717715378832539b4c1340']
```## API
### hashLengthRegex (bitLength, [options])
Returns a regular expression for matching hashes of the specified bit-length.
#### bitLength
Type: `number`
Number of bits of desired hash.
#### options
##### options.exact
Type: `boolean`
Default: `false` *(Matches any hash in a string)*Only match an exact string. Useful with `RegExp#test()` to check if a string is a hash of given bit-length.
## License
MIT © [Nikolaos Kamarinakis](https://nikolaskama.me)