validate-promise
Advanced tools
Comparing version 3.2.0 to 3.2.1
@@ -1,1 +0,1 @@ | ||
{"processes":{"6d625202-bd41-4345-8cb8-6420c21aae70":{"parent":null,"children":["d16f9a0f-781d-405f-bace-21ad8807acd9"]},"b2cdfe6a-d902-4fdf-b04a-616bec4b024c":{"parent":null,"children":[]},"d16f9a0f-781d-405f-bace-21ad8807acd9":{"parent":"6d625202-bd41-4345-8cb8-6420c21aae70","children":[]}},"files":{"/home/rob/validate-promise/src/index.ts":["b2cdfe6a-d902-4fdf-b04a-616bec4b024c","d16f9a0f-781d-405f-bace-21ad8807acd9"],"/home/rob/validate-promise/src/rules/after.ts":["b2cdfe6a-d902-4fdf-b04a-616bec4b024c","d16f9a0f-781d-405f-bace-21ad8807acd9"],"/home/rob/validate-promise/src/rules/atleastOneRequired.ts":["b2cdfe6a-d902-4fdf-b04a-616bec4b024c","d16f9a0f-781d-405f-bace-21ad8807acd9"],"/home/rob/validate-promise/src/rules/before.ts":["b2cdfe6a-d902-4fdf-b04a-616bec4b024c","d16f9a0f-781d-405f-bace-21ad8807acd9"],"/home/rob/validate-promise/src/rules/blacklist.ts":["b2cdfe6a-d902-4fdf-b04a-616bec4b024c","d16f9a0f-781d-405f-bace-21ad8807acd9"],"/home/rob/validate-promise/src/rules/email.ts":["b2cdfe6a-d902-4fdf-b04a-616bec4b024c","d16f9a0f-781d-405f-bace-21ad8807acd9"],"/home/rob/validate-promise/src/rules/equals.ts":["b2cdfe6a-d902-4fdf-b04a-616bec4b024c","d16f9a0f-781d-405f-bace-21ad8807acd9"],"/home/rob/validate-promise/src/rules/equalto.ts":["b2cdfe6a-d902-4fdf-b04a-616bec4b024c","d16f9a0f-781d-405f-bace-21ad8807acd9"],"/home/rob/validate-promise/src/rules/float.ts":["b2cdfe6a-d902-4fdf-b04a-616bec4b024c","d16f9a0f-781d-405f-bace-21ad8807acd9"],"/home/rob/validate-promise/src/rules/greaterthan.ts":["b2cdfe6a-d902-4fdf-b04a-616bec4b024c","d16f9a0f-781d-405f-bace-21ad8807acd9"],"/home/rob/validate-promise/src/rules/int.ts":["b2cdfe6a-d902-4fdf-b04a-616bec4b024c","d16f9a0f-781d-405f-bace-21ad8807acd9"],"/home/rob/validate-promise/src/rules/isUploaded.ts":["b2cdfe6a-d902-4fdf-b04a-616bec4b024c","d16f9a0f-781d-405f-bace-21ad8807acd9"],"/home/rob/validate-promise/src/rules/lessthan.ts":["b2cdfe6a-d902-4fdf-b04a-616bec4b024c","d16f9a0f-781d-405f-bace-21ad8807acd9"],"/home/rob/validate-promise/src/rules/notEquals.ts":["b2cdfe6a-d902-4fdf-b04a-616bec4b024c","d16f9a0f-781d-405f-bace-21ad8807acd9"],"/home/rob/validate-promise/src/rules/regex.ts":["b2cdfe6a-d902-4fdf-b04a-616bec4b024c","d16f9a0f-781d-405f-bace-21ad8807acd9"],"/home/rob/validate-promise/src/rules/required.ts":["b2cdfe6a-d902-4fdf-b04a-616bec4b024c","d16f9a0f-781d-405f-bace-21ad8807acd9"],"/home/rob/validate-promise/src/rules/whitelist.ts":["b2cdfe6a-d902-4fdf-b04a-616bec4b024c","d16f9a0f-781d-405f-bace-21ad8807acd9"]},"externalIds":{}} | ||
{"processes":{"66fec98f-95a0-4113-844a-d835efba706e":{"parent":null,"children":["e4fadf61-84c3-4277-bff1-53ffa1eda86d"]},"7df7854f-4e8e-4cfe-bdbf-04ee72091f35":{"parent":null,"children":[]},"e4fadf61-84c3-4277-bff1-53ffa1eda86d":{"parent":"66fec98f-95a0-4113-844a-d835efba706e","children":[]}},"files":{"/home/rob/validate-promise/src/index.ts":["7df7854f-4e8e-4cfe-bdbf-04ee72091f35","e4fadf61-84c3-4277-bff1-53ffa1eda86d"],"/home/rob/validate-promise/src/rules/after.ts":["7df7854f-4e8e-4cfe-bdbf-04ee72091f35","e4fadf61-84c3-4277-bff1-53ffa1eda86d"],"/home/rob/validate-promise/src/rules/atleastOneRequired.ts":["7df7854f-4e8e-4cfe-bdbf-04ee72091f35","e4fadf61-84c3-4277-bff1-53ffa1eda86d"],"/home/rob/validate-promise/src/rules/before.ts":["7df7854f-4e8e-4cfe-bdbf-04ee72091f35","e4fadf61-84c3-4277-bff1-53ffa1eda86d"],"/home/rob/validate-promise/src/rules/blacklist.ts":["7df7854f-4e8e-4cfe-bdbf-04ee72091f35","e4fadf61-84c3-4277-bff1-53ffa1eda86d"],"/home/rob/validate-promise/src/rules/email.ts":["7df7854f-4e8e-4cfe-bdbf-04ee72091f35","e4fadf61-84c3-4277-bff1-53ffa1eda86d"],"/home/rob/validate-promise/src/rules/equals.ts":["7df7854f-4e8e-4cfe-bdbf-04ee72091f35","e4fadf61-84c3-4277-bff1-53ffa1eda86d"],"/home/rob/validate-promise/src/rules/equalto.ts":["7df7854f-4e8e-4cfe-bdbf-04ee72091f35","e4fadf61-84c3-4277-bff1-53ffa1eda86d"],"/home/rob/validate-promise/src/rules/float.ts":["7df7854f-4e8e-4cfe-bdbf-04ee72091f35","e4fadf61-84c3-4277-bff1-53ffa1eda86d"],"/home/rob/validate-promise/src/rules/greaterthan.ts":["7df7854f-4e8e-4cfe-bdbf-04ee72091f35","e4fadf61-84c3-4277-bff1-53ffa1eda86d"],"/home/rob/validate-promise/src/rules/int.ts":["7df7854f-4e8e-4cfe-bdbf-04ee72091f35","e4fadf61-84c3-4277-bff1-53ffa1eda86d"],"/home/rob/validate-promise/src/rules/isUploaded.ts":["7df7854f-4e8e-4cfe-bdbf-04ee72091f35","e4fadf61-84c3-4277-bff1-53ffa1eda86d"],"/home/rob/validate-promise/src/rules/lessthan.ts":["7df7854f-4e8e-4cfe-bdbf-04ee72091f35","e4fadf61-84c3-4277-bff1-53ffa1eda86d"],"/home/rob/validate-promise/src/rules/notEquals.ts":["7df7854f-4e8e-4cfe-bdbf-04ee72091f35","e4fadf61-84c3-4277-bff1-53ffa1eda86d"],"/home/rob/validate-promise/src/rules/regex.ts":["7df7854f-4e8e-4cfe-bdbf-04ee72091f35","e4fadf61-84c3-4277-bff1-53ffa1eda86d"],"/home/rob/validate-promise/src/rules/required.ts":["7df7854f-4e8e-4cfe-bdbf-04ee72091f35","e4fadf61-84c3-4277-bff1-53ffa1eda86d"],"/home/rob/validate-promise/src/rules/whitelist.ts":["7df7854f-4e8e-4cfe-bdbf-04ee72091f35","e4fadf61-84c3-4277-bff1-53ffa1eda86d"]},"externalIds":{}} |
@@ -17,3 +17,5 @@ import after from './rules/after'; | ||
export { default as isUploaded } from './rules/isUploaded'; | ||
export declare type ValidationPromise<T> = (value: string | string[] | Record<string, number>, row: T, msg: (value: string, row: T, arg?: any) => string, arg?: any) => Promise<string | void>; | ||
export declare type ArgFunc<T extends object, R> = (value: string, row: T) => R; | ||
export declare type MsgFunc<T extends object, A = any> = (value: string, row: T, arg?: A | ArgFunc<T, A>) => string; | ||
export declare type ValidationPromise<T extends object = object, A = any> = (value: string | string[] | Record<string, number>, row: T, msg: MsgFunc<T, A>, arg?: A | ArgFunc<T, A>) => Promise<string | void>; | ||
export interface Validation<T extends object = object> { | ||
@@ -31,4 +33,2 @@ promises: { | ||
export default validate; | ||
export declare type ArgFunc<T extends object, R> = (value: string, row: T) => R; | ||
export declare type MsgFunc<T extends object, A = any> = (value: string, row: T, arg?: A | ArgFunc<T, A>) => string; | ||
export { after, before, blacklist, email, equals, equalto, float, greaterthan, int, lessthan, notEquals, regex, required, whitelist, }; |
@@ -1,3 +0,3 @@ | ||
import { ArgFunc, MsgFunc } from '../'; | ||
declare const _default: <T extends object = object>(value: string, row: T, msg: MsgFunc<T, string>, arg: string | ArgFunc<T, string>) => Promise<string | void>; | ||
export default _default; | ||
import { ValidationPromise } from '../'; | ||
declare const after: ValidationPromise; | ||
export default after; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = (value, row, msg, arg) => { | ||
const after = (value, row, msg, arg) => { | ||
if (typeof value !== 'string') { | ||
return Promise.reject('Value must be a string'); | ||
} | ||
const test = Date.parse(value); | ||
@@ -14,1 +17,2 @@ if (typeof arg === 'function') { | ||
}; | ||
exports.default = after; |
@@ -1,3 +0,3 @@ | ||
import { MsgFunc } from '../'; | ||
declare const _default: <T extends object = object>(value: string[], row: T, msg: MsgFunc<T, any>) => Promise<string | void>; | ||
export default _default; | ||
import { ValidationPromise } from '../'; | ||
declare const atleastOneRequried: ValidationPromise; | ||
export default atleastOneRequried; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = (value, row, msg) => { | ||
const atleastOneRequried = (value, row, msg) => { | ||
return new Promise((resolve, reject) => { | ||
if (!Array.isArray(value)) { | ||
return reject('Value must be an array'); | ||
} | ||
const found = value.some((v) => v !== '' && v !== undefined); | ||
@@ -12,1 +15,2 @@ if (found) { | ||
}; | ||
exports.default = atleastOneRequried; |
@@ -1,3 +0,3 @@ | ||
import { ArgFunc, MsgFunc } from '../'; | ||
declare const _default: <T extends object = object>(value: string, row: T, msg: MsgFunc<T, string>, arg: string | ArgFunc<T, string>) => Promise<string | void>; | ||
export default _default; | ||
import { ValidationPromise } from '../'; | ||
declare const before: ValidationPromise; | ||
export default before; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = (value, row, msg, arg) => { | ||
const before = (value, row, msg, arg) => { | ||
if (typeof value !== 'string') { | ||
return Promise.reject('Value must be a string'); | ||
} | ||
const test = Date.parse(value); | ||
@@ -14,1 +17,2 @@ if (typeof arg === 'function') { | ||
}; | ||
exports.default = before; |
@@ -1,3 +0,3 @@ | ||
import { ArgFunc, MsgFunc } from '../'; | ||
declare const _default: <T extends object = object>(value: string, row: T, msg: MsgFunc<T, string[]>, arg: string[] | ArgFunc<T, string[]>) => Promise<string | void>; | ||
export default _default; | ||
import { ValidationPromise } from '../'; | ||
declare const blacklist: ValidationPromise; | ||
export default blacklist; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = (value, row, msg, arg) => { | ||
const blacklist = (value, row, msg, arg) => { | ||
if (typeof value !== 'string') { | ||
return Promise.reject('Value must be a string'); | ||
} | ||
if (typeof arg === 'function') { | ||
@@ -12,1 +15,2 @@ arg = arg(value, row); | ||
}; | ||
exports.default = blacklist; |
@@ -1,3 +0,3 @@ | ||
import { ArgFunc, MsgFunc } from '../'; | ||
declare const _default: <T extends object = object>(value: string, row: T, msg: MsgFunc<T, string>, arg: string | ArgFunc<T, string>) => Promise<string | void>; | ||
export default _default; | ||
import { ValidationPromise } from '../'; | ||
declare const email: ValidationPromise; | ||
export default email; |
@@ -7,3 +7,6 @@ "use strict"; | ||
const is_email_1 = __importDefault(require("is-email")); | ||
exports.default = (value, row, msg, arg) => { | ||
const email = (value, row, msg, arg) => { | ||
if (typeof value !== 'string') { | ||
return Promise.reject('Value must be a string'); | ||
} | ||
if (is_email_1.default(value)) { | ||
@@ -15,1 +18,2 @@ return Promise.resolve(); | ||
}; | ||
exports.default = email; |
@@ -1,3 +0,3 @@ | ||
import { ArgFunc, MsgFunc } from '../'; | ||
declare const _default: <T extends object = object>(value: string, row: T, msg: MsgFunc<T, any>, arg: string | ArgFunc<T, any>) => Promise<string | void>; | ||
export default _default; | ||
import { ValidationPromise } from '../'; | ||
declare const equals: ValidationPromise; | ||
export default equals; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = (value, row, msg, arg) => { | ||
const equals = (value, row, msg, arg) => { | ||
if (typeof value !== 'string') { | ||
return Promise.reject('Value must be a string'); | ||
} | ||
if (typeof arg === 'function') { | ||
@@ -12,1 +15,2 @@ arg = arg(value, row); | ||
}; | ||
exports.default = equals; |
@@ -1,3 +0,3 @@ | ||
import { ArgFunc, MsgFunc } from '../'; | ||
declare const _default: <T extends object = object>(value: string, row: T, msg: MsgFunc<T, string>, arg: string | ArgFunc<T, string>) => Promise<string | void>; | ||
export default _default; | ||
import { ValidationPromise } from '../'; | ||
declare const equalsTo: ValidationPromise; | ||
export default equalsTo; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = (value, row, msg, arg) => { | ||
const equalsTo = (value, row, msg, arg) => { | ||
if (typeof value !== 'string') { | ||
return Promise.reject('Value must be a string'); | ||
} | ||
if (typeof arg === 'function') { | ||
@@ -12,1 +15,2 @@ arg = arg(value, row); | ||
}; | ||
exports.default = equalsTo; |
@@ -1,2 +0,2 @@ | ||
import { ArgFunc, MsgFunc } from '../'; | ||
import { ValidationPromise } from '../'; | ||
declare type FloatBoundsType = { | ||
@@ -6,3 +6,3 @@ min?: number; | ||
}; | ||
declare const _default: <T extends object = object>(value: string, row: T, msg: MsgFunc<T, FloatBoundsType>, arg: FloatBoundsType | ArgFunc<T, FloatBoundsType>) => Promise<string | void>; | ||
export default _default; | ||
declare const float: ValidationPromise<object, FloatBoundsType>; | ||
export default float; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = (value, row, msg, arg) => { | ||
const float = (value, row, msg, arg) => { | ||
if (typeof value !== 'string') { | ||
return Promise.reject('Value must be a string'); | ||
} | ||
if (typeof arg === 'function') { | ||
@@ -8,3 +11,3 @@ arg = arg(value, row); | ||
const float = /^(?:[-+]?(?:[0-9]+))?(?:\.[0-9]*)?(?:[eE][\+\-]?(?:[0-9]+))?$/; | ||
if (arg !== null) { | ||
if (arg !== null && arg !== undefined) { | ||
if ((arg.min !== undefined && Number(value) < Number(arg.min))) { | ||
@@ -22,1 +25,2 @@ return Promise.reject(msg(value, row, arg)); | ||
}; | ||
exports.default = float; |
@@ -1,2 +0,2 @@ | ||
import { ArgFunc, MsgFunc } from '../'; | ||
import { ValidationPromise } from '../'; | ||
declare type CompareSet = { | ||
@@ -6,3 +6,3 @@ value: string; | ||
}; | ||
declare const _default: <T extends object = object>(value: string, row: T, msg: MsgFunc<T, number | CompareSet>, arg: number | CompareSet | ArgFunc<T, number | CompareSet>) => Promise<string | void>; | ||
export default _default; | ||
declare const greaterthan: ValidationPromise<object, CompareSet>; | ||
export default greaterthan; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = (value, row, msg, arg) => { | ||
const greaterthan = (value, row, msg, arg) => { | ||
if (typeof value === 'number') { | ||
value = String(value); | ||
} | ||
if (typeof value !== 'string') { | ||
return Promise.reject('Value must be a string or number'); | ||
} | ||
let compare = arg; | ||
@@ -17,1 +23,2 @@ if (typeof arg === 'function') { | ||
}; | ||
exports.default = greaterthan; |
@@ -1,2 +0,2 @@ | ||
import { ArgFunc, MsgFunc } from '../'; | ||
import { ValidationPromise } from '../'; | ||
declare type IntBoundsType = { | ||
@@ -6,3 +6,3 @@ min?: number; | ||
}; | ||
declare const _default: <T extends object = object>(value: string, row: T, msg: MsgFunc<T, IntBoundsType>, arg: IntBoundsType | ArgFunc<T, IntBoundsType>) => Promise<string | void>; | ||
export default _default; | ||
declare const int: ValidationPromise<object, IntBoundsType>; | ||
export default int; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = (value, row, msg, arg) => { | ||
const int = (value, row, msg, arg) => { | ||
if (typeof value === 'number') { | ||
value = String('number'); | ||
} | ||
if (typeof value !== 'string') { | ||
return Promise.reject('Value must be a number or a string'); | ||
} | ||
if (typeof arg === 'function') { | ||
@@ -8,3 +14,3 @@ arg = arg(value, row); | ||
const int = /^(?:[-+]?(?:0|[1-9][0-9]*))$/; | ||
if (arg !== null) { | ||
if (arg !== null && arg !== undefined) { | ||
if (arg.min !== undefined && Number(value) < Number(arg.min)) { | ||
@@ -22,1 +28,2 @@ return Promise.reject(msg(value, row, arg)); | ||
}; | ||
exports.default = int; |
@@ -1,3 +0,3 @@ | ||
import { ArgFunc, MsgFunc } from '../'; | ||
declare const _default: <T extends object = object>(value: Record<string, number>, row: T, msg: MsgFunc<T, any>, arg: ArgFunc<T, number | Record<string, number>>) => Promise<any>; | ||
export default _default; | ||
import { ValidationPromise } from '../'; | ||
declare const isUpladed: ValidationPromise<object, number | Record<string, number>>; | ||
export default isUpladed; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = (value, row, msg, arg) => { | ||
const isUpladed = (value, row, msg, arg) => { | ||
if (value === undefined) { | ||
@@ -15,1 +15,2 @@ return Promise.reject(msg(value, row, arg)); | ||
}; | ||
exports.default = isUpladed; |
@@ -1,2 +0,2 @@ | ||
import { ArgFunc, MsgFunc } from '../'; | ||
import { ValidationPromise } from '../'; | ||
declare type CompareSet = { | ||
@@ -6,3 +6,3 @@ value: string; | ||
}; | ||
declare const _default: <T extends object = object>(value: string, row: T, msg: MsgFunc<T, number | CompareSet>, arg: number | CompareSet | ArgFunc<T, number | CompareSet>) => Promise<string | void>; | ||
export default _default; | ||
declare const lessthan: ValidationPromise<object, CompareSet>; | ||
export default lessthan; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = (value, row, msg, arg) => { | ||
const lessthan = (value, row, msg, arg) => { | ||
let compare = arg; | ||
if (typeof value !== 'string') { | ||
return Promise.reject('Value must be a string'); | ||
} | ||
if (typeof arg === 'function') { | ||
@@ -17,1 +20,2 @@ compare = arg(value, row); | ||
}; | ||
exports.default = lessthan; |
@@ -1,3 +0,3 @@ | ||
import { MsgFunc } from '../'; | ||
declare const _default: <T extends object = object>(value: string, row: T, msg: MsgFunc<T, any>, arg: any) => Promise<string | void>; | ||
export default _default; | ||
import { ValidationPromise } from '../'; | ||
declare const notEquals: ValidationPromise; | ||
export default notEquals; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = (value, row, msg, arg) => { | ||
const notEquals = (value, row, msg, arg) => { | ||
if (typeof value !== 'string') { | ||
return Promise.reject('Value must be a string'); | ||
} | ||
if (typeof arg === 'function') { | ||
@@ -12,1 +15,2 @@ arg = arg(value, row); | ||
}; | ||
exports.default = notEquals; |
@@ -1,3 +0,3 @@ | ||
import { ArgFunc, MsgFunc } from '../'; | ||
declare const _default: <T extends object = object>(value: string, row: T, msg: MsgFunc<T, string>, arg: string | ArgFunc<T, string>) => Promise<string | void>; | ||
export default _default; | ||
import { ValidationPromise } from '../'; | ||
declare const regex: ValidationPromise; | ||
export default regex; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = (value, row, msg, arg) => { | ||
const regex = (value, row, msg, arg) => { | ||
if (typeof value !== 'string') { | ||
return Promise.reject('Value must be a string'); | ||
} | ||
const test = typeof arg === 'function' ? arg(value, row) : arg; | ||
@@ -11,1 +14,2 @@ const regex = new RegExp(test, 'g'); | ||
}; | ||
exports.default = regex; |
@@ -1,3 +0,3 @@ | ||
import { MsgFunc } from '../'; | ||
declare const _default: <T extends object = object>(value: string, row: T, msg: MsgFunc<T, any>) => Promise<string | void>; | ||
export default _default; | ||
import { ValidationPromise } from '../'; | ||
declare const required: ValidationPromise; | ||
export default required; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = (value, row, msg) => { | ||
const required = (value, row, msg) => { | ||
return new Promise((resolve, reject) => { | ||
@@ -11,1 +11,2 @@ if (value !== '' && value !== undefined) { | ||
}; | ||
exports.default = required; |
@@ -1,3 +0,3 @@ | ||
import { ArgFunc, MsgFunc } from '../'; | ||
declare const _default: <T extends object = object>(value: string, row: T, msg: MsgFunc<T, string[]>, arg: string[] | ArgFunc<T, string[]>) => Promise<string | void>; | ||
export default _default; | ||
import { ValidationPromise } from '../'; | ||
declare const whitelist: ValidationPromise; | ||
export default whitelist; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = (value, row, msg, arg) => { | ||
const whitelist = (value, row, msg, arg) => { | ||
if (typeof value !== 'string') { | ||
return Promise.reject('Value must be a string'); | ||
} | ||
if (typeof arg === 'function') { | ||
@@ -12,1 +15,2 @@ arg = arg(value, row); | ||
}; | ||
exports.default = whitelist; |
{ | ||
"name": "validate-promise", | ||
"version": "3.2.0", | ||
"version": "3.2.1", | ||
"description": "Promised based validation library", | ||
@@ -59,2 +59,2 @@ "main": "dist/index.js", | ||
} | ||
} | ||
} |
@@ -22,7 +22,19 @@ import get from 'lodash.get'; | ||
export type ValidationPromise<T> = ( | ||
/** | ||
* @template T Interface for the validation row | ||
* @template R Return type for the validation argument | ||
*/ | ||
export type ArgFunc<T extends object, R> = (value: string, row: T) => R; | ||
/** | ||
* @template T Interface for the validation row | ||
* @template A Argument type for validation rule | ||
*/ | ||
export type MsgFunc<T extends object, A = any> = (value: string, row: T, arg?: A | ArgFunc<T, A>) => string; | ||
export type ValidationPromise<T extends object = object, A = any> = ( | ||
value: string | string[] | Record<string, number>, | ||
row: T, | ||
msg: (value: string, row: T, arg?: any) => string, | ||
arg?: any, | ||
msg: MsgFunc<T, A>, | ||
arg?: A | ArgFunc<T, A>, | ||
) => Promise<string | void>; | ||
@@ -41,2 +53,8 @@ | ||
interface ValidationRule { | ||
propPath: string[]; | ||
rule: Promise<any>; | ||
} | ||
interface ValidationResponse { | ||
@@ -56,8 +74,2 @@ state: 'fulfilled' | 'rejected'; | ||
interface ValidationRule { | ||
propPath: string[]; | ||
rule: Promise<any>; | ||
} | ||
/** | ||
@@ -140,15 +152,2 @@ * Iterates over an array of promises, unline Promise.all it will not | ||
/** | ||
* @template T Interface for the validation row | ||
* @template R Return type for the validation argument | ||
*/ | ||
export type ArgFunc<T extends object, R> = (value: string, row: T) => R; | ||
/** | ||
* @template T Interface for the validation row | ||
* @template A Argument type for validation rule | ||
*/ | ||
export type MsgFunc<T extends object, A = any> = (value: string, row: T, arg?: A | ArgFunc<T, A>) => string; | ||
export { | ||
@@ -155,0 +154,0 @@ after, |
@@ -1,5 +0,2 @@ | ||
import { | ||
ArgFunc, | ||
MsgFunc, | ||
} from '../'; | ||
import { ValidationPromise } from '../'; | ||
@@ -9,8 +6,11 @@ /** | ||
*/ | ||
export default <T extends object = object>( | ||
value: string, | ||
row: T, | ||
msg: MsgFunc<T, string>, | ||
arg: string | ArgFunc<T, string> | ||
): Promise<string | void> => { | ||
const after: ValidationPromise = ( | ||
value, | ||
row, | ||
msg, | ||
arg, | ||
) => { | ||
if (typeof value !== 'string') { | ||
return Promise.reject('Value must be a string'); | ||
} | ||
const test: number = Date.parse(value); | ||
@@ -27,1 +27,3 @@ if (typeof arg === 'function') { | ||
}; | ||
export default after; |
@@ -1,2 +0,2 @@ | ||
import { MsgFunc } from '../'; | ||
import { ValidationPromise } from '../'; | ||
@@ -6,8 +6,11 @@ /** | ||
*/ | ||
export default <T extends object = object>( | ||
value: string[], | ||
row: T, | ||
msg: MsgFunc<T>, | ||
const atleastOneRequried: ValidationPromise = ( | ||
value, | ||
row, | ||
msg, | ||
): Promise<string | void> => { | ||
return new Promise((resolve, reject) => { | ||
if (!Array.isArray(value)) { | ||
return reject('Value must be an array'); | ||
} | ||
const found = value.some((v) => v !== '' && v !== undefined); | ||
@@ -21,1 +24,3 @@ if (found) { | ||
}; | ||
export default atleastOneRequried; |
@@ -1,5 +0,2 @@ | ||
import { | ||
ArgFunc, | ||
MsgFunc, | ||
} from '../'; | ||
import { ValidationPromise } from '../'; | ||
@@ -9,8 +6,11 @@ /** | ||
*/ | ||
export default <T extends object = object>( | ||
value: string, | ||
row: T, | ||
msg: MsgFunc<T, string>, | ||
arg: string | ArgFunc<T, string>, | ||
) : Promise<string | void> => { | ||
const before: ValidationPromise = ( | ||
value, | ||
row, | ||
msg, | ||
arg, | ||
) => { | ||
if (typeof value !== 'string') { | ||
return Promise.reject('Value must be a string'); | ||
} | ||
const test = Date.parse(value); | ||
@@ -27,1 +27,3 @@ if (typeof arg === 'function') { | ||
}; | ||
export default before; |
@@ -1,5 +0,2 @@ | ||
import { | ||
ArgFunc, | ||
MsgFunc, | ||
} from '../'; | ||
import { ValidationPromise } from '../'; | ||
@@ -9,8 +6,11 @@ /** | ||
*/ | ||
export default <T extends object = object>( | ||
value: string, | ||
row: T, | ||
msg: MsgFunc<T, string[]>, | ||
arg: string[] | ArgFunc<T, string[]> | ||
const blacklist: ValidationPromise = ( | ||
value, | ||
row, | ||
msg, | ||
arg, | ||
): Promise<string | void> => { | ||
if (typeof value !== 'string') { | ||
return Promise.reject('Value must be a string'); | ||
} | ||
if (typeof arg === 'function') { | ||
@@ -24,1 +24,3 @@ arg = arg(value, row); | ||
}; | ||
export default blacklist; |
import isEmail from 'is-email'; | ||
import { | ||
ArgFunc, | ||
MsgFunc, | ||
} from '../'; | ||
import { ValidationPromise } from '../'; | ||
/** | ||
* Check if a value is an email | ||
* @param {String} value To validate | ||
* @param {Object} row Form data | ||
* @param {Function} msg Error message function | ||
* @param {*} arg Validation arguement | ||
* @return {Promise} . | ||
*/ | ||
export default <T extends object = object>( | ||
value: string, | ||
row: T, | ||
msg: MsgFunc<T, string>, | ||
arg: string | ArgFunc<T, string>, | ||
) : Promise<string | void> => { | ||
const email: ValidationPromise = ( | ||
value, | ||
row, | ||
msg, | ||
arg, | ||
) => { | ||
if (typeof value !== 'string') { | ||
return Promise.reject('Value must be a string'); | ||
} | ||
if (isEmail(value)) { | ||
@@ -27,1 +22,3 @@ return Promise.resolve(); | ||
}; | ||
export default email; |
@@ -1,5 +0,2 @@ | ||
import { | ||
ArgFunc, | ||
MsgFunc, | ||
} from '../'; | ||
import { ValidationPromise } from '../'; | ||
@@ -9,8 +6,11 @@ /** | ||
*/ | ||
export default <T extends object = object>( | ||
value: string, | ||
row: T, | ||
msg: MsgFunc<T, any>, | ||
arg: string | ArgFunc<T, any> | ||
): Promise<string | void> => { | ||
const equals: ValidationPromise = ( | ||
value, | ||
row, | ||
msg, | ||
arg, | ||
) => { | ||
if (typeof value !== 'string') { | ||
return Promise.reject('Value must be a string'); | ||
} | ||
if (typeof arg === 'function') { | ||
@@ -25,1 +25,3 @@ arg = arg(value, row); | ||
}; | ||
export default equals; |
@@ -1,5 +0,2 @@ | ||
import { | ||
ArgFunc, | ||
MsgFunc, | ||
} from '../'; | ||
import { ValidationPromise } from '../'; | ||
@@ -9,8 +6,11 @@ /** | ||
*/ | ||
export default <T extends object = object>( | ||
value: string, | ||
row: T, | ||
msg: MsgFunc<T, string>, | ||
arg: string | ArgFunc<T, string> | ||
): Promise<string | void> => { | ||
const equalsTo: ValidationPromise = ( | ||
value, | ||
row, | ||
msg, | ||
arg | ||
) => { | ||
if (typeof value !== 'string') { | ||
return Promise.reject('Value must be a string'); | ||
} | ||
if (typeof arg === 'function') { | ||
@@ -25,1 +25,4 @@ arg = arg(value, row); | ||
}; | ||
export default equalsTo; | ||
@@ -1,5 +0,2 @@ | ||
import { | ||
ArgFunc, | ||
MsgFunc, | ||
} from '../'; | ||
import { ValidationPromise } from '../'; | ||
@@ -14,8 +11,11 @@ type FloatBoundsType = { | ||
*/ | ||
export default <T extends object = object>( | ||
value: string, | ||
row: T, | ||
msg: MsgFunc<T, FloatBoundsType>, | ||
arg: FloatBoundsType | ArgFunc<T, FloatBoundsType>, | ||
): Promise<string | void> => { | ||
const float: ValidationPromise<object, FloatBoundsType> = ( | ||
value, | ||
row, | ||
msg, | ||
arg, | ||
) => { | ||
if (typeof value !== 'string') { | ||
return Promise.reject('Value must be a string'); | ||
} | ||
if (typeof arg === 'function') { | ||
@@ -27,3 +27,3 @@ arg = arg(value, row); | ||
if (arg !== null) { | ||
if (arg !== null && arg !== undefined) { | ||
if ((arg.min !== undefined && Number(value) < Number(arg.min))) { | ||
@@ -43,1 +43,3 @@ return Promise.reject(msg(value, row, arg)); | ||
}; | ||
export default float; |
@@ -1,5 +0,2 @@ | ||
import { | ||
ArgFunc, | ||
MsgFunc, | ||
} from '../'; | ||
import { ValidationPromise } from '../'; | ||
@@ -14,8 +11,14 @@ type CompareSet = { | ||
*/ | ||
export default <T extends object = object>( | ||
value: string, | ||
row: T, | ||
msg: MsgFunc<T, number | CompareSet>, | ||
arg: number | CompareSet | ArgFunc<T, number | CompareSet>, | ||
): Promise<string | void> => { | ||
const greaterthan: ValidationPromise<object, CompareSet> = ( | ||
value, | ||
row, | ||
msg, | ||
arg, | ||
): Promise<string | void> => { | ||
if (typeof value === 'number') { | ||
value = String(value); | ||
} | ||
if (typeof value !== 'string') { | ||
return Promise.reject('Value must be a string or number'); | ||
} | ||
let compare: typeof arg | string = arg; | ||
@@ -35,1 +38,3 @@ if (typeof arg === 'function') { | ||
}; | ||
export default greaterthan; |
@@ -1,5 +0,2 @@ | ||
import { | ||
ArgFunc, | ||
MsgFunc, | ||
} from '../'; | ||
import { ValidationPromise } from '../'; | ||
@@ -14,8 +11,14 @@ type IntBoundsType = { | ||
*/ | ||
export default <T extends object = object>( | ||
value: string, | ||
row: T, | ||
msg: MsgFunc<T, IntBoundsType>, | ||
arg: IntBoundsType | ArgFunc<T, IntBoundsType>, | ||
): Promise<string | void> => { | ||
const int: ValidationPromise<object, IntBoundsType> = ( | ||
value, | ||
row, | ||
msg, | ||
arg, | ||
) => { | ||
if (typeof value === 'number') { | ||
value = String('number'); | ||
} | ||
if (typeof value !== 'string') { | ||
return Promise.reject('Value must be a number or a string'); | ||
} | ||
if (typeof arg === 'function') { | ||
@@ -27,3 +30,3 @@ arg = arg(value, row); | ||
if (arg !== null) { | ||
if (arg !== null && arg !== undefined) { | ||
if (arg.min !== undefined && Number(value) < Number(arg.min)) { | ||
@@ -43,1 +46,3 @@ return Promise.reject(msg(value, row, arg)); | ||
}; | ||
export default int; |
@@ -1,11 +0,8 @@ | ||
import { | ||
ArgFunc, | ||
MsgFunc, | ||
} from '../'; | ||
import { ValidationPromise } from '../'; | ||
export default <T extends object = object>( | ||
value: Record<string, number>, | ||
row: T, | ||
msg: MsgFunc<T>, | ||
arg: ArgFunc<T, number | Record<string, number>>, | ||
const isUpladed: ValidationPromise<object, number | Record<string, number>> = ( | ||
value, | ||
row, | ||
msg, | ||
arg, | ||
): Promise<any> => { | ||
@@ -22,2 +19,4 @@ if (value === undefined) { | ||
return Promise.resolve(); | ||
} | ||
} | ||
export default isUpladed; |
@@ -1,5 +0,2 @@ | ||
import { | ||
ArgFunc, | ||
MsgFunc, | ||
} from '../'; | ||
import { ValidationPromise } from '../'; | ||
@@ -11,13 +8,15 @@ type CompareSet = { | ||
/** | ||
* Check if a value is less than thr given value | ||
*/ | ||
export default <T extends object = object>( | ||
value: string, | ||
row: T, | ||
msg: MsgFunc<T, number | CompareSet>, | ||
arg: number | CompareSet | ArgFunc<T, number | CompareSet> | ||
): Promise<string | void> => { | ||
const lessthan: ValidationPromise<object, CompareSet> = ( | ||
value, | ||
row, | ||
msg, | ||
arg | ||
) => { | ||
let compare: typeof arg | string = arg; | ||
if (typeof value !== 'string') { | ||
return Promise.reject('Value must be a string'); | ||
} | ||
if (typeof arg === 'function') { | ||
@@ -37,1 +36,3 @@ compare = arg(value, row); | ||
}; | ||
export default lessthan; |
@@ -1,5 +0,2 @@ | ||
import { | ||
ArgFunc, | ||
MsgFunc, | ||
} from '../'; | ||
import { ValidationPromise } from '../'; | ||
@@ -9,8 +6,11 @@ /** | ||
*/ | ||
export default <T extends object = object>( | ||
value: string, | ||
row: T, | ||
msg: MsgFunc<T, any>, | ||
arg: any | ArgFunc<T, any>, | ||
): Promise<string | void> => { | ||
const notEquals: ValidationPromise = ( | ||
value, | ||
row, | ||
msg, | ||
arg, | ||
) => { | ||
if (typeof value !== 'string') { | ||
return Promise.reject('Value must be a string'); | ||
} | ||
if (typeof arg === 'function') { | ||
@@ -25,1 +25,4 @@ arg = arg(value, row); | ||
}; | ||
export default notEquals | ||
@@ -1,5 +0,2 @@ | ||
import { | ||
ArgFunc, | ||
MsgFunc, | ||
} from '../'; | ||
import { ValidationPromise } from '../'; | ||
@@ -14,8 +11,11 @@ /** | ||
*/ | ||
export default <T extends object = object>( | ||
value: string, | ||
row: T, | ||
msg: MsgFunc<T, string>, | ||
arg: string | ArgFunc<T, string>, | ||
): Promise<string | void> => { | ||
const regex: ValidationPromise = ( | ||
value, | ||
row, | ||
msg, | ||
arg, | ||
) => { | ||
if (typeof value !== 'string') { | ||
return Promise.reject('Value must be a string'); | ||
} | ||
const test = typeof arg === 'function' ? arg(value, row) : arg; | ||
@@ -29,1 +29,3 @@ const regex = new RegExp(test, 'g'); | ||
}; | ||
export default regex; |
@@ -1,2 +0,2 @@ | ||
import { MsgFunc } from '../'; | ||
import { ValidationPromise } from '../'; | ||
@@ -6,3 +6,3 @@ /** | ||
*/ | ||
export default <T extends object = object>(value: string, row: T, msg: MsgFunc<T>) : Promise<string | void> => { | ||
const required: ValidationPromise = (value, row, msg) => { | ||
return new Promise((resolve, reject) => { | ||
@@ -15,1 +15,3 @@ if (value !== '' && value !== undefined) { | ||
}; | ||
export default required; |
@@ -1,5 +0,2 @@ | ||
import { | ||
ArgFunc, | ||
MsgFunc, | ||
} from '../'; | ||
import { ValidationPromise } from '../'; | ||
@@ -9,8 +6,11 @@ /** | ||
*/ | ||
export default <T extends object = object>( | ||
value: string, | ||
row: T, | ||
msg: MsgFunc<T, string[]>, | ||
arg: string[] | ArgFunc<T, string[]> | ||
): Promise<string | void> => { | ||
const whitelist: ValidationPromise = ( | ||
value, | ||
row, | ||
msg, | ||
arg, | ||
) => { | ||
if (typeof value !== 'string') { | ||
return Promise.reject('Value must be a string'); | ||
} | ||
if (typeof arg === 'function') { | ||
@@ -24,1 +24,3 @@ arg = arg(value, row); | ||
}; | ||
export default whitelist; |
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
348593
2685