mirror of
https://github.com/idanoo/GoScrobble
synced 2025-07-01 13:42:20 +00:00
0.2.0 - Mid migration
This commit is contained in:
parent
139e6a915e
commit
7e38fdbd7d
42393 changed files with 5358157 additions and 62 deletions
17
web/node_modules/css-select-base-adapter/.gitattributes
generated
vendored
Normal file
17
web/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
|
21
web/node_modules/css-select-base-adapter/LICENSE
generated
vendored
Normal file
21
web/node_modules/css-select-base-adapter/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2018 Nik Coughlin
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
131
web/node_modules/css-select-base-adapter/index.js
generated
vendored
Normal file
131
web/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;
|
||||
}
|
25
web/node_modules/css-select-base-adapter/package.json
generated
vendored
Normal file
25
web/node_modules/css-select-base-adapter/package.json
generated
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"name": "css-select-base-adapter",
|
||||
"version": "0.1.1",
|
||||
"description": "Provides some base functions needed by a css-select adapter so that you don't have to implement the whole thing.",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "mocha"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/nrkn/css-select-base-adapter.git"
|
||||
},
|
||||
"keywords": [
|
||||
"css",
|
||||
"select",
|
||||
"adapter",
|
||||
"css-select"
|
||||
],
|
||||
"bugs": {
|
||||
"url": "https://github.com/nrkn/css-select-base-adapter/issues"
|
||||
},
|
||||
"homepage": "https://github.com/nrkn/css-select-base-adapter#readme",
|
||||
"author": "Nik Coughlin <nrkn.com@gmail.com>",
|
||||
"license": "MIT"
|
||||
}
|
70
web/node_modules/css-select-base-adapter/readme.md
generated
vendored
Normal file
70
web/node_modules/css-select-base-adapter/readme.md
generated
vendored
Normal file
|
@ -0,0 +1,70 @@
|
|||
# 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
|
||||
|
||||
`npm install css-select-base-adapter --save`
|
||||
|
||||
```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.
|
||||
|
||||
## license
|
||||
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 Nik Coughlin
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
34
web/node_modules/css-select-base-adapter/test/data.js
generated
vendored
Normal file
34
web/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
web/node_modules/css-select-base-adapter/test/implementation.js
generated
vendored
Normal file
22
web/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
web/node_modules/css-select-base-adapter/test/index.js
generated
vendored
Normal file
103
web/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 )
|
||||
})
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue