Skip to content

speed up diffKeys() with new Set() API #24

Description

@TechQuery

Task description

  1. 基于 Set 对象交集、差集 API 加速“列表差异对比”函数
  2. 基于 Uint8Array 对象 Base64、Hex 方法简化多个数据函数
  3. 升级基础设施到 TypeScript 6、PNPM 11

Document

  1. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/intersection
  2. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/difference
  3. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/fromBase64
  4. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toBase64
  5. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toHex

Target

web-utility/source/data.ts

Lines 121 to 138 in 0530fc2

export function diffKeys<T extends IndexKey>(oldList: T[], newList: T[]) {
const map = {} as Record<T, DiffStatus>;
for (const item of oldList) map[item] = DiffStatus.Old;
for (const item of newList) {
map[item] ||= 0;
map[item] += DiffStatus.New;
}
return {
map,
group: groupBy(
Object.entries<DiffStatus>(map),
([key, status]) => status
)
};
}

web-utility/source/data.ts

Lines 99 to 117 in 190843a

/**
* Encode string to Base64 with Unicode support
*
* @param input - String to encode
* @returns Base64 encoded string
*/
export const encodeBase64 = (input: string) =>
btoa(String.fromCharCode(...new TextEncoder().encode(input)));
/**
* Decode Base64 string with Unicode support
*
* @param input - Base64 encoded string to decode
* @returns Decoded Unicode string
*/
export const decodeBase64 = (input: string) =>
new TextDecoder().decode(
Uint8Array.from(atob(input), char => char.charCodeAt(0))
);

Reward currency

TQT $

Reward amount

45

Reward payer

石垚 tech-query@idea2app.cn

Task source

https://idea2app.feishu.cn/record/PHFwrmKOceCEv4cvjL7cxrpJnWg

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions