{"id":16844747,"url":"https://github.com/stephanhoyer/vandalize","last_synced_at":"2025-08-09T09:32:34.917Z","repository":{"id":57390440,"uuid":"50331392","full_name":"StephanHoyer/vandalize","owner":"StephanHoyer","description":"functional minimal framework to create your own validation/sanitation lib","archived":false,"fork":false,"pushed_at":"2023-12-15T11:45:01.000Z","size":12,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-11T06:49:51.021Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/StephanHoyer.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":"2016-01-25T06:39:47.000Z","updated_at":"2016-01-25T22:53:12.000Z","dependencies_parsed_at":"2025-02-10T21:33:22.720Z","dependency_job_id":"5101efef-f4aa-4d0e-8e05-396676b71301","html_url":"https://github.com/StephanHoyer/vandalize","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/StephanHoyer%2Fvandalize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StephanHoyer%2Fvandalize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StephanHoyer%2Fvandalize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StephanHoyer%2Fvandalize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StephanHoyer","download_url":"https://codeload.github.com/StephanHoyer/vandalize/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247325645,"owners_count":20920713,"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-13T12:56:29.545Z","updated_at":"2025-04-05T10:42:29.577Z","avatar_url":"https://github.com/StephanHoyer.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# vandalize\nfunctional minimal framework to create your own validation/sanitation lib\n\n## create a sanitizer\n\n```javascript\n  // create your base sanitizers\n  var san = require('vandalize/san')({\n    up: () =\u003e (value) =\u003e value.toUpperCase(),\n    cut: (length) =\u003e (value) =\u003e value.slice(0, length)\n  })\n\n  // combine your sanitizers to your specific sanitizer\n  var cleanUsername = san.cut(6).up()\n\n  // use it\n  var username = cleanUsername('foobarbaz')\n  assert(username === 'FOOBAR')\n```\n\nSpecial handling for objects\n\n```javascript\n  var cleanUser = san.object({\n    name: val.up(),\n    password: val.cut(3)\n  })\n\n  var user = cleanUser({\n    name: 'mr. hello',\n    password: '1234567'\n  })\n\n  // it's not really strict equality, this is just for brewity\n  assert(user === { name: 'MR. HELLO', password: '123'})\n```\n\n## create a validator\n\n```javascript\n  // create your base validators\n  var val = require('vandalize/val')({\n    isString: () =\u003e (value) =\u003e typeof value === 'string'\n    hasLength: (length) =\u003e (value) =\u003e value.length === length\n  })\n\n  // combine your validators to your specific validator\n  var isUsername = val.isString().hasLength(5)\n\n  // use it\n  assert(isUsername('foobarbaz') === false)\n  assert(isUsername(1) === false)\n  assert(isUsername('12345') === true)\n```\n\n### Special handling for objects\n\n```javascript\n  var isUser = val.object({\n    name: val.isString(),\n    password: val.hasLength(3)\n  })\n\n  var result = isUser({\n    name: 'mr. hello',\n    password: '1234567'\n  })\n\n  // it's not really strict equality, this is just for brewity\n  assert(result === { key: 'password', message: 'validation failed' })\n```\n\n### Use your own message\n\nYou can use your own error message by either providing it on the validator\nitself or when initilizing your custom validator\n\n```javascript\n  var val = require('vandalize/val')({\n    isString: () =\u003e (value) =\u003e {\n      return typeof value === 'string' || 'expected string, got ' + typeof value\n    }\n  })\n\n  var checker = val.isString()\n\n  assert(checker(123) === 'expected string, got number')\n```\n\n```javascript\n  var val = require('vandalize/val')({\n    isString: () =\u003e (value) =\u003e typeof value === 'string'\n  })\n\n  var checker = val.isString('expected string')\n\n  assert(checker(123) === 'expected string')\n```\n\n### Exceptions\n\nYou can also use exceptions to let a validation fail\n\n```javascript\n  var val = require('vandalize/val')({\n    isString: () =\u003e (value) =\u003e {\n      if (typeof value !== 'string') {\n        throw new Error('expected string, got ' + typeof value)\n      }\n      return true\n    }\n  })\n\n  var checker = val.isString()\n\n  assert(checker(123) === 'expected string, got number')\n```\n\n### Exception mode\n\nYou can also let the lib throw exceptions on a failing validation.\n\n```javascript\n  var val = require('vandalize/val')({\n    isString: () =\u003e (value) =\u003e typeof value === 'string' || 'expected string, got ' + typeof value\n  }, {\n    mode: 'exception'\n  })\n\n  var checker = val.isString()\n\n  try {\n    assert(checker(123))\n  } catch(e) {\n    assert(e.message === 'expected string, got number')\n  }\n```\n\n### All-errors-mode\n\nIn all other modes the first error that arises will quit further validation. In\n`all`-mode the validation process continues up to the last defined validator.\n\n```javascript\n  var val = require('vandalize/val')({\n    isString: () =\u003e (value) =\u003e typeof value === 'string' || 'should be a string, is a ' + typeof value,\n    hasLength: (length) =\u003e (value) =\u003e value.length === length || 'should have length ' + length\n  }, {\n    mode: 'all'\n  })\n\n  var isUsername = val.isString().hasLength(5)\n\n  // it's not really strict equality, this is just for brewity\n  assert(isUsername('foobarbaz') === ['should have length 5'])\n  assert(isUsername(1) === ['should be a string, is a number', 'should have length 5'])\n  assert(isUsername('12345') === [])\n```\n\n`exeption`- and `all`-mode are also supported for objects. See the tests for detailed example.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstephanhoyer%2Fvandalize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstephanhoyer%2Fvandalize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstephanhoyer%2Fvandalize/lists"}