-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
46 lines (37 loc) · 944 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'use strict'
const ripemdRegExps = {
128: '[a-f0-9]{32}',
160: '[a-f0-9]{40}',
256: '[a-f0-9]{64}',
320: '[a-f0-9]{80}'
}
function buildRegExp(bodyExp, options) {
let beginning = '\\b(?:'
let end = ')\\b'
if (options && options.exact) {
beginning = '^('
end = ')$'
}
const regExp = beginning + bodyExp + end
if (options && options.exact) {
return new RegExp(regExp)
}
return new RegExp(regExp, 'g')
}
const ripemdRegex = options => {
const individualRegExps = []
for (const version in ripemdRegExps) {
const oneRegExp = '(?:' + ripemdRegExps[version] + ')'
individualRegExps.push(oneRegExp)
}
const bodyExp = individualRegExps.join('|')
return buildRegExp(bodyExp, options)
}
ripemdRegex.version = (version, options) => {
if (!ripemdRegExps[version]) {
throw new Error('Invalid hash version')
}
const bodyExp = ripemdRegExps[version]
return buildRegExp(bodyExp, options)
}
module.exports = ripemdRegex