fix accessing data prior to scraping
This commit is contained in:
parent
1fed10dc9e
commit
9f9335e248
1 changed files with 9 additions and 15 deletions
|
@ -118,27 +118,24 @@ export async function read(DATA_NAME, CLOUD = 0) {
|
||||||
@param {Array} SOURCE the source of the data
|
@param {Array} SOURCE the source of the data
|
||||||
@param {string} TERM the term to search
|
@param {string} TERM the term to search
|
||||||
@param {Array} ADDITIONAL_PLACES additional places to search
|
@param {Array} ADDITIONAL_PLACES additional places to search
|
||||||
|
@param {object} OPTIONS the options
|
||||||
@return {Array} the results
|
@return {Array} the results
|
||||||
*/
|
*/
|
||||||
export async function search(SOURCE, TERM, ADDITIONAL_PLACES, STRICT = false) {
|
export async function search(SOURCE, TERM, ADDITIONAL_PLACES, STRICT = false, OPTIONS = {}) {
|
||||||
let DATA = await read(SOURCE);
|
let DATA = await read(SOURCE, (OPTIONS[`cloud`] != null) ? OPTIONS[`cloud`] : 0);
|
||||||
let RESULTS;
|
let RESULTS;
|
||||||
|
|
||||||
if (DATA) {
|
if (DATA) {
|
||||||
RESULTS = {};
|
RESULTS = {};
|
||||||
|
|
||||||
if (TERM) {
|
if (TERM && (!(typeof ADDITIONAL_PLACES).includes(`str`) || !ADDITIONAL_PLACES)) {
|
||||||
// Sequentially search through the data, first by key.
|
// Sequentially search through the data, first by key.
|
||||||
let key_number = {"total": (Object.keys(DATA)).length, "current": 0};
|
let key_number = {"total": (Object.keys(DATA)).length, "current": 0};
|
||||||
|
|
||||||
while (key_number[`current`] < key_number[`total`]) {
|
while (key_number[`current`] < key_number[`total`]) {
|
||||||
let DATA_NAME = (Object.keys(DATA))[key_number[`current`]]
|
let DATA_NAME = (Object.keys(DATA))[key_number[`current`]]
|
||||||
|
|
||||||
if (
|
if (STRICT ? DATA_NAME == TERM : (DATA_NAME.includes(TERM) || TERM.includes(DATA_NAME))) {
|
||||||
STRICT
|
|
||||||
? DATA_NAME == TERM
|
|
||||||
: (DATA_NAME.includes(TERM) || TERM.includes(DATA_NAME))
|
|
||||||
) {
|
|
||||||
RESULTS[DATA_NAME] = DATA[DATA_NAME];
|
RESULTS[DATA_NAME] = DATA[DATA_NAME];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,10 +144,7 @@ export async function search(SOURCE, TERM, ADDITIONAL_PLACES, STRICT = false) {
|
||||||
|
|
||||||
// Then, get the additional places.
|
// Then, get the additional places.
|
||||||
if (
|
if (
|
||||||
(ADDITIONAL_PLACES != null ? Array.isArray(ADDITIONAL_PLACES) : false)
|
(ADDITIONAL_PLACES != null ? Array.isArray(ADDITIONAL_PLACES) : false) ? ADDITIONAL_PLACES.length > 0 : false) {
|
||||||
? ADDITIONAL_PLACES.length > 0
|
|
||||||
: false
|
|
||||||
) {
|
|
||||||
for (let PARAMETER_PRIORITY_NUMBER = 0; PARAMETER_PRIORITY_NUMBER < ADDITIONAL_PLACES.length; PARAMETER_PRIORITY_NUMBER++) {
|
for (let PARAMETER_PRIORITY_NUMBER = 0; PARAMETER_PRIORITY_NUMBER < ADDITIONAL_PLACES.length; PARAMETER_PRIORITY_NUMBER++) {
|
||||||
// Recursively search
|
// Recursively search
|
||||||
RESULTS = Object.assign({}, RESULTS, search(SOURCE, TERM, ADDITIONAL_PLACES[PARAMETER_PRIORITY_NUMBER], STRICT));
|
RESULTS = Object.assign({}, RESULTS, search(SOURCE, TERM, ADDITIONAL_PLACES[PARAMETER_PRIORITY_NUMBER], STRICT));
|
||||||
|
@ -162,11 +156,11 @@ export async function search(SOURCE, TERM, ADDITIONAL_PLACES, STRICT = false) {
|
||||||
let VALUE = {};
|
let VALUE = {};
|
||||||
VALUE[`test`] = TERM;
|
VALUE[`test`] = TERM;
|
||||||
|
|
||||||
for (let DICTIONARY_INDEX = 0; DICTIONARY_INDEX < (Object.keys(DATA)).length; DICTIONARY_INDEX) {
|
for (let DICTIONARY_INDEX = 0; DICTIONARY_INDEX < (Object.keys(DATA)).length; DICTIONARY_INDEX++) {
|
||||||
VALUE[`parent`] = DATA[(Object.keys(DATA))[DICTIONARY_INDEX]];
|
VALUE[`parent`] = DATA[(Object.keys(DATA))[DICTIONARY_INDEX]];
|
||||||
|
|
||||||
if (((typeof VALUE[`parent`]).includes(`obj`) && !Array.isArray(VALUE[`parent`]) && VALUE[`parent`] != null) ? (Object.keys(VALUE[`parent`])).length > 0 : false ) {
|
if (((typeof VALUE[`parent`]).includes(`obj`) && !Array.isArray(VALUE[`parent`]) && VALUE[`parent`] != null) ? (Object.keys(VALUE[`parent`])).length > 0 : false ) {
|
||||||
VALUE[`current`] = (VALUE[`parent`])[`test`];
|
VALUE[`current`] = VALUE[`parent`][ADDITIONAL_PLACES];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VALUE[`current`]) {
|
if (VALUE[`current`]) {
|
||||||
|
@ -193,7 +187,7 @@ export async function search(SOURCE, TERM, ADDITIONAL_PLACES, STRICT = false) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return RESULTS;
|
return RESULTS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue