mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 20:25:26 +00:00
Changed messages format export from default to non-default
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import PKPass from "./PKPass";
|
||||
import type PKPass from "./PKPass";
|
||||
import * as Schemas from "./schemas";
|
||||
import * as Utils from "./utils";
|
||||
import formatMessage, * as Messages from "./messages";
|
||||
import * as Messages from "./messages";
|
||||
|
||||
/**
|
||||
* Class to represent lower-level keys pass fields
|
||||
@@ -48,7 +48,7 @@ export default class FieldsArray extends Array<Schemas.Field> {
|
||||
|
||||
if (this[sharedKeysPoolSymbol].has(current.key)) {
|
||||
console.warn(
|
||||
formatMessage(
|
||||
Messages.format(
|
||||
Messages.FIELDS.REPEATED_KEY,
|
||||
current.key,
|
||||
),
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { Stream } from "stream";
|
||||
import FieldsArray from "./FieldsArray";
|
||||
import Bundle, { filesSymbol } from "./Bundle";
|
||||
import getModelFolderContents from "./getModelFolderContents";
|
||||
@@ -5,8 +6,7 @@ import * as Schemas from "./schemas";
|
||||
import * as Signature from "./Signature";
|
||||
import * as Strings from "./StringsUtils";
|
||||
import * as Utils from "./utils";
|
||||
import { Stream } from "stream";
|
||||
import formatMessage, * as Messages from "./messages";
|
||||
import * as Messages from "./messages";
|
||||
|
||||
/** Exporting for tests specs */
|
||||
export const propsSymbol = Symbol("props");
|
||||
@@ -44,7 +44,7 @@ export default class PKPass extends Bundle {
|
||||
|
||||
if (!source) {
|
||||
throw new TypeError(
|
||||
formatMessage(Messages.FROM.MISSING_SOURCE, source),
|
||||
Messages.format(Messages.FROM.MISSING_SOURCE, source),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -372,7 +372,9 @@ export default class PKPass extends Bundle {
|
||||
validateJSONBuffer(buffer, Schemas.PassProps),
|
||||
);
|
||||
} catch (err) {
|
||||
console.warn(formatMessage(Messages.PASS_SOURCE.INVALID, err));
|
||||
console.warn(
|
||||
Messages.format(Messages.PASS_SOURCE.INVALID, err),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -395,7 +397,9 @@ export default class PKPass extends Bundle {
|
||||
try {
|
||||
validateJSONBuffer(buffer, Schemas.Personalize);
|
||||
} catch (err) {
|
||||
console.warn(formatMessage(Messages.PERSONALIZE.INVALID, err));
|
||||
console.warn(
|
||||
Messages.format(Messages.PERSONALIZE.INVALID, err),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -576,7 +580,7 @@ export default class PKPass extends Bundle {
|
||||
for (let i = 0; i < fileNames.length; i++) {
|
||||
if (/personalization/.test(fileNames[i])) {
|
||||
console.warn(
|
||||
formatMessage(
|
||||
Messages.format(
|
||||
Messages.CLOSE.PERSONALIZATION_REMOVED,
|
||||
fileNames[i],
|
||||
),
|
||||
@@ -698,7 +702,7 @@ export default class PKPass extends Bundle {
|
||||
|
||||
if (typeof lang !== "string") {
|
||||
throw new TypeError(
|
||||
formatMessage(Messages.LANGUAGES.INVALID_LANG, typeof lang),
|
||||
Messages.format(Messages.LANGUAGES.INVALID_LANG, typeof lang),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -723,7 +727,7 @@ export default class PKPass extends Bundle {
|
||||
|
||||
if (!translations || !Object.keys(translations).length) {
|
||||
console.warn(
|
||||
formatMessage(Messages.LANGUAGES.NO_TRANSLATIONS, lang),
|
||||
Messages.format(Messages.LANGUAGES.NO_TRANSLATIONS, lang),
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -754,7 +758,7 @@ export default class PKPass extends Bundle {
|
||||
this[propsSymbol]["expirationDate"] = Utils.processDate(date);
|
||||
} catch (err) {
|
||||
throw new TypeError(
|
||||
formatMessage(Messages.DATE.INVALID, "expirationDate", date),
|
||||
Messages.format(Messages.DATE.INVALID, "expirationDate", date),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -849,7 +853,7 @@ export default class PKPass extends Bundle {
|
||||
this[propsSymbol]["relevantDate"] = Utils.processDate(date);
|
||||
} catch (err) {
|
||||
throw new TypeError(
|
||||
formatMessage(Messages.DATE.INVALID, "relevantDate", date),
|
||||
Messages.format(Messages.DATE.INVALID, "relevantDate", date),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as path from "path";
|
||||
import * as Utils from "./utils";
|
||||
import formatMessage, * as Messages from "./messages";
|
||||
import * as Messages from "./messages";
|
||||
import { promises as fs } from "fs";
|
||||
|
||||
/**
|
||||
@@ -54,7 +54,7 @@ export default async function getModelFolderContents(
|
||||
if (err.syscall === "open") {
|
||||
// file opening failed
|
||||
throw new Error(
|
||||
formatMessage(
|
||||
Messages.format(
|
||||
Messages.MODELS.FILE_NO_OPEN,
|
||||
JSON.stringify(err),
|
||||
),
|
||||
@@ -62,7 +62,7 @@ export default async function getModelFolderContents(
|
||||
} else if (err.syscall === "scandir") {
|
||||
// directory reading failed
|
||||
throw new Error(
|
||||
formatMessage(Messages.MODELS.DIR_NOT_FOUND, err.path),
|
||||
Messages.format(Messages.MODELS.DIR_NOT_FOUND, err.path),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ export const PACK = {
|
||||
* @param values
|
||||
*/
|
||||
|
||||
export default function format(messageName: string, ...values: any[]) {
|
||||
export function format(messageName: string, ...values: any[]) {
|
||||
// reversing because it is better popping than shifting.
|
||||
const replaceValues = values.reverse();
|
||||
return messageName.replace(/%s/g, () => replaceValues.pop());
|
||||
|
||||
@@ -18,7 +18,7 @@ import { PassFields, TransitType } from "./PassFields";
|
||||
import { Semantics } from "./Semantics";
|
||||
import { CertificatesSchema } from "./Certificates";
|
||||
|
||||
import formatMessage, * as Messages from "../messages";
|
||||
import * as Messages from "../messages";
|
||||
|
||||
const RGB_COLOR_REGEX =
|
||||
/rgb\(\s*(?:[01]?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\s*,\s*(?:[01]?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\s*,\s*(?:[01]?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\s*\)/;
|
||||
@@ -204,7 +204,7 @@ export function assertValidity<T>(
|
||||
if (customErrorMessage) {
|
||||
console.warn(validation.error);
|
||||
throw new TypeError(
|
||||
`${validation.error.name} happened. ${formatMessage(
|
||||
`${validation.error.name} happened. ${Messages.format(
|
||||
customErrorMessage,
|
||||
validation.error.message,
|
||||
)}`,
|
||||
@@ -253,7 +253,7 @@ export function filterValid<T extends Object>(
|
||||
try {
|
||||
return [...acc, validate(schema, current)];
|
||||
} catch (err) {
|
||||
console.warn(formatMessage(Messages.FILTER_VALID.INVALID, err));
|
||||
console.warn(Messages.format(Messages.FILTER_VALID.INVALID, err));
|
||||
return [...acc];
|
||||
}
|
||||
}, []);
|
||||
|
||||
Reference in New Issue
Block a user