Skip to content

Commit

Permalink
feat: rewrite in typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
estrattonbailey committed Dec 24, 2021
1 parent 4bac3c1 commit cf1b35c
Show file tree
Hide file tree
Showing 23 changed files with 3,329 additions and 12,537 deletions.
3 changes: 3 additions & 0 deletions .c8rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"reporter": ["text", "lcov"]
}
49 changes: 34 additions & 15 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,50 @@
name: Release
name: CD

on:
push:
branches:
- master
- next
- main
- beta

env:
PNPM_CACHE_FOLDER: .pnpm-store

jobs:
release:
name: CD
runs-on: ubuntu-18.04
build:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 12
- name: Installing dependencies
run: npm i
- name: Lint
run: npm run lint
- name: Test
run: npm run test
- name: Release
node-version: 14

# pnpm stuff
- name: pnpm — install
run: npm i pnpm@latest -g
- name: pnpm - config
run: pnpm config set store-dir $PNPM_CACHE_FOLDER
- name: pnpm - install
run: pnpm install

# build
- name: lint
run: pnpm lint
- name: build
run: pnpm build # bae — before everything else
- name: test
run: pnpm t

- name: coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

# release
- name: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release
run: pnpm exec semantic-release
42 changes: 31 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,49 @@
name: Lint & Test
name: CI

on:
pull_request:
branches:
- '**'

env:
PNPM_CACHE_FOLDER: .pnpm-store

jobs:
build:
name: CI
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 12
- name: Installing dependencies
run: npm i
- name: Lint
run: npm run lint
- name: Test
run: npm run test
- name: Release
node-version: 14

# pnpm stuff
- name: pnpm — install
run: npm i pnpm@latest -g
- name: pnpm - config
run: pnpm config set store-dir $PNPM_CACHE_FOLDER
- name: pnpm - install
run: pnpm install

# build
- name: lint
run: pnpm lint
- name: build
run: pnpm build # bae — before everything else
- name: test
run: pnpm t

- name: coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

# release
- name: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release -d
run: pnpm exec semantic-release -d
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.DS_Store
*.map
node_modules/
dist
.nyc_output
.pnpm*
coverage

# built files
index.js
index.d.ts
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

pnpm exec commitlint --edit
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

pnpm t && pnpm run format
9 changes: 9 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/bench
/lib
.c8rc
.gitignore
.prettierignore
.prettierrc
commitlint.config.js
release.config.js
tsconfig.json
14 changes: 13 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
node_modules
bench
demo
fixtures
test/fixtures
dist
build
.nyc_output
coverage
pnpm-lock.yaml
.pnpm*
.changeset

