New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@sebgroup/frontend-tools

Package Overview
Dependencies
Maintainers
4
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sebgroup/frontend-tools - npm Package Compare versions

Comparing version 2.0.2 to 2.1.0

arrayToObject/index.js.map

0

arrayToObject/arrayToObject.d.ts

@@ -0,0 +0,0 @@ /**

@@ -1,2 +0,16 @@

function n(n,t=""){return Object.assign({},...n.map((n,e)=>({[t+e]:n})))}export{n as arrayToObject};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Converts an array into an object
* @param array The target array
* @param keyField The key to be used as identifier for each key of the new object
* @returns {Object} The generated object
*/
function arrayToObject(array, keyField = "") {
return Object.assign({}, ...array.map((item, index) => ({ [keyField + index]: item })));
}
exports.arrayToObject = arrayToObject;
//# sourceMappingURL=arrayToObject.js.map
export * from "./arrayToObject";

@@ -1,1 +0,10 @@

export * from "./arrayToObject";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var arrayToObject = require('./arrayToObject.js');
exports.arrayToObject = arrayToObject.arrayToObject;
//# sourceMappingURL=index.js.map

@@ -0,0 +0,0 @@ /**

@@ -1,2 +0,15 @@

function t(t){return t.charAt(0).toUpperCase()+t.substr(1,t.length-1)}export{t as capitalize};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Capitalizes a string word. It doesn't capitalize a sentence, only the first letter.
* @param {string} str The string needed to be capitalized
* @returns {string} The capitalized string
*/
function capitalize(str) {
return str.charAt(0).toUpperCase() + str.substr(1, str.length - 1);
}
exports.capitalize = capitalize;
//# sourceMappingURL=capitalize.js.map
export * from "./capitalize";

@@ -1,1 +0,10 @@

export * from "./capitalize";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var capitalize = require('./capitalize.js');
exports.capitalize = capitalize.capitalize;
//# sourceMappingURL=index.js.map

@@ -1,2 +0,17 @@

function n(n,t,e){return n&&n.length>=t&&n.length<=e}export{n as checkStringLength};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Check if a string matches a specific length
* @param {string} value The string to be checked
* @param {number} min The desired minimum length
* @param {number} max The desired maximum length
* @returns {boolean} True if the string length falls between the minimum and the maximum
*/
function checkStringLength(value, min, max) {
return value && (value.length >= min && value.length <= max);
}
exports.checkStringLength = checkStringLength;
//# sourceMappingURL=checkStringLength.js.map
export * from "./checkStringLength";

@@ -1,1 +0,10 @@

export * from "./checkStringLength";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var checkStringLength = require('./checkStringLength.js');
exports.checkStringLength = checkStringLength.checkStringLength;
//# sourceMappingURL=index.js.map

@@ -0,0 +0,0 @@ /**

@@ -1,2 +0,19 @@

function e(e){return e instanceof Date||(e=new Date(e)),e.setHours(0,0,0,0),e}export{e as clearTime};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Clear the time of a date object
* @param {Date} date The date to clear its time
* @returns {Date} The cleared date object
*/
function clearTime(date) {
if (!(date instanceof Date)) {
date = new Date(date);
}
date.setHours(0, 0, 0, 0);
return date;
}
exports.clearTime = clearTime;
//# sourceMappingURL=clearTime.js.map
export * from "./clearTime";

@@ -1,1 +0,10 @@

export * from "./clearTime";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var clearTime = require('./clearTime.js');
exports.clearTime = clearTime.clearTime;
//# sourceMappingURL=index.js.map

