Skip to content

Commit

Permalink
Remove string.toBool function (#5493)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
  • Loading branch information
mvaligursky and Martin Valigursky committed Jul 21, 2023
1 parent 54837e4 commit ad2182e
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 45 deletions.
26 changes: 0 additions & 26 deletions src/core/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,32 +140,6 @@ const string = {
return s;
},

/**
* Convert a string value to a boolean. In non-strict mode (the default), 'true' is converted
* to true, all other values are converted to false. In strict mode, 'true' is converted to
* true, 'false' is converted to false, all other values will throw an Exception.
*
* @param {string} s - The string to convert.
* @param {boolean} [strict] - In strict mode an Exception is thrown if s is not an accepted
* string value. Defaults to false.
* @returns {boolean} The converted value.
*/
toBool: function (s, strict = false) {
if (s === 'true') {
return true;
}

if (strict) {
if (s === 'false') {
return false;
}

throw new TypeError('Not a boolean string');
}

return false;
},

/**
* Get the code point number for a character in a string. Polyfill for
* [`codePointAt`]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt}.
Expand Down
19 changes: 0 additions & 19 deletions test/core/string.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,6 @@ describe('string', function () {

});

describe('#toBool', function () {

it('handles strict conversion', function () {
expect(string.toBool('true', true)).to.be.true;
expect(string.toBool('false', true)).to.be.false;
expect(function () {
string.toBool('abc', true);
}).to.throw;
});

it('handles non-strict conversion', function () {
expect(string.toBool('true')).to.be.true;
expect(string.toBool('false')).to.be.false;
expect(string.toBool('abc')).to.be.false;
expect(string.toBool(undefined)).to.be.false;
});

});

describe('#getSymbols', function () {

it('returns an array of the expected length', function () {
Expand Down

0 comments on commit ad2182e

Please sign in to comment.