Skip to content

Commit

Permalink
docs: configure for docs only
Browse files Browse the repository at this point in the history
  • Loading branch information
jg-rp committed Sep 18, 2023
1 parent 30b0ccb commit 114a02f
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 80 deletions.
4 changes: 4 additions & 0 deletions docs/docs/intro.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
slug: /
---

import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";

Expand Down
63 changes: 60 additions & 3 deletions docs/docs/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,73 @@ console.log(pointer.to("2/baz/2").resolve(data)); // 6

## JSON Patch

TODO:
Apply a JSON Patch ([RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902)) to some data with `jsonpatch.apply()`. **Data is modified in place.**.

### JSONPatch constructor

TODO:
```javascript
import { jsonpatch } from "json-p3";

const ops = [
{ op: "add", path: "/some/foo", value: { foo: {} } },
{ op: "add", path: "/some/foo", value: { bar: [] } },
{ op: "copy", from: "/some/other", path: "/some/foo/else" },
{ op: "add", path: "/some/foo/bar/-", value: 1 },
];

const data = { some: { other: "thing" } };
jsonpatch.apply(ops, data);
console.log(data);
// { some: { other: 'thing', foo: { bar: [Array], else: 'thing' } } }
```

`apply()` is a convenience function equivalent to `new JSONPatch(ops).apply(data)`. Use the [`JSONPatch`](./api/classes/jsonpatch.JSONPatch.md) constructor when you need to apply the same patch to multiple different data structures.

```javascript
import { JSONPatch } from "json-p3";

const patch = new JSONPatch([
{ op: "add", path: "/some/foo", value: { foo: {} } },
{ op: "add", path: "/some/foo", value: { bar: [] } },
{ op: "copy", from: "/some/other", path: "/some/foo/else" },
{ op: "add", path: "/some/foo/bar/-", value: 1 },
]);

const data = { some: { other: "thing" } };
patch.apply(data);
console.log(data);
// { some: { other: 'thing', foo: { bar: [Array], else: 'thing' } } }
```

`apply()` is also re-exported from JSON P3's top-level namespace.

### Builder API

TODO:
`JSONPatch` objects offer a builder interface for constructing JSON patch documents. We use strings as JSON Pointers in this example, but existing `JSONPointer` objects are OK too.

```javascript
import { JSONPatch } from "json-p3";

const data = { some: { other: "thing" } };

const patch = new JSONPatch()
.add("/some/foo", { foo: [] })
.add("/some/foo", { bar: [] })
.copy("/some/other", "/some/foo/else")
.copy("/some/foo/else", "/some/foo/bar/-");

patch.apply(data);
console.log(JSON.stringify(data, undefined, " "));
```

```json title="output"
{
"some": {
"other": "thing",
"foo": {
"bar": ["thing"],
"else": "thing"
}
}
}
```
8 changes: 3 additions & 5 deletions docs/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,11 @@ const config = {
/** @type {import('@docusaurus/preset-classic').Options} */
({
docs: {
routeBasePath: "/",
sidebarPath: require.resolve("./sidebars.js"),
editUrl: "https://github.com/jg-rp/json-p3/tree/docs",
},
blog: {
showReadingTime: true,
editUrl: "https://github.com/jg-rp/json-3/tree/blog",
},
blog: false,
theme: {
customCss: require.resolve("./src/css/custom.css"),
},
Expand Down Expand Up @@ -82,7 +80,7 @@ const config = {
label: "Docs",
},
{
to: "/docs/api/",
to: "/api/",
label: "API",
position: "left",
},
Expand Down
2 changes: 1 addition & 1 deletion docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const sidebars = {
docsSidebar: [
{
type: "category",
label: "Introduction",
label: "Getting Started",
collapsed: false,
items: ["intro", "quick-start"],
},
Expand Down
41 changes: 0 additions & 41 deletions docs/src/pages/index.js

This file was deleted.

23 changes: 0 additions & 23 deletions docs/src/pages/index.module.css

This file was deleted.

7 changes: 0 additions & 7 deletions docs/src/pages/markdown-page.md

This file was deleted.

0 comments on commit 114a02f

Please sign in to comment.