boolean.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. "use strict";
  2. /*
  3. This file is part of web3.js.
  4. web3.js is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. web3.js is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License
  13. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. Object.defineProperty(exports, "__esModule", { value: true });
  16. exports.isBoolean = void 0;
  17. const string_js_1 = require("./string.js");
  18. const isBoolean = (value) => {
  19. if (!['number', 'string', 'boolean'].includes(typeof value)) {
  20. return false;
  21. }
  22. if (typeof value === 'boolean') {
  23. return true;
  24. }
  25. if (typeof value === 'string' && !(0, string_js_1.isHexStrict)(value)) {
  26. return value === '1' || value === '0';
  27. }
  28. if (typeof value === 'string' && (0, string_js_1.isHexStrict)(value)) {
  29. return value === '0x1' || value === '0x0';
  30. }
  31. if (typeof value === 'number') {
  32. return value === 1 || value === 0;
  33. }
  34. return false;
  35. };
  36. exports.isBoolean = isBoolean;
  37. //# sourceMappingURL=boolean.js.map