提交学习笔记专用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.0 KiB

  1. # unplugin-utils
  2. [![npm version][npm-version-src]][npm-version-href]
  3. [![npm downloads][npm-downloads-src]][npm-downloads-href]
  4. [![Unit Test][unit-test-src]][unit-test-href]
  5. [![codecov][codecov-src]][codecov-href]
  6. A set of utility functions commonly used by unplugins.
  7. Thanks to [@rollup/pluginutils](https://github.com/rollup/plugins/tree/master/packages/pluginutils). This projects is heavily copied from it.
  8. ## Why Fork?
  9. - 🌍 Platform agnostic, supports running in the browser, Node.js...
  10. - ✂️ Subset, smaller bundle size.
  11. - **💯 Coverage**: 100% test coverage.
  12. ## Install
  13. ```bash
  14. npm i unplugin-utils
  15. ```
  16. ## Usage
  17. ### createFilter
  18. ```ts
  19. export default function myPlugin(options = {}) {
  20. const filter = createFilter(options.include, options.exclude)
  21. return {
  22. transform(code, id) {
  23. if (!filter(id)) return
  24. // proceed with the transformation...
  25. },
  26. }
  27. }
  28. ```
  29. ### normalizePath
  30. ```ts
  31. import { normalizePath } from 'unplugin-utils'
  32. normalizePath(String.raw`foo\bar`) // 'foo/bar'
  33. normalizePath('foo/bar') // 'foo/bar'
  34. ```
  35. ## Sponsors
  36. <p align="center">
  37. <a href="https://cdn.jsdelivr.net/gh/sxzz/sponsors/sponsors.svg">
  38. <img src='https://cdn.jsdelivr.net/gh/sxzz/sponsors/sponsors.svg'/>
  39. </a>
  40. </p>
  41. ## License
  42. [MIT](./LICENSE) License © 2025-PRESENT [Kevin Deng](https://github.com/sxzz)
  43. [MIT](./LICENSE) Copyright (c) 2019 RollupJS Plugin Contributors (https://github.com/rollup/plugins/graphs/contributors)
  44. <!-- Badges -->
  45. [npm-version-src]: https://img.shields.io/npm/v/unplugin-utils.svg
  46. [npm-version-href]: https://npmjs.com/package/unplugin-utils
  47. [npm-downloads-src]: https://img.shields.io/npm/dm/unplugin-utils
  48. [npm-downloads-href]: https://www.npmcharts.com/compare/unplugin-utils?interval=30
  49. [unit-test-src]: https://github.com/sxzz/unplugin-utils/actions/workflows/unit-test.yml/badge.svg
  50. [unit-test-href]: https://github.com/sxzz/unplugin-utils/actions/workflows/unit-test.yml
  51. [codecov-src]: https://codecov.io/gh/sxzz/unplugin-utils/graph/badge.svg?token=VDWXCPSL1O
  52. [codecov-href]: https://codecov.io/gh/sxzz/unplugin-utils