Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/promatik/cantil-js

A tiny javascript framework with the helpers you need to boost your productivity
https://github.com/promatik/cantil-js

Last synced: about 1 month ago
JSON representation

A tiny javascript framework with the helpers you need to boost your productivity

Awesome Lists containing this project

README

        

Cantil JS logo


Size
Size
Downloads


Version
License

# Cantil JS

A tiny framework with the helpers you need to boost your productivity.

### Install

```js
npm i cantil
```

### Usage

```js
require('cantil');
```

### Methods

---

#### `query` / `queryAll`
_Shortcut for `document.querySelector` and `document.querySelectorAll`_

```js
// query the first

element
let p = query('p');

// query all

elements
queryAll('p');

// query all inside p
p.queryAll('a'); // or queryAll('p:first-child a');
```

---

#### NodeList / HTMLCollection Array Prototype
_By default NodeList and HTMLCollection don't have Array metods like `map`, `filter` or `reduce` (among others)._
_Cantil JS enables these methods πŸŽ‰_

```js
queryAll('p')
.filter(p => p.classList.contains('active'))
.map(p => p.innerText)
.join(', ');
```

---

#### `index`
_Position of the element relative to its parent_

```js
p.index();
```

---

#### `sibling` / `siblings`
_Query the siblings of the element_

```js
// query the first

sibling of



p.sibling('h1');

// query all


siblings of



p.siblings('h1');
```

---

### `onDomReady`
_Promise for DOM ready_

```js
import { onDomReady } from 'cantil';

init: () => {
console.log("App ready");
};

onDomReady().then(init);
```

---

### `template`
_Clones a DOM template making it ready to use_

```js
import { template } from 'cantil';

let element = template('template#example');

query('section').append(element);
```

---

### `once`
_Ensures the callable runs only once_

```js
import { once } from 'cantil';

let callOnce = once(() => {
console.log('callOnce');
});

callOnce();
callOnce();
callOnce();
```

## License

Copyright Β© 2020 AntΓ³nio Almeida (promatik) and contributors

Licensed under the MIT license, see [LICENSE.md](LICENSE.md) for details.