mirror of
https://github.com/toss/es-toolkit.git
synced 2024-11-27 14:57:44 +03:00
chore(startsWith, endsWith): Update docs and import tests from lodash
This commit is contained in:
parent
b9b409db32
commit
2db0b49579
@ -165,6 +165,8 @@ function sidebar(): DefaultTheme.Sidebar {
|
||||
{ text: 'lowerCase', link: '/reference/string/lowerCase' },
|
||||
{ text: 'startCase', link: '/reference/string/startCase' },
|
||||
{ text: 'capitalize', link: '/reference/string/capitalize' },
|
||||
{ text: 'startsWith (compat)', link: '/reference/compat/string/startsWith' },
|
||||
{ text: 'endsWith (compat)', link: '/reference/compat/string/endsWith' },
|
||||
],
|
||||
},
|
||||
{
|
||||
|
@ -179,6 +179,8 @@ function sidebar(): DefaultTheme.Sidebar {
|
||||
{ text: 'lowerCase', link: '/ko/reference/string/lowerCase' },
|
||||
{ text: 'startCase', link: '/ko/reference/string/startCase' },
|
||||
{ text: 'capitalize', link: '/ko/reference/string/capitalize' },
|
||||
{ text: 'startsWith (호환성)', link: '/ko/reference/compat/string/startsWith' },
|
||||
{ text: 'endsWith (호환성)', link: '/ko/reference/compat/string/endsWith' },
|
||||
],
|
||||
}
|
||||
],
|
||||
|
@ -160,6 +160,8 @@ function sidebar(): DefaultTheme.Sidebar {
|
||||
{ text: 'kebabCase', link: '/zh_hans/reference/string/kebabCase' },
|
||||
{ text: 'lowerCase', link: '/zh_hans/reference/string/lowerCase' },
|
||||
{ text: 'capitalize', link: '/zh_hans/reference/string/capitalize' },
|
||||
{ text: 'startsWith (兼容性)', link: '/zh_hans/reference/string/startsWith' },
|
||||
{ text: 'endsWith (兼容性)', link: '/zh_hans/reference/string/endsWith' },
|
||||
],
|
||||
}
|
||||
],
|
||||
|
@ -322,7 +322,7 @@ It's worth noting that even if an implementation is labeled as "in review", it m
|
||||
| [camelCase](https://lodash.com/docs/4.17.15#camelCase) | 📝 |
|
||||
| [capitalize](https://lodash.com/docs/4.17.15#capitalize) | 📝 |
|
||||
| [deburr](https://lodash.com/docs/4.17.15#deburr) | ❌ |
|
||||
| [endsWith](https://lodash.com/docs/4.17.15#endsWith) | ❌ |
|
||||
| [endsWith](https://lodash.com/docs/4.17.15#endsWith) | ✅ |
|
||||
| [escape](https://lodash.com/docs/4.17.15#escape) | ❌ |
|
||||
| [escapeRegExp](https://lodash.com/docs/4.17.15#escapeRegExp) | ❌ |
|
||||
| [kebabCase](https://lodash.com/docs/4.17.15#kebabCase) | 📝 |
|
||||
@ -337,7 +337,7 @@ It's worth noting that even if an implementation is labeled as "in review", it m
|
||||
| [snakeCase](https://lodash.com/docs/4.17.15#snakeCase) | 📝 |
|
||||
| [split](https://lodash.com/docs/4.17.15#split) | ❌ |
|
||||
| [startCase](https://lodash.com/docs/4.17.15#startCase) | ❌ |
|
||||
| [startsWith](https://lodash.com/docs/4.17.15#startsWith) | ❌ |
|
||||
| [startsWith](https://lodash.com/docs/4.17.15#startsWith) | ✅ |
|
||||
| [template](https://lodash.com/docs/4.17.15#template) | ❌ |
|
||||
| [toLower](https://lodash.com/docs/4.17.15#toLower) | ❌ |
|
||||
| [toUpper](https://lodash.com/docs/4.17.15#toUpper) | ❌ |
|
||||
|
@ -323,7 +323,7 @@ chunk([1, 2, 3, 4], 0);
|
||||
| [camelCase](https://lodash.com/docs/4.17.15#camelCase) | 📝 |
|
||||
| [capitalize](https://lodash.com/docs/4.17.15#capitalize) | 📝 |
|
||||
| [deburr](https://lodash.com/docs/4.17.15#deburr) | ❌ |
|
||||
| [endsWith](https://lodash.com/docs/4.17.15#endsWith) | ❌ |
|
||||
| [endsWith](https://lodash.com/docs/4.17.15#endsWith) | ✅ |
|
||||
| [escape](https://lodash.com/docs/4.17.15#escape) | ❌ |
|
||||
| [escapeRegExp](https://lodash.com/docs/4.17.15#escapeRegExp) | ❌ |
|
||||
| [kebabCase](https://lodash.com/docs/4.17.15#kebabCase) | 📝 |
|
||||
@ -338,7 +338,7 @@ chunk([1, 2, 3, 4], 0);
|
||||
| [snakeCase](https://lodash.com/docs/4.17.15#snakeCase) | 📝 |
|
||||
| [split](https://lodash.com/docs/4.17.15#split) | ❌ |
|
||||
| [startCase](https://lodash.com/docs/4.17.15#startCase) | ❌ |
|
||||
| [startsWith](https://lodash.com/docs/4.17.15#startsWith) | ❌ |
|
||||
| [startsWith](https://lodash.com/docs/4.17.15#startsWith) | ✅ |
|
||||
| [template](https://lodash.com/docs/4.17.15#template) | ❌ |
|
||||
| [toLower](https://lodash.com/docs/4.17.15#toLower) | ❌ |
|
||||
| [toUpper](https://lodash.com/docs/4.17.15#toUpper) | ❌ |
|
||||
|
34
docs/ko/reference/compat/string/endsWith.md
Normal file
34
docs/ko/reference/compat/string/endsWith.md
Normal file
@ -0,0 +1,34 @@
|
||||
# endsWith
|
||||
|
||||
::: info
|
||||
[lodash와 호환](../../../compatibility.md)되는 `es-toolkit/compat` 라이브러리에서 쓸 수 있어요.
|
||||
:::
|
||||
|
||||
문자열이 주어진 문자열로 끝나는지 확인해요. 검색을 마칠 인덱스를 지정할 수 있어요.
|
||||
|
||||
## 인터페이스
|
||||
|
||||
```typescript
|
||||
function endsWith(str: string, target: string, position: number = 0): string;
|
||||
```
|
||||
|
||||
### 파라미터
|
||||
|
||||
- `str` (`string`): 검색할 문자열.
|
||||
- `target` (`string`): 끝날 때 일치해야 할 문자열.
|
||||
- `position` (`number`, 선택): 검색을 마칠 인덱스.
|
||||
|
||||
### 반환 값
|
||||
|
||||
(`boolean`): 문자열이 주어진 문자열로 끝나는지 여부.
|
||||
|
||||
## 예시
|
||||
|
||||
```typescript
|
||||
import { endsWith } from 'es-toolkit/compat';
|
||||
|
||||
endsWith('fooBar', 'foo') // returns true
|
||||
endsWith('fooBar', 'Bar') // returns false
|
||||
endsWith('fooBar', 'abcdef') // returns false
|
||||
endsWith('fooBar', 'Bar', 3) // returns true
|
||||
```
|
34
docs/ko/reference/compat/string/startsWith.md
Normal file
34
docs/ko/reference/compat/string/startsWith.md
Normal file
@ -0,0 +1,34 @@
|
||||
# startsWith
|
||||
|
||||
::: info
|
||||
[lodash와 호환](../../../compatibility.md)되는 `es-toolkit/compat` 라이브러리에서 쓸 수 있어요.
|
||||
:::
|
||||
|
||||
문자열이 주어진 문자열로 시작하는지 확인해요. 검색을 시작할 인덱스를 지정할 수 있어요.
|
||||
|
||||
## 인터페이스
|
||||
|
||||
```typescript
|
||||
function startsWith(str: string, target: string, position: number = 0): string;
|
||||
```
|
||||
|
||||
### 파라미터
|
||||
|
||||
- `str` (`string`): 검색할 문자열.
|
||||
- `target` (`string`): 시작할 때 일치해야 할 문자열.
|
||||
- `position` (`number`, 선택): 검색을 시작할 인덱스.
|
||||
|
||||
### 반환 값
|
||||
|
||||
(`boolean`): 문자열이 주어진 문자열로 시작하는지 여부
|
||||
|
||||
## 예시
|
||||
|
||||
```typescript
|
||||
import { startsWith } from 'es-toolkit/compat';
|
||||
|
||||
startsWith('fooBar', 'foo') // returns true
|
||||
startsWith('fooBar', 'Bar') // returns false
|
||||
startsWith('fooBar', 'abcdef') // returns false
|
||||
startsWith('fooBar', 'Bar', 3) // returns true
|
||||
```
|
@ -1,34 +0,0 @@
|
||||
# endsWith
|
||||
|
||||
TODO translate to korean
|
||||
|
||||
Checks if a string contains another string at the end of the string.
|
||||
|
||||
Checks if one string ends with another string. Optional position parameter to search up the this position.
|
||||
|
||||
## Signature
|
||||
|
||||
```typescript
|
||||
function endsWith(str: string, target: string, position: number = 0): string;
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
- `str` (`string`): The string that will be searched.
|
||||
- `target` (`string`): The string that it should contain at the end.
|
||||
- `position` (`number`, optional): Optional: position to search up to this character position.
|
||||
|
||||
### Returns
|
||||
|
||||
(`boolean`) Whether or not the str string ends with the target string
|
||||
|
||||
## Examples
|
||||
|
||||
```typescript
|
||||
import { endsWith } from 'es-toolkit/string';
|
||||
|
||||
endsWith('fooBar', 'foo') // returns true
|
||||
endsWith('fooBar', 'Bar') // returns false
|
||||
endsWith('fooBar', 'abcdef') // returns false
|
||||
endsWith('fooBar', 'Bar', 3) // returns true
|
||||
```
|
@ -1,34 +0,0 @@
|
||||
# startsWith
|
||||
|
||||
TODO translate to korean
|
||||
|
||||
Converts a string to kebab case.
|
||||
|
||||
Snake case is the naming convention in which each word is written in lowercase and separated by an dash (\-) character. For example, `kebab_case`.
|
||||
|
||||
## Signature
|
||||
|
||||
```typescript
|
||||
function startsWith(str: string, target: string, position: number = 0): string;
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
- `str` (`string`): The string that will be searched.
|
||||
- `target` (`string`): The string that it should contain at the start.
|
||||
- `position` (`number`, optional): Optional: offset to start searching in the str string.
|
||||
|
||||
### Returns
|
||||
|
||||
(`boolean`) Whether or not the str string starts with the target string
|
||||
|
||||
## Examples
|
||||
|
||||
```typescript
|
||||
import { startsWith } from 'es-toolkit/string';
|
||||
|
||||
startsWith('fooBar', 'foo') // returns true
|
||||
startsWith('fooBar', 'Bar') // returns false
|
||||
startsWith('fooBar', 'abcdef') // returns false
|
||||
startsWith('fooBar', 'Bar', 3) // returns true
|
||||
```
|
36
docs/reference/compat/string/endsWith.md
Normal file
36
docs/reference/compat/string/endsWith.md
Normal file
@ -0,0 +1,36 @@
|
||||
# endsWith
|
||||
|
||||
::: info
|
||||
This is available in our [compatibility library](../../../compatibility.md), `es-toolkit/compat`.
|
||||
:::
|
||||
|
||||
Checks if a string contains another string at the end of the string.
|
||||
|
||||
Checks if one string ends with another string. Optional position parameter to search up the this position.
|
||||
|
||||
## Signature
|
||||
|
||||
```typescript
|
||||
function endsWith(str: string, target: string, position: number = 0): string;
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
- `str` (`string`): The string that will be searched.
|
||||
- `target` (`string`): The string that it should contain at the end.
|
||||
- `position` (`number`, optional): Optional: position to search up to this character position.
|
||||
|
||||
### Returns
|
||||
|
||||
(`boolean`): Whether or not the str string ends with the target string
|
||||
|
||||
## Examples
|
||||
|
||||
```typescript
|
||||
import { endsWith } from 'es-toolkit/string';
|
||||
|
||||
endsWith('fooBar', 'foo') // returns true
|
||||
endsWith('fooBar', 'Bar') // returns false
|
||||
endsWith('fooBar', 'abcdef') // returns false
|
||||
endsWith('fooBar', 'foo', 3) // returns true
|
||||
```
|
36
docs/reference/compat/string/startsWith.md
Normal file
36
docs/reference/compat/string/startsWith.md
Normal file
@ -0,0 +1,36 @@
|
||||
# startsWith
|
||||
|
||||
::: info
|
||||
This is available in our [compatibility library](../../../compatibility.md), `es-toolkit/compat`.
|
||||
:::
|
||||
|
||||
Checks if a string contains another string at the beginning of the string.
|
||||
|
||||
Checks if one string startsWith another string. Optional position parameter to start searching from a certain index.
|
||||
|
||||
## Signature
|
||||
|
||||
```typescript
|
||||
function startsWith(str: string, target: string, position: number = 0): string;
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
- `str` (`string`): The string that will be searched.
|
||||
- `target` (`string`): The string that it should contain at the start.
|
||||
- `position` (`number`, optional): Optional: offset to start searching in the str string.
|
||||
|
||||
### Returns
|
||||
|
||||
(`boolean`) Whether or not the str string starts with the target string
|
||||
|
||||
## Examples
|
||||
|
||||
```typescript
|
||||
import { startsWith } from 'es-toolkit/string';
|
||||
|
||||
startsWith('fooBar', 'foo') // returns true
|
||||
startsWith('fooBar', 'Bar') // returns false
|
||||
startsWith('fooBar', 'abcdef') // returns false
|
||||
startsWith('fooBar', 'Bar', 3) // returns true
|
||||
```
|
@ -1,32 +0,0 @@
|
||||
# endsWith
|
||||
|
||||
Checks if a string contains another string at the end of the string.
|
||||
|
||||
Checks if one string ends with another string. Optional position parameter to search up the this position.
|
||||
|
||||
## Signature
|
||||
|
||||
```typescript
|
||||
function endsWith(str: string, target: string, position: number = 0): string;
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
- `str` (`string`): The string that will be searched.
|
||||
- `target` (`string`): The string that it should contain at the end.
|
||||
- `position` (`number`, optional): Optional: position to search up to this character position.
|
||||
|
||||
### Returns
|
||||
|
||||
(`boolean`) Whether or not the str string ends with the target string
|
||||
|
||||
## Examples
|
||||
|
||||
```typescript
|
||||
import { endsWith } from 'es-toolkit/string';
|
||||
|
||||
endsWith('fooBar', 'foo') // returns true
|
||||
endsWith('fooBar', 'Bar') // returns false
|
||||
endsWith('fooBar', 'abcdef') // returns false
|
||||
endsWith('fooBar', 'foo', 3) // returns true
|
||||
```
|
@ -1,32 +0,0 @@
|
||||
# startsWith
|
||||
|
||||
Checks if a string contains another string at the beginning of the string.
|
||||
|
||||
Checks if one string startsWith another string. Optional position parameter to start searching from a certain index.
|
||||
|
||||
## Signature
|
||||
|
||||
```typescript
|
||||
function startsWith(str: string, target: string, position: number = 0): string;
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
- `str` (`string`): The string that will be searched.
|
||||
- `target` (`string`): The string that it should contain at the start.
|
||||
- `position` (`number`, optional): Optional: offset to start searching in the str string.
|
||||
|
||||
### Returns
|
||||
|
||||
(`boolean`) Whether or not the str string starts with the target string
|
||||
|
||||
## Examples
|
||||
|
||||
```typescript
|
||||
import { startsWith } from 'es-toolkit/string';
|
||||
|
||||
startsWith('fooBar', 'foo') // returns true
|
||||
startsWith('fooBar', 'Bar') // returns false
|
||||
startsWith('fooBar', 'abcdef') // returns false
|
||||
startsWith('fooBar', 'Bar', 3) // returns true
|
||||
```
|
@ -322,7 +322,7 @@ chunk([1, 2, 3, 4], 0);
|
||||
| [camelCase](https://lodash.com/docs/4.17.15#camelCase) | 📝 |
|
||||
| [capitalize](https://lodash.com/docs/4.17.15#capitalize) | 📝 |
|
||||
| [deburr](https://lodash.com/docs/4.17.15#deburr) | ❌ |
|
||||
| [endsWith](https://lodash.com/docs/4.17.15#endsWith) | ❌ |
|
||||
| [endsWith](https://lodash.com/docs/4.17.15#endsWith) | ✅ |
|
||||
| [escape](https://lodash.com/docs/4.17.15#escape) | ❌ |
|
||||
| [escapeRegExp](https://lodash.com/docs/4.17.15#escapeRegExp) | ❌ |
|
||||
| [kebabCase](https://lodash.com/docs/4.17.15#kebabCase) | 📝 |
|
||||
@ -337,7 +337,7 @@ chunk([1, 2, 3, 4], 0);
|
||||
| [snakeCase](https://lodash.com/docs/4.17.15#snakeCase) | 📝 |
|
||||
| [split](https://lodash.com/docs/4.17.15#split) | ❌ |
|
||||
| [startCase](https://lodash.com/docs/4.17.15#startCase) | ❌ |
|
||||
| [startsWith](https://lodash.com/docs/4.17.15#startsWith) | ❌ |
|
||||
| [startsWith](https://lodash.com/docs/4.17.15#startsWith) | ✅ |
|
||||
| [template](https://lodash.com/docs/4.17.15#template) | ❌ |
|
||||
| [toLower](https://lodash.com/docs/4.17.15#toLower) | ❌ |
|
||||
| [toUpper](https://lodash.com/docs/4.17.15#toUpper) | ❌ |
|
||||
|
32
docs/zh_hans/reference/compat/string/endsWith.md
Normal file
32
docs/zh_hans/reference/compat/string/endsWith.md
Normal file
@ -0,0 +1,32 @@
|
||||
# endsWith
|
||||
|
||||
检查字符串是否在其末尾包含另一个字符串。
|
||||
|
||||
检查一个字符串是否以另一个字符串结尾。可以选择一个可选的位置参数在这个位置之前进行搜索。
|
||||
|
||||
## 签名
|
||||
|
||||
```typescript
|
||||
function endsWith(str: string, target: string, position: number = 0): string;
|
||||
```
|
||||
|
||||
### 参数
|
||||
|
||||
- `str` (`string`): 要搜索的字符串。
|
||||
- `target` (`string`): 应该包含在末尾的字符串。
|
||||
- `position` (`number`, 可选): 可选:搜索到这个字符位置。
|
||||
|
||||
### 返回值
|
||||
|
||||
(`boolean`): str 字符串是否以 target 字符串结尾。
|
||||
|
||||
## 示例
|
||||
|
||||
```typescript
|
||||
import { endsWith } from 'es-toolkit/compat';
|
||||
|
||||
endsWith('fooBar', 'foo') // 返回 true
|
||||
endsWith('fooBar', 'Bar') // 返回 false
|
||||
endsWith('fooBar', 'abcdef') // 返回 false
|
||||
endsWith('fooBar', 'Bar', 3) // 返回 true
|
||||
```
|
36
docs/zh_hans/reference/compat/string/startsWith.md
Normal file
36
docs/zh_hans/reference/compat/string/startsWith.md
Normal file
@ -0,0 +1,36 @@
|
||||
# startsWith
|
||||
|
||||
::: info
|
||||
此功能在我们的[兼容性库](../../../compatibility.md)中可用,`es-toolkit/compat`。
|
||||
:::
|
||||
|
||||
检查字符串是否在其开头包含另一个字符串。
|
||||
|
||||
检查一个字符串是否以另一个字符串开头。可以选择一个可选的位置参数从某个索引开始搜索。
|
||||
|
||||
## 签名
|
||||
|
||||
```typescript
|
||||
function startsWith(str: string, target: string, position: number = 0): string;
|
||||
```
|
||||
|
||||
### 参数
|
||||
|
||||
- `str` (`string`): 要搜索的字符串。
|
||||
- `target` (`string`): 应该包含在开头的字符串。
|
||||
- `position` (`number`, 可选): 可选:从 str 字符串的某个偏移量开始搜索。
|
||||
|
||||
### 返回值
|
||||
|
||||
(`boolean`) str 字符串是否以 target 字符串开头。
|
||||
|
||||
## 示例
|
||||
|
||||
```typescript
|
||||
import { startsWith } from 'es-toolkit/compat';
|
||||
|
||||
startsWith('fooBar', 'foo') // 返回 true
|
||||
startsWith('fooBar', 'Bar') // 返回 false
|
||||
startsWith('fooBar', 'abcdef') // 返回 false
|
||||
startsWith('fooBar', 'Bar', 3) // 返回 true
|
||||
```
|
@ -1,34 +0,0 @@
|
||||
# endsWith
|
||||
|
||||
TODO translate to chineese
|
||||
|
||||
Checks if a string contains another string at the end of the string.
|
||||
|
||||
Checks if one string ends with another string. Optional position parameter to search up the this position.
|
||||
|
||||
## Signature
|
||||
|
||||
```typescript
|
||||
function endsWith(str: string, target: string, position: number = 0): string;
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
- `str` (`string`): The string that will be searched.
|
||||
- `target` (`string`): The string that it should contain at the end.
|
||||
- `position` (`number`, optional): Optional: position to search up to this character position.
|
||||
|
||||
### Returns
|
||||
|
||||
(`boolean`) Whether or not the str string ends with the target string
|
||||
|
||||
## Examples
|
||||
|
||||
```typescript
|
||||
import { endsWith } from 'es-toolkit/string';
|
||||
|
||||
endsWith('fooBar', 'foo') // returns true
|
||||
endsWith('fooBar', 'Bar') // returns false
|
||||
endsWith('fooBar', 'abcdef') // returns false
|
||||
endsWith('fooBar', 'Bar', 3) // returns true
|
||||
```
|
@ -1,34 +0,0 @@
|
||||
# startsWith
|
||||
|
||||
TODO translate to chineese
|
||||
|
||||
Converts a string to kebab case.
|
||||
|
||||
Snake case is the naming convention in which each word is written in lowercase and separated by an dash (\-) character. For example, `kebab_case`.
|
||||
|
||||
## Signature
|
||||
|
||||
```typescript
|
||||
function startsWith(str: string, target: string, position: number = 0): string;
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
- `str` (`string`): The string that will be searched.
|
||||
- `target` (`string`): The string that it should contain at the start.
|
||||
- `position` (`number`, optional): Optional: offset to start searching in the str string.
|
||||
|
||||
### Returns
|
||||
|
||||
(`boolean`) Whether or not the str string starts with the target string
|
||||
|
||||
## Examples
|
||||
|
||||
```typescript
|
||||
import { startsWith } from 'es-toolkit/string';
|
||||
|
||||
startsWith('fooBar', 'foo') // returns true
|
||||
startsWith('fooBar', 'Bar') // returns false
|
||||
startsWith('fooBar', 'abcdef') // returns false
|
||||
startsWith('fooBar', 'Bar', 3) // returns true
|
||||
```
|
@ -27,3 +27,5 @@ export * from '../index.ts';
|
||||
export { chunk } from './array/chunk.ts';
|
||||
export { zipObjectDeep } from './array/zipObjectDeep.ts';
|
||||
export { set } from './object/set.ts';
|
||||
export { startsWith } from './string/startsWith.ts';
|
||||
export { endsWith } from './string/endsWith.ts';
|
||||
|
74
src/compat/string/endsWith.spec.ts
Normal file
74
src/compat/string/endsWith.spec.ts
Normal file
@ -0,0 +1,74 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { endsWith } from './endsWith';
|
||||
|
||||
describe('endsWith', () => {
|
||||
it('should return true if the string ends with the target string', async () => {
|
||||
expect(endsWith('fooBar', 'Bar')).toEqual(true);
|
||||
});
|
||||
|
||||
it('should return false if the string does not end with the target string', async () => {
|
||||
expect(endsWith('fooBar', 'abc')).toEqual(false);
|
||||
});
|
||||
|
||||
it('should return false if the string does not end with the target string, but does contain it', async () => {
|
||||
expect(endsWith('fooBar', 'foo')).toEqual(false);
|
||||
});
|
||||
|
||||
it('should return true if the target string is an empty string', async () => {
|
||||
expect(endsWith('fooBar', '')).toEqual(true);
|
||||
});
|
||||
|
||||
it('should return true if the string and target string are empty strings', async () => {
|
||||
expect(endsWith('', '')).toEqual(true);
|
||||
});
|
||||
|
||||
it('should return false if the string past the provided position does not end with the target string', async () => {
|
||||
expect(endsWith('fooBar', 'foo', 5)).toEqual(false);
|
||||
});
|
||||
|
||||
it('should return true if the string before the provided position ends with the target string', async () => {
|
||||
expect(endsWith('fooBar123', 'foo', 3)).toEqual(true);
|
||||
});
|
||||
|
||||
const string = 'abc';
|
||||
|
||||
it('should return `true` if a string ends with `target`', () => {
|
||||
expect(endsWith(string, 'c')).toBe(true);
|
||||
});
|
||||
|
||||
it('should return `false` if a string does not end with `target`', () => {
|
||||
expect(endsWith(string, 'b')).toBe(false);
|
||||
});
|
||||
|
||||
it('should work with a `position`', () => {
|
||||
expect(endsWith(string, 'b', 2)).toBe(true);
|
||||
});
|
||||
|
||||
it('should work with `position` >= `length`', () => {
|
||||
expect(endsWith(string, 'c', 3)).toBe(true);
|
||||
expect(endsWith(string, 'c', 5)).toBe(true);
|
||||
expect(endsWith(string, 'c', Number.MAX_SAFE_INTEGER)).toBe(true);
|
||||
expect(endsWith(string, 'c', Infinity)).toBe(true);
|
||||
});
|
||||
|
||||
it('should treat a negative `position` as `0`', () => {
|
||||
expect(endsWith(string, string[0], -1)).toBe(false);
|
||||
expect(endsWith(string, string[1], -1)).toBe(false);
|
||||
expect(endsWith(string, string[2], -1)).toBe(false);
|
||||
expect(endsWith(string, '', -1)).toBe(true);
|
||||
|
||||
expect(endsWith(string, string[0], -3)).toBe(false);
|
||||
expect(endsWith(string, string[1], -3)).toBe(false);
|
||||
expect(endsWith(string, string[2], -3)).toBe(false);
|
||||
expect(endsWith(string, '', -3)).toBe(true);
|
||||
|
||||
expect(endsWith(string, string[0], -Infinity)).toBe(false);
|
||||
expect(endsWith(string, string[1], -Infinity)).toBe(false);
|
||||
expect(endsWith(string, string[2], -Infinity)).toBe(false);
|
||||
expect(endsWith(string, '', -Infinity)).toBe(true);
|
||||
});
|
||||
|
||||
it('should coerce `position` to an integer', () => {
|
||||
expect(endsWith(string, 'ab', 2.2)).toBe(true);
|
||||
});
|
||||
});
|
@ -5,22 +5,64 @@ describe('startsWith', () => {
|
||||
it('should return true if the string starts with the target string', async () => {
|
||||
expect(startsWith('fooBar', 'foo')).toEqual(true);
|
||||
});
|
||||
|
||||
it('should return false if the string does not start with the target string', async () => {
|
||||
expect(startsWith('fooBar', 'abc')).toEqual(false);
|
||||
});
|
||||
|
||||
it('should return false if the string does not start with the target string, but does contain it', async () => {
|
||||
expect(startsWith('fooBar', 'Bar')).toEqual(false);
|
||||
});
|
||||
|
||||
it('should return true if the target string is an empty string', async () => {
|
||||
expect(startsWith('fooBar', '')).toEqual(true);
|
||||
});
|
||||
|
||||
it('should return true if the string and target string are empty strings', async () => {
|
||||
expect(startsWith('', '')).toEqual(true);
|
||||
});
|
||||
|
||||
it('should return false if the string past the provided position does not start with the target string', async () => {
|
||||
expect(startsWith('fooBar', 'Bar', 5)).toEqual(false);
|
||||
});
|
||||
|
||||
it('should return true if the string past the provided position does start with the target string', async () => {
|
||||
expect(startsWith('fooBar', 'Bar', 3)).toEqual(true);
|
||||
});
|
||||
|
||||
const string = 'abc';
|
||||
|
||||
it('should return `true` if a string starts with `target`', () => {
|
||||
expect(startsWith(string, 'a')).toBe(true);
|
||||
});
|
||||
|
||||
it('should return `false` if a string does not start with `target`', () => {
|
||||
expect(startsWith(string, 'b')).toBe(false);
|
||||
});
|
||||
|
||||
it('should work with a `position`', () => {
|
||||
expect(startsWith(string, 'b', 1)).toBe(true);
|
||||
});
|
||||
|
||||
it('should work with `position` >= `length`', () => {
|
||||
expect(startsWith(string, 'a', 3)).toBe(false);
|
||||
expect(startsWith(string, 'a', 5)).toBe(false);
|
||||
expect(startsWith(string, 'a', Number.MAX_SAFE_INTEGER)).toBe(false);
|
||||
expect(startsWith(string, 'a', Infinity)).toBe(false);
|
||||
});
|
||||
|
||||
it('should treat a negative `position` as `0`', () => {
|
||||
expect(startsWith(string, 'a', -1)).toBe(true);
|
||||
expect(startsWith(string, 'b', -1)).toBe(false);
|
||||
|
||||
expect(startsWith(string, 'a', -3)).toBe(true);
|
||||
expect(startsWith(string, 'b', -3)).toBe(false);
|
||||
|
||||
expect(startsWith(string, 'a', -Infinity)).toBe(true);
|
||||
expect(startsWith(string, 'b', -Infinity)).toBe(false);
|
||||
});
|
||||
|
||||
it('should coerce `position` to an integer', () => {
|
||||
expect(startsWith(string, 'bc', 1.2)).toBe(true);
|
||||
});
|
||||
});
|
@ -1,26 +0,0 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { endsWith } from './endsWith';
|
||||
|
||||
describe('endsWith', () => {
|
||||
it('should return true if the string ends with the target string', async () => {
|
||||
expect(endsWith('fooBar', 'Bar')).toEqual(true);
|
||||
});
|
||||
it('should return false if the string does not end with the target string', async () => {
|
||||
expect(endsWith('fooBar', 'abc')).toEqual(false);
|
||||
});
|
||||
it('should return false if the string does not end with the target string, but does contain it', async () => {
|
||||
expect(endsWith('fooBar', 'foo')).toEqual(false);
|
||||
});
|
||||
it('should return true if the target string is an empty string', async () => {
|
||||
expect(endsWith('fooBar', '')).toEqual(true);
|
||||
});
|
||||
it('should return true if the string and target string are empty strings', async () => {
|
||||
expect(endsWith('', '')).toEqual(true);
|
||||
});
|
||||
it('should return false if the string past the provided position does not end with the target string', async () => {
|
||||
expect(endsWith('fooBar', 'foo', 5)).toEqual(false);
|
||||
});
|
||||
it('should return true if the string before the provided position ends with the target string', async () => {
|
||||
expect(endsWith('fooBar123', 'foo', 3)).toEqual(true);
|
||||
});
|
||||
});
|
@ -3,6 +3,4 @@ export { snakeCase } from './snakeCase.ts';
|
||||
export { kebabCase } from './kebabCase.ts';
|
||||
export { lowerCase } from './lowerCase.ts';
|
||||
export { startCase } from './startCase.ts';
|
||||
export { startsWith } from './startsWith.ts';
|
||||
export { endsWith } from './endsWith.ts';
|
||||
export { capitalize } from './capitalize.ts';
|
||||
|
Loading…
Reference in New Issue
Block a user