isbn3 1.2.16 → 1.2.18
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/audit.js +24 -4
- package/lib/split_isbn_parts.js +2 -1
- package/package.json +1 -1
package/lib/audit.js
CHANGED
|
@@ -10,6 +10,8 @@ module.exports = source => {
|
|
|
10
10
|
const clues = []
|
|
11
11
|
const normalizedIsbn = normalize(source)
|
|
12
12
|
|
|
13
|
+
if (!(normalizedIsbn.length === 13 || normalizedIsbn.length === 10)) throw new Error('invalid input length')
|
|
14
|
+
|
|
13
15
|
if (data) {
|
|
14
16
|
result.groupname = data.groupname
|
|
15
17
|
if (normalizedIsbn.length === 13) {
|
|
@@ -24,6 +26,9 @@ module.exports = source => {
|
|
|
24
26
|
} else if (normalizedIsbn.startsWith('979')) {
|
|
25
27
|
guessPrefixFromChecksum(normalizedIsbn, '978', clues)
|
|
26
28
|
}
|
|
29
|
+
if (clues.length === 0) {
|
|
30
|
+
suggestCorrectChecksum(normalizedIsbn, clues)
|
|
31
|
+
}
|
|
27
32
|
} else if (normalizedIsbn.length === 10) {
|
|
28
33
|
guessMissingPrefixFromChecksum(normalizedIsbn, '978', clues)
|
|
29
34
|
guessMissingPrefixFromChecksum(normalizedIsbn, '979', clues)
|
|
@@ -41,7 +46,7 @@ const considerAltPrefix = (normalizedIsbn, altPrefix, clues) => {
|
|
|
41
46
|
const candidateData = parse(`${candidateBase}${checkDigit}`)
|
|
42
47
|
if (candidateData != null) {
|
|
43
48
|
const { isbn13h, isbn13, groupname } = candidateData
|
|
44
|
-
clues.push({ message: '
|
|
49
|
+
clues.push({ message: 'Possible prefix error', candidate: isbn13h, isbn13, groupname })
|
|
45
50
|
}
|
|
46
51
|
}
|
|
47
52
|
|
|
@@ -50,7 +55,7 @@ const guessPrefixFromChecksum = (normalizedIsbn, altPrefix, clues) => {
|
|
|
50
55
|
const altPrefixData = parse(altPrefixIsbn)
|
|
51
56
|
if (altPrefixData != null) {
|
|
52
57
|
const { isbn13h, isbn13, groupname } = altPrefixData
|
|
53
|
-
clues.push({ message: '
|
|
58
|
+
clues.push({ message: 'Checksum hints different prefix', candidate: isbn13h, isbn13, groupname })
|
|
54
59
|
}
|
|
55
60
|
}
|
|
56
61
|
|
|
@@ -59,7 +64,7 @@ const guessUnprefixedFromChecksum = (normalizedIsbn, clues) => {
|
|
|
59
64
|
const unprefixData = parse(unprefixedIsbn)
|
|
60
65
|
if (unprefixData != null) {
|
|
61
66
|
const { isbn10h, isbn13, groupname } = unprefixData
|
|
62
|
-
clues.push({ message: '
|
|
67
|
+
clues.push({ message: 'Checksum hints that a 978 was added to an ISBN-10 without updating the checksum', candidate: isbn10h, isbn13, groupname })
|
|
63
68
|
}
|
|
64
69
|
}
|
|
65
70
|
|
|
@@ -68,8 +73,23 @@ const guessMissingPrefixFromChecksum = (normalizedIsbn, missingPrefix, clues) =>
|
|
|
68
73
|
const prefixData = parse(prefixedIsbn)
|
|
69
74
|
if (prefixData != null) {
|
|
70
75
|
const { isbn13h, isbn13, groupname } = prefixData
|
|
71
|
-
clues.push({ message: `
|
|
76
|
+
clues.push({ message: `Checksum hints that it is an ISBN-13 without its ${missingPrefix} prefix`, candidate: isbn13h, isbn13, groupname })
|
|
72
77
|
}
|
|
73
78
|
}
|
|
74
79
|
|
|
75
80
|
const normalize = input => input.replace(/[^\dX]/g, '')
|
|
81
|
+
|
|
82
|
+
const suggestCorrectChecksum = (normalizedIsbn, clues) => {
|
|
83
|
+
const candidateBase = normalizedIsbn.slice(0, -1)
|
|
84
|
+
const checkDigit = calculateCheckDigit(candidateBase)
|
|
85
|
+
const candidateData = parse(`${candidateBase}${checkDigit}`)
|
|
86
|
+
if (candidateData != null) {
|
|
87
|
+
const { isbn13h, isbn13, isbn10h, isbn10, groupname } = candidateData
|
|
88
|
+
const message = 'No alternative prefix or form could be found. Maybe the problem is the invalid checksum?'
|
|
89
|
+
if (normalizedIsbn.length === 13) {
|
|
90
|
+
clues.push({ message, candidate: isbn13h, isbn13, groupname })
|
|
91
|
+
} else {
|
|
92
|
+
clues.push({ message, candidate: isbn10h, isbn10, groupname })
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
package/lib/split_isbn_parts.js
CHANGED
|
@@ -21,11 +21,12 @@ const findValidCodes = isbn13 => {
|
|
|
21
21
|
// (so there won't be cases of the kind '2' > '199' === true)
|
|
22
22
|
if (min <= publisher && max >= publisher) {
|
|
23
23
|
const restAfterPublisher = restAfterGroup.substr(publisher.length)
|
|
24
|
+
const check = restAfterPublisher.slice(-1)
|
|
24
25
|
return {
|
|
25
26
|
group,
|
|
26
27
|
publisher,
|
|
27
28
|
article: restAfterPublisher.slice(0, -1),
|
|
28
|
-
check:
|
|
29
|
+
check: check === 'x' ? 'X' : check
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
}
|