@@ -0,0 +0,0 @@ export interface SetItemOptions {

@@ -1,2 +0,99 @@

class e{get length(){return this.keys().length}getItem(e){return e&&decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*"+encodeURIComponent(e).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=\\s*([^;]*).*$)|^.*$"),"$1"))||null}setItem(e,t,o={}){if(!e||/^(?:expires|max\-age|path|domain|secure)$/i.test(e))return!1;let n="",s="";return o&&(o.expires&&o.expires instanceof Date&&(n="; Expires="+o.expires.toUTCString()),o.maxAge&&"number"==typeof o.maxAge&&o.maxAge!==1/0&&(s="; Max-age="+o.maxAge)),document.cookie=`${encodeURIComponent(e)}=${encodeURIComponent(t)}${n}${s}`,this.hasItem(e)}removeItem(e){return this.hasItem(e)&&(document.cookie=encodeURIComponent(e)+"=; max-age=-1"),!this.hasItem(e)}hasItem(e){return!(!e||/^(?:expires|max\-age|path|domain|secure)$/i.test(e))&&new RegExp("(?:^|;\\s*)"+encodeURIComponent(e).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=").test(document.cookie)}clear(){const e=document.cookie.split(";");for(let t=0;t<e.length;t++){const o=e[t],n=o.indexOf("="),s=n>-1?o.substr(0,n):o,r=n>-1?o.substr(n+1,o.length):"";document.cookie=`${s}${r?"=":""}; max-age=-1`}}keys(){const e=document.cookie.replace(/((?:^|\s*;)[^\=]+)(?=;|$)|^\s*|\s*(?:\=[^;]*)?(?:\1|$)/g,"").split(/\s*(?:\=[^;]*)?;\s*/);for(let t=e.length,o=0;o<t;o++)e[o]=decodeURIComponent(e[o]);return e}key(e){return this.keys()[e]}}export{e as CookieStorage};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/**
* CookieStorage is a handler for reading and writing cookies in Javascript
* Usage is similar to `localStorage` and `sessionStorage`
*/
class CookieStorage {
get length() { return this.keys().length; }
/**
* Retrieve an item from the stored cookie
* @param key The key of the cookie to be retrieved
* @returns The value of the cookie, `null` if it doesn't exist
*/
getItem(key) {
if (!key) {
return null;
}
return decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent(key).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || null;
}
/**
* Sets an item to the stored cookie
* @param key The key of the cookie to be set
* @param value The value of the cookie
* @param options Available options are `expires`, `maxAge` and `secure` @see SetItemOptions interface for reference
* @returns `true` if successful
*/
setItem(key, value, options = {}) {
if (!key || /^(?:expires|max\-age|path|domain|secure)$/i.test(key)) {
return false;
}
let expires = "";
let maxAge = "";
if (options) {
if (options.expires && options.expires instanceof Date) {
expires = "; Expires=" + options.expires.toUTCString();
}
if (options.maxAge && typeof options.maxAge === "number" && options.maxAge !== Infinity) {
maxAge = `; Max-age=${options.maxAge}`;
}
}
document.cookie = `${encodeURIComponent(key)}=${encodeURIComponent(value)}${expires}${maxAge}`;
return this.hasItem(key);
}
/**
* Remove an item from the stored cookie
* @param {string} key The key of the cookie to be removed
* @returns {boolean} `true` if successful
*/
removeItem(key) {
if (this.hasItem(key)) {
document.cookie = `${encodeURIComponent(key)}=; max-age=-1`;
}
return !this.hasItem(key);
}
/**
* Verifies if an item exists in the cookie
* @param {string} key The key of the item to be verified
* @returns {boolean} `true` if it exists
*/
hasItem(key) {
if (!key || /^(?:expires|max\-age|path|domain|secure)$/i.test(key)) {
return false;
}
return (new RegExp("(?:^|;\\s*)" + encodeURIComponent(key).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=")).test(document.cookie);
}
clear() {
const cookies = document.cookie.split(";");
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i];
const eqPos = cookie.indexOf("=");
const name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
const value = eqPos > -1 ? cookie.substr(eqPos + 1, cookie.length) : "";
document.cookie = `${name}${value ? "=" : ""}; max-age=-1`;
}
}
/**
* Retrives the list of keys in the stored cookie
* @returns The list of keys in the stored cookie
*/
keys() {
const aKeys = document.cookie.replace(/((?:^|\s*;)[^\=]+)(?=;|$)|^\s*|\s*(?:\=[^;]*)?(?:\1|$)/g, "").split(/\s*(?:\=[^;]*)?;\s*/);
for (let nLen = aKeys.length, nIdx = 0; nIdx < nLen; nIdx++) {
aKeys[nIdx] = decodeURIComponent(aKeys[nIdx]);
}
return aKeys;
}
/**
* @param index The index of the array of keys
* @returns The key at the given index, if any
*/
key(index) {
return this.keys()[index];
}
}
exports.CookieStorage = CookieStorage;
//# sourceMappingURL=CookieStorage.js.map
export * from "./CookieStorage";

@@ -1,1 +0,10 @@

export * from "./CookieStorage";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var CookieStorage = require('./CookieStorage.js');
exports.CookieStorage = CookieStorage.CookieStorage;
//# sourceMappingURL=index.js.map

@@ -0,0 +0,0 @@ /**

@@ -1,2 +0,25 @@

import{isValidDate as e}from"../isValidDate/isValidDate.js";function t(t,a,i){if(i&&console.warn('The range argument has been depracated. The range "day" will be used instead. \nTo compare units less than day use firstDate.getTime() - secondDate.getTime() to get milliseconds'),!e(t)||!e(a))throw new Error("both parameters must be of type Date");return Math.ceil((a.getTime()-t.getTime())/1e3/60/60/24)}export{t as dateDiff};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var isValidDate = require('../isValidDate/isValidDate.js');
/**
* Compare and returns the dirrence between two dates
* @param {Date} firstDate { date} the first date
* @param {Date} secondDate { date } second date to compare against
* @param {any} range DEPRACATED (This argument is depracated)
* @returns {number} The difference in days
*/
function dateDiff(firstDate, secondDate, range) {
if (range) {
console.warn("The range argument has been depracated. The range \"day\" will be used instead. \nTo compare units less than day use firstDate.getTime() - secondDate.getTime() to get milliseconds");
}
if (!isValidDate.isValidDate(firstDate) || !isValidDate.isValidDate(secondDate)) {
throw new Error("both parameters must be of type Date");
}
return Math.ceil((secondDate.getTime() - firstDate.getTime()) / 1000 / 60 / 60 / 24);
}
exports.dateDiff = dateDiff;
//# sourceMappingURL=dateDiff.js.map
export * from "./dateDiff";

@@ -1,1 +0,10 @@

export * from "./dateDiff";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var dateDiff = require('./dateDiff.js');
exports.dateDiff = dateDiff.dateDiff;
//# sourceMappingURL=index.js.map

@@ -0,0 +0,0 @@ /**

@@ -1,2 +0,48 @@

function e(t,n=new WeakMap){if(Object(t)!==t)return t;if(t instanceof Set)return new Set(t);if(n.has(t))return n.get(t);{let r=Object.create(null);return t instanceof Date?r=new Date(t.getTime()):t instanceof RegExp?r=new RegExp(t.source,t.flags):t.constructor&&(r="symbol"==typeof(o=t)||"object"==typeof o&&"[object Symbol]"===Object.prototype.toString.call(o)?t:new t.constructor),n.set(t,r),t instanceof Map&&Array.from(t,([t,o])=>r.set(t,e(o,n))),Object.assign(r,...Object.keys(t).map(o=>({[o]:e(t[o],n)})))}var o}export{e as deepCopy};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Get a deep copy of an object
* @param obj any complex object
* @returns {Object} The generated object
*/
function deepCopy(obj, hash = new WeakMap()) {
if (Object(obj) !== obj) { // Primitive type
return obj;
}
else if (obj instanceof Set) { // Setter
return new Set(obj);
}
else if (hash.has(obj)) { // Cyclic reference
return hash.get(obj);
}
else {
let result = Object.create(null);
if (obj instanceof Date) { // Date object
result = new Date(obj.getTime());
}
else if (obj instanceof RegExp) { // Regular expression
result = new RegExp(obj.source, obj.flags);
}
else if (obj.constructor) {
result = isSymbol(obj) ? obj : new obj.constructor(); // symbol should be referenced only
}
hash.set(obj, result);
if (obj instanceof Map) { // Map object
Array.from(obj, ([key, val]) => result.set(key, deepCopy(val, hash)));
}
return Object.assign(result, ...Object.keys(obj).map((key) => ({ [key]: deepCopy(obj[key], hash) })));
}
}
/**
* check if the variable is a symbol
* @param x obj or any datatype
*/
function isSymbol(x) {
return typeof x === "symbol" ||
typeof x === "object" && Object.prototype.toString.call(x) === "[object Symbol]";
}
exports.deepCopy = deepCopy;
//# sourceMappingURL=deepCopy.js.map
export * from "./deepCopy";

@@ -1,1 +0,10 @@

export * from "./deepCopy";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var deepCopy = require('./deepCopy.js');
exports.deepCopy = deepCopy.deepCopy;
//# sourceMappingURL=index.js.map

@@ -0,0 +0,0 @@ declare type DateTimeFormat = Intl.DateTimeFormatOptions;

@@ -1,2 +0,21 @@

function t(t,e={day:"numeric",month:"long",year:"numeric"},n="sv-SE"){const r=Date.parse(t);return isNaN(r)?String(t):Intl.DateTimeFormat(n||"sv-SE",e||{}).format(new Date(r))}export{t as formatDate};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Date formatter
* @param date The date object or date string
* @param format The output format
* @param locale The locale. Default is `sv-SE`
* @returns The formattted date or the input if it fails to parse it
*/
function formatDate(date, format = { day: "numeric", month: "long", year: "numeric" }, locale = "sv-SE") {
const parsedDate = Date.parse(date);
if (isNaN(parsedDate)) {
return String(date);
}
return Intl.DateTimeFormat(locale || "sv-SE", format || {}).format(new Date(parsedDate));
}
exports.formatDate = formatDate;
//# sourceMappingURL=formatDate.js.map
export * from "./formatDate";

@@ -1,1 +0,10 @@

export * from "./formatDate";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var formatDate = require('./formatDate.js');
exports.formatDate = formatDate.formatDate;
//# sourceMappingURL=index.js.map

@@ -0,0 +0,0 @@ export declare type ValidationSpecs = {

@@ -1,2 +0,196 @@

import{isValidDate as e}from"../isValidDate/isValidDate.js";import{deepCopy as t}from"../deepCopy/deepCopy.js";import{isEmpty as r}from"../isEmpty/isEmpty.js";import{isPhoneNumber as s}from"../isPhoneNumber/isPhoneNumber.js";import{isEmail as a}from"../isEmail/isEmail.js";import{isStrongPassword as i}from"../isStrongPassword/isStrongPassword.js";import{isDateBefore as o}from"../isDateBefore/isDateBefore.js";import{isDateAfter as n}from"../isDateAfter/isDateAfter.js";class l{constructor(e,t){this.value=null,this.specs={},this.validations=[],this.name=e,this.value=t,this.specs={},this.validations=[]}}class m{constructor(e){if(this.formObject=new Map,this.formObjectErrors={},this.customValidators=[],!r(e)&&"object"==typeof e){const r=t(e);this.originalFormObject=r;for(const e in r)this.formObject.set(e,new l(e,r[e]))}}addValidation(e,t,s){return e&&e instanceof Array&&t&&"string"==typeof t&&this.isValidType(t)&&(e.length?e.map(e=>{this.formObject.has(e)&&(this.formObject.get(e).validations.push(t),r(s)||(this.formObject.get(e).specs=Object.assign(Object.assign({},this.formObject.get(e).specs),s)))}):this.formObject.forEach(e=>{e.validations.push(t),r(s)||(e.specs=Object.assign(Object.assign({},e.specs),s))})),this}addCustomValidation(e,t){return e&&e instanceof Array&&e.length&&t&&t instanceof Function&&this.customValidators.push({errorFields:e,validator:t}),this}getErrors(){return this.formObjectErrors}getError(e){return this.formObjectErrors[e]}validate(){return this.formObject.forEach(e=>{if(e.validations.length){let t,s=0;do{t=this.validateField(e.value,e.validations[s],e.specs),r(t)||(this.formObjectErrors[e.name]=t),s++}while(s<e.validations.length&&!t)}}),this.customValidators.length&&this.customValidators.map(e=>{const t=e.validator(this.originalFormObject);e.errorFields.map(e=>{this.formObject.has(e)&&!this.getError(e)&&t&&(this.formObjectErrors[e]=t)})}),this}validateField(t,l,m){let h=null;const u=new Date(t),c=r(t);if(c&&"required"!==l)return null;const d=e(u);switch(l){case"required":return c?{errorCode:"empty"}:null;case"isDate":return d?null:{errorCode:"invalidDate"};case"dateRange":return d?(m.minDate&&(h=o(u,m.minDate)?{errorCode:"beforeMinDate",specs:{minDate:m.minDate}}:null),!h&&m.maxDate&&(h=n(u,m.maxDate)?{errorCode:"afterMaxDate",specs:{maxDate:m.maxDate}}:null),h):null;case"textLength":return"string"==typeof t?(m.minLength&&(h=t.length<m.minLength?{errorCode:"lessThanMinLength",specs:{minLength:m.minLength}}:null),!h&&m.maxLength&&(h=t.length>m.maxLength?{errorCode:"moreThanMaxLength",specs:{maxLength:m.maxLength}}:null),h):null;case"valueRange":return"number"==typeof t?(m.minValue&&(h=t<m.minValue?{errorCode:"lessThanMinValue",specs:{minValue:m.minValue}}:null),!h&&m.maxValue&&(h=t>m.maxValue?{errorCode:"moreThanMaxValue",specs:{maxValue:m.maxValue}}:null),h):null;case"validEmail":return a(t)?null:{errorCode:"invalidEmail"};case"strongPassword":return i(t)?null:{errorCode:"weakPassword"};case"isPhoneNumber":return s(t)?null:{errorCode:"invalidPhoneNumber"}}}isValidType(e){return{required:!0,isDate:!0,dateRange:!0,textLength:!0,valueRange:!0,validEmail:!0,strongPassword:!0,isPhoneNumber:!0}.hasOwnProperty(e)}}export{m as FormValidator};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var isEmpty = require('../isEmpty/isEmpty.js');
var isPhoneNumber = require('../isPhoneNumber/isPhoneNumber.js');
var isEmail = require('../isEmail/isEmail.js');
var deepCopy = require('../deepCopy/deepCopy.js');
var isStrongPassword = require('../isStrongPassword/isStrongPassword.js');
var isValidDate = require('../isValidDate/isValidDate.js');
var isDateBefore = require('../isDateBefore/isDateBefore.js');
var isDateAfter = require('../isDateAfter/isDateAfter.js');
class ValidatorModelItem {
constructor(name, value) {
this.value = null;
this.specs = {};
this.validations = [];
this.name = name;
this.value = value;
this.specs = {};
this.validations = [];
}
}
class FormValidator {
constructor(formObject) {
this.formObject = new Map();
this.formObjectErrors = {};
this.customValidators = [];
if (!isEmpty.isEmpty(formObject) && typeof formObject === "object") {
const clone = deepCopy.deepCopy(formObject);
this.originalFormObject = clone;
for (const field in clone) {
this.formObject.set(field, new ValidatorModelItem(field, clone[field]));
}
}
}
addValidation(fields, type, specs) {
if (fields && fields instanceof Array && type && typeof type === "string" && this.isValidType(type)) {
if (fields.length) {
fields.map((field) => {
if (this.formObject.has(field)) {
this.formObject.get(field).validations.push(type);
if (!isEmpty.isEmpty(specs)) {
this.formObject.get(field).specs = Object.assign(Object.assign({}, this.formObject.get(field).specs), specs);
}
}
});
}
else {
this.formObject.forEach((item) => {
item.validations.push(type);
if (!isEmpty.isEmpty(specs)) {
item.specs = Object.assign(Object.assign({}, item.specs), specs);
}
});
}
}
return this;
}
/**
* Add a custom validator that returns an error message if found
* @param {Array<string>} errorFields The fields where the error is reported to
* @param {function} validator The validator method
* @returns {FormValidator} The form validator object
* @example addValidator(["balance", "payment"], ["payment"], (balance: number, payment: number) => { return payment > balance ? "The payment exceeds your balance" : null; });
*/
addCustomValidation(errorFields, validator) {
if (errorFields && errorFields instanceof Array && errorFields.length && validator && validator instanceof Function) {
this.customValidators.push({ errorFields, validator });
}
return this;
}
/**
* Get the error found in the form object. Has to be called after `validate` method has been called.
* @returns {any} The form object object populated by validation errors, if found any. Otherwise, it's an empty object.
*/
getErrors() {
return this.formObjectErrors;
}
/**
* Get a specific error found during validation, if any. Has to be called after `validate` method has been called.
* @returns {any} The error of the specific item in the form, if any.
*/
getError(name) {
return this.formObjectErrors[name];
}
/**
* Validates the form object passed in the constructor
* @returns {FormValidator} The form validator object
*/
validate() {
this.formObject.forEach((item) => {
if (item.validations.length) {
let fieldError;
let i = 0;
do {
fieldError = this.validateField(item.value, item.validations[i], item.specs);
if (!isEmpty.isEmpty(fieldError)) {
this.formObjectErrors[item.name] = fieldError;
}
i++;
} while (i < item.validations.length && !fieldError);
}
});
if (this.customValidators.length) {
this.customValidators.map((customValidator) => {
const customValidatorError = customValidator.validator(this.originalFormObject);
customValidator.errorFields.map((field) => {
if (this.formObject.has(field) && !this.getError(field) && customValidatorError) {
this.formObjectErrors[field] = customValidatorError;
}
});
});
}
return this;
}
/**
* Validate a parameter in the form formObject based on predefined set of criteria
* @param {ValidatorModelItem} fieldObject The field object stored in the local formObject
* @returns {string} The error found in the parameter
*/
validateField(value, type, specs) {
let fieldError = null;
// Don't validate an empty field if it's not required
const date = new Date(value);
const empty = isEmpty.isEmpty(value);
if (empty && type !== "required") {
return null;
}
const valid = isValidDate.isValidDate(date);
switch (type) {
case "required": return empty ? { errorCode: "empty" } : null;
case "isDate": return valid ? null : { errorCode: "invalidDate" };
case "dateRange":
if (valid) {
if (specs.minDate) {
fieldError = isDateBefore.isDateBefore(date, specs.minDate) ? { errorCode: "beforeMinDate", specs: { minDate: specs.minDate } } : null;
}
if (!fieldError && specs.maxDate) {
fieldError = isDateAfter.isDateAfter(date, specs.maxDate) ? { errorCode: "afterMaxDate", specs: { maxDate: specs.maxDate } } : null;
}
return fieldError;
}
else {
return null;
}
case "textLength":
if (typeof value === "string") {
if (specs.minLength) {
fieldError = value.length < specs.minLength ? { errorCode: "lessThanMinLength", specs: { minLength: specs.minLength } } : null;
}
if (!fieldError && specs.maxLength) {
fieldError = value.length > specs.maxLength ? { errorCode: "moreThanMaxLength", specs: { maxLength: specs.maxLength } } : null;
}
return fieldError;
}
else {
return null;
}
case "valueRange":
if (typeof value === "number") {
if (specs.minValue) {
fieldError = value < specs.minValue ? { errorCode: "lessThanMinValue", specs: { minValue: specs.minValue } } : null;
}
if (!fieldError && specs.maxValue) {
fieldError = value > specs.maxValue ? { errorCode: "moreThanMaxValue", specs: { maxValue: specs.maxValue } } : null;
}
return fieldError;
}
else {
return null;
}
case "validEmail": return isEmail.isEmail(value) ? null : { errorCode: "invalidEmail" };
case "strongPassword": return isStrongPassword.isStrongPassword(value) ? null : { errorCode: "weakPassword" };
case "isPhoneNumber": return isPhoneNumber.isPhoneNumber(value) ? null : { errorCode: "invalidPhoneNumber" };
}
}
// Helpers
isValidType(type) {
const availableValidationTypes = {
required: true,
isDate: true,
dateRange: true,
textLength: true,
valueRange: true,
validEmail: true,
strongPassword: true,
isPhoneNumber: true,
};
return availableValidationTypes.hasOwnProperty(type);
}
}
exports.FormValidator = FormValidator;
//# sourceMappingURL=FormValidator.js.map
export * from "./FormValidator";

@@ -1,1 +0,10 @@

export * from "./FormValidator";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var FormValidator = require('./FormValidator.js');
exports.FormValidator = FormValidator.FormValidator;
//# sourceMappingURL=index.js.map

@@ -1,2 +0,42 @@

import{isBrowserOpera as r}from"../isBrowserOpera/isBrowserOpera.js";import{isBrowserFirefox as o}from"../isBrowserFirefox/isBrowserFirefox.js";import{isBrowserSafari as s}from"../isBrowserSafari/isBrowserSafari.js";import{isBrowserChrome as e}from"../isBrowserChrome/isBrowserChrome.js";import{isBrowserIE as i}from"../isBrowserIE/isBrowserIE.js";import{isBrowserEdge as m}from"../isBrowserEdge/isBrowserEdge.js";function f(){return r()?"Opera":o()?"Firefox":s()?"Safari":i()?"IE":m()?"Edge":e()?"Chrome":""}export{f as getBrowserName};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var isBrowserOpera = require('../isBrowserOpera/isBrowserOpera.js');
var isBrowserFirefox = require('../isBrowserFirefox/isBrowserFirefox.js');
var isBrowserSafari = require('../isBrowserSafari/isBrowserSafari.js');
var isBrowserChrome = require('../isBrowserChrome/isBrowserChrome.js');
var isBrowserIE = require('../isBrowserIE/isBrowserIE.js');
var isBrowserEdge = require('../isBrowserEdge/isBrowserEdge.js');
/**
* Get the name of the current browser
* @note The method detects the browser by features
* @returns {string} The name of the browser
*/
function getBrowserName() {
if (isBrowserOpera.isBrowserOpera()) {
return "Opera";
}
else if (isBrowserFirefox.isBrowserFirefox()) {
return "Firefox";
}
else if (isBrowserSafari.isBrowserSafari()) {
return "Safari";
}
else if (isBrowserIE.isBrowserIE()) {
return "IE";
}
else if (isBrowserEdge.isBrowserEdge()) {
return "Edge";
}
else if (isBrowserChrome.isBrowserChrome()) {
return "Chrome";
}
else {
return "";
}
}
exports.getBrowserName = getBrowserName;
//# sourceMappingURL=getBrowserName.js.map
export * from "./getBrowserName";

@@ -1,1 +0,10 @@

export * from "./getBrowserName";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var getBrowserName = require('./getBrowserName.js');
exports.getBrowserName = getBrowserName.getBrowserName;
//# sourceMappingURL=index.js.map

@@ -1,2 +0,33 @@

function e(){const e=navigator.userAgent;let t,r=e.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||[];return/trident/i.test(r[1])?(t=/\brv[ :]+(\d+)/g.exec(e)||[],+(t[1]||0)):"Chrome"===r[1]&&(t=e.match(/\bOPR|Edge\/(\d+)/),null!=t)?+t[1]||0:(r=r[2]?[r[1],r[2]]:[navigator.appName,navigator.appVersion,"-?"],t=e.match(/version\/(\d+)/i),null!=t&&r.splice(1,1,t[1]),+r[1]||0)}export{e as getBrowserVersion};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Get the version of the current browser
* @note This method detects the browser version by the navigator's user agent (`navigator.userAgent`)
* @returns {number} The browser version, it will return `0` if it fails to find it
*/
function getBrowserVersion() {
const userAgent = navigator.userAgent;
let temp;
let match = userAgent.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
if (/trident/i.test(match[1])) {
temp = /\brv[ :]+(\d+)/g.exec(userAgent) || [];
return +(temp[1] || 0);
}
if (match[1] === "Chrome") {
temp = userAgent.match(/\bOPR|Edge\/(\d+)/);
if (temp != null) {
return +temp[1] || 0;
}
}
match = match[2] ? [match[1], match[2]] : [navigator.appName, navigator.appVersion, "-?"];
temp = userAgent.match(/version\/(\d+)/i);
if (temp != null) {
match.splice(1, 1, temp[1]);
}
return +match[1] || 0;
}
exports.getBrowserVersion = getBrowserVersion;
//# sourceMappingURL=getBrowserVersion.js.map
export * from "./getBrowserVersion";

@@ -1,1 +0,10 @@

export * from "./getBrowserVersion";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var getBrowserVersion = require('./getBrowserVersion.js');
exports.getBrowserVersion = getBrowserVersion.getBrowserVersion;
//# sourceMappingURL=index.js.map

@@ -0,0 +0,0 @@ export * from "./arrayToObject";

@@ -1,2 +0,78 @@

export{arrayToObject}from"./arrayToObject/arrayToObject.js";export{capitalize}from"./capitalize/capitalize.js";export{checkStringLength}from"./checkStringLength/checkStringLength.js";export{clearTime}from"./clearTime/clearTime.js";export{CookieStorage}from"./CookieStorage/CookieStorage.js";export{isValidDate}from"./isValidDate/isValidDate.js";export{dateDiff}from"./dateDiff/dateDiff.js";export{deepCopy}from"./deepCopy/deepCopy.js";export{formatDate}from"./formatDate/formatDate.js";export{isEmpty}from"./isEmpty/isEmpty.js";export{isPhoneNumber}from"./isPhoneNumber/isPhoneNumber.js";export{isEmail}from"./isEmail/isEmail.js";export{isStrongPassword}from"./isStrongPassword/isStrongPassword.js";export{isDateBefore}from"./isDateBefore/isDateBefore.js";export{isDateAfter}from"./isDateAfter/isDateAfter.js";export{FormValidator}from"./FormValidator/FormValidator.js";export{isBrowserOpera}from"./isBrowserOpera/isBrowserOpera.js";export{isBrowserFirefox}from"./isBrowserFirefox/isBrowserFirefox.js";export{isBrowserSafari}from"./isBrowserSafari/isBrowserSafari.js";export{isBrowserChrome}from"./isBrowserChrome/isBrowserChrome.js";export{isBrowserIE}from"./isBrowserIE/isBrowserIE.js";export{isBrowserEdge}from"./isBrowserEdge/isBrowserEdge.js";export{getBrowserName}from"./getBrowserName/getBrowserName.js";export{getBrowserVersion}from"./getBrowserVersion/getBrowserVersion.js";export{isPrimitive}from"./isPrimitive/isPrimitive.js";export{isSameDate}from"./isSameDate/isSameDate.js";export{isSameObject}from"./isSameObject/isSameObject.js";export{modifyDate}from"./modifyDate/modifyDate.js";export{randomId}from"./randomId/randomId.js";export{StorageManagement}from"./StorageManagement/StorageManagement.js";export{stringInsert}from"./stringInsert/stringInsert.js";export{toCurrency}from"./toCurrency/toCurrency.js";export{toDate}from"./toDate/toDate.js";export{toggleBodyOverflow}from"./toggleBodyOverflow/toggleBodyOverflow.js";export{toLocalDateString}from"./toLocalDateString/toLocalDateString.js";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var arrayToObject = require('./arrayToObject/arrayToObject.js');
var capitalize = require('./capitalize/capitalize.js');
var checkStringLength = require('./checkStringLength/checkStringLength.js');
var clearTime = require('./clearTime/clearTime.js');
var CookieStorage = require('./CookieStorage/CookieStorage.js');
var dateDiff = require('./dateDiff/dateDiff.js');
var deepCopy = require('./deepCopy/deepCopy.js');
var formatDate = require('./formatDate/formatDate.js');
var FormValidator = require('./FormValidator/FormValidator.js');
var getBrowserName = require('./getBrowserName/getBrowserName.js');
var getBrowserVersion = require('./getBrowserVersion/getBrowserVersion.js');
var isBrowserChrome = require('./isBrowserChrome/isBrowserChrome.js');
var isBrowserEdge = require('./isBrowserEdge/isBrowserEdge.js');
var isBrowserFirefox = require('./isBrowserFirefox/isBrowserFirefox.js');
var isBrowserIE = require('./isBrowserIE/isBrowserIE.js');
var isBrowserOpera = require('./isBrowserOpera/isBrowserOpera.js');
var isBrowserSafari = require('./isBrowserSafari/isBrowserSafari.js');
var isDateAfter = require('./isDateAfter/isDateAfter.js');
var isDateBefore = require('./isDateBefore/isDateBefore.js');
var isEmail = require('./isEmail/isEmail.js');
var isEmpty = require('./isEmpty/isEmpty.js');
var isPhoneNumber = require('./isPhoneNumber/isPhoneNumber.js');
var isPrimitive = require('./isPrimitive/isPrimitive.js');
var isSameDate = require('./isSameDate/isSameDate.js');
var isSameObject = require('./isSameObject/isSameObject.js');
var isStrongPassword = require('./isStrongPassword/isStrongPassword.js');
var isValidDate = require('./isValidDate/isValidDate.js');
var modifyDate = require('./modifyDate/modifyDate.js');
var randomId = require('./randomId/randomId.js');
var StorageManagement = require('./StorageManagement/StorageManagement.js');
var stringInsert = require('./stringInsert/stringInsert.js');
var toCurrency = require('./toCurrency/toCurrency.js');
var toDate = require('./toDate/toDate.js');
var toggleBodyOverflow = require('./toggleBodyOverflow/toggleBodyOverflow.js');
var toLocalDateString = require('./toLocalDateString/toLocalDateString.js');
exports.arrayToObject = arrayToObject.arrayToObject;
exports.capitalize = capitalize.capitalize;
exports.checkStringLength = checkStringLength.checkStringLength;
exports.clearTime = clearTime.clearTime;
exports.CookieStorage = CookieStorage.CookieStorage;
exports.dateDiff = dateDiff.dateDiff;
exports.deepCopy = deepCopy.deepCopy;
exports.formatDate = formatDate.formatDate;
exports.FormValidator = FormValidator.FormValidator;
exports.getBrowserName = getBrowserName.getBrowserName;
exports.getBrowserVersion = getBrowserVersion.getBrowserVersion;
exports.isBrowserChrome = isBrowserChrome.isBrowserChrome;
exports.isBrowserEdge = isBrowserEdge.isBrowserEdge;
exports.isBrowserFirefox = isBrowserFirefox.isBrowserFirefox;
exports.isBrowserIE = isBrowserIE.isBrowserIE;
exports.isBrowserOpera = isBrowserOpera.isBrowserOpera;
exports.isBrowserSafari = isBrowserSafari.isBrowserSafari;
exports.isDateAfter = isDateAfter.isDateAfter;
exports.isDateBefore = isDateBefore.isDateBefore;
exports.isEmail = isEmail.isEmail;
exports.isEmpty = isEmpty.isEmpty;
exports.isPhoneNumber = isPhoneNumber.isPhoneNumber;
exports.isPrimitive = isPrimitive.isPrimitive;
exports.isSameDate = isSameDate.isSameDate;
exports.isSameObject = isSameObject.isSameObject;
exports.isStrongPassword = isStrongPassword.isStrongPassword;
exports.isValidDate = isValidDate.isValidDate;
exports.modifyDate = modifyDate.modifyDate;
exports.randomId = randomId.randomId;
exports.StorageManagement = StorageManagement.StorageManagement;
exports.stringInsert = stringInsert.stringInsert;
exports.toCurrency = toCurrency.toCurrency;
exports.toDate = toDate.toDate;
exports.toggleBodyOverflow = toggleBodyOverflow.toggleBodyOverflow;
exports.toLocalDateString = toLocalDateString.toLocalDateString;
//# sourceMappingURL=index.js.map
export * from "./isBrowserChrome";

@@ -1,1 +0,10 @@

export * from "./isBrowserChrome";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var isBrowserChrome = require('./isBrowserChrome.js');
exports.isBrowserChrome = isBrowserChrome.isBrowserChrome;
//# sourceMappingURL=index.js.map

@@ -1,2 +0,14 @@

function o(){return!(!window.chrome||!window.chrome.webstore&&!window.chrome.runtime)}export{o as isBrowserChrome};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Check if the current browser is Chrome
* @returns {boolean} True if Chrome
*/
function isBrowserChrome() {
return !!window.chrome && (!!window.chrome.webstore || !!window.chrome.runtime);
}
exports.isBrowserChrome = isBrowserChrome;
//# sourceMappingURL=isBrowserChrome.js.map
export * from "./isBrowserEdge";

@@ -1,1 +0,10 @@

export * from "./isBrowserEdge";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var isBrowserEdge = require('./isBrowserEdge.js');
exports.isBrowserEdge = isBrowserEdge.isBrowserEdge;
//# sourceMappingURL=index.js.map

@@ -1,2 +0,14 @@

function i(){return!window.isIE&&!!window.StyleMedia}export{i as isBrowserEdge};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Check if the current browser is Edge
* @returns {boolean} True if Edge
*/
function isBrowserEdge() {
return !window.isIE && !!window.StyleMedia;
}
exports.isBrowserEdge = isBrowserEdge;
//# sourceMappingURL=isBrowserEdge.js.map
export * from "./isBrowserFirefox";

@@ -1,1 +0,10 @@

export * from "./isBrowserFirefox";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var isBrowserFirefox = require('./isBrowserFirefox.js');
exports.isBrowserFirefox = isBrowserFirefox.isBrowserFirefox;
//# sourceMappingURL=index.js.map

@@ -1,2 +0,14 @@

function n(){return!!window.InstallTrigger}export{n as isBrowserFirefox};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Check if the current browser is Firefox
* @returns {boolean} True if Firefox
*/
function isBrowserFirefox() {
return !!window.InstallTrigger;
}
exports.isBrowserFirefox = isBrowserFirefox;
//# sourceMappingURL=isBrowserFirefox.js.map
export * from "./isBrowserIE";

@@ -1,1 +0,10 @@

export * from "./isBrowserIE";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var isBrowserIE = require('./isBrowserIE.js');
exports.isBrowserIE = isBrowserIE.isBrowserIE;
//# sourceMappingURL=index.js.map

@@ -0,0 +0,0 @@ /**

@@ -1,3 +0,14 @@

function e(){/*@cc_on!@*/
return!!document.documentMode}export{e as isBrowserIE};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Check if the current browser is IE
* @returns {boolean} True if IE
*/
function isBrowserIE() {
return /*@cc_on!@*/ !!document.documentMode;
}
exports.isBrowserIE = isBrowserIE;
//# sourceMappingURL=isBrowserIE.js.map
export * from "./isBrowserOpera";

@@ -1,1 +0,10 @@

export * from "./isBrowserOpera";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var isBrowserOpera = require('./isBrowserOpera.js');
exports.isBrowserOpera = isBrowserOpera.isBrowserOpera;
//# sourceMappingURL=index.js.map

@@ -1,2 +0,14 @@

function n(){return!!window.opr&&!!window.opr.addons||!!window.opera||navigator.userAgent.indexOf(" OPR/")>=0}export{n as isBrowserOpera};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Check if the current browser is Opera
* @returns {boolean} True if Opera
*/
function isBrowserOpera() {
return (!!window.opr && !!window.opr.addons) || !!window.opera || navigator.userAgent.indexOf(" OPR/") >= 0;
}
exports.isBrowserOpera = isBrowserOpera;
//# sourceMappingURL=isBrowserOpera.js.map
export * from "./isBrowserSafari";

@@ -1,1 +0,10 @@

export * from "./isBrowserSafari";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var isBrowserSafari = require('./isBrowserSafari.js');
exports.isBrowserSafari = isBrowserSafari.isBrowserSafari;
//# sourceMappingURL=index.js.map

@@ -1,2 +0,15 @@

function i(){return/constructor/i.test(window.HTMLElement)||"[object SafariRemoteNotification]"===(!window.safari||void 0!==window.safari&&window.safari.pushNotification).toString()}export{i as isBrowserSafari};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Check if the current browser is Safari
* @returns {boolean} True if Safari
*/
function isBrowserSafari() {
return /constructor/i.test(window.HTMLElement) ||
((p) => p.toString() === "[object SafariRemoteNotification]")(!window["safari"] || (typeof window.safari !== "undefined" && window.safari.pushNotification));
}
exports.isBrowserSafari = isBrowserSafari;
//# sourceMappingURL=isBrowserSafari.js.map
export * from "./isDateAfter";

@@ -1,1 +0,10 @@

export * from "./isDateAfter";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var isDateAfter = require('./isDateAfter.js');
exports.isDateAfter = isDateAfter.isDateAfter;
//# sourceMappingURL=index.js.map

@@ -0,0 +0,0 @@ /**

@@ -1,2 +0,23 @@

import{isValidDate as t}from"../isValidDate/isValidDate.js";function e(e,a){return t(e)&&t(a)?e.getFullYear()>a.getFullYear()||e.getMonth()>a.getMonth()||e.getDate()>a.getDate():e>a}export{e as isDateAfter};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var isValidDate = require('../isValidDate/isValidDate.js');
/**
* Compare two dates and return true if the first is greater than the second ignoring the time
* @param {Date} a The first date
* @param {Date} b The second date
* @returns {boolean} True if date `a` comes after than date `b`
*/
function isDateAfter(a, b) {
if (!isValidDate.isValidDate(a) || !isValidDate.isValidDate(b)) {
return a > b;
}
else {
return a.getFullYear() > b.getFullYear() || a.getMonth() > b.getMonth() || a.getDate() > b.getDate();
}
}
exports.isDateAfter = isDateAfter;
//# sourceMappingURL=isDateAfter.js.map
export * from "./isDateBefore";

@@ -1,1 +0,10 @@

export * from "./isDateBefore";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var isDateBefore = require('./isDateBefore.js');
exports.isDateBefore = isDateBefore.isDateBefore;
//# sourceMappingURL=index.js.map

@@ -0,0 +0,0 @@ /**

@@ -1,2 +0,23 @@

import{isValidDate as t}from"../isValidDate/isValidDate.js";function e(e,a){return t(e)&&t(a)?e.getFullYear()<a.getFullYear()||e.getMonth()<a.getMonth()||e.getDate()<a.getDate():e<a}export{e as isDateBefore};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var isValidDate = require('../isValidDate/isValidDate.js');
/**
* Compare two dates and return true if the first is less (or before) than the second ignoring the time
* @param {Date} a The first date
* @param {Date} b The second date
* @returns {boolean} True if date `a` comes before date `b`
*/
function isDateBefore(a, b) {
if (!isValidDate.isValidDate(a) || !isValidDate.isValidDate(b)) {
return a < b;
}
else {
return a.getFullYear() < b.getFullYear() || a.getMonth() < b.getMonth() || a.getDate() < b.getDate();
}
}
exports.isDateBefore = isDateBefore;
//# sourceMappingURL=isDateBefore.js.map
export * from "./isEmail";

@@ -1,1 +0,10 @@

export * from "./isEmail";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var isEmail = require('./isEmail.js');
exports.isEmail = isEmail.isEmail;
//# sourceMappingURL=index.js.map

@@ -0,0 +0,0 @@ /**

@@ -1,2 +0,15 @@

function e(e){return new RegExp(/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/).test(e)}export{e as isEmail};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Check if an email is valid
* @param {string} value email
* @returns {boolean} true if email is valid, false if email is not valid
*/
function isEmail(value) {
return new RegExp(/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/).test(value);
}
exports.isEmail = isEmail;
//# sourceMappingURL=isEmail.js.map
export * from "./isEmpty";

@@ -1,1 +0,10 @@

export * from "./isEmpty";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var isEmpty = require('./isEmpty.js');
exports.isEmpty = isEmpty.isEmpty;
//# sourceMappingURL=index.js.map

@@ -0,0 +0,0 @@ /**

@@ -1,2 +0,32 @@

function n(n){return null==n||!(n instanceof Date)&&(!(n instanceof Function)&&(n instanceof Object&&!(n instanceof Array)?Object.keys(n).length<1:n.length<1))}export{n as isEmpty};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Check if a string is empty
* @param {any} value String variable to be checked
* @returns {boolean} True if empty
*/
function isEmpty(value) {
if (value === undefined || value === null) { // undefined or null
return true;
}
else if (value instanceof Date) { // Date object behave different from normal objects
return false;
}
else if ((value instanceof Function)) {
return false;
}
else if ((value instanceof Object) && !(value instanceof Array)) { // Object, not an array
return Object.keys(value).length < 1;
}
else if (value.length < 1) { // Array or string
return true;
}
else {
return false;
}
}
exports.isEmpty = isEmpty;
//# sourceMappingURL=isEmpty.js.map
export * from "./isPhoneNumber";

@@ -1,1 +0,10 @@

export * from "./isPhoneNumber";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var isPhoneNumber = require('./isPhoneNumber.js');
exports.isPhoneNumber = isPhoneNumber.isPhoneNumber;
//# sourceMappingURL=index.js.map

@@ -1,2 +0,15 @@

function t(t){return new RegExp(/^[0-9]{4,15}$/g).test(String(t))}export{t as isPhoneNumber};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Verifies if a string is a valid phone number
* @param {string | number} value Value to be verified
* @returns {boolean} true if it is valid
*/
function isPhoneNumber(value) {
return new RegExp(/^[0-9]{4,15}$/g).test(String(value));
}
exports.isPhoneNumber = isPhoneNumber;
//# sourceMappingURL=isPhoneNumber.js.map
export * from "./isPrimitive";

@@ -1,1 +0,10 @@

export * from "./isPrimitive";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var isPrimitive = require('./isPrimitive.js');
exports.isPrimitive = isPrimitive.isPrimitive;
//# sourceMappingURL=index.js.map

@@ -0,0 +0,0 @@ /**

@@ -1,2 +0,15 @@

function t(t){return t!==Object(t)}export{t as isPrimitive};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Verifies if a value is primitive (string, number, boolean)
* @param {any} value The value to be tested
* @returns {boolean} True if it's primitive, false otherwise
*/
function isPrimitive(value) {
return (value !== Object(value));
}
exports.isPrimitive = isPrimitive;
//# sourceMappingURL=isPrimitive.js.map
export * from "./isSameDate";

@@ -1,1 +0,10 @@

export * from "./isSameDate";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var isSameDate = require('./isSameDate.js');
exports.isSameDate = isSameDate.isSameDate;
//# sourceMappingURL=index.js.map

@@ -0,0 +0,0 @@ /**

@@ -1,2 +0,23 @@

import{isValidDate as t}from"../isValidDate/isValidDate.js";function a(a,e){return!(!t(a)||!t(e))&&a.toLocaleDateString()===e.toLocaleDateString()}export{a as isSameDate};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var isValidDate = require('../isValidDate/isValidDate.js');
/**
* Compare two dates and return true they are the same date ignoring the time
* @param {Date} a The first date,
* @param {Date} b The second date
* @returns {boolean} True if date are the same
*/
function isSameDate(a, b) {
if (!isValidDate.isValidDate(a) || !isValidDate.isValidDate(b)) {
return false;
}
else {
return a.toLocaleDateString() === b.toLocaleDateString();
}
}
exports.isSameDate = isSameDate;
//# sourceMappingURL=isSameDate.js.map
export * from "./isSameObject";

@@ -1,1 +0,10 @@

export * from "./isSameObject";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var isSameObject = require('./isSameObject.js');
exports.isSameObject = isSameObject.isSameObject;
//# sourceMappingURL=index.js.map

@@ -0,0 +0,0 @@ /**

@@ -1,2 +0,33 @@

function t(t,e,n){if(n){const n=Object.keys(t),r=Object.keys(e);if(n.length===r.length){for(let i=0;i<n.length;i++)if(t[n[i]]!==e[r[i]])return!1;return!0}return!1}return JSON.stringify(t)===JSON.stringify(e)}export{t as isSameObject};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Compare if two objects are the same, returns true or false
* @param type the comparison type
* @param objectA the first object
* @param objectB the second object to compare against
*/
function isSameObject(objectA, objectB, deep) {
if (deep) {
const objAKeys = Object.keys(objectA);
const objBKeys = Object.keys(objectB);
// first step, compare if the two keys length match
if (objAKeys.length === objBKeys.length) {
// step two, compare each value by key
for (let i = 0; i < objAKeys.length; i++) {
if (objectA[objAKeys[i]] !== objectB[objBKeys[i]]) {
return false;
}
}
return true;
}
return false;
}
else {
return JSON.stringify(objectA) === JSON.stringify(objectB);
}
}
exports.isSameObject = isSameObject;
//# sourceMappingURL=isSameObject.js.map
export * from "./isStrongPassword";

@@ -1,1 +0,10 @@

export * from "./isStrongPassword";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var isStrongPassword = require('./isStrongPassword.js');
exports.isStrongPassword = isStrongPassword.isStrongPassword;
//# sourceMappingURL=index.js.map

@@ -1,2 +0,20 @@

function t(t){return/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-_]).{8,}$/.test(t)}export{t as isStrongPassword};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Verifies a password strength
* @param {string} newPassword The new password needed to be verified
* @returns {boolean} True if the password is strong
* @rules :
* - Must be at least 8 characters long.
* - Must include at least one uppercase character.
* - Must include at least one lowercase character.
* - Must include at least one number.
*/
function isStrongPassword(newPassword) {
return /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-_]).{8,}$/.test(newPassword);
}
exports.isStrongPassword = isStrongPassword;
//# sourceMappingURL=isStrongPassword.js.map
export * from "./isValidDate";

