style: Fix style

This commit is contained in:
raon0211 2024-10-14 15:36:07 +09:00
parent 2dc88361a8
commit 610f479593
7 changed files with 182 additions and 1 deletions

View File

@ -120,7 +120,7 @@ function toDocumentationItems(docs: DocNode[]): DocumentationItems {
})
.map(([name, entries]) => {
const sourcePath = fileURLToPath(entries[0].location.filename);
const docPath: string = path.relative(basePath, sourcePath).replace(/.ts$/g, '.md');
const docPath: string = path.join(path.dirname(path.relative(basePath, sourcePath)), `${name}.md`);
return {
docPath: docPath,

View File

@ -0,0 +1,34 @@
# first
::: info
この関数は互換性のために `es-toolkit/compat` からのみインポートできます。代替可能なネイティブ JavaScript API があるか、まだ十分に最適化されていないためです。
`es-toolkit/compat` からこの関数をインポートすると、[lodash と完全に同じように動作](../../../compatibility.md)します。
:::
配列の最初の要素を返します。配列が空の場合は`undefined`を返します。
この関数は配列を受け取り、配列の最初の要素を返します。
配列が空の場合、関数は`undefined`を返します。
## インターフェース
```typescript
function first<T>(arr: ArrayLike<T> | undefined | null): T | undefined;
```
### パラメータ
- `arr` (`ArrayLike<T> | undefined | null`): 最初の要素を取得するための配列です。
### 戻り値
(`T | undefined`): 配列の最初の要素、または配列が空の場合は`undefined`です。
## 例
```typescript
const emptyArr: number[] = [];
const noElement = head(emptyArr);
// noElement will be undefined
```

View File

@ -0,0 +1,49 @@
# first
::: info
이 함수는 호환성을 위한 `es-toolkit/compat` 에서만 가져올 수 있어요. 대체할 수 있는 네이티브 JavaScript API가 있거나, 아직 충분히 최적화되지 않았기 때문이에요.
`es-toolkit/compat`에서 이 함수를 가져오면, [lodash와 완전히 똑같이 동작](../../../compatibility.md)해요.
:::
배열의 첫 번째 요소를 반환해요.
이 함수는 배열을 입력받아 배열의 첫 번째 요소를 반환해요. 배열이 비어 있는 경우, 함수는 `undefined`를 반환해요.
## 인터페이스
```typescript
function first<T>(arr: ArrayLike<T> | undefined | null): T | undefined;
```
### 파라미터
- `arr` (`T[]`): 첫 번째 요소를 가져올 배열.
### 반환 값
(`T | undefined`): 배열의 첫 번째 요소, 배열이 비어 있는 경우 `undefined`.
## 예시
```typescript
const arr1 = [1, 2, 3];
const firstElement1 = first(arr1);
// firstElement1은 1이에요.
const arr2: string[] = [];
const firstElement2 = first(arr2);
// firstElement2는 undefined에요.
const arr3 = ['a', 'b', 'c'];
const firstElement3 = first(arr3);
// firstElement3는 'a'이에요.
const arr4 = [true, false, true];
const firstElement4 = first(arr4);
// firstElement4는 true에요.
const arr5: [number, string, boolean] = [1, 'a', true];
const firstElement5 = first(arr5);
// firstElement5는 1이에요.
```

View File

@ -0,0 +1,34 @@
# first
::: info
This function is only available in `es-toolkit/compat` for compatibility reasons. It either has alternative native JavaScript APIs or isnt fully optimized yet.
When imported from `es-toolkit/compat`, it behaves exactly like lodash and provides the same functionalities, as detailed [here](../../../compatibility.md).
:::
Returns the first element of an array or `undefined` if the array is empty.
This function takes an array and returns the first element of the array.
If the array is empty, the function returns `undefined`.
## Signature
```typescript
function first<T>(arr: ArrayLike<T> | undefined | null): T | undefined;
```
### Parameters
- `arr` (`ArrayLike<T> | undefined | null`): The array from which to get the first element.
### Returns
(`T | undefined`): The first element of the array, or `undefined` if the array is empty.
## Examples
```typescript
const emptyArr: number[] = [];
const noElement = head(emptyArr);
// noElement will be undefined
```

View File

@ -0,0 +1,34 @@
# first
::: info
出于兼容性原因,此函数仅在 `es-toolkit/compat` 中提供。它可能具有替代的原生 JavaScript API或者尚未完全优化。
`es-toolkit/compat` 导入时,它的行为与 lodash 完全一致,并提供相同的功能,详情请见 [这里](../../../compatibility.md)。
:::
返回数组的第一个元素,如果数组为空,则返回`undefined`。
此函数接受一个数组并返回数组的第一个元素。
如果数组为空,函数将返回`undefined`。
## 签名
```typescript
function first<T>(arr: ArrayLike<T> | undefined | null): T | undefined;
```
### 参数
- `arr` (`ArrayLike<T> | undefined | null`): 获取第一个元素的数组。
### 返回值
(`T | undefined`): 数组的第一个元素,如果数组为空,则为`undefined`。
## 示例
```typescript
const emptyArr: number[] = [];
const noElement = head(emptyArr);
// noElement will be undefined
```

View File

@ -2,6 +2,23 @@ import { intersection as intersectionToolkit } from '../../array/intersection.ts
import { uniq } from '../../array/uniq.ts';
import { isArrayLikeObject } from '../predicate/isArrayLikeObject.ts';
/**
* Returns the intersection of multiple arrays.
*
* This function takes multiple arrays and returns a new array containing the elements that are
* present in all provided arrays. It effectively filters out any elements that are not found
* in every array.
*
* @template T - The type of elements in the arrays.
* @param {...(ArrayLike<T> | null | undefined)} arrays - The arrays to compare.
* @returns {T[]} A new array containing the elements that are present in all arrays.
*
* @example
* const array1 = [1, 2, 3, 4, 5];
* const array2 = [3, 4, 5, 6, 7];
* const result = intersection(array1, array2);
* // result will be [3, 4, 5] since these elements are in both arrays.
*/
export function intersection<T>(...arrays: Array<ArrayLike<T> | null | undefined>): T[] {
if (arrays.length === 0) {
return [];

View File

@ -1,6 +1,19 @@
import { escape as escapeToolkit } from '../../string/escape.ts';
import { toString } from '../util/toString.ts';
/**
* Converts the characters "&", "<", ">", '"', and "'" in `str` to their corresponding HTML entities.
* For example, "<" becomes "&lt;".
*
* @param {string} str The string to escape.
* @returns {string} Returns the escaped string.
*
* @example
* escape('This is a <div> element.'); // returns 'This is a &lt;div&gt; element.'
* escape('This is a "quote"'); // returns 'This is a &quot;quote&quot;'
* escape("This is a 'quote'"); // returns 'This is a &#39;quote&#39;'
* escape('This is a & symbol'); // returns 'This is a &amp; symbol'
*/
export function escape(string?: string): string {
return escapeToolkit(toString(string));
}