@talismn/util 0.3.0 → 0.3.2

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/README.md CHANGED
@@ -1,5 +1,3 @@
1
1
  # @talismn/util
2
2
 
3
3
  This library hosts non-UI code meant to be shared between Talisman projects
4
-
5
- It doesn't need to be published as npm package, therefore it is simply transpiled with tsc.
@@ -26,3 +26,5 @@ export * from "./validateHexString";
26
26
  export * from "./normalizeAddress";
27
27
  export * from "./isAddressEqual";
28
28
  export * from "./isAscii";
29
+ export * from "./isNotNil";
30
+ export * from "./isTruthy";
@@ -0,0 +1,9 @@
1
+ /**
2
+ * WARNING: This function only checks against null or undefined, it does not coerce the value.
3
+ * ie: false and 0 are considered not nil
4
+ * Use isTruthy instead for a regular coercion check.
5
+ *
6
+ * @param value
7
+ * @returns whether the value is neither null nor undefined
8
+ */
9
+ export declare const isNotNil: <T>(value: T | null | undefined) => value is T;
@@ -0,0 +1 @@
1
+ export declare const isTruthy: <T>(value: T | null | undefined) => value is T;
@@ -303,6 +303,18 @@ const isAscii = str => {
303
303
  return [...str].every(char => char.charCodeAt(0) <= 127);
304
304
  };
305
305
 
306
+ /**
307
+ * WARNING: This function only checks against null or undefined, it does not coerce the value.
308
+ * ie: false and 0 are considered not nil
309
+ * Use isTruthy instead for a regular coercion check.
310
+ *
311
+ * @param value
312
+ * @returns whether the value is neither null nor undefined
313
+ */
314
+ const isNotNil = value => value !== null && value !== undefined;
315
+
316
+ const isTruthy = value => Boolean(value);
317
+
306
318
  exports.BigMath = BigMath;
307
319
  exports.Deferred = Deferred;
308
320
  exports.MAX_DECIMALS_FORMAT = MAX_DECIMALS_FORMAT;
@@ -323,6 +335,8 @@ exports.isAscii = isAscii;
323
335
  exports.isBigInt = isBigInt;
324
336
  exports.isBooleanTrue = isBooleanTrue;
325
337
  exports.isEthereumAddress = isEthereumAddress;
338
+ exports.isNotNil = isNotNil;
339
+ exports.isTruthy = isTruthy;
326
340
  exports.isValidSubstrateAddress = isValidSubstrateAddress;
327
341
  exports.normalizeAddress = normalizeAddress;
328
342
  exports.planckToTokens = planckToTokens;
@@ -303,6 +303,18 @@ const isAscii = str => {
303
303
  return [...str].every(char => char.charCodeAt(0) <= 127);
304
304
  };
305
305
 
306
+ /**
307
+ * WARNING: This function only checks against null or undefined, it does not coerce the value.
308
+ * ie: false and 0 are considered not nil
309
+ * Use isTruthy instead for a regular coercion check.
310
+ *
311
+ * @param value
312
+ * @returns whether the value is neither null nor undefined
313
+ */
314
+ const isNotNil = value => value !== null && value !== undefined;
315
+
316
+ const isTruthy = value => Boolean(value);
317
+
306
318
  exports.BigMath = BigMath;
307
319
  exports.Deferred = Deferred;
308
320
  exports.MAX_DECIMALS_FORMAT = MAX_DECIMALS_FORMAT;
@@ -323,6 +335,8 @@ exports.isAscii = isAscii;
323
335
  exports.isBigInt = isBigInt;
324
336
  exports.isBooleanTrue = isBooleanTrue;
325
337
  exports.isEthereumAddress = isEthereumAddress;
338
+ exports.isNotNil = isNotNil;
339
+ exports.isTruthy = isTruthy;
326
340
  exports.isValidSubstrateAddress = isValidSubstrateAddress;
327
341
  exports.normalizeAddress = normalizeAddress;
328
342
  exports.planckToTokens = planckToTokens;
@@ -297,4 +297,16 @@ const isAscii = str => {
297
297
  return [...str].every(char => char.charCodeAt(0) <= 127);
298
298
  };
299
299
 
300
- export { BigMath, Deferred, MAX_DECIMALS_FORMAT, addTrailingSlash, blake2Concat, classNames, convertAddress, decodeAnyAddress, decodeSs58Format, encodeAnyAddress, firstThenDebounce, formatDecimals, formatPrice, hasOwnProperty, isAddressEqual, isArrayOf, isAscii, isBigInt, isBooleanTrue, isEthereumAddress, isValidSubstrateAddress, normalizeAddress, planckToTokens, sleep, throwAfter, tokensToPlanck, twox64Concat, validateHexString };
300
+ /**
301
+ * WARNING: This function only checks against null or undefined, it does not coerce the value.
302
+ * ie: false and 0 are considered not nil
303
+ * Use isTruthy instead for a regular coercion check.
304
+ *
305
+ * @param value
306
+ * @returns whether the value is neither null nor undefined
307
+ */
308
+ const isNotNil = value => value !== null && value !== undefined;
309
+
310
+ const isTruthy = value => Boolean(value);
311
+
312
+ export { BigMath, Deferred, MAX_DECIMALS_FORMAT, addTrailingSlash, blake2Concat, classNames, convertAddress, decodeAnyAddress, decodeSs58Format, encodeAnyAddress, firstThenDebounce, formatDecimals, formatPrice, hasOwnProperty, isAddressEqual, isArrayOf, isAscii, isBigInt, isBooleanTrue, isEthereumAddress, isNotNil, isTruthy, isValidSubstrateAddress, normalizeAddress, planckToTokens, sleep, throwAfter, tokensToPlanck, twox64Concat, validateHexString };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@talismn/util",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "author": "Talisman",
5
5
  "homepage": "https://talisman.xyz",
6
6
  "license": "GPL-3.0-or-later",