Skip to content

Commit 4edc83d

Browse files
authored
feat: port more string functions from lodash (#60)
1 parent 81763cd commit 4edc83d

17 files changed

+270
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"author": "Tinkoff team",
55
"scripts": {
66
"release": "node ./releaseUtils/index.js",
7-
"benchmark": "ts-node --skip-project runBenchmark.ts",
7+
"benchmark": "ts-node --project tsconfig.benchmark.json runBenchmark.ts",
88
"prebenchmark": "npm install --no-save ts-node lodash ramda lazy.js underscore",
99
"docs": "node ./generate/docs/index.js",
1010
"test": "jest --coverage",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import camelCaseName from '../camelCaseName';
2+
3+
const camelCaseLodash = require('lodash/camelCase');
4+
5+
const testStr = 'very-log-foo-bar-string';
6+
7+
export default {
8+
lodash: () => {
9+
camelCaseLodash(testStr);
10+
},
11+
utils: () => {
12+
camelCaseName(testStr);
13+
},
14+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import kebabCaseName from '../kebabCaseName';
2+
3+
const kebabCaseLodash = require('lodash/kebabCase');
4+
5+
const testStr = 'VeryLogFooBarString';
6+
7+
export default {
8+
lodash: () => {
9+
kebabCaseLodash(testStr);
10+
},
11+
utils: () => {
12+
kebabCaseName(testStr);
13+
},
14+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import snakeCaseName from '../snakeCaseName';
2+
3+
const snakeCaseLodash = require('lodash/snakeCase');
4+
5+
const testStr = 'VeryLogFooBarString';
6+
7+
export default {
8+
lodash: () => {
9+
snakeCaseLodash(testStr);
10+
},
11+
utils: () => {
12+
snakeCaseName(testStr);
13+
},
14+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const upperFirstLodash = require('lodash/upperFirst');
2+
import upperFirst from '../upperFirst';
3+
4+
const testStr = 'very-log-foo-bar-string';
5+
6+
export default {
7+
lodash: () => {
8+
upperFirstLodash(testStr);
9+
},
10+
utils: () => {
11+
upperFirst(testStr);
12+
},
13+
};

src/string/__benchmarks__/words.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const wordsLodash = require('lodash/words');
2+
import words from '../words';
3+
4+
const testStr = 'very-log-foo-bar-string';
5+
6+
export default {
7+
lodash: () => {
8+
wordsLodash(testStr);
9+
},
10+
utils: () => {
11+
words(testStr);
12+
},
13+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import camelCaseName from '../camelCaseName';
2+
3+
describe('utils/string/camelCaseName', () => {
4+
it.each([
5+
['', ''],
6+
['abc', 'abc'],
7+
['Foo Bar', 'fooBar'],
8+
['foo-bar', 'fooBar'],
9+
['foo_bar', 'fooBar'],
10+
['FOO_BAR', 'fooBar'],
11+
['fooBar', 'fooBar'],
12+
['Foo Bär', 'fooBR'],
13+
])('should return camel cased string for %s: %s', (str, expected) => {
14+
expect(camelCaseName(str)).toEqual(expected);
15+
});
16+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import kebabCaseName from '../kebabCaseName';
2+
3+
describe('utils/string/kebabCaseName', () => {
4+
it.each([
5+
['', ''],
6+
['abc', 'abc'],
7+
['Foo Bar', 'foo-bar'],
8+
['fooBar', 'foo-bar'],
9+
['foo-bar', 'foo-bar'],
10+
['foo_Bar', 'foo-bar'],
11+
['FOO_BAR', 'foo-bar'],
12+
['Foo Bär', 'foo-b-r'],
13+
])('should return kebab cased string for %s: %s', (str, expected) => {
14+
expect(kebabCaseName(str)).toEqual(expected);
15+
});
16+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import snakeCaseName from '../snakeCaseName';
2+
3+
describe('utils/string/snakeCaseName', () => {
4+
it.each([
5+
['', ''],
6+
['abc', 'abc'],
7+
['Foo Bar', 'foo_bar'],
8+
['fooBar', 'foo_bar'],
9+
['foo_Bar', 'foo_bar'],
10+
['foo-Bar', 'foo_bar'],
11+
['FOO_BAR', 'foo_bar'],
12+
['Foo Bär', 'foo_b_r'],
13+
])('should return snake cased string for %s: %s', (str, expected) => {
14+
expect(snakeCaseName(str)).toEqual(expected);
15+
});
16+
});

src/string/__tests__/upperFirst.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import upperFirst from '../upperFirst';
2+
3+
describe('utils/string/upperFirst', () => {
4+
it.each([
5+
['', ''],
6+
['foo', 'Foo'],
7+
['FOO', 'FOO'],
8+
['über', 'Über'],
9+
])('should convert the first character of string to upper case for %s: %s', (str, expected) => {
10+
expect(upperFirst(str)).toEqual(expected);
11+
});
12+
});

0 commit comments

Comments
 (0)