{"id":16641805,"url":"https://github.com/samthor/cjs-faker","last_synced_at":"2026-04-27T02:31:17.282Z","repository":{"id":57199111,"uuid":"102444062","full_name":"samthor/cjs-faker","owner":"samthor","description":"Fakes commonJS and AMD boilerplate to allow importing legacy code as an ES6 module","archived":false,"fork":false,"pushed_at":"2018-12-06T22:49:30.000Z","size":14,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-18T23:35:18.362Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://samthor.github.io/cjs-faker/demo/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/samthor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-05T06:40:29.000Z","updated_at":"2017-09-07T00:39:23.000Z","dependencies_parsed_at":"2022-09-16T15:01:37.555Z","dependency_job_id":null,"html_url":"https://github.com/samthor/cjs-faker","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/samthor%2Fcjs-faker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samthor%2Fcjs-faker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samthor%2Fcjs-faker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samthor%2Fcjs-faker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samthor","download_url":"https://codeload.github.com/samthor/cjs-faker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243164895,"owners_count":20246718,"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-10-12T07:47:56.802Z","updated_at":"2025-12-25T02:49:16.168Z","avatar_url":"https://github.com/samthor.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"cjs-faker fakes commonJS and AMD boilerplate to allow importing legacy code via ES6 modules.\n\nThis is implemented by providing fake `exports`/`module.exports`, `require()` and `define()` calls that are used by the commonJS or AMD code being included.\nYou must shim _all_ modules that you depend on.\n\n# Rationale\n\nThis approach is mostly a thought experiment in evaluating legacy code at runtime, rather than requiring a build step (as `require()` and `define()` are not supported natively by browsers).\n\nFor most practical purposes, you'll be better off using Rollup with [its commonJS plugin](https://github.com/rollup/rollup-plugin-commonjs).\nUsing Rollup requires a build step before you can import legacy code as an ES6 module, but doesn't require a shim per module in the dependency tree.\n\n# Usage\n\nUsage requires providing a shim around all commonJS or AMD modules:\n\n```js\n// wrap_base64.js\nimport faker from './node_modules/cjs-faker/cjs-faker.js';\nimport 'https://cdn.rawgit.com/mathiasbynens/base64/a8d7cabd/base64.js';\nexport default faker('base64');\n```\n\nNow you can just use the `base64` module inside ES6:\n\n```js\nimport base64 from './wrap_base64.js';\nconsole.info(base64.encode('Hello!'));\n\n// or use require() itself for already wrapped modules\nconst base64 = require('base64');\n```\n\nNo build steps are required.\n\n## Dependency Tree\n\nIf you depend on commonJS module A, which depends on commonJS module B etc, you must provide the shim for B first, then A.\nThe default `faker` method in the examples fills a registry that is available via the global `require()` call, so B has to be shimmed first for A's `require('a')` call to succeed.\n\nSee file B:\n\n```js\n// wrap_b.js\nimport faker from './node_modules/cjs-faker/cjs-faker.js';\nimport './path/to/b.js';\nexport default faker('b');\n```\n\nAnd file A:\n\n```js\n// wrap_a.js\nimport faker from './node_modules/cjs-faker/cjs-faker.js';\nimport './path/to/a.js';\nexport default faker('a');\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamthor%2Fcjs-faker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamthor%2Fcjs-faker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamthor%2Fcjs-faker/lists"}