├── mock ├── empty.js ├── tls.js ├── tty.js ├── net.js ├── punycode.js ├── buffer.js ├── console.js ├── dns.js └── process.js ├── .gitignore ├── .gitattributes ├── LICENSE ├── package.json ├── index.js └── README.md /mock/empty.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /mock/tls.js: -------------------------------------------------------------------------------- 1 | // todo 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /mock/tty.js: -------------------------------------------------------------------------------- 1 | exports.isatty = function () {}; 2 | exports.setRawMode = function () {}; 3 | -------------------------------------------------------------------------------- /mock/net.js: -------------------------------------------------------------------------------- 1 | exports.createServer = 2 | exports.createConnection = 3 | exports.connect = 4 | function () {}; 5 | 6 | exports.isIP = 7 | exports.isIPv4 = 8 | exports.isIPv6 = 9 | function () { return true }; 10 | 11 | -------------------------------------------------------------------------------- /mock/punycode.js: -------------------------------------------------------------------------------- 1 | exports.ucs2 = {}; 2 | exports.encode = exports.decode = 3 | exports.ucs2.encode = exports.ucs2.decode = 4 | exports.toUnicode = exports.toASCII = 5 | function (s) { return s }; 6 | exports.version = "0.0.0"; -------------------------------------------------------------------------------- /mock/buffer.js: -------------------------------------------------------------------------------- 1 | function Buffer() { 2 | throw new Error("Buffer is not included."); 3 | } 4 | Buffer.isBuffer = function() { 5 | return false; 6 | }; 7 | 8 | exports.INSPECT_MAX_BYTES = 50; 9 | exports.SlowBuffer = Buffer; 10 | exports.Buffer = Buffer; 11 | -------------------------------------------------------------------------------- /mock/console.js: -------------------------------------------------------------------------------- 1 | var console; 2 | if (typeof global !== "undefined" && global.console) { 3 | console = global.console 4 | } else if (typeof window !== "undefined" && window.console) { 5 | console = window.console 6 | } else { 7 | console = window.console = {} 8 | } 9 | module.exports = console; 10 | for(var name in {log:1, info:1, error:1, warn:1, dir:1, trace:1, assert:1, time:1, timeEnd: 1}) 11 | if(!console[name]) 12 | console[name] = function() {}; 13 | -------------------------------------------------------------------------------- /mock/dns.js: -------------------------------------------------------------------------------- 1 | exports.lookup = exports.resolve4 = 2 | exports.resolve6 = exports.resolveCname = 3 | exports.resolveMx = exports.resolveNs = 4 | exports.resolveTxt = exports.resolveSrv = 5 | exports.resolveNaptr = exports.reverse = 6 | exports.resolve = 7 | function () { 8 | if (!arguments.length) return; 9 | 10 | var callback = arguments[arguments.length - 1]; 11 | if (callback && typeof callback === 'function') { 12 | callback(null, '0.0.0.0') 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /mock/process.js: -------------------------------------------------------------------------------- 1 | exports.nextTick = function nextTick(fn) { 2 | var args = Array.prototype.slice.call(arguments); 3 | args.shift(); 4 | setTimeout(function () { 5 | fn.apply(null, args); 6 | }, 0); 7 | }; 8 | 9 | exports.platform = exports.arch = 10 | exports.execPath = exports.title = 'browser'; 11 | exports.pid = 1; 12 | exports.browser = true; 13 | exports.env = {}; 14 | exports.argv = []; 15 | 16 | exports.binding = function (name) { 17 | throw new Error('No such module. (Possibly not yet loaded)') 18 | }; 19 | 20 | (function () { 21 | var cwd = '/'; 22 | var path; 23 | exports.cwd = function () { return cwd }; 24 | exports.chdir = function (dir) { 25 | if (!path) path = require('path'); 26 | cwd = path.resolve(dir, cwd); 27 | }; 28 | })(); 29 | 30 | exports.exit = exports.kill = 31 | exports.umask = exports.dlopen = 32 | exports.uptime = exports.memoryUsage = 33 | exports.uvCounters = function() {}; 34 | exports.features = {}; 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | (The MIT License) 2 | 3 | Copyright (c) 2012 Tobias Koppers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | 'Software'), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-libs-browser", 3 | "version": "2.2.1", 4 | "author": "Tobias Koppers @sokra", 5 | "description": "The node core libs for in browser usage.", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/webpack/node-libs-browser.git" 9 | }, 10 | "dependencies": { 11 | "assert": "^1.1.1", 12 | "browserify-zlib": "^0.2.0", 13 | "buffer": "^4.3.0", 14 | "console-browserify": "^1.1.0", 15 | "constants-browserify": "^1.0.0", 16 | "crypto-browserify": "^3.11.0", 17 | "domain-browser": "^1.1.1", 18 | "events": "^3.0.0", 19 | "https-browserify": "^1.0.0", 20 | "os-browserify": "^0.3.0", 21 | "path-browserify": "0.0.1", 22 | "process": "^0.11.10", 23 | "punycode": "^1.2.4", 24 | "querystring-es3": "^0.2.0", 25 | "readable-stream": "^2.3.3", 26 | "stream-browserify": "^2.0.1", 27 | "stream-http": "^2.7.2", 28 | "string_decoder": "^1.0.0", 29 | "timers-browserify": "^2.0.4", 30 | "tty-browserify": "0.0.0", 31 | "url": "^0.11.0", 32 | "util": "^0.11.0", 33 | "vm-browserify": "^1.0.1" 34 | }, 35 | "homepage": "http://github.com/webpack/node-libs-browser", 36 | "main": "index.js", 37 | "files": [ 38 | "index.js", 39 | "mock/" 40 | ], 41 | "scripts": { 42 | "test": "echo \"Error: no test specified\" && exit 1" 43 | }, 44 | "license": "MIT", 45 | "bugs": { 46 | "url": "https://github.com/webpack/node-libs-browser/issues" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | exports.assert = require.resolve('assert/'); 2 | exports.buffer = require.resolve('buffer/'); 3 | exports.child_process = null; 4 | exports.cluster = null; 5 | exports.console = require.resolve('console-browserify'); 6 | exports.constants = require.resolve('constants-browserify'); 7 | exports.crypto = require.resolve('crypto-browserify'); 8 | exports.dgram = null; 9 | exports.dns = null; 10 | exports.domain = require.resolve('domain-browser'); 11 | exports.events = require.resolve('events/'); 12 | exports.fs = null; 13 | exports.http = require.resolve('stream-http'); 14 | exports.https = require.resolve('https-browserify'); 15 | exports.module = null; 16 | exports.net = null; 17 | exports.os = require.resolve('os-browserify/browser.js'); 18 | exports.path = require.resolve('path-browserify'); 19 | exports.punycode = require.resolve('punycode/'); 20 | exports.process = require.resolve('process/browser.js'); 21 | exports.querystring = require.resolve('querystring-es3/'); 22 | exports.readline = null; 23 | exports.repl = null; 24 | exports.stream = require.resolve('stream-browserify'); 25 | exports._stream_duplex = require.resolve('readable-stream/duplex.js'); 26 | exports._stream_passthrough = require.resolve('readable-stream/passthrough.js'); 27 | exports._stream_readable = require.resolve('readable-stream/readable.js'); 28 | exports._stream_transform = require.resolve('readable-stream/transform.js'); 29 | exports._stream_writable = require.resolve('readable-stream/writable.js'); 30 | exports.string_decoder = require.resolve('string_decoder/'); 31 | exports.sys = require.resolve('util/util.js'); 32 | exports.timers = require.resolve('timers-browserify'); 33 | exports.tls = null; 34 | exports.tty = require.resolve('tty-browserify'); 35 | exports.url = require.resolve('url/'); 36 | exports.util = require.resolve('util/util.js'); 37 | exports.vm = require.resolve('vm-browserify'); 38 | exports.zlib = require.resolve('browserify-zlib'); 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # node-libs-browser 2 | 3 | The node core libs for in-browser usage. 4 | 5 | NOTE: This library is deprecated and won't accept Pull Requests that include Breaking Changes or new Features. Only bugfixes are accepted. 6 | 7 | [![dependencies status](http://david-dm.org/webpack/node-libs-browser.png)](http://david-dm.org/webpack/node-libs-browser) 8 | 9 | Exports a hash [object] of absolute paths to each lib, keyed by lib names. Modules without browser replacements are `null`. 10 | 11 | Some modules have mocks in the `mock` directory. These are replacements with minimal functionality. 12 | 13 | | lib name | browser implementation | mock implementation | 14 | |:--------:|:----------------------:|:-------------------:| 15 | | assert | [defunctzombie/commonjs-assert](https://github.com/defunctzombie/commonjs-assert) | --- | 16 | | buffer | [feross/buffer](https://github.com/feross/buffer) | [buffer.js](https://github.com/webpack/node-libs-browser/blob/master/mock/buffer.js) | 17 | | child_process | --- | --- | 18 | | cluster | --- | --- | 19 | | console | [Raynos/console-browserify](https://github.com/Raynos/console-browserify) | [console.js](https://github.com/webpack/node-libs-browser/blob/master/mock/console.js) | 20 | | constants | [juliangruber/constants-browserify](https://github.com/juliangruber/constants-browserify) | --- | 21 | | crypto | [crypto-browserify/crypto-browserify](https://github.com/crypto-browserify/crypto-browserify) | --- | 22 | | dgram | --- | --- | 23 | | dns | --- | [dns.js](https://github.com/webpack/node-libs-browser/blob/master/mock/dns.js) | 24 | | domain | [bevry/domain-browser](https://github.com/bevry/domain-browser) | --- | 25 | | events | [Gozala/events](https://github.com/Gozala/events) | --- | 26 | | fs | --- | --- | 27 | | http | [jhiesey/stream-http](https://github.com/jhiesey/stream-http) | --- | 28 | | https | [substack/https-browserify](https://github.com/substack/https-browserify) | --- | 29 | | module | --- | --- | 30 | | net | --- | [net.js](https://github.com/webpack/node-libs-browser/blob/master/mock/net.js) | 31 | | os | [CoderPuppy/os-browserify](https://github.com/CoderPuppy/os-browserify) | --- | 32 | | path | [substack/path-browserify](https://github.com/substack/path-browserify) | --- | 33 | | process | [shtylman/node-process](https://github.com/shtylman/node-process) | [process.js](https://github.com/webpack/node-libs-browser/blob/master/mock/process.js) | 34 | | punycode | [bestiejs/punycode.js](https://github.com/bestiejs/punycode.js) | --- | 35 | | querystring | [mike-spainhower/querystring](https://github.com/mike-spainhower/querystring) | --- | 36 | | readline | --- | --- | 37 | | repl | --- | --- | 38 | | stream | [substack/stream-browserify](https://github.com/substack/stream-browserify) | --- | 39 | | string_decoder | [rvagg/string_decoder](https://github.com/rvagg/string_decoder) | --- | 40 | | sys | [defunctzombie/node-util](https://github.com/defunctzombie/node-util) | --- | 41 | | timers | [jryans/timers-browserify](https://github.com/jryans/timers-browserify) | --- | 42 | | tls | --- | [tls.js](https://github.com/webpack/node-libs-browser/blob/master/mock/tls.js) | 43 | | tty | [substack/tty-browserify](https://github.com/substack/tty-browserify) | [tty.js](https://github.com/webpack/node-libs-browser/blob/master/mock/tty.js) | 44 | | url | [defunctzombie/node-url](https://github.com/defunctzombie/node-url) | --- | 45 | | util | [defunctzombie/node-util](https://github.com/defunctzombie/node-util) | --- | 46 | | vm | [substack/vm-browserify](https://github.com/substack/vm-browserify) | --- | 47 | | zlib | [devongovett/browserify-zlib](https://github.com/devongovett/browserify-zlib) | --- | 48 | 49 | ## Outdated versions 50 | 51 | ### `buffer` 52 | 53 | The current `buffer` implementation uses feross/buffer@4.x because feross/buffer@5.x relies on [typed arrays](https://github.com/feross/buffer/commit/5daca86b7cd5d2b8ccb167534d47421029f639e9#commitcomment-19698936). 54 | This will be dropped as soon as IE9 is not a typical browser target anymore. 55 | 56 | ### `punycode` 57 | 58 | The current `punycode` implementation uses bestiejs/punycode.js@1.x because bestiejs/punycode.js@2.x requires modern JS engines that understand `const` and `let`. 59 | It will be removed someday since it has already been [deprecated from the node API](https://nodejs.org/api/punycode.html). 60 | 61 | ## License 62 | 63 | MIT 64 | --------------------------------------------------------------------------------