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

Commit

Permalink
fix: fix validation for breakpoint names
Browse files Browse the repository at this point in the history
  • Loading branch information
mg901 committed Jul 21, 2019
1 parent f0f7d83 commit d35692f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
4 changes: 2 additions & 2 deletions breakpoints/validators.js
Expand Up @@ -28,9 +28,9 @@ const validateOrientation = (atrule) => {
// validateBreakpointValue :: (Object, Object) -> Void
const validateBreakpointValue = (breakpoints, atrule) =>
getBreakpointValues(atrule.params).forEach((p) => {
const isValidValue = breakpoints[camelize(p)] || hasPxOrEm(p);
const isValidValue = !!breakpoints[camelize(p)] || hasPxOrEm(p);

if (!isValidValue) {
if (isValidValue) {
throw atrule.error(
`[typographist]: '${p}' is invalid breakpoint name. Use '${makeBreakpointList(
breakpoints,
Expand Down
23 changes: 20 additions & 3 deletions utils/index.js
@@ -1,4 +1,4 @@
const { toRem, modularScale } = require('@typographist/core');
const { toRem, modularScale, pipe, tail, map } = require('@typographist/core');

const ALL_CHARACTERS_AFTER_COLON = /:.+\b/;
const ALL_PARENTHESES = /[()]/g;
Expand Down Expand Up @@ -61,11 +61,28 @@ 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
const calcFontSize = (breakpoints) => (target, breakName = 'initial') => {
const { root, base, ratio } = breakpoints[breakName];
if (!breakpoints[breakName]) {
throw new Error(
`[typographist]: '${toKebabCase(
breakName,
)}' is invalid breakpoint name. Use '${validBreakpointNames(
breakpoints,
).join(', ')}'.`,
);
} else {
const { root, base, ratio } = breakpoints[breakName];

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

// makeBreakpointName :: String -> String
Expand Down

0 comments on commit d35692f

Please sign in to comment.