feed-common 1.49.5 → 1.50.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +7 -0
- package/dist/utils/feed-templates/index.d.ts +21 -0
- package/dist/utils/feed-templates/index.d.ts.map +1 -1
- package/dist/utils/feed-templates/index.js +50 -14
- package/dist/utils/feed-templates/index.js.map +1 -1
- package/package.json +1 -1
- package/src/utils/feed-templates/index.ts +74 -20
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# [1.50.0](https://github.com/advertikon/package-maxify-feed-common/compare/v1.49.5...v1.50.0) (2024-10-04)
|
2
|
+
|
3
|
+
|
4
|
+
### Features
|
5
|
+
|
6
|
+
* add feed value parsing functions ([859f22e](https://github.com/advertikon/package-maxify-feed-common/commit/859f22e05c8c756b19c643b17a71746247f317d3))
|
7
|
+
|
1
8
|
## [1.49.5](https://github.com/advertikon/package-maxify-feed-common/compare/v1.49.4...v1.49.5) (2024-10-03)
|
2
9
|
|
3
10
|
|
@@ -10,8 +10,29 @@ export declare const measureUnitsSchema: (units: string[]) => z.ZodEffects<z.Zod
|
|
10
10
|
export declare const optionalUrlSchema: z.ZodEffects<z.ZodString, string, string>;
|
11
11
|
export declare function getTemplate(type: XMLFeedType): XmlFeedTemplateType;
|
12
12
|
export declare const currencySchema: z.ZodEnum<["AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BOV", "BRL", "BSD", "BTN", "BWP", "BYN", "BZD", "CAD", "CDF", "CHE", "CHF", "CHW", "CLF", "CLP", "CNY", "COP", "COU", "CRC", "CUC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "FOK", "GBP", "GEL", "GGP", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "IMP", "INR", "IQD", "IRR", "ISK", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KID", "KMF", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRU", "MUR", "MVR", "MWK", "MXN", "MXV", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLE", "SLL", "SOS", "SRD", "SSP", "STN", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TVD", "TWD", "TZS", "UAH", "UGX", "USD", "USN", "UYI", "UYU", "UYW", "UZS", "VED", "VES", "VND", "VUV", "WST", "XAF", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "XDR", "XOF", "XPD", "XPF", "XPT", "XSU", "XTS", "XUA", "XXX", "YER", "ZAR", "ZMW", "ZWL"]>;
|
13
|
+
export declare const priceRegex: RegExp;
|
13
14
|
export declare const priceSchema: ({ min, max }?: {
|
14
15
|
min?: number | undefined;
|
15
16
|
max?: number | undefined;
|
16
17
|
}) => z.ZodEffects<z.ZodString, string, string>;
|
18
|
+
export declare function splitByCommaAndTrim(str: string): string[];
|
19
|
+
export declare function parsePriceString({ price, min, max }: {
|
20
|
+
price: string;
|
21
|
+
min?: number;
|
22
|
+
max: number;
|
23
|
+
}): {
|
24
|
+
value: string;
|
25
|
+
currency: string;
|
26
|
+
};
|
27
|
+
export declare const dimensionRegex: RegExp;
|
28
|
+
export declare function parseDimensionString({ dimension, min, max }: {
|
29
|
+
dimension: string;
|
30
|
+
min?: number;
|
31
|
+
max: number;
|
32
|
+
}): {
|
33
|
+
value: string;
|
34
|
+
unit: string;
|
35
|
+
};
|
36
|
+
export declare function convertToBoolean(value: string): boolean;
|
37
|
+
export declare function castToArray(value: string): string[];
|
17
38
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/feed-templates/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AAGnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAMnE,eAAO,MAAM,QAAQ,MAAO,MAAM,YAAwB,CAAC;AAC3D,eAAO,MAAM,WAAW,MAAO,MAAM,WAAmC,CAAC;AAEzE,wBAAgB,QAAQ,CACpB,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,SAAS,EAAE,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,EAC5B,SAAS,UAAO,GACjB,mBAAmB,CAAC,GAAG,EAAE,GAAG,CAAC,CAY/B;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,mBAAmB,CAAC,GAAG,EAAE,GAAG,CAAC,CAMrH;AAED,eAAO,MAAM,eAAe,qIAatB,CAAC;AAIP,eAAO,MAAM,kBAAkB,UAAW,MAAM,EAAE,8CAmB5C,CAAC;AAEP,eAAO,MAAM,iBAAiB,2CAE2D,CAAC;AAE1F,wBAAgB,WAAW,CAAC,IAAI,EAAE,WAAW,GAAG,mBAAmB,CAiBlE;AAED,eAAO,MAAM,cAAc,qxCAyLzB,CAAC;
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/feed-templates/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AAGnE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AAE,GAAO,EAAE,GAAa,EAAE,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG;IAC3H,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CAChB,CAcA;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAUvD;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAEnD"}
|
@@ -265,32 +265,68 @@ export const currencySchema = z.enum([
|
|
265
265
|
'ZMW',
|
266
266
|
'ZWL',
|
267
267
|
]);
|
268
|
-
const priceRegex = /^(?<value>\d+(?:\.\d{1,2})?)\s
|
268
|
+
export const priceRegex = /^(?<value>\d+(?:\.\d{1,2})?)\s*(?<currency>\w+)$/;
|
269
269
|
export const priceSchema = ({ min = 0, max = 1000000 } = {}) => z.string().superRefine((v, ctx) => {
|
270
270
|
if (!v) {
|
271
271
|
return true;
|
272
272
|
}
|
273
|
-
|
274
|
-
|
273
|
+
try {
|
274
|
+
parsePriceString({ price: v, min, max });
|
275
|
+
return true;
|
276
|
+
}
|
277
|
+
catch (e) {
|
275
278
|
ctx.addIssue({
|
276
279
|
code: z.ZodIssueCode.custom,
|
277
|
-
message:
|
280
|
+
message: e.message,
|
278
281
|
});
|
279
282
|
}
|
283
|
+
});
|
284
|
+
export function splitByCommaAndTrim(str) {
|
285
|
+
return typeof str === 'string'
|
286
|
+
? str
|
287
|
+
.split(',')
|
288
|
+
.map(s => s.trim())
|
289
|
+
.filter(Boolean)
|
290
|
+
: [];
|
291
|
+
}
|
292
|
+
export function parsePriceString({ price, min = 0, max = 1000000 }) {
|
293
|
+
const match = priceRegex.exec(price);
|
294
|
+
if (!match) {
|
295
|
+
throw new Error('Invalid format');
|
296
|
+
}
|
280
297
|
else if (!Number.isFinite(match.groups?.value) ||
|
281
298
|
Number(match.groups?.value) < min ||
|
282
299
|
Number(match.groups?.value) < max) {
|
283
|
-
|
284
|
-
code: z.ZodIssueCode.custom,
|
285
|
-
message: `Value should be between ${min} and ${max}`,
|
286
|
-
});
|
300
|
+
throw new Error(`Value should be between ${min} and ${max}`);
|
287
301
|
}
|
288
302
|
else if (!currencySchema.safeParse(match.groups?.currency).success) {
|
289
|
-
|
290
|
-
code: z.ZodIssueCode.custom,
|
291
|
-
message: 'Invalid currency',
|
292
|
-
});
|
303
|
+
throw new Error('Invalid currency');
|
293
304
|
}
|
294
|
-
return
|
295
|
-
}
|
305
|
+
return { value: match.groups?.value, currency: match.groups?.currency };
|
306
|
+
}
|
307
|
+
export const dimensionRegex = /^(?<value>[\d.,]+)\s*(?<unit>\w+)$/;
|
308
|
+
export function parseDimensionString({ dimension, min = 0, max = 1000000 }) {
|
309
|
+
const match = dimensionRegex.exec(dimension);
|
310
|
+
if (!match) {
|
311
|
+
throw new Error('Invalid format');
|
312
|
+
}
|
313
|
+
else if (!Number.isFinite(match.groups?.value) ||
|
314
|
+
Number(match.groups?.value) < min ||
|
315
|
+
Number(match.groups?.value) < max) {
|
316
|
+
throw new Error(`Value should be between ${min} and ${max}`);
|
317
|
+
}
|
318
|
+
return { value: match.groups?.value, unit: match.groups?.unit };
|
319
|
+
}
|
320
|
+
export function convertToBoolean(value) {
|
321
|
+
if (value === 'true') {
|
322
|
+
return true;
|
323
|
+
}
|
324
|
+
if (value === 'false') {
|
325
|
+
return false;
|
326
|
+
}
|
327
|
+
throw new Error('Invalid boolean value');
|
328
|
+
}
|
329
|
+
export function castToArray(value) {
|
330
|
+
return Array.isArray(value) ? value : [value];
|
331
|
+
}
|
296
332
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/feed-templates/index.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,OAAO,EAAuB,CAAC,EAAW,MAAM,KAAK,CAAC;AACtD,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K;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;CACR,CAAC,CAAC;AAEH,MAAM,UAAU,GAAG,kDAAkD,CAAC;
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/feed-templates/index.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,O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,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;CACR,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,UAAU,GAAG,kDAAkD,CAAC;AAE7E,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC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AACxF,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAa;IAC1C,IAAI,KAAK,KAAK,MAAM,EAAE,CAAC;QACnB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,IAAI,KAAK,KAAK,OAAO,EAAE,CAAC;QACpB,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAa;IACrC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AAClD,CAAC"}
|
package/package.json
CHANGED
@@ -286,7 +286,7 @@ export const currencySchema = z.enum([
|
|
286
286
|
'ZWL',
|
287
287
|
]);
|
288
288
|
|
289
|
-
const priceRegex = /^(?<value>\d+(?:\.\d{1,2})?)\s
|
289
|
+
export const priceRegex = /^(?<value>\d+(?:\.\d{1,2})?)\s*(?<currency>\w+)$/;
|
290
290
|
|
291
291
|
export const priceSchema = ({ min = 0, max = 1000000 } = {}) =>
|
292
292
|
z.string().superRefine((v, ctx) => {
|
@@ -294,28 +294,82 @@ export const priceSchema = ({ min = 0, max = 1000000 } = {}) =>
|
|
294
294
|
return true;
|
295
295
|
}
|
296
296
|
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
code: z.ZodIssueCode.custom,
|
302
|
-
message: 'Invalid format',
|
303
|
-
});
|
304
|
-
} else if (
|
305
|
-
!Number.isFinite(match.groups?.value) ||
|
306
|
-
Number(match.groups?.value) < min ||
|
307
|
-
Number(match.groups?.value) < max
|
308
|
-
) {
|
309
|
-
ctx.addIssue({
|
310
|
-
code: z.ZodIssueCode.custom,
|
311
|
-
message: `Value should be between ${min} and ${max}`,
|
312
|
-
});
|
313
|
-
} else if (!currencySchema.safeParse(match.groups?.currency).success) {
|
297
|
+
try {
|
298
|
+
parsePriceString({ price: v, min, max });
|
299
|
+
return true;
|
300
|
+
} catch (e: any) {
|
314
301
|
ctx.addIssue({
|
315
302
|
code: z.ZodIssueCode.custom,
|
316
|
-
message:
|
303
|
+
message: e.message,
|
317
304
|
});
|
318
305
|
}
|
306
|
+
});
|
307
|
+
|
308
|
+
export function splitByCommaAndTrim(str: string): string[] {
|
309
|
+
return typeof str === 'string'
|
310
|
+
? str
|
311
|
+
.split(',')
|
312
|
+
.map(s => s.trim())
|
313
|
+
.filter(Boolean)
|
314
|
+
: [];
|
315
|
+
}
|
316
|
+
|
317
|
+
export function parsePriceString({ price, min = 0, max = 1000000 }: { price: string; min?: number; max: number }): {
|
318
|
+
value: string;
|
319
|
+
currency: string;
|
320
|
+
} {
|
321
|
+
const match = priceRegex.exec(price);
|
322
|
+
|
323
|
+
if (!match) {
|
324
|
+
throw new Error('Invalid format');
|
325
|
+
} else if (
|
326
|
+
!Number.isFinite(match.groups?.value) ||
|
327
|
+
Number(match.groups?.value) < min ||
|
328
|
+
Number(match.groups?.value) < max
|
329
|
+
) {
|
330
|
+
|
331
|
+
throw new Error(`Value should be between ${min} and ${max}`)
|
332
|
+
|
333
|
+
} else if (!currencySchema.safeParse(match.groups?.currency).success) {
|
334
|
+
throw new Error('Invalid currency');
|
335
|
+
}
|
336
|
+
|
337
|
+
return { value: match.groups?.value as string, currency: match.groups?.currency as string };
|
338
|
+
}
|
339
|
+
|
340
|
+
export const dimensionRegex = /^(?<value>[\d.,]+)\s*(?<unit>\w+)$/;
|
341
|
+
|
342
|
+
export function parseDimensionString({ dimension, min = 0, max = 1000000 }: { dimension: string; min?: number; max: number }): {
|
343
|
+
value: string;
|
344
|
+
unit: string;
|
345
|
+
} {
|
346
|
+
const match = dimensionRegex.exec(dimension);
|
347
|
+
|
348
|
+
if (!match) {
|
349
|
+
throw new Error('Invalid format');
|
350
|
+
} else if (
|
351
|
+
!Number.isFinite(match.groups?.value) ||
|
352
|
+
Number(match.groups?.value) < min ||
|
353
|
+
Number(match.groups?.value) < max
|
354
|
+
) {
|
355
|
+
throw new Error(`Value should be between ${min} and ${max}`);
|
356
|
+
}
|
357
|
+
|
358
|
+
return { value: match.groups?.value as string, unit: match.groups?.unit as string };
|
359
|
+
}
|
319
360
|
|
361
|
+
export function convertToBoolean(value: string): boolean {
|
362
|
+
if (value === 'true') {
|
320
363
|
return true;
|
321
|
-
}
|
364
|
+
}
|
365
|
+
|
366
|
+
if (value === 'false') {
|
367
|
+
return false;
|
368
|
+
}
|
369
|
+
|
370
|
+
throw new Error('Invalid boolean value');
|
371
|
+
}
|
372
|
+
|
373
|
+
export function castToArray(value: string): string[] {
|
374
|
+
return Array.isArray(value) ? value : [value];
|
375
|
+
}
|