Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getCacheKey(operation) {
const { key } = operation
const cacheKey = fnv1a(
'' + url + JSON.stringify(getFetchOptions(operation) + key),
)
return cacheKey
}
private createQuery(query: DocumentNode): string {
if (this.queryCache.has(query)) {
return this.queryCache.get(query)!;
}
const queryString = print(addTypenames(query));
this.queryCache.set(query, queryString);
const queryId = String(hash(queryString));
this.queryIds.set(query, queryId);
this.dataCache.set(queryId, new Map());
return queryString;
}
function generateKey(keyObj) {
return fnv1a(JSON.stringify(keyObj)).toString(36)
}
return (text, options) => {
const key = hash(`${text}${JSON.stringify(options)}`);
if (cache[key] !== undefined) {
return cache[key];
}
sandbox.font = Text.getFontDefinition(options);
const lines = formatString(text);
const height = options.fontSize * options.lineHeight * lines.length;
const width = lines.reduce((max, line) => Math.max(max, sandbox.measureText(line).width), 0);
const result = {
width,
height,
};
cache[key] = result;
return result;
};
})();