Skip to main content

getMatchedResource

Callable

  • getMatchedResource<T>(resources: ResourceEntry<T>[], envConfig: Record<string, string>, weights?: Record<string, number>, taskId?: string): T

  • Get the matched record from the resource list.

    @example
    const resources = [
    { selector: ['lang:zh-Hans', 'client:web'], item: "https://exmaple.com/zh/web.html"},
    { selector: ['lang:zh-Hans', 'client:app'], item: "https://exmaple.com/zh/app.html"},
    { selector: ['lang:en', 'client:web'], item: "https://exmaple.com/en/web.html"},
    { selector: ['lang:en', 'client:app'], item: "https://exmaple.com/en/app.html"},
    ];
    const envConfig = {
    lang: 'zh-Hans',
    category: 'image',
    client: 'app',
    };
    const weights = {
    lang: 1,
    };
    const matchedRecord = getMatchedRecord(resources, envConfig, weights);

    Type parameters

    • T

    Parameters

    • resources: ResourceEntry<T>[]

      The resource list.

    • envConfig: Record<string, string>

      Environment variable of current system.

    • weights: Record<string, number> = null
    • taskId: string = 'select-task'

    Returns T

    Matched asset.