@nlozgachev/pipelined 0.63.0 → 0.64.0

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/data.mjs CHANGED
@@ -1716,6 +1716,60 @@ var Arr = {
1716
1716
 
1717
1717
  // src/Data/BigNum.ts
1718
1718
  var BigNum = {
1719
+ is: {
1720
+ /**
1721
+ * Returns `true` when the bigint is equal to zero (`0n`).
1722
+ *
1723
+ * @example
1724
+ * ```ts
1725
+ * BigNum.is.zero(0n); // true
1726
+ * BigNum.is.zero(5n); // false
1727
+ * ```
1728
+ */
1729
+ zero: (b) => b === 0n,
1730
+ /**
1731
+ * Returns `true` when the bigint is an even integer.
1732
+ *
1733
+ * @example
1734
+ * ```ts
1735
+ * BigNum.is.even(4n); // true
1736
+ * BigNum.is.even(3n); // false
1737
+ * ```
1738
+ */
1739
+ even: (b) => b % 2n === 0n,
1740
+ /**
1741
+ * Returns `true` when the bigint is an odd integer.
1742
+ *
1743
+ * @example
1744
+ * ```ts
1745
+ * BigNum.is.odd(3n); // true
1746
+ * BigNum.is.odd(4n); // false
1747
+ * ```
1748
+ */
1749
+ odd: (b) => b % 2n !== 0n,
1750
+ /**
1751
+ * Returns `true` when the bigint is strictly greater than zero (`0n`).
1752
+ *
1753
+ * @example
1754
+ * ```ts
1755
+ * BigNum.is.positive(5n); // true
1756
+ * BigNum.is.positive(0n); // false
1757
+ * BigNum.is.positive(-5n); // false
1758
+ * ```
1759
+ */
1760
+ positive: (b) => b > 0n,
1761
+ /**
1762
+ * Returns `true` when the bigint is strictly less than zero (`0n`).
1763
+ *
1764
+ * @example
1765
+ * ```ts
1766
+ * BigNum.is.negative(-5n); // true
1767
+ * BigNum.is.negative(0n); // false
1768
+ * BigNum.is.negative(5n); // false
1769
+ * ```
1770
+ */
1771
+ negative: (b) => b < 0n
1772
+ },
1719
1773
  // --- from ---
1720
1774
  from: {
1721
1775
  /**
@@ -1865,6 +1919,345 @@ var BigNum = {
1865
1919
  max: (b) => (a) => a > b ? a : b
1866
1920
  };
1867
1921
 
1922
+ // src/Data/Bool.ts
1923
+ var isBoolean = (u) => typeof u === "boolean";
1924
+ var isTrue = (u) => u === true;
1925
+ var isFalse = (u) => u === false;
1926
+ var isTruthy = (u) => Boolean(u);
1927
+ var isFalsy = (u) => !u;
1928
+ var not = (b) => !b;
1929
+ var and = (that) => (self) => self && that;
1930
+ var or = (that) => (self) => self || that;
1931
+ var xor = (that) => (self) => self !== that;
1932
+ var andLazy = (that) => (self) => self && that();
1933
+ var orLazy = (that) => (self) => self || that();
1934
+ var all = (booleans) => {
1935
+ for (let i = 0; i < booleans.length; i++) {
1936
+ if (!booleans[i]) {
1937
+ return false;
1938
+ }
1939
+ }
1940
+ return true;
1941
+ };
1942
+ var any = (booleans) => {
1943
+ for (let i = 0; i < booleans.length; i++) {
1944
+ if (booleans[i]) {
1945
+ return true;
1946
+ }
1947
+ }
1948
+ return false;
1949
+ };
1950
+ var fold = (onFalse, onTrue) => (b) => b ? onTrue() : onFalse();
1951
+ var match = (cases) => (b) => b ? cases.true() : cases.false();
1952
+ var fromString = (s) => {
1953
+ const trimmed = s.trim().toLowerCase();
1954
+ if (trimmed === "true") {
1955
+ return Maybe.make.some(true);
1956
+ }
1957
+ if (trimmed === "false") {
1958
+ return Maybe.make.some(false);
1959
+ }
1960
+ return Maybe.make.none();
1961
+ };
1962
+ var fromNumber = (n) => {
1963
+ if (n === 1) {
1964
+ return Maybe.make.some(true);
1965
+ }
1966
+ if (n === 0) {
1967
+ return Maybe.make.some(false);
1968
+ }
1969
+ return Maybe.make.none();
1970
+ };
1971
+ var fromTruthy = (value) => Boolean(value);
1972
+ var toMaybe = (onTrue) => (b) => b ? Maybe.make.some(onTrue()) : Maybe.make.none();
1973
+ var toResult2 = (onErr, onOk) => (b) => b ? Result.make.ok(onOk()) : Result.make.err(onErr());
1974
+ var toNumber = (b) => b ? 1 : 0;
1975
+ var toString = (b) => b ? "true" : "false";
1976
+ var Bool = {
1977
+ is: {
1978
+ /**
1979
+ * Type guard — checks if a value is a primitive boolean.
1980
+ *
1981
+ * @example
1982
+ * ```ts
1983
+ * Bool.is.boolean(true); // true
1984
+ * Bool.is.boolean(false); // true
1985
+ * Bool.is.boolean("true"); // false
1986
+ * Bool.is.boolean(null); // false
1987
+ * ```
1988
+ */
1989
+ boolean: isBoolean,
1990
+ /**
1991
+ * Narrowing guard — checks if a value is strictly `true`.
1992
+ *
1993
+ * @example
1994
+ * ```ts
1995
+ * Bool.is.true(true); // true
1996
+ * Bool.is.true(false); // false
1997
+ * ```
1998
+ */
1999
+ true: isTrue,
2000
+ /**
2001
+ * Narrowing guard — checks if a value is strictly `false`.
2002
+ *
2003
+ * @example
2004
+ * ```ts
2005
+ * Bool.is.false(false); // true
2006
+ * Bool.is.false(true); // false
2007
+ * ```
2008
+ */
2009
+ false: isFalse,
2010
+ /**
2011
+ * Type guard — checks if a value is truthy (not `false`, `0`, `0n`, `""`, `null`, `undefined`, or `NaN`).
2012
+ *
2013
+ * @example
2014
+ * ```ts
2015
+ * Bool.is.truthy("hello"); // true
2016
+ * Bool.is.truthy(42); // true
2017
+ * Bool.is.truthy(0); // false
2018
+ * Bool.is.truthy(null); // false
2019
+ * ```
2020
+ */
2021
+ truthy: isTruthy,
2022
+ /**
2023
+ * Type guard — checks if a value is falsy (`false`, `0`, `0n`, `""`, `null`, `undefined`, or `NaN`).
2024
+ *
2025
+ * @example
2026
+ * ```ts
2027
+ * Bool.is.falsy(""); // true
2028
+ * Bool.is.falsy(null); // true
2029
+ * Bool.is.falsy("content"); // false
2030
+ * ```
2031
+ */
2032
+ falsy: isFalsy
2033
+ },
2034
+ /**
2035
+ * Unary boolean negation: inverts the given boolean value.
2036
+ *
2037
+ * @example
2038
+ * ```ts
2039
+ * Bool.not(true); // false
2040
+ * Bool.not(false); // true
2041
+ * ```
2042
+ */
2043
+ not,
2044
+ /**
2045
+ * Logical AND combinator. Returns `true` only if both `self` and `that` are `true`.
2046
+ *
2047
+ * Data-last: `pipe(self, Bool.and(that))`.
2048
+ *
2049
+ * @example
2050
+ * ```ts
2051
+ * pipe(true, Bool.and(true)); // true
2052
+ * pipe(true, Bool.and(false)); // false
2053
+ * ```
2054
+ */
2055
+ and,
2056
+ /**
2057
+ * Logical OR combinator. Returns `true` if either `self` or `that` is `true`.
2058
+ *
2059
+ * Data-last: `pipe(self, Bool.or(that))`.
2060
+ *
2061
+ * @example
2062
+ * ```ts
2063
+ * pipe(false, Bool.or(true)); // true
2064
+ * pipe(false, Bool.or(false)); // false
2065
+ * ```
2066
+ */
2067
+ or,
2068
+ /**
2069
+ * Logical XOR (exclusive OR) combinator. Returns `true` if exactly one of `self` and `that` is `true`.
2070
+ *
2071
+ * Data-last: `pipe(self, Bool.xor(that))`.
2072
+ *
2073
+ * @example
2074
+ * ```ts
2075
+ * pipe(true, Bool.xor(false)); // true
2076
+ * pipe(true, Bool.xor(true)); // false
2077
+ * ```
2078
+ */
2079
+ xor,
2080
+ /**
2081
+ * Lazy logical AND combinator.
2082
+ * If `self` is `false`, the `that` computation is never evaluated.
2083
+ *
2084
+ * Data-last: `pipe(self, Bool.andLazy(that))`.
2085
+ *
2086
+ * @example
2087
+ * ```ts
2088
+ * pipe(
2089
+ * isCached,
2090
+ * Bool.andLazy(() => checkPermissions())
2091
+ * );
2092
+ * ```
2093
+ */
2094
+ andLazy,
2095
+ /**
2096
+ * Lazy logical OR combinator.
2097
+ * If `self` is `true`, the `that` computation is never evaluated.
2098
+ *
2099
+ * Data-last: `pipe(self, Bool.orLazy(that))`.
2100
+ *
2101
+ * @example
2102
+ * ```ts
2103
+ * pipe(
2104
+ * isAdmin,
2105
+ * Bool.orLazy(() => hasAccess(userId))
2106
+ * );
2107
+ * ```
2108
+ */
2109
+ orLazy,
2110
+ /**
2111
+ * N-ary AND aggregation across an array of booleans.
2112
+ * Returns `true` if every boolean is `true`, or for an empty array (vacuous truth).
2113
+ * Short-circuits on the first `false`.
2114
+ *
2115
+ * @example
2116
+ * ```ts
2117
+ * Bool.all([true, true, true]); // true
2118
+ * Bool.all([true, false, true]); // false
2119
+ * Bool.all([]); // true
2120
+ * ```
2121
+ */
2122
+ all,
2123
+ /**
2124
+ * N-ary OR aggregation across an array of booleans.
2125
+ * Returns `true` if at least one boolean is `true`. Returns `false` for an empty array.
2126
+ * Short-circuits on the first `true`.
2127
+ *
2128
+ * @example
2129
+ * ```ts
2130
+ * Bool.any([false, true, false]); // true
2131
+ * Bool.any([false, false]); // false
2132
+ * Bool.any([]); // false
2133
+ * ```
2134
+ */
2135
+ any,
2136
+ /**
2137
+ * Catamorphism for boolean: evaluates `onFalse()` when `false` and `onTrue()` when `true`.
2138
+ *
2139
+ * Positional ordering: `onFalse` first, `onTrue` second.
2140
+ * Aligned with `Result.fold(onErr, onOk)` and `Maybe.fold(onNone, onSome)`.
2141
+ *
2142
+ * @example
2143
+ * ```ts
2144
+ * pipe(
2145
+ * isDarkMode,
2146
+ * Bool.fold(
2147
+ * () => "light-theme",
2148
+ * () => "dark-theme"
2149
+ * )
2150
+ * );
2151
+ * ```
2152
+ */
2153
+ fold,
2154
+ /**
2155
+ * Pattern matching on boolean using named cases `{ true, false }`.
2156
+ *
2157
+ * @example
2158
+ * ```ts
2159
+ * pipe(
2160
+ * isEnabled,
2161
+ * Bool.match({
2162
+ * true: () => "Feature Active",
2163
+ * false: () => "Feature Disabled",
2164
+ * })
2165
+ * );
2166
+ * ```
2167
+ */
2168
+ match,
2169
+ // --- from ---
2170
+ from: {
2171
+ /**
2172
+ * Parses a string into a `Maybe<boolean>`.
2173
+ * Returns `Some(true)` for `"true"`, `Some(false)` for `"false"` (case-insensitive & trimmed),
2174
+ * and `None` for any other string.
2175
+ *
2176
+ * @example
2177
+ * ```ts
2178
+ * Bool.from.string("true"); // Some(true)
2179
+ * Bool.from.string("FALSE"); // Some(false)
2180
+ * Bool.from.string("yes"); // None
2181
+ * ```
2182
+ */
2183
+ string: fromString,
2184
+ /**
2185
+ * Converts a number into a `Maybe<boolean>`.
2186
+ * Returns `Some(true)` for `1`, `Some(false)` for `0`, and `None` for any other number.
2187
+ *
2188
+ * @example
2189
+ * ```ts
2190
+ * Bool.from.number(1); // Some(true)
2191
+ * Bool.from.number(0); // Some(false)
2192
+ * Bool.from.number(42); // None
2193
+ * ```
2194
+ */
2195
+ number: fromNumber,
2196
+ /**
2197
+ * Coerces any unknown value into a boolean via standard JS `Boolean(value)`.
2198
+ *
2199
+ * @example
2200
+ * ```ts
2201
+ * Bool.from.truthy("hello"); // true
2202
+ * Bool.from.truthy(0); // false
2203
+ * ```
2204
+ */
2205
+ truthy: fromTruthy
2206
+ },
2207
+ // --- to ---
2208
+ to: {
2209
+ /**
2210
+ * Lifts a boolean condition into a `Maybe`.
2211
+ * Returns `Some(onTrue())` when `true`, and `None` when `false`.
2212
+ *
2213
+ * @example
2214
+ * ```ts
2215
+ * pipe(
2216
+ * user.isVerified,
2217
+ * Bool.to.Maybe(() => user.profile)
2218
+ * ); // Some(profile) or None
2219
+ * ```
2220
+ */
2221
+ Maybe: toMaybe,
2222
+ /**
2223
+ * Lifts a boolean condition into a `Result`.
2224
+ * Returns `Ok(onOk())` when `true`, and `Err(onErr())` when `false`.
2225
+ *
2226
+ * @example
2227
+ * ```ts
2228
+ * pipe(
2229
+ * hasPermission,
2230
+ * Bool.to.Result(
2231
+ * () => "Permission denied",
2232
+ * () => sessionData
2233
+ * )
2234
+ * ); // Ok(sessionData) or Err("Permission denied")
2235
+ * ```
2236
+ */
2237
+ Result: toResult2,
2238
+ /**
2239
+ * Converts a boolean to numeric `1` or `0`.
2240
+ *
2241
+ * @example
2242
+ * ```ts
2243
+ * Bool.to.number(true); // 1
2244
+ * Bool.to.number(false); // 0
2245
+ * ```
2246
+ */
2247
+ number: toNumber,
2248
+ /**
2249
+ * Converts a boolean to literal string `"true"` or `"false"`.
2250
+ *
2251
+ * @example
2252
+ * ```ts
2253
+ * Bool.to.string(true); // "true"
2254
+ * Bool.to.string(false); // "false"
2255
+ * ```
2256
+ */
2257
+ string: toString
2258
+ }
2259
+ };
2260
+
1868
2261
  // src/Data/Dict.ts
1869
2262
  var DictIs = {
1870
2263
  empty: (m) => m.size === 0,
@@ -3253,6 +3646,7 @@ var Uniq = {
3253
3646
  export {
3254
3647
  Arr,
3255
3648
  BigNum,
3649
+ Bool,
3256
3650
  Dict,
3257
3651
  Json,
3258
3652
  Num,