Skip to content

Commit

Permalink
feat: add string.prototype.bold
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Champion authored and JakeChampion committed Jul 31, 2019
1 parent 7912033 commit fe231bb
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 8 deletions.
21 changes: 13 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -900,21 +900,26 @@ jobs:
command: node ./test/polyfills/test-individual-feature.js
String.prototype.blink
- run:
name: Testing String.prototype.codePointAt
name: Testing String.prototype.bold
no_output_timeout: 180m
command: node ./test/polyfills/test-individual-feature.js
String.prototype.codePointAt
String.prototype.bold
- run:
name: Testing String.prototype.endsWith
name: Testing String.prototype.codePointAt
no_output_timeout: 180m
command: node ./test/polyfills/test-individual-feature.js
String.prototype.endsWith
String.prototype.codePointAt
test_13:
docker:
- image: circleci/node:10
steps:
- checkout
- run: npm ci
- run:
name: Testing String.prototype.endsWith
no_output_timeout: 180m
command: node ./test/polyfills/test-individual-feature.js
String.prototype.endsWith
- run:
name: Testing String.prototype.fixed
no_output_timeout: 180m
Expand Down Expand Up @@ -980,16 +985,16 @@ jobs:
no_output_timeout: 180m
command: node ./test/polyfills/test-individual-feature.js
String.prototype.strike
- run:
name: Testing String.prototype.sub
no_output_timeout: 180m
command: node ./test/polyfills/test-individual-feature.js String.prototype.sub
test_14:
docker:
- image: circleci/node:10
steps:
- checkout
- run: npm ci
- run:
name: Testing String.prototype.sub
no_output_timeout: 180m
command: node ./test/polyfills/test-individual-feature.js String.prototype.sub
- run:
name: Testing String.prototype.sup
no_output_timeout: 180m
Expand Down
26 changes: 26 additions & 0 deletions polyfills/String/prototype/bold/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
dependencies = [
"_ESAbstract.CreateHTML",
"_ESAbstract.CreateMethodProperty",
]
spec = "https://www.ecma-international.org/ecma-262/6.0/#sec-string.prototype.bold"
docs = "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/bold"

# Browsers which have always supported the feature are commented out.
[browsers]
# android = "*"
bb = "*"
# chrome = "*"
# edge = "*"
# edge_mob = "*"
firefox = "< 4"
# ios_chr = "*"
# ios_saf = "*"
ie = "*"
ie_mob = "*"
# opera = "*"
op_mini = "*"
# op_mob = "*"
# safari = "*"
firefox_mob = "< 4"
# samsung_mob = "*"

4 changes: 4 additions & 0 deletions polyfills/String/prototype/bold/detect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'bold' in String.prototype && (function() {
var test = ''.bold('"');
return test == test.toLowerCase() && test.split('"').length <= 3;
}())
9 changes: 9 additions & 0 deletions polyfills/String/prototype/bold/polyfill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* globals CreateHTML, CreateMethodProperty */
// B.2.3.5String.prototype.bold ( )
// When the bold method is called with no arguments, the following steps are taken:
CreateMethodProperty(String.prototype, 'bold', function bold() {
// 1. Let S be the this value.
var S = this;
// 2. Return ? CreateHTML(S, "b", "", "").
return CreateHTML(S, "b", "", "");
});
42 changes: 42 additions & 0 deletions polyfills/String/prototype/bold/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* eslint-env mocha */
/* globals proclaim */

var hasStrictMode = (function () {
return this === null;
}).call(null);

var ifHasStrictModeIt = hasStrictMode ? it : it.skip;

it('is a function', function () {
proclaim.isFunction(String.prototype.bold);
});

it('has correct arity', function () {
proclaim.arity(String.prototype.bold, 0);
});

it('has correct name', function () {
proclaim.hasName(String.prototype.bold, 'bold');
});

it('is not enumerable', function () {
proclaim.isNotEnumerable(String.prototype, 'bold');
});

ifHasStrictModeIt('should throw a TypeError when called with undefined context', function () {
proclaim.throws(function () {
String.prototype.bold.call(undefined);
}, TypeError);
});

ifHasStrictModeIt('should throw a TypeError when called with null context', function () {
proclaim.throws(function () {
String.prototype.bold.call(null);
}, TypeError);
});

it('works on strings correctly', function() {
proclaim.deepEqual('_'.bold(), '<b>_</b>');
proclaim.deepEqual('<'.bold(), '<b><</b>');
proclaim.deepEqual(String.prototype.bold.call(1234), '<b>1234</b>');
});

0 comments on commit fe231bb

Please sign in to comment.