/**
 * @since Last modified: 2023-12-29 22:52:18
 * @function sliceFrags
 * @description Get an array of string fragments from a string based on the start and end keywords..
 * @param {object} obj - The parameters.
 * @param {object} obj.str - The original string.
* @param {object} obj.start="{" - The start charactor.
* @param {object} obj.end="}" - The end charactor.
* @param {boolean} obj.contain=true - Whether the result contains starting and ending characters.
 * @returns  {string[]} - The string fragments array.
 * @see {@link https://codepen.io/axui/pen/oNVXMOb|demo @ codepen}
 * @example
 * ax.sliceFrags({str:'I {live} in {your} new house'});
 * <!--Return : ['{live}','{your}']-->
 */
'use strict';
const sliceFrags = ({ str = '', start = '{', end = '}', contain = true }: { str: string, start?: string, end?: string, contain?: boolean }): string[] => {
    let reg = new RegExp(`\\${start}([^\\${end}]+)\\${end}`, 'g'),
        arr = str.match(reg) || [];
    return (!contain && arr.length > 0) ? arr.map((k: string) => k.replace(start, '').replace(end, '')) : arr;
};
export default sliceFrags;
