mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 21:25:26 +00:00
Documented _validateType and changed its implementation
This commit is contained in:
16
index.js
16
index.js
@@ -25,7 +25,7 @@ class Pass {
|
|||||||
this.modelDirectory = null;
|
this.modelDirectory = null;
|
||||||
this._parseSettings(options)
|
this._parseSettings(options)
|
||||||
;// .then(() => console.log("WAT IS", this));
|
;// .then(() => console.log("WAT IS", this));
|
||||||
this.passTypes = /^(boardingPass|eventTicket|coupon|generic|storeCard)$/;
|
this.passTypes = ["boardingPass", "eventTicket", "coupon", "generic", "storeCard"];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -214,11 +214,19 @@ class Pass {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Checks if pass model type is one of the supported ones
|
||||||
|
|
||||||
|
@method _validateType
|
||||||
|
@params {Buffer} passBuffer - buffer of the pass structure content
|
||||||
|
@returns {Boolean} - true if type is supported, false otherwise.
|
||||||
|
*/
|
||||||
|
|
||||||
_validateType(passBuffer) {
|
_validateType(passBuffer) {
|
||||||
try {
|
try {
|
||||||
let passFile = JSON.parse(passBuffer.toString("utf8"));
|
let passFile = JSON.parse(passBuffer.toString("utf8"));
|
||||||
|
|
||||||
return Object.keys(passFile).some(key => this.passTypes.test(key));
|
return this.passTypes.some(passType => passFile.hasOwnProperty(passType));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -305,9 +313,7 @@ class Pass {
|
|||||||
try {
|
try {
|
||||||
let passFile = JSON.parse(passBuffer.toString("utf8"));
|
let passFile = JSON.parse(passBuffer.toString("utf8"));
|
||||||
|
|
||||||
for (let prop in options) {
|
Object.keys(options).forEach(opt => passFile[opt] = options[opt]);
|
||||||
passFile[prop] = options[prop];
|
|
||||||
}
|
|
||||||
|
|
||||||
return done(Buffer.from(JSON.stringify(passFile)));
|
return done(Buffer.from(JSON.stringify(passFile)));
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user