mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 17:25:21 +00:00
Improved message type
This commit is contained in:
@@ -1,8 +1,4 @@
|
|||||||
interface MessageGroup {
|
const errors = {
|
||||||
[key: string]: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const errors: MessageGroup = {
|
|
||||||
CP_INIT_ERROR: "Something went really bad in the %s initialization! Look at the log below this message. It should contain all the infos about the problem: \n%s",
|
CP_INIT_ERROR: "Something went really bad in the %s initialization! Look at the log below this message. It should contain all the infos about the problem: \n%s",
|
||||||
CP_NO_OPTS: "Cannot initialize the pass or abstract model creation: no options were passed.",
|
CP_NO_OPTS: "Cannot initialize the pass or abstract model creation: no options were passed.",
|
||||||
CP_NO_CERTS: "Cannot initialize the pass creation: no valid certificates were passed.",
|
CP_NO_CERTS: "Cannot initialize the pass creation: no valid certificates were passed.",
|
||||||
@@ -19,7 +15,7 @@ const errors: MessageGroup = {
|
|||||||
NO_PASS_TYPE: "Cannot proceed with pass creation. Model definition (pass.json) has no valid type in it.\nRefer to https://apple.co/2wzyL5J to choose a valid pass type."
|
NO_PASS_TYPE: "Cannot proceed with pass creation. Model definition (pass.json) has no valid type in it.\nRefer to https://apple.co/2wzyL5J to choose a valid pass type."
|
||||||
};
|
};
|
||||||
|
|
||||||
const debugMessages: MessageGroup = {
|
const debugMessages = {
|
||||||
TRSTYPE_NOT_VALID: "Transit type changing rejected as not compliant with Apple Specifications. Transit type would become \"%s\" but should be in [PKTransitTypeAir, PKTransitTypeBoat, PKTransitTypeBus, PKTransitTypeGeneric, PKTransitTypeTrain]",
|
TRSTYPE_NOT_VALID: "Transit type changing rejected as not compliant with Apple Specifications. Transit type would become \"%s\" but should be in [PKTransitTypeAir, PKTransitTypeBoat, PKTransitTypeBus, PKTransitTypeGeneric, PKTransitTypeTrain]",
|
||||||
BRC_NOT_SUPPORTED: "Format not found among barcodes. Cannot set backward compatibility.",
|
BRC_NOT_SUPPORTED: "Format not found among barcodes. Cannot set backward compatibility.",
|
||||||
BRC_FORMATTYPE_UNMATCH: "Format must be a string or null. Cannot set backward compatibility.",
|
BRC_FORMATTYPE_UNMATCH: "Format must be a string or null. Cannot set backward compatibility.",
|
||||||
@@ -32,13 +28,15 @@ const debugMessages: MessageGroup = {
|
|||||||
PRS_REMOVED: "Personalization has been removed as it requires an NFC-enabled pass to work."
|
PRS_REMOVED: "Personalization has been removed as it requires an NFC-enabled pass to work."
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type AllMessages = keyof (typeof debugMessages & typeof errors);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a message with replaced values
|
* Creates a message with replaced values
|
||||||
* @param {string} messageName
|
* @param {string} messageName
|
||||||
* @param {any[]} values
|
* @param {any[]} values
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export default function format(messageName: string, ...values: any[]) {
|
export default function format(messageName: AllMessages, ...values: any[]) {
|
||||||
// reversing because it is better popping than shifting.
|
// reversing because it is better popping than shifting.
|
||||||
let replaceValues = values.reverse();
|
let replaceValues = values.reverse();
|
||||||
return resolveMessageName(messageName).replace(/%s/g, () => {
|
return resolveMessageName(messageName).replace(/%s/g, () => {
|
||||||
@@ -52,7 +50,7 @@ export default function format(messageName: string, ...values: any[]) {
|
|||||||
* @param {string} name
|
* @param {string} name
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function resolveMessageName(name: string): string {
|
function resolveMessageName(name: AllMessages): string {
|
||||||
if (!errors[name] && !debugMessages[name]) {
|
if (!errors[name] && !debugMessages[name]) {
|
||||||
return `<ErrorName "${name}" is not linked to any error messages>`;
|
return `<ErrorName "${name}" is not linked to any error messages>`;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user