INNER CODE UNIT · TypeScript

cache

OS-Guild/graphql-to-mongodb · src/common.ts:14

export function cache<T>(cacheObj: object, key: any, callback: cacheCallback<T>): T {
    let item: T = cacheObj[key];

    if (item === undefined) {
        item = callback(key);
        cacheObj[key] = item;
    }

    return item;
}

export function setSuffix(text: string, locate: string, replaceWith: string): string {
    const regex = new RegExp(`${locate}$`);
    return regex.test(text)
        ? text.replace(regex, replaceWith)
        : `${text}${replaceWith}`;
}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…