Removal of hasPrefix function in badge-data.js (#1376)

* Removed hasPrefix method and added tests to cover prependPrefix
This commit is contained in:
Pyves
2017-12-18 05:58:28 +01:00
committed by Danial
parent 432024db30
commit 32671dfd87
2 changed files with 7 additions and 13 deletions

View File

@@ -17,14 +17,10 @@ function isDataUri(s) {
return s !== undefined && /^(data:)([^;]+);([^,]+),(.+)$/.test(s);
}
function hasPrefix(s, prefix) {
return s !== undefined && s.slice(0, prefix.length) === prefix;
}
function prependPrefix(s, prefix) {
if (s === undefined) {
return undefined;
} else if (hasPrefix(s, prefix)) {
} else if (s.startsWith(prefix)) {
return s;
} else {
return prefix + s;
@@ -102,7 +98,7 @@ function makeBadgeData(defaultLabel, overrides) {
}
module.exports = {
hasPrefix,
prependPrefix,
isDataUri,
isValidStyle,
isSixHex,

View File

@@ -4,7 +4,7 @@ const assert = require('assert');
const { test, given, forCases } = require('sazerac');
const {
isDataUri,
hasPrefix,
prependPrefix,
isSixHex,
makeLabel,
makeLogo,
@@ -13,12 +13,10 @@ const {
} = require('./badge-data');
describe('Badge data helpers', function() {
test(hasPrefix, () => {
forCases([
given('data:image/svg+xml;base64,PHN2ZyB4bWxu', 'data:'),
given('data:foobar', 'data:'),
]).expect(true);
given('foobar', 'data:').expect(false);
test(prependPrefix, () => {
given('data:image/svg+xml;base64,PHN2ZyB4bWxu', 'data:').expect('data:image/svg+xml;base64,PHN2ZyB4bWxu');
given('foobar', 'data:').expect('data:foobar');
given(undefined, 'data:').expect(undefined);
});
test(isDataUri, () => {