Monads键入安全选项与结果类型,受Rust启发

这款monads库简直是 JavaScript 开发者的福音!它让你在代码中使用OptionResult等类型,提升了类型安全。最棒的是,它受到了Rust的启发,给你带来了一些类似 Rust 的功能,尤其在nullundefined时更能避免一些低级错误。你可以用Some或者None来封装值,像这样:

import { Some } from 'https://deno.land/x/monads/mod.ts'
const air = Some('air').unwrapOr('baloon')
console.log(air) // 'air'
unwrapOr方法让你能一个默认值,防止空值带来的麻烦。它支持 Node.js 和浏览器环境,安装也简单:npm install @hqoss/monads,不过要注意,这个库是 ES2018 目标的。,挺适合喜欢Rust风格的开发者,是在一些复杂数据结构时,能让代码更整洁、可靠。如果你喜欢更强的类型安全,可以试试这款库。

zip
monads-master.zip 预估大小:36个文件
folder
monads-master 文件夹
file
mod.ts 242B
folder
docs 文件夹
file
globals.md 6KB
folder
interfaces 文件夹
file
resright.md 6KB
file
reserr.md 4KB
file
optsome.md 3KB
file
resleft.md 6KB
file
resok.md 4KB
file
match.md 1KB
file
result.md 3KB
file
option.md 3KB
file
optnone.md 3KB
file
either.md 5KB
file
package.json 1KB
folder
.github 文件夹
folder
workflows 文件夹
file
ci.yaml 760B
file
publish.yaml 624B
folder
test 文件夹
folder
option 文件夹
file
option.test.ts 14KB
folder
result 文件夹
file
result.test.ts 13KB
folder
either 文件夹
file
either.test.ts 15KB
file
.prettierrc 70B
file
jest.config.js 371B
file
package-lock.json 230KB
file
.npmignore 31B
file
tsconfig.json 5KB
file
LICENSE.md 1KB
file
.gitignore 593B
folder
lib 文件夹
folder
option 文件夹
file
option.deno.ts 3KB
file
README.md 6KB
file
option.ts 3KB
folder
result 文件夹
file
result.ts 4KB
file
result.deno.ts 4KB
file
README.md 6KB
folder
either 文件夹
file
either.ts 4KB
file
either.deno.ts 4KB
file
README.md 727B
file
index.ts 206B
file
README.md 6KB
zip 文件大小:89.24KB