made with requirebin
Created
July 8, 2016 03:20
-
-
Save ajoslin/211d0997953c490542b8e03e784783b7 to your computer and use it in GitHub Desktop.
requirebin sketch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Obstruct = require('obstruction') | |
var parse = Obstruct({ | |
value: Obstruct.parent({ | |
name: true | |
}) | |
}) | |
var result = parse({ | |
value: { | |
name: 'bob' | |
} | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setTimeout(function(){require=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){"use strict";var Obstruct=require("./obstruct");module.exports=function arraySchema(schema){var parse=schema;if(typeof parse!=="function"){parse=Obstruct(schema)}return function mapArray(array){return array.map(parse)}}},{"./obstruct":7}],2:[function(require,module,exports){exports=module.exports=ap;function ap(args,fn){return function(){var rest=[].slice.call(arguments),first=args.slice();first.push.apply(first,rest);return fn.apply(this,first)}}exports.pa=pa;function pa(args,fn){return function(){var rest=[].slice.call(arguments);rest.push.apply(rest,args);return fn.apply(this,rest)}}exports.apa=apa;function apa(left,right,fn){return function(){return fn.apply(this,left.concat.apply(left,arguments).concat(right))}}exports.partial=partial;function partial(fn){var args=[].slice.call(arguments,1);return ap(args,fn)}exports.partialRight=partialRight;function partialRight(fn){var args=[].slice.call(arguments,1);return pa(args,fn)}exports.curry=curry;function curry(fn){return partial(partial,fn)}exports.curryRight=function curryRight(fn){return partial(partialRight,fn)}},{}],3:[function(require,module,exports){"use strict";function isObjOrFn(x){return(typeof x==="object"||typeof x==="function")&&x!==null}module.exports.get=function(obj,path){if(!isObjOrFn(obj)||typeof path!=="string"){return obj}var pathArr=path.split(".");pathArr.some(function(path,index){obj=obj[path];if(obj===undefined){return true}});return obj};module.exports.set=function(obj,path,value){if(!isObjOrFn(obj)||typeof path!=="string"){return}var pathArr=path.split(".");pathArr.forEach(function(path,index){if(!isObjOrFn(obj[path])){obj[path]={}}if(index===pathArr.length-1){obj[path]=value}obj=obj[path]})}},{}],4:[function(require,module,exports){"use strict";module.exports=function isObject(x){return typeof x==="object"&&x!==null}},{}],5:[function(require,module,exports){module.exports=Array.isArray||function(arr){return Object.prototype.toString.call(arr)=="[object Array]"}},{}],6:[function(require,module,exports){"use strict";module.exports=function(obj,cb){var ret={};var keys=Object.keys(obj);for(var i=0;i<keys.length;i++){var key=keys[i];var res=cb(key,obj[key],obj);ret[res[0]]=res[1]}return ret}},{}],7:[function(require,module,exports){"use strict";var isObject=require("is-object");var dotProp=require("dot-prop");var isArray=require("isarray");var mapObject=require("map-obj");var partial=require("ap").partial;module.exports=Obstruct;function Obstruct(schema,object){if(!isObject(schema)){throw new Error("schema object is required")}if(arguments.length<2){return partial(Obstruct,schema)}return mapObject(schema,createParser(object))}function createParser(object){return function parser(key,value){if(!value){throw new Error("falsy values not allowed in schema ("+key+")")}if(~key.indexOf(".")){throw new Error("dots are not allowed in schema keys")}var srcKey,result;if(isArray(value)){srcKey=value[0];value=value[1]}else{srcKey=key}if(value===true){result=object[key]}if(typeof value==="string"){result=dotProp.get(object,value)}if(typeof value==="function"){result=value(dotProp.get(object,srcKey),object,srcKey)}if(isObject(value)){result=Obstruct(value,dotProp.get(object,srcKey))}return[key,result]}}},{ap:2,"dot-prop":3,"is-object":4,isarray:5,"map-obj":6}],8:[function(require,module,exports){"use struct";var Obstruct=require("./obstruct");module.exports=function optional(schema){var parse=schema;if(typeof parse!=="function"){parse=Obstruct(schema)}return function optionalValue(value){if(value!=null)return parse(value)}}},{"./obstruct":7}],9:[function(require,module,exports){"use strict";var Obstruct=require("./obstruct");module.exports=function parent(schema){var parse=schema;if(typeof parse!=="function"){parse=Obstruct(schema)}return function parseParent(value,parent){return parse(parent)}}},{"./obstruct":7}],obstruction:[function(require,module,exports){"use strict";var Obstruct=require("./obstruct");var optional=require("./optional");var array=require("./array");var parent=require("./parent");Obstruct.optional=optional;Obstruct.array=array;Obstruct.parent=parent;module.exports=Obstruct},{"./array":1,"./obstruct":7,"./optional":8,"./parent":9}]},{},[]);var Obstruct=require("obstruction");var parse=Obstruct({value:Obstruct.parent({name:true})});var result=parse({value:{name:"bob"}})},0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "requirebin-sketch", | |
"version": "1.0.0", | |
"dependencies": { | |
"obstruction": "2.0.0" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- contents of this file will be placed inside the <body> --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- contents of this file will be placed inside the <head> --> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/falcor/0.1.17/falcor.browser.js" type="text/javascript"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment