Skip to content

Convert to ES6 import/export syntax #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/node_modules
/dist
/index.js
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"name": "css-to-react-native",
"version": "2.1.1",
"description": "Convert CSS text to a React Native stylesheet object",
"main": "dist/index.js",
"main": "index.js",
"scripts": {
"build": "babel src --ignore test.js --out-dir dist",
"build": "rollup ./src/index.js -o index.js --f cjs && babel index.js -o index.js",
"test": "jest",
"test:watch": "jest --watch",
"lint": "eslint src",
Expand All @@ -13,7 +13,7 @@
"lint-staged": "lint-staged"
},
"files": [
"dist",
"index.js",
"src"
],
"repository": {
Expand Down Expand Up @@ -43,7 +43,8 @@
"eslint-plugin-prettier": "^2.6.0",
"jest": "^22.2.2",
"lint-staged": "^6.1.0",
"prettier": "^1.10.2"
"prettier": "^1.10.2",
"rollup": "^0.55.5"
},
"dependencies": {
"css-color-keywords": "^1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/TokenStream.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const SYMBOL_MATCH = 'SYMBOL_MATCH'

module.exports = class TokenStream {
export default class TokenStream {
constructor(nodes, parent) {
this.index = 0
this.nodes = nodes
Expand Down
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable no-param-reassign */
const parse = require('postcss-value-parser')
const camelizeStyleName = require('fbjs/lib/camelizeStyleName')
const transforms = require('./transforms')
const TokenStream = require('./TokenStream')
import parse from 'postcss-value-parser'
import camelizeStyleName from 'fbjs/lib/camelizeStyleName'
import transforms from './transforms/index'
import TokenStream from './TokenStream'

// Note if this is wrong, you'll need to change tokenTypes.js too
const numberOrLengthRe = /^([+-]?(?:\d*\.)?\d+(?:[Ee][+-]?\d+)?)(?:px)?$/i
Expand Down
10 changes: 4 additions & 6 deletions src/tokenTypes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { stringify } = require('postcss-value-parser')
const cssColorKeywords = require('css-color-keywords')
import { stringify } from 'postcss-value-parser'
import cssColorKeywords from 'css-color-keywords'

const matchString = node => {
if (node.type !== 'string') return null
Expand Down Expand Up @@ -40,7 +40,7 @@ const noopToken = predicate => node => (predicate(node) ? '<token>' : null)
const valueForTypeToken = type => node =>
node.type === type ? node.value : null

const regExpToken = (regExp, transform = String) => node => {
export const regExpToken = (regExp, transform = String) => node => {
if (node.type !== 'word') return null

const match = node.value.match(regExp)
Expand All @@ -51,9 +51,7 @@ const regExpToken = (regExp, transform = String) => node => {
return value
}

module.exports.regExpToken = regExpToken

module.exports.tokens = {
export const tokens = {
SPACE: noopToken(node => node.type === 'space'),
SLASH: noopToken(node => node.type === 'div' && node.value === '/'),
COMMA: noopToken(node => node.type === 'div' && node.value === ','),
Expand Down
4 changes: 2 additions & 2 deletions src/transforms/boxShadow.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { parseShadow } = require('./util')
import { parseShadow } from './util'

module.exports = tokenStream => {
export default tokenStream => {
const { offset, radius, color } = parseShadow(tokenStream)
return {
$merge: {
Expand Down
4 changes: 2 additions & 2 deletions src/transforms/flex.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { tokens } = require('../tokenTypes')
import { tokens } from '../tokenTypes'

const { NONE, AUTO, NUMBER, LENGTH, SPACE } = tokens

Expand All @@ -8,7 +8,7 @@ const defaultFlexBasis = 0

const FLEX_BASIS_AUTO = {} // Used for reference equality

module.exports = tokenStream => {
export default tokenStream => {
let flexGrow
let flexShrink
let flexBasis
Expand Down
6 changes: 3 additions & 3 deletions src/transforms/font.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const parseFontFamily = require('./fontFamily')
const { regExpToken, tokens } = require('../tokenTypes')
import parseFontFamily from './fontFamily'
import { regExpToken, tokens } from '../tokenTypes'

const { SPACE, LENGTH, NUMBER, SLASH } = tokens
const NORMAL = regExpToken(/^(normal)$/)
Expand All @@ -11,7 +11,7 @@ const defaultFontStyle = 'normal'
const defaultFontWeight = 'normal'
const defaultFontVariant = []

module.exports = tokenStream => {
export default tokenStream => {
let fontStyle
let fontWeight
let fontVariant
Expand Down
4 changes: 2 additions & 2 deletions src/transforms/fontFamily.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { tokens } = require('../tokenTypes')
import { tokens } from '../tokenTypes'

const { SPACE, IDENT, STRING } = tokens

module.exports = tokenStream => {
export default tokenStream => {
let fontFamily

if (tokenStream.matches(STRING)) {
Expand Down
26 changes: 11 additions & 15 deletions src/transforms/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
const { regExpToken, tokens } = require('../tokenTypes')
const boxShadow = require('./boxShadow')
const flex = require('./flex')
const font = require('./font')
const fontFamily = require('./fontFamily')
const textShadow = require('./textShadow')
const textDecoration = require('./textDecoration')
const textDecorationLine = require('./textDecorationLine')
const transform = require('./transform')
const {
directionFactory,
anyOrderFactory,
shadowOffsetFactory,
} = require('./util')
import { regExpToken, tokens } from '../tokenTypes'
import boxShadow from './boxShadow'
import flex from './flex'
import font from './font'
import fontFamily from './fontFamily'
import textShadow from './textShadow'
import textDecoration from './textDecoration'
import textDecorationLine from './textDecorationLine'
import transform from './transform'
import { directionFactory, anyOrderFactory, shadowOffsetFactory } from './util'

const { IDENT, WORD, COLOR } = tokens

Expand Down Expand Up @@ -60,7 +56,7 @@ const fontWeight = tokenStream => tokenStream.expect(WORD) // Also match numbers
const shadowOffset = shadowOffsetFactory()
const textShadowOffset = shadowOffsetFactory()

module.exports = {
export default {
background,
border,
borderColor,
Expand Down
2 changes: 1 addition & 1 deletion src/transforms/textDecoration.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const defaultTextDecorationLine = 'none'
const defaultTextDecorationStyle = 'solid'
const defaultTextDecorationColor = 'black'

module.exports = tokenStream => {
export default tokenStream => {
let line
let style
let color
Expand Down
4 changes: 2 additions & 2 deletions src/transforms/textDecorationLine.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { tokens } = require('../tokenTypes')
import { tokens } from '../tokenTypes'

const { SPACE, LINE } = tokens

module.exports = tokenStream => {
export default tokenStream => {
const lines = []

let didParseFirst = false
Expand Down
4 changes: 2 additions & 2 deletions src/transforms/textShadow.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { parseShadow } = require('./util')
import { parseShadow } from './util'

module.exports = tokenStream => {
export default tokenStream => {
const { offset, radius, color } = parseShadow(tokenStream)
return {
$merge: {
Expand Down
4 changes: 2 additions & 2 deletions src/transforms/transform.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { tokens } = require('../tokenTypes')
import { tokens } from '../tokenTypes'

const { SPACE, COMMA, LENGTH, NUMBER, ANGLE } = tokens

Expand Down Expand Up @@ -54,7 +54,7 @@ const partTransforms = {
skew: xyAngle('skew', '0deg'),
}

module.exports = tokenStream => {
export default tokenStream => {
let transforms = []

let didParseFirst = false
Expand Down
10 changes: 5 additions & 5 deletions src/transforms/util.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { tokens } = require('../tokenTypes')
import { tokens } from '../tokenTypes'

const { LENGTH, PERCENT, COLOR, SPACE, NONE } = tokens

module.exports.directionFactory = ({
export const directionFactory = ({
types = [LENGTH, PERCENT],
directions = ['Top', 'Right', 'Bottom', 'Left'],
prefix = '',
Expand Down Expand Up @@ -34,7 +34,7 @@ module.exports.directionFactory = ({
return { $merge: output }
}

module.exports.anyOrderFactory = (properties, delim = SPACE) => tokenStream => {
export const anyOrderFactory = (properties, delim = SPACE) => tokenStream => {
const propertyNames = Object.keys(properties)
const values = propertyNames.reduce((accum, propertyName) => {
accum[propertyName] === undefined // eslint-disable-line
Expand Down Expand Up @@ -70,14 +70,14 @@ module.exports.anyOrderFactory = (properties, delim = SPACE) => tokenStream => {
return { $merge: values }
}

module.exports.shadowOffsetFactory = () => tokenStream => {
export const shadowOffsetFactory = () => tokenStream => {
const width = tokenStream.expect(LENGTH)
const height = tokenStream.matches(SPACE) ? tokenStream.expect(LENGTH) : width
tokenStream.expectEmpty()
return { width, height }
}

module.exports.parseShadow = tokenStream => {
export const parseShadow = tokenStream => {
let offsetX
let offsetY
let radius
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3809,6 +3809,10 @@ rimraf@^2.5.1, rimraf@^2.5.4, rimraf@^2.6.1:
dependencies:
glob "^7.0.5"

rollup@^0.55.5:
version "0.55.5"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-0.55.5.tgz#2f88c300f7cf24b5ec2dca8a6aba73b04e087e93"

run-async@^2.2.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.3.0.tgz#0371ab4ae0bdd720d4166d7dfda64ff7a445a6c0"
Expand Down