• Stars
    star
    113
  • Rank 303,698 (Top 7 %)
  • Language
    JavaScript
  • License
    ISC License
  • Created over 6 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🪓 An enchanted hyperscript weapon.
HyperAxe

HyperAxe

An enchanted hyperscript weapon.

npm build downloads

npm install hyperaxe
const { body, h1 } = require('hyperaxe')

body(
  h1('hello world')
)
// => <body><h1>hello world</h1></body>

Usage

Exports all HTML tags.

const { a, img, video } = require('hyperaxe')

a({ href: '#' }, 'click')
// <a href="#">click</a>

img({ src: 'cats.gif', alt: 'lolcats' })
// <img src="cats.gif" alt="lolcats">

video({ src: 'dogs.mp4', autoplay: true })
// <video src="dogs.mp4" autoplay="true"></video>

Default export accepts a tag and returns an element factory.

const x = require('hyperaxe')
const p = x('p')

p('over 9000')
// <p>over 9000</p>

CSS shorthand works too.

const x = require('hyperaxe')
const horse = x('.horse.with-hands')

horse('neigh')
// <div class="horse with-hands">neigh</div>

Makes creating custom components easy.

const x = require('hyperaxe')

const siteNav = (...links) => x('nav.site')(
  links.map(link =>
    x('a.link')({ href: link.href }, link.text)
  )
)

x.body(
  siteNav(
    { href: '#apps', text: 'apps' },
    { href: '#games', text: 'games' }
  )
)
// <body>
//   <nav class="site">
//     <a class="link" href="#apps">apps</a>
//     <a class="link" href="#games">games</a>
//   </nav>
// </body>

Example

Here's a counter increment example using nanochoo:

const { body, button, h1 } = require('hyperaxe')
const nano = require('nanochoo')

const app = nano()

app.use(store)
app.view(view)
app.mount('body')

function view (state, emit) {
  return body(
    h1(`count is ${state.count}`),
    button({ onclick }, 'Increment')
  )

  function onclick () {
    emit('increment', 1)
  }
}

function store (state, emitter) {
  state.count = 0

  emitter.on('increment', function (count) {
    state.count += count
    emitter.emit('render')
  })
}

API

hyperaxe

hyperaxe(tag) => ([props], [...children]) => HTMLElement
  • tag string - valid HTML tag name or CSS shorthand (required)
  • props object - HTML attributes (optional)
  • children node, string, number, array - child nodes or primitives (optional)

Returns a function that creates HTML elements.

The factory is variadic, so any number of children are accepted.

x('.variadic')(
  x('h1')('hi'),
  x('h2')('hello'),
  x('h3')('hey'),
  x('h4')('howdy')
)

Arrays of children also work.

const kids = [
  x('p')('Once upon a time,'),
  x('p')('there was a variadic function,'),
  x('p')('that also accepted arrays.')
]

x('.arrays')(kids)

In a browser context, the object returned by the factory is an HTMLElement object. In a server (node) context, the object returned is an instance of html-element. In both contexts, the stringified HTML is accessible via the outerHTML attribute.

hyperaxe[tag]

All HTML tags are attached to hyperaxe as keys.

They return the same function as described above, with the tag argument prefilled.

Think of it as a kind of partial application.

The main motivation for doing this is convenience.

const { p } = require('hyperaxe')

p('this is convenient')

You can pass raw HTML by setting the innerHTML property of an element.

const { div } = require('hyperaxe')

div({ innerHTML: '<p>Raw HTML!' })

hyperaxe.createFactory(h)

Creates a hyperaxe element factory for a given hyperscript implementation (h).

If you use another implementation than hyperscript proper, you can exclude that dependency by using require('hyperaxe/factory'). For the time being, no other implementations are tested though, so wield at your own peril!

hyperaxe.getFactory(h)

Same as createFactory, except it only creates a new factory on the first call and returns a cached version after that.

Enchantments

  • Summons DOM nodes.
  • +1 vs. virtual DOM nodes.
  • Grants Haste.

Dependencies

  • html-tags: List of standard HTML tags.
  • hyperscript: Create HyperText with JavaScript, on client or server.

Dev Dependencies

  • standard: JavaScript Standard Style.
  • standard-version: Replacement for npm version with automatic CHANGELOG generation.
  • tape: tap-producing test harness for node and browsers.

See Also

This library's approach and API are heavily inspired by reaxe.

Contributing

Contributors welcome! Please read the contributing guidelines before getting started.

License

ISC

Axe image is from emojidex.

More Repositories

1

gh-release

🚀 Create a GitHub Release for a Node package.
JavaScript
151
star
2

himawari-bg

🌏 Set the latest image from Himawari 8 as your desktop background.
JavaScript
90
star
3

style.css

🔰 Classless stylesheet for HTML documents.
SCSS
77
star
4

changelog-parser

🪵 Change log parser for node.
JavaScript
73
star
5

module-init

🏁 Create a new node module with all the right stuff.
JavaScript
71
star
6

sitedown

📄 Turn some markdown files into a website.
JavaScript
68
star
7

magnet-link

DEPRECATED: Get a magnet link from a torrent file.
JavaScript
64
star
8

format-duration

⏱ Convert milliseconds to a standard duration string.
JavaScript
54
star
9

nano-s3

Upload a file to S3.
JavaScript
45
star
10

gamepad-tester

