Skip to content

Commit

Permalink
Merge branch 'release/release/0.13.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
holtwick committed Sep 5, 2023
2 parents bb08daf + ead81ce commit cc2b117
Show file tree
Hide file tree
Showing 17 changed files with 244 additions and 194 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"**/dist/**",
"**/cypress/**",
"**/.{idea,git,cache,output,temp}/**"
]
],
"typescript.tsdk": "node_modules/typescript/lib"
}
62 changes: 32 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
{
"name": "zeed",
"type": "module",
"version": "0.11.5",
"version": "0.13.1",
"description": "🌱 Simple foundation library",
"author": {
"name": "Dirk Holtwick",
"email": "[email protected]",
"url": "https://holtwick.de"
},
"license": "MIT",
"funding": {
"type": "GitHub Sponsors ❤",
"url": "https://github.com/sponsors/holtwick"
},
"homepage": "https://github.com/holtwick/zeed",
"repository": {
"type": "git",
"url": "https://github.com/holtwick/zeed.git"
},
"bugs": {
"url": "https://github.com/holtwick/zeed/issues"
},
"keywords": [
"foundation",
"typescript",
Expand All @@ -31,7 +12,26 @@
"utils",
"zeed"
],
"homepage": "https://github.com/holtwick/zeed",

Check failure on line 15 in package.json

View workflow job for this annotation

GitHub Actions / build

Expected object keys to be in specified order. 'homepage' should be before 'keywords'
"bugs": {
"url": "https://github.com/holtwick/zeed/issues"
},
"repository": {

Check failure on line 19 in package.json

View workflow job for this annotation

GitHub Actions / build

Expected object keys to be in specified order. 'repository' should be before 'bugs'
"type": "git",
"url": "https://github.com/holtwick/zeed.git"
},
"funding": {

Check failure on line 23 in package.json

View workflow job for this annotation

GitHub Actions / build

Expected object keys to be in specified order. 'funding' should be before 'repository'
"type": "GitHub Sponsors ❤",
"url": "https://github.com/sponsors/holtwick"
},
"license": "MIT",

Check failure on line 27 in package.json

View workflow job for this annotation

GitHub Actions / build

Expected object keys to be in specified order. 'license' should be before 'funding'
"author": {

Check failure on line 28 in package.json

View workflow job for this annotation

GitHub Actions / build

Expected object keys to be in specified order. 'author' should be before 'license'
"name": "Dirk Holtwick",
"email": "[email protected]",
"url": "https://holtwick.de"
},
"sideEffects": false,
"type": "module",

Check failure on line 34 in package.json

View workflow job for this annotation

GitHub Actions / build

Expected object keys to be in specified order. 'type' should be before 'sideEffects'
"exports": {
".": {
"types": "./dist/index.all.d.ts",
Expand All @@ -47,35 +47,37 @@
"files": [
"dist"
],
"engines": {
"node": ">=14.13.1"
},
"scripts": {
"build": "nr clean && nr build:tsup",
"build:tsup": "tsup src/index.all.ts --dts-only && tsup src/index.browser.ts src/index.node.ts",
"check": "tsc --noEmit -p tsconfig.json",
"circles": "madge --circular --summary --orphans --leaves --warning --extensions ts src",
"clean": "rm -rf dist",
"coverage": "vitest --run --coverage",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"prepublishOnly": "nr build && nr test:publish",
"prepublishOnly": "nr build && nr circles && nr lint && nr test:publish",
"release": "na version patch && na publish",
"start": "nr watch",
"test": "vitest",
"test:publish": "vitest --run",
"watch": "nr build:tsup -- --watch",
"release": "na version patch && na publish"
"watch": "nr build:tsup -- --watch"
},
"devDependencies": {
"@antfu/eslint-config": "^0.41.0",
"@antfu/ni": "^0.21.6",
"@types/node": "^20.5.6",
"@antfu/ni": "^0.21.8",
"@types/node": "<20",
"c8": "^8.0.1",
"cross-fetch": "^4.0.0",
"esbuild": "^0.19.2",
"eslint": "^8.47.0",
"eslint": "^8.48.0",
"madge": "^6.1.0",
"tsup": "^7.2.0",
"typescript": "^5.2.2",
"vite": "^4.4.9",
"vitest": "^0.34.2"
"vitest": "^0.34.3"
},
"engines": {

Check failure on line 80 in package.json

View workflow job for this annotation

GitHub Actions / build

Expected object keys to be in specified order. 'engines' should be before 'devDependencies'
"node": ">=18"
}
}
14 changes: 0 additions & 14 deletions src/common/bin/lib0/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,6 @@ export function createUint8ArrayFromLen(len: number) {
return new Uint8Array(len)
}

/**
* Create Uint8Array with initial content from buffer
*/
export function createUint8ArrayViewFromArrayBuffer(buffer: ArrayBuffer, byteOffset: number, length: number) {
return new Uint8Array(buffer, byteOffset, length)
}

/**
* Create Uint8Array with initial content from buffer
*/
export function createUint8ArrayFromArrayBuffer(buffer: ArrayBuffer) {
return new Uint8Array(buffer)
}

/**
* Copy the content of an Uint8Array view to a new ArrayBuffer.
*/
Expand Down
19 changes: 19 additions & 0 deletions src/common/bin/lib0/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Original at https://github.com/dmonad/lib0
*
* Utility functions to work with buffers (Uint8Array).
*/

/**
* Create Uint8Array with initial content from buffer
*/
export function createUint8ArrayViewFromArrayBuffer(buffer: ArrayBuffer, byteOffset: number, length: number) {
return new Uint8Array(buffer, byteOffset, length)
}

/**
* Create Uint8Array with initial content from buffer
*/
export function createUint8ArrayFromArrayBuffer(buffer: ArrayBuffer) {
return new Uint8Array(buffer)
}
2 changes: 1 addition & 1 deletion src/common/bin/lib0/decoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/

import { BIT7, BIT8, BITS6, BITS7 } from './binary'
import { createUint8ArrayViewFromArrayBuffer } from './buffer'
import { createUint8ArrayViewFromArrayBuffer } from './create'
import { getUtf8TextDecoder } from './string'

const errorUnexpectedEndOfArray = 'Unexpected end of array'
Expand Down
2 changes: 1 addition & 1 deletion src/common/bin/lib0/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/

import { BIT7, BIT8, BITS31, BITS6, BITS7, BITS8 } from './binary'
import { createUint8ArrayViewFromArrayBuffer } from './buffer'
import { createUint8ArrayViewFromArrayBuffer } from './create'
import { encodeUtf8, getUtf8TextEncoder } from './string'

/**
Expand Down
22 changes: 22 additions & 0 deletions src/common/dispose-defer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,26 @@ describe('dispose', () => {
// expect(stack).toEqual(['b', 'a'])
})

// TODO future
// it("should use using", async () => {
// class TempFile implements Disposable {

// constructor(path: string) {
// console.log('constructor')
// }

// [Symbol.dispose]() {
// console.log('dispose')
// }
// }

// function fn() {
// using f = new TempFile('abc')
// console.log('fn return')
// }

// console.log('fn before')
// fn()
// console.log('fn after')
// })
})
9 changes: 4 additions & 5 deletions src/common/dispose-defer.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { Disposer, DisposerFunction } from './dispose-types'
import { isString } from './data'
import { arrayFilterInPlace } from './data/array'
import type { Disposer, DisposerFunction } from './dispose-types'
import { isPromise } from './exec/promise'
import { DefaultLogger } from './log'
import type { LoggerInterface } from './log-base'
import { useEventListener, useInterval, useTimeout } from './dispose-utils'

/** Different kinds of implementations have grown, this should unify them */
function callDisposer(disposable: Disposer): Promise<void> | void {
Expand Down Expand Up @@ -111,9 +110,9 @@ export function useDispose(config?: string | UseDisposeConfig | LoggerInterface)
},

// Utils
timeout: (fn: DisposerFunction, timeout = 0) => track(useTimeout(fn, timeout)),
interval: (fn: DisposerFunction, interval = 0) => track(useInterval(fn, interval)),
on: (emitter: any, eventName: string, fn: (ev?: any) => void, ...args: any[]) => track(useEventListener(emitter, eventName, fn, ...args)),
// timeout: (fn: DisposerFunction, timeout = 0) => track(useTimeout(fn, timeout)),
// interval: (fn: DisposerFunction, interval = 0) => track(useInterval(fn, interval)),
// on: (emitter: any, eventName: string, fn: (ev?: any) => void, ...args: any[]) => track(useEventListener(emitter, eventName, fn, ...args)),
})
}

