{"id":44657998,"url":"https://github.com/tudddorrr/hefty","last_synced_at":"2026-02-14T22:25:38.169Z","repository":{"id":57262306,"uuid":"342408719","full_name":"tudddorrr/hefty","owner":"tudddorrr","description":"Easy, unopinionated and intuitive Typescript fixtures","archived":false,"fork":false,"pushed_at":"2024-08-02T14:56:51.000Z","size":217,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-27T00:49:08.411Z","etag":null,"topics":["factory","fixtures","mock","seeding","testing"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/hefty","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tudddorrr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-25T23:37:43.000Z","updated_at":"2024-08-02T14:56:54.000Z","dependencies_parsed_at":"2022-08-25T02:13:00.020Z","dependency_job_id":null,"html_url":"https://github.com/tudddorrr/hefty","commit_stats":null,"previous_names":["sekaru/hefty"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tudddorrr/hefty","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tudddorrr%2Fhefty","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tudddorrr%2Fhefty/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tudddorrr%2Fhefty/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tudddorrr%2Fhefty/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tudddorrr","download_url":"https://codeload.github.com/tudddorrr/hefty/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tudddorrr%2Fhefty/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29458457,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-14T21:29:27.764Z","status":"ssl_error","status_checked_at":"2026-02-14T21:28:11.111Z","response_time":53,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["factory","fixtures","mock","seeding","testing"],"created_at":"2026-02-14T22:25:37.668Z","updated_at":"2026-02-14T22:25:38.162Z","avatar_url":"https://github.com/tudddorrr.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hefty\nEasy, unopinionated and intuitive Typescript fixtures.\n\n## Installation\n`npm install hefty --save-dev`\n\n## Usage\nHefty lets you create factories, chain multiple states and override those states too. Check out the tests for more examples.\n\n### Create a Factory\nFactories are made up of entities with one or more states applied to them. States are called with the same params you get with `Array.map()`.\n\n```\n// User.ts\nclass User {\n  email: string\n  emailConfirmed: boolean\n  onboarded: boolean\n}\n\n// UserFactory.ts\nimport { Factory } from 'hefty'\n\nclass UserFactory extends Factory\u003cUser\u003e {\n  constructor() {\n    super(User)\n  }\n\n  hasConfirmed(): this {\n    return this.state(() =\u003e ({\n      emailConfirmed: true\n    }))\n  }\n\n  hasOnboarded(): this {\n    return this.state(() =\u003e ({\n      onboarded: true\n    }))\n  }\n}\n```\n\n### Create some users\n```\nconst factory = new UserFactory()\n\nconst user1: User = await factory.one()\n// -\u003e emailConfirmed = false\n\nconst user2: User = await factory.emailConfirmed().one()\n// -\u003e emailConfirmed = true\n\nconst user3: User = await factory.emailConfirmed().onboarded().one()\n// -\u003e emailConfirmed = true, onboarded = true\n\nconst user4: User = await factory.emailConfirmed().state(() =\u003e ({ email: hello@web.site })).one()\n// -\u003e emailConfirmed = true, email = hello@web.site\n\nconst users: User[] = await factory.emailConfirmed().many(3)\n// -\u003e generates 3 users with emailConfirmed = true\n```\n\nState functions defined in the factory and `state()` can be chained as many times as you like in any order. They'll all be applied sequentially when `one()` or `many()` is called.\n\n### Factories with default states\nFactories can implement a `definition()` function that is called before any other states are applied.\n\n```\nexport default class UserFactory extends Factory\u003cUser\u003e {\n  constructor() {\n    super(User)\n  }\n\n  protected definition(): void {\n    this.state(() =\u003e {\n      createdAt: 'today',\n      emailConfirmed: true\n    })\n  }\n\n  onboarded(): this {\n    return this.state(() =\u003e ({\n      onboarded: true\n    }))\n  }\n\n  emailConfirmed(): this {\n    return this.state(() =\u003e ({\n      emailConfirmed: true\n    }))\n  }\n}\n\nconst factory = await new UserFactory().one()\n// =\u003e createdAt = today, emailConfirmed: true \n```\n\n### Promises\nHefty will automatically resolve any promise-based `state()` callbacks.\n\n```\nexport default class UserFactory extends Factory\u003cUser\u003e {\n  constructor() {\n    super(User)\n  }\n\n  protected definition(): void {\n    this.state(async () =\u003e ({\n      password: await bcrypt.hash('password', 10)\n    }))\n  }\n}\n```\n\n### Constructors\nYou can pass constructor params to the `construct()` function. Entities will be initialised with these params before the definition is applied.\n\n```\n// User.ts\nclass User {\n  email: string\n\n  constructor(email: string) {\n    this.email = email\n  }\n}\n\n// User.test.ts\nconst email = 'hello@mail.com'\nexpect((await new UserFactory().construct(email).one()).email).toBe(email)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftudddorrr%2Fhefty","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftudddorrr%2Fhefty","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftudddorrr%2Fhefty/lists"}