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

input-output-hk / atala-prism-wallet-sdk-ts / 9416468997

07 Jun 2024 11:46AM UTC coverage: 69.3% (+1.2%) from 68.144%
9416468997

Pull #215

github

web-flow
Merge ff72c3dfc into 78838eaef
Pull Request #215: feat: Backup and Restore

1087 of 1756 branches covered (61.9%)

Branch coverage included in aggregate %.

218 of 264 new or added lines in 29 files covered. (82.58%)

3 existing lines in 2 files now uncovered.

2290 of 3117 relevant lines covered (73.47%)

19.41 hits per line

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

84.38
/src/utils/guards.ts
1
import { Nil } from "./types";
2

3
/**
4
 * isNullish
5
 * Typeguard - check a value is undefined or null
6
 */
7
export const isNil = (value: unknown): value is Nil => value === null || value === undefined;
80✔
8

9
/**
10
 * notNil
11
 * Typeguard - check a value is neither undefined or null
12
 * @see isNil
13
 */
14
export const notNil = <T>(value: T | Nil): value is T => !isNil(value);
44✔
15

16
/**
17
 * isEmpty
18
 * Logic - check a given value is considered empty
19
 * empty depends on typeof value:
20
 * - null
21
 * - undefined
22
 * - array: length = 0
23
 * - string: length = 0
24
 * @see isNil
25
 * @see isString
26
 * @see isArray
27
 */
28
export const isEmpty = (value: unknown) => {
38✔
29
  if (isString(value) || isArray(value)) {
97!
30
    return value.length === 0;
97✔
31
  }
32

NEW
33
  return isNil(value);
×
34
};
35

36

37
/**
38
 * isObject
39
 * Typeguard - check a value is an object in the conceptual sense not the JS sense
40
 * excluding JS overlap with:
41
 *   null
42
 *   Arrays
43
 *   Functions
44
 */
45
export const isObject = <T>(value: T): value is Exclude<T & Record<string, any>, Nil | any[] | ((...args: any) => any)> =>
38✔
46
  typeof value === 'object' && notNil(value) && !isArray(value);
40✔
47

48
/**
49
 * isString
50
 * TypeGuard to check a value is a string
51
 */
52
export const isString = (value: unknown): value is string => typeof value === 'string';
150✔
53

54
/**
55
 * notEmptyString
56
 * Typeguard + Logic - check a value is a string with contents
57
 */
58
export const notEmptyString = (value: unknown): value is string => isString(value) && !isEmpty(value);
49✔
59

60
/**
61
 * isArray
62
 * Typeguard - check a value is an Array
63
 */
64
export const isArray = (value: unknown): value is unknown[] => Array.isArray(value);
104✔
65

66
/**
67
 * notEmptyArray
68
 * Typeguard + Logic - check a value is an Array with contents
69
 */
70
// export const notEmptyArray = (value: unknown): value is unknown[] => isArray(value) && !isEmpty(value);
71

72
/**
73
 * asArray
74
 * convert a value to an array
75
 * @param items - the value to be converted
76
 *   - nullish returns empty array
77
 *   - single item returns array with item
78
 *   - array returns array
79
 * @param guard? - optional Typeguard to filter items ensuring item types
80
 */
81
export function asArray<T>(items: T | T[] | Nil): T[];
82
export function asArray<T, U extends T>(items: T | T[] | Nil, guard: (item: unknown) => item is U): U[];
83
export function asArray<T>(items: T | T[] | Nil, guard?: (item: unknown) => item is T): T[] {
84
  if (isNil(items)) {
18!
NEW
85
    return [];
×
86
  }
87

88
  const unGuarded = items instanceof Array ? items : [items];
18✔
89

90
  return isNil(guard) ? unGuarded : unGuarded.filter(guard);
18!
91
}
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

© 2026 Coveralls, Inc