{"id":23063470,"url":"https://github.com/julienetie/typecase","last_synced_at":"2025-10-30T04:35:44.092Z","repository":{"id":57383289,"uuid":"103056324","full_name":"julienetie/typecase","owner":"julienetie","description":"A type checker for dynamically typed JavaScript","archived":false,"fork":false,"pushed_at":"2018-03-16T05:09:22.000Z","size":39,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-15T06:15:01.961Z","etag":null,"topics":["checker","dynamic-types","type","type-check","type-checker","type-error","typecheck","typechecker","types"],"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/julienetie.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}},"created_at":"2017-09-10T19:36:12.000Z","updated_at":"2025-08-27T12:14:03.000Z","dependencies_parsed_at":"2022-09-26T16:50:22.393Z","dependency_job_id":null,"html_url":"https://github.com/julienetie/typecase","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/julienetie/typecase","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/julienetie%2Ftypecase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/julienetie%2Ftypecase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/julienetie%2Ftypecase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/julienetie%2Ftypecase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/julienetie","download_url":"https://codeload.github.com/julienetie/typecase/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/julienetie%2Ftypecase/sbom","scorecard":{"id":542144,"data":{"date":"2025-08-11","repo":{"name":"github.com/julienetie/typecase","commit":"646c095f64f11e49beb4e4230d9a7bd1dcde829a"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"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":"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":"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":"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":"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":"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":"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":"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":"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":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"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":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"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"}}]},"last_synced_at":"2025-08-20T08:28:15.392Z","repository_id":57383289,"created_at":"2025-08-20T08:28:15.392Z","updated_at":"2025-08-20T08:28:15.392Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279006626,"owners_count":26084131,"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","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["checker","dynamic-types","type","type-check","type-checker","type-error","typecheck","typechecker","types"],"created_at":"2024-12-16T04:10:33.021Z","updated_at":"2025-10-11T07:40:17.342Z","avatar_url":"https://github.com/julienetie.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"_en-GB_\n# Typecase\n\u003cimg src=\"http://oi63.tinypic.com/4j2544.jpg\" width=\"300\" text-align=\"center\"\u003e\n\nTypecase aims to provide a useful type of a given value. It is intended for standard dynamically typed JavaScript.\n\nTypes seem to be a commonly misunderstood subject in the world of JavaScript and can sometimes be difficult to manage even if you do understand it well. Typecase differentiates between different types from the perspective of the JavaScript language and common usage rather than other [statically typed languages](https://stackoverflow.com/questions/1517582/what-is-the-difference-between-statically-typed-and-dynamically-typed-languages).\n\n## Why\n- It's JavaScript (No extra compiling, no local software setup).\t\t\n- Ideal for both lower and higher level development.\t\t\n- Covers a range of commonly used types as well as dynamic types e.g. objectHTMLBodyElement.\t\t\n- Type checking syntax for single return values (pure functions)\t\t\n- Assign callbacks for various types - TBA\t\t\n- Option to toggle between debug/prod mode (Similar to Object.freeze usage) - TBA \t\t\n- Typecase serves as a type-checker but can be toggled as a function wrapper that simply returns a given value.\t\t\n\t\t\n\n## Install\n```bash\nnpm install typecase;\n```\n\n```javascript\nimport {type, typecase} from 'typecase';\n```\n---\n\n## .true\n```javascript\n// Returns a Boolean of the expected value match.\ntype(value).true // true | false\n```\n\n## .false\n```javascript\n// Returns a Boolean of the expected value match.\ntype(value).false // true | false\n```\n\n## .exist\n```javascript\n// Value is neither null nor undefined.\ntype(value).exist // OR !type(value).exist\n\n```\n## .empty\n```javascript\n// Value is null, undefined or an emppty string ''.\ntype(value)empty // OR !type(value).empty\n```\n## .zero\n```javascript\n// Value is null, undefined or equal to 0.\ntype(value).zero // OR !type(value).zero\n```\n\n## Types\ntypecase allows you to see types for what they are. When applicable, \nthe object wrapper is shown by the prefix 'object'. Less common type classes\n(such as elements) will return undefined if the value is falsy. All other\ntypes return boolean values.\n\n```javascript \ntype (\u003cvalue\u003e).\u003ctype\u003e // true | false\n```\n```javascript\n// Common types\n\n// String\ntype('Hello World!').string\ntype(String()).string\ntype(new String()).objectString\n\n// Number\ntype(1000).number\ntype(Number(1000)).number\ntype(new Number()).objectNumber\n\n// Boolean\ntype(true).boolean\ntype(Boolean(true)).boolean\ntype(new Boolean()).objectBoolean\n\n// Array\ntype([]).array\ntype(Array()).array\ntype(new Array()).array\n\n// Function\ntype(()=\u003e{}).function\ntype(function(){}).function\ntype(Function()).function\ntype(new Function()).function\n\n// Date, Map, WeakMap, Symbol\ntype(new Date()).objectDate\ntype(Symbol('foo')).symbol\ntype(new Map()).objectMap\ntype(new WeakMap()).objectWeakMap\n\n// RegExp\ntype(/Hello/).regExp\ntype(RegExp()).regExp\ntype(new RegExp()).regExp\n\n// Null, undefined and NaN\ntype(undefined).undefined\ntype(null).null\ntype(NaN).NaN\n\n// Objects \ntype({}).object\ntype(\u003cother objectObjects\u003e).object\n\n// Non-standard type examples\ntype(document.createElement('div')).objectHTMLDivElement    // true | undefined\ntype(document.body).objectHTMLBodyElement                   // true | undefined\n...And so on.\n```\n\n## .some()\nReturns true if at least one of the types validate as expected. If not returns false.\nIf the expected types are of an equivalent amount to the values supplied, each type\nand value will be compared in order. If not they will be compared sporadically.\n\n```javascript\ntype(value, value, value, value).some('string','objectDate', 'number', 'array')\n\ntype(value, value, value, value, value, value).some('string','objectDate')\n```\n\n## .every()\nReturns true if all types validate as expected. If not returns false.\nValues and expectedTypes must be of equal length.\n```javascript\ntype(value, value, value, value).every('string','objectDate','true','false')\n```\n\n## .is\nReveals the type as a string.\n```javascript\ntype(10000).is // \"number\"\n```\n\n## .class (TBA)\nReveals the raw object class.\n```javascript\ntype(null).class // \"[object Null]\"\ntype(NaN).class // \"[object Number]\"\n```\n## typecase() \n\n**typecase** serves as a type-checker but can be toggled as a function wrapper that simply returns a given value.\n\n```javascript\n// Check a type\nimport {type, typecase} from 'typecase'\n\n\tconst greeting = 'Hello World!';\nif(type(greeting).string){\n\tconsole.log(greeting)\n}\n\n// Return the correct type or throw an error\nconst If = typecase({\n\t\t\t\terrorHandlers:{\n\t\t\t\t\tobjectDate: function(value, type){throw new TypeError(`${value} is not of type ${type}`)}\n\t\t\t\t},\n\t\t\t\tsilence: false, // Silence callbacks\n\t\t\t\tdebug: true     // If false will parse all types without checks\n\t\t\t})\n\nconst someFunction = (value)=\u003e{\n\tvalue = 2000  // Oh no\n\treturn If(value).objectDate\n}\nconst newDate = new Date()\nsomeFunction(newDate) // Throws error\n\n\n```\n\n\n## What this library is not\n\nThis library does not check if a value is an instance of another, use the instanceof operator:\n\n```javascript \nsomeDOMElement instanceof Element // true\n```\nAlternatively (type check only)\n```javascript \n type(someDOMElement).is.includes('Element') // true\n```\n\n\nTypecase does not aim to tell you the specific \"type\" of sub-object it may contain,\nthis is usually not important since you would likely need to check for \nexisting properties, and if not then native properties will be sufficient.\n\nFor everything else kind-of type related, the native language will be sufficient.\n\n## Explanations.\n- Although `Array` is an object `'array'` is returned rather than `'objectArray'` because it is not an intended object for `Object` use unlike i.e. `new Boolean()`. The same applies to RegExp.\n\n- Although `NaN` is an invalid type-of `'number'`, because this is commonly problematic `'NaN'` is returned instead.\n- `'objectObject'` is always returned as `'object'` for simplicity.\n- `null` is returned as `\"null\"` since `typeof null // object` is a mistake.\n- `'empty'` and `'zero'` also check for non-existence.\n\n- Typecase uses the most appropriate method for checking a type to be more inlline with compiler optimisations at runtime. Despite this consideration, it's alway best to [use typeof where feasible](https://medium.com/@julienetienne/is-javascript-trash-part-1-5310ac4e20d0#b6da).\n\n\nMIT (c) 2018 Julien Etienne.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjulienetie%2Ftypecase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjulienetie%2Ftypecase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjulienetie%2Ftypecase/lists"}