Skip to content

Commit

Permalink
✨ 新增 ag.global.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaubee committed Oct 10, 2024
1 parent fa9f14a commit bb5a1e1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## [docs 文档](https://jsr.io/@gaubee/util/doc)

###### 简介
### 简介

1. 个人项目经验,涵盖大量常用函数集合,建议与 deno 的 [`@std/*`](https://jsr.io/@std) 互为补充。
> 这个库中与 @std 系列有一些交集,交集的部分通常是我个人觉得我自己的实现更好:
Expand All @@ -12,10 +12,13 @@
> - 可能是条件边界覆盖更全。
1. 这个库不会包含垫片相关的,只要在 esnext 范畴内我都会使用,所以请自行处理垫片相关的问题

###### 关于 @gaubee/util/global
### 关于 @gaubee/util/global

> 如果你的项目是 application 级别,不会被其它项目所依赖,那么我建议导入 global 系列,它能大幅度提升你的 js 开发体验。
> 虽然大家都说“不要污染原型链”,但是辩证看待,我建议你在合适的时候,“应该充分利用原型链”。
> 在原型链上扩展函数,通过链式调用,可以达到很多符合直觉的开发体验。
>
> 并且,随着 [shadowrealm 提案](https://github.com/tc39/proposal-shadowrealm) 的演进,未来污染原型链在复杂项目里头就将不再是问题。
由于 jsr 上不允许上传污染全局的模块,所以如果需要,请使用 [npm 版本](https://www.npmjs.com/package/@gaubee/util)
**npm 版本还包含了 commonjs 的直接支持**
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gaubee/util",
"version": "0.7.2",
"version": "0.8.0",
"tasks": {
"build": "deno run -A ./dnt.ts",
"npm": "deno task build && deno task pub-npm",
Expand Down
15 changes: 15 additions & 0 deletions src/ag.global.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ag_done, ag_then, AGF } from "./ag.ts";
import { curryThisFn, extendsMethod } from "./func.ts";

const done = curryThisFn(ag_done);
const then = curryThisFn(ag_then);

extendsMethod(AGF.prototype, "done", done);
extendsMethod(AGF.prototype, "then", then);

declare global {
interface AsyncGenerator<T = unknown, TReturn = any, TNext = unknown> extends AsyncIterator<T, TReturn, TNext> {
done: typeof done;
then: typeof then;
}
}
1 change: 1 addition & 0 deletions src/global.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "./ag.global.ts";
import "./collections.global.ts";
import "./encoding.global.ts";
import "./object.global.ts";

0 comments on commit bb5a1e1

Please sign in to comment.