@maskera/core 0.7.3 → 0.7.5

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/dist/index.d.cts CHANGED
@@ -52,7 +52,7 @@ declare function canonicalize(input: string): CanonicalText;
52
52
  * Built-in PII labels. The `string` fallback lets you add custom detectors
53
53
  * with arbitrary labels without fighting the type system.
54
54
  */
55
- type PiiLabel = "PERSONNUMMER" | "SAMORDNINGSNUMMER" | "ORGANISATIONSNUMMER" | "EPOST" | "TELEFON" | "POSTNUMMER" | "BANKGIRO" | "PLUSGIRO" | "IBAN" | "IP_ADRESS" | "URL" | "KORTNUMMER" | "ADRESS" | "LAGENHETSNUMMER" | "REGNUMMER" | (string & {});
55
+ type PiiLabel = "PERSONNUMMER" | "SAMORDNINGSNUMMER" | "ORGANISATIONSNUMMER" | "EPOST" | "TELEFON" | "POSTNUMMER" | "BANKGIRO" | "PLUSGIRO" | "IBAN" | "IP_ADRESS" | "URL" | "KORTNUMMER" | "KONTONUMMER" | "JOURNALNUMMER" | "ADRESS" | "LAGENHETSNUMMER" | "REGNUMMER" | (string & {});
56
56
  /** A raw match found by a detector, before placeholder assignment. */
