npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@gitbook/slate-hyperprint

v2.3.0

Published

A Slate plugin to print Slate models to their slate-hyperscript representation.

Downloads

727

Readme

slate-hyperprint

NPM version

A library to convert Slate models to their slate-hyperscript representation.

You can use slate-hyperprint as a library to:

  • Run a script to easily convert Slate tests written in Yaml/JSON to hyperscript.
  • Improve the output of unit tests by comparing hyperscript strings instead of JSON values.
  • Facilitate debugging and console logging of Slate values.

See the online demo, that converts a Slate JSON representation to a Slate hyperscript representation.

⚠️ This repository is now using GitBook's fork of ianstormtaylor/slate. Previous versions are still available on NPM All the versions using GitBook's fork of slate are now published under the @gitbook NPM scope. To learn more about why we forked Slate, read our manifest

Setup

yarn add slate-hyperprint [--dev]

Usage

import Slate from 'slate';
import hyperprint from 'slate-hyperprint';

console.log(
    hyperprint(
        Slate.Value.create({
            document: Slate.Document.create({
                nodes: [
                    Slate.Block.create({
                        type: 'paragraph',
                        data: { a: 1 },
                        nodes: [
                            Slate.Text.create('Hello')
                        ]
                    }
                )]
            })
        })
    )
);
// <value>
//   <document>
//     <paragraph a={1}>
//       Hello
//     </paragraph>
//   </document>
// </value>

hyperprint.log(...)
// Equivalent to console.log(hyperprint(...))

Options

slate-hyperprint accepts an option object:

hyperprint(value, options);
  • preserveKeys: boolean = false True to print node keys
  • strict: boolean = false True to preserve empty texts and other things that the formatting would otherwise omit. Useful when using hyperprint compare values in tests, because the output is stricter.
  • prettier: Object = { semi: false, singleQuote: true, tabWidth: 4 } Prettier config to use when formatting the output JSX.

Test

yarn run test

Build

yarn run build

CLI

slate-hyperprint also export a command line interface tool that converts yaml files to jsx. When installed globally (npm install slate-hyperprint --global) it can be used like so:

$ slate-hyperprint document.yaml

It will load the file, create a Slate document and print it to the console in jsx. Note: it will look for a value.document, state.document or document property. It will consider the whole content as the document if none are found.

You can write the output to a file like so slate-hyperprint input.yaml > output.js

Here is a command to convert a whole bunch of yaml files in a test folder:

$ for file in tests/**/*.yaml; do basename=$(echo $file | sed 's/\.yaml//'); slate-hyperprint $basename.yaml > $basename.js; done;

Thanks

The React equivalent react-element-to-jsx-string is and will remain a great source of inspiration.