{"id":21713928,"url":"https://github.com/cytle/faker-ts","last_synced_at":"2025-04-12T19:06:03.635Z","repository":{"id":42105855,"uuid":"194484305","full_name":"cytle/faker-ts","owner":"cytle","description":"Mock data from TypeScript","archived":false,"fork":false,"pushed_at":"2022-04-12T23:15:13.000Z","size":211,"stargazers_count":32,"open_issues_count":4,"forks_count":7,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-10T16:04:52.273Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/cytle.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":"2019-06-30T06:42:58.000Z","updated_at":"2024-03-18T07:55:57.000Z","dependencies_parsed_at":"2022-08-12T06:04:51.971Z","dependency_job_id":null,"html_url":"https://github.com/cytle/faker-ts","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cytle%2Ffaker-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cytle%2Ffaker-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cytle%2Ffaker-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cytle%2Ffaker-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cytle","download_url":"https://codeload.github.com/cytle/faker-ts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226421288,"owners_count":17622387,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-11-26T00:28:48.119Z","updated_at":"2024-11-26T00:28:48.785Z","avatar_url":"https://github.com/cytle.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# faker-ts\n\nMock data from TypeScript\n\n## Usage\n\n``` ts\nimport { tsMock, tsMockService } from 'faker-ts';\n\nconst files = ['foo.ts'];\n// foo.ts\n// export interface IFoo { a: string }\n\nconst mocker = tsMock(files);\nmocker.generateMock('IFoo'); // { \"a\": \"commodo voluptate pariatur\" }\n\n// or listening file change\nconst mocker = tsMockService(files); // see more Mock Server with Koa\n```\n\n### CLI\n\n``` shell\nyarn global add faker-ts\n```\n\ne.g.\n\n``` shell\necho \"interface IFoo { title: string; }\" \u003e foo.ts\nfaker-ts foo.ts IFoo # Mock data\n```\n\n### Mock Server with Koa\n\n``` ts\nimport Koa from 'koa';\nimport Router from 'koa-router';\nimport * as ts from 'typescript';\nimport { tsMockService } from 'faker-ts';\n\nexport function createServer(files: string[], jsonCompilerOptions?: ts.CompilerOptions, basePath?: string) {\n  const app = new Koa();\n  const router = new Router();\n\n  const mocker = tsMockService(files, jsonCompilerOptions, basePath);\n\n  app.use(async (ctx, next) =\u003e {\n    try {\n      await next();\n    } catch (error) {\n      ctx.body = { msg: error.message };\n    }\n  });\n\n  router.get('/mocks/:symbol', async (ctx) =\u003e {\n    ctx.body = mocker.generateMock(ctx.params.symbol);\n  });\n\n  router.get('/schemas/:symbol', async (ctx) =\u003e {\n    ctx.body = mocker.generateSchema(ctx.params.symbol);\n  });\n\n  router.get('/schemas', async (ctx) =\u003e {\n    ctx.body = mocker.generateSchema();\n  });\n\n  router.get('/symbols', async (ctx) =\u003e {\n    ctx.body = mocker.generator.getMainFileSymbols(mocker.program);\n  });\n\n  app\n    .use(router.routes())\n    .use(router.allowedMethods());\n\n  return app;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcytle%2Ffaker-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcytle%2Ffaker-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcytle%2Ffaker-ts/lists"}