Skip to content

Commit

Permalink
Merge pull request #53 from jokester/next-iteration
Browse files Browse the repository at this point in the history
v0.5.0
  • Loading branch information
jokester committed Feb 11, 2024
2 parents 860d8d6 + ae8da58 commit c6eec7d
Show file tree
Hide file tree
Showing 20 changed files with 489 additions and 993 deletions.
59 changes: 19 additions & 40 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jokester/ts-commonutil",
"version": "0.4.2",
"version": "0.5.0",
"author": "Wang Guan <momocraft@gmail.com>",
"description": "Common TypeScript code for my multiple projects",
"repository": {
Expand All @@ -26,41 +26,35 @@
"util"
],
"engines": {
"node": ">=12"
"node": ">=16"
},
"module": "lib/index.js",
"main": "lib/index.js",
"engineStrict": true,
"license": "MIT",
"bugs": {
"url": "https://github.com/jokester/ts-commonutil/issues"
},
"homepage": "https://github.com/jokester/ts-commonutil#readme",
"dependencies": {
},
"peerDependencies": {
"tslib": "^2.4.0"
"tslib": "^2.6"
},
"devDependencies": {
"@types/jest": "^28",
"@types/node": "^16",
"@types/node": "^18",
"@types/react": "latest",
"@types/react-dom": "latest",
"codecov": "^3.8.3",
"eventemitter3": "^4",
"fp-ts": "<3",
"gts": "^3.1.0",
"gts": "^5.2.0",
"jest": "^28",
"loglevel": "^1.8.0",
"mobx": "^6.6.1",
"next": "^12.2",
"playwright": "^1.32.1",
"puppeteer": "^19.8.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rxjs": "^7",
"ts-jest": "^28",
"tslib": "^2.4.0",
"typescript": "^4.7",
"typescript": "^5.3",
"winston": "^3.8.0"
},
"exports": {
Expand Down Expand Up @@ -174,10 +168,10 @@
"require": "./lib/event-emitter/typed-event-emitter.js",
"type": "./lib/event-emitter/typed-event-emitter.d.ts"
},
"./lib/fp-ts-extension/monoid": {
"import": "./lib/__esm/fp-ts-extension/monoid.js",
"require": "./lib/fp-ts-extension/monoid.js",
"type": "./lib/fp-ts-extension/monoid.d.ts"
"./lib/fp-ts/monoid": {
"import": "./lib/__esm/fp-ts/monoid.js",
"require": "./lib/fp-ts/monoid.js",
"type": "./lib/fp-ts/monoid.d.ts"
},
"./lib/frontend/dummy-img": {
"import": "./lib/__esm/frontend/dummy-img.js",
Expand Down Expand Up @@ -244,11 +238,6 @@
"require": "./lib/obsolete/array-monad.js",
"type": "./lib/obsolete/array-monad.d.ts"
},
"./lib/puppeteer/puppeteer": {
"import": "./lib/__esm/puppeteer/puppeteer.js",
"require": "./lib/puppeteer/puppeteer.js",
"type": "./lib/puppeteer/puppeteer.d.ts"
},
"./lib/puppeteer/watch-res": {
"import": "./lib/__esm/puppeteer/watch-res.js",
"require": "./lib/puppeteer/watch-res.js",
Expand Down Expand Up @@ -334,16 +323,6 @@
"require": "./lib/react/mobx/use-derived.js",
"type": "./lib/react/mobx/use-derived.d.ts"
},
"./lib/react/next/link-a": {
"import": "./lib/__esm/react/next/link-a.jsx",
"require": "./lib/react/next/link-a.jsx",
"type": "./lib/react/next/link-a.d.ts"
},
"./lib/react/next/wrapped-next-router": {
"import": "./lib/__esm/react/next/wrapped-next-router.js",
"require": "./lib/react/next/wrapped-next-router.js",
"type": "./lib/react/next/wrapped-next-router.d.ts"
},
"./lib/react/util/prop-of": {
"import": "./lib/__esm/react/util/prop-of.js",
"require": "./lib/react/util/prop-of.js",
Expand All @@ -359,11 +338,6 @@
"require": "./lib/rxjs/stochastic-processes.js",
"type": "./lib/rxjs/stochastic-processes.d.ts"
},
"./lib/rxjs/tap-log": {
"import": "./lib/__esm/rxjs/tap-log.js",
"require": "./lib/rxjs/tap-log.js",
"type": "./lib/rxjs/tap-log.d.ts"
},
"./lib/text/chunk-to-lines": {
"import": "./lib/__esm/text/chunk-to-lines.js",
"require": "./lib/text/chunk-to-lines.js",
Expand All @@ -385,8 +359,8 @@
"type": "./lib/type/index.d.ts"
},
"./lib/type/omit": {
"import": "./lib/__esm/type/omit.jsx",
"require": "./lib/type/omit.jsx",
"import": "./lib/__esm/type/omit.js",
"require": "./lib/type/omit.js",
"type": "./lib/type/omit.d.ts"
},
"./lib/util/lru": {
Expand All @@ -403,10 +377,15 @@
"import": "./lib/__esm/util/randoms.js",
"require": "./lib/util/randoms.js",
"type": "./lib/util/randoms.d.ts"
},
"./lib/util/with-retry": {
"import": "./lib/__esm/util/with-retry.js",
"require": "./lib/util/with-retry.js",
"type": "./lib/util/with-retry.d.ts"
}
},
"resolutions": {
"@types/node": "16",
"@types/react": "^18"
}
}
}
5 changes: 4 additions & 1 deletion src/collection/default-map.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
export class DefaultMap<K, V> extends Map<K, V> {
constructor(private readonly createDefault: (k: K) => V, entries?: readonly [K, V][]) {
constructor(
private readonly createDefault: (k: K) => V,
entries?: readonly [K, V][],
) {
super(entries);
}

Expand Down
6 changes: 5 additions & 1 deletion src/collection/min-heap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ export class MinHeap<T> {
private readonly tree: T[] = [];
slice = this.tree.slice.bind(this.tree);

constructor(private readonly order: TotalOrdered<T>, private readonly strict = false, initialTree?: T[]) {
constructor(
private readonly order: TotalOrdered<T>,
private readonly strict = false,
initialTree?: T[],
) {
if (initialTree) this.tree.push(...initialTree);
if (strict) this.assertInvariants();
}
Expand Down
5 changes: 4 additions & 1 deletion src/collection/segment-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ export class SegmentTree<T> {
*/
private readonly sums: T[];

constructor(private readonly monoid: Monoid<T>, init: T[]) {
constructor(
private readonly monoid: Monoid<T>,
init: T[],
) {
const lenSums = powOf2.nextPowOf2(init.length);

this.elems = init.slice();
Expand Down
1 change: 1 addition & 0 deletions src/concurrency/async-throttle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export function asyncThrottle<T>(func: () => T | PromiseLike<T>, wait = 0): () =
/**
* @param func a supposedly idempotent function
* @param wait
* TODO should add a "longest wait"
*/
export function asyncDebounce<T>(func: () => T | PromiseLike<T>, wait = 0): () => PromiseLike<T> {
let pending: {
Expand Down
22 changes: 14 additions & 8 deletions src/concurrency/timing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,26 @@ export async function withTimeout<T>(p: PromiseLike<T>, delayMs: number): Promis
}

/**
* @param {number} minimumPeriod
* @param {() => Promise<T>} task
* @param waitOnException {boolean=true} wait even if task() throws
* @returns {Promise<T>}
* @param minDuration in ms
* @param io
* @param waitOnException wait even if task() throws
* @returns result of io()
*/
export async function withMinimumDuration<T>(
minimumPeriod: number,
task: () => Promise<T>,
minDuration: number,
io: () => Promise<T>,
waitOnException = true,
): Promise<T> {
const start = Date.now();
try {
return wait(minimumPeriod, task());
return await wait(minDuration, io());
} catch (e) {
if (waitOnException) await wait(minimumPeriod);
if (waitOnException) {
const elapsed = Date.now() - start;
if (elapsed < minDuration) {
await wait(minDuration - elapsed);
}
}
throw e;
}
}
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions src/node/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/**
* Read stream until end
* @deprecated use 'node:stream/consumers' instead.
* @see https://nodejs.org/api/webstreams.html#streamconsumersjsonstream
*/
export function readStream(stream: NodeJS.ReadableStream): Promise<Buffer> {
return new Promise<Buffer>((resolve, reject) => {
Expand All @@ -19,6 +21,9 @@ export function readStream(stream: NodeJS.ReadableStream): Promise<Buffer> {
});
}

/**
* @deprecated use 'node:fs/promises' instead.
*/
import * as fsp from './fsp';

export { fsp };
Empty file removed src/puppeteer/puppeteer.ts
Empty file.
6 changes: 2 additions & 4 deletions src/react/hook/use-in-server.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { useState, useLayoutEffect, useEffect } from 'react';

const useIsomorphicEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;
import { useState, useLayoutEffect } from 'react';

export function useInServer(): boolean {
const [inServer, setInServer] = useState(true);
useIsomorphicEffect(() => {
useLayoutEffect(() => {
setInServer(false);
}, []);

Expand Down
13 changes: 0 additions & 13 deletions src/react/next/link-a.tsx

This file was deleted.

78 changes: 0 additions & 78 deletions src/react/next/wrapped-next-router.ts

This file was deleted.

21 changes: 0 additions & 21 deletions src/rxjs/tap-log.ts

This file was deleted.

File renamed without changes.
2 changes: 1 addition & 1 deletion src/util/lru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* i.e. they do no use timeout/promise/async,await,
* and will not run before/after function calls.
*
* @export
* @class SingleThreadedLRU
* @template T {type} type of cached values, must be non-falsy
* @deprecated prefer npm/flru instead, as fox said
*/
export class SingleThreadedLRU<T> {
private readonly values = new Map<string, T>();
Expand Down
4 changes: 0 additions & 4 deletions src/util/randoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,3 @@ function sample<T>(from: ReadonlyArray<T>, count: number): T[] {

return sampled;
}

export const Randoms = {
sample,
};
Loading

0 comments on commit c6eec7d

Please sign in to comment.