Skip to content

Commit

Permalink
feat: upgrade h3-defu
Browse files Browse the repository at this point in the history
  • Loading branch information
cpreston321 committed Jan 11, 2024
1 parent e152481 commit f8d6186
Show file tree
Hide file tree
Showing 15 changed files with 3,189 additions and 3,643 deletions.
15 changes: 0 additions & 15 deletions .editorconfig

This file was deleted.

2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

5 changes: 0 additions & 5 deletions .eslintrc

This file was deleted.

4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
updates:
# Fetch and update latest `npm` packages
- package-ecosystem: npm
directory: '/'
directory: /
schedule:
interval: weekly
time: '00:00'
Expand All @@ -18,7 +18,7 @@ updates:

# Fetch and update latest `github-actions` pkgs
- package-ecosystem: github-actions
directory: '/'
directory: /
schedule:
interval: daily
time: '00:00'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jobs:
- run: corepack enable
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 20
registry-url: 'https://registry.npmjs.org'
cache: "pnpm"
cache: pnpm
- run: pnpm install
- run: pnpm lint
- run: pnpm test:coverage
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
shamefully-hoist=true
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[![Codecov][codecov-src]][codecov-href]

> JSON Defaults for [h3](https://github.com/unjs/h3), using [defu](https://github.com/unjs/defu) under the hood.
## Install

```sh
Expand All @@ -22,33 +23,39 @@ pnpm install h3-defu
## Usage

```js
import { createApp } from 'h3'
import { createServer } from 'http'
import { readBodyWithDefaults, getQueryWithDefaults } from 'h3-defu'
// or
// if this way is more familiar to you until the convention is full deprecated
import { useBodyWithDefaults, useQueryWithDefaults } from 'h3-defu'
import { createServer } from 'node:http'
import { createApp, eventHandler, toNodeListener } from 'h3'
import { getQueryWithDefaults, readBodyWithDefaults } from 'h3-defu'

const app = createApp()

app.use('/', async (event) => {
app.use('/api/test', eventHandler(async (event) => {
// Default body
// example BODY: { show: false }
// expected: { show: false, name: 'Anonymous' }
const body = await readBodyWithDefaults(event, {
show: true,
name: "Anonymous"
name: 'Anonymous'
})

// Default query
// example: /api/test?page=2
// expected: { page: 1, limit: 10 }
const query = getQueryWithDefaults(event, {
page: 1,
limit: 10
})
})

createServer(app).listen(process.env.PORT || 3000)
return {
body,
query
}
}))

createServer(toNodeListener(app)).listen(process.env.PORT || 3000)
```

## Development 💻
## Development 💻

- Clone this repository
- Install dependencies using `pnpm install`
Expand Down
3 changes: 3 additions & 0 deletions eslint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import antfu from '@antfu/eslint-config'

export default antfu()
28 changes: 19 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "h3-defu",
"type": "module",
"version": "0.1.4",
"packageManager": "pnpm@8.14.1",
"description": "A simple utility to deep merge objects that extends h3 body and query parameters passed.",
"repository": "cpreston321/h3-defu",
"license": "MIT",
"type": "module",
"repository": "cpreston321/h3-defu",
"exports": {
".": {
"import": "./dist/index.mjs",
Expand All @@ -20,27 +21,36 @@
"scripts": {
"build": "unbuild",
"dev": "vitest dev",
"lint": "eslint --ext .ts,.js,.mjs,.cjs .",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"prepack": "unbuild",
"release": "pnpm test && standard-version && git push --follow-tags && pnpm publish",
"test": "vitest run",
"test:coverage": "pnpm test -- --reporter verbose --coverage"
},
"dependencies": {
"defu": "^6.1.0",
"h3": "^0.7.21"
"defu": "^6.1.4",
"h3": "^1.10.0"
},
"devDependencies": {
"@nuxtjs/eslint-config-typescript": "latest",
"@antfu/eslint-config": "^2.6.2",
"@types/supertest": "latest",
"@vitest/coverage-c8": "^0.24.0",
"@vitest/coverage-c8": "^0.33.0",
"c8": "latest",
"eslint": "latest",
"eslint": "npm:eslint-ts-patch@8.56.0-0",
"eslint-ts-patch": "8.56.0-0",
"lint-staged": "^15.2.0",
"simple-git-hooks": "^2.9.0",
"standard-version": "latest",
"supertest": "latest",
"typescript": "latest",
"unbuild": "latest",
"vitest": "latest"
},
"packageManager": "pnpm@7.12.1"
"simple-git-hooks": {
"pre-commit": "pnpm lint-staged"
},
"lint-staged": {
"*": "eslint --fix"
}
}
Loading

0 comments on commit f8d6186

Please sign in to comment.