Project

General

Profile

Download (999 Bytes) Statistics
| Branch: | Tag: | Revision:

haketilo / common / settings_query.js @ 5957fbee

1
/**
2
 * Hachette querying page settings with regard to wildcard records
3
 *
4
 * Copyright (C) 2021 Wojtek Kosior
5
 * Redistribution terms are gathered in the `copyright' file.
6
 */
7

    
8
/*
9
 * IMPORTS_START
10
 * IMPORT TYPE_PREFIX
11
 * IMPORT for_each_possible_pattern
12
 * IMPORTS_END
13
 */
14

    
15
function check_pattern(storage, pattern, multiple, matched)
16
{
17
    const settings = storage.get(TYPE_PREFIX.PAGE, pattern);
18

    
19
    if (settings === undefined)
20
	return;
21

    
22
    matched.push([pattern, settings]);
23

    
24
    if (!multiple)
25
	return false;
26
}
27

    
28
function query(storage, url, multiple)
29
{
30
    const matched = [];
31
    const cb = p => check_pattern(storage, p, multiple, matched);
32
    for_each_possible_pattern(url, cb);
33

    
34
    return multiple ? matched : (matched[0] || [undefined, undefined]);
35
}
36

    
37
function query_best(storage, url)
38
{
39
    return query(storage, url, false);
40
}
41

    
42
function query_all(storage, url)
43
{
44
    return query(storage, url, true);
45
}
46

    
47
/*
48
 * EXPORTS_START
49
 * EXPORT query_best
50
 * EXPORT query_all
51
 * EXPORTS_END
52
 */
(10-10/13)