Simple electron app for testing the Gamepad API.
JavaScript
26
star
11

electron-hello-world

🙅 [deprecated]
JavaScript
25
star
12

electron-browser-window-options

Reference for default Electron BrowserWindow options.
JavaScript
23
star
13

gfm.css

Styles for github flavored markdown.
HTML
22
star
14

martin

🙅 [deprecated]
Ruby
21
star
15

electron-multiple-windows-demo

An example electron app showing how to manage multiple windows.
JavaScript
19
star
16

init-module

🍬 Add some sugar to the npm init command.
JavaScript
19
star
17

coolgifs.neocities.org

🆒 the web site of cool gifs 😎
JavaScript
18
star
18

dotfiles

💻 Minimalist config for working in a terminal environment.
Shell
18
star
19

himawari-urls

🌐 Get URLs for Himawari 8 image tiles based on a given date.
JavaScript
18
star
20

hi8

🌻 See Earth from Himawari-8 on your desktop every 10 minutes.
JavaScript
15
star
21

module.party

❌ dead site
HTML
14
star
22

jekyll-reveal

markdown → slides (reveal.js) → gh-pages (jekyll)
CSS
13
star
23

pino-gris

A verbose ndjson log formatter for pino.
JavaScript
13
star
24

reader

Quick sketch of a feed reader built with Electron.
JavaScript
12
star
25

contact

💬 How to contact me on the internet.
11
star
26

open-source-maintenance-guidelines

🐶 How to be a Good Open Source Shepherd
11
star
27

gh-release-assets

Upload assets to a GitHub release
JavaScript
10
star
28

no-moments

Hide the "Moments" button on Twitter.
CSS
10
star
29

yt-pip

📺 Watch youtube videos using macOS picture-in-picture.
JavaScript
9
star
30

yokel

8
star
31

contracts

📝 Generate a web development contract based on a template.
JavaScript
8
star
32

goes-bg

🌎 Set the latest image from GOES 16 & 17 as your desktop background.
JavaScript
8
star
33

bagel.technology

❌ dead site
HTML
7
star
34

earth-tweets

❌ dead site
JavaScript
7
star
35

himawari-history

Download all Himawari 8 images in a date range.
JavaScript
7
star
36

CONTRIBUTING.md

Open contributing and collaborating guidelines.
6
star
37

tinystore

tiny web storage wrapper
JavaScript
6
star
38

meowl.party

❌ dead site
HTML
6
star
39

cwp

Get a path string relative to the current working directory.
JavaScript
5
star
40

kill-desktop-osx

Kill Your Desktop (OS X only).
JavaScript
5
star
41

hype-html

nanohtml (and hyperx) packaged for esm
JavaScript
5
star
42

top-bar.css

🎩 A top bar navigation pattern.
HTML
5
star
43

fritter-crawler

Rough draft of a script for crawling the fritter network.
JavaScript
5
star
44

electron-repl

Interactive REPL for debugging Electron programs.
JavaScript
5
star
45

electron-ipc-log

[deprecated] Log all user-defined IPC traffic in an electron app.
JavaScript
4
star
46

droptop

JavaScript
4
star
47

contribs

🙏 Generate boilerplate open source contributing guidelines.
JavaScript
4
star
48

dragon-wario

Command-line CYOA with Node.js.
JavaScript
4
star
49

npm-maintainer-dash

🔬 list user's npm pkgs sorted by monthly downloads
JavaScript
3
star
50

latest-earth

HTML
3
star
51

shape-rotator

JavaScript
3
star
52

isc-license

Generate an ISC license.
JavaScript
3
star
53

trimet-bus-sim

PDX Bus Driver Sim 2000
JavaScript
3
star
54

kill-tweet-stream

Save time by hiding the tweet stream on Twitter.
CSS
3
star
55

neocities-cli

JavaScript
3
star
56

is-webgl-enabled

Detect if WebGL is enabled in the current environment.
JavaScript
3
star
57

proton

⚡ electron + photon app boilerplate (wip)
HTML
2
star
58

boing

Est quid sit.
HTML
2
star
59

gravatar-url-cli

Get a Gravatar URL for an email from the command line.
JavaScript
2
star
60

module-downloads

Dashboard for viewing module downloads from the NPM registry.
JavaScript
2
star
61

burger-week-challenge-2014

A burger challenge map.
HTML
2
star
62

signalhub.decent.digital

Signalhub server for Hypermodules projects
1
star
63

broken-remote

JavaScript
1
star
64

tools

A list of development tools I've built or used.
1
star
65

cgsa

Cellular Geographic Service Areas (FCC)
1
star
66

intro-to-node

JavaScript
1
star
67

qr2p

JavaScript
1
star
68

node-static-server-template

Quick! Serve a static site with node.js!
JavaScript
1
star
69

css-units

JavaScript
1
star
70

parcel-express

Starter kit for working with parcel and express.
JavaScript
1
star
71

tetromino

real-time multi-player tetris with node and socket.io
JavaScript
1
star
72

eternal-recurrence

✍️ Generative creative writing via OpenAI
JavaScript
1
star
73

donothing.online

❌ dead site
HTML
1
star
74

docker-env-vars

all the ways env vars work in docker
Dockerfile
1
star
75

box-socket

A simple demonstration of real-time multiplayer interaction with WebSockets.
JavaScript
1
star