Skip to content

Commit

Permalink
Merge branch 'release/v0.16.11'
Browse files Browse the repository at this point in the history
  • Loading branch information
holtwick committed Feb 9, 2024
2 parents 6fcce80 + e0c45d9 commit 19c987f
Show file tree
Hide file tree
Showing 76 changed files with 72 additions and 198 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ Overview of available IDs:

Typed and async emitter:

```ts
```
interface MyEvents {
inc: (count: number) => number
}
Expand All @@ -169,13 +169,13 @@ await e.emit('inc', 1) // counter === 1

It is also possible to alternatively use a Proxy called `.call` that makes nice dynamic function calls of the events:

```ts
```
await e.call.inc(1)
```

We can also alternatively declare the listeners this way:

```ts
```
e.onCall({
async inc(count: number): number {
return counter + 1
Expand All @@ -185,7 +185,7 @@ e.onCall({

You can also use a global emitter that will be available even over module boundaries:

```ts
```
declare global {
interface ZeedGlobalEmitter {
test: (x: string) => void
Expand All @@ -200,7 +200,7 @@ getGlobalEmitter().call.test('Hello World')

Communicating to servers or other remote parts through messages as if they were methods on a local object in a type safe way:

```ts
```
const m = useMessageHub({ cannel }).send<MyMessages>()
m.echo({ hello: 'world' })
```
Expand All @@ -211,7 +211,7 @@ m.echo({ hello: 'world' })

A conflict free sorting algorithm with minimal data changes. Just extend an object from `SortableItem`, which will provide an additional property of type number called `sort_weight`.

