mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 23:25:26 +00:00
Added fieldsArea class to add fields to primaryFields, secondaryFields, etc
This commit is contained in:
39
fields.js
Normal file
39
fields.js
Normal file
@@ -0,0 +1,39 @@
|
||||
const schema = require("./schema");
|
||||
|
||||
class FieldsArea {
|
||||
constructor() {
|
||||
this.fields = [];
|
||||
}
|
||||
|
||||
push(...fields) {
|
||||
if (fields[0] instanceof Array && fields[0].length) {
|
||||
fields = fields[0];
|
||||
}
|
||||
|
||||
let validFields = fields.filter(f => typeof f === "object" && schema.isValid(f, schema.constants.field));
|
||||
|
||||
this.fields.push(...validFields);
|
||||
|
||||
return validFields.length;
|
||||
}
|
||||
|
||||
pop(quantity = -1) {
|
||||
if (!this.fields.length) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (quantity > -1) {
|
||||
let removedElements = this.fields.slice(quantity);
|
||||
this.fields = this.fields.slice(0, this.fields.length - quantity);
|
||||
|
||||
return removedElements;
|
||||
}
|
||||
|
||||
return this.fields.pop();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
areas: ["primaryFields", "secondaryFields", "auxiliaryFields", "backFields", "headerFields"],
|
||||
FieldsArea
|
||||
};
|
||||
Reference in New Issue
Block a user