Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add parseBoolean utils #18

Merged
merged 4 commits into from
Jan 31, 2023
Merged

feat: add parseBoolean utils #18

merged 4 commits into from
Jan 31, 2023

Conversation

scmmishra
Copy link
Member

@scmmishra scmmishra commented Jan 29, 2023

This PR adds a new function, parseBoolean, to the library. This function takes a single argument, candidate, which can be either a string or a number, and attempts to parse it as a boolean value. If the parsing is successful, the parsed boolean value is returned. If the parsing fails (e.g. the input is not a valid boolean string), the function returns false.

Usage

const result = parseBoolean('true'); // true
const result = parseBoolean(1); // true
const result = parseBoolean('not a boolean'); // false

This function can be used when you want to parse a string or number which is expected to be boolean in nature and need to ensure it returns boolean only.

@github-actions
Copy link

github-actions bot commented Jan 29, 2023

size-limit report 📦

Path Size
dist/utils.cjs.production.min.js 1.59 KB (+3.1% 🔺)
dist/utils.esm.js 1.06 KB (+5.34% 🔺)

@scmmishra scmmishra merged commit 196c837 into main Jan 31, 2023
@muhsin-k muhsin-k deleted the feat/parseboolean-utils branch December 9, 2023 04:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants