@choksheak/ts-utils 0.1.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.
@@ -0,0 +1,3 @@
1
+ {
2
+ "editor.formatOnSave": true
3
+ }
package/LICENSE ADDED
@@ -0,0 +1,31 @@
1
+ THE UNLICENSE
2
+
3
+ #####################################################################
4
+ # Author's note: No restrictions apply whatsoever. Feel free to do
5
+ # whatever you want with the source code.
6
+ #####################################################################
7
+
8
+ This is free and unencumbered software released into the public domain.
9
+
10
+ Anyone is free to copy, modify, publish, use, compile, sell, or
11
+ distribute this software, either in source code form or as a compiled
12
+ binary, for any purpose, commercial or non-commercial, and by any
13
+ means.
14
+
15
+ In jurisdictions that recognize copyright laws, the author or authors
16
+ of this software dedicate any and all copyright interest in the
17
+ software to the public domain. We make this dedication for the benefit
18
+ of the public at large and to the detriment of our heirs and
19
+ successors. We intend this dedication to be an overt act of
20
+ relinquishment in perpetuity of all present and future rights to this
21
+ software under copyright law.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
27
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
28
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29
+ OTHER DEALINGS IN THE SOFTWARE.
30
+
31
+ For more information, please refer to <https://unlicense.org>
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @choksheak/ts-utils
2
+
3
+ This package is a random bunch of Typescript utilities that I have needed in almost every project that I have worked in. Hence making an easy way to share this code and also for my own personal and professional use. Feel free to use it in your own projects without any restrictions.
4
+
5
+ The code supports full tree-shaking. Therefore your code will only grow in size by whatever you use. Any code that you are not using will not contribute to your code size.
@@ -0,0 +1,11 @@
1
+ import globals from "globals";
2
+ import pluginJs from "@eslint/js";
3
+ import tseslint from "typescript-eslint";
4
+
5
+ /** @type {import('eslint').Linter.Config[]} */
6
+ export default [
7
+ { files: ["**/*.{js,mjs,cjs,ts}"] },
8
+ { languageOptions: { globals: globals.browser } },
9
+ pluginJs.configs.recommended,
10
+ ...tseslint.configs.recommended,
11
+ ];
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@choksheak/ts-utils",
3
+ "license": "The Unlicense",
4
+ "version": "0.1.0",
5
+ "description": "Random Typescript utilities with support for full tree-shaking",
6
+ "private": false,
7
+ "scripts": {
8
+ "lint": "eslint src/**",
9
+ "format": "prettier --write \"**/*.{js,ts}\""
10
+ },
11
+ "devDependencies": {
12
+ "@eslint/js": "^9.14.0",
13
+ "@types/jest": "^27.5.2",
14
+ "@types/node": "^16.18.97",
15
+ "eslint": "^9.14.0",
16
+ "globals": "^15.12.0",
17
+ "prettier": "^3.3.3",
18
+ "typescript": "^5.4.5",
19
+ "typescript-eslint": "^8.13.0"
20
+ }
21
+ }
package/src/nonNil.ts ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Type asserts that `t` is neither null nor undefined.
3
+ * Throws an error if `t` is null or undefined.
4
+ */
5
+ export function nonNil<T>(t: T | null | undefined, varName = "variable"): T {
6
+ if (t === null || t === undefined) {
7
+ throw new Error(`Missing ${varName}`);
8
+ }
9
+ return t;
10
+ }