0.2.0 - Mid migration

This commit is contained in:
Daniel Mason 2022-04-25 14:47:15 +12:00
parent 139e6a915e
commit 7e38fdbd7d
42393 changed files with 5358157 additions and 62 deletions

34
web/node_modules/css-select-base-adapter/test/data.js generated vendored Normal file
View 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 ]

View 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
View 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 )
})
})