{"id":26611103,"url":"https://github.com/envelope/troi","last_synced_at":"2025-07-24T20:09:02.924Z","repository":{"id":57162507,"uuid":"294710374","full_name":"envelope/troi","owner":"envelope","description":"Middleware-based data validation and sanitization library","archived":false,"fork":false,"pushed_at":"2025-02-22T13:26:01.000Z","size":105,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-10T00:43:37.437Z","etag":null,"topics":["javascript","sanitize","validation"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/envelope.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":"2020-09-11T14:00:07.000Z","updated_at":"2025-02-22T13:25:28.000Z","dependencies_parsed_at":"2024-10-02T23:01:11.678Z","dependency_job_id":"ec0d78c6-1895-4193-9fdc-f576b98d03c2","html_url":"https://github.com/envelope/troi","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/envelope%2Ftroi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/envelope%2Ftroi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/envelope%2Ftroi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/envelope%2Ftroi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/envelope","download_url":"https://codeload.github.com/envelope/troi/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248137998,"owners_count":21053775,"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":["javascript","sanitize","validation"],"created_at":"2025-03-24T02:25:31.720Z","updated_at":"2025-04-10T00:43:43.153Z","avatar_url":"https://github.com/envelope.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Troi\n\nTroi is a middleware-based data validation and sanitization library.\n\n[![Build Status](https://travis-ci.org/envelope/troi.svg?branch=master)](https://travis-ci.org/envelope/troi)\n[![npm version](https://img.shields.io/npm/v/troi.svg?style=flat-square)](https://www.npmjs.com/package/troi)\n\n## Installation\n\n```\nnpm install troi\n```\n\n## Example\n\n```JavaScript\nconst troi = require('troi/chain');\n\nconst schema = troi.object({\n  username: troi.filled()\n    .string()\n    .trim()\n    .lengthBetween(2, 10),\n  email: troi.filled()\n    .lowercase()\n    .email(),\n  password: troi.filled()\n    .string()\n    .lengthBetween(3, 30)\n    .pattern(/^[a-zA-Z0-9]+$/)\n});\n\nschema.validate({\n  username: 'karate-kid',\n  email: 'larusso@example.org',\n  password: 'n0C0br4k4i'\n});\n// -\u003e { username: 'karate-kid', email: 'larusso@example.org', password: 'N0C0br4k4i' }\n\nschema.validate({\n  username: 'karate-kid'\n});\n// Throws validation error\n```\n\n### API\nWork in progress\n\n#### `filled()`\n#### `required()`\n#### `optional()`\n#### `nullable()`\n#### `string()`\n#### `number()`\n#### `integer()`\n#### `boolean()`\n#### `date()`\n#### `array(itemValidator?: function)`\n#### `object(properties?: object)`\n#### `params(schema: object)`\n#### `oneOf(values: Array\u003cany\u003e)`\n#### `unique()`\n#### `between(min: number, max: number)`\n#### `min(min: number)`\n#### `max(max: number)`\n#### `lengthBetween(min: number, max: number)`\n#### `minLength(min: number)`\n#### `maxLength(min: number)`\n#### `length(expectedLength: number)`\n#### `pattern(regexp: RegExp, type?: string)`\n#### `email()`\n#### `lowercase()`\n#### `uppercase()`\n\n### Chain API\n\nWork in progress\n\n## Concepts and Terminology\n\n### Middleware Function\n\nMiddleware functions can perform the following tasks:\n\n- return validation errors and stop further execution\n- transform values (examples: `trim`, `nullify`)\n- intercept execution (examples: `optional`, `nullable`)\n\n### Transform function\n\nA middleware function that *may* transform its `input` argument and return another value.\n\n```JavaScript\nconst trim = (input, next) =\u003e next(typeof input === 'string' ? input.trim() : input);\n```\n\n### Interceptor function\n\nA middleware function that *may* stop the execution of remaining middleware functions.\n\n```JavaScript\nconst optional = (input, next) =\u003e input === undefined ? input : next(input)\n```\n\n### Identity Function\n\nA function that always returns the same value that was used as its argument.\n\n```JavaScript\nidentity('string') // returns 'string'\n```\n\n## Todos\n- [ ] Allow middleware to pass `ValidationError` to `next()` and stop execution\n- [ ] Make chain builder immutable\n- [ ] Add `coerce` transform function\n- [ ] Rename all `value` arguments to `input` for consistency\n- [ ] Use rollup.js\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenvelope%2Ftroi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fenvelope%2Ftroi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenvelope%2Ftroi/lists"}