2023-02


每天给你推荐一个新奇,好玩,高品质的开源库,好文,观点或言论等。
项目主页维护当前月份的内容,想看往期内容,可以翻到下方历史汇总部分,然后选择自己感兴趣的月份点进去即可。
chrome 的 headless 模式(无头浏览器)可以做一些集成测试。而之前由于 headless 模式和非 headless 模式两者是使用不用的技术实现,因此会有一些 bug(比如在无头浏览器好好的,在有头浏览器就有 bug,反之亦然)。
新的 chrome (版本大于等于 Chrome 112) 无头浏览器和有头浏览器采用的技术(codebase)是一样的, 因此不会有上面提到的问题。
via: https://developer.chrome.com/articles/new-headless/
《useSignal() is the Future of Web Frameworks》这篇文章解释了为什么 react 不能像 vue 那样智能追踪需要更新的组件。react 想做到这一点,就需要引入类似 useSignal() 这样的机制。而 preact 就对 useSignal() 进行了支持。
目前 Vue, Preact, Solid 和 Qwik 都支持。
via: https://www.builder.io/blog/usesignal-is-the-future-of-web-frameworks
A 'CSS reset' for TypeScript, improving types for common JavaScript API's
ts-reset 是一个类似于垫片的库,可以”修复“一些 ts 上的诡异行为。
Without ts-reset:
- 🚨 .json (in fetch) and JSON.parse both return any
- 🤦 .filter(Boolean) doesn't behave how you expect
- 😡 array.includes often breaks on readonly arrays ts-reset smooths over these hard edges, just like a CSS reset does in the browser.
With ts-reset:
- 👍 .json (in fetch) and JSON.parse both return unknown
- ✅ .filter(Boolean) behaves EXACTLY how you expect
- 🥹 array.includes is widened to be more ergonomic
- 🚀 And several more changes!
via: https://github.com/total-typescript/ts-reset
The fastest JSON schema Validator. Supports JSON Schema(最快的 JSON schema 验证器,支持 JSON schema)。
via: https://github.com/ajv-validator/ajv
如果你有验证 JSON 的需求,可以一试。
下面是一个使用 ajv 的简单例子。
// or ESM/TypeScript import
import Ajv from "ajv"
// Node.js require:
const Ajv = require("ajv")
const ajv = new Ajv() // options can be passed, e.g. {allErrors: true}
const schema = {
type: "object",
properties: {
foo: {type: "integer"},
bar: {type: "string"},
},
required: ["foo"],
additionalProperties: false,
}
const data = {
foo: 1,
bar: "abc",
}
const validate = ajv.compile(schema)
const valid = validate(data)
if (!valid) console.log(validate.errors)
另外它的报错相对于用户来说不友好,可以结合使用 better-ajv-errors 来获得更好的效果。

via: https://github.com/atlassian/better-ajv-errors
一个帮助你 debug 的库。可以:
- 通过环境变量显示指定的信息(信息过滤的作用
- 自动在尾部添加时间消耗
- 不同颜色高亮显示
- 等等
支持在 nodejs 和 浏览器中使用。


via: https://www.npmjs.com/package/debug
这个教程内容其实一般,不是我看过的同类型中质量最好的,但是其交互式的这种形式我特别喜欢,想要借鉴。
这真的是一个我一直想做的类型 - 交互式教程。我的想法是做一个交互式的算法教程,我之前没有接触过这种形式,但是在我的想象中如果做出来,那么肯定能帮助到很多人。
这个教程是使用 JS 编写 Lisp 的编译器。可以帮助你理解: