@icure/be-fhc-api 0.4.4 → 0.4.7

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.
Files changed (65) hide show
  1. package/api/fhcDataAttributeServiceApi.d.ts +37 -0
  2. package/api/fhcDataAttributeServiceApi.js +65 -0
  3. package/api/fhcEhboxV3Api.d.ts +10 -0
  4. package/api/fhcEhboxV3Api.js +23 -0
  5. package/api/fhcSchematronApi.d.ts +29 -0
  6. package/api/fhcSchematronApi.js +53 -0
  7. package/fhcApi.d.ts +2 -6
  8. package/fhcApi.js +2 -7
  9. package/model/Acknowledgement.d.ts +19 -0
  10. package/model/Acknowledgement.js +9 -0
  11. package/model/ActivePattern.d.ts +18 -0
  12. package/model/ActivePattern.js +20 -0
  13. package/model/DaasResponse.d.ts +20 -0
  14. package/model/DaasResponse.js +9 -0
  15. package/model/DiagnosticReference.d.ts +16 -0
  16. package/model/DiagnosticReference.js +20 -0
  17. package/model/EhboxIdentifierType.d.ts +20 -0
  18. package/model/EhboxIdentifierType.js +9 -0
  19. package/model/FailedAssert.d.ts +22 -0
  20. package/model/FailedAssert.js +9 -0
  21. package/model/FiredRule.d.ts +18 -0
  22. package/model/FiredRule.js +20 -0
  23. package/model/ItemType.d.ts +2 -2
  24. package/model/KmehrRegimen.d.ts +16 -0
  25. package/model/KmehrRegimen.js +9 -0
  26. package/model/Mapstringstring.d.ts +15 -0
  27. package/model/Mapstringstring.js +20 -0
  28. package/model/MessageOperationResponse.d.ts +1 -0
  29. package/model/MessageStatusOperationResponse.d.ts +19 -0
  30. package/model/MessageStatusOperationResponse.js +9 -0
  31. package/model/Ns.d.ts +16 -0
  32. package/model/Ns.js +20 -0
  33. package/model/NsPrefixInAttributeValues.d.ts +16 -0
  34. package/model/NsPrefixInAttributeValues.js +20 -0
  35. package/model/SchematronOutput.d.ts +30 -0
  36. package/model/SchematronOutput.js +9 -0
  37. package/model/SchematronValidationResult.d.ts +20 -0
  38. package/model/SchematronValidationResult.js +9 -0
  39. package/model/SuccessfulReport.d.ts +22 -0
  40. package/model/SuccessfulReport.js +9 -0
  41. package/model/User.d.ts +17 -0
  42. package/model/User.js +20 -0
  43. package/model/models.d.ts +19 -0
  44. package/model/models.js +19 -0
  45. package/package.json +1 -1
  46. package/x-api/message-x-api.d.ts +0 -35
  47. package/x-api/message-x-api.js +0 -790
  48. package/x-api/receipt-x-api.d.ts +0 -10
  49. package/x-api/receipt-x-api.js +0 -42
  50. package/x-api/utils/efact-parser.d.ts +0 -234
  51. package/x-api/utils/efact-parser.js +0 -1121
  52. package/x-api/utils/efact-util.d.ts +0 -28
  53. package/x-api/utils/efact-util.js +0 -316
  54. package/x-api/utils/fhc-invoice-sender-util.d.ts +0 -3
  55. package/x-api/utils/fhc-invoice-sender-util.js +0 -31
  56. package/x-api/utils/fhc-patient-util.d.ts +0 -3
  57. package/x-api/utils/fhc-patient-util.js +0 -20
  58. package/x-api/utils/formatting-util.d.ts +0 -76
  59. package/x-api/utils/formatting-util.js +0 -218
  60. package/x-api/utils/hcp-util.d.ts +0 -16
  61. package/x-api/utils/hcp-util.js +0 -131
  62. package/x-api/utils/insurability-util.d.ts +0 -22
  63. package/x-api/utils/insurability-util.js +0 -56
  64. package/x-api/utils/uuid-encoder.d.ts +0 -44
  65. package/x-api/utils/uuid-encoder.js +0 -110
@@ -1,218 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toMoment = exports.personNameAbbrev = exports.personName = exports.toUrlParams = exports.money = exports.amount = exports.unit = exports.timeEncode = exports.dateEncode = exports.timeDecode = exports.dateDecode = exports.phoneNumberFormat = exports.phoneNumberValidate = exports.ssinValidate = exports.ssinFormat = exports.nihiiValidate = exports.nihiiFormat = exports.ibanFormat = exports.ibanValidate = exports.isValidIBAN = void 0;
4
- const libphonenumber_js_1 = require("libphonenumber-js");
5
- const moment = require("moment");
6
- const _ = require("lodash");
7
- // TODO: move this to env.js?
8
- const DEFAULT_COUNTRY = "BE";
9
- const nihiiRegExp = new RegExp("^(\\d{1})(\\d{5})(\\d{2})(\\d{3})$");
10
- const ssinRegExp = new RegExp("^(\\d{2})(\\d{2})(\\d{2})(\\d{3})(\\d{2})$");
11
- const ibanRegExp = new RegExp("^(\\d{4})(\\d{4})(\\d{4})(\\d{4})$");
12
- const patterns = {
13
- IBAN: (iban) => /^BE\d{14}$/.test(iban) && isValidIBAN(iban),
14
- IBANBE: (iban) => /^BE\d{14}$/.test(iban) && isValidIBAN(iban)
15
- };
16
- //http://ht5ifv.serprest.pt/extensions/tools/IBAN/
17
- function isValidIBAN(iban) {
18
- //This function check if the checksum if correct
19
- iban = iban.replace(/^(.{4})(.*)$/, "$2$1"); //Move the first 4 chars from left to the right
20
- const fun = (e) => (e.charCodeAt(0) - "A".charCodeAt(0) + 10).toString();
21
- iban = iban.replace(/[A-Z]/g, fun); //Convert A-Z to 10-25
22
- let $sum = 0;
23
- let $ei = 1; //First exponent
24
- for (let $i = iban.length - 1; $i >= 0; $i--) {
25
- $sum += $ei * parseInt(iban.charAt($i), 10); //multiply the digit by it's exponent
26
- $ei = ($ei * 10) % 97; //compute next base 10 exponent in modulus 97
27
- }
28
- return $sum % 97 === 1;
29
- }
30
- exports.isValidIBAN = isValidIBAN;
31
- function ibanValidate(iban) {
32
- if (iban.startsWith("BE")) {
33
- return patterns.IBANBE(iban);
34
- }
35
- else {
36
- return patterns.IBAN(iban);
37
- }
38
- }
39
- exports.ibanValidate = ibanValidate;
40
- function ibanFormat(iban) {
41
- return iban.replace(ibanRegExp, "$1 $2 $3 $4");
42
- }
43
- exports.ibanFormat = ibanFormat;
44
- function nihiiFormat(nihii) {
45
- return nihii.replace(nihiiRegExp, "$1 $2 $3 $4");
46
- }
47
- exports.nihiiFormat = nihiiFormat;
48
- function nihiiValidate(nihii) {
49
- return !!nihii.match(nihiiRegExp);
50
- }
51
- exports.nihiiValidate = nihiiValidate;
52
- function ssinFormat(ssin) {
53
- return ssin.replace(ssinRegExp, "$1 $2 $3 $4 $5");
54
- }
55
- exports.ssinFormat = ssinFormat;
56
- function ssinValidate(ssin) {
57
- return !!ssin.match(ssinRegExp);
58
- }
59
- exports.ssinValidate = ssinValidate;
60
- /* Alternate lib free version
61
- export function phoneNumberValidate(phoneNumber: string): boolean {
62
- return (
63
- !!phoneNumber.match(/(?:\+|00)([1-9][0-9]{1-2})([- /.]*([0-9]+))+/) ||
64
- !!phoneNumber.match(/(0[1-9][0-9]*)([- /.]*([0-9]+))+/)
65
- )
66
- }
67
-
68
- export function phoneNumberFormat(phoneNumber: string): string {
69
- let match = phoneNumber.match(/(?:\+|00)([1-9][0-9]{1-2})([- /.]*([0-9]+))+/)
70
- if (match) {
71
- return `+${match[1]} ${match[2].replace(/[- /.]/g, " ")}`.replace(/ /g, " ")
72
- }
73
- match = phoneNumber.match(/0([1-9][0-9]*)([- /.]*([0-9]+))+/)
74
- if (match) {
75
- return `+32 ${match[1]} ${match[2].replace(/[- /.]/g, " ")}`.replace(/ /g, " ")
76
- }
77
- return phoneNumber
78
- }
79
- */
80
- function phoneNumberValidate(phoneNumber) {
81
- return (0, libphonenumber_js_1.isValidNumber)(phoneNumber);
82
- }
83
- exports.phoneNumberValidate = phoneNumberValidate;
84
- function phoneNumberFormat(phoneNumber) {
85
- const parsedPhoneNumber = (0, libphonenumber_js_1.parseNumber)(phoneNumber, DEFAULT_COUNTRY);
86
- // If the number is not valid, we leave the input string as-is.
87
- return _.isEmpty(parsedPhoneNumber)
88
- ? phoneNumber
89
- : (0, libphonenumber_js_1.formatNumber)(parsedPhoneNumber, "International");
90
- }
91
- exports.phoneNumberFormat = phoneNumberFormat;
92
- /**
93
- * Converts a backend date number (e.g., patient birth date) into a Date object.
94
- * @param dateNumber a YYYYMMDD date number from the backend
95
- * @return a Date object
96
- * @throws Error if it is impossible to create a date from the number, other if dateNumber is negative.
97
- * @see #dateEncode
98
- * @see #timeDecode
99
- */
100
- function dateDecode(dateNumber) {
101
- if (!dateNumber) {
102
- return undefined;
103
- }
104
- if (dateNumber < 0) {
105
- throw new Error("We don't decode negative dates. Please make sure you have valid data.");
106
- }
107
- const dateNumberStr = _.padStart(dateNumber.toString(), 8, "19700101");
108
- if (dateNumberStr.length > 8) {
109
- if (dateNumberStr.endsWith("000000")) {
110
- return dateNumber ? moment(dateNumberStr, "YYYYMMDD000000").toDate() : undefined;
111
- }
112
- throw Error("Decoded date is over year 9999. We can't format it properly.");
113
- }
114
- return dateNumber ? moment(dateNumberStr, "YYYYMMDD").toDate() : undefined;
115
- }
116
- exports.dateDecode = dateDecode;
117
- /**
118
- * Converts a backend time number (e.g., health element openingDate) into a Date object.
119
- * @param timeNumber a YYYYMMDD date number from the backend
120
- * @return a Date object
121
- * @see #timeEncode
122
- * @see #dateDecode
123
- */
124
- function timeDecode(timeNumber) {
125
- return timeNumber ? moment(timeNumber.toString(), "YYYYMMDDHHmmss").toDate() : undefined;
126
- }
127
- exports.timeDecode = timeDecode;
128
- /**
129
- * Encodes a Date object into a backend date number (e.g., patient birth date).
130
- * @param date a Date object
131
- * @return a YYYYMMDD date number for the backend
132
- * @see #dateDecode
133
- * @see #timeEncode
134
- */
135
- function dateEncode(date) {
136
- const dateStr = _.padStart(moment(date).format("YYYYMMDD"), 8, "19700101");
137
- // date is null if the field is not set
138
- return date ? Number(dateStr) : undefined;
139
- }
140
- exports.dateEncode = dateEncode;
141
- /**
142
- * Encodes a Date object into a backend time number (e.g., health element openingDate).
143
- * @param date a Date object
144
- * @return a YYYYMMDDHHmmss date number for the backend
145
- * @see #timeDecode
146
- * @see #dateEncode
147
- */
148
- function timeEncode(date) {
149
- return date ? Number(moment(date).format("YYYYMMDDHHmmss")) : undefined;
150
- }
151
- exports.timeEncode = timeEncode;
152
- /**
153
- * Formats a value and a physical unit into text.
154
- * @param value the numerical or string value to encode
155
- * @param unit the unit represented as a string (an empty string is also supported)
156
- */
157
- function unit(value, unit) {
158
- unit = unit || "";
159
- let separator;
160
- if (!unit || unit.startsWith("°")) {
161
- separator = "";
162
- }
163
- else {
164
- // including '%'
165
- separator = "\xa0";
166
- }
167
- return value + separator + unit;
168
- }
169
- exports.unit = unit;
170
- /**
171
- * 0.1 + 0.2 = 0.30000000000000004. Use this function to be better at maths.
172
- * @param a number
173
- * @return the rounded number, two after the comma
174
- */
175
- function amount(value) {
176
- return Number((value || 0).toFixed(2));
177
- }
178
- exports.amount = amount;
179
- /**
180
- * A simple formatter to keep the logic across the app.
181
- * Input: 2.1 ; Output: 2.10€
182
- */
183
- function money(value) {
184
- return [(value || 0).toFixed(2), "€"].join("");
185
- }
186
- exports.money = money;
187
- /**
188
- * Transform a dictionary to a url params.
189
- * From { key1: value1, key2: value2, ... } returns key1=value1&key2=value2&...=...
190
- */
191
- function toUrlParams(params) {
192
- return _.filter(_.map(params, (value, key) => (value ? key + "=" + value : undefined))).join("&");
193
- }
194
- exports.toUrlParams = toUrlParams;
195
- function personName(person) {
196
- return `${person.firstName || ""} ${person.lastName || ""}`.trim();
197
- }
198
- exports.personName = personName;
199
- function personNameAbbrev(person) {
200
- const firstName = person.firstName ? person.firstName[0] + "." : undefined;
201
- return personName(Object.assign(Object.assign({}, person), { firstName }));
202
- }
203
- exports.personNameAbbrev = personNameAbbrev;
204
- function toMoment(epochOrLongCalendar) {
205
- if (!epochOrLongCalendar && epochOrLongCalendar !== 0) {
206
- return null;
207
- }
208
- if (epochOrLongCalendar >= 18000101 && epochOrLongCalendar < 25400000) {
209
- return moment("" + epochOrLongCalendar, "YYYYMMDD");
210
- }
211
- else if (epochOrLongCalendar >= 18000101000000) {
212
- return moment("" + epochOrLongCalendar, "YYYYMMDDhhmmss");
213
- }
214
- else {
215
- return moment(epochOrLongCalendar);
216
- }
217
- }
218
- exports.toMoment = toMoment;
@@ -1,16 +0,0 @@
1
- import { HealthcareParty } from "@icure/api";
2
- export interface KendoDropdownSpeciality {
3
- text: string;
4
- value: string;
5
- }
6
- export declare const SPECIALITIES: Array<string>;
7
- /**
8
- * Translation keys for specialities.
9
- * @see SPECIALITIES
10
- */
11
- export declare const SPECIALITIES_KEYS: {
12
- [spec: string]: string;
13
- };
14
- export declare function isDoctor(nihii: string): boolean;
15
- export declare function isDoctorAssistant(nihii: string): boolean;
16
- export declare function getPhoneNumber(hcp: HealthcareParty, maxLength: number | undefined): number | null;
@@ -1,131 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPhoneNumber = exports.isDoctorAssistant = exports.isDoctor = exports.SPECIALITIES_KEYS = exports.SPECIALITIES = void 0;
4
- const _ = require("lodash");
5
- const api_1 = require("@icure/api");
6
- exports.SPECIALITIES = [
7
- "ADMINISTRATION",
8
- "CARE_GIVER",
9
- "ANATOMOPATHOLOGY",
10
- "ANESTHESIOLOGY",
11
- "SOCIAL_WORKER",
12
- "PHARMA_ASSISTANT",
13
- "AUDIOLOGIST",
14
- "BACTERIOLOGY",
15
- "TRUSS_ORTHOTIST",
16
- "CLINICAL_BIOLOGY",
17
- "CARDIOLOGY",
18
- "GENERAL_SURGERY",
19
- "MAXILLOFACIAL_SURGERY",
20
- "PLASTIC_SURGERY",
21
- "STOMATOLOGICAL_SURGERY",
22
- "CARDIOVASCULAR_SURGERY",
23
- "DENTISTRY",
24
- "DERMATOLOGY",
25
- "DIETETIC",
26
- "ENDOCRINOLOGY",
27
- "OCCUPATIONAL_THERAPIST",
28
- "GASTROENTEROLOGY",
29
- "GENETIC",
30
- "GERIATRICS",
31
- "GYNECOLOGY",
32
- "HEMATOLOGY",
33
- "NURSE",
34
- "NURSE_EDUCATOR",
35
- "PHYSIOTHERAPY",
36
- "SPEECH",
37
- "ACUTE_MEDICINE",
38
- "GENERAL_MEDICINE",
39
- "INTERNAL_MEDICINE",
40
- "NUCLEAR_MEDICINE",
41
- "PHYSICAL_MEDICINE",
42
- "NEONATOLOGY",
43
- "NEPHROLOGY",
44
- "NEUROSURGERY",
45
- "NEUROLOGY",
46
- "NEUROPEDIATRICS",
47
- "NEUROPSYCHIATRY",
48
- "NUTRITIONIST",
49
- "ONCOLOGY",
50
- "OPHTHALMOLOGY",
51
- "ORTHOPEDICS",
52
- "ORTHOPTISTE",
53
- "OTORHINOLARYNGOLOGY",
54
- "PEDIATRICS",
55
- "PHARMACOLOGY",
56
- "RESPIRATORY",
57
- "PODIATRIST",
58
- "PUBLIC_HEALTH_PREVENTION",
59
- "PROSTHETIST",
60
- "PSYCHIATRY",
61
- "MEDICAL_PSYCHOLOGY",
62
- "RADIODIAGNOSTICS",
63
- "RADIOTHERAPY",
64
- "RESUSCITATION",
65
- "RHEUMATOLOGY",
66
- "MIDWIFE",
67
- "STOMATOLOGY",
68
- "EMERGENCY",
69
- "UROLOGY",
70
- "TOXICOLOGY",
71
- "TRANSPORT"
72
- ];
73
- /**
74
- * Translation keys for specialities.
75
- * @see SPECIALITIES
76
- */
77
- exports.SPECIALITIES_KEYS = _.fromPairs(exports.SPECIALITIES.map(spec => [spec, "hcp-form.SPECIALITIES." + spec]));
78
- function isDoctor(nihii) {
79
- return (!!nihii &&
80
- nihii.length === 11 &&
81
- nihii.startsWith("1") &&
82
- !nihii.endsWith("005") &&
83
- !nihii.endsWith("006"));
84
- }
85
- exports.isDoctor = isDoctor;
86
- function isDoctorAssistant(nihii) {
87
- return (!!nihii &&
88
- nihii.length === 11 &&
89
- nihii.startsWith("1") &&
90
- nihii.endsWith("005") &&
91
- nihii.endsWith("006"));
92
- }
93
- exports.isDoctorAssistant = isDoctorAssistant;
94
- function getPhoneNumber(hcp, maxLength) {
95
- const phoneNumbers = (hcp.addresses || []).map(a => {
96
- const t = (a.telecoms || []).find((t) => t.telecomType === api_1.Telecom.TelecomTypeEnum.Phone.toString() ||
97
- t.telecomType === api_1.Telecom.TelecomTypeEnum.Mobile.toString());
98
- let res = t && t.telecomNumber;
99
- if (res && maxLength) {
100
- while (res.length > maxLength) {
101
- if (res.startsWith("0032")) {
102
- res = "0" + res.substr(4);
103
- }
104
- else if (res.startsWith("+32")) {
105
- res = "0" + res.substr(3);
106
- }
107
- else if (res.startsWith("32")) {
108
- res = "0" + res.substr(2);
109
- }
110
- else if (res.startsWith("00")) {
111
- res = res.substr(2);
112
- }
113
- else if (res.startsWith("0")) {
114
- res = res.substr(1);
115
- }
116
- else if (res.startsWith("352")) {
117
- res = "0" + res.substr(3);
118
- }
119
- else if (res.startsWith("33")) {
120
- res = "0" + res.substr(2);
121
- }
122
- else {
123
- res = res.substr(1);
124
- }
125
- }
126
- }
127
- return res && Number(res);
128
- });
129
- return (!phoneNumbers.length || _.isNaN(phoneNumbers[0]) ? null : phoneNumbers[0]) || null;
130
- }
131
- exports.getPhoneNumber = getPhoneNumber;
@@ -1,22 +0,0 @@
1
- import { Patient, Insurability } from "@icure/api";
2
- export declare function isBIM(ct1: number | string, ct2: number | string): boolean;
3
- export declare function patientIsBIM(patient: Patient): boolean;
4
- export declare function isPatientPaymentByIo(patient: Patient): boolean;
5
- /**
6
- * Returns the titulary id from patient insurability
7
- * @throws error if the patient has no insurability data
8
- * @param patient The patient
9
- */
10
- export declare function getMembership(patient: Patient): string;
11
- /**
12
- * Returns the insurability from patient
13
- * @throws error if the patient has no insurability data
14
- * @param patient The patient
15
- */
16
- export declare function getInsurability(patient: Patient): Insurability;
17
- /**
18
- * Returns the insurability from patient
19
- * @throws error if the patient has no insurability data
20
- * @param patient
21
- */
22
- export declare function isPatientHospitalized(patient: Patient): boolean;
@@ -1,56 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isPatientHospitalized = exports.getInsurability = exports.getMembership = exports.isPatientPaymentByIo = exports.patientIsBIM = exports.isBIM = void 0;
4
- const _ = require("lodash");
5
- function isBIM(ct1, ct2) {
6
- //BIM if ct1 ood and ct2 ood
7
- return +ct1 % 2 !== 0 && +ct2 % 2 !== 0;
8
- }
9
- exports.isBIM = isBIM;
10
- function patientIsBIM(patient) {
11
- // FIXME this doesn't check the date of the insurability. It is related to the idea of having only on insurability at a time.
12
- return isBIM(_.get(patient, "insurabilities[0].parameters.tc1"), _.get(patient, "insurabilities[0].parameters.tc2"));
13
- }
14
- exports.patientIsBIM = patientIsBIM;
15
- function isPatientPaymentByIo(patient) {
16
- const paymentByIo = _.get(patient, "insurabilities[0].parameters.paymentByIo");
17
- return paymentByIo === "true";
18
- }
19
- exports.isPatientPaymentByIo = isPatientPaymentByIo;
20
- /**
21
- * Returns the titulary id from patient insurability
22
- * @throws error if the patient has no insurability data
23
- * @param patient The patient
24
- */
25
- function getMembership(patient) {
26
- const ioCode = _.get(patient, "insurabilities[0].identificationNumber");
27
- if (_.isUndefined(ioCode)) {
28
- // TODO translate
29
- throw new Error("Le patient n'a pas de données d'assurabilité");
30
- }
31
- return ioCode;
32
- }
33
- exports.getMembership = getMembership;
34
- /**
35
- * Returns the insurability from patient
36
- * @throws error if the patient has no insurability data
37
- * @param patient The patient
38
- */
39
- function getInsurability(patient) {
40
- const insurability = _.get(patient, "insurabilities[0]");
41
- if (_.isUndefined(insurability)) {
42
- // TODO translate
43
- throw new Error("Le patient n'a pas de données d'assurabilité");
44
- }
45
- return insurability;
46
- }
47
- exports.getInsurability = getInsurability;
48
- /**
49
- * Returns the insurability from patient
50
- * @throws error if the patient has no insurability data
51
- * @param patient
52
- */
53
- function isPatientHospitalized(patient) {
54
- return getInsurability(patient).hospitalisation || false;
55
- }
56
- exports.isPatientHospitalized = isPatientHospitalized;
@@ -1,44 +0,0 @@
1
- export declare class UuidEncoder {
2
- private encStr;
3
- private isCaseSensitive;
4
- private base;
5
- /**
6
- * @public
7
- * @param [baseEncodingStr] A string containing all usable letters for encoding
8
- * @constructor
9
- */
10
- constructor(baseEncodingStr?: string);
11
- /**
12
- * Set encoding base
13
- * @param {string} baseEncodingStr A string containing all usable letters for encoding
14
- * @public
15
- */
16
- setBaseEncodingStr(baseEncodingStr: string): void;
17
- /**
18
- * @private
19
- * @param {string} baseEncodingStr
20
- * @returns {string}
21
- */
22
- static resolveEncodingStr(baseEncodingStr: string): string;
23
- /**
24
- * @public
25
- * @param baseEncodingStr
26
- * @returns {boolean}
27
- */
28
- static isCaseSensitiveBase(baseEncodingStr: string): boolean;
29
- /**
30
- * Encode a UUID
31
- * @param {string} uuid Properly formatted UUID
32
- * @returns {string} Encoded UUID
33
- * @public
34
- */
35
- encode(uuid: string): string;
36
- /**
37
- * Decode an encoded UUID
38
- * @public
39
- * @param {string} str Previously encoded string
40
- * @returns {string} Properly formatted UUID
41
- * @throws Throws an {Error} when encountering invalid data
42
- */
43
- decode(str: string): string;
44
- }
@@ -1,110 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UuidEncoder = void 0;
4
- const bigInt = require("big-integer");
5
- const knownBases = {
6
- base64: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/",
7
- base62: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
8
- base58: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",
9
- base36: "0123456789abcdefghijklmnopqrstuvwxyz",
10
- base32: "0123456789abcdefghjkmnpqrstvwxyz",
11
- base16: "0123456789abcdef",
12
- base10: "0123456789",
13
- base2: "01"
14
- };
15
- const caseSensitiveBases = {
16
- base62: true,
17
- base58: true,
18
- base36: false,
19
- base32: false,
20
- base16: false,
21
- base10: true,
22
- base2: true
23
- };
24
- class UuidEncoder {
25
- /**
26
- * @public
27
- * @param [baseEncodingStr] A string containing all usable letters for encoding
28
- * @constructor
29
- */
30
- constructor(baseEncodingStr = "base36") {
31
- this.encStr = knownBases.base36;
32
- this.isCaseSensitive = false;
33
- this.base = 36;
34
- this.setBaseEncodingStr(baseEncodingStr);
35
- }
36
- /**
37
- * Set encoding base
38
- * @param {string} baseEncodingStr A string containing all usable letters for encoding
39
- * @public
40
- */
41
- setBaseEncodingStr(baseEncodingStr) {
42
- this.encStr = UuidEncoder.resolveEncodingStr(baseEncodingStr);
43
- this.isCaseSensitive = UuidEncoder.isCaseSensitiveBase(baseEncodingStr);
44
- this.base = this.encStr.length;
45
- }
46
- /**
47
- * @private
48
- * @param {string} baseEncodingStr
49
- * @returns {string}
50
- */
51
- static resolveEncodingStr(baseEncodingStr) {
52
- return Object.prototype.hasOwnProperty.call(knownBases, baseEncodingStr)
53
- ? knownBases[baseEncodingStr]
54
- : baseEncodingStr;
55
- }
56
- /**
57
- * @public
58
- * @param baseEncodingStr
59
- * @returns {boolean}
60
- */
61
- static isCaseSensitiveBase(baseEncodingStr) {
62
- return Object.prototype.hasOwnProperty.call(caseSensitiveBases, baseEncodingStr)
63
- ? caseSensitiveBases[baseEncodingStr]
64
- : true;
65
- }
66
- /**
67
- * Encode a UUID
68
- * @param {string} uuid Properly formatted UUID
69
- * @returns {string} Encoded UUID
70
- * @public
71
- */
72
- encode(uuid) {
73
- const cleanUuid = uuid.replace(/-/g, "");
74
- const { base, encStr } = this;
75
- let iUuid = bigInt(cleanUuid, 16);
76
- let str = "";
77
- do {
78
- str = encStr.substr(iUuid.mod(base).valueOf(), 1) + str;
79
- iUuid = iUuid.divide(base);
80
- } while (iUuid.greater(0));
81
- return str;
82
- }
83
- /**
84
- * Decode an encoded UUID
85
- * @public
86
- * @param {string} str Previously encoded string
87
- * @returns {string} Properly formatted UUID
88
- * @throws Throws an {Error} when encountering invalid data
89
- */
90
- decode(str) {
91
- let iUuid = bigInt(0);
92
- const { base, encStr } = this;
93
- const len = str.length;
94
- const finalStr = this.isCaseSensitive ? str : str.toLowerCase();
95
- for (let pos = 0; pos < len; pos += 1) {
96
- const ch = finalStr.substr(pos, 1);
97
- const encPos = encStr.indexOf(ch);
98
- if (encPos < 0) {
99
- throw new Error("Invalid encoded data");
100
- }
101
- iUuid = iUuid.add(encPos);
102
- if (pos < len - 1) {
103
- iUuid = iUuid.multiply(base);
104
- }
105
- }
106
- const uuid = iUuid.toString(16).padStart(32, "0");
107
- return `${uuid.substr(0, 8)}-${uuid.substr(8, 4)}-${uuid.substr(12, 4)}-${uuid.substr(16, 4)}-${uuid.substr(20)}`;
108
- }
109
- }
110
- exports.UuidEncoder = UuidEncoder;