@doctocar/tooling 0.3.1-18 → 0.3.1-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/dist/utils/format/__tests__/formatApproximateAddress.test.d.ts +1 -0
- package/dist/utils/format/__tests__/formatApproximateAddress.test.js +45 -0
- package/dist/utils/format/__tests__/formatFullName.test.d.ts +1 -0
- package/dist/utils/format/__tests__/formatFullName.test.js +20 -0
- package/dist/utils/format/__tests__/formatObfuscatedFullName.test.d.ts +1 -0
- package/dist/utils/format/__tests__/formatObfuscatedFullName.test.js +26 -0
- package/dist/utils/format/__tests__/formatObfuscatedLicensePlate.test.d.ts +1 -0
- package/dist/utils/format/__tests__/formatObfuscatedLicensePlate.test.js +32 -0
- package/dist/utils/format/formatApproximateAddress.d.ts +2 -0
- package/dist/utils/format/formatApproximateAddress.js +35 -0
- package/dist/utils/format/formatFullName.d.ts +2 -0
- package/dist/utils/format/formatFullName.js +14 -0
- package/dist/utils/format/formatObfuscatedFullName.d.ts +2 -0
- package/dist/utils/format/formatObfuscatedFullName.js +28 -0
- package/dist/utils/format/formatObfuscatedLicensePlate.d.ts +1 -0
- package/dist/utils/format/formatObfuscatedLicensePlate.js +26 -0
- package/dist/utils/format/index.d.ts +5 -0
- package/dist/utils/format/index.js +5 -0
- package/dist/utils/format/types/FormatApproximateAddressParams.type.d.ts +9 -0
- package/dist/utils/format/types/FormatApproximateAddressParams.type.js +2 -0
- package/dist/utils/format/types/FormatFullNameParams.type.d.ts +4 -0
- package/dist/utils/format/types/FormatFullNameParams.type.js +2 -0
- package/dist/utils/format/types/FormatObfuscatedFullNameParams.type.d.ts +4 -0
- package/dist/utils/format/types/FormatObfuscatedFullNameParams.type.js +2 -0
- package/dist/utils/format/types/index.d.ts +3 -0
- package/dist/utils/format/types/index.js +19 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const formatApproximateAddress_1 = require("../formatApproximateAddress");
|
|
4
|
+
describe("formatApproximateAddress", () => {
|
|
5
|
+
it("joins city and district with a bullet separator", () => {
|
|
6
|
+
expect((0, formatApproximateAddress_1.formatApproximateAddress)({
|
|
7
|
+
city: "Madrid",
|
|
8
|
+
district: "Salamanca",
|
|
9
|
+
})).toBe("Madrid • Salamanca");
|
|
10
|
+
});
|
|
11
|
+
it("returns only the city when no other fields are set", () => {
|
|
12
|
+
expect((0, formatApproximateAddress_1.formatApproximateAddress)({ city: "Barcelona" })).toBe("Barcelona");
|
|
13
|
+
});
|
|
14
|
+
it("returns only the country when it is the only field", () => {
|
|
15
|
+
expect((0, formatApproximateAddress_1.formatApproximateAddress)({ country: "France" })).toBe("France");
|
|
16
|
+
});
|
|
17
|
+
it("never includes street name in the output", () => {
|
|
18
|
+
expect((0, formatApproximateAddress_1.formatApproximateAddress)({
|
|
19
|
+
city: "Paris",
|
|
20
|
+
streetName: "10 Rue de Rivoli",
|
|
21
|
+
})).toBe("Paris");
|
|
22
|
+
});
|
|
23
|
+
it("appends administrative areas and postal code in a stable order", () => {
|
|
24
|
+
expect((0, formatApproximateAddress_1.formatApproximateAddress)({
|
|
25
|
+
city: "Lyon",
|
|
26
|
+
district: "Part-Dieu",
|
|
27
|
+
administrativeAreaLevel2: "Métropole",
|
|
28
|
+
administrativeAreaLevel1: "Auvergne-Rhône-Alpes",
|
|
29
|
+
postalCode: "69003",
|
|
30
|
+
country: "France",
|
|
31
|
+
})).toBe("Lyon • Part-Dieu • Métropole • Auvergne-Rhône-Alpes • 69003 • France");
|
|
32
|
+
});
|
|
33
|
+
it("skips empty, null, or whitespace-only fields", () => {
|
|
34
|
+
expect((0, formatApproximateAddress_1.formatApproximateAddress)({
|
|
35
|
+
city: " Toulouse ",
|
|
36
|
+
district: " ",
|
|
37
|
+
country: null,
|
|
38
|
+
})).toBe("Toulouse");
|
|
39
|
+
});
|
|
40
|
+
it("returns empty string when no usable fields are present", () => {
|
|
41
|
+
expect((0, formatApproximateAddress_1.formatApproximateAddress)({
|
|
42
|
+
streetName: "Secret Street",
|
|
43
|
+
})).toBe("");
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const formatFullName_1 = require("../formatFullName");
|
|
4
|
+
describe("formatFullName", () => {
|
|
5
|
+
it("joins first and last name with a space", () => {
|
|
6
|
+
expect((0, formatFullName_1.formatFullName)({ firstName: "John", lastName: "Doe" })).toBe("John Doe");
|
|
7
|
+
});
|
|
8
|
+
it("returns only first name when last name is missing", () => {
|
|
9
|
+
expect((0, formatFullName_1.formatFullName)({ firstName: "John" })).toBe("John");
|
|
10
|
+
});
|
|
11
|
+
it("returns only last name when first name is missing", () => {
|
|
12
|
+
expect((0, formatFullName_1.formatFullName)({ lastName: "Doe" })).toBe("Doe");
|
|
13
|
+
});
|
|
14
|
+
it("returns empty string when both are missing", () => {
|
|
15
|
+
expect((0, formatFullName_1.formatFullName)({})).toBe("");
|
|
16
|
+
});
|
|
17
|
+
it("trims whitespace on parts", () => {
|
|
18
|
+
expect((0, formatFullName_1.formatFullName)({ firstName: " John ", lastName: " Doe " })).toBe("John Doe");
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const formatObfuscatedFullName_1 = require("../formatObfuscatedFullName");
|
|
4
|
+
describe("formatObfuscatedFullName", () => {
|
|
5
|
+
it("returns first name and last initial with period", () => {
|
|
6
|
+
expect((0, formatObfuscatedFullName_1.formatObfuscatedFullName)({ firstName: "John", lastName: "Doe" })).toBe("John D.");
|
|
7
|
+
});
|
|
8
|
+
it("returns only the first name when last name is missing", () => {
|
|
9
|
+
expect((0, formatObfuscatedFullName_1.formatObfuscatedFullName)({ firstName: "John" })).toBe("John");
|
|
10
|
+
});
|
|
11
|
+
it("returns empty string when both names are null", () => {
|
|
12
|
+
expect((0, formatObfuscatedFullName_1.formatObfuscatedFullName)({ firstName: null, lastName: null })).toBe("");
|
|
13
|
+
});
|
|
14
|
+
it("returns empty string when both names are undefined", () => {
|
|
15
|
+
expect((0, formatObfuscatedFullName_1.formatObfuscatedFullName)({})).toBe("");
|
|
16
|
+
});
|
|
17
|
+
it("returns empty string when both names are blank", () => {
|
|
18
|
+
expect((0, formatObfuscatedFullName_1.formatObfuscatedFullName)({ firstName: " ", lastName: "\t" })).toBe("");
|
|
19
|
+
});
|
|
20
|
+
it("returns last initial only when first name is missing", () => {
|
|
21
|
+
expect((0, formatObfuscatedFullName_1.formatObfuscatedFullName)({ lastName: "Doe" })).toBe("D.");
|
|
22
|
+
});
|
|
23
|
+
it("trims surrounding whitespace on names", () => {
|
|
24
|
+
expect((0, formatObfuscatedFullName_1.formatObfuscatedFullName)({ firstName: " John ", lastName: " Doe " })).toBe("John D.");
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const formatObfuscatedLicensePlate_1 = require("../formatObfuscatedLicensePlate");
|
|
4
|
+
describe("formatObfuscatedLicensePlate", () => {
|
|
5
|
+
it("obfuscates a long hyphenated plate", () => {
|
|
6
|
+
expect((0, formatObfuscatedLicensePlate_1.formatObfuscatedLicensePlate)("ABC-DEF-GHI")).toBe("ABC****HI");
|
|
7
|
+
});
|
|
8
|
+
it("obfuscates a compact alphanumeric plate", () => {
|
|
9
|
+
expect((0, formatObfuscatedLicensePlate_1.formatObfuscatedLicensePlate)("AB123CD")).toBe("AB****CD");
|
|
10
|
+
});
|
|
11
|
+
it("ignores separators and uppercases", () => {
|
|
12
|
+
expect((0, formatObfuscatedLicensePlate_1.formatObfuscatedLicensePlate)("ab-12-3-cd")).toBe("AB****CD");
|
|
13
|
+
});
|
|
14
|
+
it("returns empty string for null or undefined", () => {
|
|
15
|
+
expect((0, formatObfuscatedLicensePlate_1.formatObfuscatedLicensePlate)(null)).toBe("");
|
|
16
|
+
expect((0, formatObfuscatedLicensePlate_1.formatObfuscatedLicensePlate)(undefined)).toBe("");
|
|
17
|
+
});
|
|
18
|
+
it("returns empty string when there are no alphanumeric characters", () => {
|
|
19
|
+
expect((0, formatObfuscatedLicensePlate_1.formatObfuscatedLicensePlate)("---")).toBe("");
|
|
20
|
+
});
|
|
21
|
+
it("uses a three-character prefix when length is greater than 7", () => {
|
|
22
|
+
expect((0, formatObfuscatedLicensePlate_1.formatObfuscatedLicensePlate)("ABCDEFGH")).toBe("ABC****GH");
|
|
23
|
+
});
|
|
24
|
+
it("shows the full normalized plate when it has fewer than 5 characters", () => {
|
|
25
|
+
expect((0, formatObfuscatedLicensePlate_1.formatObfuscatedLicensePlate)("ABCD")).toBe("ABCD");
|
|
26
|
+
expect((0, formatObfuscatedLicensePlate_1.formatObfuscatedLicensePlate)("ABC")).toBe("ABC");
|
|
27
|
+
expect((0, formatObfuscatedLicensePlate_1.formatObfuscatedLicensePlate)("AB")).toBe("AB");
|
|
28
|
+
});
|
|
29
|
+
it("starts heavy obfuscation from 5 characters onward", () => {
|
|
30
|
+
expect((0, formatObfuscatedLicensePlate_1.formatObfuscatedLicensePlate)("AB12E")).toBe("AB****2E");
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatApproximateAddress = formatApproximateAddress;
|
|
4
|
+
function pickNonEmpty(value) {
|
|
5
|
+
const trimmed = value?.trim();
|
|
6
|
+
return trimmed ? trimmed : undefined;
|
|
7
|
+
}
|
|
8
|
+
function formatApproximateAddress(params) {
|
|
9
|
+
const parts = [];
|
|
10
|
+
const city = pickNonEmpty(params.city);
|
|
11
|
+
const district = pickNonEmpty(params.district);
|
|
12
|
+
const administrativeAreaLevel2 = pickNonEmpty(params.administrativeAreaLevel2);
|
|
13
|
+
const administrativeAreaLevel1 = pickNonEmpty(params.administrativeAreaLevel1);
|
|
14
|
+
const postalCode = pickNonEmpty(params.postalCode);
|
|
15
|
+
const country = pickNonEmpty(params.country);
|
|
16
|
+
if (city) {
|
|
17
|
+
parts.push(city);
|
|
18
|
+
}
|
|
19
|
+
if (district) {
|
|
20
|
+
parts.push(district);
|
|
21
|
+
}
|
|
22
|
+
if (administrativeAreaLevel2) {
|
|
23
|
+
parts.push(administrativeAreaLevel2);
|
|
24
|
+
}
|
|
25
|
+
if (administrativeAreaLevel1) {
|
|
26
|
+
parts.push(administrativeAreaLevel1);
|
|
27
|
+
}
|
|
28
|
+
if (postalCode) {
|
|
29
|
+
parts.push(postalCode);
|
|
30
|
+
}
|
|
31
|
+
if (country) {
|
|
32
|
+
parts.push(country);
|
|
33
|
+
}
|
|
34
|
+
return parts.join(" • ");
|
|
35
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatFullName = formatFullName;
|
|
4
|
+
function formatFullName(params) {
|
|
5
|
+
const firstName = params.firstName?.trim() ?? "";
|
|
6
|
+
const lastName = params.lastName?.trim() ?? "";
|
|
7
|
+
if (!firstName) {
|
|
8
|
+
return lastName;
|
|
9
|
+
}
|
|
10
|
+
if (!lastName) {
|
|
11
|
+
return firstName;
|
|
12
|
+
}
|
|
13
|
+
return `${firstName} ${lastName}`;
|
|
14
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatObfuscatedFullName = formatObfuscatedFullName;
|
|
4
|
+
function trimOrEmpty(value) {
|
|
5
|
+
return value?.trim() ?? "";
|
|
6
|
+
}
|
|
7
|
+
function obfuscatedLastInitial(lastName) {
|
|
8
|
+
const trimmed = lastName.trim();
|
|
9
|
+
if (!trimmed) {
|
|
10
|
+
return "";
|
|
11
|
+
}
|
|
12
|
+
return `${trimmed[0]}.`;
|
|
13
|
+
}
|
|
14
|
+
function formatObfuscatedFullName(params) {
|
|
15
|
+
const firstName = trimOrEmpty(params.firstName);
|
|
16
|
+
const lastName = trimOrEmpty(params.lastName);
|
|
17
|
+
if (!firstName && !lastName) {
|
|
18
|
+
return "";
|
|
19
|
+
}
|
|
20
|
+
if (!lastName) {
|
|
21
|
+
return firstName;
|
|
22
|
+
}
|
|
23
|
+
const initial = obfuscatedLastInitial(lastName);
|
|
24
|
+
if (!firstName) {
|
|
25
|
+
return initial;
|
|
26
|
+
}
|
|
27
|
+
return `${firstName} ${initial}`;
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function formatObfuscatedLicensePlate(licensePlate?: string | null): string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatObfuscatedLicensePlate = formatObfuscatedLicensePlate;
|
|
4
|
+
const OBFUSCATION = "****";
|
|
5
|
+
const MIN_LENGTH_FOR_HEAVY_OBFUSCATION = 5;
|
|
6
|
+
function normalizeLicensePlate(licensePlate) {
|
|
7
|
+
return licensePlate.replace(/[^a-zA-Z0-9]/g, "").toUpperCase();
|
|
8
|
+
}
|
|
9
|
+
function formatObfuscatedLicensePlate(licensePlate) {
|
|
10
|
+
if (licensePlate == null) {
|
|
11
|
+
return "";
|
|
12
|
+
}
|
|
13
|
+
const normalized = normalizeLicensePlate(licensePlate);
|
|
14
|
+
if (!normalized) {
|
|
15
|
+
return "";
|
|
16
|
+
}
|
|
17
|
+
const n = normalized.length;
|
|
18
|
+
if (n < MIN_LENGTH_FOR_HEAVY_OBFUSCATION) {
|
|
19
|
+
return normalized;
|
|
20
|
+
}
|
|
21
|
+
const prefixLength = n > 7 ? 3 : 2;
|
|
22
|
+
const suffixLength = 2;
|
|
23
|
+
const prefix = normalized.slice(0, prefixLength);
|
|
24
|
+
const suffix = normalized.slice(-suffixLength);
|
|
25
|
+
return `${prefix}${OBFUSCATION}${suffix}`;
|
|
26
|
+
}
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
+
export * from "./types";
|
|
1
2
|
export * from "./formatPriceInCents";
|
|
2
3
|
export * from "./escapeHtml";
|
|
4
|
+
export * from "./formatObfuscatedFullName";
|
|
5
|
+
export * from "./formatFullName";
|
|
6
|
+
export * from "./formatObfuscatedLicensePlate";
|
|
7
|
+
export * from "./formatApproximateAddress";
|
|
@@ -14,5 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
17
18
|
__exportStar(require("./formatPriceInCents"), exports);
|
|
18
19
|
__exportStar(require("./escapeHtml"), exports);
|
|
20
|
+
__exportStar(require("./formatObfuscatedFullName"), exports);
|
|
21
|
+
__exportStar(require("./formatFullName"), exports);
|
|
22
|
+
__exportStar(require("./formatObfuscatedLicensePlate"), exports);
|
|
23
|
+
__exportStar(require("./formatApproximateAddress"), exports);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type FormatApproximateAddressParams = {
|
|
2
|
+
city?: string | null;
|
|
3
|
+
administrativeAreaLevel1?: string | null;
|
|
4
|
+
administrativeAreaLevel2?: string | null;
|
|
5
|
+
postalCode?: string | null;
|
|
6
|
+
country?: string | null;
|
|
7
|
+
streetName?: string | null;
|
|
8
|
+
district?: string | null;
|
|
9
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./FormatApproximateAddressParams.type"), exports);
|
|
18
|
+
__exportStar(require("./FormatFullNameParams.type"), exports);
|
|
19
|
+
__exportStar(require("./FormatObfuscatedFullNameParams.type"), exports);
|