Skip to content

Commit

Permalink
remove flow from the codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
robinweser committed Nov 16, 2022
1 parent efa808c commit b9a8c6b
Show file tree
Hide file tree
Showing 16 changed files with 405 additions and 429 deletions.
3 changes: 0 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
"node": true,
"jest": true
},
"plugins": [
"flowtype"
],
"rules": {
"semi": [ 2, "never" ],
"object-curly-newline": [ 0 ],
Expand Down
5 changes: 1 addition & 4 deletions modules/generator/generatePluginList.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/* @flow */
import pluginMap from './maps/pluginMap'

export default function getRecommendedPlugins(
browserList: Object
): Array<string> {
export default function getRecommendedPlugins(browserList) {
const recommendedPlugins = {}

for (const plugin in pluginMap) {
Expand Down
18 changes: 7 additions & 11 deletions modules/generator/generatePrefixMap.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* @flow */
import { getSupport } from 'caniuse-api'

import propertyMap from './maps/propertyMap'
Expand Down Expand Up @@ -29,11 +28,7 @@ const flexPropsIE = [
'flexBasis',
]

function filterAndRemoveIfEmpty(
map: Object,
property: string,
filter: Function
): void {
function filterAndRemoveIfEmpty(map, property, filter) {
if (map[property]) {
map[property] = map[property].filter(filter)

Expand All @@ -43,7 +38,7 @@ function filterAndRemoveIfEmpty(
}
}

export default function generatePrefixMap(browserList: Object): Object {
export default function generatePrefixMap(browserList) {
const prefixMap = {}

for (const browser in prefixBrowserMap) {
Expand All @@ -54,15 +49,16 @@ export default function generatePrefixMap(browserList: Object): Object {
const versions = getSupport(keyword)

for (let i = 0, len = keywordProperties.length; i < len; ++i) {
if (versions[browser]){
if (versions[browser]) {
if (versions[browser].x >= browserList[browser]) {
var property = keywordProperties[i];
const property = keywordProperties[i]

if (!prefixMap[property]) {
prefixMap[property] = [];
prefixMap[property] = []
}

if (prefixMap[property].indexOf(prefix) === -1) {
prefixMap[property].push(prefix);
prefixMap[property].push(prefix)
}
}
}
Expand Down
21 changes: 3 additions & 18 deletions modules/generator/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* @flow */
import generatePrefixMap from './generatePrefixMap'
import generatePluginList from './generatePluginList'

Expand All @@ -9,11 +8,7 @@ function generateImportString(plugin, compatibility) {
return `import ${plugin} from 'inline-style-prefixer/lib/plugins/${plugin}'`
}

export function generateFile(
prefixMap: Object,
pluginList: Array<string>,
compatibility?: boolean
) {
export function generateFile(prefixMap, pluginList, compatibility) {
const pluginImports = pluginList
.map((plugin) => generateImportString(plugin, compatibility))
.join('\n')
Expand Down Expand Up @@ -46,7 +41,7 @@ ${moduleExporter} {
}`
}

function saveFile(fileContent: string, path: string): void {
function saveFile(fileContent, path) {
/* eslint-disable global-require */
const fs = require('fs')
/* eslint-enable global-require */
Expand All @@ -60,23 +55,13 @@ function saveFile(fileContent: string, path: string): void {
})
}

type GenerationOption = {
path?: string,
compatibility?: boolean,
plugins?: boolean,
prefixMap?: boolean,
}

const defaultOptions = {
prefixMap: true,
plugins: true,
compatibility: false,
}

export default function generateData(
browserList: Object,
userOptions: GenerationOption = {}
) {
export default function generateData(browserList, userOptions = {}) {
const options = {
...defaultOptions,
...userOptions,
Expand Down
2 changes: 1 addition & 1 deletion modules/plugins/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const FILTER_REGEX = /filter\(/g
// http://caniuse.com/#feat=css-filter-function
const prefixes = ['-webkit-', '']

export default function filter(property: string, value: any): ?Array<string> {
export default function filter(property, value) {
if (
typeof value === 'string' &&
!isPrefixedValue(value) &&
Expand Down
7 changes: 1 addition & 6 deletions modules/plugins/flexboxOld.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* @flow */
const alternativeValues = {
'space-around': 'justify',
'space-between': 'justify',
Expand All @@ -15,11 +14,7 @@ const alternativeProps = {
flexGrow: 'WebkitBoxFlex',
}

export default function flexboxOld(
property: string,
value: any,
style: Object
): void {
export default function flexboxOld(property, value, style) {
if (property === 'flexDirection' && typeof value === 'string') {
if (value.indexOf('column') > -1) {
style.WebkitBoxOrient = 'vertical'
Expand Down
3 changes: 1 addition & 2 deletions modules/plugins/gradient.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* @flow */
import isPrefixedValue from 'css-in-js-utils/lib/isPrefixedValue'

const prefixes = ['-webkit-', '-moz-', '']
const values = /linear-gradient|radial-gradient|repeating-linear-gradient|repeating-radial-gradient/gi

export default function gradient(property: string, value: any): ?Array<string> {
export default function gradient(property, value) {
if (
typeof value === 'string' &&
!isPrefixedValue(value) &&
Expand Down
32 changes: 13 additions & 19 deletions modules/plugins/grid.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* @flow */

function isSimplePositionValue(value: any) {
function isSimplePositionValue(value) {
return typeof value === 'number' && !isNaN(value)
}

function isComplexSpanValue(value: string) {
function isComplexSpanValue(value) {
return typeof value === 'string' && value.includes('/')
}

Expand All @@ -16,13 +14,13 @@ const displayValues = {
}

const propertyConverters = {
alignSelf: (value: any, style: Object) => {
alignSelf: (value, style) => {
if (alignmentValues.indexOf(value) > -1) {
style.msGridRowAlign = value
}
},

gridColumn: (value: any, style: Object) => {
gridColumn: (value, style) => {
if (isSimplePositionValue(value)) {
style.msGridColumn = value
} else if (isComplexSpanValue(value)) {
Expand All @@ -40,20 +38,20 @@ const propertyConverters = {
}
},

gridColumnEnd: (value: any, style: Object) => {
gridColumnEnd: (value, style) => {
const { msGridColumn } = style
if (isSimplePositionValue(value) && isSimplePositionValue(msGridColumn)) {
style.msGridColumnSpan = value - msGridColumn
}
},

gridColumnStart: (value: any, style: Object) => {
gridColumnStart: (value, style) => {
if (isSimplePositionValue(value)) {
style.msGridColumn = value
}
},

gridRow: (value: any, style: Object) => {
gridRow: (value, style) => {
if (isSimplePositionValue(value)) {
style.msGridRow = value
} else if (isComplexSpanValue(value)) {
Expand All @@ -71,39 +69,35 @@ const propertyConverters = {
}
},

gridRowEnd: (value: any, style: Object) => {
gridRowEnd: (value, style) => {
const { msGridRow } = style
if (isSimplePositionValue(value) && isSimplePositionValue(msGridRow)) {
style.msGridRowSpan = value - msGridRow
}
},

gridRowStart: (value: any, style: Object) => {
gridRowStart: (value, style) => {
if (isSimplePositionValue(value)) {
style.msGridRow = value
}
},

gridTemplateColumns: (value: any, style: Object) => {
gridTemplateColumns: (value, style) => {
style.msGridColumns = value
},

gridTemplateRows: (value: any, style: Object) => {
gridTemplateRows: (value, style) => {
style.msGridRows = value
},

justifySelf: (value: any, style: Object) => {
justifySelf: (value, style) => {
if (alignmentValues.indexOf(value) > -1) {
style.msGridColumnAlign = value
}
},
}

export default function grid(
property: string,
value: any,
style: Object
): ?Array<string> {
export default function grid(property, value, style) {
if (property === 'display' && value in displayValues) {
return displayValues[value]
}
Expand Down
3 changes: 1 addition & 2 deletions modules/plugins/imageSet.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* @flow */
import isPrefixedValue from 'css-in-js-utils/lib/isPrefixedValue'

// http://caniuse.com/#feat=css-image-set
const prefixes = ['-webkit-', '']

export default function imageSet(property: string, value: any): ?Array<string> {
export default function imageSet(property, value) {
if (
typeof value === 'string' &&
!isPrefixedValue(value) &&
Expand Down
7 changes: 1 addition & 6 deletions modules/plugins/logical.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* @flow */
const alternativeProps = {
marginBlockStart: ['WebkitMarginBefore'],
marginBlockEnd: ['WebkitMarginAfter'],
Expand Down Expand Up @@ -26,11 +25,7 @@ const alternativeProps = {
borderInlineEndWidth: ['WebkitBorderEndWidth', 'MozBorderEndWidth'],
}

export default function logical(
property: string,
value: any,
style: Object
): void {
export default function logical(property, value, style) {
if (Object.prototype.hasOwnProperty.call(alternativeProps, property)) {
const alternativePropList = alternativeProps[property]
for (let i = 0, len = alternativePropList.length; i < len; ++i) {
Expand Down
3 changes: 1 addition & 2 deletions modules/plugins/position.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* @flow */
export default function position(property: string, value: any): ?Array<string> {
export default function position(property, value) {
if (property === 'position' && value === 'sticky') {
return ['-webkit-sticky', 'sticky']
}
Expand Down
3 changes: 1 addition & 2 deletions modules/plugins/sizing.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* @flow */
const prefixes = ['-webkit-', '-moz-', '']

const properties = {
Expand All @@ -18,7 +17,7 @@ const values = {
'contain-floats': true,
}

export default function sizing(property: string, value: any): ?Array<any> {
export default function sizing(property, value) {
if (properties.hasOwnProperty(property) && values.hasOwnProperty(value)) {
return prefixes.map((prefix) => prefix + value)
}
Expand Down
10 changes: 2 additions & 8 deletions modules/plugins/transition.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* @flow */
import hyphenateProperty from 'css-in-js-utils/lib/hyphenateProperty'
import isPrefixedValue from 'css-in-js-utils/lib/isPrefixedValue'

Expand All @@ -19,7 +18,7 @@ const prefixMapping = {
ms: '-ms-',
}

function prefixValue(value: string, propertyPrefixMap: Object): string {
function prefixValue(value, propertyPrefixMap) {
if (isPrefixedValue(value)) {
return value
}
Expand Down Expand Up @@ -56,12 +55,7 @@ function prefixValue(value: string, propertyPrefixMap: Object): string {
return multipleValues.join(',')
}

export default function transition(
property: string,
value: any,
style: Object,
propertyPrefixMap: Object
): ?string {
export default function transition(property, value, style, propertyPrefixMap) {
// also check for already prefixed transitions
if (typeof value === 'string' && properties.hasOwnProperty(property)) {
const outputValue = prefixValue(value, propertyPrefixMap)
Expand Down
2 changes: 0 additions & 2 deletions modules/utils/prefixProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ export default function prefixProperty(prefixProperties, property, style) {
style[prefixedProperty] = style[property]
}
}

style[property] = style[property]
}

return style
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"babel:lib": "cross-env BABEL_ENV=commonjs babel -d lib modules --ignore __tests__",
"babel": "yarn babel:es && yarn babel:lib",
"build": "yarn run check && yarn generate && yarn babel",
"check": "yarn clear && yarn format && yarn lint && yarn coverage && yarn flow",
"check": "yarn clear && yarn format && yarn lint && yarn coverage",
"clear": "rimraf lib es coverage _book",
"docs": "gitbook install && gitbook build && gh-pages -d _book",
"flow": "flow",
Expand Down Expand Up @@ -58,13 +58,11 @@
"babel-preset-stage-0": "^6.5.0",
"caniuse-api": "^3.0.0",
"cross-env": "^5.2.0",
"eslint": "^3.14.0",
"eslint": "^5.0.0",
"eslint-config-airbnb": "^14.0.0",
"eslint-plugin-flowtype": "^2.30.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^3.0.2",
"eslint-plugin-react": "^6.9.0",
"flow-bin": "^0.80.0",
"gh-pages": "^1.2.0",
"gitbook": "^3.2.2",
"gitbook-cli": "^2.3.0",
Expand Down
Loading

0 comments on commit b9a8c6b

Please sign in to comment.