{"id":41782390,"url":"https://github.com/dividedbyzeroco/enforce-js","last_synced_at":"2026-01-25T04:04:28.682Z","repository":{"id":57225316,"uuid":"120897780","full_name":"dividedbyzeroco/enforce-js","owner":"dividedbyzeroco","description":"Data enforcer syntax for verbose validations","archived":false,"fork":false,"pushed_at":"2018-11-09T04:00:48.000Z","size":34,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-09T05:36:20.124Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dividedbyzeroco.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-09T11:30:14.000Z","updated_at":"2018-11-09T04:00:49.000Z","dependencies_parsed_at":"2022-08-24T10:40:20.464Z","dependency_job_id":null,"html_url":"https://github.com/dividedbyzeroco/enforce-js","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dividedbyzeroco/enforce-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dividedbyzeroco%2Fenforce-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dividedbyzeroco%2Fenforce-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dividedbyzeroco%2Fenforce-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dividedbyzeroco%2Fenforce-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dividedbyzeroco","download_url":"https://codeload.github.com/dividedbyzeroco/enforce-js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dividedbyzeroco%2Fenforce-js/sbom","scorecard":{"id":345305,"data":{"date":"2025-08-11","repo":{"name":"github.com/dividedbyzeroco/enforce-js","commit":"7242f3c1cbe662dcda55017f727a041430952f59"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":1.3,"checks":[{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":0,"reason":"license file not detected","details":["Warn: project does not have a license file"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":0,"reason":"31 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-c6rq-rjc2-86v2","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq","Warn: Project is vulnerable to: GHSA-ff7x-qrg7-qggm","Warn: Project is vulnerable to: GHSA-8r6j-v8pm-fqw3","Warn: Project is vulnerable to: MAL-2023-462","Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97","Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37","Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-fhjf-83wg-r2j9","Warn: Project is vulnerable to: GHSA-8hfj-j24r-96c4","Warn: Project is vulnerable to: GHSA-wc69-rhjr-hc9g","Warn: Project is vulnerable to: GHSA-56x4-j7p9-fcf9","Warn: Project is vulnerable to: GHSA-v78c-4p63-2j6c","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-4g88-fppr-53pp","Warn: Project is vulnerable to: GHSA-4jqc-8m5r-9rpr","Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9","Warn: Project is vulnerable to: GHSA-r628-mhmh-qjhw","Warn: Project is vulnerable to: GHSA-9r2w-394v-53qc","Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh","Warn: Project is vulnerable to: GHSA-qq89-hq3f-393p","Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36","Warn: Project is vulnerable to: GHSA-332q-7ff2-57h2"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-18T06:54:34.210Z","repository_id":57225316,"created_at":"2025-08-18T06:54:34.211Z","updated_at":"2025-08-18T06:54:34.211Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28742983,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-25T02:46:29.005Z","status":"ssl_error","status_checked_at":"2026-01-25T02:44:29.968Z","response_time":113,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":"2026-01-25T04:04:28.077Z","updated_at":"2026-01-25T04:04:28.671Z","avatar_url":"https://github.com/dividedbyzeroco.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Enforce JS\nEnforcing data validations through readable definitions\n\n## Introduction\n`enforce` is a data validation tool that allows you to assert rules on supplied variables and parameters, using a human-friendly format.\n\n## Getting Started\nTo install `enforce`, run the following code in your npm project.\n\n```javascript\nnpm install --save enforce-js\n```\nAfter installing, simply import the module.\n\n```javascript\nimport enforce from 'enforce-js';\n```\n\n## Syntax\nTo `enforce` validation on a variable, simply follow the syntax below.\n\n```javascript\nenforce`${{ variable }} as dataType, rule1, rule2, ...`;\n```\n\n### Example\n\n```javascript\n// Validate a variable\nconst message = 'Hello, world!';\nenforce`${{ message }} as a string, with 5 to 20 characters`; // ok\n```\n\n\u003e NOTE: `enforce` uses double brackets as a shortcut to `{ variable: variable }`\n\n## Regular Data Types\n`enforce` supports primitive javascript data types, which by default, are __non-nullable__. To explictly define a variable to be nullable, use the `optional` keyword.\n\n\u003e NOTE: Non-nullable in `enforce` means the value can either be `undefined` or the specified data type. It cannot be a javascript `null` object.\n\n- 'a string'\n- 'a number'\n- 'a boolean'\n- 'an array'\n- 'an object'\n- 'a function'\n- 'an optional string'\n- 'an optional number'\n- 'an optional boolean'\n- 'an optional array'\n- 'an optional object'\n- 'an optional function'\n- 'a value'\n- 'any value'\n\n## Rules\nAdditional rules can help further validate a supplied variable. If the below rules do not meet the requirements of what may be needed, you may use the `and matches REGEXP` rule in order to fill the gap, or you can try [Extending Rules](#extending-rules).\n\n- 'with `MIN` to `MAX` characters' (MIN: number, MAX: number)\n- 'with `MIN` or more characters' (MIN: number)\n- 'with up to `MAX` characters' (MAX: number)\n- 'greater than `MIN`' (MIN: number)\n- 'greater than or equal to `MIN`' (MIN: number)\n- 'less than `MAX`' (MAX: number)\n- 'less than or equal to `MAX`' (MAX: number)\n- 'and matches `REGEXP`' (REGEXP: regular expression)\n\n## Validating Classes\n\n`enforce` also supports validating class-type objects. To validate whether a supplied variable or parameter is an instance of a class, you can directly supply the class as a data type.\n\n```javascript\nclass Animal { /* class definition */ }\nconst dog = new Animal();\n\nenforce`${{ dog }} as an ${{ Animal }}`; // ok\n\nclass Dog extends Animal { /* class definition */ }\nconst corgi = new Dog();\n\nenforce`${{ corgi }} as a ${{ Dog }}`; // ok\nenforce`${{ corgi }} as an ${{ Animal }}`; // ok\nenforce`${{ dog }} as a ${{ Dog }}`; // error!\n```\n\n## Catching Errors\n\nBy default, if a given parameter does not meet the rules provided, a `ValidationError` will be thrown with a message containing the original definition. To better handle the error, an additional `name` parameter is also supplied to let you know which parameter was invalid.\n\n```javascript\nconst countingNumber = -1;\n\nenforce`${{ countingNumber }} as a number, greater than or equal to 0`;\n\n// OUTPUT\n// error.message: 'countingNumber' must be a number, greater than or equal to 0\n// error.name: countingNumber\n```\n\nThe recommended approach is to have a try-catch block that retrieves the invalid parameter.\n\n```javascript\nimport enforce, { ValidationError } from 'enforce-js';\n\ntry {\n    const countingNumber = -1;\n    enforce`${{ countingNumber }} as a number, greater than or equal to 0`;\n}\ncatch(err) {\n    if(err instanceof ValidationError) {\n        console.error(`The error message was: ${err.message}, and the invalid parameter is: ${err.name}`);\n    }\n}\n```\n\n\u003e NOTE: `enforce` format is also validated and throws a `FormatError` when the supplied definition is invalid.\n\n```javascript\nimport enforce, { FormatError } from 'enforce-js';\n\ntry {\n    const countingNumber = -1;\n    enforce`${{ countingNumber }} as a postive number, and is the square root of 4`;\n}\ncatch(err) {\n    if(err instanceof FormatError) {\n        console.error(`The error message was: ${err.message}, and the invalid parameter is: ${err.name}`);\n    }\n}\n```\n\n## Extending Rules\n\nIf you need additional rules currently not supported by `enforce`, you can extend the library by using the `.extend()` method. \n\n```javascript\nenforce.extend(REGEXP, VALIDATOR);\n\n// REGEXP = Regular Expression matching the rule\n// VALIDATOR = Function that will check if the supplied value is valid\n```\n\n### Example\n\n```javascript\n// Extend a new rule\nenforce.extend(/^and is equal to \\d{1,}$/i, (val, rule) =\u003e {\n    // e.g. rule == 'is equal to 5'\n    const number = parseInt(rule.slice(rule.lastIndexOf(' ')));\n    return val === number;\n});\n\n// Enforce the new rule\nconst thisNumber = 5;\nenforce`${{ thisNumber }} as a number, and is equal to 5`;\n```\n\n## Examples\n\n```javascript\n// Import module\nimport enforce, { ValidationError } from 'enforce-js';\n\n// Validate a variable\nconst message = 'Hello, world!';\nenforce`${{ message }} as a string, with 5 to 20 characters`; // ok\n\n// Validate function parameters\nconst register = ({ username, name, password, age, options }) =\u003e {\n    try {\n        enforce`${{ username }} as a string`;\n        enforce`${{ name }} as an optional string`;\n        enforce`${{ password }} as a string, with 6 to 8 characters`;\n        enforce`${{ password }} as a password, with 6 to 8 characters, and matches /^\\\\d{6,8}$/i`;\n        enforce`${{ age }} as a number, greater than 18`;\n        enforce`${{ options }} as an optional object`;\n\n        const { messages } = options;\n        enforce`${{ messages }} as a boolean`;\n\n        /* function definition */\n    }\n    catch(err) {\n        if(err instanceof ValidationError) {\n            return `Invalid Parameter: ${err.name}`;\n        }\n    }\n}\n\n// Use function\nconst result = register({\n    username: 'tardisblue', // ok\n    name: 'Amy Pond', // ok\n    password: '1234', // error!\n    age: 21 // ok\n});\n\n// result: `Invalid Parameter: password`\n\n// Validate if an object is an instance of a class\nclass Post { /* class definition */ }\nconst post = new Post();\n\nenforce`${{ post }} as a ${{ Post }}`; // ok\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdividedbyzeroco%2Fenforce-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdividedbyzeroco%2Fenforce-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdividedbyzeroco%2Fenforce-js/lists"}