{"name":"@putout/plugin-types","version":"6.2.0","keywords":["putout","putout-plugin","plugin","types"],"author":{"url":"https://github.com/coderaiser","name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"license":"MIT","_id":"@putout/plugin-types@6.2.0","homepage":"https://github.com/coderaiser/putout/tree/master/packages/plugin-types#readme","bugs":{"url":"https://github.com/coderaiser/putout/issues"},"tag":false,"dist":{"shasum":"bdfc7ade06e0f5558f99ef8d336633f38300b111","tarball":"http://registry-npm.ywwl.com/@putout/plugin-types/download/@putout/plugin-types-6.2.0.tgz","fileCount":11,"integrity":"sha512-gj2QjGIVlCs+4Vd8rzQd9lZbWxismwWkJdRAIgEgXpJrc+ZIyCIufoFK9vyxQeHzM8S53FRpy64G6U0JNRu5GQ==","signatures":[{"sig":"MEUCIBHBF0grraxfb6pR2bojcu+XNop7HetPRcOLtkgBr5DeAiEAghtAZ2IHp9070q3+WFVwWoxNzSJ/12gdsJh14qXIkjw=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":14680,"size":4742,"noattachment":false,"key":"/@putout/plugin-types/-/@putout/plugin-types-6.2.0.tgz"},"main":"lib/index.js","type":"commonjs","engines":{"node":">=18"},"gitHead":"8568d2adc562c6abbcb6ce7b65f58fe3dbccceaf","release":false,"scripts":{"lint":"madrun lint","test":"madrun test","report":"madrun report","coverage":"madrun coverage","fix:lint":"madrun fix:lint","fresh:lint":"madrun fresh:lint","lint:fresh":"madrun lint:fresh","watch:test":"madrun watch:test"},"_npmUser":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"changelog":false,"repository":{"url":"git+https://github.com/coderaiser/putout.git","type":"git"},"_npmVersion":"10.9.0","description":"🐊Putout plugin adds ability to transform code related to types assertions","directories":{},"_nodeVersion":"22.13.0","dependencies":{},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"c8":"^10.0.0","lerna":"^6.0.1","eslint":"^9.0.0","madrun":"^10.0.0","montag":"^1.2.1","nodemon":"^3.0.1","@putout/test":"^11.0.0","eslint-plugin-n":"^17.0.0","eslint-plugin-putout":"^23.0.0","@putout/plugin-putout":"*"},"peerDependencies":{"putout":">=37"},"_npmOperationalInternal":{"tmp":"tmp/plugin-types_6.2.0_1737390590356_0.3908150534493944","host":"s3://npm-registry-packages-npm-production"},"readme":"# @putout/plugin-types [![NPM version][NPMIMGURL]][NPMURL]\n\n[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-types.svg?style=flat&longCache=true\n[NPMURL]: https://npmjs.org/package/@putout/plugin-types \"npm\"\n\n🐊[**Putout**](https://github.com/coderaiser/putout) plugin adds ability to help with transforming code related to types.\n\n## Install\n\n```\nnpm i putout @putout/plugin-types -D\n```\n\n## Rules\n\n- ✅ [apply-is-array](#apply-is-array);\n- ✅ [convert-typeof-to-is-type](#convert-typeof-to-is-type);\n- ✅ [declare](#declare);\n- ✅ [remove-double-negations](#remove-double-negations);\n- ✅ [remove-useless-conversion](#remove-useless-conversion);\n- ✅ [remove-useless-constructor](#remove-useless-constructor);\n- ✅ [remove-useless-typeof](#remove-useless-typeof);\n\n## Config\n\n```json\n{\n    \"rules\": {\n        \"types/declare\": \"on\",\n        \"types/convert-typeof-to-istype\": \"on\",\n        \"types/remove-useless-conversion\": \"on\",\n        \"types/remove-useless-constructor\": \"on\",\n        \"types/remove-double-negations\": \"on\",\n        \"types/remove-useless-typeof\": \"on\",\n        \"types/apply-is-array\": \"on\"\n    }\n}\n```\n\n## declare\n\nBased on [`@putout/operator-declare`](https://github.com/coderaiser/putout/tree/master/packages/operator-declare#putoutoperator-declare-).\nSupported assertions:\n\n- `isString`;\n- `isEmptyString`;\n- `isNumber`;\n- `isNumberLike` - checks if `a` can be convert to `Number` from `String`;\n- `isFn`;\n- `isBool`;\n- `isObject`;\n- `isUndefined`;\n- `isSymbol`;\n- `isNull`;\n- `isBigInt`;\n- `isArray`;\n- `isEmptyArray`;\n- `isError`;\n\n### ❌ Example of incorrect code\n\n```js\nisString('hello');\nisNumber('a' - 5);\n```\n\n### ✅ Example of correct code\n\n```js\nconst isString = (a) => typeof a === 'string';\nconst isNumber = (a) => !Number.isNaN(a) && typeof a === 'number';\n\nisString('hello');\n\nisNumber('a' - 5);\n```\n\nWhen you want to skip some declaration use `dismiss`:\n\n```json\n{\n    \"rules\": {\n        \"types/declare\": [\"on\", {\n            \"dismiss\": [\"isString\"]\n        }]\n    }\n}\n```\n\n## convert-typeof-to-is-type\n\n> The `typeof` operator returns a string indicating the type of the unevaluated operand.\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof)\n\n### ❌ Example of incorrect code\n\n```js\nif (typeof a === 'boolean')\n    return x;\n```\n\n### ✅ Example of correct code\n\n```js\nconst isBool = (a) => typeof a === 'boolean';\n\nif (isBool(a))\n    return x;\n```\n\n## remove-useless-conversion\n\n### ❌ Example of incorrect code\n\n```js\nconst a = !![1].includes(1);\nconst b = Boolean([1].includes(1));\n```\n\n### ✅ Example of correct code\n\n```js\nconst a = [1].includes(1);\n```\n\n## remove-useless-constructor\n\n> Wrapper classes have surprising behaviour, such as `new Boolean(false)` evaluating to `true`.\n>\n> (c) [Google TypeScript Style Guide](https://google.github.io/styleguide/tsguide.html#primitive-types-wrapper-classes)\n\n🐊[**Putout**](https://github.com/coderaiser/putout) plugin adds ability to remove useless `constructor`. Use with [`new/remove-useless`](https://github.com/coderaiser/putout/tree/master/packages/plugin-new#readme).\n\n### ❌ Example of incorrect code\n\n```js\nconst s = String('hello');\nconst b = Boolean(false);\nconst n = Number(5);\n```\n\n### ✅ Example of correct code\n\n```js\nconst s = 'hello';\nconst b = false;\nconst n = 5;\n```\n\n## remove-double-negations\n\n> It is possible to use a couple of **NOT** operators (`!!`) in series to explicitly force the conversion of any value to the corresponding boolean primitive. The conversion is based on the \"truthyness\" or \"falsyness\" of the value.\n>\n> The same conversion can be done through the `Boolean` function.\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_NOT)\n\n### ❌ Example of incorrect code\n\n```js\nif (!!a)\n    console.log('hi');\n```\n\n### ✅ Example of correct code\n\n```js\nif (a)\n    console.log('hi');\n```\n\n## remove-useless-typeof\n\n> The `typeof` operator returns a string indicating the type of the unevaluated operand.\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof)\n\n### ❌ Example of incorrect code\n\n```js\ntypeof typeof 'hello';\n```\n\n### ✅ Example of correct code\n\n```js\ntypeof 'hello';\n```\n\n## apply-is-array\n\n> The `Array.isArray()` method determines whether the passed value is an `Array`.\n> When checking for `Array` instance, `Array.isArray()` is preferred over `instanceof` because it works through `iframes`.\n\n### ❌ Example of incorrect code\n\n```js\nx instanceof Array;\n```\n\n### ✅ Example of correct code\n\n```js\nconst {isArray} = Array;\nisArray(x);\n```\n\nIn case of using `inline` option:\n\n```json\n{\n    \"rules\": {\n        \"types/apply-is-array\": [\"on\", {\n            \"inline\": true\n        }]\n    }\n}\n```\n\n`Array.isArray` will be inlined:\n\n```js\nArray.isArray(x);\n```\n\n## License\n\nMIT\n\n## Comparison\n\nLinter | Rule | Fix\n--------|-------|------------|\n🐊 **Putout** | [`types`](https://github.com/coderaiser/putout/tree/master/packages/plugin-types#readme)| ✅\n⏣ **ESLint** | [`no-implicit-coercion`](https://eslint.org/docs/rules/no-implicit-coercion) | ✅\n\n## License\n\nMIT\n","publish_time":1737390590525,"maintainers":[{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"}],"_cnpm_publish_time":1737390590525,"dist-tags":{"latest":"10.6.2"}}