barbero 0.1.0-alpha.1

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 BhuannaichFhirinn
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/README.md ADDED
@@ -0,0 +1,175 @@
1
+ # Barbero
2
+
3
+ **Barbero** is a lightweight JavaScript utility library providing tools for Boolean evaluations, comparisons, and logical utilities. Simplify your true/false logic with this modern, easy-to-use toolkit.
4
+
5
+ ---
6
+
7
+ ## Features
8
+
9
+ - **Lightweight**: Small and efficient, designed to integrate seamlessly with your projects.
10
+ - **Boolean Utilities**: Perform truthy/falsey checks, comparisons, and validations.
11
+ - **Easy to Use**: Clear and intuitive functions for common tasks.
12
+ - **Tree-shakable**: Import only what you need to minimize bundle size.
13
+
14
+ ---
15
+
16
+ ## Installation
17
+
18
+ Install Barbero via NPM:
19
+
20
+ ```bash
21
+ npm install barbero
22
+ ```
23
+
24
+ Or using Yarn:
25
+
26
+ ```bash
27
+ yarn add barbero
28
+ ```
29
+
30
+ ---
31
+
32
+ ## Usage
33
+
34
+ Import and use individual functions or the entire library:
35
+
36
+ ### Example 1: Truthy/Falsey Checks
37
+
38
+ ```javascript
39
+ import { isTruthy, isFalsey } from 'barbero';
40
+
41
+ console.log(isTruthy(1)); // true
42
+ console.log(isFalsey(0)); // true
43
+ ```
44
+
45
+ ### Example 2: Null/Undefined/Empty Checks
46
+
47
+ ```javascript
48
+ import { isNullOrUndefined, isEmptyArray } from 'barbero';
49
+
50
+ console.log(isNullOrUndefined(null)); // true
51
+ console.log(isEmptyArray([])); // true
52
+ console.log(isEmptyArray([1, 2])); // false
53
+ ```
54
+
55
+ ### Example 3: Comparisons
56
+
57
+ ```javascript
58
+ import { isEqual, isStrictEqual } from 'barbero';
59
+
60
+ console.log(isEqual({ a: 1 }, { a: 1 })); // true
61
+ console.log(isStrictEqual(1, '1')); // false
62
+ ```
63
+
64
+ ### Example 4: Logical Operations
65
+
66
+ ```javascript
67
+ import { xor, nand } from 'barbero';
68
+
69
+ console.log(xor(true, false)); // true
70
+ console.log(nand(true, true)); // false
71
+ ```
72
+
73
+ ---
74
+
75
+ ## API
76
+
77
+ ### Core Functions
78
+
79
+ #### `isTruthy(value)`
80
+ Returns `true` if the value is truthy.
81
+
82
+ ```javascript
83
+ isTruthy(1); // true
84
+ isTruthy(0); // false
85
+ ```
86
+
87
+ #### `isFalsey(value)`
88
+ Returns `true` if the value is falsey.
89
+
90
+ ```javascript
91
+ isFalsey(0); // true
92
+ isFalsey('hello'); // false
93
+ ```
94
+
95
+ ### Validation Functions
96
+
97
+ #### `isNullOrUndefined(value)`
98
+ Returns `true` if the value is `null` or `undefined`.
99
+
100
+ ```javascript
101
+ isNullOrUndefined(null); // true
102
+ isNullOrUndefined(undefined); // true
103
+ isNullOrUndefined(''); // false
104
+ ```
105
+
106
+ #### `isEmptyArray(array)`
107
+ Returns `true` if the array is empty.
108
+
109
+ ```javascript
110
+ isEmptyArray([]); // true
111
+ isEmptyArray([1]); // false
112
+ ```
113
+
114
+ #### `isEmptyObject(object)`
115
+ Returns `true` if the object has no keys.
116
+
117
+ ```javascript
118
+ isEmptyObject({}); // true
119
+ isEmptyObject({ a: 1 }); // false
120
+ ```
121
+
122
+ ### Comparison Functions
123
+
124
+ #### `isEqual(a, b)`
125
+ Performs deep equality comparison between two values.
126
+
127
+ ```javascript
128
+ isEqual({ a: 1 }, { a: 1 }); // true
129
+ isEqual([1, 2], [1, 2]); // true
130
+ isEqual(1, '1'); // false
131
+ ```
132
+
133
+ #### `isStrictEqual(a, b)`
134
+ Performs strict equality comparison (no type coercion).
135
+
136
+ ```javascript
137
+ isStrictEqual(1, 1); // true
138
+ isStrictEqual(1, '1'); // false
139
+ ```
140
+
141
+ ### Logical Functions
142
+
143
+ #### `xor(a, b)`
144
+ Returns `true` if only one of the arguments is `true`.
145
+
146
+ ```javascript
147
+ xor(true, false); // true
148
+ xor(true, true); // false
149
+ ```
150
+
151
+ #### `nand(a, b)`
152
+ Returns `true` if **not both** arguments are `true`.
153
+
154
+ ```javascript
155
+ nand(true, true); // false
156
+ nand(true, false); // true
157
+ ```
158
+
159
+ ---
160
+
161
+ ## Contributing
162
+
163
+ Contributions are welcome! Please open an issue or submit a pull request on [GitHub](https://github.com/your-username/barbero).
164
+
165
+ ---
166
+
167
+ ## License
168
+
169
+ Barbero is licensed under the [MIT License](LICENSE).
170
+
171
+ ---
172
+
173
+ ## Acknowledgements
174
+
175
+ Inspired by the need for clear and simple Boolean utilities in JavaScript.
package/dist/index.cjs ADDED
@@ -0,0 +1,31 @@
1
+ // Import utilities
2
+ import { isTruthy, isFalsey } from './core/truthy.js';
3
+ import { isNullOrUndefined, isEmptyArray, isEmptyObject } from './utils/validation.js';
4
+ import { isEqual, isStrictEqual } from './core/compare.js';
5
+ import { xor, nand } from './utils/logic.js';
6
+
7
+ // Export utilities
8
+ export {
9
+ isTruthy,
10
+ isFalsey,
11
+ isNullOrUndefined,
12
+ isEmptyArray,
13
+ isEmptyObject,
14
+ isEqual,
15
+ isStrictEqual,
16
+ xor,
17
+ nand,
18
+ };
19
+
20
+ // Default export (optional for consumers who prefer this style)
21
+ export default {
22
+ isTruthy,
23
+ isFalsey,
24
+ isNullOrUndefined,
25
+ isEmptyArray,
26
+ isEmptyObject,
27
+ isEqual,
28
+ isStrictEqual,
29
+ xor,
30
+ nand,
31
+ };
package/dist/index.mjs ADDED
@@ -0,0 +1,31 @@
1
+ // Import utilities
2
+ import { isTruthy, isFalsey } from './core/truthy.js';
3
+ import { isNullOrUndefined, isEmptyArray, isEmptyObject } from './utils/validation.js';
4
+ import { isEqual, isStrictEqual } from './core/compare.js';
5
+ import { xor, nand } from './utils/logic.js';
6
+
7
+ // Export utilities
8
+ export {
9
+ isTruthy,
10
+ isFalsey,
11
+ isNullOrUndefined,
12
+ isEmptyArray,
13
+ isEmptyObject,
14
+ isEqual,
15
+ isStrictEqual,
16
+ xor,
17
+ nand,
18
+ };
19
+
20
+ // Default export (optional for consumers who prefer this style)
21
+ export default {
22
+ isTruthy,
23
+ isFalsey,
24
+ isNullOrUndefined,
25
+ isEmptyArray,
26
+ isEmptyObject,
27
+ isEqual,
28
+ isStrictEqual,
29
+ xor,
30
+ nand,
31
+ };
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "barbero",
3
+ "version": "0.1.0-alpha.1",
4
+ "description": "A lightweight utility library for Boolean logic.",
5
+ "main": "dist/index.cjs",
6
+ "module": "dist/index.mjs",
7
+ "type": "module",
8
+ "scripts": {
9
+ "build": "npm run build:cjs && npm run build:mjs",
10
+ "build:cjs": "cp src/index.js dist/index.cjs",
11
+ "build:mjs": "cp src/index.js dist/index.mjs",
12
+ "test": "echo 'No tests yet'"
13
+ },
14
+ "keywords": [
15
+ "boolean",
16
+ "utility",
17
+ "truthy",
18
+ "falsey",
19
+ "logic",
20
+ "barbero",
21
+ "javascript"
22
+ ],
23
+ "author": "Bhuannaich Fhirinn <BhuannaichFhirinn@gmail.com> (https://github.com/BhuannaichFhirinn)",
24
+ "license": "MIT",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/BhuannaichFhirinn/barbero.git"
28
+ },
29
+ "bugs": {
30
+ "url": "https://github.com/BhuannaichFhirinn/barbero/issues"
31
+ },
32
+ "homepage": "https://github.com/BhuannaichFhirinn/barbero#readme"
33
+ }
@@ -0,0 +1,27 @@
1
+ // Perform a deep equality check between two values
2
+ export const isEqual = (a, b) => {
3
+ if (a === b) return true;
4
+
5
+ if (typeof a !== typeof b) return false;
6
+
7
+ if (typeof a === 'object' && a !== null && b !== null) {
8
+ const keysA = Object.keys(a);
9
+ const keysB = Object.keys(b);
10
+
11
+ if (keysA.length !== keysB.length) return false;
12
+
13
+ for (const key of keysA) {
14
+ if (!keysB.includes(key) || !isEqual(a[key], b[key])) {
15
+ return false;
16
+ }
17
+ }
18
+
19
+ return true;
20
+ }
21
+
22
+ return false;
23
+ };
24
+
25
+ // Perform a strict equality check between two values
26
+ export const isStrictEqual = (a, b) => Object.is(a, b);
27
+
@@ -0,0 +1,5 @@
1
+ // Check if a value is truthy
2
+ export const isTruthy = (value) => !!value;
3
+
4
+ // Check if a value is falsey
5
+ export const isFalsey = (value) => !value;
package/src/index.js ADDED
@@ -0,0 +1,31 @@
1
+ // Import utilities
2
+ import { isTruthy, isFalsey } from './core/truthy.js';
3
+ import { isNullOrUndefined, isEmptyArray, isEmptyObject } from './utils/validation.js';
4
+ import { isEqual, isStrictEqual } from './core/compare.js';
5
+ import { xor, nand } from './utils/logic.js';
6
+
7
+ // Export utilities
8
+ export {
9
+ isTruthy,
10
+ isFalsey,
11
+ isNullOrUndefined,
12
+ isEmptyArray,
13
+ isEmptyObject,
14
+ isEqual,
15
+ isStrictEqual,
16
+ xor,
17
+ nand,
18
+ };
19
+
20
+ // Default export (optional for consumers who prefer this style)
21
+ export default {
22
+ isTruthy,
23
+ isFalsey,
24
+ isNullOrUndefined,
25
+ isEmptyArray,
26
+ isEmptyObject,
27
+ isEqual,
28
+ isStrictEqual,
29
+ xor,
30
+ nand,
31
+ };
@@ -0,0 +1,5 @@
1
+ // Perform an XOR (exclusive OR) operation between two values
2
+ export const xor = (a, b) => !!a !== !!b;
3
+
4
+ // Perform a NAND (NOT AND) operation between two values
5
+ export const nand = (a, b) => !(a && b);
@@ -0,0 +1,9 @@
1
+ // Check if a value is null or undefined
2
+ export const isNullOrUndefined = (value) => value === null || value === undefined;
3
+
4
+ // Check if an array is empty
5
+ export const isEmptyArray = (array) => Array.isArray(array) && array.length === 0;
6
+
7
+ // Check if an object is empty
8
+ export const isEmptyObject = (object) =>
9
+ object && typeof object === 'object' && Object.keys(object).length === 0;