Skip to content

Commit

Permalink
refactor(library): export stmt refactor
Browse files Browse the repository at this point in the history
Refactors export statements to reduce library size.
  • Loading branch information
bhough committed May 5, 2019
1 parent 70f373e commit 6f72ff0
Show file tree
Hide file tree
Showing 49 changed files with 72 additions and 147 deletions.
4 changes: 1 addition & 3 deletions src/color/complement.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ import toColorString from './toColorString'
* background: "rgba(153,153,153,0.7)";
* }
*/
function complement(color: string): string {
export default function complement(color: string): string {
if (color === 'transparent') return color
const hslColor = parseToHsl(color)
return toColorString({
...hslColor,
hue: (hslColor.hue + 180) % 360,
})
}

export default complement
4 changes: 1 addition & 3 deletions src/color/getLuminance.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import parseToRgb from './parseToRgb'
* background: "rgba(58, 133, 255, 1)";
* }
*/
function getLuminance(color: string): number {
export default function getLuminance(color: string): number {
if (color === 'transparent') return 0
const rgbColor: { [string]: number } = parseToRgb(color)
const [r, g, b] = Object.keys(rgbColor).map(key => {
Expand All @@ -38,5 +38,3 @@ function getLuminance(color: string): number {
})
return parseFloat((0.2126 * r + 0.7152 * g + 0.0722 * b).toFixed(3))
}

export default getLuminance
4 changes: 1 addition & 3 deletions src/color/grayscale.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ import toColorString from './toColorString'
* background: "rgba(153,153,153,0.7)";
* }
*/
function grayscale(color: string): string {
export default function grayscale(color: string): string {
if (color === 'transparent') return color
return toColorString({
...parseToHsl(color),
saturation: 0,
})
}

export default grayscale
4 changes: 1 addition & 3 deletions src/color/hsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import type { HslColor } from '../types/color'
* background: "#b3191c";
* }
*/
function hsl(
export default function hsl(
value: HslColor | number,
saturation?: number,
lightness?: number,
Expand All @@ -48,5 +48,3 @@ function hsl(

throw new PolishedError(1)
}

export default hsl
6 changes: 3 additions & 3 deletions src/color/hslToColorString.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ import type { HslColor, HslaColor } from '../types/color'
* background: "rgba(179,25,25,0.72)";
* }
*/
function hslToColorString(color: HslColor | HslaColor | number): string {
export default function hslToColorString(
color: HslColor | HslaColor | number,
): string {
if (
typeof color === 'object'
&& typeof color.hue === 'number'
Expand All @@ -54,5 +56,3 @@ function hslToColorString(color: HslColor | HslaColor | number): string {

throw new PolishedError(45)
}

export default hslToColorString
4 changes: 1 addition & 3 deletions src/color/hsla.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import type { HslaColor } from '../types/color'
* background: "#b3191c";
* }
*/
function hsla(
export default function hsla(
value: HslaColor | number,
saturation?: number,
lightness?: number,
Expand Down Expand Up @@ -61,5 +61,3 @@ function hsla(

throw new PolishedError(2)
}

export default hsla
4 changes: 1 addition & 3 deletions src/color/invert.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import toColorString from './toColorString'
* background: "rgba(154,155,50,0.7)";
* }
*/
function invert(color: string): string {
export default function invert(color: string): string {
if (color === 'transparent') return color
// parse color string to rgb
const value = parseToRgb(color)
Expand All @@ -36,5 +36,3 @@ function invert(color: string): string {
blue: 255 - value.blue,
})
}

export default invert
4 changes: 1 addition & 3 deletions src/color/parseToHsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ import type { HslColor, HslaColor } from '../types/color'
* // Assigns `{ hue: 128, saturation: 1, lightness: 0.5, alpha: 0.75 }` to color2
* const color2 = parseToHsl('hsla(128, 100%, 50%, 0.75)');
*/
function parseToHsl(color: string): HslColor | HslaColor {
export default function parseToHsl(color: string): HslColor | HslaColor {
// Note: At a later stage we can optimize this function as right now a hsl
// color would be parsed converted to rgb values and converted back to hsl.
return rgbToHsl(parseToRgb(color))
}

export default parseToHsl
4 changes: 1 addition & 3 deletions src/color/parseToRgb.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const hslaRegex = /^hsla\(\s*(\d{0,3}[.]?[0-9]+)\s*,\s*(\d{1,3})%\s*,\s*(\d{1,3}
* // Assigns `{ red: 92, green: 102, blue: 112, alpha: 0.75 }` to color2
* const color2 = parseToRgb('hsla(210, 10%, 40%, 0.75)');
*/
function parseToRgb(color: string): RgbColor | RgbaColor {
export default function parseToRgb(color: string): RgbColor | RgbaColor {
if (typeof color !== 'string') {
throw new PolishedError(3)
}
Expand Down Expand Up @@ -122,5 +122,3 @@ function parseToRgb(color: string): RgbColor | RgbaColor {
}
throw new PolishedError(5)
}

export default parseToRgb
4 changes: 1 addition & 3 deletions src/color/readableColor.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ import getLuminance from './getLuminance'
* }
*/

function readableColor(
export default function readableColor(
color: string,
lightReturnColor: string = '#000',
darkReturnColor: string = '#fff',
): string {
return getLuminance(color) > 0.179 ? lightReturnColor : darkReturnColor
}

export default readableColor
8 changes: 5 additions & 3 deletions src/color/rgb.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ import type { RgbColor } from '../types/color'
* background: "#ffcd64";
* }
*/
function rgb(value: RgbColor | number, green?: number, blue?: number): string {
export default function rgb(
value: RgbColor | number,
green?: number,
blue?: number,
): string {
if (
typeof value === 'number'
&& typeof green === 'number'
Expand All @@ -47,5 +51,3 @@ function rgb(value: RgbColor | number, green?: number, blue?: number): string {

throw new PolishedError(6)
}

export default rgb
4 changes: 1 addition & 3 deletions src/color/rgbToColorString.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import type { RgbColor, RgbaColor } from '../types/color'
* background: "rgba(255,205,100,0.72)";
* }
*/
function rgbToColorString(color: RgbColor | RgbaColor): string {
export default function rgbToColorString(color: RgbColor | RgbaColor): string {
if (
typeof color === 'object'
&& typeof color.red === 'number'
Expand All @@ -50,5 +50,3 @@ function rgbToColorString(color: RgbColor | RgbaColor): string {

throw new PolishedError(46)
}

export default rgbToColorString
4 changes: 1 addition & 3 deletions src/color/rgba.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import type { RgbaColor } from '../types/color'
* background: "rgba(0,0,0,0.7)";
* }
*/
function rgba(
export default function rgba(
firstValue: RgbaColor | number | string,
secondValue?: number,
thirdValue?: number,
Expand Down Expand Up @@ -74,5 +74,3 @@ function rgba(

throw new PolishedError(7)
}

export default rgba
4 changes: 1 addition & 3 deletions src/color/toColorString.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const isHsla = (color: Object): boolean => typeof color.hue === 'number'
* }
*/

function toColorString(color: Object): string {
export default function toColorString(color: Object): string {
if (typeof color !== 'object') throw new PolishedError(8)
if (isRgba(color)) return rgba(color)
if (isRgb(color)) return rgb(color)
Expand All @@ -65,5 +65,3 @@ function toColorString(color: Object): string {

throw new PolishedError(8)
}

export default toColorString
4 changes: 1 addition & 3 deletions src/helpers/directionalProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function generateStyles(
* 'paddingLeft': '48px'
* }
*/
function directionalProperty(
export default function directionalProperty(
property: string,
...values: Array<?string | ?number>
): Styles {
Expand All @@ -60,5 +60,3 @@ function directionalProperty(
const valuesWithDefaults = [firstValue, secondValue, thirdValue, fourthValue]
return generateStyles(property, valuesWithDefaults)
}

export default directionalProperty
6 changes: 3 additions & 3 deletions src/helpers/getValueAndUnit.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ const cssRegex = /^([+-]?(?:\d+|\d*\.\d+))([a-z]*|%)$/
* '--unit': 'px',
* }
*/
function getValueAndUnit(value: string): [number | string, string | void] {
export default function getValueAndUnit(
value: string,
): [number | string, string | void] {
// eslint-disable-next-line no-console
console.warn(
"getValueAndUnit has been marked for deprecation in polished 3.0 and will be fully deprecated in 4.0. It's functionality has been been moved to stripUnit as an optional return.",
Expand All @@ -36,5 +38,3 @@ function getValueAndUnit(value: string): [number | string, string | void] {
if (matchedValue) return [parseFloat(value), matchedValue[2]]
return [value, undefined]
}

export default getValueAndUnit
7 changes: 4 additions & 3 deletions src/helpers/stripUnit.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ const cssRegex = /^([+-]?(?:\d+|\d*\.\d+))([a-z]*|%)$/
* '--unit': 'px',
* }
*/
function stripUnit(value: string | number, unitReturn?: boolean): any {
export default function stripUnit(
value: string | number,
unitReturn?: boolean,
): any {
if (typeof value !== 'string') return unitReturn ? [value, undefined] : value
const matchedValue = value.match(cssRegex)

Expand All @@ -37,5 +40,3 @@ function stripUnit(value: string | number, unitReturn?: boolean): any {
if (matchedValue) return parseFloat(value)
return value
}

export default stripUnit
7 changes: 4 additions & 3 deletions src/math/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ function reverseString(str: string): string {
* fontSize: '11px',
* }
*/
function math(formula: string, additionalSymbols?: Object): string {
export default function math(
formula: string,
additionalSymbols?: Object,
): string {
const reversedFormula = reverseString(formula)
const formulaMatch = reversedFormula.match(unitRegExp)

Expand All @@ -167,5 +170,3 @@ function math(formula: string, additionalSymbols?: Object): string {
formulaMatch ? reverseString(formulaMatch[0]) : ''
}`
}

export default math
4 changes: 1 addition & 3 deletions src/mixins/between.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import PolishedError from '../internalHelpers/_errors'
* 'fontSize': 'calc(-9.090909090909093px + 9.090909090909092vw)'
* }
*/
function between(
export default function between(
fromSize: string,
toSize: string,
minScreen?: string = '320px',
Expand Down Expand Up @@ -63,5 +63,3 @@ function between(
2,
)}vw)`
}

export default between
4 changes: 1 addition & 3 deletions src/mixins/clearFix.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import type { Styles } from '../types/style'
* 'display': 'table'
* }
*/
function clearFix(parent?: string = '&'): Styles {
export default function clearFix(parent?: string = '&'): Styles {
const pseudoSelector = `${parent}::after`
return {
[pseudoSelector]: {
Expand All @@ -33,5 +33,3 @@ function clearFix(parent?: string = '&'): Styles {
},
}
}

export default clearFix
4 changes: 1 addition & 3 deletions src/mixins/cover.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import type { Styles } from '../types/style'
* 'left: '0'
* }
*/
function cover(offset?: number | string = 0): Styles {
export default function cover(offset?: number | string = 0): Styles {
return {
position: 'absolute',
top: offset,
Expand All @@ -34,5 +34,3 @@ function cover(offset?: number | string = 0): Styles {
left: offset,
}
}

export default cover
4 changes: 1 addition & 3 deletions src/mixins/ellipsis.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import type { Styles } from '../types/style'
* 'wordWrap': 'normal'
* }
*/
function ellipsis(width?: string | number = '100%'): Styles {
export default function ellipsis(width?: string | number = '100%'): Styles {
return {
display: 'inline-block',
maxWidth: width,
Expand All @@ -36,5 +36,3 @@ function ellipsis(width?: string | number = '100%'): Styles {
wordWrap: 'normal',
}
}

export default ellipsis
4 changes: 1 addition & 3 deletions src/mixins/fluidRange.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import type { Styles } from '../types/style'
* "padding": "20px",
* }
*/
function fluidRange(
export default function fluidRange(
cssProp: Array<FluidRangeConfiguration> | FluidRangeConfiguration,
minScreen?: string = '320px',
maxScreen?: string = '1200px',
Expand Down Expand Up @@ -103,5 +103,3 @@ function fluidRange(
}
}
}

export default fluidRange
4 changes: 1 addition & 3 deletions src/mixins/fontFace.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function generateSources(
* }
*/

function fontFace({
export default function fontFace({
fontFamily,
fontFilePath,
fontStretch,
Expand Down Expand Up @@ -140,5 +140,3 @@ function fontFace({
// Removes undefined fields for cleaner css object.
return JSON.parse(JSON.stringify(fontFaceDeclaration))
}

export default fontFace
4 changes: 1 addition & 3 deletions src/mixins/hiDPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* }
*/

function hiDPI(ratio?: number = 1.3): string {
export default function hiDPI(ratio?: number = 1.3): string {
return `
@media only screen and (-webkit-min-device-pixel-ratio: ${ratio}),
only screen and (min--moz-device-pixel-ratio: ${ratio}),
Expand All @@ -38,5 +38,3 @@ function hiDPI(ratio?: number = 1.3): string {
only screen and (min-resolution: ${ratio}dppx)
`
}

export default hiDPI
4 changes: 1 addition & 3 deletions src/mixins/hideText.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ import type { Styles } from '../types/style'
* }
*/

function hideText(): Styles {
export default function hideText(): Styles {
return {
textIndent: '101%',
overflow: 'hidden',
whiteSpace: 'nowrap',
}
}

export default hideText

0 comments on commit 6f72ff0

Please sign in to comment.