@eturino/ts-parse-boolean
v1.1.3
Published
Converts to a boolean. Returns false if the value is falsy. If it is truthy it checks it by converting to a string, trimming, upcasing, and checking if the value is not `FALSE` or `NO` or `0`.
Downloads
6,466
Readme
@eturino/ts-parse-boolean
TypeDoc generated docs in here
Converts to a boolean. Returns false if the value is falsy. If it is truthy it checks it by converting to a string, trimming, upcasing, and checking if the value is not FALSE
or NO
or 0
.
If we pass a value that is not a boolean
, string
, number
, null
or undefined
, it will return false
.
Installation
yarn add @eturino/ts-parse-boolean
or npm install @eturino/ts-parse-boolean
.
Usage
import parseBoolean from "@eturino/ts-parse-boolean";
parseBoolean(true); // => true
parseBoolean(false); // => false
parseBoolean(1); // => true
parseBoolean(0); // => false
parseBoolean(-8); // => true
parseBoolean(" 0 "); // => false
parseBoolean(" tRue "); // => true
parseBoolean(" No "); // => false
parseBoolean(" faLse "); // => false
parseBoolean(" Whatever "); // => true
// complex values are not parsed and we return false by default
parseBoolean(["a"]); // => false
parseBoolean({ a: 1 }); // => false
Development, Commits, versioning and publishing
See The Typescript-Starter docs.
Commits and CHANGELOG
For commits, you should use commitizen
yarn global add commitizen
#commit your changes:
git cz
As typescript-starter docs state:
This project is tooled for conventional changelog to make managing releases easier. See the standard-version documentation for more information on the workflow, or CHANGELOG.md
for an example.
# bump package.json version, update CHANGELOG.md, git tag the release
yarn run version
You may find a tool like wip
helpful for managing work in progress before you're ready to create a meaningful commit.
Creating the first version
Once you are ready to create the first version, run the following (note that reset
is destructive and will remove all files not in the git repo from the directory).
# Reset the repo to the latest commit and build everything
yarn run reset && yarn run test && yarn run doc:html
# Then version it with standard-version options. e.g.:
# don't bump package.json version
yarn run version -- --first-release
# Other popular options include:
# PGP sign it:
# $ yarn run version -- --sign
# alpha release:
# $ yarn run version -- --prerelease alpha
And after that, remember to publish the docs.
And finally push the new tags to github and publish the package to npm.
# Push to git
git push --follow-tags origin master
# Publish to NPM (allowing public access, required if the package name is namespaced like `@somewhere/some-lib`)
yarn publish --access public
Publish the Docs
yarn run doc:html && yarn run doc:publish
This will generate the docs and publish them in github pages.
Generate a version
There is a single yarn command for preparing a new release. See One-step publish preparation script in TypeScript-Starter
# Prepare a standard release
yarn prepare-release
# Push to git
git push --follow-tags origin master
# Publish to NPM (allowing public access, required if the package name is namespaced like `@somewhere/some-lib`)
yarn publish --access public