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

dscript

v1.1.0

Published

Framework agnostic hyperscript

Downloads

9

Readme

dscript

NPM version Build Status Coverage Status

Code Climate Dependencies DevDependencies

PRs Welcome Commitizen friendly semantic-release

Framework agnostic hyperscript

Should work with any JSX pragma that works out of the box with Babel's JSX implementation or a function that accepts an HTML tag or component, attributes object, and children list.

Install

npm install --save dscript

Note: Webpack users will need to setup a json-loader as dscript relies on html-tags, which uses a JSON file

General Usage

import dscript from 'dscript'
import {element} from 'deku'

const {div, li, ul} = dscript(element)

const handleClick = () => alert('hi!')

export default ({props}) =>
  div('.list-container', {onClick: handleClick}, [
    ul(
      props.items.map(item =>
        li(item.name)
      )
    )
  ])

Usage with React

It is recommended to use dscript-react to remove dscript boilerplate.

Take the following:

import React from 'react'

export default props =>
  <ul>
    {props.items.map(item =>
      <li>{item.name}</li>
    )}
  </ul>

or:

import {createElement} from 'react'

export default props =>
  createElement('ul', {},
    props.items.map(item =>
      createElement('li', {}, [
        item.name
      ])
    )
  )

and instead write:

import {createElement} from 'react'
import dscript from 'dscript'

const {li, ul} = dscript(createElement)

export default props =>
  ul(
    props.items.map(item =>
      li(item.name)
    )
  )

Usage with Deku

It is recommended to use dscript-deku to remove dscript boilerplate.

Take the following:

import {element} from 'deku'

export default ({props}) =>
  <ul>
    {props.items.map(item =>
      <li>{item.name}</li>
    }
  </ul>

or:

import {element} from 'deku'

export default ({props}) =>
  element('ul', {},
    props.items.map(item =>
      element('li', {}, [
        item.name
      ])
    )
  )

and instead write:

import dscript from 'dscript'
import {element} from 'deku'

const {li, ul} = dscript(element)

export default ({props}) =>
  ul(
    props.items.map(item =>
      li(item.name)
    )
  )

Usage with Custom Components

Custom components example is shown using React, but works with any framework that works with dscript's basic functionality.

import dscript from 'dscript'
import {createElement} from 'react'

import customComponent from './custom-component'

const creator = dscript(createElement)

const {div, li, ul} = creator
const customComponentCreator = creator(customComponent)

const handleClick = () => alert('hi!')

export default props =>
  div('.list-container', {onClick: handleClick}, [
    customComponentCreator({total: props.total}),
    ul(
      props.items.map(item =>
        li(item.name)
      )
    )
  ])

API

dscript(createElement)

Returns an object with properties consisting of HTML tags with values being creator functions.

createElement

type: function

A function to use to create the Virtual DOM. For example, React's createElement or Deku's element.

dscript(createElement)(customComponent)

Returns a creator function to be used in dscript.

For example:

import {createElement} from 'react'
import customComponent from './lib/custom-react-component/'
import dscript from 'dscript'

const creator = dscript(createElement)

const {div} = creator
const custom = creator(customComponent)

export default div([custom()])

createElement

Same as above

customComponent

type: any

Should be a valid component for the createElement function.

Creator Functions

creatorFunction([cssClassesAndOrIdSelector,] [attributes,] [children])

A function that returns a virtual DOM node created with createElement.

cssClassesAndOrIdSelector

type: string

default: null

A convenience to add class names and an id to a virtual DOM node. Note: The provided selector will override attribute's class and id.

attributes

type: object

default: {}

An object that will be passed as the attributes to the virutal DOM node.

children

type: ...Elements

default: []

The list of children passed to the created virtual DOM node.

LICENSE

MIT © Dustin Specker