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

@docscript/docscript

v0.0.3

Published

A DSL for Javascript designed to build the DOM inspired by Kotlin

Downloads

16

Readme

DocScript

This is an early exploration of an extension to the JS language to enable a DSL designed to manipulate the DOM.

The syntax is inspired by Kotlin builders (i.e. they look ilke {}-trees rather than XML). It is meant to be used as a DSL like JSX (i.e. templating language to build HTML components).

Like Kotlin, it is designed to enable going back and fourth between the declarative code and the imperative code.

This is currently prototyped as a transpiler.

Example

DocScript extends the JS syntax to enable declaring tree-like structures and intermingling imperative code back and fourth. Its most simple invocation returns an Element:

let head = span { "Hello World!" };

Along the lines of Kotlin builders's, what goes inside the {} is valid JS code, so you can execute real statements. For example:

let body = div {
  // This is JS scope, so comments are valid!

  // Like, for real JS. E.g. if statements are executed.
  if (document.cookie) {
    "Welcome back!"
  }

  // Same goes for for loops
  for (let page of ["about", "contact"]) {
    a({href: `${page}.html`}) { page }
  }
  
  // Attributes are passed as ({key: value}) and can contain JS too.
  div({onclick: function() { alert("Hi!"); }}) {
    click me!
  } 
}

Finally, a dom() API is provided so that you can turn the Element instance into a HTMLElement instance to be embedded in the DOM.

function extra() {
  return span { "extra info" }
}

let html = div {
  // Expressions that result into a DocScript are
  // appended as children!
  head // variables get composed
  extra() // functions get called
  body
}

// The .dom() API transforms the Element instance into
// an HTMLElement instance.
document.body.appendChild(html.dom());

It plays well with components-like frameworks:

class MyComponent extends mixin(Component, React) {
  constructor() {
    this.name = "Sam Goto";
  }
  render() {
    return span { `Welcome back, ${this.foo}!` }
  }
}

Installation

npm install -g @docscript/docscript

Usage

> dsc examples/helloworld.ds.js > /tmp/helloworld.js; node /tmp/helloworld.js
{
 "name": "div",
 "children": [
  {
   "name": "span",
   "children": [
    "Hello World!"
   ]
  },
  {
   "name": "span",
   "children": [
    "extra info"
   ]
  },
  {
   "name": "div",
   "children": [
    {
     "name": "a",
     "attributes": {
      "href": "about.html"
     },
     "children": [
      "about"
     ]
    },
    {
     "name": "a",
     "attributes": {
      "href": "contact.html"
     },
     "children": [
      "contact"
     ]
    },
    {
     "name": "div",
     "attributes": {},
     "children": [
      "click me!"
     ]
    }
   ]
  }
 ]
}
Hi!

Tests

npm test

Status

You really don't want to use this right now. Very early prototype.

Related work