{"id":21557148,"url":"https://github.com/shenfe/jsnippet","last_synced_at":"2025-03-18T03:24:12.754Z","repository":{"id":143949388,"uuid":"129884538","full_name":"shenfe/jsnippet","owner":"shenfe","description":"Frontend code snippet base.","archived":false,"fork":false,"pushed_at":"2018-11-26T16:13:02.000Z","size":26,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-24T10:32:48.246Z","etag":null,"topics":["code-base","code-snippets","frontend","helper","javascript","utility"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shenfe.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":"2018-04-17T10:02:35.000Z","updated_at":"2018-11-26T16:13:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"d487021d-29db-4791-9c09-afe2620c87f9","html_url":"https://github.com/shenfe/jsnippet","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/shenfe%2Fjsnippet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shenfe%2Fjsnippet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shenfe%2Fjsnippet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shenfe%2Fjsnippet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shenfe","download_url":"https://codeload.github.com/shenfe/jsnippet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244148406,"owners_count":20406177,"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":["code-base","code-snippets","frontend","helper","javascript","utility"],"created_at":"2024-11-24T08:11:11.331Z","updated_at":"2025-03-18T03:24:12.729Z","avatar_url":"https://github.com/shenfe.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jsnippet\n\n\u003e 前端代码片段库，尤其适用于小页面、静态页面的模块。与parcel、webpack4等一起使用更佳。**可以据此建立团队使用的基础辅助代码库。**\n\n## Philosophy\n\n看不惯不同项目、不同模块各自为政的utility、helper代码，试图用npm+git的方式统一。重复的工作应该用最好的代码复用来取代，并且应易于维护。适合基于本代码库建立前端团队的基础工具代码库。\n\n## 编写snippet\n\n* 一个snippet只专注于一件事情\n* 放置在独立的子文件夹中\n* 文件夹命名符合语义化，且构成一个合法变量名identifier\n* 文件夹中放置`index.[ext]`文件，**尽可能做到单文件，至少不要依赖自己文件夹外的任何模块**\n* 文件夹中还可以有`README.md`文件和`test.js`文件等，但都不作为index文件的依赖\n* 不需要考虑语法特性问题，用最顺手或最酷炫的方式写，其他（babel、loader等工作）交给使用snippet的项目去做\n* 如果不在README中对兼容性等适用范围加以说明，默认snippet代码经转译处理后适用于所有（值得考虑的）浏览器场景\n\n## 使用snippet\n\n### 添加依赖\n\n对于一个项目，在`package.json`中加入以下依赖：\n\n```json\n\"dependencies\": {\n    \"@shenfe/jsnippet\": \"git@github.com:shenfe/jsnippet.git#tag_name\"\n}\n```\n\n### 使用\n\n使用一个snippet：\n\n```js\nimport someStuff from '@shenfe/jsnippet/someStuff'\n```\n\n建议像上面这样**按需引入**snippet。当你对其他snippet的质量和副作用不能保证时，仅仅引入自己放心的snippet是明智的。\n\n当然，要像下面这样引入也可以，但如果没有treeshaking的话，会将所有snippet都引入：\n\n```js\nimport { someStuff } from '@shenfe/jsnippet'\n```\n\n### 更新\n\n在更新时，先将`tag_name`改成更新的tag名，然后执行：\n\n```bash\n$ npm install @shenfe/jsnippet --save\n```\n\n## 探索更多可能\n\n如果自定义一套组件的编写和引用方式，则snippet还可以是前端组件的角色，包含html和css。类似于vue单文件组件那样。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshenfe%2Fjsnippet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshenfe%2Fjsnippet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshenfe%2Fjsnippet/lists"}