mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 21:25:26 +00:00
Added comments to FieldsArea class and its methods
This commit is contained in:
24
fields.js
24
fields.js
@@ -1,10 +1,25 @@
|
|||||||
const schema = require("./schema");
|
const schema = require("./schema");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pass fields area to be used as pass lower level keys
|
||||||
|
* @see https://apple.co/2wkUBd
|
||||||
|
*/
|
||||||
|
|
||||||
class FieldsArea {
|
class FieldsArea {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.fields = [];
|
this.fields = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A wrapper of Array.prototype.push to validate the pushed content with the schema.
|
||||||
|
* Accepts also one array of objects.
|
||||||
|
*
|
||||||
|
* @method push
|
||||||
|
* @params {Object[]} fields - the fields to be checked and pushed
|
||||||
|
* @params {schema.constants.field} fields[].* - each key must be compliant with schema.constants.field structure
|
||||||
|
* @returns {Number} - the amount of pushed elements (for checks)
|
||||||
|
*/
|
||||||
|
|
||||||
push(...fields) {
|
push(...fields) {
|
||||||
if (fields[0] instanceof Array && fields[0].length) {
|
if (fields[0] instanceof Array && fields[0].length) {
|
||||||
fields = fields[0];
|
fields = fields[0];
|
||||||
@@ -17,6 +32,15 @@ class FieldsArea {
|
|||||||
return validFields.length;
|
return validFields.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A wrapper of Array.prototype.pop and Array.prototype.slice to pop
|
||||||
|
* last element or n elements starting from the end.
|
||||||
|
*
|
||||||
|
* @method pop
|
||||||
|
* @params {Number} [quantity=-1] - the amount of elements to be removed
|
||||||
|
* @returns {Number} - the amount of removed elements
|
||||||
|
*/
|
||||||
|
|
||||||
pop(quantity = -1) {
|
pop(quantity = -1) {
|
||||||
if (!this.fields.length) {
|
if (!this.fields.length) {
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|||||||
Reference in New Issue
Block a user