Skip to content

Commit 88d5d4e

Browse files
committed
refactor: rename ensure<X> to assert<X>
1 parent a3ec180 commit 88d5d4e

2 files changed

Lines changed: 15 additions & 14 deletions

File tree

index.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ const rules = {
2020

2121
/**
2222
* Ensure the value is a string.
23+
* @private
2324
* @param s {any} the value to be checked
2425
* @throws {TypeError} if the value is not a string
2526
*/
26-
const ensureString = (s) => {
27+
const assertString = (s) => {
2728
const t = typeof s;
2829
if (t !== 'string') {
2930
throw new TypeError('Value must be a string');
@@ -45,7 +46,7 @@ const isFormat = {
4546
*/
4647

4748
nchar: function(value) {
48-
ensureString(value);
49+
assertString(value);
4950
return rules.NCHAR.test(value);
5051
},
5152

@@ -58,7 +59,7 @@ const isFormat = {
5859
*/
5960

6061
nqchar: function(value) {
61-
ensureString(value);
62+
assertString(value);
6263
return rules.NQCHAR.test(value);
6364
},
6465

@@ -71,7 +72,7 @@ const isFormat = {
7172
*/
7273

7374
nqschar: function(value) {
74-
ensureString(value);
75+
assertString(value);
7576
return rules.NQSCHAR.test(value);
7677
},
7778

@@ -85,7 +86,7 @@ const isFormat = {
8586
*/
8687

8788
uchar: function(value) {
88-
ensureString(value);
89+
assertString(value);
8990
// manually test \u10000-\u10FFFF
9091
if (rules.UNICODECHARNOCRLF.test(value)) {
9192
return true;
@@ -102,7 +103,7 @@ const isFormat = {
102103
* @return {boolean} true, if valid, otherwise false
103104
*/
104105
uri: function(value) {
105-
ensureString(value);
106+
assertString(value);
106107
return rules.URI.test(value);
107108
},
108109

@@ -115,7 +116,7 @@ const isFormat = {
115116
*/
116117

117118
vschar: function(value) {
118-
ensureString(value);
119+
assertString(value);
119120
return rules.VSCHAR.test(value);
120121
}
121122
};

test/formats.test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function runRanges (ranges, fn, expected) {
1717
});
1818
}
1919

20-
const ensureValidFormat = (fn) => {
20+
const assertValidFormat = (fn) => {
2121
const invalid = [null, undefined, 123, 0x00, Infinity, {}, [], true, false, () => {}, Symbol('test')];
2222
invalid.forEach(value => {
2323
try {
@@ -35,7 +35,7 @@ describe('Validator', function () {
3535

3636
describe('is', function () {
3737
it('validates if a value matches a unicode character (nchar)', function () {
38-
ensureValidFormat(isFormat.nchar);
38+
assertValidFormat(isFormat.nchar);
3939

4040
const validRanges = [
4141
[45, 46], // \u002D \u002E
@@ -60,7 +60,7 @@ describe('Validator', function () {
6060
});
6161

6262
it('validates if a value matches a unicode character, including exclamation marks (nqchar)', function () {
63-
ensureValidFormat(isFormat.nqchar);
63+
assertValidFormat(isFormat.nqchar);
6464

6565
const validRanges = [
6666
[33, 33], // \u0021
@@ -81,7 +81,7 @@ describe('Validator', function () {
8181
});
8282

8383
it('validates if a value matches a unicode character, including exclamation marks and spaces (nqschar)', function () {
84-
ensureValidFormat(isFormat.nqschar);
84+
assertValidFormat(isFormat.nqschar);
8585

8686
const validRanges = [
8787
[32, 33], // \u0020-\u0021
@@ -102,7 +102,7 @@ describe('Validator', function () {
102102
});
103103

104104
it('validates if a value matches a unicode character excluding the carriage return and linefeed characters (uchar)', function () {
105-
ensureValidFormat(isFormat.uchar);
105+
assertValidFormat(isFormat.uchar);
106106

107107
this.timeout(60000);
108108
const validRanges = [
@@ -127,7 +127,7 @@ describe('Validator', function () {
127127
});
128128

129129
it('validates if a value matches generic URIs (uri)', function () {
130-
ensureValidFormat(isFormat.uri);
130+
assertValidFormat(isFormat.uri);
131131

132132
['aa:', 'http:', 'https:'].forEach(function (uri) {
133133
isFormat.uri(uri).should.equal(true);
@@ -141,7 +141,7 @@ describe('Validator', function () {
141141
});
142142

143143
it('validates if a value matches against the printable set of unicode characters (vschar)', function () {
144-
ensureValidFormat(isFormat.vschar);
144+
assertValidFormat(isFormat.vschar);
145145

146146
const validRanges = [
147147
[32, 126] // \u0020-\u007E

0 commit comments

Comments
 (0)