├── _assets
├── src
│ └── index.js
├── README.md
├── index.js
├── package.json
└── LICENSE
├── vulture-redux
├── test
│ └── connect.test.js
├── index.js
├── src
│ ├── index.js
│ └── connect.js
├── .env
├── package.json
├── LICENSE
└── README.md
├── calebmer
├── index.js
├── README.md
├── src
│ └── index.js
├── test
│ └── index.test.js
├── .env
├── package.json
└── LICENSE
├── data-guard
├── index.js
├── src
│ ├── index.js
│ ├── normalizeValidator.js
│ ├── DataGuard.js
│ ├── createArrayValidator.js
│ ├── createObjectValidator.js
│ ├── createSuperValidator.js
│ ├── validate.js
│ ├── guard.js
│ ├── ValidationContext.js
│ ├── Messages.js
│ └── Validators.js
├── .env
├── package.json
├── test
│ ├── guard.test.js
│ ├── DataGuard.test.js
│ ├── createSuperValidator.test.js
│ ├── validate.test.js
│ └── Validators.test.js
├── LICENSE
└── README.md
├── .babelrc
├── babel-matrix
├── index.js
├── .env
├── src
│ ├── PluginSource.js
│ ├── index.js
│ ├── syntaxes.js
│ ├── getPlugins.js
│ ├── getPluginSources.js
│ └── getCellPluginSources.js
├── test
│ ├── getPluginSources.test.js
│ └── getCellPluginSources.test.js
├── package.json
├── LICENSE
└── README.md
├── .gitignore
├── babel-plugin-transform-jsx
├── index.js
├── test
│ ├── fixtures
│ │ ├── should-include-extra-space
│ │ │ ├── options.json
│ │ │ ├── actual.js
│ │ │ └── expected.js
│ │ ├── should-allow-use-variables-default
│ │ │ ├── options.json
│ │ │ ├── actual.js
│ │ │ └── expected.js
│ │ ├── should-allow-use-variables-customization
│ │ │ ├── options.json
│ │ │ ├── actual.js
│ │ │ └── expected.js
│ │ ├── should-wrap-with-a-function
│ │ │ ├── options.json
│ │ │ ├── actual.js
│ │ │ └── expected.js
│ │ ├── should-allow-module-constructor
│ │ │ ├── options.json
│ │ │ ├── actual.js
│ │ │ └── expected.js
│ │ ├── should-use-new-with-function
│ │ │ ├── options.json
│ │ │ ├── actual.js
│ │ │ └── expected.js
│ │ ├── should-nullify-children-in-closing-elements
│ │ │ ├── actual.js
│ │ │ └── expected.js
│ │ ├── should-use-new-with-module
│ │ │ ├── options.json
│ │ │ ├── actual.js
│ │ │ └── expected.js
│ │ ├── should-work-with-namespaces
│ │ │ ├── actual.js
│ │ │ └── expected.js
│ │ ├── should-allow-expression-children
│ │ │ ├── actual.js
│ │ │ └── expected.js
│ │ ├── should-work-on-text-children
│ │ │ ├── actual.js
│ │ │ └── expected.js
│ │ ├── should-not-use-variables-by-default
│ │ │ ├── actual.js
│ │ │ └── expected.js
│ │ ├── should-work-with-namespaced-attributes
│ │ │ ├── actual.js
│ │ │ └── expected.js
│ │ ├── should-output-object
│ │ │ ├── actual.js
│ │ │ └── expected.js
│ │ ├── should-work-with-members
│ │ │ ├── actual.js
│ │ │ └── expected.js
│ │ └── should-work-with-spread-attributes
│ │ │ ├── actual.js
│ │ │ └── expected.js
│ └── fixtures.test.js
├── .env
├── package.json
├── LICENSE
├── src
│ └── index.js
└── README.md
├── .env
├── _scripts
├── lint.sh
├── build.sh
├── test.sh
├── new.sh
└── release.sh
├── .editorconfig
├── babel-preset-calebmer
├── flow.js
├── README.md
├── esnext.js
├── react.js
├── LICENSE
├── es2015.js
└── package.json
├── test-dom
├── index.js
├── .env
├── package.json
├── README.md
└── LICENSE
├── package.json
├── eslint-config-calebmer
├── react-native.json
├── flow.json
├── react-web.json
├── LICENSE
├── package.json
├── react.json
├── README.md
└── index.json
└── README.md
/_assets/src/index.js:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/_assets/README.md:
--------------------------------------------------------------------------------
1 | # $1
2 | TODO
3 |
--------------------------------------------------------------------------------
/vulture-redux/test/connect.test.js:
--------------------------------------------------------------------------------
1 | // TODO
2 |
--------------------------------------------------------------------------------
/_assets/index.js:
--------------------------------------------------------------------------------
1 | module.exports = require('./lib')
2 |
--------------------------------------------------------------------------------
/calebmer/index.js:
--------------------------------------------------------------------------------
1 | module.exports = require('./lib')
2 |
--------------------------------------------------------------------------------
/data-guard/index.js:
--------------------------------------------------------------------------------
1 | module.exports = require('./lib')
2 |
--------------------------------------------------------------------------------
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["es2015", "stage-0"]
3 | }
4 |
--------------------------------------------------------------------------------
/babel-matrix/index.js:
--------------------------------------------------------------------------------
1 | module.exports = require('./lib')
2 |
--------------------------------------------------------------------------------
/vulture-redux/index.js:
--------------------------------------------------------------------------------
1 | module.exports = require('./lib')
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 | npm-debug.log
4 | */lib
5 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/index.js:
--------------------------------------------------------------------------------
1 | module.exports = require('./lib')
2 |
--------------------------------------------------------------------------------
/calebmer/README.md:
--------------------------------------------------------------------------------
1 | # calebmer
2 | This is my name. Don’t wear it out.
3 |
--------------------------------------------------------------------------------
/vulture-redux/src/index.js:
--------------------------------------------------------------------------------
1 | exports.connect = require('./connect').default
2 |
--------------------------------------------------------------------------------
/calebmer/src/index.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | givenName: 'Caleb',
3 | familyName: 'Meredith'
4 | }
5 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-include-extra-space/options.json:
--------------------------------------------------------------------------------
1 | {
2 | "noTrim": true
3 | }
4 |
--------------------------------------------------------------------------------
/.env:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | scripts=./_scripts
4 |
5 | export NODE_ENV=developmnet
6 |
7 | alias new=$scripts/new.sh
8 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-allow-use-variables-default/options.json:
--------------------------------------------------------------------------------
1 | {
2 | "useVariables": true
3 | }
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-allow-use-variables-customization/options.json:
--------------------------------------------------------------------------------
1 | {
2 | "useVariables": "^Z"
3 | }
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-wrap-with-a-function/options.json:
--------------------------------------------------------------------------------
1 | {
2 | "function": "jsxConstructor"
3 | }
4 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-allow-module-constructor/options.json:
--------------------------------------------------------------------------------
1 | {
2 | "module": "jsx-constructor"
3 | }
4 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-use-new-with-function/options.json:
--------------------------------------------------------------------------------
1 | {
2 | "useNew": true,
3 | "function": "VNode"
4 | }
5 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-nullify-children-in-closing-elements/actual.js:
--------------------------------------------------------------------------------
1 | var jsxA =
;
2 | var jsxB = ;
3 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-use-new-with-module/options.json:
--------------------------------------------------------------------------------
1 | {
2 | "useNew": true,
3 | "module": "jsx-constructor"
4 | }
5 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-work-with-namespaces/actual.js:
--------------------------------------------------------------------------------
1 | var jsxA = ;
2 | var jsxB = ;
3 |
--------------------------------------------------------------------------------
/_scripts/lint.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | npm_bin=$(cd $(dirname ${BASH_SOURCE[0]}) && pwd)/../node_modules/.bin
4 |
5 | $npm_bin/standard src/**/*.js
6 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-use-new-with-function/actual.js:
--------------------------------------------------------------------------------
1 | var object = (
2 |
3 | Hello, world!
4 |
5 | )
6 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-use-new-with-module/actual.js:
--------------------------------------------------------------------------------
1 | var object = (
2 |
3 | Hello, world!
4 |
5 | )
6 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-wrap-with-a-function/actual.js:
--------------------------------------------------------------------------------
1 | var object = (
2 |
3 | Hello, world!
4 |
5 | )
6 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-allow-module-constructor/actual.js:
--------------------------------------------------------------------------------
1 | var object = (
2 |
3 | Hello, world!
4 |
5 | )
6 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | [*]
2 | charset = utf-8
3 | end_of_line = lf
4 | insert_final_newline = true
5 | trim_trailing_whitespace = true
6 | indent_style = space
7 | indent_size = 2
8 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-allow-expression-children/actual.js:
--------------------------------------------------------------------------------
1 | var jsx = (
2 |
3 | {"a" + "b" + "c"}
4 | {1 + 2 * 3}
5 |
6 | )
7 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-include-extra-space/actual.js:
--------------------------------------------------------------------------------
1 | var jsx = (
2 |
3 |
4 | {' '}
5 |
6 |
7 |
8 | )
9 |
--------------------------------------------------------------------------------
/babel-preset-calebmer/flow.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | plugins: [
3 | require('babel-plugin-syntax-flow'),
4 | require('babel-plugin-transform-flow-comments'),
5 | ],
6 | }
7 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-allow-expression-children/expected.js:
--------------------------------------------------------------------------------
1 | var jsx = {
2 | elementName: "div",
3 | attributes: {},
4 | children: ["a" + "b" + "c", 1 + 2 * 3]
5 | };
6 |
--------------------------------------------------------------------------------
/_scripts/build.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | if [ ! -d "src" ]; then
4 | exit 0
5 | fi
6 |
7 | npm_bin=$(cd $(dirname ${BASH_SOURCE[0]}) && pwd)/../node_modules/.bin
8 |
9 | $npm_bin/babel src -d lib
10 |
--------------------------------------------------------------------------------
/test-dom/index.js:
--------------------------------------------------------------------------------
1 | var jsdom = require('jsdom').jsdom
2 | var window = jsdom('').defaultView
3 | global.window = window
4 | global.document = window.document
5 | global.navigator = window.navigator
6 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-work-on-text-children/actual.js:
--------------------------------------------------------------------------------
1 | var jsx = (
2 |
3 | Hello, world!{' '}
4 | Hello world, again.{' '}
5 | And one more time.
6 |
7 | );
8 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-work-on-text-children/expected.js:
--------------------------------------------------------------------------------
1 | var jsx = {
2 | elementName: 'div',
3 | attributes: {},
4 | children: ['Hello, world! Hello world, again. And one more time.']
5 | };
6 |
--------------------------------------------------------------------------------
/_scripts/test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | if [ ! -d "test" ]; then
4 | exit 0
5 | fi
6 |
7 | npm_bin=$(cd $(dirname ${BASH_SOURCE[0]}) && pwd)/../node_modules/.bin
8 |
9 | $npm_bin/mocha -r babel-register test/*.test.js
10 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-not-use-variables-by-default/actual.js:
--------------------------------------------------------------------------------
1 | var Variable = true;
2 |
3 | var jsxA = ;
4 | var jsxB = ;
5 | var jsxC = {Variable};
6 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-work-with-namespaced-attributes/actual.js:
--------------------------------------------------------------------------------
1 | var value3 = "value3";
2 | var value4 = "value4";
3 | var jsx = ;
4 |
--------------------------------------------------------------------------------
/data-guard/src/index.js:
--------------------------------------------------------------------------------
1 | var DataGuard = require('./DataGuard')
2 |
3 | DataGuard.default = DataGuard
4 | DataGuard.validate = require('./validate')
5 | DataGuard.guard = require('./guard')
6 |
7 | module.exports = DataGuard
8 |
--------------------------------------------------------------------------------
/calebmer/test/index.test.js:
--------------------------------------------------------------------------------
1 | import assert from 'assert'
2 | import calebmer from '../src/index.js'
3 |
4 | describe('index', () => {
5 | it('is it my name?', () => {
6 | assert.equal(calebmer.givenName, 'Caleb')
7 | })
8 | })
9 |
--------------------------------------------------------------------------------
/calebmer/.env:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | scripts=../_scripts
4 |
5 | export NODE_ENV=developmnet
6 |
7 | alias build=$scripts/build.sh
8 | alias lint=$scripts/lint.sh
9 | alias test=$scripts/test.sh
10 | alias release=$scripts/release.sh
11 |
--------------------------------------------------------------------------------
/test-dom/.env:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | scripts=../_scripts
4 |
5 | export NODE_ENV=developmnet
6 |
7 | alias build=$scripts/build.sh
8 | alias lint=$scripts/lint.sh
9 | alias test=$scripts/test.sh
10 | alias release=$scripts/release.sh
11 |
--------------------------------------------------------------------------------
/babel-matrix/.env:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | scripts=../_scripts
4 |
5 | export NODE_ENV=developmnet
6 |
7 | alias build=$scripts/build.sh
8 | alias lint=$scripts/lint.sh
9 | alias test=$scripts/test.sh
10 | alias release=$scripts/release.sh
11 |
--------------------------------------------------------------------------------
/data-guard/.env:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | scripts=../_scripts
4 |
5 | export NODE_ENV=developmnet
6 |
7 | alias build=$scripts/build.sh
8 | alias lint=$scripts/lint.sh
9 | alias test=$scripts/test.sh
10 | alias release=$scripts/release.sh
11 |
--------------------------------------------------------------------------------
/vulture-redux/.env:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | scripts=../_scripts
4 |
5 | export NODE_ENV=developmnet
6 |
7 | alias build=$scripts/build.sh
8 | alias lint=$scripts/lint.sh
9 | alias test=$scripts/test.sh
10 | alias release=$scripts/release.sh
11 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/.env:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | scripts=../_scripts
4 |
5 | export NODE_ENV=developmnet
6 |
7 | alias build=$scripts/build.sh
8 | alias lint=$scripts/lint.sh
9 | alias test=$scripts/test.sh
10 | alias release=$scripts/release.sh
11 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-work-with-namespaces/expected.js:
--------------------------------------------------------------------------------
1 | var jsxA = {
2 | elementName: "ns:thing",
3 | attributes: {},
4 | children: null
5 | };
6 | var jsxB = {
7 | elementName: "ns:thing",
8 | attributes: {},
9 | children: []
10 | };
11 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-nullify-children-in-closing-elements/expected.js:
--------------------------------------------------------------------------------
1 | var jsxA = {
2 | elementName: "div",
3 | attributes: {},
4 | children: []
5 | };
6 | var jsxB = {
7 | elementName: "div",
8 | attributes: {},
9 | children: null
10 | };
11 |
--------------------------------------------------------------------------------
/babel-matrix/src/PluginSource.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Representation of a Babel plugin hosted on NPM.
3 | *
4 | * @class
5 | */
6 | class PluginSource {
7 | constructor (name, version) {
8 | this.name = name
9 | this.version = version
10 | }
11 | }
12 |
13 | export default PluginSource
14 |
--------------------------------------------------------------------------------
/babel-matrix/src/index.js:
--------------------------------------------------------------------------------
1 | import { assign } from 'lodash'
2 |
3 | exports.getPlugins = require('./getPlugins.js').default
4 | exports.getPluginSources = require('./getPluginSources.js').default
5 | exports.PluginSource = require('./PluginSource.js').default
6 |
7 | assign(exports, require('./syntaxes.js'))
8 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-use-new-with-function/expected.js:
--------------------------------------------------------------------------------
1 | var object = new VNode({
2 | elementName: "div",
3 | attributes: {},
4 | children: [new VNode({
5 | elementName: "strong",
6 | attributes: {},
7 | children: ["Hello,"]
8 | }), " world!"]
9 | });
10 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-wrap-with-a-function/expected.js:
--------------------------------------------------------------------------------
1 | var object = jsxConstructor({
2 | elementName: "div",
3 | attributes: {},
4 | children: [jsxConstructor({
5 | elementName: "strong",
6 | attributes: {},
7 | children: ["Hello,"]
8 | }), " world!"]
9 | });
10 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "private": true,
3 | "dependencies": {
4 | "babel-cli": "^6.10.1",
5 | "babel-preset-es2015": "^6.9.0",
6 | "babel-preset-stage-0": "^6.5.0",
7 | "babel-register": "^6.9.0",
8 | "mocha": "^2.5.3",
9 | "semver": "^5.2.0",
10 | "standard": "^5.4.1"
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/data-guard/src/normalizeValidator.js:
--------------------------------------------------------------------------------
1 | const isFunction = require('lodash/isFunction')
2 | const createObjectValidator = require('./createObjectValidator')
3 |
4 | function normalizeValidator (validator) {
5 | return isFunction(validator) ? validator : createObjectValidator(validator)
6 | }
7 |
8 | module.exports = normalizeValidator
9 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-allow-module-constructor/expected.js:
--------------------------------------------------------------------------------
1 | import _jsx from "jsx-constructor";
2 | var object = _jsx({
3 | elementName: "div",
4 | attributes: {},
5 | children: [_jsx({
6 | elementName: "strong",
7 | attributes: {},
8 | children: ["Hello,"]
9 | }), " world!"]
10 | });
11 |
--------------------------------------------------------------------------------
/data-guard/src/DataGuard.js:
--------------------------------------------------------------------------------
1 | const mapValues = require('lodash/mapValues')
2 | const Validators = require('./Validators')
3 | const createSuperValidator = require('./createSuperValidator')
4 |
5 | const DataGuard = mapValues(Validators, (validator, name) => (...args) => createSuperValidator()[name](...args))
6 |
7 | module.exports = DataGuard
8 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-work-with-namespaced-attributes/expected.js:
--------------------------------------------------------------------------------
1 | var value3 = "value3";
2 | var value4 = "value4";
3 | var jsx = {
4 | elementName: "div",
5 | attributes: {
6 | key1: "value1",
7 | "ns:key2": "value2",
8 | "ns:key3": value3,
9 | key4: value4
10 | },
11 | children: []
12 | };
13 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-use-new-with-module/expected.js:
--------------------------------------------------------------------------------
1 | import _JSXNode from "jsx-constructor";
2 | var object = new _JSXNode({
3 | elementName: "div",
4 | attributes: {},
5 | children: [new _JSXNode({
6 | elementName: "strong",
7 | attributes: {},
8 | children: ["Hello,"]
9 | }), " world!"]
10 | });
11 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-output-object/actual.js:
--------------------------------------------------------------------------------
1 | var jsx = (
2 |
3 |
4 |
5 | A JSX Test
6 |
7 |
8 |
9 |
Just a basic JSX transformation
10 |
11 |
12 |
13 | )
14 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-work-with-members/actual.js:
--------------------------------------------------------------------------------
1 | var object = {
2 | a: 1,
3 | b: {
4 | c: 2
5 | }
6 | };
7 |
8 | var jsxA = ;
9 | var jsxB = ;
10 | var jsxC = ;
11 | var jsxD = ;
12 | var jsxE = {object.a};
13 | var jsxF = {object.b.c};
14 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-not-use-variables-by-default/expected.js:
--------------------------------------------------------------------------------
1 | var Variable = true;
2 |
3 | var jsxA = {
4 | elementName: "Variable",
5 | attributes: {},
6 | children: null
7 | };
8 | var jsxB = {
9 | elementName: "Variable",
10 | attributes: {},
11 | children: []
12 | };
13 | var jsxC = {
14 | elementName: "Variable",
15 | attributes: {},
16 | children: [Variable]
17 | };
18 |
--------------------------------------------------------------------------------
/babel-matrix/src/syntaxes.js:
--------------------------------------------------------------------------------
1 | export const COMMON_JS = 'commonjs'
2 | export const AMD = 'amd'
3 | export const UMD = 'umd'
4 | export const SYSTEM_JS = 'systemjs'
5 | export const ES_MODULES = 'esmodule'
6 | export const ES5 = 'es5'
7 | export const ES6 = 'es6'
8 | export const ESNEXT = 'esnext'
9 | export const REACT = 'react'
10 | export const FLOW = 'flow'
11 |
12 | export const SYNTAXES = [COMMON_JS, AMD, UMD, SYSTEM_JS, ES_MODULES, ES5, ES6, ESNEXT, REACT, FLOW]
13 |
--------------------------------------------------------------------------------
/babel-matrix/test/getPluginSources.test.js:
--------------------------------------------------------------------------------
1 | import assert from 'assert'
2 | import * as s from '../src/syntaxes.js'
3 | import getPluginSources from '../src/getCellPluginSources.js'
4 |
5 | describe('getPluginSources', () => {
6 | it('gets all the combinations of syntaxes', () => {
7 | assert.equal(
8 | getPluginSources(
9 | [s.ESNEXT, s.ES_MODULES, s.REACT, s.FLOW],
10 | [s.ES5, s.UMD]
11 | ).length,
12 | 0
13 | )
14 | })
15 | })
16 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-work-with-spread-attributes/actual.js:
--------------------------------------------------------------------------------
1 | var objectA = { x1: 1, y1: 2, z1: 3 };
2 | var objectB = { x2: 1, y2: 2, z2: 3 };
3 | var jsxA = ;
4 | var jsxB = ;
5 | var jsxC = ;
6 | var jsxD = ;
7 | var jsxE = ;
8 | var jsxF = ;
9 |
--------------------------------------------------------------------------------
/_scripts/new.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | name=$1
4 | root=$(cd $(dirname ${BASH_SOURCE[0]}) && pwd)/..
5 | assets=$root/_assets
6 | new=$root/$1
7 |
8 | cd $root
9 |
10 | mkdir $new || exit 1
11 |
12 | cd $new
13 |
14 | mkdir $new/src
15 | cp $assets/.env $new/.env
16 | cp $assets/LICENSE $new/LICENSE
17 | cat $assets/README.md | sed -e "s/\$1/$1/g" > $new/README.md
18 | cat $assets/package.json | sed -e "s/\$1/$1/g" > $new/package.json
19 | cp $assets/index.js $new/index.js
20 | cp $assets/src/index.js $new/src/index.js
21 |
--------------------------------------------------------------------------------
/calebmer/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "calebmer",
3 | "version": "1.0.0",
4 | "description": "This is my name. Don’t wear it out.",
5 | "author": "Caleb Meredith ",
6 | "license": "MIT",
7 | "repository": "https://github.com/calebmer/node_modules/tree/master/calebmer",
8 | "keywords": [
9 | "calebmer"
10 | ],
11 | "main": "index.js",
12 | "files": [
13 | "index.js",
14 | "lib"
15 | ],
16 | "scripts": {},
17 | "dependencies": {},
18 | "devDependencies": {}
19 | }
20 |
--------------------------------------------------------------------------------
/vulture-redux/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vulture-redux",
3 | "version": "2.0.1",
4 | "description": "Redux bindings to vulture.",
5 | "author": "Caleb Meredith ",
6 | "license": "MIT",
7 | "repository": "https://github.com/calebmer/node_modules/tree/master/vulture-redux",
8 | "keywords": [
9 | "vulture",
10 | "redux"
11 | ],
12 | "main": "index.js",
13 | "files": [
14 | "index.js",
15 | "lib"
16 | ],
17 | "scripts": {},
18 | "dependencies": {},
19 | "devDependencies": {}
20 | }
21 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-include-extra-space/expected.js:
--------------------------------------------------------------------------------
1 | var jsx = {
2 | elementName: 'jsx',
3 | attributes: {},
4 | children: ['\n ', {
5 | elementName: 'a',
6 | attributes: {},
7 | children: null
8 | }, '\n ', {
9 | elementName: 'b',
10 | attributes: {},
11 | children: null
12 | }, ' \n ', {
13 | elementName: 'c',
14 | attributes: {},
15 | children: null
16 | }, '\n ', {
17 | elementName: 'd',
18 | attributes: {},
19 | children: null
20 | }, '\n ']
21 | };
22 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-allow-use-variables-customization/actual.js:
--------------------------------------------------------------------------------
1 | var ZVariable = true;
2 | var NotZVariable = true;
3 |
4 | // Include attribute named after the variables to ensure variables are only recognized for elements
5 | var jsxA = ;
6 | var jsxB = ;
7 | var jsxC = {ZVariable};
8 | var jsxD = ;
9 | var jsxE = ;
10 | var jsxF = {NotZVariable};
11 |
--------------------------------------------------------------------------------
/data-guard/src/createArrayValidator.js:
--------------------------------------------------------------------------------
1 | const ValidationContext = require('./ValidationContext')
2 |
3 | function createArrayValidator (validator) {
4 | return array => {
5 | if (!array) {
6 | return false
7 | }
8 |
9 | const validatedItems = array.map(
10 | (value, index) => ValidationContext.run(index, () => validator(value))
11 | )
12 |
13 | for (const index in validatedItems) {
14 | if (!validatedItems[index]) {
15 | return false
16 | }
17 | }
18 |
19 | return true
20 | }
21 | }
22 |
23 | module.exports = createArrayValidator
24 |
--------------------------------------------------------------------------------
/test-dom/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "test-dom",
3 | "version": "1.0.0",
4 | "description": "Easily import a global instance of JSDOM into your tests.",
5 | "author": "Caleb Meredith ",
6 | "license": "MIT",
7 | "repository": "https://github.com/calebmer/node_modules/tree/master/test-dom",
8 | "keywords": [
9 | "dom",
10 | "test",
11 | "easy"
12 | ],
13 | "main": "index.js",
14 | "files": [
15 | "index.js"
16 | ],
17 | "scripts": {},
18 | "dependencies": {
19 | "jsdom": "^9.2.1"
20 | },
21 | "devDependencies": {}
22 | }
23 |
--------------------------------------------------------------------------------
/eslint-config-calebmer/react-native.json:
--------------------------------------------------------------------------------
1 | {
2 | "globals": {
3 | "__DEV__": true
4 | },
5 | "plugins": [
6 | "react-native"
7 | ],
8 | "settings": {
9 | "import/resolver": {
10 | "node": {
11 | "extensions": [
12 | ".js",
13 | ".android.js",
14 | ".ios.js"
15 | ]
16 | }
17 | }
18 | },
19 | "rules": {
20 | "react-native/no-unused-styles": "error",
21 | "react-native/split-platform-components": "off",
22 | "react-native/no-inline-styles": "error",
23 | "react-native/no-color-literals": "error"
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/_assets/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "$1",
3 | "version": "0.0.0",
4 | "description": null,
5 | "author": "Caleb Meredith ",
6 | "license": "MIT",
7 | "repository": "https://github.com/calebmer/node_modules/tree/master/$1",
8 | "keywords": [],
9 | "main": "index.js",
10 | "files": [
11 | "index.js",
12 | "lib"
13 | ],
14 | "scripts": {
15 | "build": "../_scripts/build.sh",
16 | "lint": "../_scripts/lint.sh",
17 | "test": "../_scripts/test.sh",
18 | "release": "../_scripts/release.sh",
19 | },
20 | "dependencies": {},
21 | "devDependencies": {}
22 | }
23 |
--------------------------------------------------------------------------------
/data-guard/src/createObjectValidator.js:
--------------------------------------------------------------------------------
1 | const ValidationContext = require('./ValidationContext')
2 |
3 | function createObjectValidator (shape) {
4 | return object => {
5 | if (!object) {
6 | return false
7 | }
8 |
9 | const validatedKeys = Object.keys(shape).map(key => ValidationContext.run(key, () => {
10 | const validator = shape[key]
11 | const value = object[key]
12 | return validator(value)
13 | }))
14 |
15 | for (const index in validatedKeys) {
16 | if (!validatedKeys[index]) {
17 | return false
18 | }
19 | }
20 |
21 | return true
22 | }
23 | }
24 |
25 | module.exports = createObjectValidator
26 |
--------------------------------------------------------------------------------
/eslint-config-calebmer/flow.json:
--------------------------------------------------------------------------------
1 | {
2 | "plugins": [
3 | "flowtype"
4 | ],
5 | "rules": {
6 | "flowtype/define-flow-type": "error",
7 | "flowtype/require-parameter-type": ["error", { "excludeArrowFunctions": "expressionsOnly" }],
8 | "flowtype/require-return-type": ["error", { "excludeArrowFunctions": "expressionsOnly" }],
9 | "flowtype/require-valid-file-annotation": ["error", "always"],
10 | "flowtype/space-after-type-colon": ["error", "always"],
11 | "flowtype/space-before-type-colon": ["error", "never"],
12 | "flowtype/type-id-match": "off",
13 | "flowtype/use-flow-type": "error",
14 | "flowtype/valid-syntax": "error"
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/data-guard/src/createSuperValidator.js:
--------------------------------------------------------------------------------
1 | const assign = require('lodash/assign')
2 | const mapValues = require('lodash/mapValues')
3 | const Validators = require('./Validators')
4 |
5 | function createSuperValidator (validators = []) {
6 | const superValidator = value => (
7 | validators.reduce((success, validator) => validator(value) && success, true)
8 | )
9 |
10 | assign(
11 | superValidator,
12 | mapValues(
13 | Validators,
14 | createValidator => (...args) => (
15 | createSuperValidator(validators.concat([createValidator(...args)]))
16 | )
17 | )
18 | )
19 |
20 | return superValidator
21 | }
22 |
23 | module.exports = createSuperValidator
24 |
--------------------------------------------------------------------------------
/babel-matrix/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "babel-matrix",
3 | "version": "2.0.0",
4 | "description": "Describe input build syntaxes and output build syntaxes and let babel-matrix figure out your babel configuration for you.",
5 | "author": "Caleb Meredith ",
6 | "license": "MIT",
7 | "repository": "https://github.com/calebmer/node_modules/tree/master/babel-matrix",
8 | "keywords": [
9 | "babel",
10 | "matrix",
11 | "javascript",
12 | "fatigue"
13 | ],
14 | "main": "index.js",
15 | "files": [
16 | "index.js",
17 | "lib"
18 | ],
19 | "scripts": {},
20 | "dependencies": {
21 | "lodash": "^4.6.1"
22 | },
23 | "devDependencies": {}
24 | }
25 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-allow-use-variables-default/actual.js:
--------------------------------------------------------------------------------
1 | var UppercaseVariable = true;
2 | var lowercaseVariable = true;
3 |
4 | // Include attribute named after the variables to ensure variables are only recognized for elements
5 | var jsxA = ;
6 | var jsxB = ;
7 | var jsxC = {UppercaseVariable};
8 | var jsxD = ;
9 | var jsxE = ;
10 | var jsxF = {lowercaseVariable};
11 |
--------------------------------------------------------------------------------
/data-guard/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "data-guard",
3 | "version": "2.1.5",
4 | "description": "A data validation library for any use case.",
5 | "author": "Caleb Meredith ",
6 | "license": "MIT",
7 | "repository": "https://github.com/calebmer/node_modules/tree/master/data-guard",
8 | "keywords": [
9 | "data",
10 | "validation",
11 | "simple",
12 | "guard",
13 | "react",
14 | "prop",
15 | "types",
16 | "function",
17 | "arguments"
18 | ],
19 | "main": "index.js",
20 | "files": [
21 | "index.js",
22 | "lib"
23 | ],
24 | "scripts": {},
25 | "dependencies": {
26 | "lodash": "^4.0.0"
27 | },
28 | "devDependencies": {}
29 | }
30 |
--------------------------------------------------------------------------------
/babel-preset-calebmer/README.md:
--------------------------------------------------------------------------------
1 | # babel-preset-calebmer
2 | This Babel preset holds plugins that make modern JavaScript development with a Babel compiler much easier.
3 |
4 | What’s included?
5 |
6 | - All the ES2015 transforms. ES module transformation can be configured using a `modules` option (true if you don’t want modules compiled into CommonJS).
7 | - All of the ES2016 transforms.
8 | - Assorted proposal transforms, including: trailing commas, async functions, class properties, object rest spread, export extensions, and function bind.
9 | - React transforms with extra development and production transforms. Use the `production` option to configure.
10 | - Loose mode in supported transforms. Use the `production` option to configure.
11 |
--------------------------------------------------------------------------------
/test-dom/README.md:
--------------------------------------------------------------------------------
1 | # test-dom
2 | Ever wanted to test your React or other DOM based app in Node.js? Well luckily there is this great library called JSDOM that lets you interact with DOM structures in a Node.js environment. This package globally exposes an instance of JSDOM when required making it super easy to use in your tests. Just:
3 |
4 | ```js
5 | // Require…
6 | require('test-dom')
7 |
8 | // …and profit!
9 | document.createElement('div')
10 | ```
11 |
12 | The library itself is under 20 lines of code. This is it:
13 |
14 | ```js
15 | var jsdom = require('jsdom').jsdom
16 | var window = jsdom('').defaultView
17 | global.window = window
18 | global.document = window.document
19 | global.navigator = window.navigator
20 | ```
21 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-work-with-members/expected.js:
--------------------------------------------------------------------------------
1 | var object = {
2 | a: 1,
3 | b: {
4 | c: 2
5 | }
6 | };
7 |
8 | var jsxA = {
9 | elementName: object.a,
10 | attributes: {},
11 | children: null
12 | };
13 | var jsxB = {
14 | elementName: object.b.c,
15 | attributes: {},
16 | children: null
17 | };
18 | var jsxC = {
19 | elementName: object.a,
20 | attributes: {},
21 | children: []
22 | };
23 | var jsxD = {
24 | elementName: object.b.c,
25 | attributes: {},
26 | children: []
27 | };
28 | var jsxE = {
29 | elementName: object.a,
30 | attributes: {},
31 | children: [object.a]
32 | };
33 | var jsxF = {
34 | elementName: object.b.c,
35 | attributes: {},
36 | children: [object.b.c]
37 | };
38 |
--------------------------------------------------------------------------------
/babel-preset-calebmer/esnext.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | plugins: [
3 | // [es2016](https://github.com/babel/babel/tree/master/packages/babel-preset-es2016)
4 | require('babel-plugin-transform-exponentiation-operator'),
5 |
6 | // function x(a, b, c,) {}
7 | require('babel-plugin-syntax-trailing-function-commas'),
8 | // await fetch()
9 | require('babel-plugin-syntax-async-functions'),
10 | // class { handleClick = () => { } }
11 | require('babel-plugin-transform-class-properties'),
12 | // { ...todo, completed: true }
13 | require('babel-plugin-transform-object-rest-spread'),
14 | // export foo from './bar'
15 | require('babel-plugin-transform-export-extensions'),
16 | // foo::bar()
17 | require('babel-plugin-transform-function-bind'),
18 | ]
19 | }
20 |
--------------------------------------------------------------------------------
/data-guard/test/guard.test.js:
--------------------------------------------------------------------------------
1 | import assert from 'assert'
2 | import guard from '../src/guard'
3 | import * as v from '../src/Validators'
4 |
5 | describe('guard()', () => {
6 | const guardArgs = [v.number(), v.string()]
7 |
8 | it('wraps a function', () => {
9 | const value = { a: 1, b: 2 }
10 | const func = () => value
11 | const guardedFunc = guard()(func)
12 | assert.equal(func(), guardedFunc())
13 | })
14 |
15 | it('will log an error', () => {
16 | const guardedFunc = guard(...guardArgs)(() => true)
17 | guardedFunc('asd', 3, 5)
18 | guardedFunc(2, 8, 5, 6, [])
19 | })
20 |
21 | it('has a strict mode', () => {
22 | const guardedFunc = guard.strict(...guardArgs)(() => true)
23 | assert.throws(() => guardedFunc('asd', 3, 5), /wrong type/i)
24 | })
25 | })
26 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-output-object/expected.js:
--------------------------------------------------------------------------------
1 | var jsx = {
2 | elementName: "html",
3 | attributes: {
4 | lang: "en"
5 | },
6 | children: [{
7 | elementName: "head",
8 | attributes: {},
9 | children: [{
10 | elementName: "meta",
11 | attributes: {
12 | charSet: "utf8"
13 | },
14 | children: null
15 | }, {
16 | elementName: "title",
17 | attributes: {},
18 | children: ["A JSX Test"]
19 | }]
20 | }, {
21 | elementName: "body",
22 | attributes: {},
23 | children: [{
24 | elementName: "div",
25 | attributes: {
26 | id: "container"
27 | },
28 | children: [{
29 | elementName: "p",
30 | attributes: {},
31 | children: ["Just a basic JSX transformation"]
32 | }]
33 | }]
34 | }]
35 | };
36 |
--------------------------------------------------------------------------------
/data-guard/test/DataGuard.test.js:
--------------------------------------------------------------------------------
1 | import assert from 'assert'
2 | import DataGuard from '../src/DataGuard'
3 |
4 | describe('DataGuard', () => {
5 | it('exposes all of the validators', () => {
6 | assert(DataGuard.any)
7 | assert(DataGuard.string)
8 | assert(DataGuard.shape)
9 | })
10 |
11 | it('returns a super validator after calling one of the validators', () => {
12 | const testValidators = ['any', 'string', 'shape', 'required']
13 | testValidators.forEach(testValidator => {
14 | assert(DataGuard[testValidator]().any)
15 | assert(DataGuard[testValidator]().string)
16 | assert(DataGuard[testValidator]().shape)
17 | assert(DataGuard[testValidator]()[testValidator]().any)
18 | assert(DataGuard[testValidator]()[testValidator]().string)
19 | assert(DataGuard[testValidator]()[testValidator]().shape)
20 | })
21 | })
22 | })
23 |
--------------------------------------------------------------------------------
/babel-preset-calebmer/react.js:
--------------------------------------------------------------------------------
1 | module.exports = function preset (context, opts = {}) {
2 | const production = Boolean(opts.production || process.env.NODE_ENV === 'production')
3 |
4 | return {
5 | plugins: [
6 | require('babel-plugin-transform-react-jsx'),
7 | require('babel-plugin-syntax-jsx'),
8 | require('babel-plugin-transform-react-display-name'),
9 | !production && require('babel-plugin-transform-react-jsx-source'),
10 | !production && require('babel-plugin-transform-react-jsx-self'),
11 | production && require('babel-plugin-transform-react-inline-elements'),
12 | production && require('babel-plugin-transform-react-constant-elements'),
13 | production && require('babel-plugin-transform-react-remove-prop-types').default,
14 | production && require('babel-plugin-transform-react-pure-class-to-function'),
15 | ].filter(Boolean)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/babel-matrix/src/getPlugins.js:
--------------------------------------------------------------------------------
1 | import getPluginSources from './getPluginSources.js'
2 |
3 | /**
4 | * Gets the `require`d form of all of the babel plugins for a given input and
5 | * output list of syntaxes. This function does require that the plugins have
6 | * been installed so they may be `require`d.
7 | *
8 | * @param {[string]} inputSyntaxes A list of input syntaxes to use.
9 | * @param {[string]} outputSyntaxes A list of output syntaxes to use.
10 | * @param {boolean} isProduction A boolean specifying whether or not to include production plugins. Default is false.
11 | * @return {[object]} A list of the `require`d Babel plugins.
12 | */
13 | function getPlugins (inputSyntaxes, outputSyntaxes, isProduction = false) {
14 | const pluginSources = getPluginSources(inputSyntaxes, outputSyntaxes, isProduction)
15 | return pluginSources.map(pluginSource => require(pluginSource.name))
16 | }
17 |
18 | export default getPlugins
19 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "babel-plugin-transform-jsx",
3 | "version": "2.0.0",
4 | "description": "Turn JSX into static objects.",
5 | "author": "Caleb Meredith ",
6 | "contributors": [
7 | {
8 | "name": "Brandon Payton",
9 | "email": "brandon@happycode.net",
10 | "url": "http://happycode.net"
11 | }
12 | ],
13 | "license": "MIT",
14 | "repository": "https://github.com/calebmer/node_modules/tree/master/babel-plugin-transform-jsx",
15 | "keywords": [
16 | "jsx",
17 | "babel-plugin",
18 | "transform",
19 | "open",
20 | "standard",
21 | "plugin",
22 | "babel"
23 | ],
24 | "main": "index.js",
25 | "files": [
26 | "index.js",
27 | "lib"
28 | ],
29 | "scripts": {},
30 | "dependencies": {
31 | "babel-plugin-syntax-jsx": "^6.3.13",
32 | "esutils": "^2.0.2",
33 | "lodash": "^4.0.0"
34 | },
35 | "devDependencies": {
36 | "babel-core": "^6.4.0",
37 | "babel-plugin-external-helpers": "^6.4.0"
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-allow-use-variables-customization/expected.js:
--------------------------------------------------------------------------------
1 | var ZVariable = true;
2 | var NotZVariable = true;
3 |
4 | // Include attribute named after the variables to ensure variables are only recognized for elements
5 | var jsxA = {
6 | elementName: ZVariable,
7 | attributes: {
8 | ZVariable: ""
9 | },
10 | children: null
11 | };
12 | var jsxB = {
13 | elementName: ZVariable,
14 | attributes: {
15 | ZVariable: ""
16 | },
17 | children: []
18 | };
19 | var jsxC = {
20 | elementName: ZVariable,
21 | attributes: {
22 | ZVariable: ""
23 | },
24 | children: [ZVariable]
25 | };
26 | var jsxD = {
27 | elementName: "NotZVariable",
28 | attributes: {
29 | NotZVariable: ""
30 | },
31 | children: null
32 | };
33 | var jsxE = {
34 | elementName: "NotZVariable",
35 | attributes: {
36 | NotZVariable: ""
37 | },
38 | children: []
39 | };
40 | var jsxF = {
41 | elementName: "NotZVariable",
42 | attributes: {
43 | NotZVariable: ""
44 | },
45 | children: [NotZVariable]
46 | };
47 |
--------------------------------------------------------------------------------
/vulture-redux/src/connect.js:
--------------------------------------------------------------------------------
1 | const defaultMapStateToData = () => ({})
2 | const defaultMapDispatchToData = dispatch => ({ dispatch })
3 | const defaultMergeData = (stateData, dispatchData, ownData) => ({
4 | ...ownData,
5 | ...stateData,
6 | ...dispatchData
7 | })
8 |
9 | export default function connect (
10 | mapStateToData = defaultMapStateToData,
11 | mapDispatchToData = defaultMapDispatchToData,
12 | mergeData = defaultMergeData
13 | ) {
14 | return component => function connectedComponent (ownData, ...args) {
15 | if (!ownData || !ownData.store.dispatch || !ownData.store.getState) {
16 | throw new Error('To connect to redux, the first argument must be an object with a store property.')
17 | }
18 |
19 | const { store: { getState, dispatch } } = ownData
20 | const state = getState()
21 | const stateData = mapStateToData(state, ownData)
22 | const dispatchData = mapDispatchToData(dispatch, ownData)
23 | const mergedData = mergeData(stateData, dispatchData, ownData)
24 |
25 | return component.call(this, mergedData, ...args)
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/data-guard/src/validate.js:
--------------------------------------------------------------------------------
1 | const Messages = require('./Messages')
2 | const normalizeValidator = require('./normalizeValidator')
3 | const ValidationContext = require('./ValidationContext')
4 |
5 | const createValidate = ({ strict = false } = {}) => (validator, maybeValue) => {
6 | const actuallyValidate = value => {
7 | validator = normalizeValidator(validator)
8 | const result = ValidationContext.runValidation(() => validator(value))
9 |
10 | if (strict) {
11 | result.details.forEach(({ path, value, errors }) =>
12 | errors.forEach(name => {
13 | throw new Error(Messages.create(name, path, value))
14 | })
15 | )
16 | if (!result.success) {
17 | throw new Error('Validation failed for unknown reasons.')
18 | }
19 | return true
20 | }
21 |
22 | return result
23 | }
24 |
25 | if (maybeValue) {
26 | return actuallyValidate(maybeValue)
27 | }
28 |
29 | return actuallyValidate
30 | }
31 |
32 | const validate = createValidate()
33 | validate.strict = createValidate({ strict: true })
34 |
35 | module.exports = validate
36 |
--------------------------------------------------------------------------------
/eslint-config-calebmer/react-web.json:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "browser": true
4 | },
5 | "plugins": [
6 | "jsx-a11y"
7 | ],
8 | "rules": {
9 | "jsx-a11y/aria-props": "error",
10 | "jsx-a11y/aria-proptypes": "error",
11 | "jsx-a11y/aria-role": "error",
12 | "jsx-a11y/aria-unsupported-elements": "error",
13 | "jsx-a11y/heading-has-content": "error",
14 | "jsx-a11y/href-no-hash": "error",
15 | "jsx-a11y/html-has-lang": "error",
16 | "jsx-a11y/img-has-alt": "error",
17 | "jsx-a11y/img-redundant-alt": "error",
18 | "jsx-a11y/label-has-for": "error",
19 | "jsx-a11y/lang": "error",
20 | "jsx-a11y/mouse-events-have-key-events": "error",
21 | "jsx-a11y/no-access-key": "error",
22 | "jsx-a11y/no-marquee": "error",
23 | "jsx-a11y/no-onchange": "error",
24 | "jsx-a11y/onclick-has-focus": "error",
25 | "jsx-a11y/onclick-has-role": "error",
26 | "jsx-a11y/role-has-required-aria-props": "error",
27 | "jsx-a11y/role-supports-aria-props": "error",
28 | "jsx-a11y/scope": "error",
29 | "jsx-a11y/tabindex-no-positive": "error"
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/_assets/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2016 Caleb Meredith
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining
4 | a copy of this software and associated documentation files (the
5 | "Software"), to deal in the Software without restriction, including
6 | without limitation the rights to use, copy, modify, merge, publish,
7 | distribute, sublicense, and/or sell copies of the Software, and to
8 | permit persons to whom the Software is furnished to do so, subject to
9 | the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included
12 | in all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/calebmer/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2016 Caleb Meredith
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining
4 | a copy of this software and associated documentation files (the
5 | "Software"), to deal in the Software without restriction, including
6 | without limitation the rights to use, copy, modify, merge, publish,
7 | distribute, sublicense, and/or sell copies of the Software, and to
8 | permit persons to whom the Software is furnished to do so, subject to
9 | the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included
12 | in all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/data-guard/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2016 Caleb Meredith
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining
4 | a copy of this software and associated documentation files (the
5 | "Software"), to deal in the Software without restriction, including
6 | without limitation the rights to use, copy, modify, merge, publish,
7 | distribute, sublicense, and/or sell copies of the Software, and to
8 | permit persons to whom the Software is furnished to do so, subject to
9 | the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included
12 | in all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/test-dom/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2016 Caleb Meredith
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining
4 | a copy of this software and associated documentation files (the
5 | "Software"), to deal in the Software without restriction, including
6 | without limitation the rights to use, copy, modify, merge, publish,
7 | distribute, sublicense, and/or sell copies of the Software, and to
8 | permit persons to whom the Software is furnished to do so, subject to
9 | the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included
12 | in all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/babel-matrix/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2016 Caleb Meredith
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining
4 | a copy of this software and associated documentation files (the
5 | "Software"), to deal in the Software without restriction, including
6 | without limitation the rights to use, copy, modify, merge, publish,
7 | distribute, sublicense, and/or sell copies of the Software, and to
8 | permit persons to whom the Software is furnished to do so, subject to
9 | the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included
12 | in all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/vulture-redux/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2016 Caleb Meredith
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining
4 | a copy of this software and associated documentation files (the
5 | "Software"), to deal in the Software without restriction, including
6 | without limitation the rights to use, copy, modify, merge, publish,
7 | distribute, sublicense, and/or sell copies of the Software, and to
8 | permit persons to whom the Software is furnished to do so, subject to
9 | the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included
12 | in all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/babel-preset-calebmer/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2016 Caleb Meredith
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining
4 | a copy of this software and associated documentation files (the
5 | "Software"), to deal in the Software without restriction, including
6 | without limitation the rights to use, copy, modify, merge, publish,
7 | distribute, sublicense, and/or sell copies of the Software, and to
8 | permit persons to whom the Software is furnished to do so, subject to
9 | the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included
12 | in all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2016 Caleb Meredith
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining
4 | a copy of this software and associated documentation files (the
5 | "Software"), to deal in the Software without restriction, including
6 | without limitation the rights to use, copy, modify, merge, publish,
7 | distribute, sublicense, and/or sell copies of the Software, and to
8 | permit persons to whom the Software is furnished to do so, subject to
9 | the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included
12 | in all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/eslint-config-calebmer/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2016 Caleb Meredith
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining
4 | a copy of this software and associated documentation files (the
5 | "Software"), to deal in the Software without restriction, including
6 | without limitation the rights to use, copy, modify, merge, publish,
7 | distribute, sublicense, and/or sell copies of the Software, and to
8 | permit persons to whom the Software is furnished to do so, subject to
9 | the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included
12 | in all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-allow-use-variables-default/expected.js:
--------------------------------------------------------------------------------
1 | var UppercaseVariable = true;
2 | var lowercaseVariable = true;
3 |
4 | // Include attribute named after the variables to ensure variables are only recognized for elements
5 | var jsxA = {
6 | elementName: UppercaseVariable,
7 | attributes: {
8 | UppercaseVariable: ""
9 | },
10 | children: null
11 | };
12 | var jsxB = {
13 | elementName: UppercaseVariable,
14 | attributes: {
15 | UppercaseVariable: ""
16 | },
17 | children: []
18 | };
19 | var jsxC = {
20 | elementName: UppercaseVariable,
21 | attributes: {
22 | UppercaseVariable: ""
23 | },
24 | children: [UppercaseVariable]
25 | };
26 | var jsxD = {
27 | elementName: "lowercaseVariable",
28 | attributes: {
29 | lowercaseVariable: ""
30 | },
31 | children: null
32 | };
33 | var jsxE = {
34 | elementName: "lowercaseVariable",
35 | attributes: {
36 | lowercaseVariable: ""
37 | },
38 | children: []
39 | };
40 | var jsxF = {
41 | elementName: "lowercaseVariable",
42 | attributes: {
43 | lowercaseVariable: ""
44 | },
45 | children: [lowercaseVariable]
46 | };
47 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures.test.js:
--------------------------------------------------------------------------------
1 | import Assert from 'assert'
2 | import Path from 'path'
3 | import Fs from 'fs'
4 |
5 | const Babel = require('babel-core')
6 |
7 | const fixturesDirectory = Path.join(__dirname, 'fixtures')
8 |
9 | const babelOptions = options => ({
10 | plugins: [
11 | require('babel-plugin-external-helpers'),
12 | [require('../src').default, options]
13 | ]
14 | })
15 |
16 | Fs.readdirSync(fixturesDirectory).forEach(testDirectory)
17 |
18 | function testDirectory(name) {
19 | const options = {}
20 | const testDirectory = Path.join(fixturesDirectory, name)
21 | const actualCode = Fs.readFileSync(Path.join(testDirectory, 'actual.js'), 'utf8')
22 | const expectedCode = Fs.readFileSync(Path.join(testDirectory, 'expected.js'), 'utf8')
23 |
24 | if (Fs.existsSync(Path.join(testDirectory, 'options.json'))) {
25 | Object.assign(options, JSON.parse(Fs.readFileSync(Path.join(testDirectory, 'options.json'), 'utf8')))
26 | }
27 |
28 | it(name, () => {
29 | const transformedCode = Babel.transform(actualCode, babelOptions(options)).code
30 | Assert.equal(transformedCode + '\n', expectedCode)
31 | })
32 | }
33 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/test/fixtures/should-work-with-spread-attributes/expected.js:
--------------------------------------------------------------------------------
1 | var objectA = { x1: 1, y1: 2, z1: 3 };
2 | var objectB = { x2: 1, y2: 2, z2: 3 };
3 | var jsxA = {
4 | elementName: "div",
5 | attributes: babelHelpers.extends({}, objectA),
6 | children: []
7 | };
8 | var jsxB = {
9 | elementName: "div",
10 | attributes: babelHelpers.extends({
11 | a: 1,
12 | b: 2
13 | }, objectA),
14 | children: []
15 | };
16 | var jsxC = {
17 | elementName: "div",
18 | attributes: babelHelpers.extends({}, objectA, {
19 | a: 1,
20 | b: 2
21 | }),
22 | children: []
23 | };
24 | var jsxD = {
25 | elementName: "div",
26 | attributes: babelHelpers.extends({
27 | a: 1
28 | }, objectA, {
29 | b: 2
30 | }),
31 | children: []
32 | };
33 | var jsxE = {
34 | elementName: "div",
35 | attributes: babelHelpers.extends({
36 | a: 1
37 | }, objectA, objectB, {
38 | b: 2
39 | }),
40 | children: []
41 | };
42 | var jsxF = {
43 | elementName: "div",
44 | attributes: babelHelpers.extends({
45 | a: 1
46 | }, objectA, {
47 | b: 2
48 | }, objectB, {
49 | c: 3
50 | }),
51 | children: []
52 | };
53 |
--------------------------------------------------------------------------------
/data-guard/test/createSuperValidator.test.js:
--------------------------------------------------------------------------------
1 | import assert from 'assert'
2 | import isFunction from 'lodash/isFunction'
3 | import createSuperValidator from '../src/createSuperValidator'
4 |
5 | describe('createSuperValidator()', () => {
6 | it('will create a function with all the validators as properties', () => {
7 | assert(isFunction(createSuperValidator()))
8 | assert(createSuperValidator().any)
9 | assert(createSuperValidator().string)
10 | assert(createSuperValidator().shape)
11 | })
12 |
13 | it('can chain validators', () => {
14 | const superValidator = createSuperValidator().any().string().shape()
15 | assert(isFunction(createSuperValidator()))
16 | assert(createSuperValidator().any)
17 | assert(createSuperValidator().string)
18 | assert(createSuperValidator().shape)
19 | })
20 |
21 | it('will create new super validators when chaining', () => {
22 | const superValidator = createSuperValidator()
23 | assert.notEqual(superValidator, superValidator.string())
24 | })
25 |
26 | it('will run all validators', () => {
27 | assert(createSuperValidator().string().match(/^\d+$/)('4127'))
28 | assert(!createSuperValidator().string().match(/^\d+$/)('4127x'))
29 | })
30 | })
31 |
--------------------------------------------------------------------------------
/eslint-config-calebmer/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "eslint-config-calebmer",
3 | "version": "8.2.1",
4 | "description": "An opinionated eslint config with attitude 😘",
5 | "author": "Caleb Meredith ",
6 | "license": "MIT",
7 | "repository": "https://github.com/calebmer/node_modules/tree/master/eslint-config-calebmer",
8 | "keywords": [
9 | "eslint-config",
10 | "eslint",
11 | "config",
12 | "calebmer"
13 | ],
14 | "main": "index.js",
15 | "files": [
16 | "index.json",
17 | "flow.json",
18 | "react.json",
19 | "react-native.json",
20 | "react-web.json"
21 | ],
22 | "scripts": {
23 | "build": "../_scripts/build.sh",
24 | "lint": "../_scripts/lint.sh",
25 | "test": "../_scripts/test.sh",
26 | "release": "../_scripts/release.sh"
27 | },
28 | "dependencies": {
29 | "babel-eslint": "^6.0.2",
30 | "eslint": "3.5.0",
31 | "eslint-plugin-babel": "3.3.0",
32 | "eslint-plugin-flowtype": "^2.7.0",
33 | "eslint-plugin-import": "1.12.0",
34 | "eslint-plugin-jsdoc": "2.3.1",
35 | "eslint-plugin-jsx-a11y": "2.0.1",
36 | "eslint-plugin-promise": "2.0.0",
37 | "eslint-plugin-react": "6.0.0",
38 | "eslint-plugin-react-native": "1.2.1",
39 | "eslint-plugin-xo": "^0.5.1"
40 | },
41 | "devDependencies": {}
42 | }
43 |
--------------------------------------------------------------------------------
/data-guard/src/guard.js:
--------------------------------------------------------------------------------
1 | const Messages = require('./Messages')
2 | const validate = require('./validate')
3 |
4 | const unknownValidationMessage = 'Validation failed for unknown reasons'
5 |
6 | const createGuard = ({ strict = false } = {}) => (...validators) => func => function guardedFunction (...args) {
7 | const funcName = func.name
8 |
9 | for (const index in validators) {
10 | const { success, details } = validate(validators[index], args[index])
11 | if (!success) {
12 | let warned = false
13 | details.forEach(({ path, value, errors }) =>
14 | errors.forEach(name => {
15 | warned = true
16 | const errorMessage = Messages.create(name, `/${index}${path === '/' ? '' : path}`, value)
17 | if (strict) {
18 | throw new Error(errorMessage)
19 | } else {
20 | console.warn(`Validation error for ${funcName || 'an anonymous function'}. ${errorMessage}`)
21 | }
22 | })
23 | )
24 | if (!warned) {
25 | if (strict) {
26 | throw new Error(unknownValidationMessage)
27 | } else {
28 | console.warn(unknownValidationMessage)
29 | }
30 | }
31 | }
32 | }
33 |
34 | return func.apply(this, args)
35 | }
36 |
37 | const guard = createGuard()
38 | guard.strict = createGuard({ strict: true })
39 |
40 | module.exports = guard
41 |
--------------------------------------------------------------------------------
/babel-matrix/src/getPluginSources.js:
--------------------------------------------------------------------------------
1 | import { uniq, lowerCase } from 'lodash'
2 | import getCellPluginSources from './getCellPluginSources.js'
3 |
4 | /**
5 | * Gets the `PluginSource` form a last of input and a list of output syntaxes.
6 | *
7 | * @param {[string]} inputSyntaxes A list of input syntaxes to use.
8 | * @param {[string]} outputSyntaxes A list of output syntaxes to use.
9 | * @param {boolean} isProduction A boolean specifying whether or not to include production plugins. Default is false.
10 | * @return {[PluginSource]} A list of `PluginSource`s to be used by Babel when transpiling.
11 | */
12 | function getPluginSources (inputSyntaxes, outputSyntaxes, isProduction = false) {
13 | const pluginSources = []
14 | const addPluginSources = ps => ps.forEach(p => pluginSources.push(p))
15 |
16 | // Make sure we only have unique lower case syntaxes in our lists.
17 | inputSyntaxes = uniq(inputSyntaxes.map(lowerCase))
18 | outputSyntaxes = uniq(outputSyntaxes.map(lowerCase))
19 |
20 | // Get all of the combinations for the input and output syntaxes and add the
21 | // plugins they use.
22 | inputSyntaxes.forEach(inputSyntax => {
23 | outputSyntaxes.forEach(outputSyntax => {
24 | const cellPluginSources = getCellPluginSources(inputSyntax, outputSyntax, isProduction)
25 | addPluginSources(cellPluginSources)
26 | })
27 | })
28 |
29 | return pluginSources
30 | }
31 |
32 | export default getPluginSources
33 |
--------------------------------------------------------------------------------
/data-guard/src/ValidationContext.js:
--------------------------------------------------------------------------------
1 | const ValidationContext = {
2 | root: null,
3 | stack: [],
4 | details: [],
5 |
6 | head () {
7 | const { stack } = this
8 | return stack.length === 0 ? null : stack[stack.length - 1]
9 | },
10 |
11 | runValidation (validation) {
12 | const { stack, details } = this
13 |
14 | const detail = createDetail()
15 |
16 | details.push(detail)
17 | stack.push(detail)
18 |
19 | const success = validation()
20 |
21 | // Reset the stack and details.
22 | this.stack = []
23 | this.details = []
24 |
25 | // It‘s more asthetic to have this be `/` representing the root.
26 | detail.path = '/'
27 |
28 | return {
29 | success,
30 | details: details.filter(detail => detail.errors.length > 0)
31 | }
32 | },
33 |
34 | run (name, callback) {
35 | const { stack, details } = this
36 |
37 | // We can not run a named context as root.
38 | if (stack.length === 0) {
39 | return callback()
40 | }
41 |
42 | const detail = createDetail(`${this.head().path}/${name}`)
43 |
44 | details.push(detail)
45 | stack.push(detail)
46 | const result = callback()
47 | stack.pop()
48 | return result
49 | },
50 |
51 | setValue (value) {
52 | const head = this.head()
53 | if (head) {
54 | head.value = value
55 | }
56 | },
57 |
58 | addError (error) {
59 | const head = this.head()
60 | if (head) {
61 | head.errors.push(error)
62 | }
63 | }
64 | }
65 |
66 | module.exports = ValidationContext
67 |
68 | function createDetail (path = '') {
69 | return {
70 | path,
71 | errors: []
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/data-guard/src/Messages.js:
--------------------------------------------------------------------------------
1 | const isString = require('lodash/isString')
2 | const isArray = require('lodash/isArray')
3 |
4 | const Messages = {
5 | creators: {
6 | boolean: value => `${getValue(value)} is the wrong type. Must be boolean, not ${getType(value)}`,
7 | number: value => `${getValue(value)} is the wrong type. Must be number, not ${getType(value)}`,
8 | string: value => `${getValue(value)} is the wrong type. Must be string, not ${getType(value)}`,
9 | object: value => `${getValue(value)} is the wrong type. Must be object, not ${getType(value)}`,
10 | array: value => `${getValue(value)} is the wrong type. Must be array, not ${getType(value)}`,
11 | function: value => `${getValue(value)} is the wrong type. Must be function, not ${getType(value)}`,
12 | required: () => `A value is required`,
13 | shape: () => `The value has an incorrect shape`,
14 | items: () => `Some of the item are invalid`,
15 | match: value => `${getValue(value)} failed its regular expression test`,
16 | enum: value => `${getValue(value)} is not one of the defined values`,
17 | instanceOf: value => `${getValue(value)} is not an instance of the defined constructor`
18 | },
19 |
20 | create (name, path, value) {
21 | const messageCreator = this.creators[name]
22 | if (messageCreator) {
23 | return `${messageCreator(value)} @ ${path}`
24 | } else {
25 | return `${value} failed ${name} validation @ ${path}`
26 | }
27 | }
28 | }
29 |
30 | module.exports = Messages
31 |
32 | function getValue (value) {
33 | return isString(value) ? `"${value}"` : value.toString()
34 | }
35 |
36 | function getType (value) {
37 | return isArray(value) ? 'array' : typeof value
38 | }
39 |
--------------------------------------------------------------------------------
/data-guard/src/Validators.js:
--------------------------------------------------------------------------------
1 | const isBoolean = require('lodash/isBoolean')
2 | const isNumber = require('lodash/isNumber')
3 | const isString = require('lodash/isString')
4 | const isObject = require('lodash/isObjectLike')
5 | const isArray = require('lodash/isArrayLikeObject')
6 | const isFunction = require('lodash/isFunction')
7 | const mapValues = require('lodash/mapValues')
8 | const flow = require('lodash/flow')
9 | const normalizeValidator = require('./normalizeValidator')
10 | const createObjectValidator = require('./createObjectValidator')
11 | const createArrayValidator = require('./createArrayValidator')
12 | const ValidationContext = require('./ValidationContext')
13 |
14 | const maybe = validator => value => value == null || validator(value)
15 |
16 | const Validators = mapValues({
17 | any: () => () => true,
18 | boolean: () => maybe(isBoolean),
19 | number: () => maybe(isNumber),
20 | string: () => maybe(isString),
21 | object: () => maybe(value => isObject(value) && !isArray(value)),
22 | array: () => maybe(isArray),
23 | function: () => maybe(isFunction),
24 | required: () => value => value != null,
25 | shape: createObjectValidator,
26 | items: flow(normalizeValidator, createArrayValidator),
27 | match: regex => value => regex.test(value),
28 | enum: values => value => values.indexOf(value) !== -1,
29 | instanceOf: func => value => value instanceof func
30 | }, transformToReportError)
31 |
32 | module.exports = Validators
33 |
34 | function transformToReportError (createValidator, name) {
35 | return (...args) => {
36 | const validator = createValidator(...args)
37 | return value => {
38 | const success = validator(value)
39 |
40 | ValidationContext.setValue(value)
41 |
42 | if (!success) {
43 | ValidationContext.addError(name)
44 | }
45 |
46 | return success
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/_scripts/release.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | bold=$(tput bold)
4 | normal=$(tput sgr0)
5 | scripts=$(cd $(dirname ${BASH_SOURCE[0]}) && pwd)
6 |
7 | if [ ! -f package.json ]; then
8 | echo "Current working directory is not a node package!"
9 | exit 1
10 | fi
11 |
12 | require_clean_work_tree() {
13 | # Update the index
14 | git update-index -q --ignore-submodules --refresh
15 | err=0
16 |
17 | # Disallow unstaged changes in the working tree
18 | if ! git diff-files --quiet --ignore-submodules --
19 | then
20 | echo >&2 "You have unstaged changes."
21 | git diff-files --name-status -r --ignore-submodules -- >&2
22 | err=1
23 | fi
24 |
25 | # Disallow uncommitted changes in the index
26 | if ! git diff-index --cached --quiet HEAD --ignore-submodules --
27 | then
28 | echo >&2 "Your index contains uncommitted changes."
29 | git diff-index --cached --name-status -r --ignore-submodules HEAD -- >&2
30 | err=1
31 | fi
32 |
33 | if [ $err = 1 ]
34 | then
35 | echo >&2 "Please commit or stash them."
36 | exit 1
37 | fi
38 | }
39 |
40 | require_clean_work_tree
41 |
42 | curr_version=$(node -e "console.log(require('$PWD/package.json').version)")
43 | next_version=$(node -e "console.log(require('semver').inc('$curr_version', '${1:-patch}'))")
44 |
45 | echo "The current version is ${bold}v${curr_version}${normal} and the new version will be ${bold}v${next_version}${normal}"
46 | read -p "Is this ok? [y/n] " -n 1 -r
47 | echo
48 |
49 | if [[ $REPLY =~ ^[^Yy]$ ]]
50 | then
51 | echo "Ok, maybe later."
52 | exit 0
53 | fi
54 |
55 | export VERSION=$next_version
56 |
57 | git checkout master
58 |
59 | $scripts/lint.sh || exit 1
60 | $scripts/test.sh || exit 1
61 | $scripts/build.sh || exit 1
62 |
63 | node -e "var fs = require('fs'); var pkg = require('$PWD/package.json'); pkg.version = '$VERSION'; fs.writeFileSync('$PWD/package.json', JSON.stringify(pkg, null, 2) + '\n');"
64 |
65 | npm publish || exit 1
66 |
67 | git add package.json
68 | git commit -m "$(basename $(pwd)) v${VERSION}"
69 | git push origin master
70 |
--------------------------------------------------------------------------------
/eslint-config-calebmer/react.json:
--------------------------------------------------------------------------------
1 | {
2 | "ecmaFeatures": {
3 | "jsx": true
4 | },
5 | "plugins": [
6 | "react"
7 | ],
8 | "rules": {
9 | "react/display-name": "off",
10 | "react/forbid-prop-types": "off",
11 | "react/no-danger": "off",
12 | "react/no-deprecated": "error",
13 | "react/no-did-mount-set-state": "error",
14 | "react/no-did-update-set-state": "error",
15 | "react/no-direct-mutation-state": "error",
16 | "react/no-find-dom-node": "error",
17 | "react/no-is-mounted": "error",
18 | "react/no-multi-comp": ["error", { "ignoreStateless": true }],
19 | "react/no-render-return-value": "off",
20 | "react/no-set-state": "off",
21 | "react/no-unknown-property": "error",
22 | "react/prefer-es6-class": "error",
23 | "react/prefer-stateless-function": "error",
24 | "react/prop-types": "error",
25 | "react/react-in-jsx-scope": "error",
26 | "react/require-optimization": "off",
27 | "react/require-render-return": "error",
28 | "react/self-closing-comp": "error",
29 | "react/sort-comp": "error",
30 | "react/jsx-boolean-value": ["error", "always"],
31 | "react/jsx-closing-bracket-location": ["error", "tag-aligned"],
32 | "react/jsx-curly-spacing": ["error", "never"],
33 | "react/jsx-equals-spacing": ["error", "never"],
34 | "react/jsx-filename-extension": "off",
35 | "react/jsx-first-prop-new-line": "off",
36 | "react/jsx-handler-names": "off",
37 | "react/jsx-indent-props": ["error", 2],
38 | "react/jsx-key": "error",
39 | "react/jsx-max-props-per-line": "off",
40 | "react/jsx-no-bind": "off",
41 | "react/jsx-no-comment-textnodes": "error",
42 | "react/jsx-no-duplicate-props": "error",
43 | "react/jsx-no-literals": "off",
44 | "react/jsx-no-target-blank": "error",
45 | "react/jsx-no-undef": "error",
46 | "react/jsx-pascal-case": "error",
47 | "react/jsx-sort-prop-types": "off",
48 | "react/jsx-sort-props": "off",
49 | "react/jsx-space-before-closing": ["error", "never"],
50 | "react/jsx-uses-react": "error",
51 | "react/jsx-uses-vars": "error",
52 | "react/jsx-wrap-multilines": "error"
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/babel-matrix/test/getCellPluginSources.test.js:
--------------------------------------------------------------------------------
1 | import assert from 'assert'
2 | import * as s from '../src/syntaxes.js'
3 | import getCellPluginSources from '../src/getCellPluginSources.js'
4 |
5 | describe('getCellPluginSources', () => {
6 | it('can’t find plugins for input basic module systems', () => {
7 | assert.throws(() => getCellPluginSources(s.COMMON_JS, s.AMD))
8 | assert.throws(() => getCellPluginSources(s.AMD, s.AMD))
9 | assert.throws(() => getCellPluginSources(s.UMD, s.SYSTEM_JS))
10 | assert.throws(() => getCellPluginSources(s.SYSTEM_JS, s.COMMON_JS))
11 | assert.equal(getCellPluginSources(s.SYSTEM_JS, s.REACT).length, 0)
12 | assert.equal(getCellPluginSources(s.SYSTEM_JS, s.ES5).length, 0)
13 | })
14 |
15 | it('will always add the strict module for es modules', () => {
16 | assert.equal(getCellPluginSources(s.ES_MODULES, s.COMMON_JS).length, 2)
17 | assert.equal(getCellPluginSources(s.ES_MODULES, s.AMD).length, 2)
18 | assert.equal(getCellPluginSources(s.ES_MODULES, s.UMD).length, 2)
19 | assert.equal(getCellPluginSources(s.ES_MODULES, s.SYSTEM_JS).length, 2)
20 | assert.equal(getCellPluginSources(s.ES_MODULES, s.REACT).length, 1)
21 | assert.equal(getCellPluginSources(s.ES_MODULES, s.ES6).length, 1)
22 | assert.equal(getCellPluginSources(s.ES_MODULES, s.ESNEXT).length, 1)
23 | })
24 |
25 | it('won’t build old versions to future versions', () => {
26 | assert.throws(() => getCellPluginSources(s.ES5, s.ES6))
27 | assert.throws(() => getCellPluginSources(s.ES5, s.ESNEXT))
28 | assert.throws(() => getCellPluginSources(s.ES6, s.ESNEXT))
29 | })
30 |
31 | it('will add lot’s of plugins for large presets', () => {
32 | assert.equal(getCellPluginSources(s.ES6, s.ES5).length, 20)
33 | assert.equal(getCellPluginSources(s.ESNEXT, s.ES6).length, 10)
34 | assert.equal(getCellPluginSources(s.ESNEXT, s.ES5).length, 30)
35 | })
36 |
37 | it('singular features will always add their plugins unless they are there', () => {
38 | assert.equal(getCellPluginSources(s.REACT, s.ES5).length, 3)
39 | assert.equal(getCellPluginSources(s.REACT, s.REACT).length, 0)
40 | assert.equal(getCellPluginSources(s.FLOW, s.REACT).length, 2)
41 | assert.equal(getCellPluginSources(s.FLOW, s.FLOW).length, 0)
42 | })
43 |
44 | it('react will add extra plugins in production', () => {
45 | assert.equal(getCellPluginSources(s.REACT, s.ES5, true).length, 5)
46 | })
47 | })
48 |
--------------------------------------------------------------------------------
/babel-matrix/README.md:
--------------------------------------------------------------------------------
1 | # babel-matrix
2 | Describe input build syntaxes and output build syntaxes and let `babel-matrix` figure out your babel configuration for you.
3 |
4 | There are so many different syntaxes you want to use, and so many targets to build to. NodeJS, the Browser, Webpack, Webpack with ES Module support, and the list goes on…
5 |
6 | In addition there are hundreds of Babel plugins and all of their versions that you also have to worry about.
7 |
8 | Well do not fear, `babel-matrix` is here! `babel-matrix` aims to make your Babel configuration *easy* to understand. Simply define a list of input syntaxes, for example `es6`, `esmodule`, `react`, and `flow`. A list of output syntaxes, like `es5` and `cjs`, and `babel-matrix` will get a list of all the babel plugins you will need to get from your ES6 React with Flow syntax to your CommonJS ES5 syntax for Webpack.
9 |
10 | Supported syntaxes are:
11 |
12 | - commonjs
13 | - amd
14 | - umd
15 | - systemjs
16 | - esmodule
17 | - es5
18 | - es6
19 | - esnext
20 | - react
21 | - flow
22 |
23 | And any more can be added at your request!
24 |
25 | ## API
26 | This functions are exported as named properties on the object you get through `require`. So you can import: `import { getPlugins } from 'babel-matrix'`, or require: `var getPlugins = require('babel-matrix').getPlugins` like so.
27 |
28 | ### `getPlugins(inputSyntaxes: [string], outputSyntaxes: [string], isProduction: boolean): [object]`
29 | This function takes a list of input syntaxes (e.g. `['es6', 'esmodule', 'react', 'flow']`) and a list of output syntaxes (e.g. `['es5', 'cjs']`) and return an array of the `require`d Babel plugins needed to transform your input syntaxes into your output syntaxes.
30 |
31 | **Note:** If you do not have the packages `babel-matrix` expects in your `node_modules` directory, this function will not work. Look at the next function to get information to install your plugins.
32 |
33 | ### `getPluginSources(inputSyntaxes: [string], outputSyntaxes: [string], isProduction: boolean): [PluginSource]`
34 | This function takes the same parameters as `getPlugins`, except instead of `require`ing the modules, it returns a list of objects. The objects returned in the list have two properties:
35 |
36 | - `name`: This is the name used to `require` the plugin.
37 | - `version`: This is the version of the plugin `name` we want.
38 |
39 | If you don’t have the plugins pre-installed you should use this function to install the plugins first.
40 |
--------------------------------------------------------------------------------
/babel-preset-calebmer/es2015.js:
--------------------------------------------------------------------------------
1 | const moduleTypes = ['native', 'commonjs', 'amd', 'umd', 'systemjs']
2 |
3 | module.exports = function preset (context, opts = {}) {
4 | const modules = opts.modules || 'commonjs'
5 | const production = Boolean(opts.production || process.env.NODE_ENV === 'production')
6 | const loose = production
7 |
8 | if (moduleTypes.indexOf(modules) === -1)
9 | throw new Error(`The string '${modules}' is not a valid module type.`)
10 |
11 | return {
12 | plugins: [
13 | // [es2015](https://github.com/babel/babel/tree/master/packages/babel-preset-es2015)
14 | [require('babel-plugin-transform-es2015-template-literals'), { loose }],
15 | require('babel-plugin-transform-es2015-literals'),
16 | require('babel-plugin-transform-es2015-function-name'),
17 | [require('babel-plugin-transform-es2015-arrow-functions')],
18 | require('babel-plugin-transform-es2015-block-scoped-functions'),
19 | [require('babel-plugin-transform-es2015-classes'), { loose }],
20 | require('babel-plugin-transform-es2015-object-super'),
21 | require('babel-plugin-transform-es2015-shorthand-properties'),
22 | require('babel-plugin-transform-es2015-duplicate-keys'),
23 | [require('babel-plugin-transform-es2015-computed-properties'), { loose }],
24 | [require('babel-plugin-transform-es2015-for-of'), { loose }],
25 | require('babel-plugin-transform-es2015-sticky-regex'),
26 | require('babel-plugin-transform-es2015-unicode-regex'),
27 | require('babel-plugin-check-es2015-constants'),
28 | [require('babel-plugin-transform-es2015-spread'), { loose }],
29 | require('babel-plugin-transform-es2015-parameters'),
30 | [require('babel-plugin-transform-es2015-destructuring'), { loose }],
31 | require('babel-plugin-transform-es2015-block-scoping'),
32 | require('babel-plugin-transform-es2015-typeof-symbol'),
33 | [require('babel-plugin-transform-regenerator'), { async: false, asyncGenerators: false }],
34 |
35 | modules === 'commonjs' && [require('babel-plugin-transform-es2015-modules-commonjs'), { loose }],
36 | modules === 'systemjs' && [require('babel-plugin-transform-es2015-modules-systemjs'), { loose }],
37 | modules === 'amd' && [require('babel-plugin-transform-es2015-modules-amd'), { loose }],
38 | modules === 'umd' && [require('babel-plugin-transform-es2015-modules-umd'), { loose }],
39 | ].filter(Boolean)
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/vulture-redux/README.md:
--------------------------------------------------------------------------------
1 | # vulture-redux
2 | Functional programming bindings of [`redux`](http://npmjs.com/packages/redux) to [`vulture`](https://www.npmjs.com/package/vulture) inspired by [`react-redux`](https://www.npmjs.com/package/react-redux).
3 |
4 | ## API
5 | ### connect(mapStateToData?, mapDispatchToData?, mergeData?)(component)
6 | Connects a vulture component to a redux store.
7 |
8 | `vulture` allows the developer to pass in any number of arguments of any type. This means there is no standard “props” concept like in React. Because of this a few assumptions about the data structure must be made by `vulture-redux`.
9 |
10 | The first argument of a `connect`ed function must be an object. This object *must* contain a redux store object. This first object will also be populated with data from the map functions defined by connect.
11 |
12 | #### Arguments
13 | - `mapStateToProps(state, ownData?)`: This optional user defined function takes the store’s current state and returns an object of data which will be passed to the decorated component.
14 | - `mapDispatchToData(dispatch, ownData?)`: This optional user defined function takes the store’s dispatch function and maps it into an object which will be passed to the component. Returns an object where the only key/value pair is `dispatch` by default.
15 | - `mergeData(stateData, dispatchData, ownData)`: This optional user defined function merges all of the different data objects together. The object returned by this functions is what actually gets passed to the decorated component.
16 |
17 | #### Examples
18 | This generally is hard to understand without some examples, so here we go.
19 |
20 | This is without `vulture-redux`:
21 |
22 | ```js
23 | import v from 'vulture'
24 | import { createStore } from 'redux'
25 | import reducer from './reducer'
26 |
27 | const store = createStore(reducer)
28 |
29 | MyComponent({ store })
30 |
31 | function MyComponent ({ store }) {
32 | const { message } = store.getState()
33 | return v('em', [message])
34 | }
35 | ```
36 |
37 | This is with `vulture-redux`:
38 |
39 | ```js
40 | import v from 'vulture'
41 | import { createStore } from 'redux'
42 | import { connect } from 'vulture-redux'
43 | import reducer from './reducer'
44 |
45 | const store = createStore(reducer)
46 |
47 | MyComponent({ store })
48 |
49 | const MyComponent = connect(
50 | state => ({ message: state.message })
51 | )(({ message }) => (
52 | v('em', [message])
53 | ))
54 | ```
55 |
56 | And if you want to use `vulture`’s helper `createComponent` function:
57 |
58 | ```js
59 | import v from 'vulture'
60 | import { createComponent } from 'vulture/component'
61 | import { createStore } from 'redux'
62 | import { connect } from 'vulture-redux'
63 | import reducer from './reducer'
64 |
65 | const store = createStore(reducer)
66 |
67 | export default createComponent(
68 | connect(
69 | state => ({ message: state.message })
70 | ),
71 | function MyComponent ({ message }) {
72 | return v('em', [message])
73 | }
74 | )
75 | ```
76 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # node_modules
2 | This is a monorepo for JavaScript packages that Caleb Meredith maintains. A monorepo is a single git repository, a single folder, which contains multiple modules. Instead of having a separate repository for each module Caleb publishes to npm, he instead opts for one. But why?
3 |
4 | Remember the article [JavaScript fatigue](https://medium.com/@ericclemmons/48d4011b6fc4)? This is one solution. By putting every single module in one repository all of the build scripts, lint scripts, test scripts, release scripts only need to be written once. Starting a new module is as simple as calling a ”new” command. In addition putting everything in one place lowers the barrier to modification raising quality of all packages.
5 |
6 | ## Quality guarantee
7 | As long as I am the maintainer of these modules I accept sole responsibility for these modules. Instead of depending on open source contributions I guarantee all modules in this repository will get bug fixes, security updates, and highly requested features in a timely manner. I also guarantee that all modules will (eventually) be well documented and strictly adhere to semantic versioning.
8 |
9 | This guarantee uniquely applies to the modules in this repository as the barrier for modifying them is so low.
10 |
11 | However, that said it might take me a week or so to get to the point where I can fix your issue or add your feature. In addition I might not see the value in your feature and refuse to add it. In that instance I encourage you to submit a pull request if you need timely changes. For more information on [pull request guidelines](#pull-request-guidelines), look a little down the page.
12 |
13 | ## Issue guidelines
14 | I will try to get to your issue as soon as possible, but in order to help me help you please provide the following information:
15 |
16 | - What module you have an issue/feature request for.
17 | - What version of the module you are currently on.
18 | - In the case of an error a small snippet of code which reproduces your error. This is important as I can put it in a test to ensure that your error will never happen again.
19 |
20 | ## Pull request guidelines
21 | If you want to make a pull request, please adhere to the following:
22 |
23 | - Only modify files in one module. Please don‘t change all of the modules or change the build scripts. If you feel something on a higher level then a module needs to be changed, tell me and I‘ll do it.
24 | - Give a good reason your pull request should be merged with tangible impacts. I am accepting responsibility for all code that I merge in, I need there to be a good reason to maintain your code.
25 | - Write tests. This is the key to writing a pull request that won‘t be regressed by someone else in the future.
26 |
27 | ## Developing in the monorepo
28 | To develop a module first clone the repo (it‘s recommended you rename the folder from `node_modules`). Next switch into the directory of the module you want to work on. Finally (and this is really important) call `source .env`. What this does is it takes all of the scripts and makes them available to you as you develop.
29 |
30 | ```bash
31 | $ git clone https://github.com/calebmer/node_modules.git node-modules
32 | $ cd node_modules/{module-i-want-to-work-on}
33 | $ source .env
34 | ```
35 |
36 | ### Development scripts
37 | If you are in the module you want to develop and you have called `source .env`, you will have access to the following scripts:
38 |
39 | - `$ build`: This runs babel and builds the module.
40 | - `$ lint`: This lints your code to ensure it complies with the standard coding style.
41 | - `$ test`: This runs the tests for your code.
42 |
43 | Happy developing!
44 |
45 | * * *
46 |
47 | If you use and enjoy any of these modules you can show your thanks by following me, [`@calebmer`](https://twitter.com/calebmer), on Twitter.
48 |
49 | Thanks and enjoy 👍
50 |
--------------------------------------------------------------------------------
/data-guard/test/validate.test.js:
--------------------------------------------------------------------------------
1 | import assert from 'assert'
2 | import isObject from 'lodash/isObject'
3 | import * as v from '../src/Validators'
4 | import validate from '../src/validate'
5 | import createSuperValidator from '../src/createSuperValidator'
6 |
7 | describe('validate()', () => {
8 | const shape = {
9 | a: v.number(),
10 | b: v.boolean(),
11 |
12 | c: v.shape({
13 | a: v.number(),
14 | b: v.boolean()
15 | }),
16 |
17 | d: v.items({
18 | a: v.number(),
19 | b: v.boolean()
20 | })
21 | }
22 |
23 | it('will accept a validator', () => {
24 | validate(v.number(), 2)
25 | })
26 |
27 | it('will return an object', () => {
28 | assert(isObject(validate(v.number(), 2)))
29 | })
30 |
31 | it('has a strict method', () =>
32 | assert.throws(() => validate.strict(v.string(), 2), /wrong type/i)
33 | )
34 |
35 | it('will return an object with a success property', () => {
36 | assert.equal(validate(v.number(), 2).success, true)
37 | assert.equal(validate(v.number(), true).success, false)
38 | })
39 |
40 | it('will use a shape validator', () => {
41 | assert.equal(validate(shape, { a: 2, b: false, c: { a: 3, b: true }, d: [] }).success, true)
42 | assert.equal(validate(shape, { a: true, b: 4 }).success, false)
43 | })
44 |
45 | it('can be curried', () => {
46 | assert.equal(validate(v.number())(2).success, true)
47 | assert.equal(validate(v.number())(true).success, false)
48 | })
49 |
50 | it('will return an object of errors', () => {
51 | assert.deepEqual(validate(v.number(), 2), {
52 | success: true,
53 | details: []
54 | })
55 |
56 | assert.deepEqual(validate(v.number(), true), {
57 | success: false,
58 | details: [
59 | {
60 | path: '/',
61 | value: true,
62 | errors: ['number']
63 | }
64 | ]
65 | })
66 |
67 | const value = {
68 | a: true,
69 | b: 4,
70 | c: { a: false, b: 8 },
71 | d: [
72 | { a: true, b: 200 },
73 | { a: false, b: 100 },
74 | { a: 4, b: true },
75 | { a: false, b: true }
76 | ]
77 | }
78 |
79 | assert.deepEqual(validate(shape, value), {
80 | success: false,
81 | details: [{
82 | path: '/a',
83 | value: true,
84 | errors: ['number']
85 | }, {
86 | path: '/b',
87 | value: 4,
88 | errors: ['boolean']
89 | }, {
90 | path: '/c',
91 | value: { a: false, b: 8 },
92 | errors: ['shape']
93 | }, {
94 | path: '/c/a',
95 | value: false,
96 | errors: ['number']
97 | }, {
98 | path: '/c/b',
99 | value: 8,
100 | errors: ['boolean']
101 | }, {
102 | path: '/d',
103 | value: value.d,
104 | errors: ['items']
105 | }, {
106 | path: '/d/0/a',
107 | value: true,
108 | errors: ['number']
109 | }, {
110 | path: '/d/0/b',
111 | value: 200,
112 | errors: ['boolean']
113 | }, {
114 | path: '/d/1/a',
115 | value: false,
116 | errors: ['number']
117 | }, {
118 | path: '/d/1/b',
119 | value: 100,
120 | errors: ['boolean']
121 | }, {
122 | path: '/d/3/a',
123 | value: false,
124 | errors: ['number']
125 | }]
126 | })
127 | })
128 |
129 | it('will return multiple errors', () => {
130 | assert.deepEqual(validate(createSuperValidator().string().enum([2]).enum([3]), 5), {
131 | success: false,
132 | details: [{
133 | path: '/',
134 | value: 5,
135 | errors: ['string', 'enum', 'enum']
136 | }]
137 | })
138 | })
139 | })
140 |
--------------------------------------------------------------------------------
/babel-preset-calebmer/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "babel-preset-calebmer",
3 | "version": "4.1.0",
4 | "description": "A Babel preset for modern JavaScript development.",
5 | "author": "Caleb Meredith ",
6 | "license": "MIT",
7 | "repository": "https://github.com/calebmer/node_modules/tree/master/babel-preset-calebmer",
8 | "keywords": [],
9 | "main": "index.js",
10 | "files": [
11 | "es2015.js",
12 | "esnext.js",
13 | "flow.js",
14 | "react.js"
15 | ],
16 | "scripts": {
17 | "build": "../_scripts/build.sh",
18 | "lint": "../_scripts/lint.sh",
19 | "test": "../_scripts/test.sh",
20 | "release": "../_scripts/release.sh",
21 | "bundle": "bundle-dependencies update"
22 | },
23 | "dependencies": {
24 | "babel-plugin-check-es2015-constants": "^6.8.0",
25 | "babel-plugin-syntax-async-functions": "^6.13.0",
26 | "babel-plugin-syntax-flow": "^6.13.0",
27 | "babel-plugin-syntax-jsx": "^6.13.0",
28 | "babel-plugin-syntax-trailing-function-commas": "^6.13.0",
29 | "babel-plugin-transform-class-properties": "^6.11.5",
30 | "babel-plugin-transform-es2015-arrow-functions": "^6.8.0",
31 | "babel-plugin-transform-es2015-block-scoped-functions": "^6.8.0",
32 | "babel-plugin-transform-es2015-block-scoping": "^6.10.1",
33 | "babel-plugin-transform-es2015-classes": "^6.9.0",
34 | "babel-plugin-transform-es2015-computed-properties": "^6.8.0",
35 | "babel-plugin-transform-es2015-destructuring": "^6.9.0",
36 | "babel-plugin-transform-es2015-duplicate-keys": "^6.8.0",
37 | "babel-plugin-transform-es2015-for-of": "^6.8.0",
38 | "babel-plugin-transform-es2015-function-name": "^6.9.0",
39 | "babel-plugin-transform-es2015-literals": "^6.8.0",
40 | "babel-plugin-transform-es2015-modules-commonjs": "^6.11.5",
41 | "babel-plugin-transform-es2015-object-super": "^6.8.0",
42 | "babel-plugin-transform-es2015-parameters": "^6.11.4",
43 | "babel-plugin-transform-es2015-shorthand-properties": "^6.8.0",
44 | "babel-plugin-transform-es2015-spread": "^6.8.0",
45 | "babel-plugin-transform-es2015-sticky-regex": "^6.8.0",
46 | "babel-plugin-transform-es2015-template-literals": "^6.8.0",
47 | "babel-plugin-transform-es2015-typeof-symbol": "^6.8.0",
48 | "babel-plugin-transform-es2015-unicode-regex": "^6.11.0",
49 | "babel-plugin-transform-exponentiation-operator": "^6.8.0",
50 | "babel-plugin-transform-export-extensions": "^6.8.0",
51 | "babel-plugin-transform-flow-comments": "^6.8.0",
52 | "babel-plugin-transform-function-bind": "^6.8.0",
53 | "babel-plugin-transform-object-rest-spread": "^6.8.0",
54 | "babel-plugin-transform-react-constant-elements": "^6.9.1",
55 | "babel-plugin-transform-react-display-name": "^6.8.0",
56 | "babel-plugin-transform-react-inline-elements": "^6.8.0",
57 | "babel-plugin-transform-react-jsx": "^6.8.0",
58 | "babel-plugin-transform-react-jsx-self": "^6.11.0",
59 | "babel-plugin-transform-react-jsx-source": "^6.9.0",
60 | "babel-plugin-transform-react-pure-class-to-function": "^1.0.1",
61 | "babel-plugin-transform-react-remove-prop-types": "^0.2.9",
62 | "babel-plugin-transform-regenerator": "^6.11.4"
63 | },
64 | "devDependencies": {
65 | "bundle-dependencies": "^1.0.2"
66 | },
67 | "bundledDependencies": [
68 | "babel-plugin-check-es2015-constants",
69 | "babel-plugin-syntax-async-functions",
70 | "babel-plugin-syntax-flow",
71 | "babel-plugin-syntax-jsx",
72 | "babel-plugin-syntax-trailing-function-commas",
73 | "babel-plugin-transform-class-properties",
74 | "babel-plugin-transform-es2015-arrow-functions",
75 | "babel-plugin-transform-es2015-block-scoped-functions",
76 | "babel-plugin-transform-es2015-block-scoping",
77 | "babel-plugin-transform-es2015-classes",
78 | "babel-plugin-transform-es2015-computed-properties",
79 | "babel-plugin-transform-es2015-destructuring",
80 | "babel-plugin-transform-es2015-duplicate-keys",
81 | "babel-plugin-transform-es2015-for-of",
82 | "babel-plugin-transform-es2015-function-name",
83 | "babel-plugin-transform-es2015-literals",
84 | "babel-plugin-transform-es2015-modules-commonjs",
85 | "babel-plugin-transform-es2015-object-super",
86 | "babel-plugin-transform-es2015-parameters",
87 | "babel-plugin-transform-es2015-shorthand-properties",
88 | "babel-plugin-transform-es2015-spread",
89 | "babel-plugin-transform-es2015-sticky-regex",
90 | "babel-plugin-transform-es2015-template-literals",
91 | "babel-plugin-transform-es2015-typeof-symbol",
92 | "babel-plugin-transform-es2015-unicode-regex",
93 | "babel-plugin-transform-exponentiation-operator",
94 | "babel-plugin-transform-export-extensions",
95 | "babel-plugin-transform-flow-comments",
96 | "babel-plugin-transform-function-bind",
97 | "babel-plugin-transform-object-rest-spread",
98 | "babel-plugin-transform-react-constant-elements",
99 | "babel-plugin-transform-react-display-name",
100 | "babel-plugin-transform-react-inline-elements",
101 | "babel-plugin-transform-react-jsx",
102 | "babel-plugin-transform-react-jsx-self",
103 | "babel-plugin-transform-react-jsx-source",
104 | "babel-plugin-transform-react-pure-class-to-function",
105 | "babel-plugin-transform-react-remove-prop-types",
106 | "babel-plugin-transform-regenerator"
107 | ]
108 | }
109 |
--------------------------------------------------------------------------------
/data-guard/test/Validators.test.js:
--------------------------------------------------------------------------------
1 | import assert from 'assert'
2 | import * as v from '../src/Validators'
3 |
4 | describe('Validators', () => {
5 | describe('any()', () => {
6 | it('will always be true', () => {
7 | assert(v.any()(true))
8 | assert(v.any()(5))
9 | assert(v.any()('asd'))
10 | assert(v.any()({ a: 1, b: 2 }))
11 | assert(v.any()([1, 2]))
12 | assert(v.any()(function () {}))
13 | })
14 | })
15 |
16 | describe('boolean()', () => {
17 | it('will only work for booleans', () => {
18 | assert(v.boolean()(true))
19 | assert(v.boolean()(false))
20 | assert(!v.boolean()(5))
21 | assert(!v.boolean()('asd'))
22 | assert(!v.boolean()({}))
23 | assert(!v.boolean()([]))
24 | assert(!v.boolean()(function () {}))
25 | })
26 |
27 | it('will work for nulls', () => {
28 | assert(v.boolean()())
29 | assert(v.boolean()(null))
30 | })
31 | })
32 |
33 | describe('number()', () => {
34 | it('will only work for numbers', () => {
35 | assert(v.number()(5))
36 | assert(v.number()(6))
37 | assert(!v.number()(true))
38 | assert(!v.number()('asd'))
39 | assert(!v.number()({}))
40 | assert(!v.number()([]))
41 | assert(!v.number()(function () {}))
42 | })
43 |
44 | it('will work for nulls', () => {
45 | assert(v.number()())
46 | assert(v.number()(null))
47 | })
48 | })
49 |
50 | describe('string()', () => {
51 | it('will work for strings', () => {
52 | assert(v.string()(''))
53 | assert(v.string()('asd'))
54 | assert(!v.string()(true))
55 | assert(!v.string()(2))
56 | assert(!v.string()({}))
57 | assert(!v.string()([]))
58 | assert(!v.string()(function () {}))
59 | })
60 |
61 | it('will work for nulls', () => {
62 | assert(v.string()())
63 | assert(v.string()(null))
64 | })
65 | })
66 |
67 | describe('object()', () => {
68 | it('will work for objects', () => {
69 | assert(v.object()({}))
70 | assert(!v.object()(true))
71 | assert(!v.object()(2))
72 | assert(!v.object()(function () {}))
73 | })
74 |
75 | it('will work for nulls', () => {
76 | assert(v.object()())
77 | assert(v.object()(null))
78 | })
79 |
80 | it('will not work for arrays', () => {
81 | assert(!v.object()([]))
82 | })
83 | })
84 |
85 | describe('array()', () => {
86 | it('will work for arrays', () => {
87 | assert(v.array()([]))
88 | assert(!v.array()(true))
89 | assert(!v.array()(2))
90 | assert(!v.array()({}))
91 | assert(!v.array()(function () {}))
92 | })
93 |
94 | it('will work for nulls', () => {
95 | assert(v.array()())
96 | assert(v.array()(null))
97 | })
98 | })
99 |
100 | describe('function()', () => {
101 | it('will only work for functions', () => {
102 | assert(v.function()(function () {}))
103 | assert(v.function()(() => true))
104 | assert(!v.function()(true))
105 | assert(!v.function()(5))
106 | assert(!v.function()('asd'))
107 | assert(!v.function()({}))
108 | assert(!v.function()([]))
109 | })
110 |
111 | it('will work for nulls', () => {
112 | assert(v.function()())
113 | assert(v.function()(null))
114 | })
115 | })
116 |
117 | describe('required()', () => {
118 | it('rejects falsey values', () => {
119 | assert(v.required()(true))
120 | assert(v.required()(false))
121 | assert(v.required()(5))
122 | assert(v.required()('asd'))
123 | assert(v.required()({ a: 1, b: 2 }))
124 | assert(v.required()([1, 2]))
125 | assert(v.required()(function () {}))
126 | assert(v.required()(NaN))
127 | assert(!v.required()())
128 | assert(!v.required()(null))
129 | })
130 | })
131 |
132 | describe('shape()', () => {
133 | it('will validate with a shape', () => {
134 | const shape = {
135 | a: v.number(),
136 | b: v.boolean()
137 | }
138 | assert(v.shape(shape)({ a: 1, b: false }))
139 | assert(!v.shape(shape)({ a: true, b: 2 }))
140 | })
141 | })
142 |
143 | describe('items()', () => {
144 | it('can be provided a validator', () => {
145 | assert(v.items(v.number())([1, 2, 3]))
146 | assert(!v.items(v.number())([1, 'asd', 3]))
147 | })
148 |
149 | it('can be provided a shape', () => {
150 | const shape = {
151 | a: v.number(),
152 | b: v.boolean()
153 | }
154 | assert(v.items(shape)([{ a: 1, b: false }, { a: 2, b: true }]))
155 | assert(!v.items(shape)([{ a: 1, b: false }, { a: 2, b: true }, { a: true, b: 2 }]))
156 | })
157 | })
158 |
159 | describe('match()', () => {
160 | it('will test using a regular expression', () => {
161 | assert(v.match(/^\d+$/)('2394'))
162 | assert(!v.match(/^\d+$/)('2394x'))
163 | })
164 | })
165 |
166 | describe('enum()', () => {
167 | it('requires value to be in the specified list', () => {
168 | const list = ['a', 'b', 3, false]
169 | assert(v.enum(list)('a'))
170 | assert(v.enum(list)(false))
171 | assert(v.enum(list)(3))
172 | assert(!v.enum(list)(true))
173 | assert(!v.enum(list)(4))
174 | assert(!v.enum(list)('c'))
175 | })
176 | })
177 |
178 | describe('instanceOf()', () => {
179 | it('uses the instanceof operator', () => {
180 | assert(v.instanceOf(Error)(new Error('Hello, world!')))
181 | assert(!v.instanceOf(Error)(new Map()))
182 | assert(!v.instanceOf(Error)({}))
183 | assert(!v.instanceOf(Error)([]))
184 | assert(!v.instanceOf(Error)(2))
185 | })
186 | })
187 | })
188 |
--------------------------------------------------------------------------------
/babel-matrix/src/getCellPluginSources.js:
--------------------------------------------------------------------------------
1 | import { compact } from 'lodash'
2 | import * as s from './syntaxes.js'
3 | import PluginSource from './PluginSource.js'
4 |
5 | /**
6 | * Gets plugins for a given cell in the syntax matrix.
7 | *
8 | * @param {string} inputSyntax The input syntax, should be one of the syntax strings.
9 | * @param {string} outputSyntax The output syntax, should be one of the output syntax strings.
10 | * @param {boolean} isProduction A flag signaling whether or not production plugins should be added.
11 | * @return {[PluginSource]} A list of the `PluginSource`s to be used by Babel for this cell of the matrix.
12 | */
13 | function getCellPluginSources (inputSyntax, outputSyntax, isProduction = false) {
14 | // This function is a really good argument against JavaScript…
15 | // Consider using coffeescript.
16 | switch (inputSyntax) {
17 | case s.COMMON_JS:
18 | case s.AMD:
19 | case s.UMD:
20 | case s.SYSTEM_JS: {
21 | switch (outputSyntax) {
22 | case s.COMMON_JS:
23 | case s.AMD:
24 | case s.UMD:
25 | case s.SYSTEM_JS:
26 | case s.ES_MODULES:
27 | throw new Error(`Module syntax '${inputSyntax}' can not build to '${outputSyntax}'.`)
28 | default:
29 | return []
30 | }
31 | }
32 | case s.ES_MODULES: {
33 | switch (outputSyntax) {
34 | case s.COMMON_JS:
35 | return [STRICT_PLUGIN, p('transform-es2015-modules-commonjs', '6.6.x')]
36 | case s.AMD:
37 | return [STRICT_PLUGIN, p('transform-es2015-modules-amd', '6.6.x')]
38 | case s.UMD:
39 | return [STRICT_PLUGIN, p('transform-es2015-modules-umd', '6.6.x')]
40 | case s.SYSTEM_JS:
41 | return [STRICT_PLUGIN, p('transform-es2015-modules-systemjs', '6.6.x')]
42 | default:
43 | return [STRICT_PLUGIN]
44 | }
45 | }
46 | case s.ES5: {
47 | switch (outputSyntax) {
48 | case s.ES6:
49 | case s.ESNEXT:
50 | throw new Error(`Cannot build es5 to new syntax '${outputSyntax}'.`)
51 | default:
52 | return []
53 | }
54 | }
55 | case s.ES6: {
56 | switch (outputSyntax) {
57 | case s.ES5:
58 | return ES6_TO_ES5_PLUGINS
59 | case s.ESNEXT:
60 | throw new Error('Cannot build es6 to new syntax esnext')
61 | default:
62 | return []
63 | }
64 | }
65 | case s.ESNEXT: {
66 | switch (outputSyntax) {
67 | case s.ES5:
68 | return ESNEXT_TO_ES5_PLUGINS
69 | case s.ES6:
70 | return ESNEXT_TO_ES6_PLUGINS
71 | default:
72 | return []
73 | }
74 | }
75 | case s.REACT: {
76 | switch (outputSyntax) {
77 | case s.REACT:
78 | return []
79 | default:
80 | return compact([
81 | p('syntax-jsx', '6.5.x'),
82 | p('transform-react-jsx', '6.5.x'),
83 | p('transform-react-display-name', '6.5.x'),
84 | isProduction ? p('transform-react-constant-elements', '6.5.x') : null,
85 | isProduction ? p('transform-react-inline-elements', '6.6.x') : null
86 | ])
87 | }
88 | }
89 | case s.FLOW: {
90 | switch (outputSyntax) {
91 | case s.FLOW:
92 | return []
93 | default:
94 | return [
95 | p('syntax-flow', '6.5.x'),
96 | isProduction
97 | ? p('transform-strip-flow-types', '6.7.x')
98 | : p('transform-flow-comments', '6.7.x')
99 | ]
100 | }
101 | }
102 | default:
103 | return []
104 | }
105 | }
106 |
107 | export default getCellPluginSources
108 |
109 | // Convenience function for creating the source of babel plugins.
110 | function p (generalName, version) {
111 | return new PluginSource(`babel-plugin-${generalName}`, version)
112 | }
113 |
114 | const STRICT_PLUGIN = p('transform-strict-mode', '6.6.x')
115 |
116 | const ES6_TO_ES5_PLUGINS = [
117 | p('transform-es2015-template-literals', '6.6.x'),
118 | p('transform-es2015-literals', '6.3.x'),
119 | p('transform-es2015-function-name', '6.3.x'),
120 | p('transform-es2015-arrow-functions', '6.3.x'),
121 | p('transform-es2015-block-scoped-functions', '6.3.x'),
122 | p('transform-es2015-classes', '6.6.x'),
123 | p('transform-es2015-object-super', '6.3.x'),
124 | p('transform-es2015-shorthand-properties', '6.3.x'),
125 | p('transform-es2015-computed-properties', '6.3.x'),
126 | p('transform-es2015-duplicate-keys', '6.6.x'),
127 | p('transform-es2015-for-of', '6.6.x'),
128 | p('transform-es2015-sticky-regex', '6.3.x'),
129 | p('transform-es2015-unicode-regex', '6.3.x'),
130 | p('check-es2015-constants', '6.3.x'),
131 | p('transform-es2015-spread', '6.3.x'),
132 | p('transform-es2015-parameters', '6.6.x'),
133 | p('transform-es2015-destructuring', '6.6.x'),
134 | p('transform-es2015-block-scoping', '6.6.x'),
135 | p('transform-es2015-typeof-symbol', '6.6.x'),
136 | p('transform-regenerator', '6.6.x')
137 | ]
138 |
139 | const ESNEXT_TO_ES6_PLUGINS = [
140 | p('transform-async-to-generator', '6.7.x'),
141 | p('transform-exponentiation-operator', '6.5.x'),
142 | p('syntax-trailing-function-commas', '6.5.x'),
143 | p('transform-object-rest-spread', '6.6.x'),
144 | p('transform-class-constructor-call', '6.6.x'),
145 | p('transform-class-properties', '6.6.x'),
146 | p('transform-decorators', '6.6.x'),
147 | p('transform-export-extensions', '6.5.x'),
148 | p('transform-do-expressions', '6.5.x'),
149 | p('transform-function-bind', '6.5.x')
150 | ]
151 |
152 | const ESNEXT_TO_ES5_PLUGINS = ESNEXT_TO_ES6_PLUGINS.concat(ES6_TO_ES5_PLUGINS)
153 |
--------------------------------------------------------------------------------
/eslint-config-calebmer/README.md:
--------------------------------------------------------------------------------
1 | # `eslint-config-calebmer`
2 | An opinionated eslint config with attitude 😘
3 |
4 | Based on the [standard][] coding style except more strict and more opinions.
5 |
6 | [standard]: http://npmjs.org/standard
7 |
8 | ## Features
9 | - Enhanced [promise][] rules.
10 | - [ES module][] static linting configuration which checks for existing imports/exports.
11 | - [JSDoc][] specific rules for the best documentation in the land!
12 | - Test environment (via `calebmer/tests`) with [Mocha][] specific rules.
13 | - [Markdown][] code block linting. Just remember to run eslint with an extension argument: `eslint --ext md …`.
14 |
15 | [promise]: http://npmjs.org/eslint-plugin-promise
16 | [es module]: https://www.npmjs.com/package/eslint-plugin-import
17 | [jsdoc]: https://www.npmjs.com/package/eslint-plugin-jsdoc
18 | [mocha]: https://www.npmjs.com/package/eslint-plugin-mocha
19 | [markdown]: https://www.npmjs.com/package/eslint-plugin-markdown
20 |
21 | ## Bikeshedding
22 | If you don’t like a rule, we can do some bikeshedding, just open an issue. If we can’t quickly come to a resolution, my subjective preference wins out.
23 |
24 | Warrants for some rules are below.
25 |
26 | ## Warrants
27 | Some of the decisions made in this config may be controversial, or I may forget why I made them. Therefore here are my warrants for some of the more controversial decisions made in this config.
28 |
29 | **Table of contents:**
30 |
31 | - [Semicolons](#semicolons)
32 | - [Brace Style](#brace-style)
33 | - [Comma Dangle](#comma-dangle)
34 | - [No Namespace Imports](#no-namespace-imports)
35 |
36 | ### [Semicolons][]
37 | Semicolons are disabled. I don’t want to write any more characters than I have to. Deal with it 😎
38 |
39 | [Semicolons]: http://eslint.org/docs/rules/semi
40 |
41 | ### [Brace Style][]
42 | The brace style is configured to Stroustrup. This forces braces from if/else statements to act like this:
43 |
44 | ```js
45 | // Yep 👍
46 |
47 | if (foo) {
48 | bar()
49 | }
50 | else {
51 | baz()
52 | }
53 | ```
54 |
55 | …instead of the more common style *one true brace style* which looks like this:
56 |
57 | ```js
58 | // Nope 😫
59 |
60 | if (foo) {
61 | bar()
62 | } else {
63 | baz()
64 | }
65 | ```
66 |
67 | There are three reasons for choosing Stroustrup.
68 |
69 | #### 1. Documentation
70 | When doing algorithm documentation for if/else statements it is very hard to decide where to write documentation with the “one true brace style.” Do you write documentation at the start of the if/else block? Do you write documentation inside the if/else blocks? To demonstrate:
71 |
72 | ```js
73 | // Does documentation go here?
74 | if (foo) {
75 | // Or here?
76 | bar()
77 | // But definetly not here…
78 | } else {
79 | // If it goes here it may be confused for documenting `baz` instead of the block as a whole.
80 | baz()
81 | }
82 | ```
83 |
84 | But with Stroustrup documenting if/else blocks is easy.
85 |
86 | ```js
87 | // Document the if here. 👍
88 | if (foo) {
89 | bar()
90 | }
91 | // Document the else here. 🎉
92 | else {
93 | baz()
94 | }
95 | ```
96 |
97 | #### 2. Consistency
98 | You would *never* write this:
99 |
100 | ```js
101 | function hello () {
102 | // Stuff…
103 | } function world () {
104 | // Other stuff…
105 | }
106 | ```
107 |
108 | Or if/if statements like this:
109 |
110 | ```js
111 | if (foo) {
112 | // Stuff…
113 | } if (bar) {
114 | // Other stuff… 😯
115 | } try {
116 | // More stuff… 😵
117 | } catch (error) {
118 | // Yeah, no stuff here 😉
119 | }
120 | ```
121 |
122 | So why write your if/else blocks or try/catch blocks that way? One argument may be that if/else and try/catch blocks are one piece of application logic, to counter that take a look at promises:
123 |
124 | ```js
125 | asyncWork()
126 | .then(foo => {
127 | // More async work… 🤔
128 | })
129 | .then(bar => {
130 | // Finish async work…
131 | })
132 | .catch(noop)
133 | ```
134 |
135 | This configuration prefers the above code over:
136 |
137 | ```js
138 | // Yikes! 😟
139 | asyncWork()
140 | .then(foo => {
141 | // More async work…
142 | }).then(bar => {
143 | // Finish async work…
144 | }).catch(noop)
145 | ```
146 |
147 | As this choice in method chaining ends up acting very similar to if/else blocks (in a logic sense), we pick Stroustrup for consistency.
148 |
149 | #### 3. Spacing
150 | The so called “one true brace style” can get very compact and become almost unreadable with lots of `else if`s.
151 |
152 | ```js
153 | if (foo) {
154 | bar()
155 | } else if (baz) {
156 | bux()
157 | } else {
158 | quz()
159 | }
160 | ```
161 |
162 | [brace style]: http://eslint.org/docs/rules/brace-style
163 |
164 | ### [Comma Dangle][]
165 | Inspired by “[Why you should enforce Dangling Commas for Multiline Statements][]” this configuration enforces dangling commas for multiline statements. So the following code is invalid:
166 |
167 | ```js
168 | // Yeah, no…
169 |
170 | const array = [
171 | 'foo',
172 | 'bar',
173 | 'buz'
174 | ]
175 | ```
176 |
177 | But the following code is valid:
178 |
179 | ```js
180 | // Yay! 🎉
181 |
182 | const array = [
183 | 'foo',
184 | 'bar',
185 | 'buz',
186 | ]
187 | ```
188 |
189 | Note that the only difference between the two examples is a *single comma*. For the main argument, read the article linked to earlier, but the gist of the article is that enforcing dangling commas for multiline statements is preferable because you only have to change one line instead of two when adding an item to a multiline object.
190 |
191 | This has two impacts:
192 |
193 | 1. Better git diffs.
194 | 2. Easier to edit.
195 |
196 | Therefore this rule is enforced in this configuration.
197 |
198 | [Comma Dangle]: http://eslint.org/docs/rules/comma-dangle
199 | [Why you should enforce Dangling Commas for Multiline Statements]: https://medium.com/@nikgraf/why-you-should-enforce-dangling-commas-for-multiline-statements-d034c98e36f8
200 |
201 | ### [No Namespace Imports][]
202 | If you try to import values from an ES module like so:
203 |
204 | ```js
205 | import * as foo from './foo'
206 | ```
207 |
208 | You *will* get an error.
209 |
210 | Why is this? Well because doing this can lead to importing *everything* from a module. This is an anti-pattern when you are code splitting your modules trying to make the smallest build possible. Instead of depending on a namespace import, instead use a default export object like so:
211 |
212 | ```js
213 | export default {
214 | foo: 1,
215 | bar: 2,
216 | baz: 3,
217 | }
218 | ```
219 |
220 | This way you are more explicit about your intent for the exports.
221 |
222 | Ultimately, named exports should be used when you want the user to be selective about their module imports.
223 |
224 | [No Namespace Imports]: https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-namespace.md
225 |
--------------------------------------------------------------------------------
/data-guard/README.md:
--------------------------------------------------------------------------------
1 | # data-guard
2 | Data validation is frustrating, let‘s fix that.
3 |
4 | You can stop your search for a data validation library now. `data-guard` has you covered. Why should you not write your own data validations and just use `data-guard`? Well, because `data-guard` is:
5 |
6 | - Small. Designed so that users don’t have to download a huge library just so you can do data validation.
7 | - Flexible. `data-guard` will work in any context. By default validators will just return a boolean. If you want error messages you can use the special `validate` method. In addition `data-guard` has you covered for any function type validation needs.
8 | - Functional. Functional programming is perhaps the easiest pattern to fit into your application. `data-guard` does not force you to write your code in a functional manner, but `data-guard` itself is written to be super compassable and useable with any framework in any codebase.
9 |
10 | `data-guard` is not a JSON schema validator and does not plan to be. We want to keep `data-guard` as small as possible so you don‘t introduce unnecessary technical debt into your application.
11 |
12 | For more information on a React `propTypes` style usage, look at the [Guarding function arguments](#guarding-function-arguments) section!
13 |
14 | ## Need more?
15 | See something missing that is a blocker for your use of `data-guard`, well instead of writing your own data validation library consider opening an issue. This not only means you can use `data-guard`, but everyone else who uses it both now and in the future can benefit from your feature request. Let‘s stop using a hundred different data validation frameworks and finally just agree on one.
16 |
17 | ## Usage
18 | Validators accept two parameters in a curried fashion, a config, and a value. For example, the array validator:
19 |
20 | ```js
21 | var t = require('data-guard')
22 |
23 | t.items(t.string())(['a', 'b', 'c'])
24 | ```
25 |
26 | Represents a validator which ensures that all items in an array are strings. Validators also only return a boolean. `true` if the validation succeeded, `false` if it failed. For example, see the following:
27 |
28 | ```js
29 | var t = require('data-guard')
30 |
31 | console.log(t.string()('hello, world')) // => true
32 | console.log(t.string()(2)) // => false
33 | console.log(t.items(t.number())([1, 2, 'c'])) // => false
34 | console.log(t.items(t.number())([4, 5, 6])) // => true
35 | ```
36 |
37 | ### Chaining validators
38 | Validators may also be chained together:
39 |
40 | ```js
41 | var t = require('data-guard')
42 |
43 | console.log(t.string().match(/@/)('hello, world')) // => false
44 | console.log(t.string().match(/@/)('person@email.com')) // => true
45 | ```
46 |
47 | These design decisions allow for validators to be hyper flexible. If you want a validator, you just call one and you automatically have a function which you may pass around to other functions, and when called it returns a boolean saying if the value is valid. No specific domain knowledge required of your code, just functions and booleans. However, `data-guard` does have the capability to do more. See the following:
48 |
49 | ### Getting more information about the validation
50 | ```js
51 | var t = require('data-guard')
52 | var validate = require('data-guard').validate
53 |
54 | console.log(validate(t.string().match(/@/), 'hello, world'))
55 | ```
56 |
57 | By using the validate function, you opt to pass in only the validator function (instead of calling it directly) and the value you wish to validate. This allows `data-guard` to get some extra information about the validation and it will now return the object:
58 |
59 | ```js
60 | {
61 | success: false,
62 | details: [{
63 | path: '/',
64 | value: 'hello, world',
65 | errors: ['match']
66 | }]
67 | }
68 | ```
69 |
70 | The object will always have a `success` boolean, which is just the boolean value the validator would have returned if called correctly. The `results` array will contain an object for every failed path in the validation. A `path` is defined as a JSON pointer and is useful for identifying the field in an object or array environment. For example:
71 |
72 | ```js
73 | var validator = t.shape({
74 | foo: t.string(),
75 | bar: t.number()
76 | })
77 |
78 | var value = {
79 | foo: 42,
80 | bar: 'buz'
81 | }
82 |
83 | validate(validator, value)
84 | ```
85 |
86 | Would return:
87 |
88 | ```js
89 | {
90 | success: false,
91 | details: [{
92 | path: '/',
93 | value: { ... },
94 | errors: ['shape']
95 | }, {
96 | path: '/foo',
97 | value: 42,
98 | errors: ['string']
99 | }, {
100 | path: '/bar',
101 | value: 'buz',
102 | errors: ['number']
103 | }]
104 | }
105 | ```
106 |
107 | If multiple validators return an error, all of those errors will be represented in the returned object.
108 |
109 | By calling `validate.strict(...)` instead of `validate(...)`, the function will throw an error on the first failed validator.
110 |
111 | ### Guarding function arguments
112 | Because `data-guard` really likes functional programming, it also provides a decorator function so you can “guard” your own functions. Making them pseudo-type-safe.
113 |
114 | ```js
115 | var t = require('data-guard')
116 | var guard = require('data-guard').guard
117 |
118 | function multiply(a, b) {
119 | return a * b
120 | }
121 |
122 | var guardedMultiply = guard(t.number(), t.number())(multiply)
123 | ```
124 |
125 | Now, if you call `guardedMultiply` with a value of the wrong type, say a string, it will warn you in the console. If you would rather fail instead of warn on a bad validation use `guard.strict(...)` instead of `guard(...)`.
126 |
127 | The `guard` function will take any number of parameters. These parameters are expected to be functions which return a boolean. For each validator passed to `guard`, the argument in the same place in the decorated function will be validated using that validator.
128 |
129 | This function was inspired by React’s `propTypes`.
130 |
131 | ## Validators
132 | The validators bundled with `data-guard` by default are:
133 |
134 | - `any`: Always returns true.
135 | - `boolean`: Value is optionally a boolean type.
136 | - `number`: Value is optionally a number type.
137 | - `string`: Value is optionally a string type.
138 | - `object`: Value is optionally an object type.
139 | - `array`: Value is optionally an array type.
140 | - `function`: Value is optionally a function type.
141 | - `required`: Value may not be null or undefined.
142 | - `shape`: Value must conform to a certain object shape. Must be passed an object parameter.
143 | - `items`: All items in the value array must conform to the passed validator. May be passed a shape.
144 | - `match`: Matches a string to a regular expression.
145 | - `enum`: Value must be exactly one of the values passed in.
146 | - `instanceOf`: Value must pass an `instanceof` check with the supplied function.
147 |
148 | If there is another low level validator you would like to see, please open an issue or submit a PR!
149 |
150 | ## Credits
151 | If you use and enjoy this module, the best way to show your gratitude is to follow me, [`@calebmer`](https://twitter.com/calebmer), on Twitter.
152 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/src/index.js:
--------------------------------------------------------------------------------
1 | import isString from 'lodash/isString'
2 | import identity from 'lodash/identity'
3 | import ary from 'lodash/ary'
4 | import esutils from 'esutils'
5 |
6 | const nameProperty = 'elementName'
7 | const attributesProperty = 'attributes'
8 | const childrenProperty = 'children'
9 |
10 | export default function ({ types: t }) {
11 | /* ==========================================================================
12 | * Utilities
13 | * ======================================================================= */
14 |
15 | const transformOnType = transforms => node => {
16 | const transformer = transforms[node.type]
17 | if (transformer) {
18 | return transformer(node)
19 | }
20 | throw new Error(`${node.type} could not be transformed`)
21 | }
22 |
23 | /* ==========================================================================
24 | * Initial configuration
25 | * ======================================================================= */
26 |
27 | const initConfig = (path, state) => {
28 | const {
29 | useNew = false,
30 | module: constructorModule,
31 | function: constructorFunction,
32 | useVariables = false
33 | } = state.opts
34 |
35 | let variablesRegex, jsxObjectTransformer
36 |
37 | if (useVariables === true) {
38 | // Use the default variables regular expression when true.
39 | variablesRegex = /^[A-Z]/
40 | } else if (isString(useVariables)) {
41 | // If it’s a plain regular expression string.
42 | variablesRegex = new RegExp(useVariables)
43 | }
44 |
45 | const executeExpression = useNew ? t.newExpression : t.callExpression
46 | const jsxObjectTransformerCreator = expression => value => executeExpression(expression, [value])
47 |
48 | if (constructorModule) {
49 | // If the constructor function will be retrieved from a module.
50 | const moduleName = path.scope.generateUidIdentifier(useNew ? 'JSXNode' : 'jsx')
51 | jsxObjectTransformer = jsxObjectTransformerCreator(moduleName)
52 |
53 | const importDeclaration = t.importDeclaration(
54 | [t.importDefaultSpecifier(moduleName)],
55 | t.stringLiteral(constructorModule)
56 | )
57 |
58 | // Add the import declration to the top of the file.
59 | path.findParent(p => p.isProgram()).unshiftContainer('body', importDeclaration)
60 | } else if (constructorFunction) {
61 | // If the constructor function will be an in scope function.
62 | const expression = constructorFunction.split('.').map(ary(t.identifier, 1)).reduce(ary(t.memberExpression, 2))
63 | jsxObjectTransformer = jsxObjectTransformerCreator(expression)
64 | } else {
65 | // Otherwise, we won‘t be mapping.
66 | jsxObjectTransformer = identity
67 | }
68 |
69 | return {
70 | variablesRegex,
71 | jsxObjectTransformer
72 | }
73 | }
74 |
75 | /* =========================================================================
76 | * Visitors
77 | * ======================================================================= */
78 |
79 | const visitJSXElement = (path, state) => {
80 | if (!state.get('jsxConfig')) {
81 | state.set('jsxConfig', initConfig(path, state))
82 | }
83 |
84 | const {
85 | variablesRegex,
86 | jsxObjectTransformer
87 | } = state.get('jsxConfig')
88 |
89 | /* ==========================================================================
90 | * Node Transformers
91 | * ======================================================================= */
92 |
93 | const JSXIdentifier = node => t.stringLiteral(node.name)
94 |
95 | const JSXNamespacedName = node => t.stringLiteral(`${node.namespace.name}:${node.name.name}`)
96 |
97 | const JSXMemberExpression = transformOnType({
98 | JSXIdentifier: node => t.identifier(node.name),
99 | JSXMemberExpression: node => (
100 | t.memberExpression(
101 | JSXMemberExpression(node.object),
102 | JSXMemberExpression(node.property)
103 | )
104 | )
105 | })
106 |
107 | const JSXElementName = transformOnType({
108 | JSXIdentifier: variablesRegex
109 | ? node => variablesRegex.test(node.name) ? t.identifier(node.name) : JSXIdentifier(node)
110 | : JSXIdentifier,
111 | JSXNamespacedName,
112 | JSXMemberExpression
113 | })
114 |
115 | const JSXExpressionContainer = node => node.expression
116 |
117 | const JSXAttributeName = transformOnType({ JSXIdentifier, JSXNamespacedName, JSXMemberExpression })
118 |
119 | const JSXAttributeValue = transformOnType({
120 | StringLiteral: node => node,
121 | JSXExpressionContainer
122 | })
123 |
124 | const JSXAttributes = nodes => {
125 | let object = []
126 | const objects = []
127 |
128 | nodes.forEach(node => {
129 | switch (node.type) {
130 | case 'JSXAttribute': {
131 | if (!object) {
132 | object = []
133 | }
134 |
135 | const attributeName = JSXAttributeName(node.name)
136 | const objectKey = esutils.keyword.isIdentifierNameES6(attributeName.value) ? t.identifier(attributeName.value) : attributeName
137 |
138 | object.push(t.objectProperty(objectKey, JSXAttributeValue(node.value)))
139 | break
140 | }
141 | case 'JSXSpreadAttribute': {
142 | if (object) {
143 | objects.push(t.objectExpression(object))
144 | object = null
145 | }
146 |
147 | objects.push(node.argument)
148 | break
149 | }
150 | default:
151 | throw new Error(`${node.type} cannot be used as a JSX attribute`)
152 | }
153 | })
154 |
155 | if (object && object.length > 0) {
156 | objects.push(t.objectExpression(object))
157 | }
158 |
159 | if (objects.length === 0) {
160 | return t.objectExpression([])
161 | } else if (objects.length === 1) {
162 | return objects[0]
163 | }
164 |
165 | return (
166 | t.callExpression(
167 | state.addHelper('extends'),
168 | objects
169 | )
170 | )
171 | }
172 |
173 | const JSXText = node => {
174 | if (state.opts.noTrim) return t.stringLiteral(node.value)
175 | const value = node.value.replace(/\n\s*/g, '')
176 | return value === '' ? null : t.stringLiteral(value)
177 | }
178 |
179 | const JSXElement = node => jsxObjectTransformer(
180 | t.objectExpression([
181 | t.objectProperty(t.identifier(nameProperty), JSXElementName(node.openingElement.name)),
182 | t.objectProperty(t.identifier(attributesProperty), JSXAttributes(node.openingElement.attributes)),
183 | t.objectProperty(t.identifier(childrenProperty), node.closingElement ? JSXChildren(node.children) : t.nullLiteral())
184 | ])
185 | )
186 |
187 | const JSXChild = transformOnType({ JSXText, JSXElement, JSXExpressionContainer })
188 |
189 | const JSXChildren = nodes => t.arrayExpression(
190 | nodes
191 | .map(JSXChild)
192 | .filter(Boolean)
193 | // Normalize all of our string children into one big string. This can be
194 | // an optimization as we minimize the number of nodes created.
195 | // This step just turns `['1', '2']` into `['12']`.
196 | .reduce((children, child) => {
197 | const lastChild = children.length > 0 ? children[children.length - 1] : null
198 |
199 | // If this is a string literal, and the last child is a string literal, merge them.
200 | if (child.type === 'StringLiteral' && lastChild && lastChild.type === 'StringLiteral') {
201 | return [...children.slice(0, -1), t.stringLiteral(lastChild.value + child.value)]
202 | }
203 |
204 | // Otherwise just append the child to our array normally.
205 | return [...children, child]
206 | }, [])
207 | )
208 |
209 | // Actually replace JSX with an object.
210 | path.replaceWith(JSXElement(path.node))
211 | }
212 |
213 | /* ==========================================================================
214 | * Plugin
215 | * ======================================================================= */
216 |
217 | return {
218 | inherits: require('babel-plugin-syntax-jsx'),
219 | visitor: {
220 | JSXElement: visitJSXElement
221 | }
222 | }
223 | }
224 |
--------------------------------------------------------------------------------
/eslint-config-calebmer/index.json:
--------------------------------------------------------------------------------
1 | {
2 | "parser": "babel-eslint",
3 | "env": {
4 | "es6": true
5 | },
6 | "parserOptions": {
7 | "ecmaVersion": 6,
8 | "experimentalObjectRestSpread": true
9 | },
10 | "plugins": [
11 | "babel",
12 | "xo",
13 | "promise",
14 | "import",
15 | "jsdoc"
16 | ],
17 | "settings": {
18 | "import/ignore": ["node_modules"],
19 | "import/parser": "babel-eslint"
20 | },
21 | "rules": {
22 | "comma-dangle": ["error", "always-multiline"],
23 | "no-cond-assign": ["error", "always"],
24 | "no-console": "warn",
25 | "no-constant-condition": "error",
26 | "no-control-regex": "error",
27 | "no-debugger": "error",
28 | "no-dupe-args": "error",
29 | "no-dupe-keys": "error",
30 | "no-duplicate-case": "error",
31 | "no-empty-character-class": "error",
32 | "no-empty": ["error", { "allowEmptyCatch": true }],
33 | "no-ex-assign": "error",
34 | "no-extra-boolean-cast": "error",
35 | "no-extra-parens": "off",
36 | "no-extra-semi": "error",
37 | "no-func-assign": "error",
38 | "no-inner-declarations": "error",
39 | "no-invalid-regexp": "error",
40 | "no-irregular-whitespace": "error",
41 | "no-negated-in-lhs": "error",
42 | "no-obj-calls": "error",
43 | "no-regex-spaces": "error",
44 | "no-sparse-arrays": "error",
45 | "no-unexpected-multiline": "error",
46 | "no-unreachable": "error",
47 | "no-unsafe-finally": "error",
48 | "use-isnan": "error",
49 | "valid-jsdoc": "off",
50 | "valid-typeof": "error",
51 |
52 | "accessor-pairs": "error",
53 | "block-scoped-var": "off",
54 | "complexity": "off",
55 | "consistent-return": "error",
56 | "curly": ["error", "multi-or-nest", "consistent"],
57 | "default-case": "error",
58 | "dot-location": ["error", "property"],
59 | "dot-notation": ["error", { "allowPattern": "^[A-Z]" }],
60 | "eqeqeq": ["error", "allow-null"],
61 | "guard-for-in": "off",
62 | "no-alert": "error",
63 | "no-caller": "error",
64 | "no-case-declarations": "error",
65 | "no-div-regex": "off",
66 | "no-else-return": "error",
67 | "no-empty-pattern": "error",
68 | "no-eq-null": "off",
69 | "no-eval": "error",
70 | "no-extend-native": "error",
71 | "no-extra-bind": "error",
72 | "no-fallthrough": "error",
73 | "no-floating-decimal": "error",
74 | "no-implicit-coercion": "error",
75 | "no-implied-eval": "error",
76 | "no-invalid-this": "off",
77 | "no-iterator": "error",
78 | "no-labels": "error",
79 | "no-lone-blocks": "error",
80 | "no-loop-func": "error",
81 | "no-magic-numbers": "off",
82 | "no-multi-spaces": "error",
83 | "no-multi-str": "error",
84 | "no-native-reassign": "error",
85 | "no-new-func": "error",
86 | "no-new-wrappers": "error",
87 | "no-new": "error",
88 | "no-octal-escape": "error",
89 | "no-octal": "error",
90 | "no-param-reassign": "off",
91 | "no-process-env": "error",
92 | "no-proto": "error",
93 | "no-redeclare": "error",
94 | "no-return-assign": "error",
95 | "no-script-url": "error",
96 | "no-self-compare": "error",
97 | "no-sequences": "error",
98 | "no-throw-literal": "error",
99 | "no-unused-expressions": "error",
100 | "no-useless-call": "error",
101 | "no-void": "error",
102 | "no-warning-comments": "off",
103 | "no-with": "error",
104 | "radix": "error",
105 | "vars-on-top": "off",
106 | "wrap-iife": ["error", "inside"],
107 | "yoda": "error",
108 |
109 | "strict": "off",
110 |
111 | "init-declarations": "off",
112 | "no-catch-shadow": "error",
113 | "no-delete-var": "error",
114 | "no-label-var": "error",
115 | "no-shadow-restricted-names": "error",
116 | "no-shadow": "error",
117 | "no-undef-init": "error",
118 | "no-undef": "error",
119 | "no-undefined": "error",
120 | "no-unused-vars": ["error", { "argsIgnorePattern": "^next$" }],
121 | "no-use-before-define": "off",
122 |
123 | "callback-return": "off",
124 | "global-require": "off",
125 | "handle-callback-err": ["error", "^(err|error)$"],
126 | "no-mixed-requires": "error",
127 | "no-new-require": "error",
128 | "no-path-concat": "error",
129 | "no-process-exit": "error",
130 | "no-restricted-modules": "off",
131 | "no-sync": "error",
132 |
133 | "array-bracket-spacing": "off",
134 | "babel/array-bracket-spacing": ["error", "never"],
135 | "block-spacing": ["error", "always"],
136 | "brace-style": ["error", "stroustrup", { "allowSingleLine": false }],
137 | "camelcase": ["error", { "properties": "always" }],
138 | "comma-spacing": ["error", { "before": false, "after": true }],
139 | "comma-style": ["error", "last"],
140 | "computed-property-spacing": ["error", "never"],
141 | "consistent-this": "off",
142 | "eol-last": "error",
143 | "func-names": "error",
144 | "func-style": ["error", "declaration", { "allowArrowFunctions": true }],
145 | "id-length": "off",
146 | "id-match": "off",
147 | "indent": ["error", 2, { "SwitchCase": 1 }],
148 | "jsx-quotes": ["error", "prefer-double"],
149 | "key-spacing": ["error", { "beforeColon": false, "afterColon": true }],
150 | "keyword-spacing": ["error", { "before": true, "after": true }],
151 | "linebreak-style": ["error", "unix"],
152 | "lines-around-comment": "off",
153 | "max-depth": ["error", 2],
154 | "max-len": ["error", { "code": 110, "tabWidth": 2, "comments": 80 }],
155 | "max-lines": "off",
156 | "max-nested-callbacks": "off",
157 | "max-params": "off",
158 | "max-statements": "off",
159 | "multiline-ternary": "off",
160 | "new-cap": "off",
161 | "babel/new-cap": ["error", { "newIsCap": true, "capIsNew": false }],
162 | "new-parens": "error",
163 | "newline-after-var": "off",
164 | "no-array-constructor": "error",
165 | "no-bitwise": "error",
166 | "no-continue": "off",
167 | "no-inline-comments": "error",
168 | "no-lonely-if": "error",
169 | "no-mixed-operators": "error",
170 | "no-mixed-spaces-and-tabs": "error",
171 | "no-multiple-empty-lines": ["error", { "max": 1, "maxEOF": 1 }],
172 | "no-negated-condition": "off",
173 | "no-nested-ternary": "off",
174 | "no-new-object": "error",
175 | "no-plusplus": "error",
176 | "no-restricted-syntax": "off",
177 | "no-spaced-func": "error",
178 | "no-tabs": "error",
179 | "no-ternary": "off",
180 | "no-trailing-spaces": "error",
181 | "no-underscore-dangle": "off",
182 | "no-unneeded-ternary": "error",
183 | "no-whitespace-before-property": "error",
184 | "object-curly-newline": "off",
185 | "object-curly-spacing": "off",
186 | "babel/object-curly-spacing": ["error", "always", { "objectsInObjects": true, "arraysInObjects": true }],
187 | "object-property-newline": ["error", { "allowMultiplePropertiesPerLine": true }],
188 | "one-var": ["error", "never"],
189 | "operator-assignment": ["error", "always"],
190 | "operator-linebreak": ["error", "after", { "overrides": { "?": "ignore", ":": "ignore" } }],
191 | "padded-blocks": ["error", "never"],
192 | "quote-props": ["error", "consistent"],
193 | "quotes": ["error", "single"],
194 | "require-jsdoc": "off",
195 | "semi-spacing": ["error", { "before": false, "after": true }],
196 | "semi": ["error", "never"],
197 | "sort-vars": "off",
198 | "space-before-blocks": "error",
199 | "space-before-function-paren": ["error", "always"],
200 | "space-in-parens": ["error", "never"],
201 | "space-infix-ops": "error",
202 | "space-unary-ops": ["error", { "words": true, "nonwords": false }],
203 | "spaced-comment": ["error", "always"],
204 | "unicode-bom": "off",
205 | "wrap-regex": "off",
206 |
207 | "arrow-body-style": "off",
208 | "arrow-parens": "off",
209 | "babel/arrow-parens": ["error", "as-needed"],
210 | "arrow-spacing": ["error", { "before": true, "after": true }],
211 | "constructor-super": "error",
212 | "generator-star-spacing": "off",
213 | "babel/generator-star-spacing": ["error", { "before": false, "after": true }],
214 | "no-class-assign": "error",
215 | "no-confusing-arrow": "off",
216 | "no-const-assign": "error",
217 | "no-dupe-class-members": "error",
218 | "no-this-before-super": "error",
219 | "no-useless-computed-key": "error",
220 | "no-useless-constructor": "error",
221 | "no-useless-rename": "error",
222 | "no-var": "error",
223 | "object-shorthand": "off",
224 | "babel/object-shorthand": "error",
225 | "prefer-arrow-callback": "off",
226 | "prefer-const": "error",
227 | "prefer-numeric-literals": "error",
228 | "prefer-reflect": "off",
229 | "prefer-spread": "error",
230 | "prefer-template": "error",
231 | "require-yield": "off",
232 | "rest-spread-spacing": ["error", "never"],
233 |
234 | "babel/no-await-in-loop": "error",
235 | "babel/flow-object-type": ["error", "comma"],
236 | "babel/func-params-comma-dangle": ["error", "always-multiline"],
237 |
238 | "xo/catch-error-name": ["error", { "name": "error" }],
239 | "xo/filename-case": "off",
240 | "xo/no-abusive-eslint-disable": "error",
241 | "xo/no-process-exit": "error",
242 | "xo/throw-new-error": "error",
243 |
244 | "promise/catch-or-return": "error",
245 | "promise/always-return": "off",
246 | "promise/param-names": "error",
247 | "promise/no-native": "off",
248 |
249 | "import/no-unresolved": "error",
250 | "import/named": "error",
251 | "import/default": "error",
252 | "import/namespace": "error",
253 | "import/no-restricted-paths": "off",
254 | "import/export": "error",
255 | "import/no-named-as-default": "error",
256 | "import/no-named-as-default-member": "error",
257 | "import/no-deprecated": "error",
258 | "import/no-extraneous-dependencies": "error",
259 | "import/no-mutable-exports": "error",
260 | "import/no-commonjs": "error",
261 | "import/no-amd": "error",
262 | "import/no-nodejs-modules": "off",
263 | "import/imports-first": "error",
264 | "import/no-duplicates": "error",
265 | "import/no-namespace": "error",
266 | "import/extensions": "off",
267 | "import/order": "error",
268 | "import/newline-after-import": "error",
269 | "import/prefer-default-export": "error",
270 |
271 | "jsdoc/check-param-names": "error",
272 | "jsdoc/check-tag-names": "error",
273 | "jsdoc/check-types": "error",
274 | "jsdoc/newline-after-description": "error",
275 | "jsdoc/require-description-complete-sentence": "error",
276 | "jsdoc/require-hyphen-before-param-description": "error",
277 | "jsdoc/require-param": "off",
278 | "jsdoc/require-param-description": "off",
279 | "jsdoc/require-param-type": "off",
280 | "jsdoc/require-returns-description": "off",
281 | "jsdoc/require-returns-type": "error"
282 | }
283 | }
284 |
--------------------------------------------------------------------------------
/babel-plugin-transform-jsx/README.md:
--------------------------------------------------------------------------------
1 | # babel-plugin-transform-jsx
2 |
3 | What most people don‘t remember about JSX, which Facebook popularized with React, is that JSX is an [open standard][jsxs]. JSX is not exclusive to React and should be experimented with by other framework authors. This Babel plugin aims to provide the most general and un-opionated transformation of JSX as possible.
4 |
5 | This plugin accomplishes this by eliminating the need for middleman functions and outputs plain JavaScript objects, which may then be mapped over to the appropriate format. For example, refer to the following JSX (from the [spec][jsxs]):
6 |
7 | ```jsx
8 | var dropdown = (
9 |
10 | A dropdown list
11 |
16 |
17 | );
18 | ```
19 |
20 | This will roughly be transformed into the following JavaScript object:
21 |
22 | ```js
23 | var dropdown = {
24 | elementName: 'Dropdown',
25 | attributes: {},
26 | children: [
27 | 'A dropdown list',
28 | {
29 | elementName: 'Menu',
30 | attributes: {},
31 | children: [
32 | {
33 | elementName: 'MenuItem',
34 | attributes: {},
35 | children: ['Do Something']
36 | },
37 | {
38 | elementName: 'MenuItem',
39 | attributes: {},
40 | children: ['Do Something Fun!']
41 | },
42 | {
43 | elementName: 'MenuItem',
44 | attributes: {},
45 | children: ['Do Something Else']
46 | }
47 | ]
48 | }
49 | ]
50 | };
51 | ```
52 |
53 | No JSX pragma needed and no `/* @jsx */` comments needed (although constructor functions are supported).
54 |
55 | ## A JSX Object
56 | The names of properties in a JSX object are taken directly from the [spec][jsxs]. What the spec may call `JSXElementName`, in an object it is called `elementName` and so on. Currently properties to be expected are:
57 |
58 | - `elementName`: A string specifying the JSX element’s name. Most often a string, but might be a variable if it is considered a valid expression by the JSX spec.
59 | - `attributes`: An object of key/value attributes for the JSX object. Supports spread attributes.
60 | - `children`: An array of various variables. Most often it will contain strings and JSX objects. If the JSX element was self closing this property will be `null`.
61 |
62 | ## Options
63 | This plugin accepts options in the standard babel fashion, such as the following:
64 |
65 | - `module`: The module to be imported and default export used to construct JSX objects.
66 | - `function`: The function name to be used for constructing JSX objects.
67 | - `useNew`: Instead of calling a constructor function (as defined using an earlier option) use `new`.
68 | - `useVariables`: Allow elements to reference variables, enabling component element names. When set to `true`, element names with an uppercase letter from A to Z are treated as variables. When set to a regular expression pattern, matching names are treated as variables.
69 | - `noTrim`: Specifies whether or not we should trim space in strings. To understand more about trimming, see the [Trimming](#trimming) example below. Defaults to false.
70 |
71 | ## How to integrate with your framework
72 | To integrate this JSX transformer with your framework of choice, you must first define a constructor function which takes a single argument (a JSX object) and returns the appropriate format for your framework. After that, you could take one of two approaches:
73 |
74 | 1. Ask users to add your constructor function‘s name to their plugin config under the `function` key. The user will need to manually bring the constructor function into every file‘s scope which uses JSX (this is comparable to React requiring the `react` module to be in every file).
75 | 2. Create a file where your constructor function is a default export and ask the user to add the file name to their plugin config under the `module` key. This file will be brought into the JSX file‘s scope using ES6 modules automatically.
76 |
77 | For the majority of users the algorithm to locate the file will be node‘s standard require algorithm. Therefore, It is recommended to name your file `jsx.js` and place it at the root of your package so user may use `your-module/jsx` to get the constructor function.
78 |
79 | ### Example `jsx.js` file
80 | If you are taking the second approach, and you are using the [`virtual-dom`][vdom] library an example `jsx.js` may look as follows:
81 |
82 | ```js
83 | var h = require('virtual-dom/h')
84 |
85 | module.exports = function jsx(jsxObject) {
86 | return h(
87 | jsxObject.elementName,
88 | jsxObject.attributes,
89 | jsxObject.children
90 | )
91 | }
92 | ```
93 |
94 | ## Differences with [`babel-plugin-transform-react-jsx`][btrj] and [`babel-plugin-transform-react-inline-elements`][brie]
95 |
96 | - No more `createElement` or other pragma or file import required, but is supported via the `function` and `module` options.
97 | - No `$$typeof`, `props`, `key`, `ref`, or other specific React lingo.
98 | - Does not support component element names by default, though support is available via the `useVariables` option.
99 |
100 | ## Examples
101 | ### Basic
102 | #### JSX
103 | ```jsx
104 | var object = (
105 |
106 | Hello, kitten!
107 |
108 | It is soooo cute.
109 |
110 | )
111 | ```
112 |
113 | #### JavaScript
114 | ```js
115 | var object = {
116 | elementName: 'article',
117 | attributes: {},
118 | children: [
119 | {
120 | elementName: 'h1',
121 | attributes: {},
122 | children: ['Hello, kitten!']
123 | },
124 | {
125 | elementName: 'img',
126 | attributes: {
127 | href: 'http://placekitten.com/200/300',
128 | alt: 'A cute kitten'
129 | },
130 | children: null
131 | },
132 | 'It is soooo cute.'
133 | ]
134 | }
135 | ```
136 |
137 | ### Spread
138 | If you want a JSX element to get a lot of properties, a spread attribute is an easy and convenient way to accomplish this. Just use `...` with an object with all the key/value pairs you want to pass on as attributes.
139 |
140 | #### JSX
141 | ```jsx
142 | var foo = {
143 | bar: 1,
144 | buz: 2
145 | }
146 |
147 | var object = Nice!
148 | ```
149 |
150 | #### JavaScript
151 | ```js
152 | var foo = {
153 | bar: 1,
154 | buz: 2
155 | }
156 |
157 | var object = {
158 | elementName: 'div',
159 | attributes: assign({
160 | hello: 'world'
161 | }, foo, {
162 | goodbye: 'moon'
163 | }),
164 | children: ['Nice!']
165 | }
166 | ```
167 |
168 | ### Self Closing
169 | Self closing JSX elements work just like self closing HTML elements. As they have no children, the children array will be null.
170 |
171 | #### JSX
172 | ```jsx
173 | var object =
174 | ```
175 |
176 | #### JavaScript
177 | ```js
178 | var object = {
179 | elementName: 'br',
180 | attributes: {},
181 | children: null
182 | }
183 | ```
184 |
185 | ### Constructor Function
186 | If you want your JSX object to have a constructor function use Babel options to specify a function name.
187 |
188 | #### Options
189 | ```json
190 | {
191 | "plugins": [["transform-jsx", { "function": "jsx" }]]
192 | }
193 | ```
194 |
195 | #### JSX
196 | ```jsx
197 | var object = (
198 |
199 | Hello, world!
200 |
201 | )
202 | ```
203 |
204 | #### JavaScript
205 | ```js
206 | var object = jsx({
207 | elementName: 'p',
208 | attributes: {},
209 | children: [
210 | jsx({
211 | elementName: 'string',
212 | attributes: {},
213 | children: ['Hello,']
214 | }),
215 | ' world!'
216 | ]
217 | })
218 | ```
219 |
220 | ### Constructor Module
221 | Sometimes it is annoying to have to import your constructor function in every file, so this plugin provides a way to automagically import your constructor function.
222 |
223 | A couple things to consider: First, instead of using the NodeJS only `require` function this plugin adds an ES2015 module import declaration. So in a `import … from '…'` format. Therefore, you will also need a transformation plugin for this style of import if your platform does not support it.
224 |
225 | Second, this plugin uses the default export. If you are using CommonJS `module.exports` you should be fine as long as the constructor is the value of `module.exports`.
226 |
227 | #### Options
228 | ```json
229 | {
230 | "plugins": [["transform-jsx", { "module": "jsx-module-thing" }]]
231 | }
232 | ```
233 |
234 | #### JSX
235 | ```jsx
236 | var object = (
237 |
238 | Hello, world!
239 |
240 | )
241 | ```
242 |
243 | #### JavaScript
244 | ```js
245 | import _jsx from 'jsx-module-thing'
246 |
247 | var object = _jsx({
248 | elementName: 'p',
249 | attributes: {},
250 | children: [
251 | _jsx({
252 | elementName: 'string',
253 | attributes: {},
254 | children: ['Hello,']
255 | }),
256 | ' world!'
257 | ]
258 | })
259 | ```
260 |
261 | ### Variable Element Names
262 | The React JSX transformer allows you to use variable names for elements. For example ``. By default, this plugin does not allow that behavior as it is not defined in the [JSX spec][jsxs] and rather a React specific feature. If you would like to use a variable for your component use the `useVariables` option. If it is `true` any JSX element written in PascalCase (first letter is uppercase, A–Z) will be a variable. Otherwise you can use a regular expression string if you want more fine grained control.
263 |
264 | #### Options
265 | ```json
266 | {
267 | "plugins": [["transform-jsx", { "useVariables": true }]]
268 | }
269 | ```
270 |
271 | #### JSX
272 | ```jsx
273 | var object = (
274 |
275 | Hello, world!
276 |
277 | )
278 | ```
279 |
280 | #### JavaScript
281 | ```js
282 | var object = {
283 | elementName: 'p',
284 | attributes: {},
285 | children: [
286 | {
287 | elementName: MyStrong,
288 | attributes: { foo: 'bar' },
289 | children: ['Hello,']
290 | },
291 | ' world!'
292 | ]
293 | }
294 | ```
295 |
296 | ### Trimming
297 | This JSX transformer will try to optimize your JSX text elements by “trimming” away unnesesary strings. What does that mean? Any length space in your string that starts with a new line character (`\n`) because in *most* scenarios that’s just indentation. So for example JSX that looks like this:
298 |
299 | ```jsx
300 | var jsx = (
301 |
302 | Hello, world!
303 |
304 | )
305 | ```
306 |
307 | …would (without trimming) turn into something like this:
308 |
309 | ```js
310 | var jsx = {
311 | elementName: 'p',
312 | attributes: {},
313 | children: ['\n ', {
314 | elementName: 'strong',
315 | attributes: {},
316 | children: ['Hello,']
317 | }, ' world!\n '],
318 | }
319 | ```
320 |
321 | Notice all the extra space leftover from where we indented our code? This plugin will trim that extra space to create a result that looks like:
322 |
323 | ```js
324 | var jsx = {
325 | elementName: 'p',
326 | attributes: {},
327 | children: [{
328 | elementName: 'strong',
329 | attributes: {},
330 | children: ['Hello,']
331 | }, ' world!'],
332 | }
333 | ```
334 |
335 | Which is more like what the author really wanted the JSX to transform to. If you want to preserve the white space that gets trimmed, set the `noTrim` option to `true`.
336 |
337 | If you really need a space somewhere this JSX transformer is trimming it, just us a JS-escape like so:
338 |
339 | ```jsx
340 | var jsx = (
341 |
342 | Hello, world!{' '}
343 | Hello world again!
344 |
345 | )
346 | ```
347 |
348 | > For pre-2.0.0 users, the original trimming algorithm was similar to what you’d find in a browser. Any whitespace of more than one character was collapsed into a single space string. The trimming method in 2.0.0 and on removes this browser-specific behavior for a method that’s more universal.
349 |
350 | * * *
351 |
352 | ## Credits
353 | If you like this plugin, follow me, [`@calebmer`][twcm], on Twitter. It will be great seeing you there and you can get updates of all the stuff I will be doing.
354 |
355 | Thanks and enjoy 👍
356 |
357 | [jsxs]: http://facebook.github.io/jsx/
358 | [btrj]: https://www.npmjs.com/package/babel-plugin-transform-react-jsx
359 | [brie]: https://www.npmjs.com/package/babel-plugin-transform-react-inline-elements
360 | [twcm]: https://twitter.com/calebmer
361 | [vdom]: https://www.npmjs.com/package/virtual-dom
362 |
--------------------------------------------------------------------------------