@jeniex/utils 1.1.2 → 1.1.4

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/browser/index.cjs CHANGED
@@ -54,6 +54,11 @@ function asserted(object) {
54
54
  }
55
55
  return object;
56
56
  }
57
+ function stringOrThrow(value) {
58
+ if (!isString(value)) {
59
+ throw new Error('Expected a string.');
60
+ }
61
+ }
57
62
  function isTruthy(object) {
58
63
  return Boolean(object) === true;
59
64
  }
@@ -126,8 +131,6 @@ function capitalize(sentence) {
126
131
  }
127
132
 
128
133
  const scriptName = GM.info.script.name;
129
- /** The identifier of the script to be used in logging. */
130
- const logId = `[${scriptName}]:`;
131
134
  /** The initial tab URL on the script run. */
132
135
  const tabURL = window.location.href;
133
136
 
@@ -461,6 +464,7 @@ async function getOptions(flags) {
461
464
 
462
465
  function customizeConsole(debug = false) {
463
466
  const base = window.console;
467
+ const logId = `[${scriptName}]:`;
464
468
  return {
465
469
  log: base.log.bind(base, logId),
466
470
  warn: base.warn.bind(base, logId),
@@ -496,7 +500,6 @@ exports.isObject = isObject;
496
500
  exports.isString = isString;
497
501
  exports.isTruthy = isTruthy;
498
502
  exports.join = join;
499
- exports.logId = logId;
500
503
  exports.noop = noop;
501
504
  exports.padZeros = padZeros;
502
505
  exports.pageLoad = pageLoad;
@@ -507,5 +510,6 @@ exports.saveFile = saveFile;
507
510
  exports.scriptName = scriptName;
508
511
  exports.setSearchParam = setSearchParam;
509
512
  exports.sleep = sleep;
513
+ exports.stringOrThrow = stringOrThrow;
510
514
  exports.tabURL = tabURL;
511
515
  exports.toString = toString;
@@ -17,6 +17,7 @@ declare function noop(): void;
17
17
  declare function toString(object: unknown): string;
18
18
 
19
19
  declare function asserted<T>(object: T | null | undefined): T;
20
+ declare function stringOrThrow(value: unknown): asserts value is string;
20
21
  declare function isTruthy<T>(object: T): object is Exclude<T, '' | 0 | false | null | undefined>;
21
22
  declare function isFalsy(object: unknown): object is '' | 0 | false | null | undefined;
22
23
  declare function isNullish(object: unknown): object is null | undefined;
@@ -107,8 +108,6 @@ declare function setSearchParam(key: string, value: string, fullURL?: string): s
107
108
  declare function removeSearchParams(keys: string[], fullURL?: string): string;
108
109
 
109
110
  declare const scriptName: string;
110
- /** The identifier of the script to be used in logging. */
111
- declare const logId: string;
112
111
  /** The initial tab URL on the script run. */
113
112
  declare const tabURL: string;
114
113
 
@@ -169,4 +168,4 @@ interface CustomizedConsole {
169
168
 
170
169
  declare function customizeConsole(debug?: boolean): CustomizedConsole;
171
170
 
172
- export { $, $$, Flag, Fn, Nullable, Prettify, addStyle, alert, asserted, capitalize, checkVPN, checkVPNRandomly, confirm, customizeConsole, fish, fishResponse, fishX, fishXResponse, getOptions, getSearchParam, imageLoad, isBoolean, isFalsy, isFunction, isNotNullish, isNullish, isNumber, isObject, isString, isTruthy, join, logId, noop, padZeros, pageLoad, prompt, remove, removeSearchParams, saveFile, scriptName, setSearchParam, sleep, tabURL, toString };
171
+ export { $, $$, Flag, Fn, Nullable, Prettify, addStyle, alert, asserted, capitalize, checkVPN, checkVPNRandomly, confirm, customizeConsole, fish, fishResponse, fishX, fishXResponse, getOptions, getSearchParam, imageLoad, isBoolean, isFalsy, isFunction, isNotNullish, isNullish, isNumber, isObject, isString, isTruthy, join, noop, padZeros, pageLoad, prompt, remove, removeSearchParams, saveFile, scriptName, setSearchParam, sleep, stringOrThrow, tabURL, toString };
package/browser/index.js CHANGED
@@ -52,6 +52,11 @@ function asserted(object) {
52
52
  }
53
53
  return object;
54
54
  }
55
+ function stringOrThrow(value) {
56
+ if (!isString(value)) {
57
+ throw new Error('Expected a string.');
58
+ }
59
+ }
55
60
  function isTruthy(object) {
56
61
  return Boolean(object) === true;
57
62
  }
@@ -124,8 +129,6 @@ function capitalize(sentence) {
124
129
  }
125
130
 
126
131
  const scriptName = GM.info.script.name;
127
- /** The identifier of the script to be used in logging. */
128
- const logId = `[${scriptName}]:`;
129
132
  /** The initial tab URL on the script run. */
130
133
  const tabURL = window.location.href;
131
134
 
@@ -459,6 +462,7 @@ async function getOptions(flags) {
459
462
 
460
463
  function customizeConsole(debug = false) {
461
464
  const base = window.console;
465
+ const logId = `[${scriptName}]:`;
462
466
  return {
463
467
  log: base.log.bind(base, logId),
464
468
  warn: base.warn.bind(base, logId),
@@ -467,4 +471,4 @@ function customizeConsole(debug = false) {
467
471
  };
468
472
  }
469
473
 
470
- export { $, $$, addStyle, alert, asserted, capitalize, checkVPN, checkVPNRandomly, confirm, customizeConsole, fish, fishResponse, fishX, fishXResponse, getOptions, getSearchParam, imageLoad, isBoolean, isFalsy, isFunction, isNotNullish, isNullish, isNumber, isObject, isString, isTruthy, join, logId, noop, padZeros, pageLoad, prompt, remove, removeSearchParams, saveFile, scriptName, setSearchParam, sleep, tabURL, toString };
474
+ export { $, $$, addStyle, alert, asserted, capitalize, checkVPN, checkVPNRandomly, confirm, customizeConsole, fish, fishResponse, fishX, fishXResponse, getOptions, getSearchParam, imageLoad, isBoolean, isFalsy, isFunction, isNotNullish, isNullish, isNumber, isObject, isString, isTruthy, join, noop, padZeros, pageLoad, prompt, remove, removeSearchParams, saveFile, scriptName, setSearchParam, sleep, stringOrThrow, tabURL, toString };
package/node/index.cjs CHANGED
@@ -58,6 +58,11 @@ function asserted(object) {
58
58
  }
59
59
  return object;
60
60
  }
61
+ function stringOrThrow(value) {
62
+ if (!isString(value)) {
63
+ throw new Error('Expected a string.');
64
+ }
65
+ }
61
66
  function isTruthy(object) {
62
67
  return Boolean(object) === true;
63
68
  }
@@ -260,4 +265,5 @@ exports.readJSON = readJSON;
260
265
  exports.remove = remove;
261
266
  exports.removeFiles = removeFiles;
262
267
  exports.sleep = sleep;
268
+ exports.stringOrThrow = stringOrThrow;
263
269
  exports.toString = toString;
package/node/index.d.ts CHANGED
@@ -17,6 +17,7 @@ declare function noop(): void;
17
17
  declare function toString(object: unknown): string;
18
18
 
19
19
  declare function asserted<T>(object: T | null | undefined): T;
20
+ declare function stringOrThrow(value: unknown): asserts value is string;
20
21
  declare function isTruthy<T>(object: T): object is Exclude<T, '' | 0 | false | null | undefined>;
21
22
  declare function isFalsy(object: unknown): object is '' | 0 | false | null | undefined;
22
23
  declare function isNullish(object: unknown): object is null | undefined;
@@ -109,4 +110,4 @@ declare function removeFiles({ folderPath, filter }: RemoveFilesOpt): Promise<vo
109
110
 
110
111
  declare function readJSON<T = object>(filePath: string, withComments?: boolean): Promise<T>;
111
112
 
112
- export { Fn, Nullable, Prettify, asserted, capitalize, isBoolean, isFalsy, isFunction, isNotNullish, isNullish, isNumber, isObject, isString, isTruthy, join, listFiles, listFolders, listFoldersSync, noop, padZeros, readJSON, remove, removeFiles, sleep, toString };
113
+ export { Fn, Nullable, Prettify, asserted, capitalize, isBoolean, isFalsy, isFunction, isNotNullish, isNullish, isNumber, isObject, isString, isTruthy, join, listFiles, listFolders, listFoldersSync, noop, padZeros, readJSON, remove, removeFiles, sleep, stringOrThrow, toString };
package/node/index.js CHANGED
@@ -56,6 +56,11 @@ function asserted(object) {
56
56
  }
57
57
  return object;
58
58
  }
59
+ function stringOrThrow(value) {
60
+ if (!isString(value)) {
61
+ throw new Error('Expected a string.');
62
+ }
63
+ }
59
64
  function isTruthy(object) {
60
65
  return Boolean(object) === true;
61
66
  }
@@ -237,4 +242,4 @@ async function readJSON(filePath, withComments = false) {
237
242
  return JSON.parse(stringJSON);
238
243
  }
239
244
 
240
- export { asserted, capitalize, isBoolean, isFalsy, isFunction, isNotNullish, isNullish, isNumber, isObject, isString, isTruthy, join, listFiles, listFolders, listFoldersSync, noop, padZeros, readJSON, remove, removeFiles, sleep, toString };
245
+ export { asserted, capitalize, isBoolean, isFalsy, isFunction, isNotNullish, isNullish, isNumber, isObject, isString, isTruthy, join, listFiles, listFolders, listFoldersSync, noop, padZeros, readJSON, remove, removeFiles, sleep, stringOrThrow, toString };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jeniex/utils",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "author": "JenieX",
5
5
  "homepage": "https://github.com/JenieX/utils",
6
6
  "type": "module",