mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Convert data from ResourceStore based on preferences
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user