@@ -1,1 +0,10 @@

export * from "./isValidDate";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var isValidDate = require('./isValidDate.js');
exports.isValidDate = isValidDate.isValidDate;
//# sourceMappingURL=index.js.map

@@ -0,0 +0,0 @@ /**

@@ -1,2 +0,15 @@

function e(e){return!(!(e&&e instanceof Date)||isNaN(e.getTime()))}export{e as isValidDate};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Is valid date: Checks if the datye is valid
* @returns {boolean} true if the date is a valid date and false if not
* @param date
*/
function isValidDate(date) {
return !!(date && date instanceof Date && !isNaN(date.getTime()));
}
exports.isValidDate = isValidDate;
//# sourceMappingURL=isValidDate.js.map
export * from "./modifyDate";

@@ -1,1 +0,10 @@

export * from "./modifyDate";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var modifyDate = require('./modifyDate.js');
exports.modifyDate = modifyDate.modifyDate;
//# sourceMappingURL=index.js.map

@@ -0,0 +0,0 @@ /** The current supported ranges of modifying a date */

@@ -1,2 +0,51 @@

function e(e,t,a,n){if(!e)return new Date;if(e instanceof Date){const r=new Date(e);let s=n;"day"===n?s="date":"year"===n&&(s="fullYear"),s=s.charAt(0).toUpperCase()+s.substr(1,s.length-1);const o="get"+s,l=e[o]?e[o]():null;let c;switch(null===l&&console.warn(`Date getAccessor "${o}" from range ${n} does not seem to exist. Provide a valid range as: "month" | "day" | "year" | "hours" | "seconds"`),a){case"ADD":c=l+t;break;case"SUBTRACT":c=l-t;break;default:return console.warn("value should be 'ADD' or 'SUBTRACT'"),new Date}const u="set"+s;return r[u]&&r[u](c),r}return new Date}export{e as modifyDate};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Modifies a date by either adding or substracting a certain range
* @param {Date} from {date} the starting date
* @param {number} value {number} the value (amount) you want added or substracted
* @param {"ADD" | "SUBTRACT"} type {ADD | SUBSTRACT} the operation type
* @param {"month" | "day" | "year" | "hours" | "seconds"} range the name of the range to modify, example: "month"
*/
function modifyDate(from, value, type, range) {
if (!from) {
return new Date();
}
else if (from instanceof Date) {
const newDate = new Date(from);
let rangeName = range;
if (range === "day") {
rangeName = "date";
}
else if (range === "year") {
rangeName = "fullYear";
}
rangeName = rangeName.charAt(0).toUpperCase() + rangeName.substr(1, rangeName.length - 1);
const getAccessor = `get${rangeName}`;
const currentValue = from[getAccessor] ? from[getAccessor]() : null;
if (currentValue === null) {
console.warn(`Date getAccessor \"${getAccessor}\" from range ${range} does not seem to exist. Provide a valid range as: \"month\" | \"day\" | \"year\" | \"hours\" | \"seconds\"`);
}
let newValue;
switch (type) {
case "ADD":
newValue = currentValue + value;
break;
case "SUBTRACT":
newValue = currentValue - value;
break;
default:
console.warn("value should be 'ADD' or 'SUBTRACT'");
return new Date();
}
const setAccessor = `set${rangeName}`;
newDate[setAccessor] && newDate[setAccessor](newValue);
return newDate;
}
return new Date();
}
exports.modifyDate = modifyDate;
//# sourceMappingURL=modifyDate.js.map

