made with requirebin
Created
June 24, 2014 20:33
-
-
Save bloodyowl/592b9a5c045b98f8596b 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 stream = require("bloody-stream") | |
var concat = require("bloody-stream/lib/concat") | |
var escapeRE = /([.*+?^=!:$(){}|[\]\/\\])/g | |
var mapEscape = function(string){ | |
return string.replace(escapeRE, "\\$1") | |
} | |
var tilde = function(words){ | |
var wordsRE = RegExp("\\b" + words.map(mapEscape).join("\\b|\\b") + "\\b", "g") | |
return stream.create(function(chunk){ | |
if(!wordsRE.test(chunk)) { | |
this.queue(chunk) | |
return | |
} | |
this.queue(chunk.replace(wordsRE, function(word){ | |
return "~" + word + "~" | |
})) | |
}) | |
} | |
function t(words){ | |
return function(string) { | |
var lines = string.split("\n") | |
var parser = tilde(words) | |
var data = "" | |
parser | |
.pipe(concat("\n")) | |
.on("data", function(chunk){ | |
data = chunk | |
}) | |
lines.forEach(function(line){ | |
parser.write(line) | |
}) | |
parser.end() | |
return data | |
} | |
} | |
var autotilde = t([ | |
"you", | |
"really", | |
"srsly" | |
]) | |
document.body.innerHTML = [ | |
"<pre>", | |
autotilde("what do you think, really?\nsrsly"), | |
"</pre>" | |
].join("") |
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
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);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.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 events=require("bloody-events");module.exports=events.extend({constructor:function(fn){events.constructor.call(this);this._pauseBuffer=[];if(typeof fn=="function"){this._transform=fn}},destructor:function(){events.destructor.call(this);this._pauseBuffer.length=0},pipe:function(stream){stream.emit("pipe",this);this.on("data:pipe",stream.accessor("write"));this.on("end",stream.accessor("end"));return stream},unpipe:function(stream){if(stream!=null){stream.emit("pipe",this);this.off("data:pipe",stream.accessor("write"));this.off("end",stream.accessor("end"));return this}this.off("data:pipe");return this},write:function(chunk){if(this._ended){throw new TypeError}if(chunk==null){this.emit("end");this._ended=true;return}this._transform(chunk);return this},pause:function(){this.write=function(chunk){this._pauseBuffer.push(chunk)};return this},resume:function(){var item;delete this.write;while(item=this._pauseBuffer.shift()){this.write(item)}return this},end:function(chunk){if(chunk!=null){this.write(chunk)}this.write(null)},queue:function(chunk){this.emit("data",chunk);this.emit("data:pipe",chunk)},_transform:function(chunk){this.queue(chunk)}})},{"bloody-events":4}],"+vaQHM":[function(require,module,exports){var stream=require("..");var emptyTypes={string:function(){return""},array:function(){return[]},number:function(){return 0},object:function(){return{}}};var checkTypes={string:function(chunk){return typeof chunk=="string"},number:function(chunk){return typeof chunk=="number"},array:function(chunk){return Object.prototype.toString.call(chunk)=="[object Array]"},object:function(chunk){return Object.prototype.toString.call(chunk)=="[object Object]"}};var concatTypes={string:function(left,right,separator){return left+(separator==null?"":separator)+right},number:function(left,right){return left+right},array:function(left,right){return left.concat(right)},object:function(left,right){var result={};var key;for(key in left){if(left.hasOwnProperty(key)){result[key]=left[key]}}for(key in right){if(right.hasOwnProperty(key)){result[key]=right[key]}}return result}};module.exports=function(separator){var result;var type=null;var ended=false;var first=true;var concat=stream.create(function(chunk){var key;if(first){for(key in checkTypes){if(checkTypes[key](chunk)){type=key;result=emptyTypes[type]();break}}if(type==null){throw new TypeError("unsupported type")}}if(!checkTypes[type](chunk)){throw new TypeError("mixed types")}result=concatTypes[type](result,chunk,first?null:separator);first=false});concat.on("end",function(){concat.queue(result)});return concat}},{"..":1}],"bloody-stream/lib/concat":[function(require,module,exports){module.exports=require("+vaQHM")},{}],4:[function(require,module,exports){var klass=require("bloody-class");var _slice=[].slice;module.exports=klass.extend({constructor:function(){this._events={}},destructor:function(){this._events={}},on:function(type,listener,once){var listeners=this._events[type]||(this._events[type]=[]);var index=-1,length=listeners.length,fn;var self=this;while(++index<length){if(listeners[index]===listener){return this}}if(once){fn=function(){self.off(type,listener);return listener.apply(null,arguments)};fn.listener=listener}listeners.push(fn||listener);return this},once:function(type,listener){this.on(type,listener,true);return this},off:function(type,listener){var listeners;var length;switch(arguments.length){case 0:this._events={};case 1:this._events[type]=null;default:listeners=this._events[type];length=listeners&&listeners.length;if(!length)return;while(--length>-1){if(listeners[length]===listener||listeners[length].listener===listener){listeners.splice(length,1);break}}}return this},emit:function(type){var listeners=this._events[type];var length;var args=_slice.call(arguments,1);var index=-1;if(!listeners){return false}listeners=listeners.concat();length=listeners.length;if(!length){return false}while(++index<length){listeners[index].apply(null,args)}return true}})},{"bloody-class":5}],5:[function(require,module,exports){var extend=require("bloody-collections/lib/extend");var hasMethod=require("./lib/hasMethod");var create=require("./lib/create");var K=function(){};module.exports={extend:function(object){var subKlass=create(this);extend(subKlass,object);return subKlass},create:function(){var instance=create(this);instance._accessors={};if(hasMethod(instance,"constructor")){instance.constructor.apply(instance,arguments)}return instance},destroy:function(){if(hasMethod(this,"destructor")){this.destructor.apply(this,arguments)}this._accessors={}},accessor:function(methodName){var thisValue=this;if(this._accessors.hasOwnProperty(methodName)){return this._accessors[methodName]}return this._accessors[methodName]=function(){return thisValue[methodName].apply(thisValue,arguments)}},constructor:K,destructor:K}},{"./lib/create":6,"./lib/hasMethod":7,"bloody-collections/lib/extend":11}],6:[function(require,module,exports){var toString=Object.prototype.toString;var isNativeRE=RegExp("^"+String(toString).replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/toString| for [^\]]+/g,".*?")+"$");if(Object.create&&isNativeRE.test(Object.create)){module.exports=Object.create}else{module.exports=function(object){function F(){}F.prototype=object;return new F}}},{}],7:[function(require,module,exports){module.exports=function(object,property){return typeof object[property]=="function"}},{}],8:[function(require,module,exports){module.exports=[function(fn,thisValue){return function(){return fn.call(thisValue)}},function(fn,thisValue){return function(a){return fn.call(thisValue,a)}},function(fn,thisValue){return function(a,b){return fn.call(thisValue,a,b)}},function(fn,thisValue){return function(a,b,c){return fn.call(thisValue,a,b,c)}},function(fn,thisValue){return function(a,b,c,d){return fn.call(thisValue,a,b,c,d)}},function(fn,thisValue){return function(){return fn.apply(thisValue,arguments)}}]},{}],9:[function(require,module,exports){var callbacks=require("./_callbacks");module.exports=function(fn,thisValue,length){if(thisValue===void 0){return fn}if(length in callbacks){return callbacks[length](fn,thisValue)}return callbacks[callbacks.length-1](fn,thisValue)}},{"./_callbacks":8}],10:[function(require,module,exports){var getKeys=require("./getKeys"),createCallback=require("./createCallback"),isArrayLike=require("./isArrayLike");module.exports=function(collection,fn,thisValue){var index=-1,length,keys,key,callback=createCallback(fn,thisValue,3);if(!collection)return;if(isArrayLike(collection)){length=collection.length;while(++index<length){if(callback(collection[index],index,collection)===false)break}return}keys=getKeys(collection);length=keys.length;while(++index<length){key=keys[index];if(callback(collection[key],key,collection)===false)break}}},{"./createCallback":9,"./getKeys":12,"./isArrayLike":13}],11:[function(require,module,exports){var each=require("./each");module.exports=extend;function extend(source,object){each(object,extendCallback,source);return source}function extendCallback(value,key){if(!this)return false;this[key]=value}},{"./each":10}],12:[function(require,module,exports){var objectPrototype=Object.prototype,enumBugProperties=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable",,"toLocaleString","toString","valueOf"],hasEnumBug=!objectPrototype.propertyIsEnumerable.call({constructor:1},"constructor"),_hasOwnProperty=objectPrototype.hasOwnProperty,hasObjectKeys=typeof Object.keys=="function",objectKeys=Object.keys;module.exports=function(object){var index,keys,length,enumKey;if(object==null)return[];if(hasObjectKeys)return objectKeys(object);keys=[];for(index in object){if(_hasOwnProperty.call(object,index))keys.push(index)}if(hasEnumBug){index=-1;length=enumBugProperties.length;while(++index<length){enumKey=enumBugProperties[index];if(_hasOwnProperty.call(object,enumKey)){keys.push(enumKey)}}}return keys}},{}],13:[function(require,module,exports){var _hasOwnProperty={}.hasOwnProperty;module.exports=function(object){var length;return object&&parseInt(length=object.length,10)===length&&!length||_hasOwnProperty.call(object,length-1)}},{}]},{},[]);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);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.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}({jLbFzv:[function(require,module,exports){var events=require("bloody-events");module.exports=events.extend({constructor:function(fn){events.constructor.call(this);this._pauseBuffer=[];if(typeof fn=="function"){this._transform=fn}},destructor:function(){events.destructor.call(this);this._pauseBuffer.length=0},pipe:function(stream){stream.emit("pipe",this);this.on("data:pipe",stream.accessor("write"));this.on("end",stream.accessor("end"));return stream},unpipe:function(stream){if(stream!=null){stream.emit("pipe",this);this.off("data:pipe",stream.accessor("write"));this.off("end",stream.accessor("end"));return this}this.off("data:pipe");return this},write:function(chunk){if(this._ended){throw new TypeError}if(chunk==null){this.emit("end");this._ended=true;return}this._transform(chunk);return this},pause:function(){this.write=function(chunk){this._pauseBuffer.push(chunk)};return this},resume:function(){var item;delete this.write;while(item=this._pauseBuffer.shift()){this.write(item)}return this},end:function(chunk){if(chunk!=null){this.write(chunk)}this.write(null)},queue:function(chunk){this.emit("data",chunk);this.emit("data:pipe",chunk)},_transform:function(chunk){this.queue(chunk)}})},{"bloody-events":3}],"bloody-stream":[function(require,module,exports){module.exports=require("jLbFzv")},{}],3:[function(require,module,exports){var klass=require("bloody-class");var _slice=[].slice;module.exports=klass.extend({constructor:function(){this._events={}},destructor:function(){this._events={}},on:function(type,listener,once){var listeners=this._events[type]||(this._events[type]=[]);var index=-1,length=listeners.length,fn;var self=this;while(++index<length){if(listeners[index]===listener){return this}}if(once){fn=function(){self.off(type,listener);return listener.apply(null,arguments)};fn.listener=listener}listeners.push(fn||listener);return this},once:function(type,listener){this.on(type,listener,true);return this},off:function(type,listener){var listeners;var length;switch(arguments.length){case 0:this._events={};case 1:this._events[type]=null;default:listeners=this._events[type];length=listeners&&listeners.length;if(!length)return;while(--length>-1){if(listeners[length]===listener||listeners[length].listener===listener){listeners.splice(length,1);break}}}return this},emit:function(type){var listeners=this._events[type];var length;var args=_slice.call(arguments,1);var index=-1;if(!listeners){return false}listeners=listeners.concat();length=listeners.length;if(!length){return false}while(++index<length){listeners[index].apply(null,args)}return true}})},{"bloody-class":4}],4:[function(require,module,exports){var extend=require("bloody-collections/lib/extend");var hasMethod=require("./lib/hasMethod");var create=require("./lib/create");var K=function(){};module.exports={extend:function(object){var subKlass=create(this);extend(subKlass,object);return subKlass},create:function(){var instance=create(this);instance._accessors={};if(hasMethod(instance,"constructor")){instance.constructor.apply(instance,arguments)}return instance},destroy:function(){if(hasMethod(this,"destructor")){this.destructor.apply(this,arguments)}this._accessors={}},accessor:function(methodName){var thisValue=this;if(this._accessors.hasOwnProperty(methodName)){return this._accessors[methodName]}return this._accessors[methodName]=function(){return thisValue[methodName].apply(thisValue,arguments)}},constructor:K,destructor:K}},{"./lib/create":5,"./lib/hasMethod":6,"bloody-collections/lib/extend":10}],5:[function(require,module,exports){var toString=Object.prototype.toString;var isNativeRE=RegExp("^"+String(toString).replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/toString| for [^\]]+/g,".*?")+"$");if(Object.create&&isNativeRE.test(Object.create)){module.exports=Object.create}else{module.exports=function(object){function F(){}F.prototype=object;return new F}}},{}],6:[function(require,module,exports){module.exports=function(object,property){return typeof object[property]=="function"}},{}],7:[function(require,module,exports){module.exports=[function(fn,thisValue){return function(){return fn.call(thisValue)}},function(fn,thisValue){return function(a){return fn.call(thisValue,a)}},function(fn,thisValue){return function(a,b){return fn.call(thisValue,a,b)}},function(fn,thisValue){return function(a,b,c){return fn.call(thisValue,a,b,c)}},function(fn,thisValue){return function(a,b,c,d){return fn.call(thisValue,a,b,c,d)}},function(fn,thisValue){return function(){return fn.apply(thisValue,arguments)}}]},{}],8:[function(require,module,exports){var callbacks=require("./_callbacks");module.exports=function(fn,thisValue,length){if(thisValue===void 0){return fn}if(length in callbacks){return callbacks[length](fn,thisValue)}return callbacks[callbacks.length-1](fn,thisValue)}},{"./_callbacks":7}],9:[function(require,module,exports){var getKeys=require("./getKeys"),createCallback=require("./createCallback"),isArrayLike=require("./isArrayLike");module.exports=function(collection,fn,thisValue){var index=-1,length,keys,key,callback=createCallback(fn,thisValue,3);if(!collection)return;if(isArrayLike(collection)){length=collection.length;while(++index<length){if(callback(collection[index],index,collection)===false)break}return}keys=getKeys(collection);length=keys.length;while(++index<length){key=keys[index];if(callback(collection[key],key,collection)===false)break}}},{"./createCallback":8,"./getKeys":11,"./isArrayLike":12}],10:[function(require,module,exports){var each=require("./each");module.exports=extend;function extend(source,object){each(object,extendCallback,source);return source}function extendCallback(value,key){if(!this)return false;this[key]=value}},{"./each":9}],11:[function(require,module,exports){var objectPrototype=Object.prototype,enumBugProperties=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable",,"toLocaleString","toString","valueOf"],hasEnumBug=!objectPrototype.propertyIsEnumerable.call({constructor:1},"constructor"),_hasOwnProperty=objectPrototype.hasOwnProperty,hasObjectKeys=typeof Object.keys=="function",objectKeys=Object.keys;module.exports=function(object){var index,keys,length,enumKey;if(object==null)return[];if(hasObjectKeys)return objectKeys(object);keys=[];for(index in object){if(_hasOwnProperty.call(object,index))keys.push(index)}if(hasEnumBug){index=-1;length=enumBugProperties.length;while(++index<length){enumKey=enumBugProperties[index];if(_hasOwnProperty.call(object,enumKey)){keys.push(enumKey)}}}return keys}},{}],12:[function(require,module,exports){var _hasOwnProperty={}.hasOwnProperty;module.exports=function(object){var length;return object&&parseInt(length=object.length,10)===length&&!length||_hasOwnProperty.call(object,length-1)}},{}]},{},[]);var stream=require("bloody-stream");var concat=require("bloody-stream/lib/concat");var escapeRE=/([.*+?^=!:$(){}|[\]\/\\])/g;var mapEscape=function(string){return string.replace(escapeRE,"\\$1")};var tilde=function(words){var wordsRE=RegExp("\\b"+words.map(mapEscape).join("\\b|\\b")+"\\b","g");return stream.create(function(chunk){if(!wordsRE.test(chunk)){this.queue(chunk);return}this.queue(chunk.replace(wordsRE,function(word){return"~"+word+"~"}))})};function t(words){return function(string){var lines=string.split("\n");var parser=tilde(words);var data="";parser.pipe(concat("\n")).on("data",function(chunk){data=chunk});lines.forEach(function(line){parser.write(line)});parser.end();return data}}var autotilde=t(["you","really","srsly"]);document.body.innerHTML=["<pre>",autotilde("what do you think, really?\nsrsly"),"</pre>"].join(""); |
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": { | |
"bloody-stream": "0.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
<style type='text/css'>html, body { margin: 0; padding: 0; border: 0; } | |
body, html { height: 100%; width: 100%; }</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment