@hypernym/utils 2.0.2 → 2.2.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,13 @@
1
+ import { access, constants, mkdir, writeFile as writeFile$1 } from 'node:fs/promises';
2
+ import { dirname } from 'node:path';
3
+
4
+ async function exists(path) {
5
+ return await access(path, constants.F_OK).then(() => true).catch(() => false);
6
+ }
7
+
8
+ async function writeFile(path, data, options) {
9
+ await mkdir(dirname(path), { recursive: true });
10
+ return await writeFile$1(path, data, options);
11
+ }
12
+
13
+ export { exists, writeFile };
package/dist/index.mjs CHANGED
@@ -8,6 +8,8 @@ const isUndefined = (v) => typeof v === "undefined";
8
8
  const isString = (v) => typeof v === "string";
9
9
  const isStringEmpty = (v) => isString(v) && v.trim().length === 0;
10
10
  const isBoolean = (v) => typeof v === "boolean";
11
+ const isFalse = (v) => v === false;
12
+ const isTrue = (v) => v === true;
11
13
  const isNumber = (v) => typeof v === "number" && !isNaN(v);
12
14
  const isArray = (v) => Array.isArray(v);
13
15
  const isArrayEmpty = (v) => isArray(v) && v.length === 0;
@@ -26,9 +28,11 @@ const isURL = (v) => v instanceof URL;
26
28
  const isError = (v) => v instanceof Error;
27
29
  const isPrimitive = (v) => isString(v) || isNumber(v) || isBigint(v) || isBoolean(v) || isSymbol(v) || isNull(v) || isUndefined(v);
28
30
  const isElement = (v) => v instanceof Element;
31
+ const isHtmlElement = (v) => v instanceof HTMLElement;
32
+ const isSvgElement = (v) => v instanceof SVGElement;
29
33
  const isNodeList = (v) => v instanceof NodeList;
30
34
  const isNodeListEmpty = (v) => isNodeList(v) && v.length === 0;
31
35
  const isHtmlCollection = (v) => v instanceof HTMLCollection;
32
36
  const isHtmlCollectionEmpty = (v) => isHtmlCollection(v) && v.length === 0;
33
37
 
34
- export { isArray, isArrayEmpty, isBigint, isBoolean, isBrowser, isDate, isElement, isError, isFunction, isHtmlCollection, isHtmlCollectionEmpty, isInfinity, isMap, isNaNValue, isNodeList, isNodeListEmpty, isNull, isNumber, isObject, isObjectEmpty, isPrimitive, isRegExp, isSet, isString, isStringEmpty, isSymbol, isURL, isUndefined, noop, toString };
38
+ export { isArray, isArrayEmpty, isBigint, isBoolean, isBrowser, isDate, isElement, isError, isFalse, isFunction, isHtmlCollection, isHtmlCollectionEmpty, isHtmlElement, isInfinity, isMap, isNaNValue, isNodeList, isNodeListEmpty, isNull, isNumber, isObject, isObjectEmpty, isPrimitive, isRegExp, isSet, isString, isStringEmpty, isSvgElement, isSymbol, isTrue, isURL, isUndefined, noop, toString };
@@ -0,0 +1,31 @@
1
+ import { writeFile as writeFile$1 } from 'node:fs/promises';
2
+
3
+ /**
4
+ * Checks if the file or directory exists.
5
+ *
6
+ * @example
7
+ *
8
+ * ```ts
9
+ * // New import
10
+ * import { exists } from '@hypernym/utils/fs'
11
+ * ```
12
+ *
13
+ * ```ts
14
+ * // Deprecated import
15
+ * import { exists } from '@hypernym/utils/node'
16
+ * ```
17
+ */
18
+ declare function exists(path: string): Promise<boolean>;
19
+
20
+ /**
21
+ * Writes data to a file recursively.
22
+ *
23
+ * @example
24
+ *
25
+ * ```ts
26
+ * import { writeFile } from '@hypernym/utils/fs'
27
+ * ```
28
+ */
29
+ declare function writeFile(path: string, data: Parameters<typeof writeFile$1>[1], options?: Parameters<typeof writeFile$1>[2]): Promise<void>;
30
+
31
+ export { exists, writeFile };
@@ -40,6 +40,14 @@ declare const isStringEmpty: (v: any) => v is string;
40
40
  * Returns a boolean if the given value is a `boolean`.
41
41
  */
42
42
  declare const isBoolean: (v: any) => v is boolean;
43
+ /**
44
+ * Returns a boolean if the given value is a `false`.
45
+ */
46
+ declare const isFalse: (v: any) => v is false;
47
+ /**
48
+ * Returns a boolean if the given value is a `true`.
49
+ */
50
+ declare const isTrue: (v: any) => v is true;
43
51
  /**
44
52
  * Returns a boolean if the given value is a `number`.
45
53
  */
@@ -112,6 +120,14 @@ declare const isPrimitive: (v: any) => v is Primitive;
112
120
  * Returns a boolean if the given value is a `Element`.
113
121
  */
114
122
  declare const isElement: (v: any) => v is Element;
