-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add babel-cli into polyfill to do transpiling
- Loading branch information
DAS
committed
Nov 22, 2017
1 parent
12ecc9e
commit e97e786
Showing
9 changed files
with
118 additions
and
47 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const [http, port] = [require('http'), 8080]; | ||
const [fs, $path, $url] = [require('fs'), require('path'), require('url')]; | ||
|
||
const requestHandler = (request, response) => { | ||
let url = request.url; | ||
fpath = $path.join(__dirname, url); | ||
fstat = $stat(fpath); | ||
console.log(new Date(), url, fstat.isFile()?'f':fstat.isDirectory()?'d':'-') | ||
if(fstat.isFile(fpath)) { | ||
fs.createReadStream(fpath).pipe(response); | ||
} else if(fstat.isDirectory()) { | ||
response.write(`<h3>Directory listing of '${url}'</h3>`); | ||
for(let i of fs.readdirSync(fpath)) response.write( | ||
`<div><a href='${$join(url, i)}'>${i}</a></div>`); | ||
response.end(); | ||
} else response.end('404 not found!'); | ||
} | ||
|
||
const server = http.createServer(requestHandler); | ||
server.listen(port, (err) => { | ||
if (err) return console.log('something bad happened', err); | ||
console.log(`server is listening on ${port}, ${__dirname}`); | ||
}); | ||
|
||
function $stat(fn) { | ||
if(fs.existsSync(fn)) return fs.lstatSync(fpath); | ||
else return { | ||
isFile() { return false;}, | ||
isDirectory() { return false;} | ||
}; | ||
}; | ||
function $join(a,b) { return $path.posix.normalize($path.posix.join(a,b)); } |
File renamed without changes.
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,34 @@ | ||
// https://babeljs.io/repl/ | ||
'use strict'; | ||
|
||
var body = document.body; | ||
var adiv = function adiv(str) { | ||
var el = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document.body; | ||
|
||
console.log(str); | ||
var div = document.createElement('div'); | ||
div.innerHTML = str; | ||
el.appendChild(div); | ||
}; | ||
|
||
var x = new Promise(function (r, e) { | ||
setTimeout(function (x) { | ||
console.log('one'); | ||
adiv('one'); | ||
r('two'); | ||
}, 500); | ||
}).then(function (d) { | ||
return new Promise(function (r, e) { | ||
setTimeout(function (x) { | ||
console.log(d); | ||
adiv(d); | ||
r('three'); | ||
}, 500); | ||
}); | ||
}).then(function (d) { | ||
return new Promise(function (r, e) { | ||
setTimeout(function (x) { | ||
console.log(d); | ||
adiv(d); | ||
r('four'); | ||
}, 500); | ||
}); | ||
}).then(function (d) { | ||
console.log(d); | ||
}); | ||
adiv(d); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
let body = document.body; | ||
let adiv = (str, el=document.body)=> { | ||
console.log(str); | ||
var div = document.createElement('div'); | ||
div.innerHTML = str; | ||
el.appendChild(div); | ||
} | ||
|
||
let x = new Promise((r,e)=> { | ||
setTimeout(x=> { | ||
adiv('one'); | ||
r('two'); | ||
}, 500); | ||
}).then(d=> new Promise((r,e)=> { | ||
setTimeout(x=> { | ||
adiv(d); | ||
r('three'); | ||
}, 500); | ||
})).then(d=> new Promise((r,e)=> { | ||
setTimeout(x=> { | ||
adiv(d); | ||
r('four'); | ||
}, 500); | ||
})).then(d=> { adiv(d); }); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "polyfill", | ||
"version": "1.0.0", | ||
"description": "I was curious about having two separate libraries, one which had been transpiled for pre-es6 compatibility (essentially just IE and Opera Mobile), and one for all major browsers which have near full es6 support inbuilt.", | ||
"main": "0ws.js", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"babel-preset-env": "^1.6.1" | ||
}, | ||
"scripts": { | ||
"start": "node 0ws.js", | ||
"build": "babel lib -d dist --presets env" | ||
}, | ||
"author": "", | ||
"license": "MIT" | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,32 @@ | ||
// content of index.js | ||
const http = require('http'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const port = 8080; | ||
const [http, port] = [require('http'), 8080]; | ||
const [fs, $path, $url] = [require('fs'), require('path'), require('url')]; | ||
|
||
const requestHandler = (request, response) => { | ||
console.log(request.url) | ||
fpath = path.join(__dirname, request.url); | ||
if(fs.existsSync(fpath)) { | ||
var rstream = fs.createReadStream(fpath); | ||
rstream.pipe(response); | ||
} else { | ||
response.end('Hello Node.js Server!') | ||
} | ||
let url = request.url; | ||
fpath = $path.join(__dirname, url); | ||
fstat = $stat(fpath); | ||
console.log(new Date(), url, fstat.isFile()?'f':fstat.isDirectory()?'d':'-') | ||
if(fstat.isFile(fpath)) { | ||
fs.createReadStream(fpath).pipe(response); | ||
} else if(fstat.isDirectory()) { | ||
response.write(`<h3>Directory listing of '${url}'</h3>`); | ||
for(let i of fs.readdirSync(fpath)) response.write( | ||
`<div><a href='${$join(url, i)}'>${i}</a></div>`); | ||
response.end(); | ||
} else response.end('404 not found!'); | ||
} | ||
|
||
const server = http.createServer(requestHandler) | ||
|
||
const server = http.createServer(requestHandler); | ||
server.listen(port, (err) => { | ||
if (err) { | ||
return console.log('something bad happened', err) | ||
} | ||
if (err) return console.log('something bad happened', err); | ||
console.log(`server is listening on ${port}, ${__dirname}`); | ||
}); | ||
|
||
console.log(`server is listening on ${port}`) | ||
}) | ||
function $stat(fn) { | ||
if(fs.existsSync(fn)) return fs.lstatSync(fpath); | ||
else return { | ||
isFile() { return false;}, | ||
isDirectory() { return false;} | ||
}; | ||
}; | ||
function $join(a,b) { return $path.posix.normalize($path.posix.join(a,b)); } |