• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

alovajs / alova / #219

01 Nov 2024 02:50PM UTC coverage: 95.359% (+1.5%) from 93.83%
#219

push

github

web-flow
Merge pull request #577 from alovajs/changeset-release/main

ci: release

1698 of 1787 branches covered (95.02%)

Branch coverage included in aggregate %.

5801 of 6077 relevant lines covered (95.46%)

223.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.69
/packages/shared/src/vars.ts
1
import { GeneralFn } from './types';
2

3
declare const Deno: any;
4
const undefStr = 'undefined';
1✔
5
// The following unified processing functions or variables added to reduce the amount of compiled code
6
export const PromiseCls = Promise;
1✔
7
export const promiseResolve = <T = void>(value?: T) => PromiseCls.resolve(value);
1✔
8
export const promiseReject = <T>(value: T) => PromiseCls.reject(value);
1✔
9
export const ObjectCls = Object;
1✔
10
export const RegExpCls = RegExp;
1✔
11
export const undefinedValue = undefined;
1✔
12
export const nullValue = null;
1✔
13
export const trueValue = true;
1✔
14
export const falseValue = false;
1✔
15
export const promiseThen = <T, TResult1 = T, TResult2 = never>(
1✔
16
  promise: Promise<T>,
7✔
17
  onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null,
7✔
18
  onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null
7✔
19
): Promise<TResult1 | TResult2> => promise.then(onFulfilled, onrejected);
7✔
20
export const promiseCatch = <T, TResult = never>(
1✔
21
  promise: Promise<T>,
×
22
  onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null
×
23
) => promise.catch(onrejected);
×
24
export const promiseFinally = <T>(promise: Promise<T>, onfinally?: (() => void) | undefined | null) =>
1✔
25
  promise.finally(onfinally);
×
26
export const JSONStringify = <T>(
1✔
27
  value: T,
1✔
28
  replacer?: (this: any, key: string, value: any) => any,
1✔
29
  space?: string | number
1✔
30
) => JSON.stringify(value, replacer, space);
1✔
31
export const JSONParse = (value: string) => JSON.parse(value);
1✔
32
export const setTimeoutFn = (fn: GeneralFn, delay = 0) => setTimeout(fn, delay);
1✔
33
export const clearTimeoutTimer = (timer: NodeJS.Timeout | string | number) => clearTimeout(timer);
1✔
34
export const objectKeys = (obj: object) => ObjectCls.keys(obj);
1✔
35
export const objectValues = (obj: object) => ObjectCls.values(obj);
1✔
36
export const forEach = <T>(ary: T[], fn: (item: T, index: number, ary: T[]) => void) => ary.forEach(fn);
1✔
37
export const pushItem = <T>(ary: T[], ...item: T[]) => ary.push(...item);
1✔
38
export const mapItem = <T, R>(ary: T[], callbackfn: (value: T, index: number, array: T[]) => R) => ary.map(callbackfn);
1✔
39
export const filterItem = <T>(ary: T[], predicate: (value: T, index: number, array: T[]) => unknown) =>
1✔
40
  ary.filter(predicate);
6✔
41
export const shift = <T>(ary: T[]) => ary.shift();
1✔
42
export const slice = <T>(ary: T[], start?: number, end?: number) => ary.slice(start, end);
1✔
43
export const splice = <T>(ary: T[], start: number, deleteCount = 0, ...items: T[]) =>
1✔
44
  ary.splice(start, deleteCount, ...items);
×
45
export const len = (data: any[] | Uint8Array | string) => data.length;
1✔
46
export const isArray = (arg: any): arg is any[] => Array.isArray(arg);
1✔
47
export const deleteAttr = <T extends Record<any, any>>(arg: T, attr: keyof T) => delete arg[attr];
1✔
48
export const typeOf = (arg: any) => typeof arg;
1✔
49
export const regexpTest = (reg: RegExp, str: string | number) => reg.test(`${str}`);
1✔
50
export const includes = <T>(ary: T[], target: T) => ary.includes(target);
1✔
51
export const valueObject = <T>(value: T, writable = falseValue) => ({ value, writable });
1✔
52
export const defineProperty = (o: object, key: string | symbol, value: any, isDescriptor = falseValue) =>
1✔
53
  ObjectCls.defineProperty(o, key, isDescriptor ? value : valueObject(value, falseValue));
×
54
// Whether it is running on the server side, node and bun are judged by process, and deno is judged by Deno.
55
// Some frameworks (such as Alipay and uniapp) will inject the process object as a global variable.
56
// Therefore, the process.cwd function unique to the server is used as the basis for judgment.
57
export const isSSR =
1✔
58
  typeof window === undefStr &&
1!
59
  (typeof process !== undefStr ? typeof (process as any).cwd === 'function' : typeof Deno !== undefStr);
×
60

61
/** cache mode */
62
// only cache in memory, it's default option
63
export const MEMORY = 'memory';
1✔
64

65
// persistent cache, and will be read to memory when page is refreshed, it means that the memory cache always exist until cache is expired.
66
export const STORAGE_RESTORE = 'restore';
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc