@webdeveric/utils 0.70.0 → 0.71.1

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.
@@ -9,39 +9,41 @@ var CommentType;
9
9
  CommentType["Single"] = "single";
10
10
  CommentType["HTML"] = "html";
11
11
  })(CommentType || (exports.CommentType = CommentType = {}));
12
- const commentTypes = {
13
- [CommentType.Block]: {
14
- commentStart: '/**\n',
15
- commentEnd: '\n */',
16
- lineStart: ' * ',
17
- lineEnd: '',
18
- },
19
- [CommentType.Legal]: {
20
- commentStart: '/*!\n',
21
- commentEnd: '\n */',
22
- lineStart: ' * ',
23
- lineEnd: '',
24
- },
25
- [CommentType.Single]: {
26
- commentStart: '',
27
- commentEnd: '',
28
- lineStart: '// ',
29
- lineEnd: '',
30
- },
31
- [CommentType.HTML]: {
32
- commentStart: '<!-- ',
33
- commentEnd: ' -->',
34
- lineStart: '',
35
- lineEnd: '',
36
- },
37
- };
12
+ function getCommentParts(type) {
13
+ return {
14
+ [CommentType.Block]: {
15
+ commentStart: '/**\n',
16
+ commentEnd: '\n */',
17
+ lineStart: ' * ',
18
+ lineEnd: '',
19
+ },
20
+ [CommentType.Legal]: {
21
+ commentStart: '/*!\n',
22
+ commentEnd: '\n */',
23
+ lineStart: ' * ',
24
+ lineEnd: '',
25
+ },
26
+ [CommentType.Single]: {
27
+ commentStart: '',
28
+ commentEnd: '',
29
+ lineStart: '// ',
30
+ lineEnd: '',
31
+ },
32
+ [CommentType.HTML]: {
33
+ commentStart: '<!-- ',
34
+ commentEnd: ' -->',
35
+ lineStart: '',
36
+ lineEnd: '',
37
+ },
38
+ }[type];
39
+ }
38
40
  function comment(text, options) {
39
41
  if (!text) {
40
42
  return '';
41
43
  }
42
44
  const { type = CommentType.Block, ...partOptions } = options ?? {};
43
45
  const { commentStart = '', commentEnd = '', lineStart = '', lineEnd = '', } = {
44
- ...commentTypes[type],
46
+ ...getCommentParts(type),
45
47
  ...partOptions,
46
48
  };
47
49
  const lines = text
@@ -37,6 +37,7 @@ __exportStar(require("./isInteger.js"), exports);
37
37
  __exportStar(require("./isIntString.js"), exports);
38
38
  __exportStar(require("./isISODateString.js"), exports);
39
39
  __exportStar(require("./isIterable.js"), exports);
40
+ __exportStar(require("./isJSONable.js"), exports);
40
41
  __exportStar(require("./isLengthAware.js"), exports);
41
42
  __exportStar(require("./isNonNullable.js"), exports);
42
43
  __exportStar(require("./isNull.js"), exports);
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isJSONable = void 0;
4
+ const isJSONable = (input) => {
5
+ return (input !== null &&
6
+ typeof input === 'object' &&
7
+ 'toJSON' in input &&
8
+ typeof input.toJSON === 'function' &&
9
+ input.toJSON.length <= 1);
10
+ };
11
+ exports.isJSONable = isJSONable;
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.trimIndentation = trimIndentation;
4
- const isWhitespaceOnly = (input) => /^\s*$/.test(input);
5
4
  function trimIndentation(input) {
6
5
  const lines = input.split('\n');
7
- const whiteSpace = lines.find((line) => !isWhitespaceOnly(line))?.match(/^(?<whiteSpace>\s*)/)?.groups?.['whiteSpace'];
6
+ const whiteSpace = lines.find((line) => !/^\s*$/.test(line))?.match(/^(?<whiteSpace>\s*)/)?.groups?.['whiteSpace'];
8
7
  if (whiteSpace) {
9
8
  const wsPattern = new RegExp(`^${whiteSpace}`);
10
9
  return lines
@@ -5,39 +5,41 @@ export var CommentType;
5
5
  CommentType["Single"] = "single";
6
6
  CommentType["HTML"] = "html";
7
7
  })(CommentType || (CommentType = {}));
8
- const commentTypes = {
9
- [CommentType.Block]: {
10
- commentStart: '/**\n',
11
- commentEnd: '\n */',
12
- lineStart: ' * ',
13
- lineEnd: '',
14
- },
15
- [CommentType.Legal]: {
16
- commentStart: '/*!\n',
17
- commentEnd: '\n */',
18
- lineStart: ' * ',
19
- lineEnd: '',
20
- },
21
- [CommentType.Single]: {
22
- commentStart: '',
23
- commentEnd: '',
24
- lineStart: '// ',
25
- lineEnd: '',
26
- },
27
- [CommentType.HTML]: {
28
- commentStart: '<!-- ',
29
- commentEnd: ' -->',
30
- lineStart: '',
31
- lineEnd: '',
32
- },
33
- };
8
+ function getCommentParts(type) {
9
+ return {
10
+ [CommentType.Block]: {
11
+ commentStart: '/**\n',
12
+ commentEnd: '\n */',
13
+ lineStart: ' * ',
14
+ lineEnd: '',
15
+ },
16
+ [CommentType.Legal]: {
17
+ commentStart: '/*!\n',
18
+ commentEnd: '\n */',
19
+ lineStart: ' * ',
20
+ lineEnd: '',
21
+ },
22
+ [CommentType.Single]: {
23
+ commentStart: '',
24
+ commentEnd: '',
25
+ lineStart: '// ',
26
+ lineEnd: '',
27
+ },
28
+ [CommentType.HTML]: {
29
+ commentStart: '<!-- ',
30
+ commentEnd: ' -->',
31
+ lineStart: '',
32
+ lineEnd: '',
33
+ },
34
+ }[type];
35
+ }
34
36
  export function comment(text, options) {
35
37
  if (!text) {
36
38
  return '';
37
39
  }
38
40
  const { type = CommentType.Block, ...partOptions } = options ?? {};
39
41
  const { commentStart = '', commentEnd = '', lineStart = '', lineEnd = '', } = {
40
- ...commentTypes[type],
42
+ ...getCommentParts(type),
41
43
  ...partOptions,
42
44
  };
43
45
  const lines = text
@@ -21,6 +21,7 @@ export * from './isInteger.js';
21
21
  export * from './isIntString.js';
22
22
  export * from './isISODateString.js';
23
23
  export * from './isIterable.js';
24
+ export * from './isJSONable.js';
24
25
  export * from './isLengthAware.js';
25
26
  export * from './isNonNullable.js';
26
27
  export * from './isNull.js';
@@ -0,0 +1,7 @@
1
+ export const isJSONable = (input) => {
2
+ return (input !== null &&
3
+ typeof input === 'object' &&
4
+ 'toJSON' in input &&
5
+ typeof input.toJSON === 'function' &&
6
+ input.toJSON.length <= 1);
7
+ };
@@ -1,7 +1,6 @@
1
- const isWhitespaceOnly = (input) => /^\s*$/.test(input);
2
1
  export function trimIndentation(input) {
3
2
  const lines = input.split('\n');
4
- const whiteSpace = lines.find((line) => !isWhitespaceOnly(line))?.match(/^(?<whiteSpace>\s*)/)?.groups?.['whiteSpace'];
3
+ const whiteSpace = lines.find((line) => !/^\s*$/.test(line))?.match(/^(?<whiteSpace>\s*)/)?.groups?.['whiteSpace'];
5
4
  if (whiteSpace) {
6
5
  const wsPattern = new RegExp(`^${whiteSpace}`);
7
6
  return lines
@@ -21,6 +21,7 @@ export * from './isInteger.js';
21
21
  export * from './isIntString.js';
22
22
  export * from './isISODateString.js';
23
23
  export * from './isIterable.js';
24
+ export * from './isJSONable.js';
24
25
  export * from './isLengthAware.js';
25
26
  export * from './isNonNullable.js';
26
27
  export * from './isNull.js';
@@ -0,0 +1,4 @@
1
+ import type { JsonValue } from '../types/common.js';
2
+ export declare const isJSONable: (input: unknown) => input is {
3
+ toJSON: (key?: string) => JsonValue;
4
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@webdeveric/utils",
3
3
  "description": "Just another collection of utilities.",
4
- "version": "0.70.0",
4
+ "version": "0.71.1",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -66,7 +66,7 @@
66
66
  "url": "https://github.com/webdeveric/utils/issues"
67
67
  },
68
68
  "homepage": "https://github.com/webdeveric/utils/#readme",
69
- "packageManager": "pnpm@10.14.0+sha512.ad27a79641b49c3e481a16a805baa71817a04bbe06a38d17e60e2eaee83f6a146c6a688125f5792e48dd5ba30e7da52a5cda4c3992b9ccf333f9ce223af84748",
69
+ "packageManager": "pnpm@10.15.1+sha512.34e538c329b5553014ca8e8f4535997f96180a1d0f614339357449935350d924e22f8614682191264ec33d1462ac21561aff97f6bb18065351c162c7e8f6de67",
70
70
  "scripts": {
71
71
  "clean": "rimraf ./dist/",
72
72
  "prebuild": "pnpm clean",
@@ -87,21 +87,21 @@
87
87
  "devDependencies": {
88
88
  "@commitlint/config-conventional": "^19.8.1",
89
89
  "@commitlint/types": "^19.8.1",
90
- "@types/node": "^22.17.2",
90
+ "@types/node": "^22.18.0",
91
91
  "@vitest/coverage-v8": "^3.2.4",
92
92
  "@webdeveric/eslint-config-ts": "^0.11.0",
93
93
  "@webdeveric/prettier-config": "^0.3.0",
94
94
  "commitlint": "^19.8.1",
95
95
  "commitlint-plugin-cspell": "^0.3.0",
96
96
  "conventional-changelog-conventionalcommits": "^9.1.0",
97
- "cspell": "^9.2.0",
97
+ "cspell": "^9.2.1",
98
98
  "eslint": "^8.57.1",
99
99
  "eslint-config-prettier": "^10.1.8",
100
100
  "eslint-import-resolver-typescript": "^4.4.4",
101
101
  "eslint-plugin-import": "^2.32.0",
102
102
  "husky": "^9.1.7",
103
103
  "jsdom": "^26.1.0",
104
- "lint-staged": "^16.1.5",
104
+ "lint-staged": "^16.1.6",
105
105
  "prettier": "^3.6.2",
106
106
  "rimraf": "^6.0.1",
107
107
  "semantic-release": "^24.2.7",