@equinor/cpl-utils 0.0.3 → 0.0.5

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/index.d.mts CHANGED
@@ -1,3 +1,23 @@
1
+ /**
2
+ * A function ensuring returning whether an item is undefined or not. If not undefined, it will exclude undefined from the type.
3
+ *
4
+ * @example
5
+ * const options: Option[] = [
6
+ * { value: "1", label: "Item 1"},
7
+ * { value: "2", label: "Item 2"},
8
+ * { value: "3", label: "Item 3"},
9
+ * ]
10
+ *
11
+ * const selectedValues = ["1", "3"]
12
+ *
13
+ * const optionsFilteredBySelectedValues = selectedValues
14
+ * .map(selectedValue => options.find(option => option.value === selectedValue))
15
+ * // type will be (Option | undefined)[]
16
+ * .filter(itemIsDefined)
17
+ * // type will be Option[]
18
+ */
19
+ declare function itemIsDefined<T>(item: T): item is Exclude<typeof item, undefined>;
20
+
1
21
  /**
2
22
  * A better typed `Object.prototype.objectHasOwnOroperty`. It helps TypeScript
3
23
  * infer types when an object has multiple types with different properties.
@@ -29,4 +49,4 @@
29
49
  */
30
50
  declare function objectHasOwnProperty<Key extends PropertyKey>(object: object, key: Key): object is Record<Key, unknown>;
31
51
 
32
- export { objectHasOwnProperty };
52
+ export { itemIsDefined, objectHasOwnProperty };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,23 @@
1
+ /**
2
+ * A function ensuring returning whether an item is undefined or not. If not undefined, it will exclude undefined from the type.
3
+ *
4
+ * @example
5
+ * const options: Option[] = [
6
+ * { value: "1", label: "Item 1"},
7
+ * { value: "2", label: "Item 2"},
8
+ * { value: "3", label: "Item 3"},
9
+ * ]
10
+ *
11
+ * const selectedValues = ["1", "3"]
12
+ *
13
+ * const optionsFilteredBySelectedValues = selectedValues
14
+ * .map(selectedValue => options.find(option => option.value === selectedValue))
15
+ * // type will be (Option | undefined)[]
16
+ * .filter(itemIsDefined)
17
+ * // type will be Option[]
18
+ */
19
+ declare function itemIsDefined<T>(item: T): item is Exclude<typeof item, undefined>;
20
+
1
21
  /**
2
22
  * A better typed `Object.prototype.objectHasOwnOroperty`. It helps TypeScript
3
23
  * infer types when an object has multiple types with different properties.
@@ -29,4 +49,4 @@
29
49
  */
30
50
  declare function objectHasOwnProperty<Key extends PropertyKey>(object: object, key: Key): object is Record<Key, unknown>;
31
51
 
32
- export { objectHasOwnProperty };
52
+ export { itemIsDefined, objectHasOwnProperty };
package/dist/index.js CHANGED
@@ -20,15 +20,22 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ itemIsDefined: () => itemIsDefined,
23
24
  objectHasOwnProperty: () => objectHasOwnProperty
24
25
  });
25
26
  module.exports = __toCommonJS(index_exports);
26
27
 
28
+ // src/itemIsDefined.ts
29
+ function itemIsDefined(item) {
30
+ return item !== void 0;
31
+ }
32
+
27
33
  // src/objectHasOwnProperty.ts
28
34
  function objectHasOwnProperty(object, key) {
29
35
  return Object.prototype.hasOwnProperty.call(object, key);
30
36
  }
31
37
  // Annotate the CommonJS export names for ESM import in node:
32
38
  0 && (module.exports = {
39
+ itemIsDefined,
33
40
  objectHasOwnProperty
34
41
  });
package/dist/index.mjs CHANGED
@@ -1,7 +1,13 @@
1
+ // src/itemIsDefined.ts
2
+ function itemIsDefined(item) {
3
+ return item !== void 0;
4
+ }
5
+
1
6
  // src/objectHasOwnProperty.ts
2
7
  function objectHasOwnProperty(object, key) {
3
8
  return Object.prototype.hasOwnProperty.call(object, key);
4
9
  }
5
10
  export {
11
+ itemIsDefined,
6
12
  objectHasOwnProperty
7
13
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/cpl-utils",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -9,14 +9,12 @@
9
9
  "dist/**"
10
10
  ],
11
11
  "devDependencies": {
12
- "@storybook/react": "^8.5.2",
13
- "@storybook/test": "^8.5.2",
14
- "eslint": "^8.57.1",
12
+ "eslint": "^9.21.0",
15
13
  "tsup": "^8.3.6",
16
14
  "typedoc": "^0.27.6",
17
15
  "typedoc-plugin-markdown": "^4.4.1",
18
- "eslint-config-custom": "0.0.6",
19
- "tsconfig": "0.0.1"
16
+ "@equinor/cpl-eslint-config": "0.0.8",
17
+ "@equinor/cpl-typescript-config": "0.0.2"
20
18
  },
21
19
  "publishConfig": {
22
20
  "access": "public"
@@ -27,6 +25,7 @@
27
25
  "dev": "tsup src/index.ts --format esm,cjs --watch --dts --external react",
28
26
  "typedoc": "typedoc && rm ./typedoc/README.mdx",
29
27
  "typedoc:watch": "typedoc --watch --preserveWatchOutput",
30
- "lint": "TIMING=1 eslint . --fix"
28
+ "lint": "TIMING=1 eslint . --fix",
29
+ "typecheck": "tsc --noEmit"
31
30
  }
32
31
  }