@greendrake/util 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/package.json +6 -2
- package/src/StalenessDetector.ts +1 -1
- package/src/browser.ts +6 -0
- package/src/locale.ts +1 -1
- package/src/main.ts +0 -2
package/README.md
CHANGED
|
@@ -151,7 +151,7 @@ document.documentElement.dir = isRTLLocale(navigator.language) ? 'rtl' : 'ltr'
|
|
|
151
151
|
|
|
152
152
|
## DOM and geolocation
|
|
153
153
|
|
|
154
|
-
Importable in Node;
|
|
154
|
+
The `./browser` entry, apart from the rest because their types are the DOM lib's: a program that type-checks without it — a bun service reaching this package through `@greendrake/rpc` — never compiles them. Importable in Node all the same; they touch `document`, `window` and `navigator` only when called.
|
|
155
155
|
|
|
156
156
|
- `getReadyStatePromise()` — resolves when `document.readyState` reaches `'complete'` (immediately if it already has); one shared promise per module instance.
|
|
157
157
|
- `hasFinePointer()` — `matchMedia('(hover: hover) and (pointer: fine)')`: true where the primary input is a mouse or trackpad rather than a finger. Serves as a proxy for "focusing a field will not raise an on-screen keyboard", which no platform exposes directly.
|
|
@@ -159,7 +159,7 @@ Importable in Node; these touch `document`, `window` and `navigator` only when c
|
|
|
159
159
|
- `getUserLocation(): Promise<UserLocation>` — `navigator.geolocation.getCurrentPosition` with `timeout: LOCATION_TIMEOUT_MS` (5000) and `maximumAge: LOCATION_MAX_AGE_MS` (60000); resolves `{ latitude, longitude }`, rejects with the geolocation error, or with `Error('Location unknown')` when the position carries no coords. The two constants are exported so an app that obtains the position from a platform API instead uses the same numbers.
|
|
160
160
|
|
|
161
161
|
```ts
|
|
162
|
-
import { getReadyStatePromise, getUserLocation, hasFinePointer, toggleFullscreen } from '@greendrake/util'
|
|
162
|
+
import { getReadyStatePromise, getUserLocation, hasFinePointer, toggleFullscreen } from '@greendrake/util/browser'
|
|
163
163
|
|
|
164
164
|
await getReadyStatePromise()
|
|
165
165
|
if (hasFinePointer()) input.focus()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@greendrake/util",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Framework-free, Node-safe utilities: typed event emitter, timing, retry, staleness, comparators, fetch helpers, misc",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Eugene Greendrake <eugene@greendrake.nz>",
|
|
@@ -20,6 +20,10 @@
|
|
|
20
20
|
".": {
|
|
21
21
|
"types": "./src/main.ts",
|
|
22
22
|
"default": "./src/main.ts"
|
|
23
|
+
},
|
|
24
|
+
"./browser": {
|
|
25
|
+
"types": "./src/browser.ts",
|
|
26
|
+
"default": "./src/browser.ts"
|
|
23
27
|
}
|
|
24
28
|
},
|
|
25
29
|
"files": [
|
|
@@ -34,7 +38,7 @@
|
|
|
34
38
|
},
|
|
35
39
|
"prettier": "@greendrake/dev-config/prettier",
|
|
36
40
|
"devDependencies": {
|
|
37
|
-
"@greendrake/dev-config": "0.
|
|
41
|
+
"@greendrake/dev-config": "0.2.0",
|
|
38
42
|
"typescript": "6.0.3"
|
|
39
43
|
}
|
|
40
44
|
}
|
package/src/StalenessDetector.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface StalenessEvents {
|
|
|
11
11
|
// drops and 'stale' fires. Events fire only on transitions.
|
|
12
12
|
export class StalenessDetector extends Emitter<StalenessEvents> {
|
|
13
13
|
#ttlMs: number
|
|
14
|
-
#timeout
|
|
14
|
+
#timeout: ReturnType<typeof setTimeout> | undefined
|
|
15
15
|
#fresh = false
|
|
16
16
|
|
|
17
17
|
constructor(ttlMs: number) {
|
package/src/browser.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// The helpers that name the document, the window or the navigator. An entry of
|
|
2
|
+
// their own rather than part of the main one: a program that type-checks
|
|
3
|
+
// without the DOM lib — a bun service importing @greendrake/rpc — would
|
|
4
|
+
// otherwise have to compile them, and fail to, for helpers it never calls.
|
|
5
|
+
export { getReadyStatePromise, hasFinePointer, toggleFullscreen } from './dom'
|
|
6
|
+
export { getUserLocation, LOCATION_TIMEOUT_MS, LOCATION_MAX_AGE_MS, type UserLocation } from './geo'
|
package/src/locale.ts
CHANGED
|
@@ -8,4 +8,4 @@
|
|
|
8
8
|
// be able to disagree.
|
|
9
9
|
export const RTL_LANGUAGES: readonly string[] = ['ar', 'fa', 'he', 'ur', 'ps', 'sd', 'ug', 'yi']
|
|
10
10
|
|
|
11
|
-
export const isRTLLocale = (tag: string): boolean => RTL_LANGUAGES.includes(tag.
|
|
11
|
+
export const isRTLLocale = (tag: string): boolean => RTL_LANGUAGES.includes(tag.replace(/-.*/, ''))
|
package/src/main.ts
CHANGED
|
@@ -5,6 +5,4 @@ export { Retrier, RetryStopped, type RetrierOptions, type RetrierEvents } from '
|
|
|
5
5
|
export { StalenessDetector, type StalenessEvents } from './StalenessDetector'
|
|
6
6
|
export { composeComparators, byProp, byPreset, type Comparator } from './compare'
|
|
7
7
|
export { NetworkError, HttpError, safeFetch, fetchJson } from './net'
|
|
8
|
-
export { getReadyStatePromise, hasFinePointer, toggleFullscreen } from './dom'
|
|
9
|
-
export { getUserLocation, LOCATION_TIMEOUT_MS, LOCATION_MAX_AGE_MS, type UserLocation } from './geo'
|
|
10
8
|
export { RTL_LANGUAGES, isRTLLocale } from './locale'
|