分享5个可能用得上的JavaScript 库
在项目开发中,当有一个现成的库可以完成的事情,可以先大概看下其实现,然后再决定是否使用,依赖库可以是项目开发的催化剂,直接使用或者借鉴编码。本来分享 5 个可能用得上的 JavaScript 库。
1. handsontable
这是星级最高的 JavaScript 库之一,拥有超过 17k
颗星。它将数据网格功能与类似电子表格的 UX 相结合。它还提供数据绑定、数据验证、过滤、排序和 CRUD 操作。它适用于 React、Angular 和 Vue。它包括许多功能,如多列排序、非连续选择、过滤数据、导出到文件 验证数据等等。
GitHub:github.com/handsontabl…
2. PapaParse
这是在浏览器内最快的 CSV(或分隔文本)解析器。根据 RFC 4180,可靠且正确的。包括许多功能,例如直接解析 CSV 文件(本地或通过网络)、流式传输大文件(甚至通过 HTTP)、反向解析(将 JSON 转换为 CSV)等等。它在 GitHub 上有超过 10.8k
颗星。
GitHub:github.com/mholt/PapaP…
3. URI
这个库提供了使用查询字符串的简单而强大的方法,具有许多 URI 规范化函数,转换相对/绝对路径。URI.js 在 GitHub 上有超过 6.2k
颗星。
GitHub:github.com/medialize/U…
示例代码:
// mutating URLs
URI("http://example.org/foo.html?hello=world")
.username("rodneyrehm")
// -> http://rodneyrehm@example.org/foo.html?hello=world
.username("")
// -> http://example.org/foo.html?hello=world
.directory("bar")
// -> http://example.org/bar/foo.html?hello=world
.suffix("xml")
// -> http://example.org/bar/foo.xml?hello=world
.query("")
// -> http://example.org/bar/foo.xml
.tld("com")
// -> http://example.com/bar/foo.xml
.query({ foo: "bar", hello: ["world", "mars"] });
// -> http://example.com/bar/foo.xml?foo=bar&hello=world&hello=mars
// cleaning things up
URI("?&foo=bar&&foo=bar&foo=baz&").normalizeQuery();
// -> ?foo=bar&foo=baz
// working with relative paths
URI("/foo/bar/baz.html").relativeTo("/foo/bar/world.html");
// -> ./baz.html
URI("/foo/bar/baz.html")
.relativeTo("/foo/bar/sub/world.html")
// -> ../baz.html
.absoluteTo("/foo/bar/sub/world.html");
// -> /foo/bar/baz.html
// URI Templates
URI.expand("/foo/{dir}/{file}", {
dir: "bar",
file: "world.html",
});
// -> /foo/bar/world.html
4. i18next
如果需要为应用程序添加国际化,那么 i18next 是一个很好的资源。它不仅仅是提供标准的 i18n 功能,例如(复数、上下文、插值和格式),提供了一个完整的解决方案,可将产品从 Web 本地化到移动设备和桌面。它在 GitHub 上有超过 6.4k
颗星。
GitHub:github.com/i18next/i18…
5. js-xss
从依赖库的名称应该就可以猜到做什么的,该库用于过滤来自用户的输入以防止 XSS 攻击。它使用白名单指定的配置清理不受信任的 HTML(以防止 XSS)。它在 GitHub 上有超过 4.7k 颗星。
GitHub:github.com/leizongmin/…
转载自:https://juejin.cn/post/7157705610601955358