├── facon.png ├── .gitignore ├── .editorconfig ├── .github └── workflows │ └── ci.yml ├── example └── index.html ├── package.json ├── license ├── src └── index.js ├── readme.md └── test └── index.js /facon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/terkelg/facon/HEAD/facon.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .nyc_output 3 | .DS_Store 4 | *.lock 5 | *.log 6 | 7 | /sync 8 | /dist 9 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_size = 2 6 | indent_style = space 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.{json,yml,md}] 13 | indent_style = space -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: push 4 | 5 | jobs: 6 | test: 7 | name: Node.js v${{ matrix.nodejs }} (${{ matrix.os }}) 8 | runs-on: ${{ matrix.os }} 9 | strategy: 10 | matrix: 11 | nodejs: [10, 12] 12 | os: [ubuntu-latest] 13 | steps: 14 | - uses: actions/checkout@v1 15 | with: 16 | fetch-depth: 1 17 | 18 | - uses: actions/setup-node@v1 19 | with: 20 | node-version: ${{ matrix.nodejs }} 21 | 22 | - name: Install 23 | run: | 24 | npm install 25 | npm install -g nyc 26 | 27 | - name: Test w/ Coverage 28 | run: npx nyc --include=src npm test 29 | 30 | - name: Report 31 | if: matrix.nodejs >= 12 32 | run: | 33 | npx nyc report --reporter=text-lcov > coverage.lcov 34 | bash <(curl -s https://codecov.io/bash) 35 | env: 36 | CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} 37 | -------------------------------------------------------------------------------- /example/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |
2 |
3 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
15 |
16 |
17 |
18 |
Tiny utility (365B) to create DOM elements with manner.
21 | 22 | Manually creating DOM nested elements can be very troublesome and verbose. 23 | Facon is a tiny utility that makes it easy to create nested DOM elements using template literals and extract references. 24 | 25 | 26 | There's no magic nor restrictive template logic. All you get are DOM references so that you can do whatever you like and take full advantage of the powerful native DOM API. 27 | 28 | 29 | > **TLDR**: Facon fixes the tiring process of creating and assembling nested DOM elements or `.innerHTML` where you later have to query for references manually. 30 | 31 | **~~lack of~~ Features** 32 | - Tiny (365 bytes gzipped) 33 | - Vanilla JS 34 | - Zero Dependencies 35 | - Fast 36 | 37 | 38 | ## Install 39 | 40 | ``` 41 | $ npm install facon 42 | ``` 43 | 44 | This module exposes three module definitions: 45 | 46 | * **ES Module**: `dist/facon.mjs` 47 | * **CommonJS**: `dist/facon.js` 48 | * **UMD**: `dist/facon.min.js` 49 | 50 | Include facon: 51 | ```js 52 | // ES6 53 | import f from 'facon' 54 | 55 | // CJS 56 | const f = require('facon'); 57 | ``` 58 | 59 | The script can also be directly included from [unpkg.com](https://unpkg.com): 60 | ```html 61 | 62 | ``` 63 | 64 | 65 | ## Usage 66 | 67 | ```js 68 | import f from 'facon'; 69 | 70 | // Create a DOM element 71 | let node = f`Hello World`; 72 | document.body.appendChild(node); 73 | 74 | // Create nested elements, and extract references 75 | let node = f` 76 |Create nested DOM elements with manner
79 |Create nested DOM elements with manner
163 |How Are you?
How Are you?