@angular-ru/cdk/string

  • capitalize

console.log(capitalize('hello world')); // Hello world
  • stringify

stringify({ a: 1, b: { c: 2 } }); // pretty print
  • toStringValue(value: T, converter?: (val: T) => string)

let value: string = toStringValue([1, 2, 3]); // "1,2,3"
value = toStringValue([1, 2, 3], (values: string[]) => values.join('; ')); // "1; 2; 3"
  • getByteSize(val: string)

expect(getByteSize('сын')).toEqual(6);
expect(getByteSize('son')).toEqual(3);
  • splitOnUniqueValues

expect(splitOnUniqueValues('1; 2; 3, 5.6;   ;, ; 3, 6, 2; 1; -52; 0')).toEqual(['1', '2', '3', '5.6', '6', '-52', '0']);
expect(splitOnUniqueValues('1 - 2 - 3 - 3 - 2 - 1', /-/g)).toEqual(['1', '2', '3']);
  • generateQuickGuid

console.log(generateQuickGuid()); // udn0la1mhfq4tudhnympq
  • isString

expect(isString('')).toEqual(true);
expect(isString(0)).toEqual(false);
expect(isString(NaN)).toEqual(false);
expect(isString(Infinity)).toEqual(false);
expect(isString(null)).toEqual(false);
expect(isString(undefined)).toEqual(false);
  • trim

expect(trim('test ')).toEqual('test');
expect(trim('      test  ')).toEqual('test');
expect(trim('   test  test  ')).toEqual('test  test');
  • getFirstSymbol

expect(getFirstSymbol(' test ')).toEqual(' ');
expect(getFirstSymbol('e123')).toEqual('e');
  • getLastSymbol

expect(getLastSymbol('test ')).toEqual(' ');
expect(getLastSymbol('test')).toEqual('t');
  • removeLastSymbol

expect(removeLastSymbol('test ')).toEqual('test');
expect(removeLastSymbol('123')).toEqual('12');
expect(removeLastSymbol('')).toEqual('');
  • replaceEveryCommaOnDot

expect(replaceEveryCommaOnDot('1,2,3')).toEqual('1.2.3');
expect(replaceEveryCommaOnDot('1,2...3,5')).toEqual('1.2...3.5');
  • getCountSpacesOnString

expect(getCountSpacesOnString('')).toEqual(0);
expect(getCountSpacesOnString('1 2 3')).toEqual(3);
expect(getCountSpacesOnString(null)).toEqual(0);
expect(getCountSpacesOnString()).toEqual(0);
  • removeNonNumericSymbols

expect(removeNonNumericSymbols('Tsgqw__-123,525.asdasd!~s . adqasllZ*a')).toEqual('-123,525..');
expect(removeNonNumericSymbols('1 2 3')).toEqual('123');
expect(removeNonNumericSymbols(null)).toEqual('');
expect(removeNonNumericSymbols()).toEqual('');

Last updated