@duplojs/utils 1.3.27 → 1.3.28

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.
@@ -1,2 +1,2 @@
1
- export declare function concat<GenericElement extends unknown>(elements: readonly GenericElement[]): (array: readonly GenericElement[]) => GenericElement[];
2
- export declare function concat<GenericElement extends unknown>(array: readonly GenericElement[], elements: readonly GenericElement[], ...elementsRest: readonly GenericElement[][]): GenericElement[];
1
+ export declare function concat<GenericFirstArray extends readonly unknown[], GenericSecondArray extends readonly unknown[]>(elements: GenericSecondArray): (array: GenericFirstArray) => (GenericFirstArray[number] | GenericSecondArray[number])[];
2
+ export declare function concat<GenericFirstArray extends readonly unknown[], GenericSecondArray extends readonly unknown[], GenericRest extends readonly unknown[][]>(array: GenericFirstArray, elements: GenericSecondArray, ...elementsRest: GenericRest): (GenericFirstArray[number] | GenericSecondArray[number] | GenericRest[number][number])[];
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ function falsy(input) {
4
+ return !input;
5
+ }
6
+
7
+ exports.falsy = falsy;
@@ -0,0 +1,2 @@
1
+ import { type FalsyValue, type UnionContain } from "./types";
2
+ export declare function falsy<GenericInput extends unknown>(input: GenericInput): input is (Extract<GenericInput, FalsyValue> | (UnionContain<GenericInput, string> extends true ? "" : never) | (UnionContain<GenericInput, number> extends true ? 0 : never) | (UnionContain<GenericInput, bigint> extends true ? 0n : never));
@@ -0,0 +1,5 @@
1
+ function falsy(input) {
2
+ return !input;
3
+ }
4
+
5
+ export { falsy };
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ function hasKinds(...args) {
4
+ if (args.length === 1) {
5
+ const [kinds] = args;
6
+ return (input) => hasKinds(input, kinds);
7
+ }
8
+ const [input, kinds] = args;
9
+ for (const kind of kinds) {
10
+ if (!kind.has(input)) {
11
+ return false;
12
+ }
13
+ }
14
+ return true;
15
+ }
16
+
17
+ exports.hasKinds = hasKinds;
@@ -0,0 +1,4 @@
1
+ import { type Kind, type KindHandler } from "./kind";
2
+ import { type AnyTuple, type UnionToIntersection } from "./types";
3
+ export declare function hasKinds<GenericInput extends unknown, const GenericKindHandlers extends AnyTuple<KindHandler>, GenericKindHandler extends GenericKindHandlers[number]>(kinds: GenericKindHandlers): (input: GenericInput) => input is Extract<GenericInput, UnionToIntersection<GenericKindHandler extends any ? Kind<GenericKindHandler["definition"]> : never>>;
4
+ export declare function hasKinds<GenericInput extends unknown, const GenericKindHandlers extends AnyTuple<KindHandler>, GenericKindHandler extends GenericKindHandlers[number]>(input: GenericInput, kinds: GenericKindHandlers): input is Extract<GenericInput, UnionToIntersection<GenericKindHandler extends any ? Kind<GenericKindHandler["definition"]> : never>>;
@@ -0,0 +1,15 @@
1
+ function hasKinds(...args) {
2
+ if (args.length === 1) {
3
+ const [kinds] = args;
4
+ return (input) => hasKinds(input, kinds);
5
+ }
6
+ const [input, kinds] = args;
7
+ for (const kind of kinds) {
8
+ if (!kind.has(input)) {
9
+ return false;
10
+ }
11
+ }
12
+ return true;
13
+ }
14
+
15
+ export { hasKinds };
@@ -41,3 +41,6 @@ export * from "./createKindIdentifier";
41
41
  export * from "./forwardLog";
42
42
  export * from "./override";
43
43
  export * from "./errorKindNamespace";
44
+ export * from "./truthy";
45
+ export * from "./falsy";
46
+ export * from "./hasKinds";
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ function truthy(input) {
4
+ return !!input;
5
+ }
6
+
7
+ exports.truthy = truthy;
@@ -0,0 +1,3 @@
1
+ import { type FalsyValue } from "./types";
2
+ export type TruthyValue<GenericInput extends unknown> = Exclude<GenericInput, FalsyValue>;
3
+ export declare function truthy<GenericInput extends unknown>(input: GenericInput): input is TruthyValue<GenericInput>;
@@ -0,0 +1,5 @@
1
+ function truthy(input) {
2
+ return !!input;
3
+ }
4
+
5
+ export { truthy };
@@ -0,0 +1 @@
1
+ export type FalsyValue = false | 0 | 0n | "" | null | undefined;
@@ -42,3 +42,4 @@ export * from "./unwrapArray";
42
42
  export * from "./onlyLiteral";
