@hairy/utils 1.6.2 → 1.7.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.
package/dist/index.cjs CHANGED
@@ -88,6 +88,7 @@ __export(index_exports, {
88
88
  isWeex: () => isWeex,
89
89
  isWindow: () => isWindow,
90
90
  join: () => join_default,
91
+ jsonTryParse: () => jsonTryParse,
91
92
  kebabCase: () => kebabCase,
92
93
  keys: () => keys_default,
93
94
  loop: () => loop,
@@ -2925,6 +2926,15 @@ var isMobile = () => isBrowser() && navigator.userAgent.toLowerCase().includes("
2925
2926
  var isFormData = (value) => isObject_default(value) && isBrowser() && value instanceof FormData;
2926
2927
  var isWindow = (value) => typeof window !== "undefined" && toString.call(value) === "[object Window]";
2927
2928
 
2929
+ // src/util/json.ts
2930
+ function jsonTryParse(text) {
2931
+ try {
2932
+ return JSON.parse(text || "");
2933
+ } catch {
2934
+ return void 0;
2935
+ }
2936
+ }
2937
+
2928
2938
  // src/util/noop.ts
2929
2939
  var noop2 = () => {
2930
2940
  };
@@ -3032,6 +3042,7 @@ function whenever(value, callback) {
3032
3042
  isWeex,
3033
3043
  isWindow,
3034
3044
  join,
3045
+ jsonTryParse,
3035
3046
  kebabCase,
3036
3047
  keys,
3037
3048
  loop,
package/dist/index.d.ts CHANGED
@@ -275,6 +275,8 @@ declare const isMobile: () => boolean;
275
275
  declare const isFormData: (value: any) => value is FormData;
276
276
  declare const isWindow: (value: any) => value is Window;
277
277
 
278
+ declare function jsonTryParse(text: string | undefined | null): any;
279
+
278
280
  declare const noop: (...args: any) => any;
279
281
 
280
282
  type UnaryFunction<ValueType, ReturnType> = (value: ValueType) => ReturnType | PromiseLike<ReturnType>;
@@ -316,4 +318,4 @@ declare function riposte<T>(...args: [cond: boolean, value: T][]): T;
316
318
  declare function unwrap<T extends object>(value: T | (() => T)): T;
317
319
  declare function whenever<T, C extends (value: Exclude<T, null | undefined>) => any>(value: T, callback: C): ReturnType<C> | undefined;
318
320
 
319
- export { type Arrayable, type Awaitable, BIG_INTS, type BooleanLike, type DecimalOptions, type DeepKeyof, type DeepPartial, type DeepReadonly, type DeepReplace, type DeepRequired, Deferred, type Delimiter, type Dimension, type DynamicObject, type FormatGroupOptions, type FormatNumericOptions, type Key, type Noop, type NumberObject, type Numberish, type Numeric, type NumericObject, type Option, type Pipeline, type StringObject, type SymbolObject, type Typeof, type UnaryFunction, arange, average, camelCase, capitalCase, compose, constantCase, cover, decimal, delay, dotCase, formToObject, formatNumeric, formatSize, formatUnit, getTypeof, gt, gte, integer, isAndroid, isBrowser, isChrome, isEdge, isFF, isFormData, isIE, isIE11, isIE9, isIOS, isMobile, isPhantomJS, isTypeof, isWeex, isWindow, kebabCase, loop, lt, lte, noCase, noop, numerfix, objectToForm, pPipe, parseNumeric, pascalCase, pascalSnakeCase, pathCase, percentage, pipe, plus, riposte, sentenceCase, snakeCase, trainCase, unum, unwrap, whenever, zerofill, zeromove };
321
+ export { type Arrayable, type Awaitable, BIG_INTS, type BooleanLike, type DecimalOptions, type DeepKeyof, type DeepPartial, type DeepReadonly, type DeepReplace, type DeepRequired, Deferred, type Delimiter, type Dimension, type DynamicObject, type FormatGroupOptions, type FormatNumericOptions, type Key, type Noop, type NumberObject, type Numberish, type Numeric, type NumericObject, type Option, type Pipeline, type StringObject, type SymbolObject, type Typeof, type UnaryFunction, arange, average, camelCase, capitalCase, compose, constantCase, cover, decimal, delay, dotCase, formToObject, formatNumeric, formatSize, formatUnit, getTypeof, gt, gte, integer, isAndroid, isBrowser, isChrome, isEdge, isFF, isFormData, isIE, isIE11, isIE9, isIOS, isMobile, isPhantomJS, isTypeof, isWeex, isWindow, jsonTryParse, kebabCase, loop, lt, lte, noCase, noop, numerfix, objectToForm, pPipe, parseNumeric, pascalCase, pascalSnakeCase, pathCase, percentage, pipe, plus, riposte, sentenceCase, snakeCase, trainCase, unum, unwrap, whenever, zerofill, zeromove };
@@ -4147,6 +4147,15 @@
4147
4147
  var isFormData = (value) => isObject_default(value) && isBrowser() && value instanceof FormData;
4148
4148
  var isWindow = (value) => typeof window !== "undefined" && toString.call(value) === "[object Window]";
4149
4149
 
4150
+ // src/util/json.ts
4151
+ function jsonTryParse(text) {
4152
+ try {
4153
+ return JSON.parse(text || "");
4154
+ } catch {
4155
+ return void 0;
4156
+ }
4157
+ }
4158
+
4150
4159
  // src/util/noop.ts
4151
4160
  var noop2 = () => {
4152
4161
  };
package/dist/index.js CHANGED
@@ -2802,6 +2802,15 @@ var isMobile = () => isBrowser() && navigator.userAgent.toLowerCase().includes("
2802
2802
  var isFormData = (value) => isObject_default(value) && isBrowser() && value instanceof FormData;
2803
2803
  var isWindow = (value) => typeof window !== "undefined" && toString.call(value) === "[object Window]";
2804
2804
 
2805
+ // src/util/json.ts
2806
+ function jsonTryParse(text) {
2807
+ try {
2808
+ return JSON.parse(text || "");
2809
+ } catch {
2810
+ return void 0;
2811
+ }
2812
+ }
2813
+
2805
2814
  // src/util/noop.ts
2806
2815
  var noop2 = () => {
2807
2816
  };
@@ -2908,6 +2917,7 @@ export {
2908
2917
  isWeex,
2909
2918
  isWindow,
2910
2919
  join_default as join,
2920
+ jsonTryParse,
2911
2921
  kebabCase,
2912
2922
  keys_default as keys,
2913
2923
  loop,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hairy/utils",
3
3
  "type": "module",
4
- "version": "1.6.2",
4
+ "version": "1.7.1",
5
5
  "description": "Library for anywhere",
6
6
  "author": "Hairyf <wwu710632@gmail.com>",
7
7
  "license": "MIT",