Learn more  » Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

skava / exotic   js

Repository URL to install this package:

Version: 2.0.8 

/ src / types / primitive / boolean / cast / ecmaToBoolean.ts

/**
 * @name toBoolean
 * @alias toBool
 *
 * @since 5.0.0-beta.6
 * @memberOf cast
 *
 * @param  {*} x anything
 * @return {boolean} !!x
 *
 * {@link https://tc39.github.io/ecma262/#sec-toboolean emca-toboolean}
 * {@link https://github.com/chriso/validator.js/blob/master/src/lib/toBoolean.js validator-toboolean}
 * @see {@link validator-toboolean}
 * @see {@link emca-toboolean}
 *
 * @example
 *
 *    toBoolean(0)     //=> false
 *    toBoolean(1)     //=> true
 *    toBoolean(true)  //=> true
 *    toBoolean(false) //=> false
 *    toBoolean({}     //=> true
 *
 */
const toBoolean = function(x: any): boolean {
  return !!x
}

export default toBoolean