feat: Convert data from ResourceStore based on preferences

This commit is contained in:
Joachim Van Herwegen
2020-08-04 10:23:00 +02:00
parent d6a35f9954
commit 5e1bb10f81
17 changed files with 565 additions and 79 deletions

View File

@@ -12,4 +12,33 @@ import { Readable } from 'stream';
*/
export const ensureTrailingSlash = (path: string): string => path.replace(/\/*$/u, '/');
/**
* Joins all strings of a stream.
* @param stream - Stream of strings.
*
* @returns The joined string.
*/
export const readableToString = async(stream: Readable): Promise<string> => (await arrayifyStream(stream)).join('');
/**
* Checks if the given two media types/ranges match each other.
* Takes wildcards into account.
* @param mediaA - Media type to match.
* @param mediaB - Media type to match.
*
* @returns True if the media type patterns can match each other.
*/
export const matchingMediaType = (mediaA: string, mediaB: string): boolean => {
const [ typeA, subTypeA ] = mediaA.split('/');
const [ typeB, subTypeB ] = mediaB.split('/');
if (typeA === '*' || typeB === '*') {
return true;
}
if (typeA !== typeB) {
return false;
}
if (subTypeA === '*' || subTypeB === '*') {
return true;
}
return subTypeA === subTypeB;
};