@ukon1990/js-utilities
Advanced tools
Comparing version 1.7.0 to 1.8.0
@@ -12,4 +12,4 @@ import { EmptyUtil } from './empty.util'; | ||
typeof value === 'object' && | ||
value.forEach && | ||
value.push); | ||
value.forEach !== undefined && | ||
value.push !== undefined); | ||
} | ||
@@ -16,0 +16,0 @@ /** |
@@ -5,8 +5,8 @@ import { ArrayUtil } from './array.util'; | ||
it('can detect arrays', () => { | ||
expect(ArrayUtil.isArray([])).toBeTruthy(); | ||
expect(ArrayUtil.isArray(['Bubblegum'])).toBeTruthy(); | ||
expect(ArrayUtil.isArray([])).toBe(true); | ||
expect(ArrayUtil.isArray(['Bubblegum'])).toBe(true); | ||
}); | ||
it('objects are not arrays(kinda)', () => { | ||
expect(ArrayUtil.isArray({ length: 10 })).toBeFalsy(); | ||
expect(ArrayUtil.isArray({})).toBeFalsy(); | ||
expect(ArrayUtil.isArray({ length: 10 })).toBe(false); | ||
expect(ArrayUtil.isArray({})).toBe(false); | ||
}); | ||
@@ -16,6 +16,6 @@ }); | ||
it('Empty array is false', () => { | ||
expect(ArrayUtil.isPopulatedArray([])).toBeFalsy(); | ||
expect(ArrayUtil.isPopulatedArray([])).toBe(false); | ||
}); | ||
it('Non-empty array is true', () => { | ||
expect(ArrayUtil.isPopulatedArray(['a'])).toBeTruthy(); | ||
expect(ArrayUtil.isPopulatedArray(['a'])).toBe(true); | ||
}); | ||
@@ -47,7 +47,7 @@ }); | ||
expect(ArrayUtil.getDifference(['1', 2], ['1', 2]).length).toBeFalsy(); | ||
expect(ArrayUtil.isEqual(['1', 2], ['1', 2])).toBeTruthy(); | ||
expect(ArrayUtil.isEqual(['1', 2], ['1', 2])).toBe(true); | ||
}); | ||
it('Non-identical arrays ar not equal', () => { | ||
expect(ArrayUtil.getDifference(['1', 2, 3], ['1', 2]).length).toBeTruthy(); | ||
expect(ArrayUtil.isEqual(['1', 2, 3], ['1', 2])).toBeFalsy(); | ||
expect(ArrayUtil.isEqual(['1', 2, 3], ['1', 2])).toBe(false); | ||
}); | ||
@@ -71,5 +71,3 @@ }); | ||
const object = { name: 'John', level: -1 }; | ||
const array = [ | ||
'a', 'b', 'a', 'a', 'b' | ||
]; | ||
const array = ['a', 'b', 'a', 'a', 'b']; | ||
ArrayUtil.removeObject('a', array); | ||
@@ -80,5 +78,3 @@ expect(array.length).toBe(2); | ||
const object = { name: 'John', level: -1 }; | ||
const array = [ | ||
0, 1, 0, 0, 1 | ||
]; | ||
const array = [0, 1, 0, 0, 1]; | ||
ArrayUtil.removeObject(1, array); | ||
@@ -89,5 +85,3 @@ expect(array.length).toBe(3); | ||
const object = { name: 'John', level: -1 }; | ||
const array = [ | ||
true, false, true, true, false | ||
]; | ||
const array = [true, false, true, true, false]; | ||
ArrayUtil.removeObject(false, array); | ||
@@ -162,8 +156,4 @@ expect(array.length).toBe(3); | ||
const list = [...Array(10000).keys()]; | ||
expect(ArrayUtil.randomOrder(list) | ||
.filter(n => n === undefined).length) | ||
.toBe(0); | ||
expect(ArrayUtil.randomOrder(list) | ||
.filter(n => n === undefined).length) | ||
.toBe(0); | ||
expect(ArrayUtil.randomOrder(list).filter(n => n === undefined).length).toBe(0); | ||
expect(ArrayUtil.randomOrder(list).filter(n => n === undefined).length).toBe(0); | ||
}); | ||
@@ -170,0 +160,0 @@ }); |
@@ -5,10 +5,10 @@ import { ObjectUtil } from './object.util'; | ||
it('Populated objects returns true', () => { | ||
expect(ObjectUtil.isObject({ name: 'true' })).toBeTruthy(); | ||
expect(ObjectUtil.isObject({ name: 'true' })).toBe(true); | ||
}); | ||
it('Empty objects are objects too', () => { | ||
expect(ObjectUtil.isObject({})).toBeTruthy(); | ||
expect(ObjectUtil.isObject({})).toBe(true); | ||
}); | ||
it('Arrays are not objects', () => { | ||
expect(ObjectUtil.isObject([])).toBeFalsy(); | ||
expect(ObjectUtil.isObject(['Tore', 'Tang', 'en', 'gammal', 'mann'])).toBeFalsy(); | ||
expect(ObjectUtil.isObject([])).toBe(false); | ||
expect(ObjectUtil.isObject(['Tore', 'Tang', 'en', 'gammal', 'mann'])).toBe(false); | ||
}); | ||
@@ -18,6 +18,6 @@ }); | ||
it('Populated objects returns true', () => { | ||
expect(ObjectUtil.isPopulatedObject({ name: 'true' })).toBeTruthy(); | ||
expect(ObjectUtil.isPopulatedObject({ name: 'true' })).toBe(true); | ||
}); | ||
it('Empty objects are false', () => { | ||
expect(ObjectUtil.isPopulatedObject({})).toBeFalsy(); | ||
expect(ObjectUtil.isPopulatedObject({})).toBe(false); | ||
}); | ||
@@ -67,3 +67,3 @@ }); | ||
expect(ObjectUtil.getDifference(obj1, obj2).length).toBeFalsy(); | ||
expect(ObjectUtil.isEqual(obj1, obj2)).toBeTruthy(); | ||
expect(ObjectUtil.isEqual(obj1, obj2)).toBe(true); | ||
}); | ||
@@ -70,0 +70,0 @@ it('Non identical objects are not equal', () => { |
import { Match } from '../models/match.model'; | ||
import { CSVOptions } from '../models/csv-options.model'; | ||
export declare class TextUtil { | ||
static toSlug(text: string): any; | ||
/** | ||
@@ -5,0 +6,0 @@ * Checks if a string is null, undefined or has a length of 0. |
@@ -5,2 +5,8 @@ import { Match } from '../models/match.model'; | ||
export class TextUtil { | ||
static toSlug(text) { | ||
return text | ||
.toLowerCase() | ||
.replace(/[ ]{1,9999}/g, '-') | ||
.replace(/[^a-zA-Z0-9-]{1,9999}/g, ''); | ||
} | ||
/** | ||
@@ -7,0 +13,0 @@ * Checks if a string is null, undefined or has a length of 0. |
@@ -111,3 +111,6 @@ import { TextUtil } from './text.util'; | ||
it('can convert a list of objects with identical keys', () => { | ||
const list = [{ name: 'John', age: 90 }, { name: 'Aga', age: 12 }]; | ||
const list = [ | ||
{ name: 'John', age: 90 }, | ||
{ name: 'Aga', age: 12 } | ||
]; | ||
expect(TextUtil.objectsToCSV(list, ';')).toEqual('Name;Age\n\r' + 'John;90\n\r' + 'Aga;12\n\r'); | ||
@@ -129,3 +132,14 @@ expect(TextUtil.objectsToCSV(list, ';', ['name'])).toEqual('Name\n\r' + 'John\n\r' + 'Aga\n\r'); | ||
}); | ||
describe('toSlug', () => { | ||
it('Turns the text into lowercase', () => { | ||
expect(TextUtil.toSlug('TEST')).toBe('test'); | ||
}); | ||
it('Turns spaces into dashes', () => { | ||
expect(TextUtil.toSlug('here are some Spaces')).toBe('here-are-some-spaces'); | ||
}); | ||
it('Removes special characters', () => { | ||
expect(TextUtil.toSlug(`oh@crap/we!"#$=)(/&%$%&/()!)(/#&%$#$("`)).toBe('ohcrapwe'); | ||
}); | ||
}); | ||
}); | ||
//# sourceMappingURL=text.util.spec.js.map |
{ | ||
"name": "@ukon1990/js-utilities", | ||
"version": "1.7.0", | ||
"version": "1.8.0", | ||
"description": "A light weight package for object and array manipulation. As well as some utilities for matching text.", | ||
@@ -12,3 +12,3 @@ "main": "dist/index.js", | ||
"deploy": "npm run test && tsc && npm publish --access public", | ||
"lint": "tslint ./src/" | ||
"lint": "tslint --project tsconfig.json" | ||
}, | ||
@@ -15,0 +15,0 @@ "keywords": [ |
@@ -1,193 +0,182 @@ | ||
import {ArrayUtil} from './array.util'; | ||
import { ArrayUtil } from './array.util'; | ||
describe('ArrayUtil', () => { | ||
describe('isArray', () => { | ||
it('can detect arrays', () => { | ||
expect(ArrayUtil.isArray([])).toBeTruthy(); | ||
expect(ArrayUtil.isArray(['Bubblegum'])).toBeTruthy(); | ||
}); | ||
describe('isArray', () => { | ||
it('can detect arrays', () => { | ||
expect(ArrayUtil.isArray([])).toBe(true); | ||
expect(ArrayUtil.isArray(['Bubblegum'])).toBe(true); | ||
}); | ||
it('objects are not arrays(kinda)', () => { | ||
expect(ArrayUtil.isArray({length: 10})).toBeFalsy(); | ||
expect(ArrayUtil.isArray({})).toBeFalsy(); | ||
}); | ||
it('objects are not arrays(kinda)', () => { | ||
expect(ArrayUtil.isArray({ length: 10 })).toBe(false); | ||
expect(ArrayUtil.isArray({})).toBe(false); | ||
}); | ||
}); | ||
describe('isPopulatedArray', () => { | ||
it('Empty array is false', () => { | ||
expect(ArrayUtil.isPopulatedArray([])).toBeFalsy(); | ||
}); | ||
describe('isPopulatedArray', () => { | ||
it('Empty array is false', () => { | ||
expect(ArrayUtil.isPopulatedArray([])).toBe(false); | ||
}); | ||
it('Non-empty array is true', () => { | ||
expect(ArrayUtil.isPopulatedArray(['a'])).toBeTruthy(); | ||
}); | ||
it('Non-empty array is true', () => { | ||
expect(ArrayUtil.isPopulatedArray(['a'])).toBe(true); | ||
}); | ||
}); | ||
describe('clone', () => { | ||
it('Can not clone null', () => { | ||
expect(ArrayUtil.clone(null)).toBeNull(); | ||
}); | ||
describe('clone', () => { | ||
it('Can not clone null', () => { | ||
expect(ArrayUtil.clone(null)).toBeNull(); | ||
}); | ||
it('Can clone an array of numbers', () => { | ||
const array = [1, 2, 3, 4, 5]; | ||
expect(ArrayUtil.clone(array)).toEqual(array); | ||
}); | ||
it('Can clone an array of numbers', () => { | ||
const array = [1, 2, 3, 4, 5]; | ||
expect(ArrayUtil.clone(array)).toEqual(array); | ||
}); | ||
it('Can clone an array of strings', () => { | ||
const array = ['1', '2', '3', '4', '5']; | ||
expect(ArrayUtil.clone(array)).toEqual(array); | ||
}); | ||
it('Can clone an array of strings', () => { | ||
const array = ['1', '2', '3', '4', '5']; | ||
expect(ArrayUtil.clone(array)).toEqual(array); | ||
}); | ||
it('Can clone an array of booleans', () => { | ||
const array = [false, false, false, false, false]; | ||
expect(ArrayUtil.clone(array)).toEqual(array); | ||
}); | ||
it('Can clone an array of booleans', () => { | ||
const array = [false, false, false, false, false]; | ||
expect(ArrayUtil.clone(array)).toEqual(array); | ||
}); | ||
it('Can clone an array of objects and arrays', () => { | ||
const array = [{isTrue: true}, {isFalse: false}, ['Non']]; | ||
expect(ArrayUtil.clone(array)).toEqual(array); | ||
}); | ||
it('Can clone an array of objects and arrays', () => { | ||
const array = [{ isTrue: true }, { isFalse: false }, ['Non']]; | ||
expect(ArrayUtil.clone(array)).toEqual(array); | ||
}); | ||
}); | ||
describe('getDifference && isEqual', () => { | ||
it('Identical arrays', () => { | ||
expect(ArrayUtil.getDifference(['1', 2], ['1', 2]).length).toBeFalsy(); | ||
expect(ArrayUtil.isEqual(['1', 2], ['1', 2])).toBeTruthy(); | ||
}); | ||
describe('getDifference && isEqual', () => { | ||
it('Identical arrays', () => { | ||
expect(ArrayUtil.getDifference(['1', 2], ['1', 2]).length).toBeFalsy(); | ||
expect(ArrayUtil.isEqual(['1', 2], ['1', 2])).toBe(true); | ||
}); | ||
it('Non-identical arrays ar not equal', () => { | ||
expect(ArrayUtil.getDifference(['1', 2, 3], ['1', 2]).length).toBeTruthy(); | ||
expect(ArrayUtil.isEqual(['1', 2, 3], ['1', 2])).toBeFalsy(); | ||
}); | ||
it('Non-identical arrays ar not equal', () => { | ||
expect( | ||
ArrayUtil.getDifference(['1', 2, 3], ['1', 2]).length | ||
).toBeTruthy(); | ||
expect(ArrayUtil.isEqual(['1', 2, 3], ['1', 2])).toBe(false); | ||
}); | ||
}); | ||
describe('removeObject', () => { | ||
it('Can remove multiples of identical objects from array', () => { | ||
const object = {name: 'John', level: -1}; | ||
const object2 = {name: 'August', level: 30}; | ||
const array = [ | ||
{name: 'John', level: -1}, | ||
{name: 'August', level: 30}, | ||
{name: 'John', level: -1}, | ||
{name: 'Peter', level: '!cow'} | ||
]; | ||
ArrayUtil.removeObject(object, array); | ||
expect(array.length).toBe(2); | ||
expect(array[0]).toEqual(object2); | ||
}); | ||
it('Can remove multiples of identical strings from array', () => { | ||
const object = {name: 'John', level: -1}; | ||
const array = [ | ||
'a', 'b', 'a', 'a', 'b' | ||
]; | ||
ArrayUtil.removeObject('a', array); | ||
expect(array.length).toBe(2); | ||
}); | ||
describe('removeObject', () => { | ||
it('Can remove multiples of identical objects from array', () => { | ||
const object = { name: 'John', level: -1 }; | ||
const object2 = { name: 'August', level: 30 }; | ||
const array = [ | ||
{ name: 'John', level: -1 }, | ||
{ name: 'August', level: 30 }, | ||
{ name: 'John', level: -1 }, | ||
{ name: 'Peter', level: '!cow' } | ||
]; | ||
ArrayUtil.removeObject(object, array); | ||
expect(array.length).toBe(2); | ||
expect(array[0]).toEqual(object2); | ||
}); | ||
it('Can remove multiples of identical strings from array', () => { | ||
const object = { name: 'John', level: -1 }; | ||
const array = ['a', 'b', 'a', 'a', 'b']; | ||
ArrayUtil.removeObject('a', array); | ||
expect(array.length).toBe(2); | ||
}); | ||
it('Can remove multiples of identical numbers from array', () => { | ||
const object = {name: 'John', level: -1}; | ||
const array = [ | ||
0, 1, 0, 0, 1 | ||
]; | ||
ArrayUtil.removeObject(1, array); | ||
expect(array.length).toBe(3); | ||
}); | ||
it('Can remove multiples of identical numbers from array', () => { | ||
const object = { name: 'John', level: -1 }; | ||
const array = [0, 1, 0, 0, 1]; | ||
ArrayUtil.removeObject(1, array); | ||
expect(array.length).toBe(3); | ||
}); | ||
it('Can remove multiples of identical booleans from array', () => { | ||
const object = {name: 'John', level: -1}; | ||
const array = [ | ||
true, false, true, true, false | ||
]; | ||
ArrayUtil.removeObject(false, array); | ||
expect(array.length).toBe(3); | ||
}); | ||
it('Can remove multiples of identical booleans from array', () => { | ||
const object = { name: 'John', level: -1 }; | ||
const array = [true, false, true, true, false]; | ||
ArrayUtil.removeObject(false, array); | ||
expect(array.length).toBe(3); | ||
}); | ||
}); | ||
describe('removeObjects', () => { | ||
it('Can remove multiples of identical objects from array', () => { | ||
const object = {name: 'John', level: -1}; | ||
const object2 = {name: 'Peter', level: '!cow'}; | ||
const object3 = {name: 'August', level: 30}; | ||
const array = [ | ||
{name: 'John', level: -1}, | ||
{name: 'August', level: 30}, | ||
{name: 'John', level: -1}, | ||
{name: 'Peter', level: '!cow'} | ||
]; | ||
ArrayUtil.removeObjects([object, object2], array); | ||
expect(array.length).toBe(1); | ||
expect(array[0]).toEqual(object3); | ||
}); | ||
describe('removeObjects', () => { | ||
it('Can remove multiples of identical objects from array', () => { | ||
const object = { name: 'John', level: -1 }; | ||
const object2 = { name: 'Peter', level: '!cow' }; | ||
const object3 = { name: 'August', level: 30 }; | ||
const array = [ | ||
{ name: 'John', level: -1 }, | ||
{ name: 'August', level: 30 }, | ||
{ name: 'John', level: -1 }, | ||
{ name: 'Peter', level: '!cow' } | ||
]; | ||
ArrayUtil.removeObjects([object, object2], array); | ||
expect(array.length).toBe(1); | ||
expect(array[0]).toEqual(object3); | ||
}); | ||
}); | ||
describe('removeDuplicates', () => { | ||
it('can remove duplicates', () => { | ||
const array = [ | ||
{name: 'John', level: -1}, | ||
{name: 'August', level: 30}, | ||
{name: 'John', level: -1}, | ||
{name: 'Peter', level: '!cow'}, | ||
null, | ||
undefined, | ||
undefined, | ||
true, | ||
false, | ||
1, | ||
1, | ||
[], | ||
[] | ||
]; | ||
describe('removeDuplicates', () => { | ||
it('can remove duplicates', () => { | ||
const array = [ | ||
{ name: 'John', level: -1 }, | ||
{ name: 'August', level: 30 }, | ||
{ name: 'John', level: -1 }, | ||
{ name: 'Peter', level: '!cow' }, | ||
null, | ||
undefined, | ||
undefined, | ||
true, | ||
false, | ||
1, | ||
1, | ||
[], | ||
[] | ||
]; | ||
ArrayUtil.removeDuplicates(array); | ||
expect(array.length).toBe(9); | ||
}); | ||
ArrayUtil.removeDuplicates(array); | ||
expect(array.length).toBe(9); | ||
}); | ||
}); | ||
describe('removeIndexes', () => { | ||
it('can remove multiple in random index order', () => { | ||
const array = [ | ||
'a', // 0 - 0 | ||
'b', // 1 - x | ||
'c', // 2 - x | ||
'd', // 3 - 1 | ||
'e', // 4 - x | ||
'f' // 5 - 2 | ||
]; | ||
ArrayUtil.removeIndexes([1,4, 2], array); | ||
expect(array.length).toBe(3); | ||
expect(array[0]).toBe('a'); | ||
expect(array[1]).toBe('d'); | ||
expect(array[2]).toBe('f'); | ||
}); | ||
describe('removeIndexes', () => { | ||
it('can remove multiple in random index order', () => { | ||
const array = [ | ||
'a', // 0 - 0 | ||
'b', // 1 - x | ||
'c', // 2 - x | ||
'd', // 3 - 1 | ||
'e', // 4 - x | ||
'f' // 5 - 2 | ||
]; | ||
ArrayUtil.removeIndexes([1, 4, 2], array); | ||
expect(array.length).toBe(3); | ||
expect(array[0]).toBe('a'); | ||
expect(array[1]).toBe('d'); | ||
expect(array[2]).toBe('f'); | ||
}); | ||
}); | ||
describe('randomOrder', () => { | ||
it('the list has the same length and unequal', () => { | ||
describe('randomOrder', () => { | ||
it('the list has the same length and unequal', () => { | ||
const list = [...Array(100).keys()]; | ||
const list1 = ArrayUtil.randomOrder(list); | ||
const list2 = ArrayUtil.randomOrder(list); | ||
const list = [...Array(100).keys()]; | ||
const list1 = ArrayUtil.randomOrder(list); | ||
const list2 = ArrayUtil.randomOrder(list); | ||
expect(list1.length).toBe(list.length); | ||
expect(list2.length).toBe(list.length); | ||
expect(ArrayUtil.isEqual(list1, list2)).toBeFalsy(); | ||
}); | ||
expect(list1.length).toBe(list.length); | ||
expect(list2.length).toBe(list.length); | ||
expect( | ||
ArrayUtil.isEqual(list1, list2)).toBeFalsy(); | ||
}); | ||
it('does not contain undefined values', () => { | ||
const list = [...Array(10000).keys()]; | ||
expect( | ||
ArrayUtil.randomOrder(list) | ||
.filter(n => n === undefined).length) | ||
.toBe(0); | ||
expect( | ||
ArrayUtil.randomOrder(list) | ||
.filter(n => n === undefined).length) | ||
.toBe(0); | ||
}); | ||
it('does not contain undefined values', () => { | ||
const list = [...Array(10000).keys()]; | ||
expect( | ||
ArrayUtil.randomOrder(list).filter(n => n === undefined).length | ||
).toBe(0); | ||
expect( | ||
ArrayUtil.randomOrder(list).filter(n => n === undefined).length | ||
).toBe(0); | ||
}); | ||
}); | ||
}); |
@@ -14,4 +14,4 @@ import { EmptyUtil } from './empty.util'; | ||
typeof value === 'object' && | ||
value.forEach && | ||
value.push | ||
value.forEach !== undefined && | ||
value.push !== undefined | ||
); | ||
@@ -18,0 +18,0 @@ } |
@@ -86,3 +86,3 @@ import {TimeSince} from '../models/time-since.model'; | ||
const now = new Date(); | ||
switch(timeUnit) { | ||
switch (timeUnit) { | ||
case 'w': | ||
@@ -89,0 +89,0 @@ case 'weeks': |
@@ -6,3 +6,3 @@ import {ArrayUtil} from './array.util'; | ||
/** | ||
* Checks if all the input is null or undefined. | ||
* Checks if all the input is null or undefined. | ||
*/ | ||
@@ -9,0 +9,0 @@ public static isNullOrUndefined(value: any, value2?: any): boolean { |
@@ -7,12 +7,12 @@ import {ObjectUtil} from './object.util'; | ||
it('Populated objects returns true', () => { | ||
expect(ObjectUtil.isObject({name: 'true'})).toBeTruthy(); | ||
expect(ObjectUtil.isObject({name: 'true'})).toBe(true); | ||
}); | ||
it('Empty objects are objects too', () => { | ||
expect(ObjectUtil.isObject({})).toBeTruthy(); | ||
expect(ObjectUtil.isObject({})).toBe(true); | ||
}); | ||
it('Arrays are not objects', () => { | ||
expect(ObjectUtil.isObject([])).toBeFalsy(); | ||
expect(ObjectUtil.isObject(['Tore', 'Tang', 'en', 'gammal', 'mann'])).toBeFalsy(); | ||
expect(ObjectUtil.isObject([])).toBe(false); | ||
expect(ObjectUtil.isObject(['Tore', 'Tang', 'en', 'gammal', 'mann'])).toBe(false); | ||
}); | ||
@@ -23,7 +23,7 @@ }); | ||
it('Populated objects returns true', () => { | ||
expect(ObjectUtil.isPopulatedObject({name: 'true'})).toBeTruthy(); | ||
expect(ObjectUtil.isPopulatedObject({name: 'true'})).toBe(true); | ||
}); | ||
it('Empty objects are false', () => { | ||
expect(ObjectUtil.isPopulatedObject({})).toBeFalsy(); | ||
expect(ObjectUtil.isPopulatedObject({})).toBe(false); | ||
}); | ||
@@ -82,3 +82,3 @@ }); | ||
expect(ObjectUtil.getDifference(obj1, obj2).length).toBeFalsy(); | ||
expect(ObjectUtil.isEqual(obj1, obj2)).toBeTruthy(); | ||
expect(ObjectUtil.isEqual(obj1, obj2)).toBe(true); | ||
}); | ||
@@ -85,0 +85,0 @@ |
@@ -100,3 +100,3 @@ import {EmptyUtil} from './empty.util'; | ||
const differences = new Array<Difference>(), | ||
onlyFieldsMap = new Map<string, boolean>(); | ||
onlyFieldsMap = new Map<string, boolean>(); | ||
@@ -103,0 +103,0 @@ ignoreFields = this.getIgnoreFields(ignoreFields, onlyFields, onlyFieldsMap); |
@@ -158,3 +158,6 @@ import { TextUtil } from './text.util'; | ||
it('can convert a list of objects with identical keys', () => { | ||
const list = [{ name: 'John', age: 90 }, { name: 'Aga', age: 12 }]; | ||
const list = [ | ||
{ name: 'John', age: 90 }, | ||
{ name: 'Aga', age: 12 } | ||
]; | ||
expect(TextUtil.objectsToCSV(list, ';')).toEqual( | ||
@@ -183,2 +186,19 @@ 'Name;Age\n\r' + 'John;90\n\r' + 'Aga;12\n\r' | ||
}); | ||
describe('toSlug', () => { | ||
it('Turns the text into lowercase', () => { | ||
expect(TextUtil.toSlug('TEST')).toBe('test'); | ||
}); | ||
it('Turns spaces into dashes', () => { | ||
expect(TextUtil.toSlug('here are some Spaces')).toBe( | ||
'here-are-some-spaces' | ||
); | ||
}); | ||
it('Removes special characters', () => { | ||
expect(TextUtil.toSlug(`oh@crap/we!"#$=)(/&%$%&/()!)(/#&%$#$("`)).toBe( | ||
'ohcrapwe' | ||
); | ||
}); | ||
}); | ||
}); |
@@ -6,2 +6,8 @@ import { Match } from '../models/match.model'; | ||
export class TextUtil { | ||
static toSlug(text: string): any { | ||
return text | ||
.toLowerCase() | ||
.replace(/[ ]{1,9999}/g, '-') | ||
.replace(/[^a-zA-Z0-9-]{1,9999}/g, ''); | ||
} | ||
/** | ||
@@ -8,0 +14,0 @@ * Checks if a string is null, undefined or has a length of 0. |
@@ -9,7 +9,2 @@ { | ||
}, | ||
"component-class-suffix": true, | ||
"contextual-lifecycle": true, | ||
"directive-class-suffix": true, | ||
"directive-selector": [true, "attribute", "app", "camelCase"], | ||
"component-selector": [true, "element", "app", "kebab-case"], | ||
"interface-name": false, | ||
@@ -35,5 +30,4 @@ "max-classes-per-file": false, | ||
"no-non-null-assertion": true, | ||
"no-redundant-jsdoc": true, | ||
"no-redundant-jsdoc": false, | ||
"no-switch-case-fall-through": true, | ||
"no-use-before-declare": true, | ||
"no-var-requires": false, | ||
@@ -43,17 +37,6 @@ "object-literal-key-quotes": [true, "as-needed"], | ||
"ordered-imports": false, | ||
"one-variable-per-declaration": false, | ||
"quotemark": [true, "single"], | ||
"trailing-comma": false, | ||
"no-conflicting-lifecycle": true, | ||
"no-host-metadata-property": true, | ||
"no-input-rename": true, | ||
"no-inputs-metadata-property": true, | ||
"no-output-native": true, | ||
"no-output-on-prefix": true, | ||
"no-output-rename": true, | ||
"no-outputs-metadata-property": true, | ||
"template-banana-in-box": true, | ||
"template-no-negated-async": true, | ||
"use-lifecycle-interface": true, | ||
"use-pipe-transform-interface": true | ||
"trailing-comma": false | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
204374
3069