Skip to content

Commit 2042e04

Browse files
updated: dependencies, npm name and project setup
1 parent ddb85bb commit 2042e04

File tree

7 files changed

+68
-38
lines changed

7 files changed

+68
-38
lines changed

.eslintrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
extends: "@gianlucaguarini/eslint-config"
1+
extends: "@gianlucaguarini/eslint-config"
2+
env:
3+
mocha: true

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ before_install:
1010
1111
1212
- npm i @gianlucaguarini/[email protected]
13+
14+
15+
before_script:
1316
- npm run build
1417

1518
notifications:

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,19 @@ Modern DOM query selectors helpers written in es2015
1010
## Usage
1111

1212
```js
13-
import $ from 'bianco-query'
13+
import $ from 'bianco.query'
14+
15+
const footer = document.querySelector('.main-footer')
16+
const header = document.querySelector('.main-header')
17+
18+
// convert DOM nodes into arrays
19+
$(footer)
20+
.concat($(header))
21+
.forEach(el => el.classList.add('fade-in'))
22+
23+
// handle DOM queries
24+
$('h1', 'main').forEach(h1 => h1.classList.add('main-title'))
1425

15-
$('h1').forEach((h1) => console.log(h1.innerHTML))
1626
```
1727

1828
## API

index.next.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
1+
import domToArray from 'bianco.dom-to-array'
12

23
/**
3-
* Simple helper to find DOM nodes returning them as Array
4+
* Simple helper to find DOM nodes returning them as array like loopable object
45
* @param { String|DOMNodeList } selector - either the query or the DOM nodes to arraify
5-
* @param { HTMLElement } ctx - context defining where the query will search DOM nodes
6+
* @param { HTMLElement } ctx - context defining where the query will search for the DOM nodes
67
* @returns { Object } DOM nodes in an array like object
78
*/
89
export default function $(selector, ctx) {
9-
var els = selector
10-
11-
// find the DOM nodes
12-
if (typeof selector === 'string')
13-
els = (ctx || document).querySelectorAll(selector)
14-
15-
16-
// arraify the DOM nodes found
17-
if (!Array.isArray(els))
18-
els = Array.from(els)
19-
20-
return els
10+
return domToArray(typeof selector === 'string' ?
11+
(ctx || document).querySelectorAll(selector) :
12+
selector
13+
)
2114
}

package.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
2-
"name": "bianco-query",
3-
"version": "0.0.2",
2+
"name": "bianco.query",
3+
"version": "0.0.0",
44
"description": "Modern DOM query selectors helpers written in es2015",
55
"main": "index.js",
66
"jsnext:main": "index.next.js",
77
"scripts": {
88
"prepublish": "npm run build && npm test",
9-
"lint": "eslint index.next.js test.js",
10-
"build": "rollup -f cjs -- index.next.js > index.js",
11-
"test": "npm run lint && node test"
9+
"lint": "eslint index.next.js test.js rollup.config.js",
10+
"build": "rollup -c",
11+
"test": "npm run lint && mocha test.js"
1212
},
1313
"files": [
1414
"index.js",
@@ -35,6 +35,10 @@
3535
"homepage": "https://github.com/biancojs/query#readme",
3636
"devDependencies": {
3737
"jsdom": "9.5.0",
38-
"jsdom-global": "2.1.0"
38+
"jsdom-global": "2.1.0",
39+
"rollup-plugin-node-resolve": "^2.0.0"
40+
},
41+
"dependencies": {
42+
"bianco.dom-to-array": "^0.0.2"
3943
}
4044
}

rollup.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default {
2+
entry: 'index.next.js',
3+
targets: [
4+
{
5+
dest: 'index.js',
6+
format: 'cjs'
7+
}
8+
]
9+
}

test.js

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
11
require('jsdom-global')()
22
const assert = require('assert')
33
const $ = require('./')
4+
const body = document.body
45

5-
function before() {
6-
var div = document.createElement('div')
6+
describe('Bianco query', function() {
7+
before(function() {
8+
var div = document.createElement('div')
79

8-
div.innerHTML = `
9-
<ul>
10-
<li class='item'></li>
11-
<li class='item'></li>
12-
</ul>
13-
`
14-
document.body.appendChild(div)
15-
}
10+
div.innerHTML = `
11+
<ul>
12+
<li class='item'></li>
13+
<li class='item'></li>
14+
</ul>
15+
`
16+
body.appendChild(div)
17+
})
1618

17-
before()
19+
it('It can query the DOM properly', function() {
20+
const div = $('div')
21+
assert.equal(typeof div, 'object')
22+
assert.equal(div.length, 1)
23+
assert.equal($('.item', div[0]).length, 2)
24+
})
1825

19-
const div = $('div')
20-
assert.equal(typeof div, 'object')
21-
assert.equal(div.length, 1)
22-
assert.equal($('.item', div[0]).length, 2)
26+
it('It can handle also DOM nodes', function() {
27+
const els = $(document.querySelector('div')).concat($(document.querySelector('ul')))
28+
assert.equal(typeof els, 'object')
29+
assert.equal(els.length, 2)
30+
})
31+
})

0 commit comments

Comments
 (0)