57
57
  interface Detection {
58
58
  /** Inclusive start index into the source string. */
@@ -102,19 +102,28 @@ interface RedactResult {
102
102
  * that can reject false positives (e.g. a number that fails a checksum).
103
103
  */
104
104
  declare function regexDetector(label: PiiLabel, regex: RegExp, validate?: (value: string) => boolean): Detector;
105
- /** Personnummer: YYYYMMDD-XXXX / YYMMDD-XXXX, `-` or `+` separator optional. */
105
+ /**
106
+ * Personnummer: YYYYMMDD-XXXX / YYMMDD-XXXX, `-` or `+` separator optional.
107
+ * Validates on date shape only, NOT Luhn: a mistyped control digit is the most
108
+ * common way a real personnummer appears in customer data, and rejecting it
109
+ * leaks exactly what we are here to mask (see isPersonnummerShape).
110
+ */
106
111
  declare const personnummer: Detector;
107
- /** Samordningsnummer: personnummer-shaped but with day + 60. */
112
+ /** Samordningsnummer: personnummer-shaped but with day + 60. Same no-Luhn policy. */
108
113
  declare const samordningsnummer: Detector;
109
114
  /** Organisationsnummer: NNNNNN-NNNN, Luhn-checked, third digit >= 2. */
110
115
  declare const organisationsnummer: Detector;
111
116
  declare const email: Detector;
112
117
  /**
113
- * Swedish phone numbers: +46 / 0 prefix, mobile and landline, including the
118
+ * Phone numbers. Swedish: +46 / 0 prefix, mobile and landline, including the
114
119
  * e-mail-signature style "+46(0)70-174 06 58" where the trunk zero rides
115
- * along in parentheses. The consumed left guard (capture group carries the
116
- * value) stops the match from starting inside a longer digit run like
117
- * "kundnummer TEST-100200-3000".
120
+ * along in parentheses. International: a `+<1-3 digit country code>` prefix
121
+ * followed by 6-12 digits with optional spaces/dashes ("+33 6 12 34 56 78",
122
+ * "+47 9123456"). The `+` is required for the international form — without
123
+ * it a bare digit run is far more often an order id or account number than a
124
+ * foreign phone number, so the unprefixed branch stays Swedish-only.
125
+ * The consumed left guard (capture group carries the value) stops the match
126
+ * from starting inside a longer digit run like "kundnummer TEST-100200-3000".
118
127
  */
119
128
  declare const phone: Detector;
120
129
  /**
@@ -144,6 +153,21 @@ declare const bankgiro: Detector;
144
153
  declare const plusgiro: Detector;
145
154
  /** Swedish IBAN: SE + 22 digits (spaces tolerated). */
146
155
  declare const iban: Detector;
156
+ /**
157
+ * Contextual domestic account number. Sweden has no single checksum-backed
158
+ * syntax for ordinary bank accounts, so the digit shape alone is much too
159
+ * broad: it also describes customer, order and journal identifiers. Requiring
160
+ * an explicit account label keeps this useful without turning every grouped
161
+ * number into PII. This detector is opt-in for rules-only callers and enabled
162
+ * by the hybrid pipeline, whose input is normally free-form customer text.
163
+ */
164
+ declare const kontonummer: Detector;
165
+ /**
166
+ * Context-labeled journal identifier. The identifier format is provider-
167
+ * specific, but the explicit Swedish field label is strong evidence and keeps
168
+ * checksum-shaped values from being misclassified as payment identifiers.
169
+ */
170
+ declare const journalnummer: Detector;
147
171
  declare const creditCard: Detector;
148
172
  declare const ipAddress: Detector;
149
173
  declare const url: Detector;
@@ -170,6 +194,8 @@ declare const regnummer: Detector;
170
194
  * `redact(text, { detectors: [...defaultDetectors, ...heuristicDetectors] })`.
171
195
  */
172
196
  declare const heuristicDetectors: Detector[];
197
+ /** Context-dependent formats that are safe only when their label is present. */
198
+ declare const contextualDetectors: Detector[];
173
199
  /**
174
200
  * Default detector set, ordered so that the most specific / highest-confidence
175
201
  * detectors run first. Overlap resolution keeps the longest, earliest match.
@@ -216,13 +242,28 @@ declare function restore(text: string, map: Record<string, string>): string;
216
242
  * and organisationsnummer. Operates on the digits only.
217
243
  */
218
244
  declare function luhnValid(digits: string): boolean;
245
+ /**
246
+ * Personnummer shape: 10 or 12 digit form with optional `-`/`+` separator and
247
+ * a real calendar date, but NO Luhn check. The date check is a real calendar
248
+ * check: a flat day <= 31 would accept "850230-…" (Feb 30) and non-leap
249
+ * Feb 29, spending the false-positive budget on dates that can never be
250
+ * issued.
251
+ *
252
+ * This — not the strict validator — is what the personnummer detector runs
253
+ * on. In real customer data people routinely mistype their own personnummer,
254
+ * and a typo lands in the control digit as often as anywhere else; rejecting
255
+ * on Luhn then leaks the single most sensitive identifier Sweden has. With
256
+ * the checksum gone the date check carries the precision burden: it rejects
257
+ * ~96% of arbitrary digit runs on its own (month 1-12, day valid in that
258
+ * month), which is what keeps order ids and account numbers from masking.
259
+ */
260
+ declare function isPersonnummerShape(value: string): boolean;
261
+ /** Samordningsnummer shape: like `isPersonnummerShape` but day has +60. */
262
+ declare function isSamordningsnummerShape(value: string): boolean;
219
263
  /**
220
264
  * Validate a Swedish personnummer.
221
265
  * Accepts 10 or 12 digit forms with optional `-`/`+` separator.
222
266
  * Checks the date part and the Luhn control digit (on the 10-digit core).
223
- * The date check is a real calendar check: a flat day <= 31 accepted
224
- * "850230-…" (Feb 30) and non-leap Feb 29, spending the false-positive
225
- * budget the checksum bought on dates that can never be issued.
226
267
  */
227
268
  declare function isPersonnummer(value: string): boolean;
228
269
  /** Swedish samordningsnummer: like a personnummer but day has +60. */
@@ -230,4 +271,4 @@ declare function isSamordningsnummer(value: string): boolean;
230
271
  /** Swedish organisationsnummer: 10 digits, third digit >= 2, Luhn valid. */
231
272
  declare function isOrganisationsnummer(value: string): boolean;
232
273
 
233
- export { type CanonicalText, type Detection, type Detector, type PiiLabel, type RedactOptions, type RedactResult, type Redaction, adress, bankgiro, canonicalize, creditCard, defaultDetectors, email, heuristicDetectors, iban, ipAddress, isOrganisationsnummer, isPersonnummer, isSamordningsnummer, lagenhetsnummer, luhnValid, organisationsnummer, personnummer, phone, plusgiro, postnummer, redact, redactFromDetections, regexDetector, regnummer, restore, runDetectors, samordningsnummer, url };
274
+ export { type CanonicalText, type Detection, type Detector, type PiiLabel, type RedactOptions, type RedactResult, type Redaction, adress, bankgiro, canonicalize, contextualDetectors, creditCard, defaultDetectors, email, heuristicDetectors, iban, ipAddress, isOrganisationsnummer, isPersonnummer, isPersonnummerShape, isSamordningsnummer, isSamordningsnummerShape, journalnummer, kontonummer, lagenhetsnummer, luhnValid, organisationsnummer, personnummer, phone, plusgiro, postnummer, redact, redactFromDetections, regexDetector, regnummer, restore, runDetectors, samordningsnummer, url };
package/dist/index.d.ts CHANGED
@@ -52,7 +52,7 @@ declare function canonicalize(input: string): CanonicalText;
52
52
  * Built-in PII labels. The `string` fallback lets you add custom detectors
53
53
  * with arbitrary labels without fighting the type system.
54
54
  */
55
- type PiiLabel = "PERSONNUMMER" | "SAMORDNINGSNUMMER" | "ORGANISATIONSNUMMER" | "EPOST" | "TELEFON" | "POSTNUMMER" | "BANKGIRO" | "PLUSGIRO" | "IBAN" | "IP_ADRESS" | "URL" | "KORTNUMMER" | "ADRESS" | "LAGENHETSNUMMER" | "REGNUMMER" | (string & {});
55
+ type PiiLabel = "PERSONNUMMER" | "SAMORDNINGSNUMMER" | "ORGANISATIONSNUMMER" | "EPOST" | "TELEFON" | "POSTNUMMER" | "BANKGIRO" | "PLUSGIRO" | "IBAN" | "IP_ADRESS" | "URL" | "KORTNUMMER" | "KONTONUMMER" | "JOURNALNUMMER" | "ADRESS" | "LAGENHETSNUMMER" | "REGNUMMER" | (string & {});
56
56
  /** A raw match found by a detector, before placeholder assignment. */
57
57
  interface Detection {
58
58
  /** Inclusive start index into the source string. */
@@ -102,19 +102,28 @@ interface RedactResult {
102
102
  * that can reject false positives (e.g. a number that fails a checksum).
103
103
  */
104
104
  declare function regexDetector(label: PiiLabel, regex: RegExp, validate?: (value: string) => boolean): Detector;
105
- /** Personnummer: YYYYMMDD-XXXX / YYMMDD-XXXX, `-` or `+` separator optional. */
105
+ /**
106
+ * Personnummer: YYYYMMDD-XXXX / YYMMDD-XXXX, `-` or `+` separator optional.
107
+ * Validates on date shape only, NOT Luhn: a mistyped control digit is the most
108
+ * common way a real personnummer appears in customer data, and rejecting it
109
+ * leaks exactly what we are here to mask (see isPersonnummerShape).
110
+ */
106
111
  declare const personnummer: Detector;
107
- /** Samordningsnummer: personnummer-shaped but with day + 60. */
112
+ /** Samordningsnummer: personnummer-shaped but with day + 60. Same no-Luhn policy. */
108
113
  declare const samordningsnummer: Detector;
109
114
  /** Organisationsnummer: NNNNNN-NNNN, Luhn-checked, third digit >= 2. */
110
115
  declare const organisationsnummer: Detector;
111
116
  declare const email: Detector;
112
117
  /**
113
- * Swedish phone numbers: +46 / 0 prefix, mobile and landline, including the
118
+ * Phone numbers. Swedish: +46 / 0 prefix, mobile and landline, including the
114
119
  * e-mail-signature style "+46(0)70-174 06 58" where the trunk zero rides
115
- * along in parentheses. The consumed left guard (capture group carries the
116
- * value) stops the match from starting inside a longer digit run like
117
- * "kundnummer TEST-100200-3000".
120
+ * along in parentheses. International: a `+<1-3 digit country code>` prefix
121
+ * followed by 6-12 digits with optional spaces/dashes ("+33 6 12 34 56 78",
122
+ * "+47 9123456"). The `+` is required for the international form — without
123
+ * it a bare digit run is far more often an order id or account number than a
124
+ * foreign phone number, so the unprefixed branch stays Swedish-only.
125
+ * The consumed left guard (capture group carries the value) stops the match
126
+ * from starting inside a longer digit run like "kundnummer TEST-100200-3000".
118
127
  */
119
128
  declare const phone: Detector;
120
129
  /**
@@ -144,6 +153,21 @@ declare const bankgiro: Detector;
144
153
  declare const plusgiro: Detector;
145
154
  /** Swedish IBAN: SE + 22 digits (spaces tolerated). */
146
155
  declare const iban: Detector;
156
+ /**
157
+ * Contextual domestic account number. Sweden has no single checksum-backed
158
+ * syntax for ordinary bank accounts, so the digit shape alone is much too
159
+ * broad: it also describes customer, order and journal identifiers. Requiring
160
+ * an explicit account label keeps this useful without turning every grouped
161
+ * number into PII. This detector is opt-in for rules-only callers and enabled
162
+ * by the hybrid pipeline, whose input is normally free-form customer text.
163
+ */
164
+ declare const kontonummer: Detector;
165
+ /**
166
+ * Context-labeled journal identifier. The identifier format is provider-
167
+ * specific, but the explicit Swedish field label is strong evidence and keeps
168
+ * checksum-shaped values from being misclassified as payment identifiers.
169
+ */
170
+ declare const journalnummer: Detector;
147
171
  declare const creditCard: Detector;
148
172
  declare const ipAddress: Detector;
149
173
  declare const url: Detector;
@@ -170,6 +194,8 @@ declare const regnummer: Detector;
170
194
  * `redact(text, { detectors: [...defaultDetectors, ...heuristicDetectors] })`.
171
195
  */
172
196
  declare const heuristicDetectors: Detector[];
197
+ /** Context-dependent formats that are safe only when their label is present. */
198
+ declare const contextualDetectors: Detector[];
173
199
  /**
174
200
  * Default detector set, ordered so that the most specific / highest-confidence
175
201
  * detectors run first. Overlap resolution keeps the longest, earliest match.
@@ -216,13 +242,28 @@ declare function restore(text: string, map: Record<string, string>): string;
216
242
  * and organisationsnummer. Operates on the digits only.
217
243
  */
218
244
  declare function luhnValid(digits: string): boolean;
245
+ /**
246
+ * Personnummer shape: 10 or 12 digit form with optional `-`/`+` separator and
247
+ * a real calendar date, but NO Luhn check. The date check is a real calendar
248
+ * check: a flat day <= 31 would accept "850230-…" (Feb 30) and non-leap
249
+ * Feb 29, spending the false-positive budget on dates that can never be
250
+ * issued.
251
+ *
252
+ * This — not the strict validator — is what the personnummer detector runs
253
+ * on. In real customer data people routinely mistype their own personnummer,
254
+ * and a typo lands in the control digit as often as anywhere else; rejecting
255
+ * on Luhn then leaks the single most sensitive identifier Sweden has. With
256
+ * the checksum gone the date check carries the precision burden: it rejects
257
+ * ~96% of arbitrary digit runs on its own (month 1-12, day valid in that
258
+ * month), which is what keeps order ids and account numbers from masking.
259
+ */
260
+ declare function isPersonnummerShape(value: string): boolean;
261
+ /** Samordningsnummer shape: like `isPersonnummerShape` but day has +60. */
262
+ declare function isSamordningsnummerShape(value: string): boolean;
219
263
  /**
220
264
  * Validate a Swedish personnummer.
221
265
  * Accepts 10 or 12 digit forms with optional `-`/`+` separator.
222
266
  * Checks the date part and the Luhn control digit (on the 10-digit core).
223
- * The date check is a real calendar check: a flat day <= 31 accepted
224
- * "850230-…" (Feb 30) and non-leap Feb 29, spending the false-positive
225
- * budget the checksum bought on dates that can never be issued.
226
267
  */
227
268
  declare function isPersonnummer(value: string): boolean;
228
269
  /** Swedish samordningsnummer: like a personnummer but day has +60. */
@@ -230,4 +271,4 @@ declare function isSamordningsnummer(value: string): boolean;
230
271
  /** Swedish organisationsnummer: 10 digits, third digit >= 2, Luhn valid. */
231
272
  declare function isOrganisationsnummer(value: string): boolean;
232
273
 
233
- export { type CanonicalText, type Detection, type Detector, type PiiLabel, type RedactOptions, type RedactResult, type Redaction, adress, bankgiro, canonicalize, creditCard, defaultDetectors, email, heuristicDetectors, iban, ipAddress, isOrganisationsnummer, isPersonnummer, isSamordningsnummer, lagenhetsnummer, luhnValid, organisationsnummer, personnummer, phone, plusgiro, postnummer, redact, redactFromDetections, regexDetector, regnummer, restore, runDetectors, samordningsnummer, url };
274
+ export { type CanonicalText, type Detection, type Detector, type PiiLabel, type RedactOptions, type RedactResult, type Redaction, adress, bankgiro, canonicalize, contextualDetectors, creditCard, defaultDetectors, email, heuristicDetectors, iban, ipAddress, isOrganisationsnummer, isPersonnummer, isPersonnummerShape, isSamordningsnummer, isSamordningsnummerShape, journalnummer, kontonummer, lagenhetsnummer, luhnValid, organisationsnummer, personnummer, phone, plusgiro, postnummer, redact, redactFromDetections, regexDetector, regnummer, restore, runDetectors, samordningsnummer, url };
package/dist/index.js CHANGED
@@ -116,25 +116,31 @@ function daysInMonth(year, month) {
116
116
  if (month === 2) return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0) ? 29 : 28;
117
117
  return [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month - 1];
118
118
  }
119
- function isPersonnummer(value) {
119
+ function isPersonnummerShape(value) {
120
120
  const m = value.match(/^(\d{2})?(\d{2})(\d{2})(\d{2})[-+]?(\d{4})$/);
121
121
  if (!m) return false;
122
122
  const year = Number((m[1] ?? "") + m[2]);
123
123
  const month = Number(m[3]);
124
124
  const day = Number(m[4]);
125
125
  if (month < 1 || month > 12) return false;
126
- if (day < 1 || day > daysInMonth(year, month)) return false;
127
- const core = value.replace(/[-+]/g, "").slice(-10);
128
- return luhnValid(core);
126
+ return day >= 1 && day <= daysInMonth(year, month);
129
127
  }
130
- function isSamordningsnummer(value) {
128
+ function isSamordningsnummerShape(value) {
131
129
  const m = value.match(/^(\d{2})?(\d{2})(\d{2})(\d{2})[-+]?(\d{4})$/);
132
130
  if (!m) return false;
133
131
  const year = Number((m[1] ?? "") + m[2]);
134
132
  const month = Number(m[3]);
135
133
  const day = Number(m[4]);
136
134
  if (month < 1 || month > 12) return false;
137
- if (day < 61 || day - 60 > daysInMonth(year, month)) return false;
135
+ return day >= 61 && day - 60 <= daysInMonth(year, month);
136
+ }
137
+ function isPersonnummer(value) {
138
+ if (!isPersonnummerShape(value)) return false;
139
+ const core = value.replace(/[-+]/g, "").slice(-10);
140
+ return luhnValid(core);
141
+ }
142
+ function isSamordningsnummer(value) {
143
+ if (!isSamordningsnummerShape(value)) return false;
138
144
  const core = value.replace(/[-+]/g, "").slice(-10);
139
145
  return luhnValid(core);
140
146
  }
@@ -242,11 +248,11 @@ function checksumWindowDetector(label, widths, validate) {
242
248
  }
243
249
  };
244
250
  }
245
- var personnummer = checksumWindowDetector("PERSONNUMMER", [12, 10], isPersonnummer);
251
+ var personnummer = checksumWindowDetector("PERSONNUMMER", [12, 10], isPersonnummerShape);
246
252
  var samordningsnummer = checksumWindowDetector(
247
253
  "SAMORDNINGSNUMMER",
248
254
  [12, 10],
249
- isSamordningsnummer
255
+ isSamordningsnummerShape
250
256
  );
251
257
  var organisationsnummer = regexDetector(
252
258
  "ORGANISATIONSNUMMER",
@@ -259,7 +265,7 @@ var email = regexDetector(
259
265
  );
260
266
  var phone = regexDetector(
261
267
  "TELEFON",
262
- /(?:^|[^\d])((?:\+46[\s-]?(?:\(0\)[\s-]?)?|0)(?:7[02369]|[1-9]\d?)(?:[\s-]?\d){6,8})\b/g
268
+ /(?:^|[^\d])((?:\+46[\s-]?(?:\(0\)[\s-]?)?|0)(?:7[02369]|[1-9]\d?)(?:[\s-]?\d){6,8}|\+\d{1,3}(?:[\s-]?\d){6,12})\b/g
263
269
  );
264
270
  var postnummer = regexDetector(
265
271
  "POSTNUMMER",
@@ -276,6 +282,18 @@ var plusgiro = regexDetector(
276
282
  (v) => luhnValid(v.replace(/\D/g, ""))
277
283
  );
278
284
  var iban = regexDetector("IBAN", /\bSE\d{2}(?:\s?\d){20}\b/gi);
285
+ var kontonummer = regexDetector(
286
+ "KONTONUMMER",
287
+ /(?:^|[^\p{L}\p{N}])(?:bankkonto|kontonummer|utbetalningskonto|konto)(?:\s+nr\.?)?\s*[:#-]?\s*((?:\d[ -]?){6,19}\d)\b/giu,
288
+ (value) => {
289
+ const digits = value.replace(/\D/g, "");
290
+ return digits.length >= 7 && digits.length <= 20;
291
+ }
292
+ );
293
+ var journalnummer = regexDetector(
294
+ "JOURNALNUMMER",
295
+ /(?:^|[^\p{L}\p{N}])(?:journalnummer|journalnr|journal-id|journalid)\s*[:#-]?\s*((?:[\p{L}\p{N}]{2,12}[-/]){1,3}[\p{L}\p{N}]{2,12}|\d{5,20})\b/giu
296
+ );
279
297
  var creditCard = regexDetector("KORTNUMMER", /\b\d(?:[ -]?\d){12,18}\b/g, (v) => {
280
298
  const digits = v.replace(/\D/g, "");
281
299
  return digits.length >= 13 && digits.length <= 19 && luhnValid(digits);
@@ -287,7 +305,7 @@ var ipAddress = regexDetector(
287
305
  var url = regexDetector("URL", /\b(?:https?:\/\/|www\.)[^\s<>")]*[^\s<>").,;:!?]/gi);
288
306
  var adress = regexDetector(
289
307
  "ADRESS",
290
- /(?:^|[^A-Za-zÅÄÖåäö0-9])((?:(?:[A-ZÅÄÖ][a-zåäö]+\s)?[A-ZÅÄÖa-zåäö][a-zåäö]*(?:gatan|vägen|gränd|gränden|torget|stigen|backen|allén|plan|gata|väg)|[A-ZÅÄÖ]+(?:GATAN|VÄGEN|GRÄND|GRÄNDEN|TORGET|STIGEN|BACKEN|ALLÉN|PLAN|GATA|VÄG))\s?\d{1,3}[A-Za-z]?)\b/g
308
+ /(?:^|[^A-Za-zÅÄÖåäö0-9])((?:(?:[A-ZÅÄÖ][a-zåäö]+\s)?[A-ZÅÄÖa-zåäö][a-zåäö]*(?:gatan|vägen|gränd|gränden|torget|stigen|backen|allén|gången|kajen|stranden|terrassen|leden|stråket|plan|gata|väg)|[A-ZÅÄÖ]+(?:GATAN|VÄGEN|GRÄND|GRÄNDEN|TORGET|STIGEN|BACKEN|ALLÉN|GÅNGEN|KAJEN|STRANDEN|TERRASSEN|LEDEN|STRÅKET|PLAN|GATA|VÄG))\s?\d{1,3}[A-Za-z]?)\b/g
291
309
  );
292
310
  var lagenhetsnummer = regexDetector(
293
311
  "LAGENHETSNUMMER",
@@ -300,6 +318,7 @@ var regnummer = regexDetector(
300
318
  (v) => !CURRENCY_CODES.has(v.slice(0, 3))
301
319
  );
302
320
  var heuristicDetectors = [adress, lagenhetsnummer, regnummer];
321
+ var contextualDetectors = [kontonummer, journalnummer];
303
322
  var defaultDetectors = [
304
323
  email,
305
324
  url,
@@ -319,11 +338,21 @@ var defaultDetectors = [
319
338
  function defaultPlaceholder(label, index) {
320
339
  return `[${label}_${index}]`;
321
340
  }
341
+ var SAME_SPAN_PRIORITY = {
342
+ JOURNALNUMMER: -10,
343
+ KONTONUMMER: -10,
344
+ TELEFON: 0,
345
+ PERSONNUMMER: 10,
346
+ SAMORDNINGSNUMMER: 11
347
+ };
322
348
  var WORD_CHAR = /[\p{L}\p{N}]/u;
323
349
  function resolveOverlaps(detections, input) {
324
350
  const sorted = [...detections].sort((a, b) => {
325
351
  if (a.start !== b.start) return a.start - b.start;
326
352
  if (b.end - b.start !== a.end - a.start) return b.end - b.start - (a.end - a.start);
353
+ const priorityA = SAME_SPAN_PRIORITY[a.label] ?? 5;
354
+ const priorityB = SAME_SPAN_PRIORITY[b.label] ?? 5;
355
+ if (priorityA !== priorityB) return priorityA - priorityB;
327
356
  return a.label.localeCompare(b.label);
328
357
  });
329
358
  const kept = [];
@@ -510,6 +539,6 @@ function restore(text, map) {
510
539
  return out + text.slice(last);
511
540
  }
512
541
 
513
- export { adress, bankgiro, canonicalize, creditCard, defaultDetectors, email, heuristicDetectors, iban, ipAddress, isOrganisationsnummer, isPersonnummer, isSamordningsnummer, lagenhetsnummer, luhnValid, organisationsnummer, personnummer, phone, plusgiro, postnummer, redact, redactFromDetections, regexDetector, regnummer, restore, runDetectors, samordningsnummer, url };
542
+ export { adress, bankgiro, canonicalize, contextualDetectors, creditCard, defaultDetectors, email, heuristicDetectors, iban, ipAddress, isOrganisationsnummer, isPersonnummer, isPersonnummerShape, isSamordningsnummer, isSamordningsnummerShape, journalnummer, kontonummer, lagenhetsnummer, luhnValid, organisationsnummer, personnummer, phone, plusgiro, postnummer, redact, redactFromDetections, regexDetector, regnummer, restore, runDetectors, samordningsnummer, url };
514
543
  //# sourceMappingURL=index.js.map
515
544
  //# sourceMappingURL=index.js.map