Skip to content

Commit

Permalink
feat: add document (#123)
Browse files Browse the repository at this point in the history
* docs: add document

* misc: format codes

* misc: add action to publish document

* fix: tscheck

* fix: type errors

* fix: actions
  • Loading branch information
mew-ton authored Feb 5, 2024
1 parent 7d5cdbb commit a4c3b07
Show file tree
Hide file tree
Showing 23 changed files with 5,745 additions and 482 deletions.
2 changes: 1 addition & 1 deletion .github/actions/init-node/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ runs:
- uses: actions/setup-node@v4
with:
cache: yarn
node-version: 18
node-version: 20

- name: cache node_modules
id: cache_node_modules
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/document.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
name: Deploy Document to GitHub Pages

on:
push:
tags:
- "**"
workflow_dispatch:

permissions:
contents: read
pages: write
id-token: write

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install, build, and upload your site
uses: withastro/action@v1
with:
path: ./docs
node-version: 20

deploy:
needs: build
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v1
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ jobs:
publish: yarn run changeset publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }}
11 changes: 11 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,14 @@ jobs:

- run: yarn test:type

astro-check:
name: "Test: astro-check"
runs-on: ubuntu-latest
needs:
- init__node
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/init-node

- run: yarn test:doc

2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://biomejs.dev/schemas/1.4.1/schema.json",
"files": {
"ignore": ["node_modules", "coverage"]
"ignore": ["node_modules", "coverage", ".astro", ".yarn"]
},
"organizeImports": {
"enabled": true
Expand Down
1 change: 1 addition & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.astro
35 changes: 35 additions & 0 deletions docs/astro.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import starlight from '@astrojs/starlight'
import { defineConfig } from 'astro/config'

// biome-ignore lint/style/noDefaultExport: <explanation>
export default defineConfig({
site: 'https://hacomono-lib.github.io',
base: '/json-origami',
integrations: [
starlight({
title: 'json-origami',
social: {
github: 'https://github.com/hacomono-lib/json-origami',
},
sidebar: [
{
label: 'Home',
link: '/',
},
{
label: 'Introduction',
collapsed: false,
items: [
{ label: 'Getting Started', link: '/guides/start' },
{ label: 'Concepts', link: '/guides/concepts' },
],
},
{
label: 'Api',
collapsed: false,
autogenerate: { directory: '/api', collapsed: false },
},
],
}),
],
})
1 change: 1 addition & 0 deletions docs/public/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/src/assets/houston.webp
Binary file not shown.
7 changes: 7 additions & 0 deletions docs/src/content/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { docsSchema, i18nSchema } from '@astrojs/starlight/schema'
import { defineCollection } from 'astro:content'

export const collections: Record<string, ReturnType<typeof defineCollection>> = {
docs: defineCollection({ schema: docsSchema() }),
i18n: defineCollection({ type: 'data', schema: i18nSchema() }),
}
76 changes: 76 additions & 0 deletions docs/src/content/docs/api/fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
title: fold
description: fold function converts a JSON object into key-value pair object by folding it.
---

`fold` function converts a JSON object into key-value pair object by folding it.

```ts
fold(object, option?)
```
## Arguments
- ### `object`
type: `object`
The JSON object to fold.
e.g.
`{ a: { b: "c" } }` will be folded to `{ "a.b": "c" }`.
- ### `option`
type: `object`
- #### `arrayIndex`
type: `"dot" | "bracket"`
default: `"bracket"`
The index of array to fold.
e.g.
`{ a: ["b"] }` will be folded to `{ "a[0]": "b" }` if `arrayIndex` is `"bracket"`,
and will be folded to `{ "a.0": "b" }` if `arrayIndex` is `"dot"`.
- #### `keyPrefix`
type: `string`
default: `""`
The prefix to prepend to the folded key.
### Example
```ts
import { fold } from 'json-origami';

const user = {
id: 1,
name: 'John',
age: 20,
address: {
street: '123 Main St',
city: 'New York',
state: 'NY',
zip: '10001',
},
};

const folded = fold(user)
/**
* {
* id: 1,
* name: 'John',
* age: 20,
* 'address.street': '123 Main St',
* 'address.city': 'New York',
* 'address.state': 'NY',
* 'address.zip': '10001',
* }
*/
```
69 changes: 69 additions & 0 deletions docs/src/content/docs/api/omit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
title: omit
description: omit function omits the specified keys from a JSON object.
---

`omit` function omits the specified keys from a JSON object.

```ts
omit(object, keys, option?)
```
## Arguments
- ### `object`
type: `object`
The JSON object to omit keys from.
- ### `keys`
type: `string[]`
The keys to omit.
- ### `option`
type: `object`
- #### `arrayIndex`
type: `"dot" | "bracket"`
default: `"bracket"`
The index of array to omit.
e.g.
`[ "a[0]" ]` will omit to `{ a: ["b"] }` if `arrayIndex` is `"bracket"`,
and `[ "a.0" ]` will omit to `{ a: { 0: "b" } }` if `arrayIndex` is `"dot"`.
### Example
```ts
import { omit } from 'json-origami';

const user = {
id: 1,
name: 'John',
age: 20,
address: {
street: '123 Main St',
city: 'New York',
state: 'NY',
zip: '10001',
},
};

const omitted = omit(user, ['id', 'name', 'address.street', 'address.city']);
/**
* {
* age: 20,
* address: {
* state: 'NY',
* zip: '10001',
* },
* }
*/
```
71 changes: 71 additions & 0 deletions docs/src/content/docs/api/pick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
title: pick
description: pick function picks the specified keys from a JSON object.
---

`pick` function picks the specified keys from a JSON object.

```ts
pick(object, keys, option?)
```
## Arguments
- ### `object`
type: `object`
The JSON object to pick keys from.
- ### `keys`
type: `string[]`
The keys to pick.
- ### `option`
type: `object`
- #### `arrayIndex`
type: `"dot" | "bracket"`
default: `"bracket"`
The index of array to pick.
e.g.
`[ "a[0]" ]` will pick to `{ a: ["b"] }` if `arrayIndex` is `"bracket"`,
and `[ "a.0" ]` will pick to `{ a: { 0: "b" } }` if `arrayIndex` is `"dot"`.
### Example
```ts
import { pick } from 'json-origami';

const user = {
id: 1,
name: 'John',
age: 20,
address: {
street: '123 Main St',
city: 'New York',
state: 'NY',
zip: '10001',
},
};

const picked = pick(user, ['id', 'name', 'address.street', 'address.city']);

/**
* {
* id: 1,
* name: 'John',
* address: {
* street: '123 Main St',
* city: 'New York',
* },
* }
*/
```
Loading

0 comments on commit a4c3b07

Please sign in to comment.