mikaelvesavuori/figmagic

View on GitHub
bin/frameworks/string/getAlphaInPercent.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { ErrorGetAlphaInPercent } from '../../frameworks/errors/errors';

/**
 * @description Get RGBA alpha value as a percentage string
 */
export const getAlphaInPercent = (color: string): string => {
  if (!color) throw Error(ErrorGetAlphaInPercent);
  const sectioned = color.split(',');
  // @ts-ignore
  return sectioned[sectioned.length - 1].replace(/ /gi, '').replace(')', '') * 100 + '%';
};