react-ternary-be-gone 0.1.4 → 0.1.5
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/LICENSE +21 -0
- package/dist/Conditional.js +19 -39
- package/package.json +10 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-2026 Ibrahim Sanduvaç
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/Conditional.js
CHANGED
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _markers = require("./markers");
|
|
9
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
9
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
11
10
|
// Pure helper: apply filter/sort/reverse/limit to an `each` array without
|
|
12
11
|
// mutating the caller's array (Array.prototype.sort/reverse mutate in place,
|
|
@@ -29,9 +28,9 @@ const processArray = (array, {
|
|
|
29
28
|
// Pure helper: render one React.Fragment per item, guarding the render-prop
|
|
30
29
|
// call so static children (a plain element instead of a function) don't
|
|
31
30
|
// crash when they reach an iteration path.
|
|
32
|
-
const renderIterableChildren = (items, children, keyExtractor) => items.map((item, index) => /*#__PURE__*/
|
|
33
|
-
|
|
34
|
-
},
|
|
31
|
+
const renderIterableChildren = (items, children, keyExtractor) => items.map((item, index) => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, {
|
|
32
|
+
key: keyExtractor ? keyExtractor(item, index) : index
|
|
33
|
+
}, typeof children === 'function' ? children(item, index, items) : children));
|
|
35
34
|
|
|
36
35
|
// `React.Children.toArray` flattens arrays produced by `.map()`, but an
|
|
37
36
|
// author-written `<>...</>` around a set of branches is itself a single
|
|
@@ -201,10 +200,9 @@ const Conditional = props => {
|
|
|
201
200
|
|
|
202
201
|
// Loading state
|
|
203
202
|
if (loading) {
|
|
204
|
-
return loadingFallback || fallback || /*#__PURE__*/
|
|
205
|
-
className: "conditional-loading"
|
|
206
|
-
|
|
207
|
-
});
|
|
203
|
+
return loadingFallback || fallback || /*#__PURE__*/_react.default.createElement("div", {
|
|
204
|
+
className: "conditional-loading"
|
|
205
|
+
}, "Loading...");
|
|
208
206
|
}
|
|
209
207
|
|
|
210
208
|
// Error state
|
|
@@ -212,10 +210,9 @@ const Conditional = props => {
|
|
|
212
210
|
if (errorFallback) {
|
|
213
211
|
return typeof errorFallback === 'function' ? errorFallback(error) : errorFallback;
|
|
214
212
|
}
|
|
215
|
-
return /*#__PURE__*/
|
|
216
|
-
className: "conditional-error"
|
|
217
|
-
|
|
218
|
-
});
|
|
213
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
214
|
+
className: "conditional-error"
|
|
215
|
+
}, "Error: ", error);
|
|
219
216
|
}
|
|
220
217
|
|
|
221
218
|
// Switch-case logic. Presence, not strict inequality to `undefined`, is
|
|
@@ -229,14 +226,10 @@ const Conditional = props => {
|
|
|
229
226
|
const matchedCase = caseChildren.find(child => !child.props.default && child.props.when === switchValue);
|
|
230
227
|
const defaultCase = caseChildren.find(child => child.props.default);
|
|
231
228
|
if (matchedCase) {
|
|
232
|
-
return /*#__PURE__*/(
|
|
233
|
-
children: matchedCase.props.children
|
|
234
|
-
});
|
|
229
|
+
return /*#__PURE__*/_react.default.createElement(Wrapper, null, matchedCase.props.children);
|
|
235
230
|
}
|
|
236
231
|
if (defaultCase) {
|
|
237
|
-
return /*#__PURE__*/(
|
|
238
|
-
children: defaultCase.props.children
|
|
239
|
-
});
|
|
232
|
+
return /*#__PURE__*/_react.default.createElement(Wrapper, null, defaultCase.props.children);
|
|
240
233
|
}
|
|
241
234
|
return fallback;
|
|
242
235
|
}
|
|
@@ -269,13 +262,9 @@ const Conditional = props => {
|
|
|
269
262
|
reverse: branchReverse,
|
|
270
263
|
limit: branchLimit
|
|
271
264
|
});
|
|
272
|
-
rendered = items.length === 0 ? branchEmpty || branchFallback || null : /*#__PURE__*/(
|
|
273
|
-
children: renderIterableChildren(items, branchChildren, branchKeyExtractor)
|
|
274
|
-
});
|
|
265
|
+
rendered = items.length === 0 ? branchEmpty || branchFallback || null : /*#__PURE__*/_react.default.createElement(BranchWrapper, null, renderIterableChildren(items, branchChildren, branchKeyExtractor));
|
|
275
266
|
} else {
|
|
276
|
-
rendered = /*#__PURE__*/
|
|
277
|
-
children: branchChildren
|
|
278
|
-
});
|
|
267
|
+
rendered = /*#__PURE__*/_react.default.createElement(BranchWrapper, null, branchChildren);
|
|
279
268
|
}
|
|
280
269
|
break;
|
|
281
270
|
}
|
|
@@ -284,9 +273,7 @@ const Conditional = props => {
|
|
|
284
273
|
|
|
285
274
|
// Only condition
|
|
286
275
|
if (hasCondition && !hasIteration) {
|
|
287
|
-
return evaluateCondition ? /*#__PURE__*/
|
|
288
|
-
children: children
|
|
289
|
-
}) : fallback;
|
|
276
|
+
return evaluateCondition ? /*#__PURE__*/_react.default.createElement(Wrapper, null, children) : fallback;
|
|
290
277
|
}
|
|
291
278
|
|
|
292
279
|
// Only iteration
|
|
@@ -299,12 +286,9 @@ const Conditional = props => {
|
|
|
299
286
|
// wrapper is swapped for a real host element whenever `animate` needs
|
|
300
287
|
// somewhere to put the class.
|
|
301
288
|
const AnimatedWrapper = animate && Wrapper === _react.default.Fragment ? 'div' : Wrapper;
|
|
302
|
-
return /*#__PURE__*/
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
} : null),
|
|
306
|
-
children: elements
|
|
307
|
-
});
|
|
289
|
+
return /*#__PURE__*/_react.default.createElement(AnimatedWrapper, animate ? {
|
|
290
|
+
className: 'conditional-animated'
|
|
291
|
+
} : null, elements);
|
|
308
292
|
}
|
|
309
293
|
|
|
310
294
|
// Both condition and iteration
|
|
@@ -312,12 +296,8 @@ const Conditional = props => {
|
|
|
312
296
|
if (!evaluateCondition) return fallback;
|
|
313
297
|
if (processedArray.length === 0) return empty || fallback;
|
|
314
298
|
const elements = renderIterableChildren(processedArray, children, keyExtractor);
|
|
315
|
-
return /*#__PURE__*/
|
|
316
|
-
children: elements
|
|
317
|
-
});
|
|
299
|
+
return /*#__PURE__*/_react.default.createElement(Wrapper, null, elements);
|
|
318
300
|
}
|
|
319
|
-
return /*#__PURE__*/
|
|
320
|
-
children: children
|
|
321
|
-
});
|
|
301
|
+
return /*#__PURE__*/_react.default.createElement(Wrapper, null, children);
|
|
322
302
|
};
|
|
323
303
|
var _default = exports.default = Conditional;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-ternary-be-gone",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "A React component designed to simplify conditional rendering and list iteration, providing a more readable and maintainable alternative to ternary operators and verbose conditional logic.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
@@ -21,8 +21,15 @@
|
|
|
21
21
|
},
|
|
22
22
|
"keywords": [
|
|
23
23
|
"react",
|
|
24
|
-
"
|
|
25
|
-
"
|
|
24
|
+
"conditional-rendering",
|
|
25
|
+
"control-flow",
|
|
26
|
+
"jsx",
|
|
27
|
+
"ternary",
|
|
28
|
+
"v-if",
|
|
29
|
+
"ng-if",
|
|
30
|
+
"v-for",
|
|
31
|
+
"switch-case",
|
|
32
|
+
"if-else"
|
|
26
33
|
],
|
|
27
34
|
"author": "Ibrahim Sanduvaç",
|
|
28
35
|
"license": "MIT",
|