123
+ /**
124
+ * Returns a boolean if the given value is a `HTMLElement`.
125
+ */
126
+ declare const isHtmlElement: (v: any) => v is HTMLElement;
127
+ /**
128
+ * Returns a boolean if the given value is a `SVGElement`.
129
+ */
130
+ declare const isSvgElement: (v: any) => v is SVGElement;
115
131
  /**
116
132
  * Returns a boolean if the given value is a `NodeList`.
117
133
  */
@@ -186,4 +202,4 @@ type RequiredObjectDeep<T extends object, Options extends RequiredOptions = {
186
202
  [K in keyof T]-?: RequiredDeep<T[K], Options>;
187
203
  };
188
204
 
189
- export { type BuiltIn, type IsAny, type IsNever, type IsNull, type PartialDeep, type Primitive, type RequiredDeep, isArray, isArrayEmpty, isBigint, isBoolean, isBrowser, isDate, isElement, isError, isFunction, isHtmlCollection, isHtmlCollectionEmpty, isInfinity, isMap, isNaNValue, isNodeList, isNodeListEmpty, isNull, isNumber, isObject, isObjectEmpty, isPrimitive, isRegExp, isSet, isString, isStringEmpty, isSymbol, isURL, isUndefined, noop, toString };
205
+ export { type BuiltIn, type IsAny, type IsNever, type IsNull, type PartialDeep, type Primitive, type RequiredDeep, isArray, isArrayEmpty, isBigint, isBoolean, isBrowser, isDate, isElement, isError, isFalse, isFunction, isHtmlCollection, isHtmlCollectionEmpty, isHtmlElement, isInfinity, isMap, isNaNValue, isNodeList, isNodeListEmpty, isNull, isNumber, isObject, isObjectEmpty, isPrimitive, isRegExp, isSet, isString, isStringEmpty, isSvgElement, isSymbol, isTrue, isURL, isUndefined, noop, toString };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hypernym/utils",
3
- "version": "2.0.2",
3
+ "version": "2.2.0",
4
4
  "author": "Hypernym Studio",
5
5
  "description": "A collection of reusable utilities.",
6
6
  "license": "MIT",
@@ -13,9 +13,13 @@
13
13
  "types": "./dist/types/index.d.ts",
14
14
  "import": "./dist/index.mjs"
15
15
  },
16
+ "./fs": {
17
+ "types": "./dist/types/fs/index.d.ts",
18
+ "import": "./dist/fs/index.mjs"
19
+ },
16
20
  "./node": {
17
- "types": "./dist/types/node/index.d.ts",
18
- "import": "./dist/node/index.mjs"
21
+ "types": "./dist/types/fs/index.d.ts",
22
+ "import": "./dist/fs/index.mjs"
19
23
  }
20
24
  },
21
25
  "files": [
@@ -36,22 +40,22 @@
36
40
  "scripts": {
37
41
  "dev": "vite playgrounds/client",
38
42
  "dev:node": "vite-node -w playgrounds/node/main.ts",
39
- "build": "rolli",
40
- "test:types": "vitest -c .config/vitest.config.ts typecheck",
43
+ "build": "hyperbundler",
44
+ "test:types": "vitest -c .config/vitest.config.ts --typecheck.only",
41
45
  "lint": "ESLINT_USE_FLAT_CONFIG=true eslint -c .config/eslint.config.js .",
42
46
  "lint:fix": "ESLINT_USE_FLAT_CONFIG=true eslint -c .config/eslint.config.js --fix .",
43
47
  "format": "prettier --config .config/prettier.config.js --write .",
44
48
  "prepublishOnly": "npm run build"
45
49
  },
46
50
  "devDependencies": {
47
- "@hypernym/eslint-config": "^2.0.1",
48
- "@hypernym/prettier-config": "^2.0.1",
51
+ "@hypernym/bundler": "^0.6.3",
52
+ "@hypernym/eslint-config": "^2.0.3",
53
+ "@hypernym/prettier-config": "^2.0.3",
49
54
  "@hypernym/tsconfig": "^1.1.0",
50
- "@types/node": "^20.8.2",
51
- "eslint": "^8.50.0",
52
- "prettier": "^3.0.3",
53
- "rolli": "^0.7.0",
54
- "typescript": "^5.2.2",
55
- "vitest": "^0.34.6"
55
+ "@types/node": "^20.10.5",
56
+ "eslint": "^8.56.0",
57
+ "prettier": "^3.1.1",
58
+ "typescript": "^5.3.3",
59
+ "vitest": "^1.1.0"
56
60
  }
57
61
  }
@@ -1,7 +0,0 @@
1
- import { access, constants } from 'node:fs/promises';
2
-
3
- async function exists(path) {
4
- return await access(path, constants.F_OK).then(() => true).catch(() => false);
5
- }
6
-
7
- export { exists };
@@ -1,6 +0,0 @@
1
- /**
2
- * Checks if the file exists.
3
- */
4
- declare function exists(path: string): Promise<boolean>;
5
-
6
- export { exists };