9

package.json
{
"name": "@sebgroup/frontend-tools",
"version": "2.1.0",
"description": "A set of frontend tools",
"author": "sebgroup",
"version": "2.0.2",
"main": "index.js",
"description": "A set of frontend tools",
"publishConfig": {
"registry": "https://registry.npmjs.org/",
"access": "public"
},
"repository": {

@@ -18,3 +14,2 @@ "type": "git",

},
"homepage": "https://github.com/sebgroup/frontend-tools",
"keywords": [

@@ -21,0 +16,0 @@ "frontend",

export * from "./randomId";

@@ -1,1 +0,10 @@

export * from "./randomId";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var randomId = require('./randomId.js');
exports.randomId = randomId.randomId;
//# sourceMappingURL=index.js.map

@@ -0,0 +0,0 @@ /**

@@ -1,2 +0,15 @@

function e(e){return e+String(1e3*Math.random()+(new Date).getTime())}export{e as randomId};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Generates a random unique ID
* @param {string} seed A seed to be inserted to the random ID to ensure further uniqueness
* @returns {string} The generated random ID
*/
function randomId(seed) {
return seed + String((Math.random() * 1000) + (new Date()).getTime());
}
exports.randomId = randomId;
//# sourceMappingURL=randomId.js.map
export * from "./StorageManagement";

@@ -1,1 +0,10 @@

export * from "./StorageManagement";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var StorageManagement = require('./StorageManagement.js');
exports.StorageManagement = StorageManagement.StorageManagement;
//# sourceMappingURL=index.js.map

@@ -0,0 +0,0 @@ export declare type StorageManagementType = "LOCAL" | "SESSION" | "COOKIE";

@@ -1,2 +0,57 @@

import{CookieStorage as e}from"../CookieStorage/CookieStorage.js";class t{constructor(t="LOCAL"){switch(t){case"LOCAL":this.handler=localStorage;break;case"SESSION":this.handler=sessionStorage;break;case"COOKIE":this.handler=new e;break;default:this.handler=localStorage}}get length(){return this.keys().length}setItem(e,t){this.handler.setItem(e,t)}getItem(e){return this.handler.getItem(e)}removeItem(e){return!!this.handler.getItem(e)&&(this.handler.removeItem(e),!0)}clear(){this.handler.clear()}keys(){return this.handler.keys?this.handler.keys():Object.keys(this.handler)}key(e){return this.keys()[e]}}export{t as StorageManagement};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var CookieStorage = require('../CookieStorage/CookieStorage.js');
class StorageManagement {
constructor(type = "LOCAL") {
switch (type) {
case "LOCAL":
this.handler = localStorage;
break;
case "SESSION":
this.handler = sessionStorage;
break;
case "COOKIE":
this.handler = new CookieStorage.CookieStorage();
break;
default: this.handler = localStorage;
}
}
get length() { return this.keys().length; }
setItem(key, value) {
this.handler.setItem(key, value);
}
getItem(key) {
return this.handler.getItem(key);
}
removeItem(key) {
if (this.handler.getItem(key)) {
this.handler.removeItem(key);
return true;
}
return false;
}
clear() {
this.handler.clear();
}
/**
* Retrieves the list of keys in the stored storage
* @returns The list of keys in the stored storage
*/
keys() {
if (this.handler.keys) {
return this.handler.keys();
}
else {
return Object.keys(this.handler);
}
}
key(index) {
return this.keys()[index];
}
}
exports.StorageManagement = StorageManagement;
//# sourceMappingURL=StorageManagement.js.map
export * from "./stringInsert";

@@ -1,1 +0,10 @@

export * from "./stringInsert";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var stringInsert = require('./stringInsert.js');
exports.stringInsert = stringInsert.stringInsert;
//# sourceMappingURL=index.js.map

@@ -0,0 +0,0 @@ /**

@@ -1,2 +0,23 @@

function r(r,n,e="@"){if(r&&"string"==typeof r)for(const i in n)r=r.replace(new RegExp(`${Array.isArray(e)?e[0]||"@":e}${i}${Array.isArray(e)?e[1]||"@":e}`,"g"),String(n[i]));return r}export{r as stringInsert};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Inserts values in a string
* This is mostly used to insert values in a translation message
* @param {string} str The string that contains the variables
* @param {object} params The params to insert in the string message
* @param {string} symbol The symbol to look for to insert the params in the string message. Default is `@` symbol. You can also pass an array of an openning and closing like this `["{{", "}}"]`
* @returns The replaced string
*/
function stringInsert(str, params, symbol = "@") {
if (str && typeof str === "string") {
for (const key in params) {
str = str.replace(new RegExp(`${Array.isArray(symbol) ? symbol[0] || "@" : symbol}${key}${Array.isArray(symbol) ? symbol[1] || "@" : symbol}`, "g"), String(params[key]));
}
}
return str;
}
exports.stringInsert = stringInsert;
//# sourceMappingURL=stringInsert.js.map
export * from "./toCurrency";

@@ -1,1 +0,10 @@

export * from "./toCurrency";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var toCurrency = require('./toCurrency.js');
exports.toCurrency = toCurrency.toCurrency;
//# sourceMappingURL=index.js.map

@@ -0,0 +0,0 @@ export interface ToCurrencyOptions {

@@ -1,2 +0,51 @@

function o(o,l={}){let e="0";const t=o=>{let t,r;o-Math.floor(o)==0?t=o:(t=Math.floor(o),!1!==(null==l?void 0:l.showDecimals)&&(r=Number((o-Math.floor(o)).toFixed((null==l?void 0:l.numOfDecimals)||2).replace("0.",""))));const n=String(t).split(""),u=[];return n.map((o,e)=>{(n.length-(e+1)||1)%3==0?(u.push(o),u.push((null==l?void 0:l.separator)||",")):u.push(o)}),e=u.join(""),e+(r?`${(null==l?void 0:l.decimalSymbol)||"."}${r}`:"")};return"number"==typeof o?t(o):"string"!=typeof o||isNaN(Number(o))?"":t(Number(o))}export{o as toCurrency};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Formats a number or a string number to a currency format
* @param {number} value raw number value
* @param {ToCurrencyOptions} options You can control the sperator, radix, decimals visibility and number of decimal places using these options
* @returns {string} The formatted currency string
*/
function toCurrency(value, options = {}) {
let amount = "0";
const format = (val) => {
let num;
let cents;
if (val - Math.floor(val) === 0) {
num = val;
}
else {
num = Math.floor(val);
if ((options === null || options === void 0 ? void 0 : options.showDecimals) !== false) {
cents = Number((val - Math.floor(val)).toFixed((options === null || options === void 0 ? void 0 : options.numOfDecimals) || 2).replace("0.", ""));
}
}
const list = String(num).split("");
const newList = [];
list.map((item, index) => {
if (((list.length - (index + 1)) || 1) % 3 === 0) {
newList.push(item);
newList.push((options === null || options === void 0 ? void 0 : options.separator) || ",");
}
else {
newList.push(item);
}
});
amount = newList.join("");
return amount + (cents ? `${(options === null || options === void 0 ? void 0 : options.decimalSymbol) || "."}${cents}` : "");
};
if (typeof value === "number") {
return format(value);
}
else if (typeof value === "string" && !isNaN(Number(value))) {
return format(Number(value));
}
else {
return "";
}
}
exports.toCurrency = toCurrency;
//# sourceMappingURL=toCurrency.js.map
export * from "./toDate";

@@ -1,1 +0,10 @@

export * from "./toDate";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var toDate = require('./toDate.js');
exports.toDate = toDate.toDate;
//# sourceMappingURL=index.js.map

@@ -0,0 +0,0 @@ export declare type DateComponents = [number, number, number?, number?, number?, number?, number?];

@@ -1,2 +0,38 @@

import{isValidDate as e}from"../isValidDate/isValidDate.js";function t(t,n){switch(n&&console.warn("The inputFormat has been depracated. The default javascript Date object string constructor will be used instead"),!0){case!t:return null;case t instanceof Date:return e(t)?t:null;case"string"==typeof t:case"number"==typeof t:{const n=new Date(t);return e(n)?n:null}case"object"==typeof t&&Array.isArray(t)&&t.length>1:{const n=new Date(...t);return e(n)?n:null}default:return null}}export{t as toDate};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var isValidDate = require('../isValidDate/isValidDate.js');
/**
* Retrives a date object based on various inputs
* @param value The date value to use to retrive the date
* @returns The date object
*/
function toDate(value,
/** DEPRACATED! The input format has been depracated. The default javascript Date object string constructor will be used instead */
inputFormat) {
if (inputFormat) {
console.warn("The inputFormat has been depracated. The default javascript Date object string constructor will be used instead");
}
switch (true) {
case !value: return null;
case value instanceof Date:
{
return isValidDate.isValidDate(value) ? value : null;
}
case typeof value === "string":
case typeof value === "number": {
const newDate = new Date(value);
return isValidDate.isValidDate(newDate) ? newDate : null;
}
case typeof value === "object" && Array.isArray(value) && value.length > 1: {
const newDate = new Date(...value);
return isValidDate.isValidDate(newDate) ? newDate : null;
}
default: return null;
}
}
exports.toDate = toDate;
//# sourceMappingURL=toDate.js.map
export * from "./toggleBodyOverflow";

@@ -1,1 +0,10 @@

export * from "./toggleBodyOverflow";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var toggleBodyOverflow = require('./toggleBodyOverflow.js');
exports.toggleBodyOverflow = toggleBodyOverflow.toggleBodyOverflow;
//# sourceMappingURL=index.js.map

@@ -1,2 +0,29 @@

function s(s){const e="overflow-hidden",o=document.getElementsByTagName("body").item(0);void 0!==s?s&&!o.classList.contains(e)?o.classList.add(e):!s&&o.classList.contains(e)&&o.classList.remove(e):console.warn("updateHTMLBodyWhenModalToggles called with invalid toggle")}export{s as toggleBodyOverflow};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Inserts a class into the body tag to disable overflow to avoid background scrolling
* @example This can be used with a modal component
* @param {boolean} toggle The value of the modal toggle
* @note It inserts the class `overflow-hidden` which is a **bootstrap** class.
* If you are not using bootstrap, please make sure that the class is defined with `overflow: hidden;`
*/
function toggleBodyOverflow(toggle) {
const className = "overflow-hidden";
const body = document.getElementsByTagName("body").item(0);
if (toggle !== undefined) {
if (toggle && !body.classList.contains(className)) {
body.classList.add(className);
}
else if (!toggle && body.classList.contains(className)) {
body.classList.remove(className);
}
}
else {
console.warn("updateHTMLBodyWhenModalToggles called with invalid toggle");
}
}
exports.toggleBodyOverflow = toggleBodyOverflow;
//# sourceMappingURL=toggleBodyOverflow.js.map
export * from "./toLocalDateString";

@@ -1,1 +0,10 @@

export * from "./toLocalDateString";
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var toLocalDateString = require('./toLocalDateString.js');
exports.toLocalDateString = toLocalDateString.toLocalDateString;
//# sourceMappingURL=index.js.map

@@ -1,2 +0,22 @@

function t(t,n){return t&&t instanceof Date&&t.toLocaleDateString?t.toLocaleDateString(n,{year:"numeric",month:"long",day:"numeric"}):String(t)}export{t as toLocalDateString};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Convert date object to local String
* @param {Date} date The date object
* @param {Array<string>} locales Optional array of locales (country codes) to use.
* Locale will fallback to default system language if none provided.
* @returns return new date string in the format `June 13, 2019` (for english locale)
*/
function toLocalDateString(date, locales) {
if (date && date instanceof Date && !!date.toLocaleDateString) {
return date.toLocaleDateString(locales, { year: "numeric", month: "long", day: "numeric" });
}
else {
return String(date);
}
}
exports.toLocalDateString = toLocalDateString;
//# sourceMappingURL=toLocalDateString.js.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc