2018-05-15 17:30:17 +02:00
/ * *
* @ author n1474335 [ n1474335 @ gmail . com ]
* @ copyright Crown Copyright 2016
* @ license Apache - 2.0
* /
2019-07-09 13:23:59 +02:00
import Operation from "../Operation.mjs" ;
import { search , DOMAIN _REGEX } from "../lib/Extract.mjs" ;
2022-04-14 19:08:16 +02:00
import { caseInsensitiveSort } from "../lib/Sort.mjs" ;
2018-05-15 17:30:17 +02:00
/ * *
* Extract domains operation
* /
class ExtractDomains extends Operation {
/ * *
* ExtractDomains constructor
* /
constructor ( ) {
super ( ) ;
this . name = "Extract domains" ;
this . module = "Regex" ;
2019-08-27 18:59:45 +02:00
this . description = "Extracts fully qualified domain names.<br>Note that this will not include paths. Use <strong>Extract URLs</strong> to find entire URLs." ;
2018-05-15 17:30:17 +02:00
this . inputType = "string" ;
this . outputType = "string" ;
this . args = [
{
2022-04-14 19:08:16 +02:00
name : "Display total" ,
type : "boolean" ,
value : false
} ,
{
name : "Sort" ,
type : "boolean" ,
value : false
} ,
{
name : "Unique" ,
type : "boolean" ,
value : false
2018-05-15 17:30:17 +02:00
}
] ;
}
/ * *
* @ param { string } input
* @ param { Object [ ] } args
* @ returns { string }
* /
run ( input , args ) {
2022-04-14 19:08:16 +02:00
const [ displayTotal , sort , unique ] = args ;
const results = search (
input ,
DOMAIN _REGEX ,
null ,
sort ? caseInsensitiveSort : null ,
unique
) ;
if ( displayTotal ) {
return ` Total found: ${ results . length } \n \n ${ results . join ( "\n" ) } ` ;
} else {
return results . join ( "\n" ) ;
}
2018-05-15 17:30:17 +02:00
}
}
export default ExtractDomains ;