UNPKG

cream-and-sugar

Version:

A deliciously functional syntax for JavaScript with native support for JSX

1,369 lines (1,255 loc) 842 kB
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ var CNS_ = require("cns-lib"); //**END LIBRARY**// const React = require('react'); const ReactDOM = require('react-dom'); const reactify = require('./util/reactify'); const Download = require('./Download'); const propTypes = { }; function render () { return CNS_.createElement("div", {className: "code-sample"}, [ CNS_.createElement("pre", {}, [ CNS_.createElement("code", {}, [ CNS_.createElement("span", {className: "fn"}, [ 'creamerize' ]), ' ', CNS_.createElement("span", {className: "num"}, [ '0' ]), ', coffee ', CNS_.createElement("span", {className: "sym"}, [ '=>' ]), ' coffee\n', CNS_.createElement("span", {className: "fn"}, [ 'creamerize' ]), ' scoops, coffee ', CNS_.createElement("span", {className: "sym"}, [ '=>\n' ]), ' ', CNS_.createElement("span", {className: "fn"}, [ 'creamerize' ]), ' scoops - ', CNS_.createElement("span", {className: "num"}, [ '1' ]), ', coffee + ', CNS_.createElement("span", {className: "num"}, [ '1' ]) ]) ]) ]); }; typeof module === 'undefined' ? typeof console !== 'undefined' && console.warn('Warning: You are attempting to export module values in a non-modular environment.') : module.exports = reactify({ render: render }, propTypes); },{"./Download":2,"./util/reactify":15,"cns-lib":18,"react":222,"react-dom":63}],2:[function(require,module,exports){ var CNS_ = require("cns-lib"); //**END LIBRARY**// const React = require('react'); const ReactDOM = require('react-dom'); const reactify = require('./util/reactify'); const propTypes = { downloadOptions: React.PropTypes.object.isRequired, downloadSelection: React.PropTypes.object.isRequired, handleSelectLink: React.PropTypes.func.isRequired, selectLink: React.PropTypes.func.isRequired }; function render () { var ref0_ = this.props; const downloadOptions = ref0_.downloadOptions; const downloadSelection = ref0_.downloadSelection; const handleSelectLink = ref0_.handleSelectLink; return CNS_.createElement("div", {className: "download"}, [ CNS_.createElement("label", {className: "download-label"}, [ "HOW WILL YOU TAKE THAT?" ]), CNS_.createElement("select", {className: "download-dropdown", value: downloadSelection.id, onChange: CNS_.lazify(handleSelectLink, this)}, [ Object.keys(downloadOptions).map(function () { const args = CNS_.args(arguments); const key = args[0]; const option = CNS_.get(key, downloadOptions); return CNS_.createElement("option", {key: key, value: option.id}, [ option.text ]); }) ]), CNS_.createElement("a", {className: "download-button", href: downloadSelection.href}, [ "GO" ]) ]); }; typeof module === 'undefined' ? typeof console !== 'undefined' && console.warn('Warning: You are attempting to export module values in a non-modular environment.') : module.exports = reactify({ render: render }, propTypes); },{"./util/reactify":15,"cns-lib":18,"react":222,"react-dom":63}],3:[function(require,module,exports){ var CNS_ = require("cns-lib"); //**END LIBRARY**// const React = require('react'); const ReactDOM = require('react-dom'); const reactify = require('./util/reactify'); const Download = require('./Download'); const propTypes = { menuOpen: React.PropTypes.bool.isRequired, downloadOptions: React.PropTypes.object.isRequired, downloadSelection: React.PropTypes.object.isRequired, handleSelectLink: React.PropTypes.func.isRequired, selectLink: React.PropTypes.func.isRequired }; function render () { var ref0_ = this.props; const menuOpen = ref0_.menuOpen; const downloadOptions = ref0_.downloadOptions; const downloadSelection = ref0_.downloadSelection; const handleSelectLink = ref0_.handleSelectLink; const selectLink = ref0_.selectLink; const classes = (function () { if (menuOpen) { return 'home-content hidden' } else if (!menuOpen) { return 'home-content' } else { throw new Error('No match found for "when" statement.'); } }.bind(this)()); return CNS_.createElement("div", {className: classes}, [ CNS_.createElement("p", {className: "home-text"}, [ " Cream & Sugar is a functional programming language that compiles to JavaScript. Inspired by languages like Elixir and Haskell, it's meant to be simple, beautiful, and easily digestible. " ]), CNS_.createElement(Download, {downloadOptions: downloadOptions, downloadSelection: downloadSelection, handleSelectLink: handleSelectLink, selectLink: selectLink}, []) ]); }; typeof module === 'undefined' ? typeof console !== 'undefined' && console.warn('Warning: You are attempting to export module values in a non-modular environment.') : module.exports = reactify({ render: render }, propTypes); },{"./Download":2,"./util/reactify":15,"cns-lib":18,"react":222,"react-dom":63}],4:[function(require,module,exports){ var CNS_ = require("cns-lib"); //**END LIBRARY**// const React = require('react'); const ReactDOM = require('react-dom'); const reactify = require('./util/reactify'); const propTypes = { toggleMenu: React.PropTypes.func.isRequired, handleClickLogo: React.PropTypes.func.isRequired }; function logoClick () { const args = CNS_.args(arguments); const evt = args[0]; var ref0_ = this.props; const handleClickLogo = ref0_.handleClickLogo; const menuOpen = ref0_.menuOpen; const boundHandler = CNS_.lazify(handleClickLogo, this); const isHomePage = location.pathname === '/cream-and-sugar/'; return (function () { if (menuOpen) { boundHandler(); return setTimeout(function () { return CNS_.qualify(isHomePage, function () { return evt.preventDefault(); }.bind(this), function () { return null; }.bind(this)); }, 500) } else if (!menuOpen) { return CNS_.qualify(isHomePage, function () { return evt.preventDefault(); }.bind(this), function () { return null; }.bind(this)) } else { throw new Error('No match found for "when" statement.'); } }.bind(this)()); }; function siteIsLive () { return /cream-and-sugar/.test(location.href); }; function render () { var ref1_ = this.props; const handleClickLogo = ref1_.handleClickLogo; const menuOpen = ref1_.menuOpen; const url = CNS_.qualify(siteIsLive(), function () { return '/cream-and-sugar/'; }.bind(this), function () { return '/'; }.bind(this)); return CNS_.createElement("a", {className: "logo", href: url, onClick: CNS_.lazify(logoClick, this)}, [ CNS_.createElement("img", {className: "logo-main", src: "https://jgnewman.github.io/cream-and-sugar/assets/images/logo.svg"}, []), CNS_.createElement("span", {className: "logo-line top-left"}, []), CNS_.createElement("span", {className: "logo-line top-right"}, []), CNS_.createElement("span", {className: "logo-line bottom-right"}, []), CNS_.createElement("span", {className: "logo-line bottom-left"}, []), CNS_.createElement("span", {className: "logo-text top"}, [ 'EST.' ]), CNS_.createElement("span", {className: "logo-text bottom"}, [ '2016' ]) ]); }; typeof module === 'undefined' ? typeof console !== 'undefined' && console.warn('Warning: You are attempting to export module values in a non-modular environment.') : module.exports = reactify({ render: render }, propTypes); },{"./util/reactify":15,"cns-lib":18,"react":222,"react-dom":63}],5:[function(require,module,exports){ var CNS_ = require("cns-lib"); //**END LIBRARY**// const React = require('react'); const ReactDOM = require('react-dom'); const reactify = require('./util/reactify'); const Download = require('./Download'); const propTypes = { menuOpen: React.PropTypes.bool.isRequired, downloadOptions: React.PropTypes.object.isRequired, downloadSelection: React.PropTypes.object.isRequired, handleSelectLink: React.PropTypes.func.isRequired, handleClickMenuLink: React.PropTypes.func.isRequired, selectLink: React.PropTypes.func.isRequired, toggleMenu: React.PropTypes.func.isRequired }; function getLeftContent () { return [{ inner: 'Overview', href: '/reference/overview/' }, { inner: 'Data Types', href: '/reference/data-types/' }, { inner: 'Logic & Infix Operators', href: '/reference/logic-infix/' }, { inner: 'Functions', href: '/reference/functions/' }, { inner: 'Modules', href: '/reference/modules/' }, { inner: 'Conditions', href: '/reference/conditions/' }, { inner: 'Iterations', href: '/reference/iterations/' }]; }; function getRightContent () { return [{ inner: 'CreamML (JSX)', href: '/reference/creamml/' }, { inner: 'Error Handling', href: '/reference/error-handling/' }, { inner: 'Method Chaining', href: '/reference/method-chaining/' }, { inner: 'Curry Piping', href: '/reference/curry-piping/' }, { inner: 'Processes', href: '/reference/processes/' }, { inner: 'Built-In Functions', href: '/reference/bifs/' }, { inner: 'An Example C&S App', href: 'https://github.com/jgnewman/react-cns' }]; }; function isRelative () { const args = CNS_.args(arguments); const path = args[0]; return !/^https?\:/.test(path); }; function normalizePath () { const args = CNS_.args(arguments); const path = args[0]; return (function () { if (/cream-and-sugar/.test(location.pathname)) { return CNS_.qualify(isRelative(path), function () { return ("/cream-and-sugar" + (path)); }.bind(this), function () { return path; }.bind(this)) } else if (true) { return path } else { throw new Error('No match found for "when" statement.'); } }.bind(this)()); }; function render () { var ref0_ = this.props; const menuOpen = ref0_.menuOpen; const downloadOptions = ref0_.downloadOptions; const handleSelectLink = ref0_.handleSelectLink; const downloadSelection = ref0_.downloadSelection; const selectLink = ref0_.selectLink; const handleClickMenuLink = ref0_.handleClickMenuLink; const classes = (function () { if (menuOpen) { return 'menu' } else if (!menuOpen) { return 'menu hidden' } else { throw new Error('No match found for "when" statement.'); } }.bind(this)()); return CNS_.createElement("div", {className: classes}, [ CNS_.createElement("div", {className: "menu-inner"}, [ CNS_.createElement("h1", {}, [ "Main Menu" ]), CNS_.createElement("h2", {}, [ "Everything You Need Is Here" ]), CNS_.createElement("div", {className: "row"}, [ CNS_.createElement("div", {className: "column"}, [ getLeftContent().map(function () { const args = CNS_.args(arguments); const obj = args[0]; const index = args[1]; const isActive = location.pathname === obj.href; const linkClasses = CNS_.qualify(isActive, function () { return 'menu-link active'; }.bind(this), function () { return 'menu-link'; }.bind(this)); const href = CNS_.qualify(isActive, function () { return null; }.bind(this), function () { return normalizePath(obj.href); }.bind(this)); const onClick = CNS_.qualify(isActive, function () { return null; }.bind(this), function () { return CNS_.lazify(handleClickMenuLink, this); }.bind(this)); return CNS_.createElement("a", {className: linkClasses, href: href, key: index, onClick: onClick}, [ obj.inner ]); }.bind(this)) ]), CNS_.createElement("div", {className: "column"}, [ getRightContent().map(function () { const args = CNS_.args(arguments); const obj = args[0]; const index = args[1]; const isActive = location.pathname === obj.href; const linkClasses = CNS_.qualify(isActive, function () { return 'menu-link active'; }.bind(this), function () { return 'menu-link'; }.bind(this)); const href = CNS_.qualify(isActive, function () { return null; }.bind(this), function () { return normalizePath(obj.href); }.bind(this)); const onClick = CNS_.qualify(isActive, function () { return null; }.bind(this), function () { return CNS_.lazify(handleClickMenuLink, this); }.bind(this)); return CNS_.createElement("a", {className: linkClasses, href: href, key: index, onClick: onClick}, [ obj.inner ]); }.bind(this)) ]) ]), CNS_.createElement(Download, {downloadOptions: downloadOptions, downloadSelection: downloadSelection, handleSelectLink: handleSelectLink, selectLink: selectLink}, []) ]), CNS_.createElement("span", {className: "copyright"}, [ "Copyright © 2016 John Newman." ]) ]); }; typeof module === 'undefined' ? typeof console !== 'undefined' && console.warn('Warning: You are attempting to export module values in a non-modular environment.') : module.exports = reactify({ render: render }, propTypes); },{"./Download":2,"./util/reactify":15,"cns-lib":18,"react":222,"react-dom":63}],6:[function(require,module,exports){ var CNS_ = require("cns-lib"); //**END LIBRARY**// const React = require('react'); const ReactDOM = require('react-dom'); const reactify = require('./util/reactify'); const propTypes = { menuOpen: React.PropTypes.bool.isRequired, toggleMenu: React.PropTypes.func.isRequired, handleClickNav: React.PropTypes.func.isRequired }; function render () { var ref0_ = this.props; const menuOpen = ref0_.menuOpen; const handleClickNav = ref0_.handleClickNav; const classes = (function () { if (menuOpen) { return 'nav open' } else if (!menuOpen) { return 'nav' } else { throw new Error('No match found for "when" statement.'); } }.bind(this)()); return CNS_.createElement("a", {className: classes, onClick: CNS_.lazify(handleClickNav, this)}, [ CNS_.createElement("span", {className: "line top"}, []), CNS_.createElement("span", {className: "line middle"}, []), CNS_.createElement("span", {className: "line bottom"}, []) ]); }; typeof module === 'undefined' ? typeof console !== 'undefined' && console.warn('Warning: You are attempting to export module values in a non-modular environment.') : module.exports = reactify({ render: render }, propTypes); },{"./util/reactify":15,"cns-lib":18,"react":222,"react-dom":63}],7:[function(require,module,exports){ var CNS_ = require("cns-lib"); //**END LIBRARY**// const React = require('react'); const ReactDOM = require('react-dom'); const store = require('./state/store'); var ref0_ = require('./util/storage'); const saveState = ref0_.saveState; const AppContainer = require('./containers/AppContainer'); const DocsContainer = require('./containers/DocsContainer'); const appDom = CNS_.dom('#app'); const docsDom = CNS_.dom('#docs-app'); store.subscribe(function () { return saveState(store.getState()); }); (function () { if (appDom) { return ReactDOM.render(CNS_.createElement(AppContainer, {store: store}, []), appDom) } else if (docsDom) { return ReactDOM.render(CNS_.createElement(DocsContainer, {store: store}, []), docsDom) } else { throw new Error('No match found for "when" statement.'); } }.bind(this)()); },{"./containers/AppContainer":8,"./containers/DocsContainer":9,"./state/store":14,"./util/storage":16,"cns-lib":18,"react":222,"react-dom":63}],8:[function(require,module,exports){ var CNS_ = require("cns-lib"); //**END LIBRARY**// const React = require('react'); const ReactDOM = require('react-dom'); var ref0_ = require('redux'); const bindActionCreators = ref0_.bindActionCreators; var ref1_ = require('react-redux'); const connect = ref1_.connect; const actions = require('../state/actions'); const reactify = require('../util/reactify'); const Logo = require('../Logo'); const Nav = require('../Nav'); const HomeContent = require('../HomeContent'); const Menu = require('../Menu'); const CodeSample = require('../CodeSample'); var ref2_ = require('../handlers/handlers'); const handleClickNav = ref2_.handleClickNav; const handleSelectLink = ref2_.handleSelectLink; const handleClickMenuLink = ref2_.handleClickMenuLink; const handleClickLogo = ref2_.handleClickLogo; function select () { const args = CNS_.args(arguments); const state = args[0]; return { menuOpen: state.menuOpen, downloadOptions: state.downloadOptions, downloadSelection: state.downloadSelection }; }; function action () { const args = CNS_.args(arguments); const dispatch = args[0]; return { toggleMenu: bindActionCreators(actions.toggleMenu, dispatch), selectLink: bindActionCreators(actions.selectLink, dispatch) }; }; function render () { var ref3_ = this.props; const menuOpen = ref3_.menuOpen; const toggleMenu = ref3_.toggleMenu; const downloadOptions = ref3_.downloadOptions; const downloadSelection = ref3_.downloadSelection; const selectLink = ref3_.selectLink; return CNS_.createElement("div", {}, [ CNS_.createElement(Logo, {menuOpen: menuOpen, toggleMenu: toggleMenu, handleClickLogo: handleClickLogo}, []), CNS_.createElement(Nav, {menuOpen: menuOpen, toggleMenu: toggleMenu, handleClickNav: handleClickNav}, []), CNS_.createElement(HomeContent, {menuOpen: menuOpen, downloadOptions: downloadOptions, downloadSelection: downloadSelection, handleSelectLink: handleSelectLink, selectLink: selectLink}, []), CNS_.createElement(Menu, {menuOpen: menuOpen, downloadOptions: downloadOptions, downloadSelection: downloadSelection, handleSelectLink: handleSelectLink, handleClickMenuLink: handleClickMenuLink, selectLink: selectLink, toggleMenu: toggleMenu}, []), CNS_.createElement(CodeSample, {}, []) ]); }; typeof module === 'undefined' ? typeof console !== 'undefined' && console.warn('Warning: You are attempting to export module values in a non-modular environment.') : module.exports = connect(select, action)(reactify({ render: render }, {})); },{"../CodeSample":1,"../HomeContent":3,"../Logo":4,"../Menu":5,"../Nav":6,"../handlers/handlers":10,"../state/actions":11,"../util/reactify":15,"cns-lib":18,"react":222,"react-dom":63,"react-redux":192,"redux":228}],9:[function(require,module,exports){ var CNS_ = require("cns-lib"); //**END LIBRARY**// const React = require('react'); const ReactDOM = require('react-dom'); var ref0_ = require('redux'); const bindActionCreators = ref0_.bindActionCreators; var ref1_ = require('react-redux'); const connect = ref1_.connect; const actions = require('../state/actions'); const reactify = require('../util/reactify'); const Logo = require('../Logo'); const Nav = require('../Nav'); const Menu = require('../Menu'); var ref2_ = require('../handlers/handlers'); const handleClickNav = ref2_.handleClickNav; const handleSelectLink = ref2_.handleSelectLink; const handleClickMenuLink = ref2_.handleClickMenuLink; const handleClickLogo = ref2_.handleClickLogo; function select () { const args = CNS_.args(arguments); const state = args[0]; return { menuOpen: state.menuOpen, downloadOptions: state.downloadOptions, downloadSelection: state.downloadSelection }; }; function action () { const args = CNS_.args(arguments); const dispatch = args[0]; return { toggleMenu: bindActionCreators(actions.toggleMenu, dispatch), selectLink: bindActionCreators(actions.selectLink, dispatch) }; }; function render () { var ref3_ = this.props; const menuOpen = ref3_.menuOpen; const toggleMenu = ref3_.toggleMenu; const downloadOptions = ref3_.downloadOptions; const downloadSelection = ref3_.downloadSelection; const selectLink = ref3_.selectLink; return CNS_.createElement("div", {}, [ CNS_.createElement(Logo, {menuOpen: menuOpen, toggleMenu: toggleMenu, handleClickLogo: handleClickLogo}, []), CNS_.createElement(Nav, {menuOpen: menuOpen, toggleMenu: toggleMenu, handleClickNav: handleClickNav}, []), CNS_.createElement(Menu, {menuOpen: menuOpen, downloadOptions: downloadOptions, downloadSelection: downloadSelection, handleSelectLink: handleSelectLink, handleClickMenuLink: handleClickMenuLink, selectLink: selectLink, toggleMenu: toggleMenu}, []) ]); }; typeof module === 'undefined' ? typeof console !== 'undefined' && console.warn('Warning: You are attempting to export module values in a non-modular environment.') : module.exports = connect(select, action)(reactify({ render: render }, {})); },{"../Logo":4,"../Menu":5,"../Nav":6,"../handlers/handlers":10,"../state/actions":11,"../util/reactify":15,"cns-lib":18,"react":222,"react-dom":63,"react-redux":192,"redux":228}],10:[function(require,module,exports){ var CNS_ = require("cns-lib"); //**END LIBRARY**// function handleClickNav () { return this.props.toggleMenu(); }; function handleClickMenuLink () { return this.props.toggleMenu(); }; function handleSelectLink () { const args = CNS_.args(arguments); const evt = args[0]; return this.props.selectLink(evt.target.value); }; function handleClickLogo () { return this.props.toggleMenu(); }; typeof module === 'undefined' ? typeof console !== 'undefined' && console.warn('Warning: You are attempting to export module values in a non-modular environment.') : module.exports = { handleClickNav: handleClickNav, handleSelectLink: handleSelectLink, handleClickMenuLink: handleClickMenuLink, handleClickLogo: handleClickLogo } },{"cns-lib":18}],11:[function(require,module,exports){ var CNS_ = require("cns-lib"); //**END LIBRARY**// function toggleMenu () { return { type: Symbol.for('TOGGLE_MENU') }; }; function selectLink () { const args = CNS_.args(arguments); const value = args[0]; return { type: Symbol.for('SELECT_LINK'), payload: value }; }; typeof module === 'undefined' ? typeof console !== 'undefined' && console.warn('Warning: You are attempting to export module values in a non-modular environment.') : module.exports = { toggleMenu: toggleMenu, selectLink: selectLink } },{"cns-lib":18}],12:[function(require,module,exports){ var CNS_ = require("cns-lib"); //**END LIBRARY**// var ref0_ = require('../util/storage'); const retrieveState = ref0_.retrieveState; const uniqueId = ref0_.uniqueId; const initialState = { menuOpen: false, downloadSelection: { id: 'browserify', text: 'Browserify transformer', href: 'https://www.npmjs.com/package/creamify' }, downloadOptions: { browserify: { id: 'browserify', text: 'Browserify transformer', href: 'https://www.npmjs.com/package/creamify' }, gulp: { id: 'gulp', text: 'Gulp plugin', href: 'https://www.npmjs.com/package/gulp-cns' }, webpack: { id: 'webpack', text: 'Webpack loader', href: 'https://www.npmjs.com/package/cns-loader' }, raw: { id: 'raw', text: 'Raw language', href: 'https://www.npmjs.com/package/cream-and-sugar' } } }; function hydrateInitialState () { const storage = retrieveState(); return CNS_.qualify(storage, function () { return storage; }.bind(this), function () { return initialState; }.bind(this)); }; typeof module === 'undefined' ? typeof console !== 'undefined' && console.warn('Warning: You are attempting to export module values in a non-modular environment.') : module.exports = hydrateInitialState(); },{"../util/storage":16,"cns-lib":18}],13:[function(require,module,exports){ var CNS_ = require("cns-lib"); //**END LIBRARY**// const initialState = require('./initialstate'); var ref0_ = require('../util/storage'); const uniqueId = ref0_.uniqueId; function reducer () { const args = CNS_.args(arguments); if (args.length === 2 && CNS_.match(args, [["Identifier","state"],["Identifier","action"]])) { const state = args[0]; const action = args[1]; if (!state) { return reducer(initialState, action); } else { return (function () { switch (action.type) { case Symbol.for('TOGGLE_MENU'): return Object.assign({}, state, { menuOpen: !state.menuOpen }); case Symbol.for('SELECT_LINK'): const newOption = CNS_.get(action.payload, state.downloadOptions); return Object.assign({}, state, { downloadSelection: newOption }); default: return state; } }.bind(this)()); } } else { throw new Error('No match found for functional pattern match statement.'); } }; typeof module === 'undefined' ? typeof console !== 'undefined' && console.warn('Warning: You are attempting to export module values in a non-modular environment.') : module.exports = reducer; },{"../util/storage":16,"./initialstate":12,"cns-lib":18}],14:[function(require,module,exports){ var CNS_ = require("cns-lib"); //**END LIBRARY**// var ref0_ = require('redux'); const createStore = ref0_.createStore; const initialState = require('./initialstate'); const reducer = require('./reducer'); const store = createStore(reducer, initialState); typeof module === 'undefined' ? typeof console !== 'undefined' && console.warn('Warning: You are attempting to export module values in a non-modular environment.') : module.exports = store; },{"./initialstate":12,"./reducer":13,"cns-lib":18,"redux":228}],15:[function(require,module,exports){ var CNS_ = require("cns-lib"); //**END LIBRARY**// const React = require('react'); function handleList () { const args = CNS_.args(arguments); if (args.length === 1 && CNS_.match(args, [["Identifier","fnList"]])) { const fnList = args[0]; return handleList(fnList, {}); } else if (args.length === 2 && CNS_.match(args, [["Arr",[]],["Identifier","accum"]])) { const accum = args[1]; return accum; } else if (args.length === 2 && CNS_.match(args, [["HeadTail",["hd","tl"]],["Identifier","accum"]])) { const hd = args[0][0]; const tl = args[0].slice(1); const accum = args[1]; return handleList(tl, CNS_.update(hd.name, hd, accum)); } else { throw new Error('No match found for functional pattern match statement.'); } }; function handleTuple () { const args = CNS_.args(arguments); const fnList = args[0]; return CNS_.tupleToObject(fnList, function () { const args = CNS_.args(arguments); const each = args[0]; return each.name; }); }; function handleObject () { const args = CNS_.args(arguments); const fnList = args[0]; return fnList; }; function handleFun () { const args = CNS_.args(arguments); const fun = args[0]; return CNS_.update(fun.name, fun, {}); }; function buildClass () { const args = CNS_.args(arguments); const obj = args[0]; const propTypes = args[1]; return CNS_.update('propTypes', propTypes, React.createClass(obj)); }; function reactify () { const args = CNS_.args(arguments); const fnList = args[0]; const propTypes = args[1]; return (function () { switch (CNS_.dataType(fnList)) { case 'array': return buildClass(handleList(fnList), propTypes); case 'tuple': return buildClass(handleTuple(fnList), propTypes); case 'object': return buildClass(handleObject(fnList), propTypes); case 'function': return buildClass(handleFun(fnList), propTypes); default: return CNS_.throw(CNS_.create(Error, 'Could not create a react class.')); } }.bind(this)()); }; typeof module === 'undefined' ? typeof console !== 'undefined' && console.warn('Warning: You are attempting to export module values in a non-modular environment.') : module.exports = CNS_.aritize(reactify, 2); },{"cns-lib":18,"react":222}],16:[function(require,module,exports){ var CNS_ = require("cns-lib"); //**END LIBRARY**// function saveState () { const args = CNS_.args(arguments); const state = args[0]; return (function () { try { const serialized = JSON.stringify(state); return localStorage.setItem('cns', serialized); } catch (err) { return undefined; } }.bind(this)()); }; function retrieveState () { return (function () { try { const serialized = localStorage.getItem('cns'); return JSON.parse(serialized); } catch (err) { return undefined; } }.bind(this)()); }; function uniqueId () { return (CNS_.create(Date).getTime()) + '-' + Math.round(Math.random() * 50000); }; typeof module === 'undefined' ? typeof console !== 'undefined' && console.warn('Warning: You are attempting to export module values in a non-modular environment.') : module.exports = { saveState: saveState, retrieveState: retrieveState, uniqueId: uniqueId } },{"cns-lib":18}],17:[function(require,module,exports){ },{}],18:[function(require,module,exports){ (function (process){ const CNS_ = { /************************************************* * All private functions will go at the top *************************************************/ /** * @private * Contains runtime configuration options */ config: { use: { react: true } }, /** * @private * Wrapper/polyfill for Object.assign that always returns a new object. * * @param {Object} base The base object to begin with. * @param {Object} toAdd Properties to add to the base. * * @return {Object} Contains all of the properties. */ assign: function (base, toAdd) { if (typeof Object.assign !== 'function') { const out = {}; Object.keys(base).forEach(function (key) { out[key] = base[key] }); Object.keys(toAdd).forEach(function (key) { out[key] = toAdd[key] }); if (typeof Object.getOwnPropertySymbols === 'function') { Object.getOwnPropertySymbols(base).forEach(function (sym) { out[sym] = base[sym] }); Object.getOwnPropertySymbols(toAdd).forEach(function (sym) { out[sym] = toAdd[sym] }); } return out; } return Object.assign({}, base, toAdd); }, /** * @private * Converts `arguments` to an array. * * @param {Arguments} args Any `arguments` object. * @return {Array} Converted from the `arguments`. */ args: function (args) { const out = []; Array.prototype.push.apply(out, args); return out; }, /** * @private * Retrieves runtime configuration options * * @param {String} key The name of the value to retrieve * @return {Any} */ getConfig: function (key) { const pieces = key.split('.'); var obj = CNS_.config; pieces.every(function (item) { obj = obj[item]; return obj !== undefined; }); return obj; }, /** * @private * Determines whether a value is reserved and shouldn't be used. * * @param {Any} val Any value. * @return {Boolean} Whether or not the value is reserved. */ isReserved: function (val) { if ( typeof val === 'string' && val.length > 1 && val[val.length-1] === '_' && val[val.length-2] !== '_' // Let it through if it ends with "__" ) { throw new Error('Value ' + val + ' matches a reserved system pattern.'); } return false; }, /** * @private * Determines whether a value is a tuple. * * @param {Any} val Any value * @return {Boolean} Whether the value was a tuple. */ isTuple: function (val) { return val.CNS_isTuple_ === CNS_; }, /** * @private * Binds a function to the current context. If the value is not a function, * Generates a function that returns the value, bound to the current context. * * @param {Any} val Any value. * @param {Any} context Any value. * @return {Function} Retrieves `val` and is bound to `context`. */ lazify: function(val, context) { return typeof val === 'function' ? val.bind(context) : function () { return val }.bind(context); }, /** * @private * Matches a function's arguments against expected patterns. * For example: CNS_.match(args, [['Identifier', 'x']]); * * @param {Array} args Contains a function's arguments. * @param {Array} pattern Describes patterns to match arguments against. * @return {Boolean} Whether or not arguments match patterns. */ match: function (args, pattern) { const NUMTEST = /^(\-)?[0-9]+(\.[0-9]+)?(e\-?[0-9]+)?$/; const ATOMTEST = /^[\$_A-z][\$_A-z0-9]*$/; const SYMTEST = /^Symbol\.for\(/; const SYMREPLACE = /^Symbol\.for\((\'|\")|(\'|\")\)$/g; function convertSpecial(special) { switch (special) { case 'null': return null; case 'undefined': return undefined; case 'true': return true; case 'false': return false; default: return special; } } function arrMismatch(matchType, arg) { const isTuple = CNS_.isTuple(arg); return matchType === 'Tuple' && !isTuple || matchType === 'Arr' && isTuple; } function testArrParam(arg, arrParam, position) { if (arrParam === '_') return true; // Yes, if it's the catch all. if (arrParam === 'NaN') return isNaN(arg[position]); // Yes, if they're both NaN. if ((converted = convertSpecial(arrParam)) !== arrParam) return arg[position] === converted; // Yes, if it's a special and the specials match. if (SYMTEST.test(arrParam)) return arg[position] === Symbol.for(arrParam.replace(SYMREPLACE, '')); // Yes, if it's a symbol and symbols match. return ATOMTEST.test(arrParam) ? true : CNS_.eql(arg[position], JSON.parse(arrParam)); // Yes, for identifiers, recursive equality check for anything else. } return args.every(function (arg, index) { if (!pattern[index]) return false; // No match if the arity's wrong. var matchType = pattern[index][0]; // For example "Tuple" var matchVal = pattern[index][1]; // For example ["x","y"] var converted; switch(matchType) { case 'Identifier': return true; // An identifier is a variable assignment so we allow it. case 'Atom': return arg === Symbol.for(matchVal); // Match if it's the same atom. case 'String': return arg === matchVal; // Match if it's the same string. case 'Number': return NUMTEST.test(arg) && arg === parseFloat(matchVal); // Match if the arg is a number and the numbers are equal. case 'Special': return matchVal === 'NaN' ? isNaN(arg) : arg === convertSpecial(matchVal); // Match if the special values are equal. case 'HeadTail': case 'LeadLast': return Array.isArray(arg); // Match any array because we're just doing array destructuring. case 'Arr': case 'Tuple': // No match if it's not an array, we've mismatched arrays/tuples, or if we have the wrong amount of items. if (!Array.isArray(arg) || arrMismatch(matchType, arg) || arg.length !== matchVal.length) return false; // Match if all of the subobjects match. return matchVal.every(function (arrParam, position) { return testArrParam(arg, arrParam, position); }); case 'Keys': case 'Obj': // Similar to the arr/tuple condition except here we don't care if the amount of keys matches our pattern length. if (typeof arg !== 'object' || arg.constructor !== Object) return false; // No match if the arg isn't an object. if (matchType === 'Keys') return true; // Match if the arg is an object and we're just destructuring keys. return matchVal.every(function (pair) { const kv = pair.split(':'); if (SYMTEST.test(kv[0])) (kv[0] = Symbol.for(kv[0].replace(SYMREPLACE, ''))); return testArrParam(arg, kv[1].trim(), typeof kv[0] === 'string' ? kv[0].trim() : kv[0]); }); default: CNS_.die('Can not pattern match against type ' + matchType); // No match if we don't have a matchable type. } }); }, /** * @private * Conditionally executes one function or another. * * @param {Any} condition Assessed for its truthiness. * @param {Function} callback Executed if `condition` is truthy. * @param {Function} elseCase Executed if `condition` is falsy. * @return {Any} The result of the executed function or `undefined`. */ qualify: function (condition, callback, elseCase) { return condition ? callback() : elseCase ? elseCase() : undefined; }, /** * @private * Generates a tuple data type * * @param {Array} arr Any array. * @return {Array} Marked with a special property identifying it as a tuple. */ tuple: function (arr) { if (!arr.length) CNS_.die('Tuples can not be empty.'); Object.defineProperty ? Object.defineProperty(arr, 'CNS_isTuple_', {enumerable: false, configurable: false, writable: false, value: CNS_}) : (arr.CNS_isTuple_ = CNS_); return arr; }, /************************************************* * End private functions, begin exposed functions *************************************************/ /** * @public * Calls a function. * For example: CNS_.apply(function () {}, x, y, z); * * @param {Function} fn The function to call. * @return {Any} The result of calling the function. */ apply: function (fn) { var args = Array.prototype.slice.call(arguments, 1); return args.length ? fn.apply(null, args) : fn(); }, /** * @public * Makes a new function that calls an existing function but only * accepts a certain amount of arguments. * * @param {Function} fun A function to lock down. * @param {Number} arity The acceptable amount of arguments. * @return {Function} A resulting function. */ aritize: function (fun, arity) { return function () { if (arguments.length === arity) { return fun.apply(undefined, arguments); } CNS_.die('Function ' + (fun.name || '') + ' called with wrong arity. Expected ' + arity + ' got ' + arguments.length + '.'); }; }, /** * @public * Converts an array to a tuple. * * @param {Array} arr Any array. * @return {Tuple} Converted from the array. */ arrayToTuple: function (arr) { if (CNS_.isTuple(arr) || !Array.isArray(arr)) CNS_.die('Argument provided is not an array'); return CNS_.tuple(arr.slice()); }, /** * @public * Creates a new function that caches its result after being called and will * forever return that same result immediately when called. The function * can also be decached. * * @param {Function} fn The function to use as a base for a caching function. * @return {Function} The caching function. */ cache: function (fn) { var executed, storedOutput; var out = function (deCache) { if (deCache === CNS_) { executed = false; storedOutput = undefined; } else if (!executed) { executed = true; storedOutput = fn.apply(null, arguments); } return storedOutput; }; out.CNS_isCachedFn_ = true; return out; }, /** * @public * Creates a `new` object. * For example: CNS_.create(ClassName, arg1, arg2); * * @param {Constructor} cls Any constructor function. * @return {Instance} An instance of the constructor's object. */ create: function(cls) { return new (Function.prototype.bind.apply(cls, arguments)); }, /** * @public * Creats an html element. * * @param {String|Constructor} type The type of element to create. * @param {Object} attrs The element's attributes. * @param {Array} body Children of the element. * @return {HtmlElement} The resulting element. */ createElement: function (type, attrs, body) { var react; const a = attrs || {}; const b = body || []; // If we have React, reference it. typeof React !== 'undefined' && (react = React); // If we have require, try to require React. if (!react && typeof require !== 'undefined') { try { react = require('react'); } catch (_) { react = null; } } // If we have react, pass to React. End. if (react && CNS_.getConfig('use.react')) { return react.createElement.apply(react, [type, a].concat(b)); } // Die if we're not in a browser environment. if (typeof document === 'undefined') { return CNS_.die('No HTML document is available.'); } // Create an element and set attributes. const elem = document.createElement(type); Object.keys(a).forEach(function (key) { switch (key) { case 'className' : return elem.setAttribute('class', a[key]); case 'htmlFor' : return elem.setAttribute('for', a[key]); default : return elem.setAttribute(key.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(), a[key]); } }); // Append children. b.forEach(function (node) { elem.appendChild(node); }); return elem; }, /** * @public * Breaks functionalism and mutates a value on an existing object. * Necessary for actions like setting location.href. For example: * * dangerouslyMutate 'href', '/example', location * * @param {String|Number} keyOrIndex Identifies the item to update. * @param {Any} val The new value. * @param {Collection} collection Any collection type. * @return {Collection} A copy of the original collection. */ dangerouslyMutate: function (keyOrIndex, val, collection) { collection[keyOrIndex] = val; return collection; }, /** * @public * Assesses data types. * * @param {Any} val Any value. * @return {String} The type of data assessed. */ dataType: function (val) { const type = typeof val; switch (type) { case 'symbol': return 'atom'; case 'number': return isNaN(val) ? 'nan' : type; case 'object': if (val === null) return 'null'; if (Array.isArray(val)) return CNS_.isTuple(val) ? 'tuple' : 'array'; if (val instanceof Date) return 'date'; if (val instanceof RegExp) return 'regexp'; if (typeof HTMLElement !== 'undefined' && val instanceof HTMLElement) return 'htmlelement'; if ( (typeof Worker !== 'undefined' && val instanceof Worker) || (val.constructor.name === 'ChildProcess' && typeof val.pid === 'number') ) return 'process'; return type; default: return type; } }, /** * @public * Decaches a previously cached function. If the provided function is not a * caching function, an error will be triggered. * * @param {Function} fn A function generated via a call to `cache`. * @return {undefined} */ decache: function (fn) { if (!fn.CNS_isCachedFn_) { throw new Error('Can not decache a non caching function.'); } return fn(CNS_); }, /** * @public * Shorcuts console.debug but only if it exists. * Tries to fall back to console.log. */ debug: function () { if (typeof console !== 'undefined' && typeof console.debug === 'function') { return console.debug.apply(console, arguments); } return CNS_.log.apply(null, arguments); }, /** * @public * Shortcuts throwing an error in a way that can be returned by a * JavaScript function. * * @param {String} msg The error message. * @return {undefined} */ die: function (msg) { throw new Error(msg); }, /** * @public * Selects a single DOM element by selector. * * @param {String} selector Describes the element to select. * @return {HTMLElement} The selected element. */ dom: function (selector) { return document.querySelector(selector); }, /** * @public * Selects an array of DOM elements by selector. * * @param {String} selector Describes the element to select. * @return {Array} The selected elements. */ domArray: function (selector) { return Array.prototype.slice.call(document.querySelectorAll(selector)); }, /** * @public * Performs a deep equal operation on two collections. * * @param {Any} a Any data. * @param {Any} b Any data. * @return {Boolean} Whether `a` and `b` are deep equal. */ eql: function (a, b) { if (a === CNS_ || b === CNS_) return true; // <- Hack to force a match if (a === b || (typeof a === 'number' && typeof b === 'number' && isNaN(a) && isNaN(b))) return true; if (typeof a !== typeof b) return false; if (typeof a === 'object') { if (Array.isArray(a)) return a.every(function(item, index) { return CNS_.eql(item, b[index]) }.bind(this)); const ks = Object.keys, ak = ks(a), bk = ks(b); if (!CNS_.eql(ak, bk)) return false; return ak.every(function (key) { return CNS_.eql(a[key], b[key]) }.bind(this)); } return false; }, /** * @public * Retrieves an item from a collection. * * @param {String|Number} item Identifies the item by key or position. * @param {Collection} collection Any collection type. * @return {Any} The retrieved item. */ get: function (item, collection) { if (!CNS_.isReserved(item)) return collection[item]; }, /** * @public * Returns the first item in a list. * * @param {Array|Tuple|String} list Any list type. * @return {Any} The item in position 0. */ head: function (list) { return list[0]; }, /** * @public * Functionizes the `instanceof` operator. * * @param {Any} val Any value. * @param {Constructor} type Any constructor function. * @return {Boolean} The result of calling `val instanceof type`. */ instanceof: function (val, type) { return val instanceof type; }, /** * @public * Sets a language configuration option. * * @param {String} key The name of the config option. * @param {Any} val The value for the option. * @return {undefined} */ lang: function (key, val) { const pieces = key.split('.'); var obj = CNS_.config; pieces.forEach(function (item, index) { const isLast = index === pieces.length - 1; if (isLast) { obj[item] = val; } else { obj[item] = obj[item] || {}; obj = obj[item]; } }); }, /** * @public * Returns the last item in a list. * * @param {Array|Tuple|String} list Any list type. * @return {Any} The item in the last position. */ last: function (list) { return list[list.length - 1]; }, /** * @public * Returns all but the last item in a list. * * @param {Array|Tuple|String} list Any list type. * @return {Array|Tuple|String} Minus the last item in `list`. */ lead: function (list) { const out = list.slice(0, list.length - 1); if (CNS_.isTuple(list)) return CNS_.tuple(out); return out; }, /** * @public * Shorcuts console.log but only if it exists. */ log: function () { if (typeof console !== 'undefined' && typeof console.log === 'function') { return console.log.apply(console, arguments); } }, /** * @public * Selects a random item from a list type colelction. * * @param {Array|Tuple|String} list Any list type. * @return {Any} A randomly selected item. */ random: function (list) { return list[Math.floor(Math.random()*list.length)]; }, /** * @public * Generates an array of a certain length specified by the bound parameters. * * @param {Number} from A lower bound. * @param {Number} through An upper bound. * @return {Array} The resulting array. */ range: function (from, through) { const out = []; for (var i = from; i <= through; i += 1) out.push(i); return out; }, /** * @public * Creates a new collection by removing an item in an existing collection. * * @param {String|Number} keyOrIndex Identifies the item to remove. * @param {Collection} collection Any collection type. * @return {Collection} A copy of the original collection. */ remove: function (keyOrIndex, collection) { CNS_.isReserved(keyOrIndex); if (Array.isArray(collection)) { if (CNS_.isTuple(collection)) CNS_.die('Can not remove items from tuples.'); const splicer = collection.slice(); splicer.splice(keyOrIndex, 1); return splicer; } else { const newObj = {}; const keys = Object.keys(collection).concat( Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(collection) : [] ); keys.forEach(function (key) { keyOrIndex !== key && (newObj[key] = collection[key]); }); return newObj; } }, /** * @public * Returns all but the first item in a list. * * @param {Array|Tuple|String} list Any list type. * @return {Array|Tuple|String} Minus the first item in `list`. */ tail: function (list) { const out = list.slice(1); if (CNS_.isTuple(list)) return CNS_.tuple(out); return out; }, /** * @public * Throws an instance of an error object. * For example: CNS_.throw(CNS_.create(Error)); * * @param {Error} err Any error object. * @return {undefined} */ throw: function (err) { throw err; }, /** * @public * Converts a tuple to an array. * * @param {Tuple} tuple An instance of a tuple data type. * @return {Array} Converted from the tuple. */ tupleToArray: function (tuple) { if (!CNS_.isTuple(tuple)) CNS_.die('Argument provided is not a tuple'); return tuple.slice(); }, /** * @public * Converts a tuple to an object. * * @param {Tuple} list A tuple data type. * @param {Function} fn Optional. Called once for each item and determines * how to name the object key. * @return {Object} */ tupleToObject: function (list, fn) { const obj = {}; if (!CNS_.isTuple(list)) CNS_.die('Argument provided is not a tuple'); list.forEach(function (item, index) { obj[fn ? fn(item, index) : index] = item }); return obj; }, /** * @public * Creates a new collection by updating an item in an existing collection. * EXCEPTION: If the collection is a function, modifies the existing function. * * @param {String|Number} keyOrIndex Identifies the item to update. * @param {Any} val The new value. * @param {Collection} collection Any collection type. * @return {Collection} A copy of the original collection. */ update: function (keyOrIn