seia.js
Version:
Lightweight SSR framework for React Server Components
18 lines (17 loc) • 653 B
JavaScript
export const trimPrefix = (path, prefix)=>path.startsWith(prefix) ? path.slice(prefix.length) : path;
export const isObject = (value)=>Object.prototype.toString.call(value) === '[object Object]';
export const parseAnchorId = (id)=>{
const i = id.indexOf('#');
return i === -1 ? {
path: id,
anchor: null
} : {
path: id.slice(0, Math.max(0, i)),
anchor: id.slice(Math.max(0, i + 1))
};
};
export const mustParseAnchorId = (id)=>{
const parsed = parseAnchorId(id);
if (parsed.anchor === null) throw new Error(`Can't extract anchor information from the given resolveId: ${id}`);
return parsed;
};