isbn3 1.2.18 → 1.2.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/get_group.js +15 -24
- package/package.json +2 -2
package/lib/get_group.js
CHANGED
|
@@ -1,32 +1,23 @@
|
|
|
1
1
|
const groups = require('./groups')
|
|
2
2
|
|
|
3
|
-
const groupsMap = {}
|
|
4
|
-
Object.keys(groups).forEach(groupPrefix => {
|
|
5
|
-
const [ prefix, group ] = groupPrefix.split('-')
|
|
6
|
-
const groupFirstDigit = group[0]
|
|
7
|
-
groupsMap[prefix] = groupsMap[prefix] || {}
|
|
8
|
-
groupsMap[prefix][groupFirstDigit] = groupsMap[prefix][groupFirstDigit] || {}
|
|
9
|
-
groupsMap[prefix][groupFirstDigit][group] = groups[groupPrefix]
|
|
10
|
-
})
|
|
11
|
-
|
|
12
3
|
module.exports = isbn13 => {
|
|
13
4
|
const prefix = isbn13.substring(0, 3)
|
|
14
|
-
if (!groupsMap[prefix]) return null
|
|
15
5
|
const restAfterPrefix = isbn13.substring(3)
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (restAfterPrefix.startsWith(groupPrefix)) {
|
|
23
|
-
return {
|
|
24
|
-
group: groupPrefix,
|
|
25
|
-
ranges: possibleGroups[groupPrefix].ranges,
|
|
26
|
-
restAfterGroup: restAfterPrefix.slice(groupPrefix.length)
|
|
27
|
-
}
|
|
28
|
-
}
|
|
6
|
+
const foundGroup = findGroup(prefix, restAfterPrefix, 5)
|
|
7
|
+
if (!foundGroup) return null
|
|
8
|
+
return {
|
|
9
|
+
group: foundGroup.groupId,
|
|
10
|
+
ranges: foundGroup.groupData.ranges,
|
|
11
|
+
restAfterGroup: restAfterPrefix.slice(foundGroup.groupId.length)
|
|
29
12
|
}
|
|
13
|
+
}
|
|
30
14
|
|
|
31
|
-
|
|
15
|
+
function findGroup (prefix, restAfterPrefix, maxGroupIdLength) {
|
|
16
|
+
let length = 0
|
|
17
|
+
while (length <= maxGroupIdLength) {
|
|
18
|
+
const groupId = restAfterPrefix.slice(0, length)
|
|
19
|
+
const groupData = groups[`${prefix}-${groupId}`]
|
|
20
|
+
if (groupData) return { groupId, groupData }
|
|
21
|
+
else length++
|
|
22
|
+
}
|
|
32
23
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "isbn3",
|
|
3
3
|
"description": "ISBN utils: parse, validate, format, audit",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.19",
|
|
5
5
|
"authors": [
|
|
6
6
|
"Hetappi <hetappi.pm@gmail.com>",
|
|
7
7
|
"Tadas S. <tadas@yoyo.lt>",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"engines": {
|
|
41
41
|
"node": ">= 6.4.0"
|
|
42
42
|
},
|
|
43
|
-
"dependencies": {},
|
|
44
43
|
"devDependencies": {
|
|
44
|
+
"@types/mocha": "^10.0.10",
|
|
45
45
|
"babel-cli": "^6.26.0",
|
|
46
46
|
"babel-preset-es2015": "^6.24.1",
|
|
47
47
|
"babelify": "^8.0.0",
|