{"id":20345659,"url":"https://github.com/kscript/file-loader","last_synced_at":"2026-05-09T08:07:07.937Z","repository":{"id":47925718,"uuid":"163146074","full_name":"kscript/file-loader","owner":"kscript","description":"文件加载器","archived":false,"fork":false,"pushed_at":"2021-08-11T20:17:35.000Z","size":33,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-02-15T01:13:03.534Z","etag":null,"topics":["file","loader","npm"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/kscript.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":"2018-12-26T06:43:00.000Z","updated_at":"2023-03-08T03:02:01.000Z","dependencies_parsed_at":"2022-08-12T14:20:54.742Z","dependency_job_id":null,"html_url":"https://github.com/kscript/file-loader","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kscript/file-loader","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kscript%2Ffile-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kscript%2Ffile-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kscript%2Ffile-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kscript%2Ffile-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kscript","download_url":"https://codeload.github.com/kscript/file-loader/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kscript%2Ffile-loader/sbom","scorecard":{"id":571228,"data":{"date":"2025-08-11","repo":{"name":"github.com/kscript/file-loader","commit":"6c47597c4210577c40ee2f98c3bace6df1a26302"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.7,"checks":[{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Code-Review","score":0,"reason":"Found 0/17 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":7,"reason":"3 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-6chw-6frg-f759","Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9","Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-20T16:24:24.450Z","repository_id":47925718,"created_at":"2025-08-20T16:24:24.450Z","updated_at":"2025-08-20T16:24:24.450Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32811662,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-08T08:22:46.396Z","status":"online","status_checked_at":"2026-05-09T02:00:06.633Z","response_time":123,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["file","loader","npm"],"created_at":"2024-11-14T22:09:18.363Z","updated_at":"2026-05-09T08:07:07.898Z","avatar_url":"https://github.com/kscript.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"### ks-file-loader\n一个文件加载器\n\n#### 安装\n```npm\n  npm i ks-file-loader -D\n```\n\n#### Api\n\n| 属性 | 类型 | 默认值 | 说明 |\n|--|--|--|--|\n| path | string | './' | 要处理目录(相对于项目目录, 而非文件所在目录) |\n| name | string / RegExp | '' | 要处理文件名 |\n| fullName | string / RegExp | '' | 要处理文件 (文件名+扩展名) |\n| ext | string / RegExp | '' | 要处理文件类型 |\n| mode | string | 'BFS' | 遍历模式: 深度优先(DFS)/广度优先(BFS) |\n| exclude | string / RegExp | - | 排除路径. 没有被排除的文件才会被加载 |\n| include | string / RegExp | - | 包含路径. 默认排除 node_modules 这样的大文件夹, 如果要加载, 须在include中指定 |\n| deep | boolean | false | 是否深层遍历 |\n| async | boolean | false | 当不深层遍历时, 是否异步加载 (异步时使用Promise.all加载, 不采用异步可以保持顺序) |\n| showDir | boolean | false | 文件夹是否经过loader |\n| readFile | boolean | false | 是否读取文件内容 |\n| output | string / Function | - | 输出文件名 |\n| outputDir | string | - | 输出文件夹名 |\n| error | function | - | 处理出错时的回调 |\n| done | function | - | 处理完毕时的回调 |\n| loader | function | - | 加载器. 参数( stats: 文件信息 data: 文件内容 done: 处理完成时要执行的回调) |\n\n\u003e loader函数有异步操作时, 有两种方式: 1、回调函数 2、Promise(推荐).  \n  当执行loader函数后, 返回值  \n  为 Promise 时, loader会先等待Promise执行完毕  \n  为 false 时, 等待用户手动调用 done  \n  为其它值时, 则继续执行  \n\n\u003e 设置了fullName时, 不再验证文件名和扩展名\n\n\u003e output 有字符串和函数两种形式\n  - 值为字符串时\n    匹配规则为\\[(.*?)(path|dir|name|hash|ext)(.*?)\\](\\?|)\n    [{前缀}{精确匹配}{后缀}]{?表示精确匹配为空时, 输出空字符串}\n  - 值为函数时, 等同于loader, 但如果返回了一个字符串, 那么则会进入 值为字符串 时的流程\n    \n\n#### 如何使用?\n\n案例1: 用 hexo 生成的博客, 在源码中有大量的空行, 使用\n```js\n// 调用示例\nconst fs = require(\"fs\");\nconst fileLoader = require('ks-file-loader')\n\nfileLoader({\n\n  // 要进行转换的目录\n  // 相对于项目目录, 而非文件所在目录\n  path: './public',\n\n  // 文件扩展名, 支持正则\n  ext: 'html',\n\n  // 文件名, 支持正则\n  // name: '',\n\n  // 完整文件名, 支持正则 (验证文件名 + 扩展名)\n  // fullName: ''\n\n  // 包含目录\n  // 默认会排除 node_modules 这样的大文件夹, 如果要加载, 必须在include中指定\n  // include: /2018/,\n\n  // 排除目录\n  exclude: /lib/,\n\n  // 遍历模式: 广度优先(BFS) / 深度优先(DFS)\n  mode: 'DFS',\n\n  // 是否深层遍历\n  deep: true,\n\n  // 是否读取文件内容\n  readFile: true,\n  /**\n   * 加载器\n   * @param {object} stats 文件信息\n   * @param {string} data 文件内容 readFile 为 false 时返回空字符串\n   * @param {function} done 文件处理完毕的回调\n   * @return {Promise|false|any} Promise: 使用Promise处理异步  false: 使用回调函数处理异步(处理完需手动调用done) 其它值: 默认为同步\n   */\n  loader: function(stats, data, done) {\n    \n    // do something..\n    // 替换多余的空行\n    var content = data.replace(/\\n(\\s+)\\n+/g, '\\n');\n\n    // Promise方式处理异步操作\n    return new Promise((resolve, reject) {\n      fs.writeFile(stats.path, content, function(error){\n        if(error){\n          // 处理出错时, 即便通过reject抛出了错误, 也会被忽略, 因此需要用户自己先行处理错误\n          reject(error);\n        } else {\n          resolve();\n        }\n      });\n    });\n    // 回调函数方式处理异步操作\n    // 写入文件\n    fs.writeFile(stats.path, content, function(error){\n      if(error){\n        console.log(error);\n      }\n      done();\n    });\n    // 返回值必须全等于false\n    return false;\n  },\n  // 转换完毕\n  done: function(){\n    console.log('complete');\n  }\n});\n```\n\n案例2: 给指定类型的文件加hash\n```js\nconst fileLoader = require('ks-file-loader')\nfileLoader({\n  ext: /^(js|ts)$/,\n  // output: '[dir/][name-]?[hash][.ext]',\n  output: function(stats) {\n    let name = /\\.d\\.ts$/.test(stats.path) ? stats.name.slice(0, -2) + '-[hash].d' : '[name-]?[hash]'\n    return '[dir/]' + name + '[.ext]'\n  }\n})\n```\n\n#### lisence\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkscript%2Ffile-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkscript%2Ffile-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkscript%2Ffile-loader/lists"}