-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into leading-option-for-debounce
- Loading branch information
Showing
70 changed files
with
5,511 additions
and
662 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
9e4933d7382649f3c3aba8e3ab3eac3d1bb9c735 | ||
069c986ac3649b060d926ec5f8447f0ac6f568b2 | ||
069c986ac3649b060d926ec5f8447f0ac6f568b2 | ||
24307efdb7a84fa0b17df1b71d1d19bbc681eb25 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the | ||
// README at: https://github.com/devcontainers/templates/tree/main/src/typescript-node | ||
{ | ||
"name": "Radashi", | ||
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile | ||
"image": "mcr.microsoft.com/devcontainers/typescript-node:1-20-bookworm", | ||
|
||
// Features to add to the dev container. More info: https://containers.dev/features. | ||
"features": { | ||
"ghcr.io/devcontainers-contrib/features/pnpm": { | ||
"version": "9.1.3" | ||
}, | ||
"ghcr.io/joshuanianji/devcontainer-features/mount-pnpm-store": {} | ||
}, | ||
"postCreateCommand": "pnpm i", | ||
"customizations": { | ||
"vscode": { | ||
"extensions": [ | ||
"vitest.explorer", | ||
"biomejs.biome", | ||
"esbenp.prettier-vscode" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Bundle Impact | ||
|
||
on: | ||
pull_request_target: | ||
branches: [main, next] | ||
types: [opened, synchronize] | ||
|
||
jobs: | ||
bundle-impact: | ||
name: Calculate Bundle Impact | ||
runs-on: ubuntu-latest | ||
permissions: | ||
pull-requests: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: pnpm/action-setup@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: '22.x' | ||
cache: pnpm | ||
|
||
- run: | | ||
pnpm install -C scripts/bundle-impact | ||
- name: Run Bundle Impact | ||
uses: actions/github-script@v7 | ||
env: | ||
TARGET_BRANCH: ${{ github.base_ref }} | ||
NODE_OPTIONS: '--import ./scripts/bundle-impact/node_modules/tsx/dist/esm/index.mjs' | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const script = await import('${{ github.workspace }}/scripts/bundle-impact/pr-bundle-impact.ts') | ||
await script.run({ github, core, context }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,23 +6,6 @@ on: | |
types: [opened, synchronize, reopened, edited] | ||
|
||
jobs: | ||
test: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [18.x, 20.x, 22.x] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: pnpm/action-setup@v4 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: pnpm | ||
- run: pnpm install | ||
- run: pnpm test | ||
|
||
validate: | ||
name: Validate | ||
runs-on: ubuntu-latest | ||
|
@@ -40,18 +23,6 @@ jobs: | |
- run: pnpm install | ||
- run: pnpm install @commitlint/[email protected] | ||
|
||
- name: Refresh Bundle Impact | ||
uses: actions/github-script@v6 | ||
if: ${{ github.head_ref != 'next' }} | ||
continue-on-error: true | ||
env: | ||
TARGET_BRANCH: ${{ github.event.pull_request.base.ref }} | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const { run } = require('./scripts/pr-bundle-impact.cjs'); | ||
run({ github, core, context }); | ||
- name: Lint | ||
run: pnpm lint | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Register PR In Database | ||
|
||
on: | ||
pull_request_target: | ||
branches: [main] | ||
types: [opened, reopened, synchronize, closed] | ||
|
||
jobs: | ||
register-pr: | ||
runs-on: ubuntu-latest | ||
continue-on-error: true | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: pnpm/action-setup@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
cache: pnpm | ||
- uses: actions/github-script@v6 | ||
env: | ||
ALGOLIA_KEY: ${{ secrets.ALGOLIA_KEY }} | ||
SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }} | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const script = await import('${{ github.workspace }}/scripts/radashi-db/ci-register-pr.ts') | ||
await script.run(context, github, console) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Test Pull Request | ||
|
||
on: | ||
pull_request: | ||
branches: [main, next] | ||
types: [opened, synchronize] | ||
|
||
jobs: | ||
test: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [18.x, 20.x, 22.x] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: pnpm/action-setup@v4 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: pnpm | ||
- run: pnpm install | ||
- run: pnpm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"recommendations": [ | ||
"vitest.explorer", | ||
"rohit-gohri.format-code-action", | ||
"biomejs.biome" | ||
"biomejs.biome", | ||
"esbenp.prettier-vscode" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import * as _ from 'radashi' | ||
import { bench } from 'vitest' | ||
|
||
describe('similarity', () => { | ||
const string1 = 'h'.repeat(100) | ||
const string2 = 'ha'.repeat(50) | ||
|
||
bench('with 50% similar characters', () => { | ||
_.similarity(string1, string2) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,53 @@ | ||
--- | ||
title: selectFirst | ||
description: Array find + map | ||
description: Find and map the first array element meeting a condition | ||
--- | ||
|
||
### Usage | ||
|
||
Returns the mapped value for the first element that satisfies the specified condition--else undefined. | ||
If the filter is omitted, returns the first non-nullish mapped value. | ||
The `selectFirst` function combines the functionality of `find` and `map` operations on an array. It iterates through the array, applying a mapper function to each element, and returns the first mapped value that satisfies a given condition. If no condition is provided, it returns the first non-nullish mapped value. | ||
|
||
```ts | ||
This function is particularly useful when you need to find and transform an element in a single operation, potentially saving time and improving code readability. | ||
|
||
**Key features:** | ||
|
||
- Short-circuits on the first element that satisfies the condition | ||
- Allows for separate mapping and condition functions | ||
- Returns `undefined` if no element satisfies the condition or if the array is empty/nullish | ||
|
||
```typescript | ||
import * as _ from 'radashi' | ||
|
||
const fish = [ | ||
{ | ||
name: 'Marlin', | ||
weight: 105, | ||
source: 'ocean', | ||
}, | ||
{ | ||
name: 'Bass', | ||
weight: 8, | ||
source: 'lake', | ||
}, | ||
{ | ||
name: 'Trout', | ||
weight: 13, | ||
source: 'lake', | ||
}, | ||
] | ||
// Find the first even number and double it | ||
_.selectFirst( | ||
[1, 3, 4, 6, 8], | ||
x => x * 2, | ||
x => x % 2 === 0, | ||
) | ||
// => 8 | ||
|
||
// Find the first non-empty string and convert to uppercase | ||
_.selectFirst( | ||
fish, | ||
f => f.weight, | ||
f => f.source === 'lake', | ||
) // => 8 | ||
['', null, 'hello', 'world'], | ||
s => s?.toUpperCase(), | ||
s => s !== null && s !== '', | ||
) | ||
// => 'HELLO' | ||
|
||
// Find the first object with a specific property and extract a value | ||
const users = [ | ||
{ id: 1, name: 'Alice', age: 30 }, | ||
{ id: 2, name: 'Bob', age: 25 }, | ||
{ id: 3, name: 'Charlie', age: 35 }, | ||
] | ||
_.selectFirst( | ||
users, | ||
user => user.name, | ||
user => user.age > 30, | ||
) | ||
// => 'Charlie' | ||
|
||
// Using default condition (non-nullish) | ||
_.selectFirst([null, undefined, 0, '', false, 'found'], x => x) | ||
// => 0 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.