@jeniex/utils 1.0.27 → 1.1.3

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
@@ -125,20 +125,7 @@ function capitalize(sentence) {
125
125
  return capitalizeWord(sentence);
126
126
  }
127
127
 
128
- let infoObject;
129
- if (typeof GM !== 'undefined') {
130
- infoObject = GM.info;
131
- // eslint-disable-next-line unicorn/no-negated-condition
132
- }
133
- else if (typeof GM_info === 'undefined') {
134
- infoObject = { script: { name: document.title } };
135
- }
136
- else {
137
- infoObject = GM_info;
138
- }
139
- const scriptName = infoObject.script.name;
140
- /** The identifier of the script to be used in logging. */
141
- const logId = `[${scriptName}]:`;
128
+ const scriptName = GM.info.script.name;
142
129
  /** The initial tab URL on the script run. */
143
130
  const tabURL = window.location.href;
144
131
 
@@ -261,8 +248,7 @@ function $$(selectors, parent) {
261
248
  * @param fullURL If provided, it will be our target, otherwise it is the current location.
262
249
  */
263
250
  function getSearchParam(key, fullURL) {
264
- const { search } = new URL(fullURL ?? window.location.href);
265
- const searchParams = new URLSearchParams(search);
251
+ const { searchParams } = new URL(fullURL ?? window.location.href);
266
252
  const value = searchParams.get(key);
267
253
  if (value === null) {
268
254
  return undefined;
@@ -471,6 +457,17 @@ async function getOptions(flags) {
471
457
  return options;
472
458
  }
473
459
 
460
+ function customizeConsole(debug = false) {
461
+ const base = window.console;
462
+ const logId = `[${scriptName}]:`;
463
+ return {
464
+ log: base.log.bind(base, logId),
465
+ warn: base.warn.bind(base, logId),
466
+ error: base.error.bind(base, logId),
467
+ debug: debug ? base.log.bind(base, logId) : noop,
468
+ };
469
+ }
470
+
474
471
  exports.$ = $;
475
472
  exports.$$ = $$;
476
473
  exports.addStyle = addStyle;
@@ -480,6 +477,7 @@ exports.capitalize = capitalize;
480
477
  exports.checkVPN = checkVPN;
481
478
  exports.checkVPNRandomly = checkVPNRandomly;
482
479
  exports.confirm = confirm;
480
+ exports.customizeConsole = customizeConsole;
483
481
  exports.fish = fish;
484
482
  exports.fishResponse = fishResponse;
485
483
  exports.fishX = fishX;
@@ -497,7 +495,6 @@ exports.isObject = isObject;
497
495
  exports.isString = isString;
498
496
  exports.isTruthy = isTruthy;
499
497
  exports.join = join;
500
- exports.logId = logId;
501
498
  exports.noop = noop;
502
499
  exports.padZeros = padZeros;
503
500
  exports.pageLoad = pageLoad;
@@ -107,8 +107,6 @@ declare function setSearchParam(key: string, value: string, fullURL?: string): s
107
107
  declare function removeSearchParams(keys: string[], fullURL?: string): string;
108
108
 
109
109
  declare const scriptName: string;
110
- /** The identifier of the script to be used in logging. */
111
- declare const logId: string;
112
110
  /** The initial tab URL on the script run. */
113
111
  declare const tabURL: string;
114
112
 
@@ -160,4 +158,13 @@ type Options = Record<string, FlagValue>;
160
158
 
161
159
  declare function getOptions(flags: Flag[]): Promise<Options>;
162
160
 
163
- export { $, $$, Flag, Fn, Nullable, Prettify, addStyle, alert, asserted, capitalize, checkVPN, checkVPNRandomly, confirm, 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 };
161
+ interface CustomizedConsole {
162
+ log: Console['log'];
163
+ warn: Console['warn'];
164
+ error: Console['error'];
165
+ debug: Console['debug'];
166
+ }
167
+
168
+ declare function customizeConsole(debug?: boolean): CustomizedConsole;
169
+
170
+ 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, tabURL, toString };
package/browser/index.js CHANGED
@@ -123,20 +123,7 @@ function capitalize(sentence) {
123
123
  return capitalizeWord(sentence);
124
124
  }
125
125
 
126
- let infoObject;
127
- if (typeof GM !== 'undefined') {
128
- infoObject = GM.info;
129
- // eslint-disable-next-line unicorn/no-negated-condition
130
- }
131
- else if (typeof GM_info === 'undefined') {
132
- infoObject = { script: { name: document.title } };
133
- }
134
- else {
135
- infoObject = GM_info;
136
- }
137
- const scriptName = infoObject.script.name;
138
- /** The identifier of the script to be used in logging. */
139
- const logId = `[${scriptName}]:`;
126
+ const scriptName = GM.info.script.name;
140
127
  /** The initial tab URL on the script run. */
141
128
  const tabURL = window.location.href;
142
129
 
@@ -259,8 +246,7 @@ function $$(selectors, parent) {
259
246
  * @param fullURL If provided, it will be our target, otherwise it is the current location.
260
247
  */
261
248
  function getSearchParam(key, fullURL) {
262
- const { search } = new URL(fullURL ?? window.location.href);
263
- const searchParams = new URLSearchParams(search);
249
+ const { searchParams } = new URL(fullURL ?? window.location.href);
264
250
  const value = searchParams.get(key);
265
251
  if (value === null) {
266
252
  return undefined;
@@ -469,4 +455,15 @@ async function getOptions(flags) {
469
455
  return options;
470
456
  }
471
457
 
472
- export { $, $$, addStyle, alert, asserted, capitalize, checkVPN, checkVPNRandomly, confirm, 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 };
458
+ function customizeConsole(debug = false) {
459
+ const base = window.console;
460
+ const logId = `[${scriptName}]:`;
461
+ return {
462
+ log: base.log.bind(base, logId),
463
+ warn: base.warn.bind(base, logId),
464
+ error: base.error.bind(base, logId),
465
+ debug: debug ? base.log.bind(base, logId) : noop,
466
+ };
467
+ }
468
+
469
+ 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, tabURL, toString };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jeniex/utils",
3
- "version": "1.0.27",
3
+ "version": "1.1.3",
4
4
  "author": "JenieX",
5
5
  "homepage": "https://github.com/JenieX/utils",
6
6
  "type": "module",