Skip to content

Commit

Permalink
Merge branch 'main' into leading-option-for-debounce
Browse files Browse the repository at this point in the history
  • Loading branch information
crishoj authored Aug 11, 2024
2 parents 718ded5 + f7e06ac commit d9aa0bf
Show file tree
Hide file tree
Showing 70 changed files with 5,511 additions and 662 deletions.
3 changes: 2 additions & 1 deletion .cliffignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
9e4933d7382649f3c3aba8e3ab3eac3d1bb9c735
069c986ac3649b060d926ec5f8447f0ac6f568b2
069c986ac3649b060d926ec5f8447f0ac6f568b2
24307efdb7a84fa0b17df1b71d1d19bbc681eb25
25 changes: 25 additions & 0 deletions .devcontainer/devcontainer.json
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"
]
}
}
}
6 changes: 0 additions & 6 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,3 @@ Yes
No

<!-- If yes, describe the impact and migration path for existing applications. -->

## Bundle impact

<!-- This is calculated in Github Actions. -->

_Calculating..._
34 changes: 34 additions & 0 deletions .github/workflows/bundle-impact.yml
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 })
29 changes: 0 additions & 29 deletions .github/workflows/check-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/publish-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ jobs:
[Your preview release is being published.](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) :hourglass:
token: ${{ secrets.GITHUB_TOKEN }}

- uses: xt0rted/pull-request-comment-branch@v2
- uses: radashi-org/pull-request-comment-branch@v2
id: comment-branch

- uses: actions/checkout@v4
if: success()
with:
ref: ${{ steps.comment-branch.outputs.head_ref }}
repository: ${{ steps.comment-branch.outputs.head_owner }}/${{ steps.comment-branch.outputs.head_repo }}

- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/register-pr.yml
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)
24 changes: 24 additions & 0 deletions .github/workflows/test-pr.yml
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
4 changes: 2 additions & 2 deletions .vscode/extensions.json
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"
]
}
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add reverse argument to `castComparator` by [@aleclarson](https://github.com/aleclarson) in [1d7937e](https://github.com/radashi-org/radashi/commit/1d7937ef006139883aedac782ad032c1d6269c7a)
- Add `isBoolean` function by [@aleclarson](https://github.com/aleclarson) in [adc419d](https://github.com/radashi-org/radashi/commit/adc419d5bbb1786d75619ed3d7f41a45f68c9857)
- Add `noop` and `always` functions by [@aleclarson](https://github.com/aleclarson) in [eb77c8f](https://github.com/radashi-org/radashi/commit/eb77c8f004a35f1499968f6e40d01b3595384848)
- Add `similarity` function by [@aleclarson](https://github.com/aleclarson) in [#122](https://github.com/radashi-org/radashi/pull/122)

- **(throttle)** Add `trailing` option by [@crishoj](https://github.com/crishoj) in [#127](https://github.com/radashi-org/radashi/pull/127)

- **(throttle)** Add `trigger` method to ThrottleFunction by [@aleclarson](https://github.com/aleclarson) in [#135](https://github.com/radashi-org/radashi/pull/135)


#### <!-- 05 -->Changed
- **(intersects)** Let `identity` callback return any value by [@aleclarson](https://github.com/aleclarson) in [#11](https://github.com/radashi-org/radashi/pull/11)
Expand Down Expand Up @@ -120,8 +126,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Improve the return type of `filterKey` by [@aleclarson](https://github.com/aleclarson) in [bc298c6](https://github.com/radashi-org/radashi/commit/bc298c6cfcaaf74726e1f2b901e210dea1fed641)
- Handle tuples in `isArray` return type by [@aleclarson](https://github.com/aleclarson) in [9257535](https://github.com/radashi-org/radashi/commit/925753578761bda277838bf8fbbcc24b3813f2b9)
- Make `select` more option-friendly by [@aleclarson](https://github.com/aleclarson) in [c9cfcd0](https://github.com/radashi-org/radashi/commit/c9cfcd0a7eb1af98682f5d9b56555162c92b7085)
- Let `shift` accept a readonly array type by [@nnmrts](https://github.com/nnmrts) in [#126](https://github.com/radashi-org/radashi/pull/126)

- Remove type constraint for mapped array passed to `sum` by [@MarlonPassos-git](https://github.com/MarlonPassos-git) in [dea0f50](https://github.com/radashi-org/radashi/commit/dea0f504f417b23aaf2b91495943501c894a172a)

### New Contributors
* [@crishoj](https://github.com/crishoj) made their first contribution in [#127](https://github.com/radashi-org/radashi/pull/127)
* [@nnmrts](https://github.com/nnmrts) made their first contribution in [#126](https://github.com/radashi-org/radashi/pull/126)
* [@stefaanv](https://github.com/stefaanv) made their first contribution in [#95](https://github.com/radashi-org/radashi/pull/95)
* [@eumkz](https://github.com/eumkz) made their first contribution in [#76](https://github.com/radashi-org/radashi/pull/76)
* [@cimbraien](https://github.com/cimbraien) made their first contribution in [#58](https://github.com/radashi-org/radashi/pull/58)
Expand Down
11 changes: 11 additions & 0 deletions benchmarks/string/similarity.bench.ts
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)
})
})
2 changes: 0 additions & 2 deletions docs/array/list.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ _.list(0, 6, i => i, 2) // [0, 2, 4, 6]

## Signatures

The list function can do a lot with different arguments.

### list(size)

When givin a single argument, it's treated as the `size`. Returns a list with values from 0 to `size`.
Expand Down
66 changes: 41 additions & 25 deletions docs/array/selectFirst.mdx
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
```
4 changes: 2 additions & 2 deletions docs/async/all.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The `all` function is similar to the builtin Promise.all or Promise.allSettled
functions. Given a list (or object) of promises, if any errors are thrown, all
errors are gathered and thrown in an AggregateError.

## Using an Array
### Using an Array

Passing an array as an argument will return the resolved promise values as an array in the same order.

Expand All @@ -21,7 +21,7 @@ const [user] = await _.all([
])
```

## Using an Object
### Using an Object

Passing an object as an argument will return an object with the same keys and the values as the resolved promise values.

Expand Down
2 changes: 1 addition & 1 deletion docs/async/parallel.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const users = await _.parallel(3, userIds, async userId => {
})
```

## Errors
### Errors

When all work is complete parallel will check for errors. If any
occurred they will all be thrown in a single `AggregateError` that
Expand Down
2 changes: 1 addition & 1 deletion docs/curry/debounce.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const makeSearchRequest = event => {
input.addEventListener('change', _.debounce({ delay: 100 }, makeSearchRequest))
```

## Timing
### Timing

A visual of the debounce behavior when `delay` is `100`. The debounce function
returned by `debounce` can be called every millisecond but it will only call
Expand Down
4 changes: 2 additions & 2 deletions docs/curry/memo.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const later = timestamp()
now === later // => true
```

## Expiration
### Expiration

You can optionally pass a `ttl` (time to live) that will expire memoized results. In versions prior to version 10, `ttl` had a value of 300 milliseconds if not specified.

Expand All @@ -40,7 +40,7 @@ now === later // => true
now === muchLater // => false
```

## Key Function
### Key Function

You can optionally customize how values are stored when memoized.

Expand Down
2 changes: 1 addition & 1 deletion docs/curry/once.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn() // 0.5
fn() // 0.5
```

## Resetting the function
### Resetting the function

The `once.reset` function clears the stored result of a function that was previously wrapped with `once`. This allows the function to be executed again as if it were never called before, enabling dynamic reuse of the function with fresh computations.

Expand Down
Loading

0 comments on commit d9aa0bf

Please sign in to comment.