@empyria/name 0.1.3 → 0.1.4
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/Name.js +12 -1
- package/package.json +1 -1
- package/test/Name.test.js +23 -0
package/lib/Name.js
CHANGED
|
@@ -92,6 +92,17 @@ export const TITLE_LIST = [
|
|
|
92
92
|
]
|
|
93
93
|
export const TITLES = enumise(TITLE_LIST)
|
|
94
94
|
|
|
95
|
+
// Honorifics as compact keys (transliterated, alphanumerics only, upper-case) — the form
|
|
96
|
+
// `nameFp` compares each token against. `TITLES` (an enumise() object) can't be used directly:
|
|
97
|
+
// it has no `.has`, its keys carry `_` separators, and its values keep original casing.
|
|
98
|
+
const TITLE_KEYS = new Set(
|
|
99
|
+
TITLE_LIST.map((t) =>
|
|
100
|
+
transliterate(t)
|
|
101
|
+
.toUpperCase()
|
|
102
|
+
.replace(/[^A-Z0-9]/g, ''),
|
|
103
|
+
),
|
|
104
|
+
)
|
|
105
|
+
|
|
95
106
|
export function findTitle(_title) {
|
|
96
107
|
if (!_title) return undefined
|
|
97
108
|
|
|
@@ -149,7 +160,7 @@ export function nameFp(value) {
|
|
|
149
160
|
.toUpperCase()
|
|
150
161
|
.split(' ')
|
|
151
162
|
.map((token) => token.replace(/[^A-Z0-9]/g, ''))
|
|
152
|
-
.filter((token) => token.length > 1 && !
|
|
163
|
+
.filter((token) => token.length > 1 && !TITLE_KEYS.has(token))
|
|
153
164
|
return [...new Set(tokens)].sort().join(' ')
|
|
154
165
|
}
|
|
155
166
|
|
package/package.json
CHANGED
package/test/Name.test.js
CHANGED
|
@@ -3,6 +3,10 @@ import {
|
|
|
3
3
|
TITLE_LIST,
|
|
4
4
|
TITLES,
|
|
5
5
|
findTitle,
|
|
6
|
+
fold,
|
|
7
|
+
idKey,
|
|
8
|
+
nameFp,
|
|
9
|
+
nameText,
|
|
6
10
|
TRANS,
|
|
7
11
|
capitalise,
|
|
8
12
|
shortify,
|
|
@@ -73,3 +77,22 @@ describe('re-exported string helpers (from @empyria/classification)', () => {
|
|
|
73
77
|
expect(slugify('Jean Pierre')).toBe('jean-pierre')
|
|
74
78
|
})
|
|
75
79
|
})
|
|
80
|
+
|
|
81
|
+
describe('fold / idKey / nameText / nameFp', () => {
|
|
82
|
+
test('idKey is format-agnostic', () => {
|
|
83
|
+
expect(idKey('5299 00 T8BM49')).toBe(idKey('529900t8bm49'))
|
|
84
|
+
expect(idKey('DE 123.456.789')).toBe('DE123456789')
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
test('nameText transliterates + lower-cases, keeps token spacing', () => {
|
|
88
|
+
expect(nameText(' José MÜLLER ')).toBe('jose muller')
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
test('nameFp is order / case / punctuation / honorific / script invariant', () => {
|
|
92
|
+
expect(nameFp('Steve Charles')).toBe(nameFp('Charles Steve'))
|
|
93
|
+
expect(nameFp('Dr. Steve Charles')).toBe(nameFp('charles, steve'))
|
|
94
|
+
expect(nameFp('Professor Ada Lovelace')).toBe(nameFp('lovelace, ada'))
|
|
95
|
+
expect(nameFp('Владимир Путин')).toBe(nameFp('Putin Vladimir'))
|
|
96
|
+
expect(nameFp('Mr.')).toBe('')
|
|
97
|
+
})
|
|
98
|
+
})
|