```ts
```
interface Row extends SortedItem {
id: string
title: string
Expand Down Expand Up @@ -260,7 +260,7 @@ deepMerge({ a: { b: 1 } }, { c: 3, a: { d: 4 } }) // {a:{b:1, d:4}, c:4}

`useDispose` will simplify cleaning up objects. You just need to `add` a function or and object with `dispose` method to be called for cleanup. This can also be nested. A simple example is a timer:

```ts
```
function disposableTimer() {
const timeout = setTimeout(() => console.log('hello world'), 1000)
return () => clearTimeout(timeout)
Expand All @@ -285,7 +285,7 @@ You can also `untrack` single entries. Entries are untracked LIFO. Disposers can

The disposer itself is also a call to dispose i.e. for convenience you can add it to objects and provide `dispose` easily like this:

```ts
```
class DisposeExample {
// the trick is to assign to member `dispose`, will be both
// the destructor and the registration point for disposables
Expand Down
1 change: 1 addition & 0 deletions demos/logging/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

/* eslint-disable no-console */

import process from 'node:process'
import { Logger, setupEnv } from 'zeed'

// Read .env file
Expand Down
2 changes: 2 additions & 0 deletions demos/node-cjs/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Simple demo for node and CommonJS loading

import process from 'node:process'

const {
Logger,
setupEnv,
Expand Down
2 changes: 2 additions & 0 deletions demos/node/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Simple demo for node and CommonJS loading

import process from 'node:process'

import {
Logger,
digest,
Expand Down
14 changes: 7 additions & 7 deletions demos/sideeffects/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Use something like `const x = 9007199254740991` instead, if it makes sense in yo

Defining `const` for primitives (string, number, boolean, etc.) and simple objects is fine, but as soon as a call is involved, this causes problems. Examples:

```ts
```
// THOSE ARE WRONG!
const argh = new Error('argh error')
Expand All @@ -31,13 +31,13 @@ const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER

Sometimes you just need one object instance to work with and it logical to use a constant that holds the object, but this is not side effects free:

```ts
```
export const utf8TextEncoder = typeof TextEncoder !== 'undefined' ? new TextEncoder() : null
```

Better access it dynamically through a getter and instantiate on first use. This has only a small overhead. In this example `null` is used to indicate, that the native `TextEncoder` is not available therefore note the comparison with `undefined` (usually we would prefer `== null` in such a scenario):

```ts
```
let utf8TextEncoder: TextEncoder | undefined | null
export function getUtf8TextEncoder(): TextEncoder | null {
Expand All @@ -51,7 +51,7 @@ export function getUtf8TextEncoder(): TextEncoder | null {

You might want to use a fancy factory like

```ts
```
function makeEncoder(forBits:number) {
return {
encode() { /* ... */ },
Expand All @@ -64,7 +64,7 @@ const { encode: encode64, decode: decode64 } = makeEncoder(64)

Great abstraction! But it will live forever after tree-shaking. Instead, you'll have to do an extra loop and be more dynamic:

```ts
```
let cache
function getEncoder(forBits:number) {
Expand All @@ -88,15 +88,15 @@ function encode64(data) {

Logging often follows this pattern at the top level of a file:

```ts
```
const log = Logger("fancy")
```

This is a constant that stays, whether used or not.

Avoid logging or do it lazily inside the function. As for [zeed](https://github.com/holtwick/zeed), I go even further and only use logging if the importing application uses logging, which looks like this

```ts
```
getGlobalLoggerIfExists()?.('fanzy')?.info('Just FYI')
```

Expand Down
1 change: 1 addition & 0 deletions demos/vite/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
import { createApp } from 'vue'

// import { Logger } from 'zeed'
Expand Down
2 changes: 1 addition & 1 deletion demos/vite/src/shims-vue.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
declare module '*.vue' {
import type { DefineComponent } from 'vue'

const component: DefineComponent<{}, {}, any>
const component: DefineComponent<object, object, any>
export default component
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "zeed",
"type": "module",
"version": "0.16.10",
"version": "0.16.11",
"description": "🌱 Simple foundation library",
"author": {
"name": "Dirk Holtwick",
Expand Down
2 changes: 0 additions & 2 deletions src/browser/base64.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

/** @deprecated use fromBase64 instead */
export function urlBase64ToUint8Array(base64String: string): Uint8Array | undefined {
const padding = '='.repeat((4 - (base64String.length % 4)) % 4)
Expand Down
2 changes: 0 additions & 2 deletions src/browser/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

export * from './base64'
export * from './gravatar'
export * from './localstorage'
Expand Down
2 changes: 0 additions & 2 deletions src/browser/localstorage.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

export {}
// import { isBrowser } from "../common/platform"
// import { LocalStorage } from "./localStorage"
Expand Down
2 changes: 0 additions & 2 deletions src/browser/localstorage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

import type { Json, ObjectStorage } from '../common/types'
import { jsonStringifySafe } from '../common/data/json'

Expand Down
2 changes: 0 additions & 2 deletions src/browser/log/log-browser-factory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

/* eslint-disable no-console */

import type { LogHandlerOptions, LogLevel, LogLevelAliasType, LoggerInterface } from '../../common/log/log-base'
Expand Down
2 changes: 0 additions & 2 deletions src/browser/log/log-browser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

/* eslint-disable no-console */

import type { LogHandler, LogHandlerOptions, LogMessage } from '../../common/log/log-base'
Expand Down
2 changes: 0 additions & 2 deletions src/common/crypto.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

/* eslint-disable prefer-spread */
/* eslint-disable no-cond-assign */

Expand Down
2 changes: 0 additions & 2 deletions src/common/data/array.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

import {
arrayAvg,
arrayBatches,
Expand Down
2 changes: 0 additions & 2 deletions src/common/data/array.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

/* eslint-disable no-cond-assign */

import type { NestedArray } from '../types'
Expand Down
2 changes: 0 additions & 2 deletions src/common/data/basex.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

/* eslint-disable node/prefer-global/buffer */

import { estimateSizeForBase, useBase } from './basex'
Expand Down
2 changes: 0 additions & 2 deletions src/common/data/bin.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

/* eslint-disable node/prefer-global/buffer */

import { Uint8ArrayToHexDump, Uint8ArrayToString, equalBinary, fromBase64String, fromHex, joinToUint8Array, stringToUInt8Array, toBase64, toBase64Url, toHex, toUint8Array } from './bin'
Expand Down
2 changes: 0 additions & 2 deletions src/common/data/camelcase.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

import {
fromCamelCase,
toCamelCase,
Expand Down
2 changes: 0 additions & 2 deletions src/common/data/convert.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

import { renderMessages, valueToInteger, valueToString } from './convert'

describe('convert', () => {
Expand Down
2 changes: 0 additions & 2 deletions src/common/data/convert.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

import { Uint8ArrayToHexDump } from './bin'

// import { jsonStringify } from './json'
Expand Down
2 changes: 0 additions & 2 deletions src/common/data/deep.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

/* eslint-disable no-new-wrappers */

import { DefaultLogger } from '../log'
Expand Down
2 changes: 0 additions & 2 deletions src/common/data/deep.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

/* eslint-disable no-prototype-builtins */

import { isArray, isObject, isPrimitive, isRecord } from './is'
Expand Down
2 changes: 0 additions & 2 deletions src/common/data/is.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

import { isEmpty, isNotEmpty, isNotNull, isNumber, isObject, isPrimitive, isRecord, isRecordPlain, isTruthy, isUint8Array, isValue } from './is'

describe('is', () => {
Expand Down
2 changes: 0 additions & 2 deletions src/common/data/json.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

import jsonParse, { jsonStringifySafe, jsonStringifySorted } from './json'

describe('convert', () => {
Expand Down
2 changes: 0 additions & 2 deletions src/common/data/orderby.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

import { composeOrderby, parseOrderby, sortedOrderby } from './orderby'

describe('order by', () => {
Expand Down
2 changes: 0 additions & 2 deletions src/common/data/orderby.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

export function parseOrderby(value = ''): {
field: string
orderby: string
Expand Down
2 changes: 0 additions & 2 deletions src/common/data/sortable.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

import { arrayShuffleForce, arrayShuffleInPlace } from './array'
import type { SortableItem } from './sortable'
import {
Expand Down
2 changes: 0 additions & 2 deletions src/common/data/sortable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

import { getSecureRandomIfPossible } from './math'

// Get a sort_weight suitable for adding to top of list
Expand Down
2 changes: 0 additions & 2 deletions src/common/data/sorted.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

import { arrayShuffleForce, arrayShuffleInPlace, last } from '..'

import { useSorted } from './sorted'
Expand Down
2 changes: 0 additions & 2 deletions src/common/data/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

import { sleep } from '../exec'
import {
cloneObject,
Expand Down
2 changes: 0 additions & 2 deletions src/common/data/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

import type { Json } from '../types'
import { jsonStringifySafe } from './json'

Expand Down
2 changes: 0 additions & 2 deletions src/common/exec/mutex.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

import { useAsyncMutex, useMutex } from './mutex'

describe('mutex', () => {
Expand Down
2 changes: 0 additions & 2 deletions src/common/exec/mutex.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

import { isPromise } from './promise'

export type Mutex = (fn: (() => void), elseFn?: (() => void)) => boolean
Expand Down
2 changes: 0 additions & 2 deletions src/common/exec/promise.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

import {
createPromise,
isPromise,
Expand Down
2 changes: 0 additions & 2 deletions src/common/exec/queue.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

import { sleep } from './promise'
import { SerialQueue } from './queue'

Expand Down
2 changes: 0 additions & 2 deletions src/common/exec/queue.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

// Can learn from here https://github.com/sindresorhus/p-queue

import { DefaultLogger } from '../log'
Expand Down
2 changes: 0 additions & 2 deletions src/common/exec/throttle-debounce.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

import { sleep } from './promise'
import { debounce, throttle } from './throttle-debounce'

Expand Down
2 changes: 0 additions & 2 deletions src/common/global.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

import { getGlobalContext } from './global'

declare global {
Expand Down
2 changes: 0 additions & 2 deletions src/common/localhost.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

import { isLocalHost } from './localhost'

describe('localhost', () => {
Expand Down
2 changes: 0 additions & 2 deletions src/common/localhost.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved.

export function isLocalHost(
hostname: string = globalThis?.location?.hostname ?? '',
): boolean {
Expand Down
Loading

0 comments on commit 19c987f

Please sign in to comment.