UNPKG

object-replace-mustache

Version:

replace placeholders of an object with a view like you would use mustache.render for strings

19 lines (15 loc) 520 B
export const isPlainObject = (value: any): value is Record<string, any> => !!value && [undefined, Object].includes(value.constructor) function escape(str: string) { return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') // $& means the whole matched string } export const delimitersMustache: [string, string] = ['{{', '}}'] export const regexForDelimiters = ( delimiters: [string, string], flags?: string, ) => { return new RegExp( `^${escape(delimiters[0])}(.*?)${escape(delimiters[1])}$`, flags, ) }