first commit
This commit is contained in:
17
build/node_modules/css-select-base-adapter/.gitattributes
generated
vendored
Normal file
17
build/node_modules/css-select-base-adapter/.gitattributes
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
||||
|
||||
# Custom for Visual Studio
|
||||
*.cs diff=csharp
|
||||
|
||||
# Standard to msysgit
|
||||
*.doc diff=astextplain
|
||||
*.DOC diff=astextplain
|
||||
*.docx diff=astextplain
|
||||
*.DOCX diff=astextplain
|
||||
*.dot diff=astextplain
|
||||
*.DOT diff=astextplain
|
||||
*.pdf diff=astextplain
|
||||
*.PDF diff=astextplain
|
||||
*.rtf diff=astextplain
|
||||
*.RTF diff=astextplain
|
||||
85
build/node_modules/css-select-base-adapter/.npmignore
generated
vendored
Normal file
85
build/node_modules/css-select-base-adapter/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules
|
||||
jspm_packages
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# =========================
|
||||
# Operating System Files
|
||||
# =========================
|
||||
|
||||
# OSX
|
||||
# =========================
|
||||
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
# Windows
|
||||
# =========================
|
||||
|
||||
# Windows image file caches
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
|
||||
# Folder config file
|
||||
Desktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
131
build/node_modules/css-select-base-adapter/index.js
generated
vendored
Normal file
131
build/node_modules/css-select-base-adapter/index.js
generated
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = adapterFactory;
|
||||
|
||||
function adapterFactory(implementation){
|
||||
ensureImplementation(implementation);
|
||||
|
||||
var adapter = {}
|
||||
|
||||
var baseAdapter = {
|
||||
removeSubsets: function (nodes){
|
||||
return removeSubsets(adapter, nodes);
|
||||
},
|
||||
existsOne: function(test, elems){
|
||||
return existsOne(adapter, test, elems);
|
||||
},
|
||||
getSiblings: function(elem){
|
||||
return getSiblings(adapter, elem);
|
||||
},
|
||||
hasAttrib: function(elem, name){
|
||||
return hasAttrib(adapter, elem, name);
|
||||
},
|
||||
findOne: function(test, arr){
|
||||
return findOne(adapter, test, arr);
|
||||
},
|
||||
findAll: function(test, elems){
|
||||
return findAll(adapter, test, elems)
|
||||
}
|
||||
};
|
||||
|
||||
Object.assign(adapter, baseAdapter, implementation);
|
||||
|
||||
return adapter;
|
||||
}
|
||||
|
||||
var expectImplemented = [
|
||||
"isTag", "getAttributeValue", "getChildren", "getName", "getParent",
|
||||
"getText"
|
||||
];
|
||||
|
||||
function ensureImplementation(implementation){
|
||||
if(!implementation) throw new TypeError("Expected implementation")
|
||||
|
||||
var notImplemented = expectImplemented.filter(function(fname){
|
||||
return typeof implementation[fname] !== "function";
|
||||
});
|
||||
|
||||
if(notImplemented.length){
|
||||
var notList = "(" + notImplemented.join(", ") + ")";
|
||||
var message = "Expected functions " + notList + " to be implemented";
|
||||
throw new Error(message);
|
||||
}
|
||||
}
|
||||
|
||||
function removeSubsets(adapter, nodes){
|
||||
var idx = nodes.length, node, ancestor, replace;
|
||||
|
||||
// Check if each node (or one of its ancestors) is already contained in the
|
||||
// array.
|
||||
while(--idx > -1){
|
||||
node = ancestor = nodes[idx];
|
||||
|
||||
// Temporarily remove the node under consideration
|
||||
nodes[idx] = null;
|
||||
replace = true;
|
||||
|
||||
while(ancestor){
|
||||
if(nodes.indexOf(ancestor) > -1){
|
||||
replace = false;
|
||||
nodes.splice(idx, 1);
|
||||
break;
|
||||
}
|
||||
ancestor = adapter.getParent(ancestor)
|
||||
}
|
||||
|
||||
// If the node has been found to be unique, re-insert it.
|
||||
if(replace){
|
||||
nodes[idx] = node;
|
||||
}
|
||||
}
|
||||
|
||||
return nodes;
|
||||
}
|
||||
|
||||
function existsOne(adapter, test, elems){
|
||||
return elems.some(function(elem){
|
||||
return adapter.isTag(elem) ?
|
||||
test(elem) || adapter.existsOne(test, adapter.getChildren(elem)) :
|
||||
false;
|
||||
});
|
||||
}
|
||||
|
||||
function getSiblings(adapter, elem){
|
||||
var parent = adapter.getParent(elem);
|
||||
return parent && adapter.getChildren(parent);
|
||||
}
|
||||
|
||||
|
||||
function hasAttrib(adapter, elem, name){
|
||||
return adapter.getAttributeValue(elem,name) !== undefined
|
||||
}
|
||||
|
||||
function findOne(adapter, test, arr){
|
||||
var elem = null;
|
||||
|
||||
for(var i = 0, l = arr.length; i < l && !elem; i++){
|
||||
if(test(arr[i])){
|
||||
elem = arr[i];
|
||||
} else {
|
||||
var childs = adapter.getChildren(arr[i]);
|
||||
if(childs && childs.length > 0){
|
||||
elem = adapter.findOne(test, childs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return elem;
|
||||
}
|
||||
|
||||
function findAll(adapter, test, elems){
|
||||
var result = [];
|
||||
|
||||
for(var i = 0, j = elems.length; i < j; i++){
|
||||
if(!adapter.isTag(elems[i])) continue;
|
||||
if(test(elems[i])) result.push(elems[i]);
|
||||
var childs = adapter.getChildren(elems[i]);
|
||||
if(childs) result = result.concat(adapter.findAll(test, childs));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
53
build/node_modules/css-select-base-adapter/package.json
generated
vendored
Normal file
53
build/node_modules/css-select-base-adapter/package.json
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
{
|
||||
"_from": "css-select-base-adapter@~0.1.0",
|
||||
"_id": "css-select-base-adapter@0.1.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-AQKz0UYw34bD65+p9UVicBBs+ZA=",
|
||||
"_location": "/css-select-base-adapter",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "css-select-base-adapter@~0.1.0",
|
||||
"name": "css-select-base-adapter",
|
||||
"escapedName": "css-select-base-adapter",
|
||||
"rawSpec": "~0.1.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "~0.1.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/imagemin-svgo/svgo"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/css-select-base-adapter/-/css-select-base-adapter-0.1.0.tgz",
|
||||
"_shasum": "0102b3d14630df86c3eb9fa9f5456270106cf990",
|
||||
"_spec": "css-select-base-adapter@~0.1.0",
|
||||
"_where": "/Users/asciidisco/Desktop/asciidisco.com/build/node_modules/imagemin-svgo/node_modules/svgo",
|
||||
"author": {
|
||||
"name": "Nik Coughlin",
|
||||
"email": "nrkn.com@gmail.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/nrkn/css-select-base-adapter/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "Provides some base functions needed by a css-select adapter so that you don't have to implement the whole thing.",
|
||||
"homepage": "https://github.com/nrkn/css-select-base-adapter#readme",
|
||||
"keywords": [
|
||||
"css",
|
||||
"select",
|
||||
"adapter",
|
||||
"css-select"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "css-select-base-adapter",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/nrkn/css-select-base-adapter.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"version": "0.1.0"
|
||||
}
|
||||
44
build/node_modules/css-select-base-adapter/readme.md
generated
vendored
Normal file
44
build/node_modules/css-select-base-adapter/readme.md
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
# css-select-base-adapter
|
||||
|
||||
Provides some base functions needed by a
|
||||
[`css-select`](https://github.com/fb55/css-select) adapter so that you don't
|
||||
have to implement the whole thing.
|
||||
|
||||
## usage
|
||||
|
||||
```javascript
|
||||
var baseAdapter = require('css-select-base-adapter');
|
||||
|
||||
var myAdapter = {
|
||||
// your partial implementation here
|
||||
};
|
||||
|
||||
// get an adapter with everything needed by css-select
|
||||
var adapter = baseAdapter(myAdapter);
|
||||
|
||||
// use adapter with css-select...
|
||||
```
|
||||
|
||||
## how it works
|
||||
|
||||
An adapter for `css-select` requires the following functions to be implemented:
|
||||
|
||||
```
|
||||
isTag, existsOne, getAttributeValue, getChildren, getName, getParent,
|
||||
getSiblings, getText, hasAttrib, removeSubsets, findAll, findOne
|
||||
```
|
||||
|
||||
You can pass this module a more minimal implementation and it will return a full
|
||||
adapter that fills in any missing functions, provided that you implement at
|
||||
least:
|
||||
|
||||
```
|
||||
isTag, getAttributeValue, getChildren, getName, getParent, getText
|
||||
```
|
||||
|
||||
If you provide any of the other methods required of an adapter, the base adapter
|
||||
will use your implementation instead of its own.
|
||||
|
||||
See the
|
||||
[`css-select` readme](https://github.com/fb55/css-select/blob/master/README.md)
|
||||
for more information on the required function signatures.
|
||||
34
build/node_modules/css-select-base-adapter/test/data.js
generated
vendored
Normal file
34
build/node_modules/css-select-base-adapter/test/data.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
'use strict'
|
||||
|
||||
const walk = ( node, parent, cb ) => {
|
||||
cb( node, parent )
|
||||
|
||||
if( Array.isArray( node.children ) )
|
||||
node.children.forEach( child => walk( child, node, cb ) )
|
||||
}
|
||||
|
||||
const data = {
|
||||
name: 'div',
|
||||
attribs: {
|
||||
id: 'container',
|
||||
class: 'message'
|
||||
},
|
||||
children: [
|
||||
{
|
||||
name: 'strong',
|
||||
attribs: {
|
||||
class: 'message'
|
||||
},
|
||||
children: [
|
||||
{ text: 'Hello' }
|
||||
]
|
||||
},
|
||||
{ text: ', World!' }
|
||||
]
|
||||
}
|
||||
|
||||
walk( data, null, ( node, parent ) => {
|
||||
if( parent ) node.parent = parent
|
||||
})
|
||||
|
||||
module.exports = [ data ]
|
||||
22
build/node_modules/css-select-base-adapter/test/implementation.js
generated
vendored
Normal file
22
build/node_modules/css-select-base-adapter/test/implementation.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
'use strict'
|
||||
|
||||
const implementation = {
|
||||
isTag: node => node !== undefined && 'name' in node,
|
||||
getAttributeValue: ( elem, name ) => {
|
||||
if( implementation.isTag( elem ) && elem.attribs ) return elem.attribs[ name ]
|
||||
},
|
||||
getChildren: node => node.children,
|
||||
getName: elem => {
|
||||
if( implementation.isTag( elem ) ) return elem.name
|
||||
},
|
||||
getParent: node => node.parent,
|
||||
getText: node => node.children.map( child => {
|
||||
if( child.text ) return child.text
|
||||
|
||||
if( implementation.isTag( child ) ) return implementation.getText( child )
|
||||
|
||||
return ''
|
||||
}).join( '' )
|
||||
}
|
||||
|
||||
module.exports = implementation
|
||||
103
build/node_modules/css-select-base-adapter/test/index.js
generated
vendored
Normal file
103
build/node_modules/css-select-base-adapter/test/index.js
generated
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require( 'assert' )
|
||||
const data = require( './data' )
|
||||
const implementation = require( './implementation' )
|
||||
const baseAdapter = require( '../' )
|
||||
|
||||
const adapter = baseAdapter( implementation )
|
||||
|
||||
const getById = id => adapter.findOne(
|
||||
node => adapter.getAttributeValue( node, 'id' ) === id,
|
||||
data
|
||||
)
|
||||
|
||||
const getByName = name => adapter.findAll(
|
||||
node => adapter.getName( node ) === name,
|
||||
data
|
||||
)
|
||||
|
||||
const getByClass = className => adapter.findAll(
|
||||
node => adapter.getAttributeValue( node, 'class' ) === className,
|
||||
data
|
||||
)
|
||||
|
||||
const existsName = name => adapter.existsOne(
|
||||
node => adapter.getName( node ) === name,
|
||||
data
|
||||
)
|
||||
|
||||
const container = getById( 'container' )
|
||||
const strong = getByName( 'strong' )[ 0 ]
|
||||
const hello = strong.children[ 0 ]
|
||||
const world = container.children[ 1 ]
|
||||
|
||||
describe( 'css-select-base-adapter', () => {
|
||||
it( 'getAttributeValue', () => {
|
||||
assert( container )
|
||||
})
|
||||
|
||||
it( 'getName', () => {
|
||||
assert( strong )
|
||||
})
|
||||
|
||||
it( 'findOne', () => {
|
||||
assert( container )
|
||||
})
|
||||
|
||||
it( 'findAll', () => {
|
||||
const messages = getByClass( 'message' )
|
||||
|
||||
assert.equal( messages.length, 2 )
|
||||
assert.equal( messages[ 0 ], container )
|
||||
assert.equal( messages[ 1 ], strong )
|
||||
})
|
||||
|
||||
it( 'getParent', () => {
|
||||
const parent = adapter.getParent( strong )
|
||||
|
||||
assert.equal( parent, container )
|
||||
})
|
||||
|
||||
it( 'getSiblings', () => {
|
||||
const siblings = adapter.getSiblings( strong )
|
||||
|
||||
assert.equal( siblings[ 0 ], strong )
|
||||
assert.equal( siblings[ 1 ], world )
|
||||
})
|
||||
|
||||
it( 'getChildren', () => {
|
||||
const children = adapter.getChildren( container )
|
||||
|
||||
assert.equal( children[ 0 ], strong )
|
||||
})
|
||||
|
||||
it( 'getText', () => {
|
||||
const text = adapter.getText( container )
|
||||
|
||||
assert.equal( text, 'Hello, World!' )
|
||||
})
|
||||
|
||||
it( 'isTag', () => {
|
||||
assert( adapter.isTag( container ) )
|
||||
assert( adapter.isTag( strong ) )
|
||||
assert( !adapter.isTag( hello ) )
|
||||
})
|
||||
|
||||
it( 'hasAttrib', () => {
|
||||
assert( adapter.hasAttrib( container, 'id' ) )
|
||||
assert( !adapter.hasAttrib( strong, 'id' ) )
|
||||
})
|
||||
|
||||
it( 'existsOne', () => {
|
||||
assert( existsName( 'strong' ) )
|
||||
assert( !existsName( 'blink' ) )
|
||||
})
|
||||
|
||||
it( 'removeSubsets', () => {
|
||||
const removed = adapter.removeSubsets([ container, strong, container ])
|
||||
|
||||
assert.equal( removed.length, 1 )
|
||||
assert.equal( removed[ 0 ], container )
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user