Removal of hasPrefix function in badge-data.js (#1376)
* Removed hasPrefix method and added tests to cover prependPrefix
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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, () => {
|
||||
|
||||
Reference in New Issue
Block a user