{"id":17004842,"url":"https://github.com/clickermonkey/valid8or","last_synced_at":"2025-03-22T10:39:18.579Z","repository":{"id":152212252,"uuid":"180898788","full_name":"ClickerMonkey/valid8or","owner":"ClickerMonkey","description":"A validator and transformer in TypeScript/JS for simple and complex data types","archived":false,"fork":false,"pushed_at":"2021-09-14T05:14:46.000Z","size":121,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-27T10:23:12.129Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ClickerMonkey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-12T00:24:57.000Z","updated_at":"2021-09-14T05:14:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"d8866cfd-172c-46fe-9e38-09cd074e3773","html_url":"https://github.com/ClickerMonkey/valid8or","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ClickerMonkey%2Fvalid8or","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ClickerMonkey%2Fvalid8or/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ClickerMonkey%2Fvalid8or/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ClickerMonkey%2Fvalid8or/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ClickerMonkey","download_url":"https://codeload.github.com/ClickerMonkey/valid8or/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244945597,"owners_count":20536295,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T04:44:36.107Z","updated_at":"2025-03-22T10:39:18.553Z","avatar_url":"https://github.com/ClickerMonkey.png","language":"TypeScript","readme":"\r\n\u003cp align=\"center\"\u003e\r\n\u003cimg src=\"https://img.shields.io/npm/v/valid8or.svg\"\u003e\r\n\u003cimg src=\"https://img.shields.io/npm/l/valid8or.svg\"\u003e\r\n\u003cimg src=\"https://travis-ci.org/ClickerMonkey/valid8or.svg?branch=master\"\u003e\r\n\u003c/p\u003e\r\n\r\n## valid8or\r\n\r\nA validator and transformer in TypeScript/JS for simple and complex data types.\r\n\r\n### Example\r\n\r\n```typescript\r\nconst arrayValidator = arr()\r\n  .required(() =\u003e [])                       // an array is required, but if undefined is given get a default value of []\r\n  .maxLength(4)                             // the array cannot contain any more than 4 elements\r\n  .type(                                    // the type of the elements in the array\r\n    obj().required().props({                // must be non-null non-undefined objects\r\n      id: str().required().trim().alpha(),  // the id is required, it will be trimmed, and tested for alpha characters only\r\n      age: int().optional().greaterThan(0), // the age is optional, so if it doesn't look like an int, ignore greaterThan\r\n      admin: bool().required(false)         // a valid admin value is expected (true/y/yes/1/false/n/no/0), but if it's missing from the object then set admin to false\r\n    }\r\n  ))\r\n;\r\n\r\nconst validValue = [\r\n  { id: 'abcd', age: '23' },\r\n  { id: 'abcd', admin: true },\r\n  { id: ' abef ', admin: '1' }\r\n]\r\n\r\nconst [pass, result, fail, items] = await arrayValidator.runAsTuple(validValue);\r\n\r\n/*\r\npass = true\r\nresult = [\r\n  { id: 'abcd', age: 23, admin: false },\r\n  { id: 'abcd', admin: true },\r\n  { id: 'abef', admin: true }]\r\nfail = undefined\r\nitems = []\r\n*/\r\n\r\nconst invalidValue = [\r\n  { id: 45, age: -45, admin: 'WHAT' },\r\n  null,\r\n  { id: 'rte' }\r\n];\r\n\r\nconst [pass, result, fail, items] = await arrayValidator.runAsTuple(invalidValue);\r\n\r\n/*\r\npass = false\r\nresult = undefined\r\nfail = [\r\n  { id: 'alpha', age: 'greaterThan', admin: 'required' },\r\n  'required',\r\n  undefined // passed validation, not a failure\r\n]\r\nitems = [\r\n  { path: [0, 'id'], message: 'alpha', value: 45 },\r\n  { path: [0, 'age'], message: 'greaterThan', value: -45 },\r\n  { path: [0, 'admin'], message: 'required', value: 'WHAT' },\r\n  { path: [1], message: 'required', value: null }\r\n]\r\n*/\r\n\r\n```\r\n\r\n## API\r\n\r\n### Validator Generators\r\n- `int()`: ValidatorNumber (type `number`)\r\n- `float()`: ValidatorNumber (type `number`)\r\n- `str()`: ValidatorString (type `string`)\r\n- `obj\u003cT\u003e()`: ValidatorObject\u003cT\u003e (type `T`)\r\n- `arr\u003cT\u003e()`: ValidatorArray\u003cT\u003e (type `T`)\r\n- `bool()`: ValidatorBoolean (type `boolean`)\r\n- `date()`: ValidatorDate (type `Date`)\r\n- `geo()`: ValidatorObject (type `GeoInput -\u003e GeoOutput`)\r\n- `any()`: ValidatorAny (type `any`)\r\n\r\n### Index\r\n\r\n#### Validators\r\n[`required`](required) [`optional`](optional) [`is`](is) [`oneOf`](oneOf) [`notOneOf`](notOneOf) [`equals`](equals) [`greaterThan`](greaterThan) [`greaterThanEqual`](greaterThanEqual) [`between`](between) [`min`](min) [`max`](max) [`fail`](fail) [`or`](or) [`validate`](validate) [`eval`](eval) [`type`](type) [`minLength`](minLength) [`maxLength`](maxLength) [`every`](every) [`some`](some) [`unique`](unique) [`isWeekday`](isWeekday) [`isDayOfMonth`](isDayOfMonth) [`isMonth`](isMonth) [`getTime`](getTime) [`isPositive`](isPositive) [`isNegative`](isNegative) [`props`](props) [`instanceOf`](instanceOf) [`wrap`](wrap) [`insensitive`](insensitive) [`exists`](exists) [`isLower`](isLower) [`isUpper`](isUpper) [`like`](like) [`unlike`](unlike) [`minLength`](minLength) [`maxLength`](maxLength) [`colorHex`](colorHex) [`colorShortHex`](colorShortHex) [`colorRGB`](colorRGB) [`colorRGBA`](colorRGBA) [`color`](color) [`linkless`](linkless) [`uuid`](uuid) [`ipv4`](ipv4) [`ipv6`](ipv6) [`ip`](ip) [`isbn`](isbn) [`phoneUS`](phoneUS) [`zipUS`](zipUS) [`alphaNumeric`](alphaNumeric) [`alpha`](alpha) [`token`](token) [`hex`](hex) [`base64`](base64) [`http`](http) [`https`](https) [`url`](url) [`email`](email) [`creditCard`](creditCard)\r\n\r\n#### Transformers\r\n[`transform`](transform) [`json`](json) [`nullify`](nullify) [`remove`](remove) [`set`](set) [`reverse`](reverse) [`filter`](filter) [`sort`](sort) [`map`](map) [`removeDuplicates`](removeDuplicates) [`endOfDay`](endOfDay) [`startOfDay`](startOfDay) [`endOfWeek`](endOfWeek) [`startOfWeek`](startOfWeek) [`endOfMonth`](endOfMonth) [`startOfMonth`](startOfMonth) [`endOfYear`](endOfYear) [`startOfYear`](startOfYear) [`floor`](floor) [`abs`](abs) [`neg`](neg) [`ceil`](ceil) [`round`](round) [`replace`](replace) [`truncate`](truncate) [`trim`](trim) [`ltrim`](ltrim) [`rtrim`](rtrim) [`lower`](lower) [`upper`](upper) [`strip`](strip) [`encode`](encode) [`encodeComponent`](encodeComponent) [`decode`](decode) [`decodeComponent`](decodeComponent) [`normalizeEmail`](normalizeEmail)\r\n\r\n#### Modifiers\r\n[`message`](message) [`withComparator`](withComparator) [`reverseComparator`](reverseComparator) [`withTruthy`](withTruthy) [`withFalsy`](withFalsy) \r\n\r\n#### Validation\r\n[`run`](run) [`runAsPromise`](runAsPromise) [`runAsTuple`](runAsTuple) \r\n\r\nEvery validator has the following methods:\r\n\r\n- `required(defaults?)`: Evaluates the value and requires a valid one.\r\n- `optional(defaults?)`: Evaluates the value and if it's not valid ignores the following validations and transforms.\r\n- `is((value) =\u003e valid)`: Does a simple validation\r\n- `transform((currentValue) =\u003e newValue)`: Transforms a value into another.\r\n- `oneOf([])`: Checks that the value exists in the array.\r\n- `oneOf(() =\u003e [])`: Checks that the value exists in the array returned when the function is invoked.\r\n- `notOneOf([])`: Checks that the value does not exist in the array.\r\n- `notOneOf(() =\u003e [])`: Checks that the value does not exist in the array returned when the function is invoked.\r\n- `equals(expects)`: Checks the value equals expects.\r\n- `equals(() =\u003e expects)`: Checks the value equals the expects value returned when the function is invoked.\r\n- `greaterThan(expects)`: Checks the value is greater than expects.\r\n- `greaterThan(() =\u003e expects)`: Checks the value is greater than the expects value returned when the function is invoked.\r\n- `greaterThanEqual(expects)`: Checks the value is greater than or equal to expects.\r\n- `greaterThanEqual(() =\u003e expects)`: Checks the value is greater than or equal to expects value returned when the function is invoked.\r\n- `between(min, max)`: Checks the value is inclusively between the given minimum and maximum values (if they are functions they are invoked).\r\n- `min(minimumAllowed)`\r\n- `max(maximumAllowed)`\r\n- `fail()`\r\n- `or(validator =\u003e validators[])`\r\n- `json()`\r\n- `nullify()`\r\n- `remove()`\r\n- `set(newValue)`\r\n- `encode()`\r\n- `encodeComponent()`\r\n- `decode()`\r\n- `decodeComponent()`\r\n- `validate(check)`: A custom validation check.\r\n- `eval(required, defaults?)`: Evaluates the value by parsing and checking it.\r\n- `message(string)`: Follows a validation and if the validation fails this will be the message returned in the failure value.\r\n- `message((value) =\u003e string)`: Follows a validation and instead of a constant string, the value passed can be incorporated into the message.\r\n- `withComparator(comparator)`: Sets a custom comparator to be used for the following validation.\r\n- `reverseComparator()`: Reverses the logic for the next validation.\r\n- `runAsPromise(testValue)`\r\n- `runAsTuple(testValue)`\r\n\r\n### ValidatorAny\r\n\r\n### ValidatorArray\r\n- `type(typeValidator)`\r\n- `minLength(min)`\r\n- `maxLength(max)`\r\n- `every(every)`\r\n- `some(some)`\r\n- `reverse()`\r\n- `filter(filter)`\r\n- `sort(sorter?)`\r\n- `map(mapper)`\r\n- `unique(comparator?)`\r\n- `removeDuplicates(comparator?)`\r\n\r\n### ValidatorBoolean\r\n- `withTruthy(regex)`\r\n- `withFalsy(regex)`\r\n\r\n### ValidatorDate\r\n- `isWeekday(weekdays)`\r\n- `isDayOfMonth(weekdays)`\r\n- `isMonth(weekdays)`\r\n- `endOfDay()`\r\n- `startOfDay()`\r\n- `endOfWeek()`\r\n- `startOfWeek()`\r\n- `endOfMonth()`\r\n- `startOfMonth()`\r\n- `endOfYear()`\r\n- `startOfYear()`\r\n- `getTime()`\r\n\r\n### ValidatorNumber\r\n- `isPositive()`\r\n- `isNegative()`\r\n- `floor()`\r\n- `abs()`\r\n- `neg()`\r\n- `ceil()`\r\n- `round()`\r\n\r\n### ValidatorObject\r\n- `props({ prop: Validator })`\r\n- `instanceOf(type)`\r\n- `wrap(type)`\r\n\r\n### ValidatorString\r\n- `insensitive()`\r\n- `exists()`\r\n- `isLower()`\r\n- `isUpper()`\r\n- `like(regex)`\r\n- `unlike(regex)`\r\n- `minLength(length)`\r\n- `maxLength(length)`\r\n- `colorHex(allowHash?, requireHash?)`\r\n- `colorShortHex(allowHash?, requireHash?)`\r\n- `colorRGB(percent?)`\r\n- `colorRGBA(percent?)`\r\n- `color(percent?, allowHash?, requireHash?)`\r\n- `linkless()`\r\n- `uuid()`\r\n- `ipv4()`\r\n- `ipv6()`\r\n- `ip()`\r\n- `isbn()`\r\n- `phoneUS()`\r\n- `zipUS()`\r\n- `alphaNumeric()`\r\n- `alpha()`\r\n- `token()`\r\n- `hex()`\r\n- `base64()`\r\n- `http()`\r\n- `https()`\r\n- `url(requireProtocol?)`\r\n- `email()`\r\n- `creditCard()`\r\n- `replace(regex, replacement)`\r\n- `truncate(maxLength)`\r\n- `trim()`\r\n- `ltrim()`\r\n- `rtrim()`\r\n- `lower()`\r\n- `upper()`\r\n- `strip(regex)`\r\n- `normalizeEmail()`\r\n\r\n## LICENSE\r\n[MIT](https://opensource.org/licenses/MIT)\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclickermonkey%2Fvalid8or","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclickermonkey%2Fvalid8or","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclickermonkey%2Fvalid8or/lists"}