forked from autarc/optimal-select
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (27 loc) · 804 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* # Example
*
*
*/
var fs = require('fs')
var cheerio = require('cheerio')
var optimalSelect = require('../lib/index')
var indexHTML = fs.readFileSync(__dirname + '/index.html').toString()
// using cheerio which is baed on htmlparser2
var $ = cheerio.load(indexHTML)
// #1 -
// browser: OptimalSelect.select(document.body)
// "[onload]"
// node: "body"
var node = $('body').get(0)
console.time('A')
console.log('\nA:', optimalSelect.select(node))
console.timeEnd('A')
// #2 -
// browser: OptimalSelect.select(document.querySelectorAll('.divider')[0])
// ".dropdown-menu > .divider:nth-child(2)"
// node: ".dropdown-menu .divider:nth-child(2)"
node = $('.divider').get(0)
console.time('B')
console.log('\nB:', optimalSelect.select(node))
console.timeEnd('B')