index.js
index.d.ts
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"semi": false,
"singleQuote": true,
"printWidth": 120,
"tabWidth": 2
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![hyposcript](https://user-images.githubusercontent.com/4732330/96394691-407b9f00-1188-11eb-92c0-e05e48da99e8.png)
# hyposcript

<br/>
[![npm version](https://img.shields.io/npm/v/hyposcript?style=flat&colorA=4488FF&colorB=4488FF)](https://www.npmjs.com/package/hyposcript) [![test coverage](https://img.shields.io/coveralls/github/sure-thing/hyposcript?style=flat&colorA=223355&colorB=223355)](https://coveralls.io/github/sure-thing/hyposcript?branch=main) [![npm bundle size](https://badgen.net/bundlephobia/min/hyposcript?color=223355&labelColor=223355)](https://bundlephobia.com/result?p=hyposcript)

Hyper minimal hyperscript for server rendering.

Expand Down
6 changes: 3 additions & 3 deletions bench/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ const hyperscript = require('hyperscript')
const vhtml = require('vhtml')
const hyposcript = require('../')

function bench (name) {
function bench(name) {
console.log(`\n# ${name}`)
const suite = new Suite()
const previous = suite.add.bind(suite)
suite.on('cycle', e => console.log(' ' + e.target))
suite.on('cycle', (e) => console.log(' ' + e.target))
suite.add = (name, runner) => previous(name.padEnd(16), runner)
return suite
}

function createApp (h) {
function createApp(h) {
return h(
'div',
{ className: 'foo' },
Expand Down
1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = { extends: ['@commitlint/config-conventional'] }
136 changes: 61 additions & 75 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,82 +1,68 @@
const aliases = {
className: 'class',
htmlFor: 'for'
}

const voids = [
'area',
'base',
'br',
'col',
'embed',
'hr',
'img',
'input',
'link',
'meta',
'param',
'source',
'track',
'wbr'
]

function styleObjectToString (style) {
let s = ''

for (const p in style) {
const k = p.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2').toLowerCase()
s += k + ':' + style[p] + ';'
var c = Object.defineProperty,
k = Object.defineProperties,
N = Object.getOwnPropertyDescriptor,
S = Object.getOwnPropertyDescriptors,
g = Object.getOwnPropertyNames,
y = Object.getOwnPropertySymbols
var a = Object.prototype.hasOwnProperty,
T = Object.prototype.propertyIsEnumerable
var h = (t, e, o) => (e in t ? c(t, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : (t[e] = o)),
u = (t, e) => {
for (var o in e || (e = {})) a.call(e, o) && h(t, o, e[o])
if (y) for (var o of y(e)) T.call(e, o) && h(t, o, e[o])
return t
},
d = (t, e) => k(t, S(e)),
C = (t) => c(t, '__esModule', { value: !0 })
var H = (t, e) => {
for (var o in e) c(t, o, { get: e[o], enumerable: !0 })
},
P = (t, e, o, i) => {
if ((e && typeof e == 'object') || typeof e == 'function')
for (let r of g(e))
!a.call(t, r) &&
(o || r !== 'default') &&
c(t, r, { get: () => e[r], enumerable: !(i = N(e, r)) || i.enumerable })
return t
}

return s
var x = (
(t) => (e, o) =>
(t && t.get(e)) || ((o = P(C({}), e, 1)), t && t.set(e, o), o)
)(typeof WeakMap != 'undefined' ? new WeakMap() : 0)
var v = {}
H(v, { h: () => w, styleObjectToString: () => m })
var $ = { className: 'class', htmlFor: 'for' },
j = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr']
function m(t) {
let e = ''
for (let o in t) e += o.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2').toLowerCase() + ':' + t[o] + ';'
return e
}

function h (t, props, ...children) {
if (t.children) return t.children.join('')

props = props || {}

const c = []

children = children.length ? children : props.children || []

while (children.length) {
const child = children.shift()
if (child) {
child.pop ? children.push(...child) : c.push(child)
}
function w(t, e, ...o) {
if (typeof t == 'object' && t.children) return t.children.join('')
e = e || {}
let i = []
for (o = o.length ? o : e.children || []; o.length; ) {
let n = o.shift()
!n || (typeof n == 'string' ? i.push(n) : o.push(...n))
}

if (t.call) return t({ ...props, children: c })

let attrs = ''

for (const k in props) {
if (k === 'children') continue

let v = props[k]
const key = aliases[k] || k

if (typeof v === 'boolean') {
attrs += `${key}`
if (typeof t == 'function') return t(d(u({}, e), { children: i }))
let r = ''
for (let n of Object.keys(e)) {
if (n === 'children') continue
let s = e[n],
f = $[n] || n
if (typeof s == 'boolean') {
r += `${f}`
continue
}

if (k === 'style') v = styleObjectToString(v)

attrs += `${key}="${v}"`
}

const a = attrs ? ' ' + attrs : ''
const v = voids.indexOf(t) > -1

let childs = ''

while (c.length) {
childs += c.shift()
n === 'style' && (s = m(s)), (r += `${f}="${s}"`)
}

return v ? '<' + t + a + ' />' : '<' + t + a + '>' + childs + '</' + t + '>'
let p = r ? ' ' + r : '',
b = j.indexOf(t) > -1,
l = ''
for (; i.length; ) l += i.shift()
return b ? '<' + t + p + ' />' : '<' + t + p + '>' + l + '</' + t + '>'
}

module.exports = { h, styleObjectToString }
module.exports = x(v)
0 && (module.exports = { h, styleObjectToString })
Loading

0 comments on commit cf1b35c

Please sign in to comment.