@naturalcycles/js-lib 15.84.1 → 15.86.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/dist/decorators/index.d.ts +2 -2
- package/dist/decorators/index.js +2 -2
- package/dist/decorators/{memoFn.d.ts → memoized.d.ts} +1 -3
- package/dist/decorators/{memoFn.js → memoized.js} +1 -3
- package/dist/decorators/{memoFnAsync.d.ts → memoizedAsync.d.ts} +1 -4
- package/dist/decorators/{memoFnAsync.js → memoizedAsync.js} +1 -4
- package/dist/ua/ua.d.ts +113 -0
- package/dist/ua/ua.js +1297 -0
- package/package.json +3 -2
- package/src/decorators/index.ts +2 -2
- package/src/decorators/{memoFn.ts → memoized.ts} +1 -3
- package/src/decorators/{memoFnAsync.ts → memoizedAsync.ts} +1 -4
- package/src/ua/ua.ts +1473 -0
|
@@ -6,7 +6,7 @@ export * from './decorator.util.js';
|
|
|
6
6
|
export * from './logMethod.decorator.js';
|
|
7
7
|
export * from './memo.decorator.js';
|
|
8
8
|
export * from './memo.util.js';
|
|
9
|
-
export * from './
|
|
10
|
-
export * from './
|
|
9
|
+
export * from './memoized.js';
|
|
10
|
+
export * from './memoizedAsync.js';
|
|
11
11
|
export * from './retry.decorator.js';
|
|
12
12
|
export * from './timeout.decorator.js';
|
package/dist/decorators/index.js
CHANGED
|
@@ -6,7 +6,7 @@ export * from './decorator.util.js';
|
|
|
6
6
|
export * from './logMethod.decorator.js';
|
|
7
7
|
export * from './memo.decorator.js';
|
|
8
8
|
export * from './memo.util.js';
|
|
9
|
-
export * from './
|
|
10
|
-
export * from './
|
|
9
|
+
export * from './memoized.js';
|
|
10
|
+
export * from './memoizedAsync.js';
|
|
11
11
|
export * from './retry.decorator.js';
|
|
12
12
|
export * from './timeout.decorator.js';
|
|
@@ -8,7 +8,5 @@ export interface MemoizedFunction {
|
|
|
8
8
|
* Only supports Sync functions.
|
|
9
9
|
* To support Async functions - use _memoFnAsync.
|
|
10
10
|
* Technically, you can use it with Async functions, but it'll return the Promise without awaiting it.
|
|
11
|
-
*
|
|
12
|
-
* @experimental
|
|
13
11
|
*/
|
|
14
|
-
export declare function
|
|
12
|
+
export declare function _memoized<FN extends AnyFunction>(fn: FN, opt?: MemoOptions<FN>): FN & MemoizedFunction;
|
|
@@ -3,10 +3,8 @@ import { jsonMemoSerializer, MapMemoCache } from './memo.util.js';
|
|
|
3
3
|
* Only supports Sync functions.
|
|
4
4
|
* To support Async functions - use _memoFnAsync.
|
|
5
5
|
* Technically, you can use it with Async functions, but it'll return the Promise without awaiting it.
|
|
6
|
-
*
|
|
7
|
-
* @experimental
|
|
8
6
|
*/
|
|
9
|
-
export function
|
|
7
|
+
export function _memoized(fn, opt = {}) {
|
|
10
8
|
const { logger = console, cacheFactory = () => new MapMemoCache(), cacheKeyFn = jsonMemoSerializer, } = opt;
|
|
11
9
|
const cache = cacheFactory();
|
|
12
10
|
const memoizedFn = function (...args) {
|
|
@@ -4,7 +4,4 @@ import type { AsyncMemoCache } from './memo.util.js';
|
|
|
4
4
|
export interface MemoizedAsyncFunction {
|
|
5
5
|
cache: AsyncMemoCache;
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
* @experimental
|
|
9
|
-
*/
|
|
10
|
-
export declare function _memoFnAsync<FN extends AnyAsyncFunction>(fn: FN, opt: AsyncMemoOptions<FN>): FN & MemoizedAsyncFunction;
|
|
7
|
+
export declare function _memoizedAsync<FN extends AnyAsyncFunction>(fn: FN, opt: AsyncMemoOptions<FN>): FN & MemoizedAsyncFunction;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { MISS } from '../types.js';
|
|
2
2
|
import { jsonMemoSerializer } from './memo.util.js';
|
|
3
|
-
|
|
4
|
-
* @experimental
|
|
5
|
-
*/
|
|
6
|
-
export function _memoFnAsync(fn, opt) {
|
|
3
|
+
export function _memoizedAsync(fn, opt) {
|
|
7
4
|
const { logger = console, cacheFactory, cacheKeyFn = jsonMemoSerializer } = opt;
|
|
8
5
|
const cache = cacheFactory();
|
|
9
6
|
const memoizedFn = async function (...args) {
|
package/dist/ua/ua.d.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/// <reference lib="dom" preserve="true" />
|
|
2
|
+
export type UADeviceType = 'console' | 'mobile' | 'tablet' | 'smarttv' | 'wearable' | 'embedded';
|
|
3
|
+
export interface UABrowser {
|
|
4
|
+
/**
|
|
5
|
+
* E.g Chrome, Edge, Firefox, Safari, Mobile Safari, Opera, IE, UCBrowser, WeChat, ...
|
|
6
|
+
*/
|
|
7
|
+
name: string | undefined;
|
|
8
|
+
version: string | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Major version, e.g. '20' for version '20.0.1090.0'.
|
|
11
|
+
*/
|
|
12
|
+
major: string | undefined;
|
|
13
|
+
}
|
|
14
|
+
export interface UACpu {
|
|
15
|
+
/**
|
|
16
|
+
* E.g 68k, amd64, arm, arm64, armhf, avr, ia32, ia64, irix, irix64, mips, mips64,
|
|
17
|
+
* pa-risc, ppc, sparc, sparc64.
|
|
18
|
+
*/
|
|
19
|
+
architecture: string | undefined;
|
|
20
|
+
}
|
|
21
|
+
export interface UADevice {
|
|
22
|
+
/**
|
|
23
|
+
* E.g Apple, Samsung, Huawei, Xiaomi, Google, Sony, LG, Microsoft, Amazon, ...
|
|
24
|
+
*/
|
|
25
|
+
vendor: string | undefined;
|
|
26
|
+
model: string | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Undefined means "desktop-like" (no specific device type detected).
|
|
29
|
+
*/
|
|
30
|
+
type: UADeviceType | undefined;
|
|
31
|
+
}
|
|
32
|
+
export interface UAEngine {
|
|
33
|
+
/**
|
|
34
|
+
* E.g Blink, Gecko, WebKit, EdgeHTML, Presto, Trident, ...
|
|
35
|
+
*/
|
|
36
|
+
name: string | undefined;
|
|
37
|
+
version: string | undefined;
|
|
38
|
+
}
|
|
39
|
+
export interface UAOS {
|
|
40
|
+
/**
|
|
41
|
+
* E.g Windows, iOS, Mac OS, Android, Linux, Chromium OS, ...
|
|
42
|
+
*/
|
|
43
|
+
name: string | undefined;
|
|
44
|
+
version: string | undefined;
|
|
45
|
+
}
|
|
46
|
+
export interface UAResult {
|
|
47
|
+
ua: string;
|
|
48
|
+
browser: UABrowser;
|
|
49
|
+
engine: UAEngine;
|
|
50
|
+
os: UAOS;
|
|
51
|
+
device: UADevice;
|
|
52
|
+
cpu: UACpu;
|
|
53
|
+
}
|
|
54
|
+
export type UAMapperFn = (match: string) => string | undefined;
|
|
55
|
+
export type UAStrMap = Record<string, string | string[]>;
|
|
56
|
+
/**
|
|
57
|
+
* Describes how a regex capture group is assigned to a result property:
|
|
58
|
+
* - `prop` - assign the raw match
|
|
59
|
+
* - `[prop, value]` - assign a fixed value (ignore the match)
|
|
60
|
+
* - `[prop, fn]` - assign `fn(match)`
|
|
61
|
+
* - `[prop, regex, replacement]` - assign `match.replace(regex, replacement)`
|
|
62
|
+
* - `[prop, fn, map]` - assign `fn(match, map)` (string-map lookup)
|
|
63
|
+
* - `[prop, regex, replacement, fn]` - assign `fn(match.replace(regex, replacement))`
|
|
64
|
+
*/
|
|
65
|
+
export type UAAction = string | readonly [string, string] | readonly [string, UAMapperFn] | readonly [string, RegExp, string] | readonly [string, (str: string, map: UAStrMap) => string | undefined, UAStrMap] | readonly [string, RegExp, string, UAMapperFn];
|
|
66
|
+
/**
|
|
67
|
+
* Alternating sequence of regex-list and action-list:
|
|
68
|
+
* `[RegExp[], UAAction[], RegExp[], UAAction[], ...]`.
|
|
69
|
+
* The regexes are tried in order; the first match wins and its capture groups
|
|
70
|
+
* are assigned via the following action-list.
|
|
71
|
+
*/
|
|
72
|
+
export type UARegexMapEntry = RegExp[] | UAAction[];
|
|
73
|
+
/**
|
|
74
|
+
* Custom regexes to extend the built-in ones.
|
|
75
|
+
* Extension regexes are tried before the built-in regexes of the same category.
|
|
76
|
+
*/
|
|
77
|
+
export interface UAParserExtensions {
|
|
78
|
+
browser?: UARegexMapEntry[];
|
|
79
|
+
cpu?: UARegexMapEntry[];
|
|
80
|
+
device?: UARegexMapEntry[];
|
|
81
|
+
engine?: UARegexMapEntry[];
|
|
82
|
+
os?: UARegexMapEntry[];
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Parses the given User-Agent string into browser, engine, os, device and cpu information.
|
|
86
|
+
*
|
|
87
|
+
* When `ua` is not provided and running in a browser - `navigator.userAgent` is used
|
|
88
|
+
* (with client-hints-based refinements, e.g. Brave and iPadOS detection).
|
|
89
|
+
*/
|
|
90
|
+
export declare function parseUserAgent(userAgent?: string, extensions?: UAParserExtensions): UAResult;
|
|
91
|
+
/**
|
|
92
|
+
* User-Agent parser.
|
|
93
|
+
*
|
|
94
|
+
* Compared to `parseUserAgent()`, the class allows parsing only the needed parts
|
|
95
|
+
* (e.g `getBrowser()` alone is much cheaper than `getResult()`),
|
|
96
|
+
* and reusing the compiled extensions across multiple `setUA()` calls.
|
|
97
|
+
*/
|
|
98
|
+
export declare class UAParser {
|
|
99
|
+
constructor(ua?: string, extensions?: UAParserExtensions);
|
|
100
|
+
constructor(extensions: UAParserExtensions);
|
|
101
|
+
private ua;
|
|
102
|
+
private readonly nav;
|
|
103
|
+
private readonly rgxMap;
|
|
104
|
+
private readonly isSelfNav;
|
|
105
|
+
getBrowser(): UABrowser;
|
|
106
|
+
getCPU(): UACpu;
|
|
107
|
+
getDevice(): UADevice;
|
|
108
|
+
getEngine(): UAEngine;
|
|
109
|
+
getOS(): UAOS;
|
|
110
|
+
getResult(): UAResult;
|
|
111
|
+
getUA(): string;
|
|
112
|
+
setUA(ua: string | undefined): this;
|
|
113
|
+
}
|