Expand Down
6 changes: 0 additions & 6 deletions src/common/dispose-types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { UseDispose } from './dispose-defer'

// https://blog.hediet.de/post/the_disposable_pattern_in_typescript
// todo adopt for `using` https://www.totaltypescript.com/typescript-5-2-new-keyword-using

Expand All @@ -10,7 +8,3 @@ export type Disposer = DisposerFunction |
dispose?: DisposerFunction | Promise<unknown>
cleanup?: DisposerFunction | Promise<unknown> // deprecated, but used often in my old code
}

export interface Disposable {
dispose: UseDispose
}
24 changes: 24 additions & 0 deletions src/common/dispose-utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { DisposerFunction } from './dispose-types'
import { promisify } from './exec'

export function useTimeout(
fn: DisposerFunction,
Expand All @@ -23,6 +24,29 @@ export function useInterval(fn: DisposerFunction, interval: number): DisposerFun
}
}

/** The interval starts only, when the function is finished. */
export function useIntervalPause(fn: DisposerFunction, interval: number, immediately = false): DisposerFunction {
let intervalHandle: any
let stop = false

async function loop(exec = false) {
if (exec)
await promisify(fn())
if (!stop)
intervalHandle = setTimeout(() => loop(true), interval)
}

void loop(immediately)

return () => {
if (intervalHandle) {
stop = true
clearInterval(intervalHandle)
intervalHandle = undefined
}
}
}

export function useEventListener(
emitter: any,
eventName: string,
Expand Down
1 change: 1 addition & 0 deletions src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export * from './log'
export * from './log-base'
export * from './log-colors'
export * from './log-console'
export * from './log-context'
export * from './log-filter'
export * from './log-memory'
export * from './msg'
Expand Down
Loading

0 comments on commit cc2b117

Please sign in to comment.