{"_id":"@albud/kind","_rev":"3-eb61cd3fdadedae4070013551d1500c4","name":"@albud/kind","dist-tags":{"latest":"0.1.7"},"versions":{"0.1.5":{"name":"@albud/kind","version":"0.1.5","license":"MIT","_id":"@albud/kind@0.1.5","maintainers":[{"name":"allain","email":"allain.lalonde@gmail.com"}],"homepage":"https://github.com/allain/kind#readme","bugs":{"url":"https://github.com/allain/kind/issues"},"dist":{"shasum":"b6a00740793c1dc68839f9107280f50ae96b7c33","tarball":"https://registry.npmjs.org/@albud/kind/-/kind-0.1.5.tgz","fileCount":16,"integrity":"sha512-PpMH7UIEn4u5CLO496NHUmCzG/62JTZL67z8mglH60SY0WdpalNEl/GiErfzlTt26/ckoG7ECIewbDcfKbcpVA==","signatures":[{"sig":"MEUCIGq1O5L11NFem33plDt3RI8gnPKGVvWpsYj/dlX+2n/EAiEAjltNhSePeLi58f62bEdjTbZxjPSTs3TzpkslQ1eRyQ8=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":46327},"main":"./script/mod.js","types":"./script/mod.d.ts","module":"./esm/mod.js","exports":{".":{"import":"./esm/mod.js","require":"./script/mod.js"}},"gitHead":"12add64be636c1625bc146d004447305b42cdb27","scripts":{},"_npmUser":{"name":"allain","email":"allain.lalonde@gmail.com"},"repository":{"url":"git+https://github.com/allain/kind.git","type":"git"},"_npmVersion":"11.5.1","description":"TypeScript library for creating classes with automatic validation and type conversion","directories":{},"_nodeVersion":"24.7.0","_hasShrinkwrap":false,"devDependencies":{"@types/node":"^20.9.0"},"_npmOperationalInternal":{"tmp":"tmp/kind_0.1.5_1757436515975_0.16245172187805812","host":"s3://npm-registry-packages-npm-production"}},"0.1.6":{"name":"@albud/kind","version":"0.1.6","keywords":["typescript","validation","class","schema","type-conversion"],"author":{"name":"Allain Lalonde"},"license":"MIT","_id":"@albud/kind@0.1.6","maintainers":[{"name":"allain","email":"allain.lalonde@gmail.com"}],"homepage":"https://github.com/albud/kind#readme","bugs":{"url":"https://github.com/albud/kind/issues"},"dist":{"shasum":"8116294c8a06f8da20785eba46ee1fc416b1c5da","tarball":"https://registry.npmjs.org/@albud/kind/-/kind-0.1.6.tgz","fileCount":6,"integrity":"sha512-R35y7xtZHkHjyVgYKy0SkjbJG30V2uYx4RzBplZHbylwGEFL/izkt2qe4SiEsK7JDvsiuwIQdF4CI6jIV0XsnQ==","signatures":[{"sig":"MEUCIQDz4vBLw4Qp4/yOnOEomYU95hs2tNe1kTF4CSg9BZUHOgIgJ/HxvJI+HvELnYmnCg7easOVnMB7VBcRQ3qTKbUAiDE=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":30484},"main":"./dist/kind.js","type":"module","types":"./dist/kind.d.ts","module":"./dist/kind.js","engines":{"node":">=18.0.0"},"exports":{".":{"types":"./dist/kind.d.ts","import":"./dist/kind.js"}},"gitHead":"9606e34e4971a3ecd0406ed344ecc232d00d36ae","scripts":{"dev":"tsc --watch","test":"node --test dist/**/*.test.js","build":"tsc","pretest":"npm run build","prepublishOnly":"npm run build"},"_npmUser":{"name":"allain","email":"allain.lalonde@gmail.com"},"repository":{"url":"git+https://github.com/albud/kind.git","type":"git"},"_npmVersion":"11.5.1","description":"TypeScript friendly library for creating classes with automatic validation and type conversion","directories":{},"_nodeVersion":"24.6.0","_hasShrinkwrap":false,"devDependencies":{"chai":"^5.0.0","typescript":"^5.0.0","@types/chai":"^4.3.0","@types/node":"^20.0.0"},"_npmOperationalInternal":{"tmp":"tmp/kind_0.1.6_1757551136151_0.16172550479987202","host":"s3://npm-registry-packages-npm-production"}},"0.1.7":{"name":"@albud/kind","version":"0.1.7","description":"TypeScript friendly library for creating classes with automatic validation and type conversion","type":"module","main":"./dist/kind.js","module":"./dist/kind.js","types":"./dist/kind.d.ts","exports":{".":{"types":"./dist/kind.d.ts","import":"./dist/kind.js"}},"scripts":{"build":"tsc","prepublishOnly":"npm run build","pretest":"npm run build","test":"node --test dist/**/*.test.js","dev":"tsc --watch"},"keywords":["typescript","validation","class","schema","type-conversion"],"author":{"name":"Allain Lalonde"},"license":"MIT","devDependencies":{"@types/node":"^20.0.0","typescript":"^5.0.0","chai":"^5.0.0","@types/chai":"^4.3.0"},"engines":{"node":">=18.0.0"},"repository":{"type":"git","url":"git+https://github.com/albud/kind.git"},"homepage":"https://github.com/albud/kind#readme","bugs":{"url":"https://github.com/albud/kind/issues"},"_id":"@albud/kind@0.1.7","gitHead":"fd316b982affd27166509a00388c495d723308c2","_nodeVersion":"24.6.0","_npmVersion":"11.5.1","dist":{"integrity":"sha512-G7OFwE0aaihyUYOkGin4btOnis8JEfra64aSak/UozPgk9YQXYx8+WWcHgj6L2z/LsGzGYU2csWjJxSyV4vVhw==","shasum":"4e7875ba0e790fc0ef8b43b48ccd0e4540896606","tarball":"https://registry.npmjs.org/@albud/kind/-/kind-0.1.7.tgz","fileCount":6,"unpackedSize":30539,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQC/KLqrPA/1OUUHpayRaza6NAvr+apPxlpyCYIy5HdSWAIgHyYRBQbKQU+W6Cyrk2KlIu6PEH3i5pMqW19qPoINZPg="}]},"_npmUser":{"name":"allain","email":"allain.lalonde@gmail.com"},"directories":{},"maintainers":[{"name":"allain","email":"allain.lalonde@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/kind_0.1.7_1757900673046_0.7783387300393987"},"_hasShrinkwrap":false}},"time":{"created":"2025-09-09T16:48:35.913Z","modified":"2025-09-15T01:44:33.447Z","0.1.5":"2025-09-09T16:48:36.175Z","0.1.6":"2025-09-11T00:38:56.341Z","0.1.7":"2025-09-15T01:44:33.248Z"},"bugs":{"url":"https://github.com/albud/kind/issues"},"author":{"name":"Allain Lalonde"},"license":"MIT","homepage":"https://github.com/albud/kind#readme","keywords":["typescript","validation","class","schema","type-conversion"],"repository":{"type":"git","url":"git+https://github.com/albud/kind.git"},"description":"TypeScript friendly library for creating classes with automatic validation and type conversion","maintainers":[{"name":"allain","email":"allain.lalonde@gmail.com"}],"readme":"# @albud/kind\n\nCreate classes with automatic validation and type conversion in TypeScript/JavaScript.\n\n**Note:** `kind` is designed for constructing data-centric classes with properties and simple methods. It may not be good fit if that doesn't sound like the kinds of classes you want to construct.\n\n## Benefits\n\nThe key advantages of using `kind` over traditional class definitions:\n\n- **Boilerplate reduction** - No more repetitive constructor code\n- **Automatic validation** - Input data is validated and converted to correct types  \n- **Type safety** - Full TypeScript support with proper type inference\n\n## Basic Usage\n\nA simple example showing how to create a class with properties and methods:\n\n```typescript\nimport { kind } from \"@albud/kind\";\n\nconst Person = kind({\n  name: String,\n  age: Number,\n  get greeting() {\n    return `Hello, I'm ${this.name} and I'm ${this.age}`;\n  }\n  greet() {\n    console.log(this.greeting)\n  }\n});\n\n// Automatically validates and converts types\nconst john = new Person({ name: \"John\", age: 30 });\nconsole.log(john.name); \nconsole.log(john.age);  \nconsole.log(john.greeting)\njohn.greet()\n```\n\n## Advanced Features\n\nExplore more sophisticated patterns and capabilities:\n\n### Optional Properties\n```typescript\nimport { kind, optional } from \"@albud/kind\";\n\nconst User = kind({\n  name: String,\n  email: optional(String),\n});\n\nconst user = new User({ name: \"John\" }); // email is undefined\n```\n\n### Arrays\n```typescript\nimport { kind, array } from \"@albud/kind\";\n\nconst TodoList = kind({\n  items: array(String),\n  completed: array(Boolean),\n});\n\nconst todos = new TodoList({\n  items: [\"Task 1\", 2, true],        // [\"Task 1\", \"2\", \"true\"]\n  completed: [\"true\", 0, 1]          // [true, false, true]\n});\n```\n\n### Custom Types\n```typescript\nclass Email extends String {\n  constructor(email: string) {\n    if (!email.includes(\"@\")) {\n      throw new Error(\"Invalid email format\");\n    }\n    super(email.toLowerCase());\n  }\n}\n\nconst User = kind({\n  name: String,\n  email: Email,\n  extraEmails: array(Email),  // Arrays of custom types work too\n});\n\nconst user = new User({\n  name: \"John\",\n  email: \"John@Example.COM\",  // Converted to \"john@example.com\"\n  extraEmails: [\"admin@site.com\", \"user@site.com\"]\n});\n```\n\n### Custom Base Class\n```typescript\nclass BaseEntity {\n  id = Math.random();\n  createdAt = new Date();\n  \n  save() {\n    console.log(`Saving entity ${this.id}`);\n  }\n}\n\nconst User = kind({\n  name: String,\n  email: String,\n}, BaseEntity);\n\nconst user = new User({ name: \"John\", email: \"john@example.com\" });\nuser.save(); // Method from BaseEntity\nconsole.log(user.id); // Property from BaseEntity\n```\n\n## Value Construction\n\nHow `kind` transforms input data using constructor functions:\n\n- `String`: Converts any value to string\n- `Number`: Converts strings/booleans to numbers (throws on invalid)\n- `Boolean`: Converts strings (\"false\"/\"0\"/\"\" → false, others → true)\n- `Date`: Converts strings/numbers to Date objects\n- Custom constructors: Uses `new Constructor(value)`\n\n## Installation\n\nHow to add `kind` to your project:\n\n```bash\n# npm\nnpm install @albud/kind\n\n# yarn\nyarn add @albud/kind\n\n# pnpm\npnpm add @albud/kind\n```\n\n```typescript\nimport { kind, optional, array } from \"@albud/kind\";\n```\n\n## But Why?\n\nSee the difference between `kind` and traditional class construction:\n\nHere's what the same `Person` class looks like without `kind`:\n\n```typescript\nclass Person {\n  name: string;\n  age: number;\n\n  constructor(data: { name: string | number; age: string | number }) {\n    if (typeof data.name !== 'string') {\n      this.name = String(data.name);\n    } else {\n      this.name = data.name;\n    }\n    \n    if (typeof data.age === 'string') {\n      this.age = Number(data.age);\n      if (isNaN(this.age)) {\n        throw new Error('Invalid age');\n      }\n    } else {\n      this.age = data.age;\n    }\n  }\n\n  greet() {\n    return `Hello, I'm ${this.name} and I'm ${this.age} years old`;\n  }\n}\n```\n\nThat's 20+ lines of boilerplate for what `kind` does in 8 lines, and `kind` handles edge cases you might forget.\n","readmeFilename":"README.md"}