{"bugs":{"url":"https://github.com/achrinza/strong-type/issues"},"dist":{"shasum":"9f6b4c14affb0503af7d335eb53db23fead2b70b","tarball":"https://registry.npmjs.org/@achrinza/strong-type/-/strong-type-0.1.12.tgz","fileCount":5,"integrity":"sha512-WfYUflj34GBDt73GgPTm6CXS9KycNPCh+MOQpJyYNQLomRTKurSsu5bvnIVcY7eYu6H1x1+NCYxgM34XzA56nA==","signatures":[{"sig":"MEQCIBrAhDKegZ7mI0uoj2648zjucUy1Ax03HfIGJfg7WC6PAiAHJs+irG1QtcHubbhmOvQSs5WaHQ7Il/HgRpPAh5+Qvg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":24114},"main":"index.js","name":"@achrinza/strong-type","type":"module","author":{"name":"Brandon Nozaki Miller"},"readme":"# @achrinza/strong-type\n\nType checking module for anywhere javascript can run ES6 modules. This includes node, electron and the browsers. Fully isomorphic.\n\nnpm @achrinza/strong-type info :  [See npm trends and stats for @achrinza/strong-type](http://npm-stat.com/charts.html?package=@achrinza/strong-type&author=&from=&to=)  \n![@achrinza/strong-type npm version](https://img.shields.io/npm/v/@achrinza/strong-type.svg) ![supported node version for @achrinza/strong-type](https://img.shields.io/node/v/@achrinza/strong-type.svg) ![total npm downloads for @achrinza/strong-type](https://img.shields.io/npm/dt/@achrinza/strong-type.svg) ![monthly npm downloads for @achrinza/strong-type](https://img.shields.io/npm/dm/@achrinza/strong-type.svg) ![npm licence for @achrinza/strong-type](https://img.shields.io/npm/l/@achrinza/strong-type.svg)\n\n` npm install --save @achrinza/strong-type `  \n\n[![RIAEvangelist](https://avatars3.githubusercontent.com/u/369041?v=3&s=100)](https://github.com/RIAEvangelist)\n\nGitHub info :  \n[![@achrinza/strong-type GitHub Release](https://img.shields.io/github/release/achrinza/strong-type.svg) ![GitHub license @achrinza/strong-type license](https://img.shields.io/github/license/achrinza/strong-type.svg) ![open issues for @achrinza/strong-type on GitHub](https://img.shields.io/github/issues/achrinza/strong-type.svg)](http://riaevangelist.github.io/@achrinza/strong-type/)\n\n\nBuild Info :  \nTravis CI (linux,windows & Mac) : [![Build Status](https://travis-ci.org/RIAEvangelist/strong-test.svg?branch=main)](https://travis-ci.org/RIAEvangelist/strong-test)\n\n## What does @achrinza/strong-type do?\n`@achrinza/strong-type` allows easy type enforcement for all JS types objects and classes. It is also extensible and provides simple to use type checks for your own custom classes and types should you want to use them.\n\n## Example | strict vs. non-strict\n\nUsing `strict` and `non-strict` modes. By default `@achrinza/strong-type` runs `strict` and will `throw` a verbose err you can handle and use if the check fails, or return true if it passes.\n\nTo use `non-strict` mode, simply pass `false` to the constructor. In this mode, `@achrinza/strong-type` will return `false` instead of throwing when the check fails, and will still return `true` when it passes.\n\n\n#### strict\n```javascript \nimport Is from '@achrinza/strong-type';\n\n//strict\nconst is = new Is;\nconst is = new Is();\nconst is = new Is(true);\n\n//throws\nis.string(1);\n```\n\n#### non-strict\n```javascript\nimport Is from '@achrinza/strong-type';\n\n//non-strict\nconst is = new Is(false);\n\n//returns false\nis.string(1);\n\n```\n\n## Example | Basic type checking\n\n`@achrinza/strong-type` is intended to be very simple to use.\n\n```javascript \nimport Is from '@achrinza/strong-type';\n\n//strict\nconst is = new Is;\n\nfunction strongTypeRequired(aNumber,aString,anAsyncFunction){\n    is.number(aNumber);\n    is.string(aString);\n    is.asyncFunction(anAsyncFunction);\n}\n\n\n//this will throw because we do not pass an async Function, but rather a normal function.\nstrongTypeRequired(1,'a',function(){})\n\n\n```\n#### browser\n![Basic Type Checking Example Web](https://raw.githubusercontent.com/achrinza/strong-type/main/docs/img/basicExampleWeb.PNG)\n\n#### node\n![Basic Type Checking Example Node](https://raw.githubusercontent.com/achrinza/strong-type/main/docs/img/basicExampleNode.PNG)\n\n## Example | Generator type checking\n\nGenerators are notoriously confusing to type check for many devs. This is why we chose to use them as an example.\n\n```javascript \nimport Is from '@achrinza/strong-type';\n\n//strict\nconst is = new Is;\n\n//empty generator for this example's sake\nfunction* myGenFunc(){};\nconst myGen=myGenFunc();\n\n//we'll show async as well\nasync function* myAsyncGenFunc(){}\nconst myAsyncGen=myAsyncGenFunc();\n\n//empty function\nfunction myFunc(){};\n\n//will pass and allow contunue\nis.generator(myGen);\n\n/*\nwill fail because a generatorFunction is a \nGeneratorFunction, not a Generator\n*/\ntry{\n    is.generator(myGenFunc);\n}catch(err){\n    console.log(err);\n}\n\n//will pass and allow contunue\nis.generatorFunction(myGenFunc);\n\n//will fail because a function is not a generatorFunction\ntry{\n    is.generatorFunction(myFunc);\n}catch(err){\n    console.log(err);\n}\n\n/*\nwill fail because this is @achrinza/strong-type, a \ngeneratorFunction is explicitly a GeneratorFunction,\nand not a Function\n*/\ntry{\n    is.function(myGenFunc);\n}catch(err){\n    console.log(err);\n}\n\n//will fail because a function is not a generatorFunction\ntry{\n    is.generatorFunction(myFunc);\n}catch(err){\n    console.log(err);\n}\n\n//will pass and allow contunue\nis.asyncGeneratorFunction(myAsyncGenFunc);\n\n//will pass and allow contunue\nis.asyncGenerator(myAsyncGen);\n\n/*\nwill fail becase @achrinza/strong-type \nasyncGenerators and generators are explicitly different\nthis is the same for generatorFunctions and functions\n*/\ntry{\n    is.asyncGenerator(myGen);\n}catch(err){\n    console.log(err);\n}\n\ntry{\n    is.generator(myAsyncGen);\n}catch(err){\n    console.log(err);\n}\n\n\n```\n\n#### browser\n![Generator Type Checking Example Web](https://raw.githubusercontent.com/achrinza/strong-type/main/docs/img/generatorExampleWeb.PNG)\n\n#### node\n![Generator Type Checking Example Node](https://raw.githubusercontent.com/achrinza/strong-type/main/docs/img/generatorExampleNode.PNG)\n\n## Date example\n\n```javascript \nimport Is from '@achrinza/strong-type';\n\nconst is = new Is;\n\n//returns true\nis.date(new Date()); \n\n//throws in strict or returns false in non-strict\nis.date(1975);\n\n```\n\n## isNaN() vs is.NaN()\n\nJavascripts types are weak by nature, so the built in `isNaN()` function returns true for anything that not a number, but `is.NaN()` only returns true if it is explicitly passed `NaN`.\n\n```js \nimport Is from '@achrinza/strong-type';\n\nconst is = new Is;\n\n//built in JS isNaN\n//returns false\nisNaN(1);\n\n//all return true\nisNaN(NaN);\nisNaN(undefined);\nisNaN('a'); \n\n//@achrinza/strong-type is.NaN all return false in non-strict mode,\n//or throw in default strict mode\nis.NaN(1);\nis.NaN(undefined);\nis.NaN('a');\n\n//in @achrinza/strong-type only this returns true\nis.NaN(NaN);\n\n```\n\n#### browser\n![Date Type Checking Example Web](https://raw.githubusercontent.com/achrinza/strong-type/main/docs/img/dateExampleWeb.PNG)\n\n#### node\n![Date Type Checking Example Node](https://raw.githubusercontent.com/achrinza/strong-type/main/docs/img/dateExampleNode.PNG)\n\n\n\n## Running the browser and node type support examples\nrun `npm i` in the root dir of this module to make sure you get the devDependencies installed.\n\n#### node example :  \n`npm run nodeExample` The whole screen should be green as all of the types are supported in node.\n\n#### browser examples and tests\n`npm start`  \nthis will spin up a `node-http-server` in this modules root on port 8000. The browser examples are in the  `./example/web/` folder, and the tests are in `./test/`. You can see them by going to this local address : [http://localhost:8000/](http://localhost:8000/example/web/index.html)\n\nChrome, Opera, and Edge support all the types so all rows will be green.\n\nYou will see some red rows in Firefox as it does not yet support all types. The unsupported types will throw type errors when checked/validated.\n\n#### Digital Ocean Static App\n\nWe use the free Digital Ocean Static Apps to host a version of the local server. It is exactly the same as if you ran `npm start` on your machine. You can also use this like a CDN as it automatically rebuilds from main/master each time the branch is updated. [@achrinza/strong-type CDN home](https://@achrinza/strong-type-hiprj.ondigitalocean.app/) : https://@achrinza/strong-type-hiprj.ondigitalocean.app/\n\n## Type check methods \n\nAll of these methods take just one arg, the `value` to check. \n\n|Most Common Type Methods|args|\n|-|-|\n|`is.globalThis`|`value`|\n|`is.array`|`value`|\n|`is.bigint`|`value`|\n|`is.boolean`|`value`|\n|`is.date`|`value`|\n|`is.finite`|`value`|\n|`is.generator`|`value`|\n|`is.asyncGenerator`|`value`|\n|`is.infinity`|`value`|\n|`is.map`|`value`|\n|`is.NaN`|`value`|\n|`is.null`|`value`|\n|`is.number`|`value`|\n|`is.object`|`value`|\n|`is.promise`|`value`|\n|`is.regExp`|`value`|\n|`is.set`|`value`|\n|`is.string`|`value`|\n|`is.symbol`|`value`|\n|`is.undefined`|`value`|\n|`is.weakMap`|`value`|\n|`is.weakSet`|`value`|\n\n|Function Type Methods|args|\n|-|-|\n|`is.function`|`value`|\n|`is.asyncFunction`|`value`|\n|`is.generatorFunction`|`value`|\n|`is.asyncGeneratorFunction`|`value`|\n\n|Error Type Methods|args|\n|-|-|\n|`is.error`|`value`|\n|`is.evalError`|`value`|\n|`is.rangeError`|`value`|\n|`is.referenceError`|`value`|\n|`is.syntaxError`|`value`|\n|`is.typeError`|`value`|\n|`is.URIError`|`value`|\n\n|Buffer/Typed Array Type Methods|args|\n|-|-|\n|`is.arrayBuffer`|`value`|\n|`is.dataView`|`value`|\n|`is.sharedArrayBuffer`|`value`|\n|`is.bigInt64Array`|`value`|\n|`is.bigUint64Array`|`value`|\n|`is.float32Array`|`value`|\n|`is.float64Array`|`value`|\n|`is.int8Array`|`value`|\n|`is.int16Array`|`value`|\n|`is.int32Array`|`value`|\n|`is.uint8Array`|`value`|\n|`is.uint8ClampedArray`|`value`|\n|`is.uint16Array`|`value`|\n|`is.uint32Array`|`value`|\n\n|Intl Type Methods|args|\n|-|-|\n|`is.intlDateTimeFormat`|`value`|\n|`is.intlCollator`|`value`|\n|`is.intlDisplayNames`|`value`|\n|`is.intlListFormat`|`value`|\n|`is.intlLocale`|`value`|\n|`is.intlNumberFormat`|`value`|\n|`is.intlPluralRules`|`value`|\n|`is.intlRelativeTimeFormat`|`value`|\n\n|Garbage Collection Type Methods|args|\n|-|-|\n|`is.finalizationRegistry`|`value`|\n|`is.weakRef`|`value`|\n\n## Core methods \n\nYou can use these to directly check your own types / classes Or extend the Is class to add your own methods in which you use these for checking more types, especially custom types and classes.\n\n|Method|args|description|\n|-|-|-|\n|`is.throw`|`valueType`, `expectedType`| this will use the valueType and expectedValueType to create and throw a new `TypeError` |\n|`is.typeCheck`|`value`, `type`| this will check the javascript spec types returned from `typeof`. So the `type` arg would be a string of `'string'`, `'boolean'`, `'number'`, `'object'`, `'undefined'`, `'bigint'` etc. |\n|`is.instanceCheck`|`value`=`new Fake`, `constructor`=`FakeCore`| The core defaults the args to a `Fake` instance and the `FakeCore` class. This allows unsupported js spec types to fail as expected with a `TypeError` instead of a `Reference` or other Error (see the `./example/web/` example in firefox which is missing some support for `Intl` classes). This method compares `value` with the `constructor` to insure the value is an `instanceof` the constructor. |\n|`is.symbolStringCheck`|`value`, `type`| This can be used to check the `Symbol.toStringTag` it works on all types, but in the core we only use it to check `generator`, `GeneratorFunction`, `async function`, and `async GeneratorFunction` as these have no other way to check their type. A generator ***for example*** has a type of `[object generator]` this way. So you pass in an expected `generator` as `value` and the string `'generator'` as the type, and we handle the rest including lowercasing everything to insure cross browser and platform checking |\n|`is.compare`|`value`, `targetValue`, `typeName`| this will do an explicit compare on the `value` and `targetValue`. In the core, we only use this for JS primitives/constants that have no other way to check such as `Infinity` and `globalThis`. The type name is the string representation of the class type, or a very explicit error string as the only place this arg is ever used is when the `compare` results in a `throws`. |\n\n## Extending the Is class for your own Types\n\nIf you are using type checking on your own types in production, its probably wise for yout to just go ahead and extend the module rather than calling the more cumbersome `Core Methods` many times.\n\n#### custom Pizza type\n```javascript\n//custom class type constructor\nclass Pizza{\n    constructor(topping){\n        this.eat=true;\n    }\n}\n\nexport {default:Pizza, Pizza}\n```\n\n#### extension\n```javascript\nimport Is from '@achrinza/strong-type';\nimport Pizza from 'my-delicious-pizza';\n\nclass IsMy extends Is{\n    //custom pizza type\n    pizza(value){\n        return this.instanceCheck(value,Pizza);\n    }\n}\n\nexport={default:IsMy, IsMy};\n```\n\n#### test\n```javascript\nimport IsMy from 'my-delicious-typechecks';\nimport Pizza from 'my-delicious-pizza';\n\nconst is=new IsMy;\n\n//will throw because 42 is not a Pizza Type\n//and \nis.pizza(42)\n\n```\n\n#### browser\n![Pizza Type Checking Example Web](https://raw.githubusercontent.com/achrinza/strong-type/main/docs/img/pizzaExampleWeb.PNG)\n\n#### node\n![Pizza Type Checking Example Node](https://raw.githubusercontent.com/achrinza/strong-type/main/docs/img/pizzaExampleNode.PNG)\n\n","engines":{"node":"12 || 13 || 14 || 15 || 16 || 17 || 18 || 19 || 20"},"gitHead":"885cd3d926b364664b0fae466cba33b8b7b84140","license":"MIT","scripts":{"test":"npm run emulate && node ./test/CI.js","start":"npm run emulate && node-http-server port=8000 verbose=true","emulate":"copyfiles -V \"./!(node_modules)/*\" \"./**!(node_modules)\"  \"./example/node_modules/@achrinza/strong-type/\" && copyfiles -V \"./node_modules/**/*\" \"./example/\" && copyfiles -V \"./!(node_modules)/*\" \"./**!(node_modules)\"  \"./test/node_modules/@achrinza/strong-type/\" && copyfiles -V \"./node_modules/**/*\" \"./test/\"","nodeExample":"node ./example/node/typecheck.js"},"_npmUser":{"name":"achrinza","email":"Vn7WbcdkHEmkHHpPCoKf@achrinza.com"},"homepage":"https://github.com/achrinza/strong-type#readme","keywords":["strong","type","validation","validate","check","checking"],"repository":{"url":"git+https://github.com/achrinza/strong-type.git","type":"git"},"_npmVersion":"9.8.1","description":"allows easy type enforcement for all JS types objects and classes. it is also extensible and provides simple to use type checks for your own custom classes and types","directories":{"example":"example"},"maintainers":[{"name":"achrinza","email":"Vn7WbcdkHEmkHHpPCoKf@achrinza.com"}],"_nodeVersion":"18.18.1","publishConfig":{"tag":"v0-latest","access":"public"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"copyfiles":"2.4.1","node-http-server":"8.1.5","@node-ipc/vanilla-test":"1.4.14"},"_npmOperationalInternal":{"tmp":"tmp/strong-type_0.1.12_1698201202367_0.2905693289451756","host":"s3://npm-registry-packages"},"_id":"@achrinza/strong-type@0.1.12","version":"0.1.12"}