├── LICENSE ├── README.md ├── golf.js ├── index.js └── package.json /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 'Dominic Tarr' 2 | 3 | Permission is hereby granted, free of charge, 4 | to any person obtaining a copy of this software and 5 | associated documentation files (the "Software"), to 6 | deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, 8 | merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom 10 | the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR 20 | ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # hscrpt 2 | 3 | `hscrpt` is a sugar-free version of [hyperscript](https://github.com/dominictarr/hyperscript) 4 | 5 | It's not a framework, it's just a tool for convienently creating html 6 | elements directly in javascript. 7 | 8 | ``` js 9 | //reactive hello world 10 | var h = require('hscrpt') 11 | var name 12 | document.body.appendChild(h('div', [ 13 | h('h1', [ 'Hello, ', name = h('span', 'World') ]), 14 | h('input', {oninput: function (ev) { 15 | name.textContent = ev.target.value 16 | }}) 17 | ])) 18 | ``` 19 | 20 | frameworks come and go. but the DOM doesn't change, 21 | because that would _break all the frameworks_. 22 | 23 | You could do this with `hyperscript`, this just removes all the sugar 24 | from hyperscript and gives you something absolutely minimal. 25 | 26 | infact: 27 | ``` js 28 | module.exports = function h (tag, attrs, content) { 29 | if(Array.isArray(attrs)) content = attrs, attrs = {} 30 | var el = document.createElement(tag) 31 | for(var k in attrs) el[k] = attrs[k] 32 | if(content) content.forEach(function (e) { 33 | if(e) el.appendChild('string' == typeof e ? document.createTextNode(e) : e) 34 | }) 35 | return el 36 | } 37 | ``` 38 | ^ you just read the entire codebase of `hscrpt`. 39 | 40 | # api: h(tagname, attrs?, children?) 41 | 42 | only `tagname` is mandatory. it must be a string. 43 | if given, `attrs` must be an `{}` 44 | and children must be an []. 45 | 46 | ## setting classes 47 | 48 | use `h('div', {classList: 'content'})` 49 | (same as `h('div.content')` in 'hyperscript'.) 50 | 51 | ## setting event listeners 52 | 53 | use `h('button', {onclick: function (ev) {...}}, ['submit'])` 54 | 55 | ## License 56 | 57 | MIT 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /golf.js: -------------------------------------------------------------------------------- 1 | exports.h=(E,a,c,K)=>{E=document.createElement(E);for(K in a)E[K]=a[K];for(K in c)K=c[K]&&E.appendChild(K.click?K:new Text(K));return E} 2 | 3 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | module.exports = function h (tag, attrs, content) { 2 | if(Array.isArray(attrs)) content = attrs, attrs = {} 3 | var el = document.createElement(tag) 4 | for(var k in attrs) el[k] = attrs[k] 5 | if(content) content.forEach(function (e) { 6 | if(e) el.appendChild('string' == typeof e ? document.createTextNode(e) : e) 7 | }) 8 | return el 9 | } 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hscrpt", 3 | "description": "", 4 | "version": "0.0.1", 5 | "homepage": "https://github.com/dominictarr/hscrpt", 6 | "repository": { 7 | "type": "git", 8 | "url": "git://github.com/dominictarr/hscrpt.git" 9 | }, 10 | "dependencies": {}, 11 | "devDependencies": {}, 12 | "scripts": { 13 | "test": "set -e; for t in test/*.js; do node $t; done" 14 | }, 15 | "author": "'Dominic Tarr' (dominictarr.com)", 16 | "license": "MIT" 17 | } 18 | --------------------------------------------------------------------------------