File tree Expand file tree Collapse file tree 7 files changed +68
-38
lines changed Expand file tree Collapse file tree 7 files changed +68
-38
lines changed Original file line number Diff line number Diff line change 1
- extends: "@gianlucaguarini/eslint-config"
1
+ extends: "@gianlucaguarini/eslint-config"
2
+ env:
3
+ mocha: true
Original file line number Diff line number Diff line change @@ -10,6 +10,9 @@ before_install:
10
10
11
11
12
12
-
npm i @gianlucaguarini/[email protected]
13
+
14
+
15
+ before_script :
13
16
- npm run build
14
17
15
18
notifications :
Original file line number Diff line number Diff line change @@ -10,9 +10,19 @@ Modern DOM query selectors helpers written in es2015
10
10
## Usage
11
11
12
12
``` 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' ))
14
25
15
- $ (' h1' ).forEach ((h1 ) => console .log (h1 .innerHTML ))
16
26
```
17
27
18
28
## API
Original file line number Diff line number Diff line change
1
+ import domToArray from 'bianco.dom-to-array'
1
2
2
3
/**
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
4
5
* @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
6
7
* @returns { Object } DOM nodes in an array like object
7
8
*/
8
9
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
+ )
21
14
}
Original file line number Diff line number Diff line change 1
1
{
2
- "name" : " bianco- query" ,
3
- "version" : " 0.0.2 " ,
2
+ "name" : " bianco. query" ,
3
+ "version" : " 0.0.0 " ,
4
4
"description" : " Modern DOM query selectors helpers written in es2015" ,
5
5
"main" : " index.js" ,
6
6
"jsnext:main" : " index.next.js" ,
7
7
"scripts" : {
8
8
"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 "
12
12
},
13
13
"files" : [
14
14
" index.js" ,
35
35
"homepage" : " https://github.com/biancojs/query#readme" ,
36
36
"devDependencies" : {
37
37
"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"
39
43
}
40
44
}
Original file line number Diff line number Diff line change
1
+ export default {
2
+ entry : 'index.next.js' ,
3
+ targets : [
4
+ {
5
+ dest : 'index.js' ,
6
+ format : 'cjs'
7
+ }
8
+ ]
9
+ }
Original file line number Diff line number Diff line change 1
1
require ( 'jsdom-global' ) ( )
2
2
const assert = require ( 'assert' )
3
3
const $ = require ( './' )
4
+ const body = document . body
4
5
5
- function before ( ) {
6
- var div = document . createElement ( 'div' )
6
+ describe ( 'Bianco query' , function ( ) {
7
+ before ( function ( ) {
8
+ var div = document . createElement ( 'div' )
7
9
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
+ } )
16
18
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
+ } )
18
25
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
+ } )
You can’t perform that action at this time.
0 commit comments