Skip to content

Commit

Permalink
Address PR Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alexs-mparticle committed Oct 17, 2023
1 parent 4dcaac7 commit 9a887f7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ const isString = (value: any): boolean => typeof value === 'string';
const isNumber = (value: any): boolean => typeof value === 'number';
const isFunction = (fn: any): boolean => typeof fn === 'function';

const toSlug = (value: any): string =>
const toDataPlanSlug = (value: any): string =>
// Make sure we are only acting on strings or numbers
isStringOrNumber(value)
? value
Expand All @@ -212,7 +212,7 @@ const toSlug = (value: any): string =>
.replace(/[^0-9a-zA-Z]+/g, '_')
: '';

const isDataPlanSlug = (str: string): boolean => str === toSlug(str);
const isDataPlanSlug = (str: string): boolean => str === toDataPlanSlug(str);

const isStringOrNumber = (value: any): boolean =>
isString(value) || isNumber(value);
Expand Down Expand Up @@ -241,7 +241,7 @@ export {
replaceApostrophesWithQuotes,
replaceQuotesWithApostrophes,
returnConvertedBoolean,
toSlug,
toDataPlanSlug,
isString,
isNumber,
isFunction,
Expand Down
30 changes: 15 additions & 15 deletions test/src/tests-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
replaceQuotesWithApostrophes,
returnConvertedBoolean,
revertCookieString,
toSlug,
toDataPlanSlug,
} from '../../src/utils';
import { expect } from 'chai';

Expand Down Expand Up @@ -274,24 +274,24 @@ describe('Utils', () => {
})
});

describe('#isSlug', () => {
describe('#toDataPlanSlug', () => {
it('should convert a string to a slug', () => {
expect(toSlug('string')).to.equal('string');
expect(toSlug('42')).to.equal('42');
expect(toSlug(37)).to.equal('37');
expect(toSlug('string with spaces')).to.equal('string_with_spaces');
expect(toSlug('kabob-case-string')).to.equal('kabob_case_string');
expect(toSlug('PascalSlug')).to.equal('pascalslug');
expect(toSlug('under_score_slug')).to.equal('under_score_slug');
expect(toDataPlanSlug('string')).to.equal('string');
expect(toDataPlanSlug('42')).to.equal('42');
expect(toDataPlanSlug(37)).to.equal('37');
expect(toDataPlanSlug('string with spaces')).to.equal('string_with_spaces');
expect(toDataPlanSlug('kabob-case-string')).to.equal('kabob_case_string');
expect(toDataPlanSlug('PascalSlug')).to.equal('pascalslug');
expect(toDataPlanSlug('under_score_slug')).to.equal('under_score_slug');
});

it('should convert non-strings to an empty string', () => {
expect(toSlug(true)).to.equal('');
expect(toSlug([])).to.equal('');
expect(toSlug({})).to.equal('');
expect(toSlug(null)).to.equal('');
expect(toSlug(undefined)).to.equal('');
expect(toSlug(()=>{})).to.equal('');
expect(toDataPlanSlug(true)).to.equal('');
expect(toDataPlanSlug([])).to.equal('');
expect(toDataPlanSlug({})).to.equal('');
expect(toDataPlanSlug(null)).to.equal('');
expect(toDataPlanSlug(undefined)).to.equal('');
expect(toDataPlanSlug(()=>{})).to.equal('');
});
});

Expand Down

0 comments on commit 9a887f7

Please sign in to comment.