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

Remove string.toBool function #5493

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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