@leancodepl/utils 9.7.4 → 10.0.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/CHANGELOG.md +12 -0
- package/dist/index.js +63 -71
- package/dist/index.umd.cjs +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See
|
|
4
4
|
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [10.0.0](https://github.com/leancodepl/js_corelibrary/compare/v9.7.4...v10.0.0) (2026-02-11)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- exclude external packages from build output
|
|
11
|
+
([4c2be7a](https://github.com/leancodepl/js_corelibrary/commit/4c2be7ac64eb6ed5603ba61b9aeef75a454dffb3))
|
|
12
|
+
|
|
13
|
+
# Change Log
|
|
14
|
+
|
|
15
|
+
All notable changes to this project will be documented in this file. See
|
|
16
|
+
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
17
|
+
|
|
6
18
|
## [9.7.4](https://github.com/leancodepl/js_corelibrary/compare/v9.7.3...v9.7.4) (2026-02-10)
|
|
7
19
|
|
|
8
20
|
**Note:** Version bump only for package @leancodepl/utils
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import a from "tiny-invariant";
|
|
2
|
+
import { jsx as p } from "react/jsx-runtime";
|
|
3
|
+
import { useState as c, useCallback as u, useMemo as d, createContext as m, useEffect as f, useContext as y } from "react";
|
|
4
|
+
function g() {
|
|
5
|
+
const [n, t] = c(0), e = u(async (r) => {
|
|
5
6
|
t((o) => o + 1);
|
|
6
7
|
try {
|
|
7
8
|
return await r();
|
|
@@ -11,23 +12,23 @@ function v() {
|
|
|
11
12
|
}, []);
|
|
12
13
|
return [n > 0, e];
|
|
13
14
|
}
|
|
14
|
-
function
|
|
15
|
-
const [t, e] =
|
|
15
|
+
function I(n) {
|
|
16
|
+
const [t, e] = g(), r = d(
|
|
16
17
|
() => n ? (...o) => e(() => n(...o)) : void 0,
|
|
17
18
|
[n, e]
|
|
18
19
|
);
|
|
19
20
|
return [t, r];
|
|
20
21
|
}
|
|
21
|
-
function
|
|
22
|
+
function k(n) {
|
|
22
23
|
return [u(() => n(!0), [n]), u(() => n(!1), [n])];
|
|
23
24
|
}
|
|
24
|
-
function
|
|
25
|
-
const [t, e] =
|
|
25
|
+
function L(n) {
|
|
26
|
+
const [t, e] = c(!1), [r, o] = k(e), i = u(() => {
|
|
26
27
|
o(), n && setTimeout(n);
|
|
27
28
|
}, [o, n]);
|
|
28
29
|
return { isDialogOpen: t, openDialog: r, closeDialog: i };
|
|
29
30
|
}
|
|
30
|
-
function
|
|
31
|
+
function N(n) {
|
|
31
32
|
const t = [];
|
|
32
33
|
for (const e in n) {
|
|
33
34
|
const r = n[e];
|
|
@@ -35,112 +36,103 @@ function S(n) {
|
|
|
35
36
|
}
|
|
36
37
|
return t;
|
|
37
38
|
}
|
|
38
|
-
function
|
|
39
|
-
const [r, o] =
|
|
39
|
+
function v(n, t, e) {
|
|
40
|
+
const [r, o] = c(n);
|
|
40
41
|
(e ? !e(n, r) : n !== r) && (o(n), t(n));
|
|
41
42
|
}
|
|
42
|
-
function
|
|
43
|
+
function w(n, t) {
|
|
43
44
|
return Object.fromEntries(Object.entries(n).map(([e, r]) => [`${t}${e}`, r]));
|
|
44
45
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (!n) {
|
|
48
|
-
if (D)
|
|
49
|
-
throw new Error(a);
|
|
50
|
-
var e = typeof t == "function" ? t() : t, r = e ? "".concat(a, ": ").concat(e) : a;
|
|
51
|
-
throw new Error(r);
|
|
52
|
-
}
|
|
46
|
+
function D(n, t) {
|
|
47
|
+
a(n !== void 0, t);
|
|
53
48
|
}
|
|
54
49
|
function x(n, t) {
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
function h(n, t) {
|
|
58
|
-
f(n != null, t);
|
|
50
|
+
a(n != null, t);
|
|
59
51
|
}
|
|
60
|
-
function
|
|
61
|
-
|
|
52
|
+
function C(n, t) {
|
|
53
|
+
a(n !== null, t);
|
|
62
54
|
}
|
|
63
|
-
function
|
|
55
|
+
function R(n, t = {}) {
|
|
64
56
|
if (typeof n == "string") {
|
|
65
57
|
const { name: e } = t, r = document.createElement("a");
|
|
66
58
|
r.href = n, r.target = "_blank", e && (r.download = e), r.click();
|
|
67
59
|
} else {
|
|
68
60
|
const e = URL.createObjectURL(n);
|
|
69
|
-
|
|
61
|
+
R(e, t), URL.revokeObjectURL(e);
|
|
70
62
|
}
|
|
71
63
|
}
|
|
72
|
-
function
|
|
73
|
-
return
|
|
64
|
+
function z(n, t) {
|
|
65
|
+
return D(n, t), n;
|
|
74
66
|
}
|
|
75
|
-
function
|
|
76
|
-
return
|
|
67
|
+
function E(n, t) {
|
|
68
|
+
return x(n, t), n;
|
|
77
69
|
}
|
|
78
|
-
function
|
|
79
|
-
return
|
|
70
|
+
function O(n, t) {
|
|
71
|
+
return C(n, t), n;
|
|
80
72
|
}
|
|
81
|
-
function
|
|
73
|
+
function l(n, t) {
|
|
82
74
|
return n.length === 0 ? "" : t(n[0]) + n.slice(1);
|
|
83
75
|
}
|
|
84
|
-
function
|
|
85
|
-
return
|
|
76
|
+
function T(n) {
|
|
77
|
+
return l(n, (t) => t.toLowerCase());
|
|
86
78
|
}
|
|
87
|
-
function
|
|
88
|
-
return
|
|
79
|
+
function h(n) {
|
|
80
|
+
return l(n, (t) => t.toUpperCase());
|
|
89
81
|
}
|
|
90
|
-
function
|
|
82
|
+
function s(n, t) {
|
|
91
83
|
if (n != null) {
|
|
92
84
|
if (Array.isArray(n))
|
|
93
|
-
return n.map((e) =>
|
|
85
|
+
return n.map((e) => s(e, t));
|
|
94
86
|
if (typeof n == "object") {
|
|
95
|
-
const e = t === "capitalize" ?
|
|
87
|
+
const e = t === "capitalize" ? h : T;
|
|
96
88
|
return Object.entries(n).reduce(
|
|
97
|
-
(r, [o, i]) => ({ ...r, [e(o)]:
|
|
89
|
+
(r, [o, i]) => ({ ...r, [e(o)]: s(i, t) }),
|
|
98
90
|
{}
|
|
99
91
|
);
|
|
100
92
|
}
|
|
101
93
|
return n;
|
|
102
94
|
}
|
|
103
95
|
}
|
|
104
|
-
function
|
|
105
|
-
return
|
|
96
|
+
function P(n) {
|
|
97
|
+
return s(n, "uncapitalize");
|
|
106
98
|
}
|
|
107
99
|
function U(n) {
|
|
108
|
-
return
|
|
100
|
+
return s(n, "capitalize");
|
|
109
101
|
}
|
|
110
|
-
function
|
|
102
|
+
function V() {
|
|
111
103
|
const n = m([void 0, () => {
|
|
112
104
|
}]);
|
|
113
105
|
function t() {
|
|
114
|
-
return
|
|
106
|
+
return y(n);
|
|
115
107
|
}
|
|
116
108
|
return t.Provider = function({ children: r, initialValue: o }) {
|
|
117
|
-
const i =
|
|
118
|
-
return /* @__PURE__ */
|
|
109
|
+
const i = c(o);
|
|
110
|
+
return /* @__PURE__ */ p(n.Provider, { value: i, children: r });
|
|
119
111
|
}, t.set = function(r) {
|
|
120
112
|
const [, o] = t();
|
|
121
|
-
|
|
113
|
+
f(() => {
|
|
122
114
|
o(r);
|
|
123
|
-
}, [o, r]),
|
|
115
|
+
}, [o, r]), f(() => () => o(void 0), [o]);
|
|
124
116
|
}, t;
|
|
125
117
|
}
|
|
126
118
|
export {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
119
|
+
w as addPrefix,
|
|
120
|
+
D as assertDefined,
|
|
121
|
+
x as assertNotEmpty,
|
|
122
|
+
C as assertNotNull,
|
|
131
123
|
U as capitalizeDeep,
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
124
|
+
R as downloadFile,
|
|
125
|
+
z as ensureDefined,
|
|
126
|
+
E as ensureNotEmpty,
|
|
127
|
+
O as ensureNotNull,
|
|
128
|
+
V as mkValueContext,
|
|
129
|
+
T as toLowerFirst,
|
|
130
|
+
h as toUpperFirst,
|
|
131
|
+
P as uncapitalizeDeep,
|
|
132
|
+
I as useBoundRunInTask,
|
|
133
|
+
L as useDialog,
|
|
134
|
+
N as useKeyByRoute,
|
|
135
|
+
g as useRunInTask,
|
|
136
|
+
k as useSetUnset,
|
|
137
|
+
v as useSyncState
|
|
146
138
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(t,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("tiny-invariant"),require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","tiny-invariant","react/jsx-runtime","react"],r):(t=typeof globalThis<"u"?globalThis:t||self,r(t["@leancodepl/utils"]={},t.invariant,t.jsxRuntime,t.react))})(this,(function(t,r,g,o){"use strict";function f(){const[n,e]=o.useState(0),u=o.useCallback(async i=>{e(s=>s+1);try{return await i()}finally{e(s=>s-1)}},[]);return[n>0,u]}function C(n){const[e,u]=f(),i=o.useMemo(()=>n?(...s)=>u(()=>n(...s)):void 0,[n,u]);return[e,i]}function l(n){return[o.useCallback(()=>n(!0),[n]),o.useCallback(()=>n(!1),[n])]}function R(n){const[e,u]=o.useState(!1),[i,s]=l(u),c=o.useCallback(()=>{s(),n&&setTimeout(n)},[s,n]);return{isDialogOpen:e,openDialog:i,closeDialog:c}}function T(n){const e=[];for(const u in n){const i=n[u];(Array.isArray(i)?i.some(s=>s!==null):i!==null)&&e.push(u)}return e}function j(n,e,u){const[i,s]=o.useState(n);(u?!u(n,i):n!==i)&&(s(n),e(n))}function N(n,e){return Object.fromEntries(Object.entries(n).map(([u,i])=>[`${e}${u}`,i]))}function d(n,e){r(n!==void 0,e)}function y(n,e){r(n!=null,e)}function m(n,e){r(n!==null,e)}function k(n,e={}){if(typeof n=="string"){const{name:u}=e,i=document.createElement("a");i.href=n,i.target="_blank",u&&(i.download=u),i.click()}else{const u=URL.createObjectURL(n);k(u,e),URL.revokeObjectURL(u)}}function h(n,e){return d(n,e),n}function b(n,e){return y(n,e),n}function E(n,e){return m(n,e),n}function p(n,e){return n.length===0?"":e(n[0])+n.slice(1)}function D(n){return p(n,e=>e.toLowerCase())}function S(n){return p(n,e=>e.toUpperCase())}function a(n,e){if(n!=null){if(Array.isArray(n))return n.map(u=>a(u,e));if(typeof n=="object"){const u=e==="capitalize"?S:D;return Object.entries(n).reduce((i,[s,c])=>({...i,[u(s)]:a(c,e)}),{})}return n}}function I(n){return a(n,"uncapitalize")}function w(n){return a(n,"capitalize")}function z(){const n=o.createContext([void 0,()=>{}]);function e(){return o.useContext(n)}return e.Provider=function({children:i,initialValue:s}){const c=o.useState(s);return g.jsx(n.Provider,{value:c,children:i})},e.set=function(i){const[,s]=e();o.useEffect(()=>{s(i)},[s,i]),o.useEffect(()=>()=>s(void 0),[s])},e}t.addPrefix=N,t.assertDefined=d,t.assertNotEmpty=y,t.assertNotNull=m,t.capitalizeDeep=w,t.downloadFile=k,t.ensureDefined=h,t.ensureNotEmpty=b,t.ensureNotNull=E,t.mkValueContext=z,t.toLowerFirst=D,t.toUpperFirst=S,t.uncapitalizeDeep=I,t.useBoundRunInTask=C,t.useDialog=R,t.useKeyByRoute=T,t.useRunInTask=f,t.useSetUnset=l,t.useSyncState=j,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leancodepl/utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"node": ">=22.0.0"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leancodepl/api-date": "
|
|
25
|
+
"@leancodepl/api-date": "10.0.0",
|
|
26
26
|
"tiny-invariant": ">=1.3.1"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|