GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — obsidian-ext/packages/jcast-util-to-json at main · MoritzRS/obsidian-ext

Expand file tree

/

jcast-util-to-json

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
/

jcast-util-to-json

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
src
src
 
 
test
test
 
 
LICENSE.md
LICENSE.md
 
 
README.md
README.md
 
 
package.json
package.json
 
 
tsconfig.json
tsconfig.json
 
 
vitest.config.ts
vitest.config.ts
 
 

README.md

Outline

jcast-util-to-json

Build NPM Version NPM Bundle Size NPM Downloads GitHub License

jcast utility to parse jcast syntax tree back into JSON Canvas.

What is this?

This package contains a utility to parse a jcast syntax tree back into a JSON Canvas string. The resulting string can be written to a file and used directly in Obsidian.md.

When to use this

You can use this utility when you want to serialize a modified jcast syntax tree back to jsoncanvas.

If you just want to parse JSON Canvas into a type-safe object, use jsoncanvas instead.

Install

This package is ESM only. In Node.js (version 18+), install with npm:

npm install @moritzrs/jcast-util-to-json

Use

import { readFileSync, writeFileSync } from "fs";
import { visit } from "unist-util-visit";
import { fromJson } from "@moritzrs/jcast-util-from-json";
import { toJson } from "@moritzrs/jcast-util-to-json";

const json = readFileSync("Untitled.canvas", "utf-8");
const tree = fromJson(json);

// Rename all groups numerically
let counter = 0;
visit(tree, "group", (group) => {
	counter += 1;
	group.value = `Group ${counter}`;
});

const modified = toJson(tree);
writeFileSync("Untitled.canvas", modified);

API

This package exports only the identifier toJson. There is no default export.

toJson(tree: Root): string

Parse a jcast syntax tree back into a JSON Canvas string. Due to jcast having a different understanding of groups, it recalculates the geometry of group nodes.

Parameters
  • tree: Root - JCAST syntax tree representing the JSON Canvas.
Returns

Serialized JSON Canvas string.

Types

This package utilized the types from the jcast package.

Related

  • jcast - JSON Canvas syntax tree
  • jcast-util-from-json - JSON Canvas parser
  • jsoncanvas - JSON Canvas parser

Contribute

I don't know if i can check PRs in a timely manner, but feel free to open PRs or issues. If participation is high I will need to add a code of conduct and contribution guidelines.

Disclaimer

This package is not affiliated with Obsidian.md or the developers of Obsidian.md.

License

MIT © Moritz R. Schulz

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.