43
43
  export * from "./sortType";
44
44
  export * from "./maybeGetter";
45
+ export * from "./falsyValue";
@@ -1 +1 @@
1
- export type Predicate<GenericFunction extends (input: any, ...args: any[]) => input is any> = GenericFunction extends (input: any, ...args: any[]) => input is infer InferredPredicate ? InferredPredicate : never;
1
+ export type Predicate<GenericFunction extends (input: any, ...args: any[]) => boolean> = GenericFunction extends (input: any, ...args: any[]) => input is infer InferredPredicate ? InferredPredicate : Parameters<GenericFunction>[0];
@@ -7,6 +7,7 @@ function bool(value) {
7
7
  return value === undefined
8
8
  || value === null
9
9
  || value === 0
10
+ || value === 0n
10
11
  || value === ""
11
12
  || value === false
12
13
  ? falsy.boolFalsy(value)
@@ -1,5 +1,5 @@
1
- import { type IsEqual } from "../../common";
2
- import { type BoolFalsyValue, type EitherBoolFalsy } from "./falsy";
1
+ import { type FalsyValue, type IsEqual } from "../../common";
2
+ import { type EitherBoolFalsy } from "./falsy";
3
3
  import { type EitherBoolTruthy } from "./truthy";
4
- export declare function bool<const GenericValue extends unknown = undefined>(value: GenericValue): GenericValue extends BoolFalsyValue ? EitherBoolFalsy<GenericValue> : IsEqual<GenericValue, number> extends true ? EitherBoolTruthy<GenericValue> | EitherBoolFalsy<0> : IsEqual<GenericValue, string> extends true ? EitherBoolTruthy<GenericValue> | EitherBoolFalsy<""> : EitherBoolTruthy<GenericValue>;
4
+ export declare function bool<const GenericValue extends unknown = undefined>(value: GenericValue): GenericValue extends FalsyValue ? EitherBoolFalsy<GenericValue> : IsEqual<GenericValue, number> extends true ? EitherBoolTruthy<GenericValue> | EitherBoolFalsy<0> : IsEqual<GenericValue, bigint> extends true ? EitherBoolTruthy<GenericValue> | EitherBoolFalsy<0n> : IsEqual<GenericValue, string> extends true ? EitherBoolTruthy<GenericValue> | EitherBoolFalsy<""> : EitherBoolTruthy<GenericValue>;
5
5
  export type Bool<GenericValue extends unknown> = EitherBoolTruthy<GenericValue> | EitherBoolFalsy;
@@ -5,6 +5,7 @@ function bool(value) {
5
5
  return value === undefined
6
6
  || value === null
7
7
  || value === 0
8
+ || value === 0n
8
9
  || value === ""
9
10
  || value === false
10
11
  ? boolFalsy(value)
@@ -1,15 +1,14 @@
1
- import { type EscapeVoid, type AnyValue, type Unwrap, type BreakGenericLink } from "../../common";
1
+ import { type EscapeVoid, type AnyValue, type Unwrap, type BreakGenericLink, type FalsyValue } from "../../common";
2
2
  import { type Kind } from "../../common/kind";
3
3
  import { eitherBoolKind } from "./base";
4
4
  import { bool } from "./create";
5
5
  import { type EitherLeft } from "../left";
6
6
  import { type EitherRight } from "../right";
7
- export type BoolFalsyValue = 0 | "" | undefined | null | false;
8
7
  export declare const eitherBoolFalsyKind: import("../../common").KindHandler<import("../../common").KindDefinition<"@DuplojsUtilsEither/bool-falsy", unknown>>;
9
- type _EitherBoolFalsy<GenericValue extends BoolFalsyValue = BoolFalsyValue> = (EitherLeft<"bool", GenericValue> & Kind<typeof eitherBoolKind.definition> & Kind<typeof eitherBoolFalsyKind.definition>);
10
- export interface EitherBoolFalsy<GenericValue extends BoolFalsyValue = BoolFalsyValue> extends _EitherBoolFalsy<GenericValue> {
8
+ type _EitherBoolFalsy<GenericValue extends FalsyValue = FalsyValue> = (EitherLeft<"bool", GenericValue> & Kind<typeof eitherBoolKind.definition> & Kind<typeof eitherBoolFalsyKind.definition>);
9
+ export interface EitherBoolFalsy<GenericValue extends FalsyValue = FalsyValue> extends _EitherBoolFalsy<GenericValue> {
11
10
  }
12
- export declare function boolFalsy<const GenericValue extends BoolFalsyValue = undefined>(value?: GenericValue): EitherBoolFalsy<GenericValue>;
11
+ export declare function boolFalsy<const GenericValue extends FalsyValue = undefined>(value?: GenericValue): EitherBoolFalsy<GenericValue>;
13
12
  type Either = EitherRight | EitherLeft;
14
13
  export declare function isBoolFalsy<GenericInput extends unknown>(input: GenericInput): input is Extract<GenericInput, EitherBoolFalsy>;
15
14
  type ToEither<GenericValue extends unknown> = GenericValue extends Either ? GenericValue : ReturnType<typeof bool<GenericValue>>;
package/dist/index.cjs CHANGED
@@ -54,6 +54,9 @@ var createKindIdentifier = require('./common/createKindIdentifier.cjs');
54
54
  var forwardLog = require('./common/forwardLog.cjs');
55
55
  var override = require('./common/override.cjs');
56
56
  var errorKindNamespace = require('./common/errorKindNamespace.cjs');
57
+ var truthy = require('./common/truthy.cjs');
58
+ var falsy = require('./common/falsy.cjs');
59
+ var hasKinds = require('./common/hasKinds.cjs');
57
60
 
58
61
 
59
62
 
@@ -135,3 +138,6 @@ exports.createKindIdentifier = createKindIdentifier.createKindIdentifier;
135
138
  exports.forwardLog = forwardLog.forwardLog;
136
139
  exports.createOverride = override.createOverride;
137
140
  exports.createErrorKind = errorKindNamespace.createErrorKind;
141
+ exports.truthy = truthy.truthy;
142
+ exports.falsy = falsy.falsy;
143
+ exports.hasKinds = hasKinds.hasKinds;
package/dist/index.mjs CHANGED
@@ -76,3 +76,6 @@ export { createKindIdentifier } from './common/createKindIdentifier.mjs';
76
76
  export { forwardLog } from './common/forwardLog.mjs';
77
77
  export { createOverride } from './common/override.mjs';
78
78
  export { createErrorKind } from './common/errorKindNamespace.mjs';
79
+ export { truthy } from './common/truthy.mjs';
80
+ export { falsy } from './common/falsy.mjs';
81
+ export { hasKinds } from './common/hasKinds.mjs';
@@ -976,6 +976,9 @@
976
976
  {
977
977
  "name": "expectType.d.ts"
978
978
  },
979
+ {
980
+ "name": "falsyValue.d.ts"
981
+ },
979
982
  {
980
983
  "name": "fixDeepFunctionInfer.d.ts"
981
984
  },
@@ -1197,6 +1200,15 @@
1197
1200
  {
1198
1201
  "name": "externalPromise.mjs"
1199
1202
  },
1203
+ {
1204
+ "name": "falsy.cjs"
1205
+ },
1206
+ {
1207
+ "name": "falsy.d.ts"
1208
+ },
1209
+ {
1210
+ "name": "falsy.mjs"
1211
+ },
1200
1212
  {
1201
1213
  "name": "forward.cjs"
1202
1214
  },
@@ -1224,6 +1236,15 @@
1224
1236
  {
1225
1237
  "name": "globalStore.mjs"
1226
1238
  },
1239
+ {
1240
+ "name": "hasKinds.cjs"
1241
+ },
1242
+ {
1243
+ "name": "hasKinds.d.ts"
1244
+ },
1245
+ {
1246
+ "name": "hasKinds.mjs"
1247
+ },
1227
1248
  {
1228
1249
  "name": "index.d.ts"
1229
1250
  },
@@ -1407,6 +1428,15 @@
1407
1428
  {
1408
1429
  "name": "toWrappedValue.mjs"
1409
1430
  },
1431
+ {
1432
+ "name": "truthy.cjs"
1433
+ },
1434
+ {
1435
+ "name": "truthy.d.ts"
1436
+ },
1437
+ {
1438
+ "name": "truthy.mjs"
1439
+ },
1410
1440
  {
1411
1441
  "name": "unwrap.cjs"
1412
1442
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duplojs/utils",
3
- "version": "1.3.27",
3
+ "version": "1.3.28",
4
4
  "author": {
5
5
  "name": "mathcovax",
6
6
  "url": "https://github.com/mathcovax"