{"_id":"@akiroz/typesafe-csv","name":"@akiroz/typesafe-csv","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@akiroz/typesafe-csv","version":"0.1.0","description":"Typesafe CSV (de)serialization for arbitarary objects","license":"MIT","homepage":"https://github.com/akiroz/typesafe-csv","main":"/dist/index.js","scripts":{"prepublish":"tsc","lint":"biome check --write --no-errors-on-unmatched --files-ignore-unknown=true","test":"node -r ts-node/register --test test/*"},"dependencies":{"dlv":"^1.1.3","dset":"^3.1.4","papaparse":"^5.5.3","zod":"^4.1.13"},"devDependencies":{"@biomejs/biome":"^2.3.8","@types/dlv":"^1.1.5","@types/papaparse":"^5.5.0","lefthook":"^2.0.4","ts-node":"^10.9.2","typescript":"^5.9.3"},"engines":{"node":">= 24"},"volta":{"node":"24.2.0"},"licenseText":"MIT License\n\nCopyright (c) 2025 akiroz\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"@akiroz/typesafe-csv@0.1.0","dist":{"shasum":"c052c534f71e8844dce4d4d17a6746e77d0371b0","integrity":"sha512-gVQhBPAWlweVzWWecSeDbcT0wyE+CejLAPsA6ZT7vYRmmT9h9XVDObzFk3zQAV69sguGVOrJH8INUNEdm+cBTA==","tarball":"https://registry.npmjs.org/@akiroz/typesafe-csv/-/typesafe-csv-0.1.0.tgz","fileCount":8,"unpackedSize":9352,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDbomE1mI23kTqLhJ4W4HtuVpKOyfdZMj5TUOiavivSkAIgLR8M+05Yzj6VIucgn06fCHKORZBpQHvsl+0FCZRMTqY="}]},"_npmUser":{"name":"akiroz","email":"npm@akiroz.life"},"directories":{},"maintainers":[{"name":"akiroz","email":"npm@akiroz.life"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/typesafe-csv_0.1.0_1764260518210_0.17280581008037577"},"_hasShrinkwrap":false}},"time":{"created":"2025-11-27T16:21:58.105Z","0.1.0":"2025-11-27T16:21:58.396Z","modified":"2025-11-27T16:21:58.695Z"},"maintainers":[{"name":"akiroz","email":"npm@akiroz.life"}],"description":"Typesafe CSV (de)serialization for arbitarary objects","homepage":"https://github.com/akiroz/typesafe-csv","license":"MIT","readme":"# Typesafe CSV\n\nAn opinionated typesafe CSV serialization library for arbitarary objects leverging [Papaparse][] and [Zod][]\n\n## Getting Started\n\nCsvSerializer takes a column schema in the form of `[CSV Header, Object Keypath, ZodType]`\n\nZod 4.1's [codec][] feature can be used to control serialization of non-string types where:\n- decode: CSV -> Object\n- encode: Object -> CSV\n\n```ts\nimport { z } from 'zod';\nimport { CsvSerializer } from '@akiroz/typesafe-csv';\n\nconst serializer = new CsvSerializer([\n    ['ID', 'id', z.string().min(1)],\n    ['Status', 'status', z.enum(['active', 'inactive']).optional()],\n    ['Is Admin', 'isAdmin', z.stringbool().optional()],\n    [\n        'Created At',\n        'meta.createdAt',\n        z\n            .codec(z.string(), z.date(), {\n                decode: (s) => new Date(s),\n                encode: (d) => d.toISOString().split('T')[0],\n            })\n            .optional(),\n    ],\n    [\n        'Score',\n        'meta.scores.primary',\n        z\n            .codec(z.string().regex(/^\\d+$/), z.number().int(), {\n                decode: (s) => Number(s),\n                encode: (n) => String(n),\n            })\n            .optional(),\n    ],\n] as const);\n\nconst data = [\n    {\n        id: '201',\n        status: 'inactive' as const,\n        isAdmin: false,\n        meta: {\n            createdAt: new Date('2023-12-25'),\n            scores: { primary: 100 },\n        },\n    },\n    {\n        id: '202',\n        // status is undefined\n        isAdmin: true,\n        meta: {\n            createdAt: new Date('2024-01-01'),\n            scores: { primary: 50 },\n        },\n    },\n];\n\nconst csvStr = serializer.export(data);\n\nconst data2 = serializer.import(csvStr);\n```\n\n| ID  | Status   | Is Admin | Created At | Score |\n|-----|----------|----------|------------|-------|\n| 201 | inactive | false    | 2023-12-25 | 100   |\n| 202 |          | true     | 2024-01-01 | 50    |\n\nEmpty values in CSV are converted to `undefined` and nullish JS values are serialized to an empty cell.\n\n## CSV Serialization Config\n\nThis library is simply a wrapper around [Papaparse][], the constructor takes a 2nd argument where Papaparse config can be specified:\n\n```ts\nconst tsvSerializer = new CsvSerializer([/* ... */], {\n    parse: {\n        delimiter: '\\t'\n    },\n    unparse: {\n        delimiter: '\\t'\n    }\n});\n```\n\n[Papaparse]: https://www.papaparse.com/\n[Zod]: https://zod.dev/\n[codec]: https://zod.dev/codecs","readmeFilename":"README.md","_rev":"1-d82bb078c8645f1742cfdb097c819708"}