Skip to content

Instantly share code, notes, and snippets.

@DimitarChristoff
Created September 20, 2016 09:37
Show Gist options
  • Save DimitarChristoff/384c1319fa264c8b5896c6db702c21b0 to your computer and use it in GitHub Desktop.
Save DimitarChristoff/384c1319fa264c8b5896c6db702c21b0 to your computer and use it in GitHub Desktop.
requirebin sketch
// Welcome! require() some modules from npm (like you were using browserify)
// and then hit Run Code to run your code on the right side.
// Modules get downloaded from browserify-cdn and bundled in your browser.
var p = require('glob-parse');
var toParse = 'js:**/*.{js,jsx}'.match(/(.+):(.+)/),
type = toParse.shift(),
pattern = toParse.pop();
console.log(p(pattern, { full: true }));
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){(function(process){function normalizeArray(parts,allowAboveRoot){var up=0;for(var i=parts.length-1;i>=0;i--){var last=parts[i];if(last==="."){parts.splice(i,1)}else if(last===".."){parts.splice(i,1);up++}else if(up){parts.splice(i,1);up--}}if(allowAboveRoot){for(;up--;up){parts.unshift("..")}}return parts}var splitPathRe=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;var splitPath=function(filename){return splitPathRe.exec(filename).slice(1)};exports.resolve=function(){var resolvedPath="",resolvedAbsolute=false;for(var i=arguments.length-1;i>=-1&&!resolvedAbsolute;i--){var path=i>=0?arguments[i]:process.cwd();if(typeof path!=="string"){throw new TypeError("Arguments to path.resolve must be strings")}else if(!path){continue}resolvedPath=path+"/"+resolvedPath;resolvedAbsolute=path.charAt(0)==="/"}resolvedPath=normalizeArray(filter(resolvedPath.split("/"),function(p){return!!p}),!resolvedAbsolute).join("/");return(resolvedAbsolute?"/":"")+resolvedPath||"."};exports.normalize=function(path){var isAbsolute=exports.isAbsolute(path),trailingSlash=substr(path,-1)==="/";path=normalizeArray(filter(path.split("/"),function(p){return!!p}),!isAbsolute).join("/");if(!path&&!isAbsolute){path="."}if(path&&trailingSlash){path+="/"}return(isAbsolute?"/":"")+path};exports.isAbsolute=function(path){return path.charAt(0)==="/"};exports.join=function(){var paths=Array.prototype.slice.call(arguments,0);return exports.normalize(filter(paths,function(p,index){if(typeof p!=="string"){throw new TypeError("Arguments to path.join must be strings")}return p}).join("/"))};exports.relative=function(from,to){from=exports.resolve(from).substr(1);to=exports.resolve(to).substr(1);function trim(arr){var start=0;for(;start<arr.length;start++){if(arr[start]!=="")break}var end=arr.length-1;for(;end>=0;end--){if(arr[end]!=="")break}if(start>end)return[];return arr.slice(start,end-start+1)}var fromParts=trim(from.split("/"));var toParts=trim(to.split("/"));var length=Math.min(fromParts.length,toParts.length);var samePartsLength=length;for(var i=0;i<length;i++){if(fromParts[i]!==toParts[i]){samePartsLength=i;break}}var outputParts=[];for(var i=samePartsLength;i<fromParts.length;i++){outputParts.push("..")}outputParts=outputParts.concat(toParts.slice(samePartsLength));return outputParts.join("/")};exports.sep="/";exports.delimiter=":";exports.dirname=function(path){var result=splitPath(path),root=result[0],dir=result[1];if(!root&&!dir){return"."}if(dir){dir=dir.substr(0,dir.length-1)}return root+dir};exports.basename=function(path,ext){var f=splitPath(path)[2];if(ext&&f.substr(-1*ext.length)===ext){f=f.substr(0,f.length-ext.length)}return f};exports.extname=function(path){return splitPath(path)[3]};function filter(xs,f){if(xs.filter)return xs.filter(f);var res=[];for(var i=0;i<xs.length;i++){if(f(xs[i],i,xs))res.push(xs[i])}return res}var substr="ab".substr(-1)==="b"?function(str,start,len){return str.substr(start,len)}:function(str,start,len){if(start<0)start=str.length+start;return str.substr(start,len)}}).call(this,require("_process"))},{_process:2}],2:[function(require,module,exports){var process=module.exports={};process.nextTick=function(){var canSetImmediate=typeof window!=="undefined"&&window.setImmediate;var canMutationObserver=typeof window!=="undefined"&&window.MutationObserver;var canPost=typeof window!=="undefined"&&window.postMessage&&window.addEventListener;if(canSetImmediate){return function(f){return window.setImmediate(f)}}var queue=[];if(canMutationObserver){var hiddenDiv=document.createElement("div");var observer=new MutationObserver(function(){var queueList=queue.slice();queue.length=0;queueList.forEach(function(fn){fn()})});observer.observe(hiddenDiv,{attributes:true});return function nextTick(fn){if(!queue.length){hiddenDiv.setAttribute("yes","no")}queue.push(fn)}}if(canPost){window.addEventListener("message",function(ev){var source=ev.source;if((source===window||source===null)&&ev.data==="process-tick"){ev.stopPropagation();if(queue.length>0){var fn=queue.shift();fn()}}},true);return function nextTick(fn){queue.push(fn);window.postMessage("process-tick","*")}}return function nextTick(fn){setTimeout(fn,0)}}();process.title="browser";process.browser=true;process.env={};process.argv=[];function noop(){}process.on=noop;process.addListener=noop;process.once=noop;process.off=noop;process.removeListener=noop;process.removeAllListeners=noop;process.emit=noop;process.binding=function(name){throw new Error("process.binding is not supported")};process.cwd=function(){return"/"};process.chdir=function(dir){throw new Error("process.chdir is not supported")}},{}],"glob-parse":[function(require,module,exports){var path=require("path");var EXTGLOB_START_CHAR={"?":true,"*":true,"+":true,"@":true,"!":true};function parse(glob,opts){var parts=[],types=[];if(!opts){opts={}}scanChunk(glob,function(type,part){if(opts.full){types.push(type)}parts.push(part)});return!opts.full?parts:{parts:parts,types:types}}function scanChunk(glob,onEach){var start,i,numStars=0;function chunk(type,start,i){if(start!==i&&i<=glob.length){onEach(type,glob.substring(start,i))}}for(start=i=0;i<glob.length;i++){if(EXTGLOB_START_CHAR[glob[i]]&&glob[i+1]==="("){chunk("str",start,i);start=i;i+=2;i=parseUntil(glob,i,"(",")");chunk("ext",start,i);start=i;continue}switch(glob[i]){case"\\":if(i===glob.length){throw new Error("No character to escape!")}i++;break;case"[":chunk("str",start,i);start=i;i=parseUntil(glob,++i,"[","]");chunk("set",start,i);start=i;break;case"{":chunk("str",start,i);start=i;i=parseUntil(glob,++i,"{","}");chunk("brace",start,i);start=i;break;case"?":chunk("str",start,i);chunk("?",start,i);start=i;break;case"*":chunk("str",start,i);start=i;numStars=1;while(glob[++i]==="*"){numStars++}chunk(numStars==1?"*":"**",start,i);start=i}}chunk("str",start,i)}function parseUntil(glob,i,startChar,endChar){var depth=0;do{if(glob[i]==="\\"){i++}else if(glob[i]===endChar){depth--;if(depth===0||depth===-1){i++;break}}else if(glob[i]===startChar){depth++}}while(++i<glob.length);return i}module.exports=parse;module.exports.basename=function(glob){var parsed=parse(glob,{full:true}),result="";parsed.parts.some(function(str,i){if(parsed.types[i]!=="str"){return true}result+=str});var lastSlash=result.lastIndexOf("/",result.length);if(lastSlash!==result.length-1){return result.substring(0,lastSlash+1)}return result}},{path:1}]},{},[]);var p=require("glob-parse");var toParse="js:**/*.{js,jsx}".match(/(.+):(.+)/),type=toParse.shift(),pattern=toParse.pop();console.log(p(pattern,{full:true}))},0);
{
"name": "requirebin-sketch",
"version": "1.0.0",
"dependencies": {
"glob-parse": "0.0.1"
}
}
<!-- contents of this file will be placed inside the <body> -->
<!-- contents of this file will be placed inside the <head> -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment