@unchainedshop/utils 5.0.0-alpha.3 → 5.0.0-alpha.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/lib/ch/priceToString.js
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
export const priceToString = ({ amount, currencyCode }) => {
|
|
2
|
-
const
|
|
3
|
-
|
|
1
|
+
export const priceToString = ({ amount, currencyCode, locale = 'de-CH', }) => {
|
|
2
|
+
const majorUnitAmount = amount / 100;
|
|
3
|
+
try {
|
|
4
|
+
return new Intl.NumberFormat(locale, {
|
|
5
|
+
style: 'currency',
|
|
6
|
+
currency: currencyCode,
|
|
7
|
+
currencyDisplay: 'code',
|
|
8
|
+
}).format(majorUnitAmount);
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return `${currencyCode} ${majorUnitAmount}`;
|
|
12
|
+
}
|
|
4
13
|
};
|
|
5
14
|
export default priceToString;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createLogger } from '@unchainedshop/logger';
|
|
2
|
+
const logger = createLogger('unchained:utils:bulk-operation');
|
|
3
|
+
export async function executeBulkOperation(ids, operation) {
|
|
4
|
+
const successIds = [];
|
|
5
|
+
const failedIds = [];
|
|
6
|
+
for (const id of new Set(ids)) {
|
|
7
|
+
try {
|
|
8
|
+
await operation(id);
|
|
9
|
+
successIds.push(id);
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
failedIds.push(id);
|
|
13
|
+
logger.debug(`Bulk operation failed for entity ${String(id)}`, {
|
|
14
|
+
error: error instanceof Error ? error.message : String(error),
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return { successIds, failedIds };
|
|
19
|
+
}
|
package/lib/phone-number.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { parsePhoneNumber } from 'awesome-phonenumber';
|
|
2
2
|
export const normalizePhoneNumber = (value, defaultCountry) => {
|
|
3
3
|
if (!value)
|
|
4
4
|
return undefined;
|
|
5
|
-
const parsed =
|
|
6
|
-
if (!parsed
|
|
5
|
+
const parsed = parsePhoneNumber(value, defaultCountry ? { regionCode: defaultCountry } : undefined);
|
|
6
|
+
if (!parsed.valid)
|
|
7
7
|
return undefined;
|
|
8
|
-
return parsed.number;
|
|
8
|
+
return parsed.number.e164;
|
|
9
9
|
};
|
|
10
10
|
export const phoneNumberToParts = (value, defaultCountry) => {
|
|
11
11
|
if (!value)
|
|
12
12
|
return undefined;
|
|
13
|
-
const parsed =
|
|
14
|
-
if (!parsed
|
|
13
|
+
const parsed = parsePhoneNumber(value, defaultCountry ? { regionCode: defaultCountry } : undefined);
|
|
14
|
+
if (!parsed.valid)
|
|
15
15
|
return undefined;
|
|
16
|
-
return { cc: parsed.
|
|
16
|
+
return { cc: String(parsed.countryCode), subscriber: parsed.number.significant };
|
|
17
17
|
};
|
package/lib/utils-index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export { default as sha1 } from './sha1.ts';
|
|
|
11
11
|
export { timingSafeEqual, timingSafeStringEqual } from './timing-safe-equal.ts';
|
|
12
12
|
export { normalizePhoneNumber, phoneNumberToParts } from './phone-number.ts';
|
|
13
13
|
export { default as memoizeWithTTL } from './memoize-with-ttl.ts';
|
|
14
|
+
export { executeBulkOperation } from './executeBulkOperation.ts';
|
|
14
15
|
export declare const SortDirection: {
|
|
15
16
|
readonly ASC: "ASC";
|
|
16
17
|
readonly DESC: "DESC";
|
package/lib/utils-index.js
CHANGED
|
@@ -11,6 +11,7 @@ export { default as sha1 } from "./sha1.js";
|
|
|
11
11
|
export { timingSafeEqual, timingSafeStringEqual } from "./timing-safe-equal.js";
|
|
12
12
|
export { normalizePhoneNumber, phoneNumberToParts } from "./phone-number.js";
|
|
13
13
|
export { default as memoizeWithTTL } from "./memoize-with-ttl.js";
|
|
14
|
+
export { executeBulkOperation } from "./executeBulkOperation.js";
|
|
14
15
|
export const SortDirection = {
|
|
15
16
|
ASC: 'ASC',
|
|
16
17
|
DESC: 'DESC',
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/utils",
|
|
3
3
|
"description": "Common utility functions and base classes for the Unchained Engine",
|
|
4
|
-
"version": "5.0.0-alpha.
|
|
4
|
+
"version": "5.0.0-alpha.5",
|
|
5
5
|
"main": "lib/utils-index.js",
|
|
6
6
|
"types": "lib/utils-index.d.ts",
|
|
7
7
|
"type": "module",
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
},
|
|
30
30
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@unchainedshop/logger": "^5.0.0-alpha.
|
|
33
|
-
"
|
|
32
|
+
"@unchainedshop/logger": "^5.0.0-alpha.5",
|
|
33
|
+
"awesome-phonenumber": "^7.8.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/node": "^26.2.0",
|
|
37
|
-
"typescript": "^
|
|
37
|
+
"typescript": "^6.0.3"
|
|
38
38
|
}
|
|
39
39
|
}
|