Skip to content

Commit

Permalink
Merge branch 'main' into feat/flip
Browse files Browse the repository at this point in the history
  • Loading branch information
D-Sketon authored Sep 25, 2024
2 parents 1b91cdc + d216470 commit 4042313
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 13 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# es-toolkit Changelog

## Version v1.21.0

Released on September 25th, 2024.

- Added support for [constantCase](https://es-toolkit.slash.page/reference/string/constantCase.html) and [isError](https://es-toolkit.slash.page/reference/predicate/isError.html).
- Added compatibility functions for [pad](https://es-toolkit.slash.page/reference/compat/string/pad.html), [padStart](https://es-toolkit.slash.page/reference/compat/string/padStart.html), [padEnd](https://es-toolkit.slash.page/reference/compat/string/padEnd.html), [defer](https://es-toolkit.slash.page/reference/compat/function/defer.html), [isFinite](https://es-toolkit.slash.page/reference/compat/predicate/isFinite.html), [toNumber](https://es-toolkit.slash.page/reference/compat/math/toNumber.html), [toFinite](https://es-toolkit.slash.page/reference/compat/math/toFinite.html), and [toInteger](https://es-toolkit.slash.page/reference/compat/math/toInteger.html).
- Improved performance for [flatten](https://es-toolkit.slash.page/reference/array/flatten.html), [isNumber](https://es-toolkit.slash.page/reference/predicate/isNumber.html), [isString](https://es-toolkit.slash.page/reference/predicate/isString.html), [isSymbol](https://es-toolkit.slash.page/reference/predicate/isSymbol.html), [isRegExp](https://es-toolkit.slash.page/reference/predicate/isRegExp.html), and [isBoolean](https://es-toolkit.slash.page/reference/predicate/isBoolean.html).
- Fixed [compact](https://es-toolkit.slash.page/reference/array/compact.html) to correctly exclude `0n` as a falsey value.
- Fixed [pick](https://es-toolkit.slash.page/reference/object/pick.html) to not pick nonexistent keys from the original object.
- Fixed [omit](https://es-toolkit.slash.page/reference/object/omit.html) to accept readonly arrays.

This version includes contributions from @hyesungoh, @D-Sketon, @mass2527, @gweesin, @VVSOGI, @coding-honey, @seonghun0828, and @jsparkdev. Thank you for your valuable contributions!

## Version v1.20.0

Released on September 20th, 2024.
Expand Down
10 changes: 7 additions & 3 deletions benchmarks/performance/pick.bench.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { bench, describe } from 'vitest';
import { pick as pickToolkit } from 'es-toolkit';
import { pick as pickCompatToolkit } from 'es-toolkit/compat';
import { pick as pickLodash } from 'lodash';
import { pick as pickToolkit_ } from 'es-toolkit';
import { pick as pickCompatToolkit_ } from 'es-toolkit/compat';
import { pick as pickLodash_ } from 'lodash';

const pickToolkit = pickToolkit_;
const pickCompatToolkit = pickCompatToolkit_;
const pickLodash = pickLodash_;

describe('pick', () => {
bench('es-toolkit/pick', () => {
Expand Down
1 change: 1 addition & 0 deletions docs/ja/reference/string/camelCase.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ camelCase('camelCase'); // 'camelCase' を返します
camelCase('some whitespace'); // 'someWhitespace' を返します
camelCase('hyphen-text'); // 'hyphenText' を返します
camelCase('HTTPRequest'); // 'httpRequest' を返します
camelCase('Keep unicode 😅') // 'keepUnicode😅' を返します
```
1 change: 1 addition & 0 deletions docs/ko/reference/string/camelCase.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ camelCase('camelCase'); // returns 'camelCase'
camelCase('some whitespace'); // returns 'someWhitespace'
camelCase('hyphen-text'); // returns 'hyphenText'
camelCase('HTTPRequest'); // returns 'httpRequest'
camelCase('Keep unicode 😅') // returns 'keepUnicode😅'
```
1 change: 1 addition & 0 deletions docs/reference/string/camelCase.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ camelCase('camelCase'); // returns 'camelCase'
camelCase('some whitespace'); // returns 'someWhitespace'
camelCase('hyphen-text'); // returns 'hyphenText'
camelCase('HTTPRequest'); // returns 'httpRequest'
camelCase('Keep unicode 😅') // returns 'keepUnicode😅'
```
1 change: 1 addition & 0 deletions docs/zh_hans/reference/string/camelCase.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ camelCase('camelCase'); // 返回 'camelCase'
camelCase('some whitespace'); // 返回 'someWhitespace'
camelCase('hyphen-text'); // 返回 'hyphenText'
camelCase('HTTPRequest'); // 返回 'httpRequest'
camelCase('Keep unicode 😅') // 返回 'keepUnicode😅'
```
2 changes: 1 addition & 1 deletion jsr.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@es-toolkit/es-toolkit",
"version": "1.20.0",
"version": "1.21.0",
"exports": {
".": "./src/index.ts",
"./compat": "./src/compat/index.ts"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "es-toolkit",
"description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
"version": "1.20.0",
"version": "1.21.0",
"homepage": "https://es-toolkit.slash.page",
"bugs": "https://github.com/toss/es-toolkit/issues",
"repository": {
Expand Down
7 changes: 7 additions & 0 deletions src/object/pick.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,11 @@ describe('pick', () => {
const result = pick(object, ['a', 'b', 'c']);
expect(result).toEqual({ a: 1, b: { nested: 'pick' }, c: 3 });
});

it('should not pick from nonexistent keys', () => {
const obj: { a?: unknown } = {};
const result = pick(obj, ['a']);

expect(Reflect.ownKeys(result)).toEqual([]);
})
});
5 changes: 4 additions & 1 deletion src/object/pick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export function pick<T extends Record<string, any>, K extends keyof T>(obj: T, k

for (let i = 0; i < keys.length; i++) {
const key = keys[i];
result[key] = obj[key];

if (Object.prototype.hasOwnProperty.call(obj, key)) {
result[key] = obj[key];
}
}

return result;
Expand Down
4 changes: 4 additions & 0 deletions src/string/_internal/getWords.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,8 @@ describe('caseSplitPattern', () => {
it('should work with numbers', () => {
expect(getWords('foo2bar')).toEqual(['foo', '2', 'bar']);
});

it('should match emojis', () => {
expect(getWords('camelCaseHTTPRequest🚀')).toEqual(['camel', 'Case', 'HTTP', 'Request', '🚀']);
});
});
14 changes: 8 additions & 6 deletions src/string/_internal/getWords.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
/**
* Regular expression pattern to split strings into words for various case conversions
*
* This pattern matches sequences of characters in a string, considering the following case:
* This pattern matches sequences of characters in a string, considering the following cases:
* - Sequences of two or more uppercase letters followed by an uppercase letter and lowercase letters or digits (for acronyms)
* - Sequences of one uppercase letter optionally followed by lowercase letters and digits
* - Single uppercase letters
* - Sequences of digis
* - Sequences of digits
* - Emojis and other Unicode characters
*
* The resulting match can be used to convert camelCase, snake_case, kebab-case, and other mixed formats into
* a consistent format like snake case.
* a consistent format like snake case. It also supports emojis and other Unicode characters.
*
* @example
* const matches = 'camelCaseHTTPRequest'.match(CASE_SPLIT_PATTERN);
* // matches: ['camel', 'Case', 'HTTP', 'Request']
* const matches = 'camelCaseHTTPRequest🚀'.match(CASE_SPLIT_PATTERN);
* // matches: ['camel', 'Case', 'HTTP', 'Request', '🚀']
*/
const CASE_SPLIT_PATTERN = /[A-Z]?[a-z]+|[0-9]+|[A-Z]+(?![a-z])/g;
const CASE_SPLIT_PATTERN =
/[A-Z]?[a-z]+|[0-9]+|[A-Z]+(?![a-z])|\p{Emoji_Presentation}|\p{Extended_Pictographic}|\p{L}+/gu;

export function getWords(str: string): string[] {
return Array.from(str.match(CASE_SPLIT_PATTERN) ?? []);
Expand Down
4 changes: 4 additions & 0 deletions src/string/camelCase.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ describe('camelCase', () => {
it('should work with screaming camel case', () => {
expect(camelCase('FOO_BAR')).toEqual('fooBar');
});

it('should support emojis', () => {
expect(camelCase('Keep unicode 😅')).toEqual('keepUnicode😅');
});
});
2 changes: 1 addition & 1 deletion src/string/camelCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import { getWords } from './_internal/getWords.ts';
* const convertedStr2 = camelCase('some whitespace') // returns 'someWhitespace'
* const convertedStr3 = camelCase('hyphen-text') // returns 'hyphenText'
* const convertedStr4 = camelCase('HTTPRequest') // returns 'httpRequest'
* const convertedStr5 = camelCase('Keep unicode 😅') // returns 'keepUnicode😅'
*/

export function camelCase(str: string): string {
const words = getWords(str);

Expand Down

0 comments on commit 4042313

Please sign in to comment.