Skip to content

Commit

Permalink
docs: ✏️ Add codecov badge
Browse files Browse the repository at this point in the history
  • Loading branch information
haozi committed Nov 16, 2023
1 parent 424c24a commit d1289ef
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"cSpell.words": ["idmp"]
"cSpell.words": ["codecov", "idmp", "typeof"]
}
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

---

An elegant library to solve duplicate and concurrent calls for idempotent functions, pure function. Less than 200b after Gzip
[![codecov](https://codecov.io/gh/ha0z1/idmp/branch/main/graph/badge.svg)](https://app.codecov.io/gh/ha0z1/idmp/blob/main/src%2Findex.ts)
[![npm](https://img.shields.io/npm/v/idmp.svg)](https://www.npmjs.com/package/idmp)
[![contributors](https://img.shields.io/github/contributors/ha0z1/idmp)](https://github.com/ha0z1/idmp/graphs/contributors)

An elegant library to solve duplicate and concurrent calls for idempotent functions, pure function. Less than 200 Bytes after Gzip

English | [简体中文](README.zh-CN.md)

Expand Down Expand Up @@ -40,22 +44,22 @@ const getInfoById = async (id: string) => {
return await fetch(API).then((d) => d.json())
}

// Handle params
// 处理有入参的场景
export const getInfoByIdIdmp = (id: string) =>
idmp(`/api/your-info?${id}`, () => getInfo(id))
idmp(`/api/your-info?${id}`, () => getInfoById(id))

// Or a more generic type juggling, for complex params, idmp will infer the return type automatically, keep it consistent with the original function
// 或者更通用的类型体操写法,用于复杂的入参,idmp 会自动推导返回值类型,与原函数保持一致
export const getInfoByIdIdmp = (...args: Parameters<typeof getInfoById>) =>
idmp(`/api/your-info?${JSON.stringify(args)}`, () => getInfo(...args))
idmp(`/api/your-info?${JSON.stringify(args)}`, () => getInfoById(...args))

// More options
// 增加更多配置项
export const getInfoByIdIdmp = (id: string) =>
idmp(`/api/your-info?${id}`, () => getInfo(id), {
idmp(`/api/your-info?${id}`, () => getInfoById(id), {
maxAge: 86400 * 1000,
})
```

Then replace `getInfo` with `getInfoIdmp`.
Then replace `getInfoByIdIdmp` with `getInfoById`.

## Options

Expand Down
14 changes: 9 additions & 5 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

---

一个优雅地解决幂等(idempotent) 函数的重复和并发调用的小库,纯函数,Gzip 后不到 200b
[![codecov](https://codecov.io/gh/ha0z1/idmp/branch/main/graph/badge.svg)](https://app.codecov.io/gh/ha0z1/idmp/blob/main/src%2Findex.ts)
[![npm](https://img.shields.io/npm/v/idmp.svg)](https://www.npmjs.com/package/idmp)
[![contributors](https://img.shields.io/github/contributors/ha0z1/idmp)](https://github.com/ha0z1/idmp/graphs/contributors)

一个优雅地解决幂等(idempotent) 函数的重复和并发调用的小库,纯函数,Gzip 后不到 200 Bytes

[English](README.md) | 简体中文

Expand Down Expand Up @@ -42,20 +46,20 @@ const getInfoById = async (id: string) => {

// 处理有入参的场景
export const getInfoByIdIdmp = (id: string) =>
idmp(`/api/your-info?${id}`, () => getInfo(id))
idmp(`/api/your-info?${id}`, () => getInfoById(id))

// 或者更通用的类型体操写法,用于复杂的入参,idmp 会自动推导返回值类型,与原函数保持一致
export const getInfoByIdIdmp = (...args: Parameters<typeof getInfoById>) =>
idmp(`/api/your-info?${JSON.stringify(args)}`, () => getInfo(...args))
idmp(`/api/your-info?${JSON.stringify(args)}`, () => getInfoById(...args))

// 增加更多配置项
export const getInfoByIdIdmp = (id: string) =>
idmp(`/api/your-info?${id}`, () => getInfo(id), {
idmp(`/api/your-info?${id}`, () => getInfoById(id), {
maxAge: 86400 * 1000,
})
```

然后用 `getInfoIdmp` 替换 `getInfo` 方法。
然后用 `getInfoByIdIdmp` 替换 `getInfoById` 方法。

## Options

Expand Down

0 comments on commit d1289ef

Please sign in to comment.