{"id":19168197,"url":"https://github.com/masx200/custom-elements-random-define","last_synced_at":"2026-05-07T19:02:41.213Z","repository":{"id":36969975,"uuid":"210078666","full_name":"masx200/custom-elements-random-define","owner":"masx200","description":"web-components随机定义custom-elements,并且防止重名定义的js库","archived":false,"fork":false,"pushed_at":"2023-02-10T06:58:02.000Z","size":219,"stargazers_count":1,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-22T22:48:24.352Z","etag":null,"topics":["javascript","web-components"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/masx200.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-22T02:20:09.000Z","updated_at":"2022-03-26T09:43:16.000Z","dependencies_parsed_at":"2023-02-12T20:45:35.998Z","dependency_job_id":null,"html_url":"https://github.com/masx200/custom-elements-random-define","commit_stats":{"total_commits":66,"total_committers":3,"mean_commits":22.0,"dds":0.2727272727272727,"last_synced_commit":"2eef98b9951d9dc00a99f98958dbcdbbd8e7974b"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masx200%2Fcustom-elements-random-define","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masx200%2Fcustom-elements-random-define/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masx200%2Fcustom-elements-random-define/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masx200%2Fcustom-elements-random-define/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/masx200","download_url":"https://codeload.github.com/masx200/custom-elements-random-define/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240248573,"owners_count":19771496,"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":["javascript","web-components"],"created_at":"2024-11-09T09:41:44.528Z","updated_at":"2026-05-07T19:02:36.179Z","avatar_url":"https://github.com/masx200.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# custom-elements-random-define\n\n`web-components` 随机定义 `custom-elements`,并且防止重名定义的 js 库\n\n如果定义重名,则自动使用随机名称定义\n\n由于修改了 `customElements` 的 API,所以需要在最前面引入此模块\n\n# 安装 npm 模块\n\n```powershell\ncnpm install --save \"@masx200/custom-elements-random-define\"\n```\n\n或者\n\n```powershell\nyarn add \"@masx200/custom-elements-random-define\"\n```\n\n# 使用 npm 模块\n\n```js\nimport RandomDefine from \"@masx200/custom-elements-random-define\";\n```\n\n# 在浏览器中使用\n\n从 cdn 获取\n\nhttps://cdn.jsdelivr.net/gh/masx200/custom-elements-random-define@latest/dist/index.min.js\n\n```js\nimport RandomDefine from \"https://cdn.jsdelivr.net/gh/masx200/custom-elements-random-define@latest/dist/index.min.js\";\n```\n\n# API\n\n```ts\ndeclare var RandomDefine: (\n    initclass: CustomElementConstructor,\n    extendsname?: string | undefined\n) =\u003e string;\n```\n\n# 使用方法\n\n## 普通组件\n\n```js\nvar mycom = class extends HTMLElement {};\nconst tag = RandomDefine(mycom);\nvar myele = new mycom();\n\nlet inst = document.createElement(tag);\n```\n\n## 继承组件\n\n```js\nvar mycom = class extends HTMLDivElement {};\nconst tag = RandomDefine(mycom, \"div\");\nvar myele = new mycom();\nlet inst = document.createElement(\"div\", { is: tag });\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmasx200%2Fcustom-elements-random-define","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmasx200%2Fcustom-elements-random-define","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmasx200%2Fcustom-elements-random-define/lists"}