Snippets Collections
export function formatPhoneLink(
  phoneNumberString: string,
  useFormat: boolean = false
): string | null {
  const cleaned = `${phoneNumberString}`.replace(/\D/g, "");

  const match = cleaned.match(/^(1|)?(\d{3})(\d{3})(\d{4})$/);
  if (useFormat && match) {
    const intlCode = match[1] ? "+1 " : "";
    return [intlCode, "(", match[2], ") ", match[3], "-", match[4]].join("");
  }
  return cleaned ?? null;

  // return null;
}
export const addCommaToPrice = (price?: string): string => {
  const priceSplit = price?.split(".");
  if (priceSplit !== undefined) {
    const priceJoin: string = priceSplit[0].replace(
      /\B(?=(\d{3})+(?!\d))/g,
      ","
    );
    return priceJoin;
  }
  return "";
};
star

Fri Dec 11 2020 14:26:09 GMT+0000 (Coordinated Universal Time)

#react.js,javascript
star

Fri Dec 11 2020 14:24:50 GMT+0000 (Coordinated Universal Time)

#react.js,javascript

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension