{"_id":"@alfarizi/convert-to-number","_rev":"5-37a5254fd83134add4d3a42c80eedc5b","name":"@alfarizi/convert-to-number","dist-tags":{"latest":"1.0.5"},"versions":{"1.0.0":{"name":"@alfarizi/convert-to-number","version":"1.0.0","keywords":["convert-to-number","javascript","typescript","convert","number"],"author":{"name":"Moh Rizal Alfarizi"},"license":"MIT","_id":"@alfarizi/convert-to-number@1.0.0","maintainers":[{"name":"alfariiizi","email":"alfariiiziiiii@gmail.com"}],"homepage":"https://github.com/alfariiizi/convert-to-number#readme","bugs":{"url":"https://github.com/alfariiizi/convert-to-number/issues"},"dist":{"shasum":"249ff6a2cd329a15bc5c1af40dc34b0e446c37ce","tarball":"https://registry.npmjs.org/@alfarizi/convert-to-number/-/convert-to-number-1.0.0.tgz","fileCount":8,"integrity":"sha512-1FjC/ZZ9u75fWu28FciUMRJl4HDIdlGQS4g6vELD3ReDPU6qeq5UigU8S6yaAQuGSRb1SFlfjlBm2DhdFyp7tQ==","signatures":[{"sig":"MEYCIQDnlUt+sLT0X9wmLCc5+kYiGRa+SNleiqj4bqUkntxcLAIhAIrKAEp3aKfD2dRTykDrOM7aEgPQPizWjlmQflkL6Gdg","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":9542},"main":"./dist/index.js","types":"./dist/index.d.ts","module":"./dist/index.mjs","gitHead":"6438addb80ec4e8a3c8e0a151a22ff236413de60","scripts":{"test":"jest","build":"tsup"},"_npmUser":{"name":"alfariiizi","email":"alfariiiziiiii@gmail.com"},"repository":{"url":"git+https://github.com/alfariiizi/convert-to-number.git","type":"git"},"_npmVersion":"10.8.2","description":"Convert any value type into number. You can also specified the fallback if the result is NaN.","directories":{},"_nodeVersion":"20.11.1","_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","tsup":"^8.3.5","ts-jest":"^29.2.5","ts-node":"^10.9.2","typescript":"^5.7.2","@types/jest":"^29.5.14"},"_npmOperationalInternal":{"tmp":"tmp/convert-to-number_1.0.0_1734841433979_0.7412288182384257","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@alfarizi/convert-to-number","version":"1.0.1","keywords":["convert-to-number","javascript","typescript","convert","number"],"author":{"name":"Moh Rizal Alfarizi"},"license":"MIT","_id":"@alfarizi/convert-to-number@1.0.1","maintainers":[{"name":"alfariiizi","email":"alfariiiziiiii@gmail.com"}],"homepage":"https://github.com/alfariiizi/convert-to-number#readme","bugs":{"url":"https://github.com/alfariiizi/convert-to-number/issues"},"dist":{"shasum":"193af7ee9311ed9cd133f383f6193be3cf9a5598","tarball":"https://registry.npmjs.org/@alfarizi/convert-to-number/-/convert-to-number-1.0.1.tgz","fileCount":9,"integrity":"sha512-wVJ/V2DGMVNYxoC5+AfFkJv+U0H//KBOluEC5Z7/v9ayT2cVfo/RsCC7vUuRzLdIiRuV2v6UR2zZsh5w2tuUAg==","signatures":[{"sig":"MEYCIQCfptxTP8Cv3X7//joUHGbDGqgQHyxHgCblk3AMybV8PgIhAP48cReXTqb26UsDoVlqbl/Ro0GTaFMaSDz+MDE+UtSh","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":12499},"main":"./dist/index.js","types":"./dist/index.d.ts","module":"./dist/index.mjs","gitHead":"64d49c305997a5497e096154238f46d24e76ed70","scripts":{"test":"jest","build":"tsup"},"_npmUser":{"name":"alfariiizi","email":"alfariiiziiiii@gmail.com"},"repository":{"url":"git+https://github.com/alfariiizi/convert-to-number.git","type":"git"},"_npmVersion":"10.8.2","description":"Convert any value type into number. You can also specified the fallback if the result is NaN.","directories":{},"_nodeVersion":"20.11.1","_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","tsup":"^8.3.5","ts-jest":"^29.2.5","ts-node":"^10.9.2","typescript":"^5.7.2","@types/jest":"^29.5.14"},"_npmOperationalInternal":{"tmp":"tmp/convert-to-number_1.0.1_1734842032121_0.08321206012608973","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"@alfarizi/convert-to-number","version":"1.0.2","keywords":["convert-to-number","javascript","typescript","convert","soft","number","array","object","string","boolean","null","undefined"],"author":{"name":"Moh Rizal Alfarizi"},"license":"MIT","_id":"@alfarizi/convert-to-number@1.0.2","maintainers":[{"name":"alfariiizi","email":"alfariiiziiiii@gmail.com"}],"homepage":"https://github.com/alfariiizi/convert-to-number#readme","bugs":{"url":"https://github.com/alfariiizi/convert-to-number/issues"},"dist":{"shasum":"ca3970da77474ae82312eee223503e5160577f43","tarball":"https://registry.npmjs.org/@alfarizi/convert-to-number/-/convert-to-number-1.0.2.tgz","fileCount":9,"integrity":"sha512-idvO3Rc8GY9zSEdD21LrmByjsmj5GOu5bA+Yn6g5FP/bE5EA4AYjVo39t3BxavIbBqIFLW9hOqaQc4YzKUu98A==","signatures":[{"sig":"MEYCIQDaJmUKezVwLZ5U38UgHwV/0108c087zPt0+aKVw24enwIhAOb2sUBQ5lHYtZNw0MIS4tc3LrpVPRcFkOcLWJ3Vw8CC","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":20021},"main":"./dist/index.js","types":"./dist/index.d.ts","module":"./dist/index.mjs","gitHead":"a57784cfdaebe03785de5af41d5b218c6d4beb85","scripts":{"test":"jest","build":"tsup"},"_npmUser":{"name":"alfariiizi","email":"alfariiiziiiii@gmail.com"},"repository":{"url":"git+https://github.com/alfariiizi/convert-to-number.git","type":"git"},"_npmVersion":"10.8.2","description":"Typesafe converter from any value type into number. You can also specified the fallback if the result is NaN.","directories":{},"_nodeVersion":"20.11.1","_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","tsup":"^8.3.5","ts-jest":"^29.2.5","ts-node":"^10.9.2","typescript":"^5.7.2","@types/jest":"^29.5.14"},"_npmOperationalInternal":{"tmp":"tmp/convert-to-number_1.0.2_1734969221455_0.9423412298127418","host":"s3://npm-registry-packages-npm-production"}},"1.0.3":{"name":"@alfarizi/convert-to-number","version":"1.0.3","keywords":["convert-to-number","javascript","typescript","convert","soft","number","array","object","string","boolean","null","undefined"],"author":{"name":"Moh Rizal Alfarizi"},"license":"MIT","_id":"@alfarizi/convert-to-number@1.0.3","maintainers":[{"name":"alfariiizi","email":"alfariiiziiiii@gmail.com"}],"homepage":"https://github.com/alfariiizi/convert-to-number#readme","bugs":{"url":"https://github.com/alfariiizi/convert-to-number/issues"},"dist":{"shasum":"78e8d73dffbda339d41b01372b28f3cc01b3140b","tarball":"https://registry.npmjs.org/@alfarizi/convert-to-number/-/convert-to-number-1.0.3.tgz","fileCount":9,"integrity":"sha512-2TZVKD56FJb6WOE2nuPVuHIu7/o+zjLuEnLXUC+ycmumE/33pLNuV6h70qp1XREH0VGvIXSDr7baUAOlLFoASQ==","signatures":[{"sig":"MEYCIQCiU2smwCz4Jd7kvAnAzJeGyRlENVSKShtmgnM+AsK4uAIhAM8vsDCG9oUeIHAKQThYqaKLc3Nh0VunTmRJLLOGQN1G","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":21263},"main":"./dist/index.js","types":"./dist/index.d.ts","module":"./dist/index.mjs","gitHead":"ddf6f663a78e67a781f2b65e7a4b17f8aa828cb1","scripts":{"test":"jest","build":"tsup"},"_npmUser":{"name":"alfariiizi","email":"alfariiiziiiii@gmail.com"},"repository":{"url":"git+https://github.com/alfariiizi/convert-to-number.git","type":"git"},"_npmVersion":"10.8.2","description":"Typesafe converter from any value type into number. You can also specified the fallback if the result is NaN.","directories":{},"_nodeVersion":"20.11.1","_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","tsup":"^8.3.5","ts-jest":"^29.2.5","ts-node":"^10.9.2","typescript":"^5.7.2","@types/jest":"^29.5.14"},"_npmOperationalInternal":{"tmp":"tmp/convert-to-number_1.0.3_1735012429467_0.051573840956317785","host":"s3://npm-registry-packages-npm-production"}},"1.0.4":{"name":"@alfarizi/convert-to-number","version":"1.0.4","keywords":["convert-to-number","javascript","typescript","convert","soft","number","array","object","string","boolean","null","undefined"],"author":{"name":"Moh Rizal Alfarizi"},"license":"MIT","_id":"@alfarizi/convert-to-number@1.0.4","maintainers":[{"name":"alfariiizi","email":"alfariiiziiiii@gmail.com"}],"homepage":"https://github.com/alfariiizi/convert-to-number#readme","bugs":{"url":"https://github.com/alfariiizi/convert-to-number/issues"},"dist":{"shasum":"90478e296bb7a803701bff78d159e996b69de3b4","tarball":"https://registry.npmjs.org/@alfarizi/convert-to-number/-/convert-to-number-1.0.4.tgz","fileCount":9,"integrity":"sha512-5KZhFyrKn9XSDmX5JuOAXTmUy63wsEh4OWDPtHiFaHKE54it3Infiqs33Q/7EVgadDKQpUOiGQ8TvSMVH0g0iQ==","signatures":[{"sig":"MEQCIGnI+DI0prKaOvHeQ7o+lEoxQEIRpyMrNnFawdHJu8gEAiAL+wEw5iW050RaY7GThkTU/fgZYX3zE9hXRyhEOaUS+w==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":21303},"main":"./dist/index.js","types":"./dist/index.d.ts","module":"./dist/index.mjs","gitHead":"870c7c61df93e18f2c123c88981d99d9a1d03c03","scripts":{"test":"jest","build":"tsup"},"_npmUser":{"name":"alfariiizi","email":"alfariiiziiiii@gmail.com"},"repository":{"url":"git+https://github.com/alfariiizi/convert-to-number.git","type":"git"},"_npmVersion":"10.8.2","description":"Typesafe converter from any value type into number. You can also specified the fallback if the result is NaN.","directories":{},"_nodeVersion":"20.11.1","_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","tsup":"^8.3.5","ts-jest":"^29.2.5","ts-node":"^10.9.2","typescript":"^5.7.2","@types/jest":"^29.5.14"},"_npmOperationalInternal":{"tmp":"tmp/convert-to-number_1.0.4_1735012514615_0.6983484858152347","host":"s3://npm-registry-packages-npm-production"}},"1.0.5":{"name":"@alfarizi/convert-to-number","version":"1.0.5","description":"Typesafe converter from any value type into number. You can also specified the fallback if the result is NaN.","main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","scripts":{"build":"tsup","test":"jest"},"repository":{"type":"git","url":"git+https://github.com/alfariiizi/convert-to-number.git"},"keywords":["convert-to-number","javascript","typescript","convert","soft","number","array","object","string","boolean","null","undefined"],"author":{"name":"Moh Rizal Alfarizi"},"license":"MIT","bugs":{"url":"https://github.com/alfariiizi/convert-to-number/issues"},"homepage":"https://github.com/alfariiizi/convert-to-number#readme","devDependencies":{"@types/jest":"^29.5.14","jest":"^29.7.0","ts-jest":"^29.2.5","ts-node":"^10.9.2","tsup":"^8.3.5","typescript":"^5.7.2"},"_id":"@alfarizi/convert-to-number@1.0.5","gitHead":"865ac4c60a90966bb3d5a884756f7cf2e1e33a93","_nodeVersion":"20.11.1","_npmVersion":"10.8.2","dist":{"integrity":"sha512-du87KOVLuMHfYZ8/Q6+RSq1pXJSK9o7YvYTAm+T2xaPedgaMCyBJPc8EiUWZcdimJKl3cBGgmkXEmzOC1I0aFA==","shasum":"42d196a0f2c94561b5f6aed367428eba8a9dd3d7","tarball":"https://registry.npmjs.org/@alfarizi/convert-to-number/-/convert-to-number-1.0.5.tgz","fileCount":9,"unpackedSize":21527,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIANjHZEDFjrwdDsqynvhYRgH4BB4qPFDbXpq77TK47C9AiEA394ehnabF+9M370FBGtW5At/NFNQ6wtTlvwl5Z7Ebs4="}]},"_npmUser":{"name":"alfariiizi","email":"alfariiiziiiii@gmail.com"},"directories":{},"maintainers":[{"name":"alfariiizi","email":"alfariiiziiiii@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/convert-to-number_1.0.5_1735013790605_0.3030491417126564"},"_hasShrinkwrap":false}},"time":{"created":"2024-12-22T04:23:53.902Z","modified":"2024-12-24T04:16:31.004Z","1.0.0":"2024-12-22T04:23:54.165Z","1.0.1":"2024-12-22T04:33:52.331Z","1.0.2":"2024-12-23T15:53:41.622Z","1.0.3":"2024-12-24T03:53:49.641Z","1.0.4":"2024-12-24T03:55:14.807Z","1.0.5":"2024-12-24T04:16:30.775Z"},"bugs":{"url":"https://github.com/alfariiizi/convert-to-number/issues"},"author":{"name":"Moh Rizal Alfarizi"},"license":"MIT","homepage":"https://github.com/alfariiizi/convert-to-number#readme","keywords":["convert-to-number","javascript","typescript","convert","soft","number","array","object","string","boolean","null","undefined"],"repository":{"type":"git","url":"git+https://github.com/alfariiizi/convert-to-number.git"},"description":"Typesafe converter from any value type into number. You can also specified the fallback if the result is NaN.","maintainers":[{"name":"alfariiizi","email":"alfariiiziiiii@gmail.com"}],"readme":"# @alfarizi/convert-to-number\n\nA TypeScript utility package for converting strings, arrays, and objects into\nnumbers, with support for nested structures. It offers both a strict conversion\n(which replaces invalid values with a fallback) and a soft conversion (which\nretains non-convertible values).\n\n## Features\n\n- Converts **string** to numbers.\n- Handles **nested arrays** and **objects**.\n- **TypeScript Support:** Fully typed for safer and predictable usage.\n- **Customizable Fallback:** Define a fallback value for unsupported\n  conversions.\n- Supports **custom fallback** values for invalid conversions.\n- Provides a **soft conversion** option where non-convertible values remain\n  unchanged.\n\n## Installation\n\nInstall the package via npm or yarn:\n\n```bash\nnpm install @alfarizi/convert-to-number\n```\n\nor\n\n```bash\nyarn add @alfarizi/convert-to-number\n```\n\n## Usage\n\n### `convertToNumber`\n\nThis function recursively converts strings, arrays, and objects to numbers. It\nreplaces non-convertible values with a fallback value (default: `0`).\n\n#### Syntax\n\n```typescript\nconvertToNumber<V, T = number>(value: V, fallback?: T): ConvertToNumberType<V, T>;\n```\n\n#### Example\n\n```typescript\nimport { convertToNumber } from \"@alfarizi/convert-to-number\";\n\nconst result = convertToNumber(\"42\");\nconsole.log(result); // 42\n\nconst resultWithFallback = convertToNumber(\"abc\", 1234);\nconsole.log(resultWithFallback); // 1234\n\nconst nestedResult = convertToNumber({\n  a: \"42\",\n  b: [\"43\", \"44\", \"abc\"],\n  c: { d: \"45\" },\n});\nconsole.log(nestedResult);\n// Output: { a: 42, b: [43, 44, 0], c: { d: 45 } }\n```\n\n### `convertToNumberSoft`\n\nThis function works similarly to `convertToNumber`, but it softens the\nconversion. If a value cannot be converted, it returns the original value\ninstead of replacing it with the fallback.\n\n#### Syntax\n\n```typescript\nconvertToNumberSoft<V>(value: V): ConvertToNumberSoftType<V>;\n```\n\n#### Example\n\n```typescript\nimport { convertToNumberSoft } from \"@alfarizi/convert-to-number\";\n\nconst result = convertToNumberSoft(\"42\");\nconsole.log(result); // 42\n\nconst resultWithInvalidValue = convertToNumberSoft(\"abc\");\nconsole.log(resultWithInvalidValue); // \"abc\"\n\nconst nestedResult = convertToNumberSoft({\n  a: \"42\",\n  b: [\"43\", \"44\", \"abc\"],\n  c: { d: \"45\" },\n});\nconsole.log(nestedResult);\n// Output: { a: 42, b: [43, 44, \"abc\"], c: { d: 45 } }\n```\n\n## API\n\n### `convertToNumber<V, T = number>(value: V, fallback?: T): ConvertToNumberType<V, T>`\n\n#### Parameters\n\n- `value` (`V`): The value to be converted to a number. It can be of any type,\n  including primitives, strings, arrays, or objects.\n- `fallback` (`T` | optional): The fallback value to return if conversion is not\n  possible. Defaults to `0` if not provided.\n\n#### Returns\n\n- `ConvertToNumberType<V, T>`: The converted number or the fallback value.\n\n## `convertToNumberSoft<V>(value: V): ConvertToNumberSoftType<V>`\n\n#### Parameters\n\n- `value` (`V`): The value to be converted to a number. It can be of any type,\n  including primitives, strings, arrays, or objects.\n\n#### Returns\n\n- `ConvertToNumberSoftType<V>`: The converted value. If the value cannot be\n  converted to a number, it will return the original value (e.g., a string that\n  can't be parsed as a number will remain as a string).\n\n## License\n\n`convert-to-number` is licensed under the MIT License. See the\n[LICENSE](LICENSE) file for details.\n\n---\n\nHappy coding!\n","readmeFilename":"README.md"}