# short-dom-util

> Simple short dom manipulation functions for personal use

Latest version **1.1.0** (published 2023-07-19) · ISC license · 0 weekly downloads

## Install

```sh
npm install short-dom-util
pnpm add short-dom-util
yarn add short-dom-util
bun add short-dom-util
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2023-07-19 |
| First published | 2023-07-19 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | tomifuchi |
| Keywords | dom, frontend, query |

## Links

- npm: https://www.npmjs.com/package/short-dom-util
- Repository: https://github.com/tomifuchi/short-dom-util
- Homepage: https://github.com/tomifuchi/short-dom-util#readme
- Issues: https://github.com/tomifuchi/short-dom-util/issues
- npm.io page: https://npm.io/package/short-dom-util

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2023-07-19
- 1.0.0 — 2023-07-19

## README

# short-dom-util
As personal collection of short dom manipulation functions.

## Syntax
All of these functions return the target to be then pass into another
function. This allow us to write compossible code.

### Creating elements
```Javascript
c(elm)//(c)reate

tc(target, val)//(t)ext(c)ontent

sa(target, attrib, val)//(s)et(a)ttribute, here attrib is a string

sma(target, attrib)//(s)et (m)ultiple (a)ttribute, here attrib is the attrib object with propertise name and value corresponding to it.

ap(target, ...objs)//(ap)pendChild

cea(elm, attrib)  //(c)reate element with (a)trribute, here attrib is an object with desired attributes values inside here's an example 
//{class: "nav-bar", id: "main-nav"}
```

### Clearing child nodes
```Javascript
clc(target) //(Cl)ear (c)hild nodes
```

### Querying
```Javascript
q(selector, parentNode=document) // parentNode.querySelector(selector)
qa(selector, parentNode=document) // parentNode.querySelectorAll(selector)
```

## Example use case
Building an application in pure Javascript ? To create element, typing
document dot something takes alot of time. Here's one way to create a form using the syntax above

```Javascript
function createFormElement() {
    const form = ap(cea('form', {action:"", method:"post" ,id:"create-todo-form"}),
        tc(c('h2'), 'todo creation'),
        ap(c('fieldset'),
            tc(c('legend'), 'todo info'),
            ap(c('p'),
                tc(cea('label',{for:"title"}), 'Title:'),
                cea('input', {type:"text", id:"title", name:"todo_title" ,required:''}),
                c('span')),
            ap(c('p'),
                tc(cea('label', {for:"description"}), 'Description:'),
                cea('input', {type:"text", id:"description", name:"todo_description", required: ''}),
                c('span')),
            ap(c('p'),
                tc(cea('label', {for:"content"}), 'Content:'),
                cea('textarea', {rows:"5" ,id:"content", maxlength:"1000", required: ''})),
            ap(c('p'),
                tc(cea('label',{for:"due-date"}), 'Due date:'),
                cea('input',{type:"date" ,id:"due-date", name:"todo_dueDate", required: ''})),
            ap(c('p'), 
                tc(cea('label', {for:"priority"}), 'Priority:'),
                ap(cea('select', {id:"priority"}),
                    tc(cea('option', {value:"normal"}),'Normal'),
                    tc(cea('option', {value:"moderate"}), 'Moderate'),
                    tc(cea('option', {value:"urgent"}), 'Urgent'))),
            ap(c('p'),
                tc(cea('label', {for:"tags"}), 'Tags'),
                tc(c('p'), 'These are space separated, and have syntax of indentifier:topic, example: rockband:guitar, programming:haskell, study:math:'),
                cea('input', {type:"text" ,id:"tags", name:"todo_tags"})),
            ap(c('p'),
                tc(c('p'), 'Status:'),
                tc(cea('label',{for:"finished"}), 'Finished'),
                cea('input', {type:"radio", id:"finished", value:"finished", name:"todo_status"}),
                tc(cea('label',{for:"unfinised"}), 'Unfinished'),
                cea('input', {type:"radio", id:"unfinished", value:"unfinished", name:"todo_status", checked: ''})),
            ap(c('p'),
                tc(cea('button', {type:"button", id:"create-todo-btn"}), 'Add todo'))
        )
    );
    sa(q('#due-date', form), 'min', new Date().toISOString().split("T")[0]);

    return form;
}
```

---
_Source: https://npm.io/package/short-dom-util · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
