Skip to content
This repository has been archived by the owner on Feb 17, 2021. It is now read-only.

Commit

Permalink
refactor: remove throw from "calcFontSize"
Browse files Browse the repository at this point in the history
  • Loading branch information
mg901 committed Jul 29, 2019
1 parent e66f0a4 commit 4bc6efc
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions utils/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { toRem, modularScale, pipe, tail, map } = require('@typographist/core');
const { toRem, modularScale } = require('@typographist/core');

const ALL_CHARACTERS_AFTER_COLON = /:.+\b/;
const ALL_PARENTHESES = /[()]/g;
Expand Down Expand Up @@ -61,24 +61,10 @@ const toEmOrNot = (x) => (hasPx(x) ? toEm(x) : x);
// toPxOrNot :: String -> String
const toPxOrNot = (x) => (hasEm(x) ? toPx(x) : x);

// validBreakpointNames :: Object -> [String]
const validBreakpointNames = pipe(
Object.keys,
tail,
map(toKebabCase),
);

// calcFontSize :: Object -> (Number | String, String) -> String
// eslint-disable-next-line consistent-return
const calcFontSize = (breakpoints) => (target, breakName = 'initial') => {
if (!breakpoints[breakName]) {
throw new Error(
`[typographist]: '${toKebabCase(
breakName,
)}' is invalid breakpoint name. Use '${validBreakpointNames(
breakpoints,
).join(', ')}'.`,
);
} else {
if (breakpoints[breakName]) {
const { root, base, ratio } = breakpoints[breakName];

return toRem(root, modularScale(Number(target), base, ratio));
Expand Down

0 comments on commit 4bc6efc

Please sign in to comment.