@reflexions/string-to-boolean 1.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/README.md ADDED
@@ -0,0 +1 @@
1
+ Converts a string to a boolean, treating '0', 'false', 'FALSE', 'off' and falsy values like '' to false, the rest to true.
@@ -0,0 +1,15 @@
1
+ 'use strict'
2
+
3
+ /**
4
+ * Converts a string to a boolean, treating '0', 'false', 'FALSE', 'off' and falsy values like '' to false, the rest to true.
5
+ * @param {string|boolean} value
6
+ */
7
+ const stringToBoolean = (value) => typeof value === 'boolean'
8
+ ? value // param is already boolean
9
+ : typeof value === 'string'
10
+ ? [ '0', 'false', 'off' ].includes(value.toLowerCase())
11
+ ? false
12
+ : Boolean(value) // returns false for ''; true for non-empty string
13
+ : Boolean(value); // returns false for null or undefined, true for objects
14
+
15
+ module.exports = stringToBoolean;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Converts a string to a boolean, treating '0', 'false', 'FALSE', 'off' and falsy values like '' to false, the rest to true.
3
+ * @param {string|boolean} value
4
+ */
5
+ const stringToBoolean = (value) => typeof value === 'boolean'
6
+ ? value // param is already boolean
7
+ : typeof value === 'string'
8
+ ? [ '0', 'false', 'off' ].includes(value.toLowerCase())
9
+ ? false
10
+ : Boolean(value) // returns false for ''; true for non-empty string
11
+ : Boolean(value); // returns false for null or undefined, true for objects
12
+
13
+ export default stringToBoolean;
package/package.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "@reflexions/string-to-boolean",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "exports": {
6
+ ".": {
7
+ "require": "./cjs/StringToBoolean.cjs",
8
+ "default": "./esm/StringToBoolean.mjs"
9
+ }
10
+ },
11
+ "keywords": [],
12
+ "author": "Reflexions Data, LLC",
13
+ "license": "ISC"
14
+ }
package/publish.sh ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env bash
2
+ npm publish --access public