mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 16:25:21 +00:00
Added expiration() and void() methods and dateToW3CString() function to convert date in W3C format
This commit is contained in:
55
index.js
55
index.js
@@ -160,6 +160,40 @@ class Pass {
|
||||
return Buffer.from(strings.join("\n"), "utf8");
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets expirationDate property to the W3C date
|
||||
*
|
||||
* @method expiration
|
||||
* @params {String} date - the date in string
|
||||
* @returns {this}
|
||||
*/
|
||||
|
||||
expiration(date) {
|
||||
if (typeof date !== "string") {
|
||||
return this;
|
||||
}
|
||||
|
||||
const convDate = dateToW3CString(date);
|
||||
|
||||
if (convDate) {
|
||||
this.props.expirationDate = convDate;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets voided property to true
|
||||
*
|
||||
* @method void
|
||||
* @return {this}
|
||||
*/
|
||||
|
||||
void() {
|
||||
this.props.voided = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if pass model type is one of the supported ones
|
||||
*
|
||||
@@ -406,6 +440,27 @@ class Pass {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a date to W3C Standard format
|
||||
*
|
||||
* @function dateToW3Cstring
|
||||
* @params {String}
|
||||
*/
|
||||
|
||||
function dateToW3CString(date) {
|
||||
if (typeof date !== "string") {
|
||||
return "";
|
||||
}
|
||||
|
||||
let parsedDate = moment(date, ["MM-DD-YYYY"]).format();
|
||||
|
||||
if (parsedDate === "Invalid date") {
|
||||
return "";
|
||||
}
|
||||
|
||||
return parsedDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a filter to arg0 to remove hidden files names (starting with dot)
|
||||
* @function removeHidden
|
||||
|
||||
Reference in New Issue
Block a user