mirror of
https://github.com/mokuappio/serverless-invoices.git
synced 2025-10-29 00:41:08 -04:00
Init commit
This commit is contained in:
24
src/utils/errors.js
Normal file
24
src/utils/errors.js
Normal file
@ -0,0 +1,24 @@
|
||||
export default class Errors {
|
||||
constructor(errors) {
|
||||
this.errors = errors;
|
||||
}
|
||||
|
||||
set(errors) {
|
||||
this.errors = errors;
|
||||
}
|
||||
|
||||
get(field) {
|
||||
if (this.has(field)) {
|
||||
return this.errors[field];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
has(field) {
|
||||
return this.errors && this.errors.hasOwnProperty(field);
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.errors = {};
|
||||
}
|
||||
}
|
||||
31
src/utils/helpers.js
Normal file
31
src/utils/helpers.js
Normal file
@ -0,0 +1,31 @@
|
||||
/* eslint-disable */
|
||||
export function uuidv4() {
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
||||
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
}
|
||||
|
||||
export function range(end, start = 0, step = 1) {
|
||||
const arr = [];
|
||||
for (let i = start; i < end; i += step) {
|
||||
arr.push(i);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a subset of the object based on a map of keys
|
||||
*
|
||||
* @param obj
|
||||
* @param map
|
||||
*/
|
||||
export function pick(obj, map) {
|
||||
const pickedKeys = Object.keys(obj)
|
||||
.filter(field => map.hasOwnProperty(field));
|
||||
const objSubset = {};
|
||||
pickedKeys.forEach((key) => {
|
||||
objSubset[map[key]] = obj[key];
|
||||
});
|
||||
return objSubset;
|
||||
}
|
||||
Reference in New Issue
Block a user