@xylabs/exists 4.13.19 → 4.13.21

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 CHANGED
@@ -12,13 +12,60 @@
12
12
  [![snyk-badge][]][snyk-link]
13
13
  [![socket-badge][]][socket-link]
14
14
 
15
- Version: 4.13.15
16
15
 
17
16
  Base functionality used throughout XY Labs TypeScript/JavaScript libraries
18
17
 
19
- ## Documentation
18
+ ## API Documentation
19
+
20
+ **@xylabs/exists**
21
+
22
+ ***
23
+
24
+ ## Functions
25
+
26
+ - [exists](#functions/exists)
27
+
28
+ ### functions
29
+
30
+ ### <a id="exists"></a>exists
31
+
32
+ [**@xylabs/exists**](#../README)
33
+
34
+ ***
35
+
36
+ ```ts
37
+ function exists<T>(x?): x is NonNullable<T>;
38
+ ```
39
+
40
+ Used to type narrow an object which is possibly null or undefined. Works well
41
+ with functional Array methods. For example:
42
+
43
+ ## Type Parameters
44
+
45
+ ### T
46
+
47
+ `T`
48
+
49
+ ## Parameters
50
+
51
+ ### x?
52
+
53
+ The object which is potentially undefined or null
54
+
55
+ `null` | `T`
56
+
57
+ ## Returns
58
+
59
+ `x is NonNullable<T>`
60
+
61
+ False if the object is null/undefined, true otherwise
62
+
63
+ ## Example
64
+
65
+ ```ts
66
+ const payloads: XyoPayload[] = boundWitness._payloads?.filter(exists) || []
67
+ ```
20
68
 
21
- Coming Soon!
22
69
 
23
70
  Part of [sdk-js](https://www.npmjs.com/package/@xyo-network/sdk-js)
24
71
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/exists",
3
- "version": "4.13.19",
3
+ "version": "4.13.21",
4
4
  "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
5
  "keywords": [
6
6
  "exists",
@@ -29,15 +29,21 @@
29
29
  "exports": {
30
30
  ".": {
31
31
  "types": "./dist/neutral/index.d.ts",
32
+ "source": "./src/index.ts",
32
33
  "default": "./dist/neutral/index.mjs"
33
34
  },
34
35
  "./package.json": "./package.json"
35
36
  },
36
37
  "module": "./dist/neutral/index.mjs",
38
+ "source": "./src/index.ts",
37
39
  "types": "./dist/neutral/index.d.ts",
40
+ "files": [
41
+ "dist",
42
+ "src"
43
+ ],
38
44
  "devDependencies": {
39
- "@xylabs/ts-scripts-yarn3": "^7.0.0-rc.27",
40
- "@xylabs/tsconfig": "^7.0.0-rc.27",
45
+ "@xylabs/ts-scripts-yarn3": "^7.0.0",
46
+ "@xylabs/tsconfig": "^7.0.0",
41
47
  "typescript": "^5.8.3",
42
48
  "vitest": "^3.2.4"
43
49
  },
@@ -0,0 +1,43 @@
1
+ import {
2
+ describe, expect, it,
3
+ } from 'vitest'
4
+
5
+ // eslint-disable-next-line no-restricted-imports
6
+ import { exists } from '../index.ts'
7
+
8
+ const filterableValues = [undefined, null]
9
+ const nonfilterableValue = {}
10
+
11
+ describe('exists', () => {
12
+ describe.each(filterableValues)('with all %p', (value) => {
13
+ it('filters all', () => {
14
+ const input = [value, value]
15
+ const actual = input.filter(exists)
16
+ expect(actual.length).toBe(0)
17
+ })
18
+ })
19
+ describe.each(filterableValues)('with mixed %p', (value) => {
20
+ it('filters some', () => {
21
+ const input = [value, nonfilterableValue, value, nonfilterableValue]
22
+ const actual = input.filter(exists)
23
+ expect(actual.length).toBe(2)
24
+ })
25
+ })
26
+ describe.each(filterableValues)('with no %p', () => {
27
+ it('filters none', () => {
28
+ const input = [nonfilterableValue, nonfilterableValue]
29
+ const actual = input.filter(exists)
30
+ expect(actual.length).toBe(input.length)
31
+ })
32
+ })
33
+ it('does not filter zero', () => {
34
+ const input = [0, 1]
35
+ const actual = input.filter(exists)
36
+ expect(actual).toEqual(input)
37
+ })
38
+ it('does not filter false', () => {
39
+ const input = [true, false]
40
+ const actual = input.filter(exists)
41
+ expect(actual).toEqual(input)
42
+ })
43
+ })
package/xy.config.ts DELETED
@@ -1,10 +0,0 @@
1
- import type { XyTsupConfig } from '@xylabs/ts-scripts-yarn3'
2
- const config: XyTsupConfig = {
3
- compile: {
4
- browser: {},
5
- neutral: { src: true },
6
- node: {},
7
- },
8
- }
9
-
10
- export default config