Julian Steinwachs
9 years ago
83 changed files with 4772 additions and 3429 deletions
@ -0,0 +1,47 @@
@@ -0,0 +1,47 @@
|
||||
var React = require('react'); |
||||
var SetIntervalMixin = require("../common/SetIntervalMixin.js"); |
||||
var SafeStateChangeMixin = require('../common/SafeStateChangeMixin.js'); |
||||
var EventListenerMixin = require('../common/EventListenerMixin.js'); |
||||
var AppSettingsMixin = require('../common/AppSettingsMixin.js'); |
||||
|
||||
var ImportAccountModalButton = require('../other/ImportAccountModalButton.js'); |
||||
|
||||
var ReactBootstrap = require('react-bootstrap') |
||||
, NavItem = ReactBootstrap.NavItem |
||||
, Nav = ReactBootstrap.Nav |
||||
, ListGroup = ReactBootstrap.ListGroup |
||||
, ListGroupItem = ReactBootstrap.ListGroupItem |
||||
, Panel = ReactBootstrap.Panel |
||||
, Glyphicon = ReactBootstrap.Glyphicon |
||||
, Button = ReactBootstrap.Button |
||||
, Input = ReactBootstrap.Input |
||||
|
||||
module.exports = Accounts = React.createClass({ |
||||
|
||||
mixins: [ |
||||
SetIntervalMixin, |
||||
SafeStateChangeMixin, |
||||
AppSettingsMixin |
||||
], |
||||
contextTypes: { |
||||
router: React.PropTypes.func |
||||
}, |
||||
render: function() { |
||||
return ( |
||||
<ListGroup> |
||||
<ListGroupItem>Settings</ListGroupItem> |
||||
<ListGroupItem> |
||||
<ul> |
||||
{this.props.accounts.map(function(acc,index) { |
||||
//console.log(acc,index)
|
||||
return ( |
||||
<li>{acc.name} - {acc.status}</li> |
||||
); |
||||
})} |
||||
</ul> |
||||
<ImportAccountModalButton/> |
||||
</ListGroupItem> |
||||
</ListGroup> |
||||
); |
||||
} |
||||
}); |
@ -0,0 +1,59 @@
@@ -0,0 +1,59 @@
|
||||
/** |
||||
* Copyright 2014-2015, Facebook, Inc. |
||||
* All rights reserved. |
||||
* |
||||
* This source code is licensed under the BSD-style license found in the |
||||
* LICENSE file in the root directory of https://github.com/facebook/react/tree/0.13-stable.
|
||||
* An additional grant of patent rights can be found in the PATENTS file in the same directory. |
||||
* |
||||
* @providesModule warning |
||||
*/ |
||||
|
||||
"use strict"; |
||||
|
||||
/** |
||||
* Similar to invariant but only logs a warning if the condition is not met. |
||||
* This can be used to log issues in development environments in critical |
||||
* paths. Removing the logging code for production environments will keep the |
||||
* same logic and follow the same code paths. |
||||
*/ |
||||
|
||||
var __DEV__ = process.env.NODE_ENV !== 'production'; |
||||
|
||||
var warning = function warning() {}; |
||||
|
||||
if (__DEV__) { |
||||
warning = function (condition, format) { |
||||
for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { |
||||
args[_key - 2] = arguments[_key]; |
||||
} |
||||
|
||||
if (format === undefined) { |
||||
throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument'); |
||||
} |
||||
|
||||
if (format.length < 10 || /^[s\W]*$/.test(format)) { |
||||
throw new Error('The warning format should be able to uniquely identify this ' + 'warning. Please, use a more descriptive format than: ' + format); |
||||
} |
||||
|
||||
if (format.indexOf('Failed Composite propType: ') === 0) { |
||||
return; // Ignore CompositeComponent proptype check.
|
||||
} |
||||
|
||||
if (!condition) { |
||||
var argIndex = 0; |
||||
var message = 'Warning: ' + format.replace(/%s/g, function () { |
||||
return args[argIndex++]; |
||||
}); |
||||
console.warn(message); |
||||
try { |
||||
// --- Welcome to debugging React ---
|
||||
// This error was thrown as a convenience so that you can use this stack
|
||||
// to find the callsite that caused this warning to fire.
|
||||
throw new Error(message); |
||||
} catch (x) {} |
||||
} |
||||
}; |
||||
} |
||||
|
||||
module.exports = warning; |
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
# Logs |
||||
logs |
||||
*.log |
||||
|
||||
# Runtime data |
||||
pids |
||||
*.pid |
||||
*.seed |
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover |
||||
lib-cov |
||||
|
||||
# Coverage directory used by tools like istanbul |
||||
coverage |
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) |
||||
.grunt |
||||
|
||||
# Compiled binary addons (http://nodejs.org/api/addons.html) |
||||
build/Release |
||||
|
||||
# Dependency directory |
||||
# Commenting this out is preferred by some people, see |
||||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- |
||||
node_modules |
||||
|
||||
# Users Environment Variables |
||||
.lock-wscript |
@ -0,0 +1,22 @@
@@ -0,0 +1,22 @@
|
||||
The MIT License (MIT) |
||||
|
||||
Copyright (c) 2015 Kiran Abburi |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
of this software and associated documentation files (the "Software"), to deal |
||||
in the Software without restriction, including without limitation the rights |
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
copies of the Software, and to permit persons to whom the Software is |
||||
furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included in all |
||||
copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||
SOFTWARE. |
||||
|
@ -0,0 +1,7 @@
@@ -0,0 +1,7 @@
|
||||
var canUseDOM = !!( |
||||
typeof window !== 'undefined' && |
||||
window.document && |
||||
window.document.createElement |
||||
); |
||||
|
||||
module.exports = canUseDOM; |
@ -0,0 +1,51 @@
@@ -0,0 +1,51 @@
|
||||
{ |
||||
"name": "can-use-dom", |
||||
"version": "0.1.0", |
||||
"description": "Test if you can use dom in the current environment", |
||||
"main": "index.js", |
||||
"scripts": { |
||||
"test": "mocha test.js" |
||||
}, |
||||
"repository": { |
||||
"type": "git", |
||||
"url": "https://github.com/akiran/can-use-dom.git" |
||||
}, |
||||
"keywords": [ |
||||
"isomorphic" |
||||
], |
||||
"author": { |
||||
"name": "Kiran Abburi" |
||||
}, |
||||
"license": "MIT", |
||||
"bugs": { |
||||
"url": "https://github.com/akiran/can-use-dom/issues" |
||||
}, |
||||
"homepage": "https://github.com/akiran/can-use-dom", |
||||
"devDependencies": { |
||||
"jsdom": "^3.1.0", |
||||
"mocha": "^2.1.0", |
||||
"should": "^4.6.3" |
||||
}, |
||||
"gitHead": "0d49ab2adaacdd6c0160c6aafd474be4904a2e52", |
||||
"_id": "can-use-dom@0.1.0", |
||||
"_shasum": "22cc4a34a0abc43950f42c6411024a3f6366b45a", |
||||
"_from": "can-use-dom@0.1.0", |
||||
"_npmVersion": "2.1.3", |
||||
"_nodeVersion": "0.10.26", |
||||
"_npmUser": { |
||||
"name": "akiran", |
||||
"email": "kiran.coder0@gmail.com" |
||||
}, |
||||
"maintainers": [ |
||||
{ |
||||
"name": "akiran", |
||||
"email": "kiran.coder0@gmail.com" |
||||
} |
||||
], |
||||
"dist": { |
||||
"shasum": "22cc4a34a0abc43950f42c6411024a3f6366b45a", |
||||
"tarball": "http://registry.npmjs.org/can-use-dom/-/can-use-dom-0.1.0.tgz" |
||||
}, |
||||
"directories": {}, |
||||
"_resolved": "https://registry.npmjs.org/can-use-dom/-/can-use-dom-0.1.0.tgz" |
||||
} |
@ -0,0 +1,20 @@
@@ -0,0 +1,20 @@
|
||||
var should = require('should'); |
||||
// var jsdom = require('jsdom');
|
||||
|
||||
describe('canUseDOM', function () { |
||||
it('should return false in nodejs environment', function (done) { |
||||
var canUseDOM = require('./index'); |
||||
canUseDOM.should.be.false; |
||||
done(); |
||||
}); |
||||
|
||||
// it('should return true in browser', function (done) {
|
||||
// jsdom.env('<div></div>', function (err, window) {
|
||||
// global.document = jsdom.jsdom('');
|
||||
// global.window = document.defaultView;
|
||||
// var canUseDOM = require('./index');
|
||||
// canUseDOM.should.be.true;
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
}); |
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
2.1.1 / 2015-09-20 |
||||
================== |
||||
|
||||
* Use correct SPDX license. |
||||
* Test "browser.js" using browserify. |
||||
* Switch from "envify" to "loose-envify". |
||||
|
||||
2.1.0 / 2015-06-03 |
||||
================== |
||||
|
||||
* Add "envify" as a dependency. |
||||
* Fixed license field in "package.json". |
||||
|
||||
2.0.0 / 2015-02-21 |
||||
================== |
||||
|
||||
* Switch to using the "browser" field. There are now browser and server versions that respect the "format" in production. |
||||
|
||||
1.0.2 / 2014-09-24 |
||||
================== |
||||
|
||||
* Added tests, npmignore and gitignore. |
||||
* Clarifications in README. |
||||
|
||||
1.0.1 / 2014-09-24 |
||||
================== |
||||
|
||||
* Actually include 'invariant.js'. |
||||
|
||||
1.0.0 / 2014-09-24 |
||||
================== |
||||
|
||||
* Initial release. |
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
# invariant |
||||
|
||||
[![Build Status](https://travis-ci.org/zertosh/invariant.svg?branch=master)](https://travis-ci.org/zertosh/invariant) |
||||
|
||||
A mirror of Facebook's `invariant` (e.g. [React](https://github.com/facebook/react/blob/v0.13.3/src/vendor/core/invariant.js), [flux](https://github.com/facebook/flux/blob/2.0.2/src/invariant.js)). |
||||
|
||||
## Install |
||||
|
||||
With [npm](http://npmjs.org) do: |
||||
|
||||
```sh |
||||
npm install invariant |
||||
``` |
||||
|
||||
## `invariant(condition, message)` |
||||
|
||||
```js |
||||
var invariant = require('invariant'); |
||||
|
||||
invariant(someTruthyVal, 'This will not throw'); |
||||
// No errors |
||||
|
||||
invariant(someFalseyVal, 'This will throw an error with this message'); |
||||
// Error: Invariant Violation: This will throw an error with this message |
||||
``` |
||||
|
||||
**Note:** When `process.env.NODE_ENV` is not `production`, the message is required. If omitted, `invariant` will throw regardless of the truthiness of the condition. When `process.env.NODE_ENV` is `production`, the message is optional – so they can be minified away. |
||||
|
||||
### Browser |
||||
|
||||
When used with [browserify](https://github.com/substack/node-browserify), it'll use `browser.js` (instead of `invariant.js`) and the [envify](https://github.com/hughsk/envify) transform will inline the value of `process.env.NODE_ENV`. |
||||
|
||||
### Node |
||||
|
||||
The node version is optimized around the performance implications of accessing `process.env`. The value of `process.env.NODE_ENV` is cached, and repeatedly used instead of reading `proces.env`. See [Server rendering is slower with npm react #812](https://github.com/facebook/react/issues/812) |
@ -0,0 +1,51 @@
@@ -0,0 +1,51 @@
|
||||
/** |
||||
* Copyright 2013-2015, Facebook, Inc. |
||||
* All rights reserved. |
||||
* |
||||
* This source code is licensed under the BSD-style license found in the |
||||
* LICENSE file in the root directory of this source tree. An additional grant |
||||
* of patent rights can be found in the PATENTS file in the same directory. |
||||
*/ |
||||
|
||||
'use strict'; |
||||
|
||||
/** |
||||
* Use invariant() to assert state which your program assumes to be true. |
||||
* |
||||
* Provide sprintf-style format (only %s is supported) and arguments |
||||
* to provide information about what broke and what you were |
||||
* expecting. |
||||
* |
||||
* The invariant message will be stripped in production, but the invariant |
||||
* will remain to ensure logic does not differ in production. |
||||
*/ |
||||
|
||||
var invariant = function(condition, format, a, b, c, d, e, f) { |
||||
if (process.env.NODE_ENV !== 'production') { |
||||
if (format === undefined) { |
||||
throw new Error('invariant requires an error message argument'); |
||||
} |
||||
} |
||||
|
||||
if (!condition) { |
||||
var error; |
||||
if (format === undefined) { |
||||
error = new Error( |
||||
'Minified exception occurred; use the non-minified dev environment ' + |
||||
'for the full error message and additional helpful warnings.' |
||||
); |
||||
} else { |
||||
var args = [a, b, c, d, e, f]; |
||||
var argIndex = 0; |
||||
error = new Error( |
||||
format.replace(/%s/g, function() { return args[argIndex++]; }) |
||||
); |
||||
error.name = 'Invariant Violation'; |
||||
} |
||||
|
||||
error.framesToPop = 1; // we don't care about invariant's own frame
|
||||
throw error; |
||||
} |
||||
}; |
||||
|
||||
module.exports = invariant; |
@ -0,0 +1,53 @@
@@ -0,0 +1,53 @@
|
||||
/** |
||||
* Copyright 2013-2015, Facebook, Inc. |
||||
* All rights reserved. |
||||
* |
||||
* This source code is licensed under the BSD-style license found in the |
||||
* LICENSE file in the root directory of this source tree. An additional grant |
||||
* of patent rights can be found in the PATENTS file in the same directory. |
||||
*/ |
||||
|
||||
'use strict'; |
||||
|
||||
/** |
||||
* Use invariant() to assert state which your program assumes to be true. |
||||
* |
||||
* Provide sprintf-style format (only %s is supported) and arguments |
||||
* to provide information about what broke and what you were |
||||
* expecting. |
||||
* |
||||
* The invariant message will be stripped in production, but the invariant |
||||
* will remain to ensure logic does not differ in production. |
||||
*/ |
||||
|
||||
var __DEV__ = process.env.NODE_ENV !== 'production'; |
||||
|
||||
var invariant = function(condition, format, a, b, c, d, e, f) { |
||||
if (__DEV__) { |
||||
if (format === undefined) { |
||||
throw new Error('invariant requires an error message argument'); |
||||
} |
||||
} |
||||
|
||||
if (!condition) { |
||||
var error; |
||||
if (format === undefined) { |
||||
error = new Error( |
||||
'Minified exception occurred; use the non-minified dev environment ' + |
||||
'for the full error message and additional helpful warnings.' |
||||
); |
||||
} else { |
||||
var args = [a, b, c, d, e, f]; |
||||
var argIndex = 0; |
||||
error = new Error( |
||||
format.replace(/%s/g, function() { return args[argIndex++]; }) |
||||
); |
||||
error.name = 'Invariant Violation'; |
||||
} |
||||
|
||||
error.framesToPop = 1; // we don't care about invariant's own frame
|
||||
throw error; |
||||
} |
||||
}; |
||||
|
||||
module.exports = invariant; |
@ -0,0 +1,3 @@
@@ -0,0 +1,3 @@
|
||||
bench/ |
||||
test/ |
||||
.travis.yml |
@ -0,0 +1,45 @@
@@ -0,0 +1,45 @@
|
||||
# loose-envify |
||||
|
||||
[![Build Status](https://travis-ci.org/zertosh/loose-envify.svg?branch=master)](https://travis-ci.org/zertosh/loose-envify) |
||||
|
||||
Fast (and loose) selective `process.env` replacer using [js-tokens](https://github.com/lydell/js-tokens) instead of an AST. Works just like [envify](https://github.com/hughsk/envify) but much faster. |
||||
|
||||
## Gotchas |
||||
|
||||
* Doesn't handle broken syntax. |
||||
* Doesn't look inside embedded expressions in template strings. |
||||
- **this won't work:** |
||||
```js |
||||
console.log(`the current env is ${process.env.NODE_ENV}`); |
||||
``` |
||||
* Doesn't replace oddly-spaced or oddly-commented expressions. |
||||
- **this won't work:** |
||||
```js |
||||
console.log(process./*won't*/env./*work*/NODE_ENV); |
||||
``` |
||||
|
||||
## Usage/Options |
||||
|
||||
loose-envify has the exact same interface as [envify](https://github.com/hughsk/envify). |
||||
|
||||
## Benchmark |
||||
|
||||
``` |
||||
envify: |
||||
|
||||
$ for i in {1..5}; do node bench/bench.js 'envify'; done |
||||
708ms |
||||
727ms |
||||
791ms |
||||
719ms |
||||
720ms |
||||
|
||||
loose-envify: |
||||
|
||||
$ for i in {1..5}; do node bench/bench.js '../'; done |
||||
51ms |
||||
52ms |
||||
52ms |
||||
52ms |
||||
52ms |
||||
``` |
@ -0,0 +1,2 @@
@@ -0,0 +1,2 @@
|
||||
// envify compatibility
|
||||
module.exports = require('./loose-envify'); |
@ -0,0 +1 @@
@@ -0,0 +1 @@
|
||||
module.exports = require('./loose-envify')(process.env); |
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
'use strict'; |
||||
|
||||
var stream = require('stream'); |
||||
var util = require('util'); |
||||
var replace = require('./replace'); |
||||
|
||||
var jsonExtRe = /\.json$/; |
||||
|
||||
module.exports = function(rootEnv) { |
||||
rootEnv = rootEnv || process.env; |
||||
return function (file, trOpts) { |
||||
if (jsonExtRe.test(file)) { |
||||
return stream.PassThrough(); |
||||
} |
||||
var envs = trOpts ? [rootEnv, trOpts] : [rootEnv]; |
||||
return new LooseEnvify(envs); |
||||
}; |
||||
}; |
||||
|
||||
function LooseEnvify(envs) { |
||||
stream.Transform.call(this); |
||||
this._data = ''; |
||||
this._envs = envs; |
||||
} |
||||
util.inherits(LooseEnvify, stream.Transform); |
||||
|
||||
LooseEnvify.prototype._transform = function(buf, enc, cb) { |
||||
this._data += buf; |
||||
cb(); |
||||
}; |
||||
|
||||
LooseEnvify.prototype._flush = function(cb) { |
||||
var replaced = replace(this._data, this._envs); |
||||
this.push(replaced); |
||||
cb(); |
||||
}; |
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT) |
||||
|
||||
Copyright (c) 2014, 2015 Simon Lydell |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
of this software and associated documentation files (the "Software"), to deal |
||||
in the Software without restriction, including without limitation the rights |
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
copies of the Software, and to permit persons to whom the Software is |
||||
furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included in |
||||
all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||||
THE SOFTWARE. |
@ -0,0 +1,65 @@
@@ -0,0 +1,65 @@
|
||||
### Version 1.0.2 (2015-10-18) ### |
||||
|
||||
- Improved: Limited npm package contents for a smaller download. Thanks to |
||||
@zertosh! |
||||
|
||||
|
||||
### Version 1.0.1 (2015-06-20) ### |
||||
|
||||
- Fixed: Declared an undeclared variable. |
||||
|
||||
|
||||
### Version 1.0.0 (2015-02-26) ### |
||||
|
||||
- Changed: Merged the 'operator' and 'punctuation' types into 'punctuator'. That |
||||
type is now equivalent to the Punctuator token in the ECMAScript |
||||
specification. (Backwards-incompatible change.) |
||||
- Fixed: A `-` followed by a number is now correctly matched as a punctuator |
||||
followed by a number. It used to be matched as just a number, but there is no |
||||
such thing as negative number literals. (Possibly backwards-incompatible |
||||
change.) |
||||
|
||||
|
||||
### Version 0.4.1 (2015-02-21) ### |
||||
|
||||
- Added: Support for the regex `u` flag. |
||||
|
||||
|
||||
### Version 0.4.0 (2015-02-21) ### |
||||
|
||||
- Improved: `jsTokens.matchToToken` performance. |
||||
- Added: Support for octal and binary number literals. |
||||
- Added: Support for template strings. |
||||
|
||||
|
||||
### Version 0.3.1 (2015-01-06) ### |
||||
|
||||
- Fixed: Support for unicode spaces. They used to be allowed in names (which is |
||||
very confusing), and some unicode newlines were wrongly allowed in strings and |
||||
regexes. |
||||
|
||||
|
||||
### Version 0.3.0 (2014-12-19) ### |
||||
|
||||
- Changed: The `jsTokens.names` array has been replaced with the |
||||
`jsTokens.matchToToken` function. The capturing groups of `jsTokens` are no |
||||
longer part of the public API; instead use said function. See this [gist] for |
||||
an example. (Backwards-incompatible change.) |
||||
- Changed: The empty string is now considered an “invalid” token, instead an |
||||
“empty” token (its own group). (Backwards-incompatible change.) |
||||
- Removed: component support. (Backwards-incompatible change.) |
||||
|
||||
[gist]: https://gist.github.com/lydell/be49dbf80c382c473004 |
||||
|
||||
|
||||
### Version 0.2.0 (2014-06-19) ### |
||||
|
||||
- Changed: Match ES6 function arrows (`=>`) as an operator, instead of its own |
||||
category (“functionArrow”), for simplicity. (Backwards-incompatible change.) |
||||
- Added: ES6 splats (`...`) are now matched as an operator (instead of three |
||||
punctuations). (Backwards-incompatible change.) |
||||
|
||||
|
||||
### Version 0.1.0 (2014-03-08) ### |
||||
|
||||
- Initial release. |
@ -0,0 +1,19 @@
@@ -0,0 +1,19 @@
|
||||
// Copyright 2014, 2015 Simon Lydell
|
||||
// X11 (“MIT”) Licensed. (See LICENSE.)
|
||||
|
||||
// This regex comes from regex.coffee, and is inserted here by generate-index.js
|
||||
// (run `npm run build`).
|
||||
module.exports = /((['"])(?:(?!\2|\\).|\\(?:\r\n|[\s\S]))*(\2)?|`(?:[^`\\$]|\\[\s\S]|\$(?!\{)|\$\{(?:[^{}]|\{[^}]*\}?)*\}?)*(`)?)|(\/\/.*)|(\/\*(?:[^*]|\*(?!\/))*(\*\/)?)|(\/(?!\*)(?:\[(?:(?![\]\\]).|\\.)*\]|(?![\/\]\\]).|\\.)+\/(?:(?!\s*(?:\b|[\u0080-\uFFFF$\\'"~({]|[+\-!](?!=)|\.?\d))|[gmiyu]{1,5}\b(?![\u0080-\uFFFF$\\]|\s*(?:[+\-*%&|^<>!=?({]|\/(?![\/*])))))|((?:0[xX][\da-fA-F]+|0[oO][0-7]+|0[bB][01]+|(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?))|((?!\d)(?:(?!\s)[$\w\u0080-\uFFFF]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]{1,6}\})+)|(--|\+\+|&&|\|\||=>|\.{3}|(?:[+\-*\/%&|^]|<{1,2}|>{1,3}|!=?|={1,2})=?|[?:~]|[;,.[\](){}])|(\s+)|(^$|[\s\S])/g |
||||
|
||||
module.exports.matchToToken = function(match) { |
||||
var token = {type: "invalid", value: match[0]} |
||||
if (match[ 1]) token.type = "string" , token.closed = !!(match[3] || match[4]) |
||||
else if (match[ 5]) token.type = "comment" |
||||
else if (match[ 6]) token.type = "comment", token.closed = !!match[7] |
||||
else if (match[ 8]) token.type = "regex" |
||||
else if (match[ 9]) token.type = "number" |
||||
else if (match[10]) token.type = "name" |
||||
else if (match[11]) token.type = "punctuator" |
||||
else if (match[12]) token.type = "whitespace" |
||||
return token |
||||
} |
@ -0,0 +1,61 @@
@@ -0,0 +1,61 @@
|
||||
{ |
||||
"name": "js-tokens", |
||||
"version": "1.0.2", |
||||
"author": { |
||||
"name": "Simon Lydell" |
||||
}, |
||||
"license": "MIT", |
||||
"description": "A regex that tokenizes JavaScript.", |
||||
"keywords": [ |
||||
"JavaScript", |
||||
"js", |
||||
"token", |
||||
"tokenize", |
||||
"regex" |
||||
], |
||||
"files": [ |
||||
"index.js" |
||||
], |
||||
"repository": { |
||||
"type": "git", |
||||
"url": "git+https://github.com/lydell/js-tokens.git" |
||||
}, |
||||
"scripts": { |
||||
"test": "mocha --ui tdd", |
||||
"esprima-compare": "node esprima-compare ./index.js everything.js/es5.js", |
||||
"build": "node generate-index.js", |
||||
"dev": "npm run build && npm test" |
||||
}, |
||||
"devDependencies": { |
||||
"coffee-script": "~1.9.3", |
||||
"esprima": "^2.3.0", |
||||
"everything.js": "^1.0.3", |
||||
"mocha": "^2.2.5" |
||||
}, |
||||
"gitHead": "90f0f0a217984625180414763234c923aeee4af5", |
||||
"bugs": { |
||||
"url": "https://github.com/lydell/js-tokens/issues" |
||||
}, |
||||
"homepage": "https://github.com/lydell/js-tokens#readme", |
||||
"_id": "js-tokens@1.0.2", |
||||
"_shasum": "8647f7e13f64ac15d9357a59a346c804d53b3efe", |
||||
"_from": "js-tokens@^1.0.1", |
||||
"_npmVersion": "2.14.7", |
||||
"_nodeVersion": "4.2.1", |
||||
"_npmUser": { |
||||
"name": "lydell", |
||||
"email": "simon.lydell@gmail.com" |
||||
}, |
||||
"dist": { |
||||
"shasum": "8647f7e13f64ac15d9357a59a346c804d53b3efe", |
||||
"tarball": "http://registry.npmjs.org/js-tokens/-/js-tokens-1.0.2.tgz" |
||||
}, |
||||
"maintainers": [ |
||||
{ |
||||
"name": "lydell", |
||||
"email": "simon.lydell@gmail.com" |
||||
} |
||||
], |
||||
"directories": {}, |
||||
"_resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-1.0.2.tgz" |
||||
} |
@ -0,0 +1,204 @@
@@ -0,0 +1,204 @@
|
||||
Overview [![Build Status](https://travis-ci.org/lydell/js-tokens.png?branch=master)](https://travis-ci.org/lydell/js-tokens) |
||||
======== |
||||
|
||||
A regex that tokenizes JavaScript. |
||||
|
||||
```js |
||||
var jsTokens = require("js-tokens") |
||||
|
||||
var jsString = "var foo=opts.foo;\n..." |
||||
|
||||
jsString.match(jsTokens) |
||||
// ["var", " ", "foo", "=", "opts", ".", "foo", ";", "\n", ...] |
||||
``` |
||||
|
||||
|
||||
Installation |
||||
============ |
||||
|
||||
- `npm install js-tokens` |
||||
|
||||
```js |
||||
var jsTokens = require("js-tokens") |
||||
``` |
||||
|
||||
|
||||
Usage |
||||
===== |
||||
|
||||
### `jsTokens` ### |
||||
|
||||
A regex with the `g` flag that matches JavaScript tokens. |
||||
|
||||
The regex _always_ matches, even invalid JavaScript and the empty string. |
||||
|
||||
The next match is always directly after the previous. |
||||
|
||||
### `var token = jsTokens.matchToToken(match)` ### |
||||
|
||||
Takes a `match` returned by `jsTokens.exec(string)`, and returns a `{type: |
||||
String, value: String}` object. The following types are available: |
||||
|
||||
- string |
||||
- comment |
||||
- regex |
||||
- number |
||||
- name |
||||
- punctuator |
||||
- whitespace |
||||
- invalid |
||||
|
||||
Multi-line comments and strings also have a `closed` property indicating if the |
||||
token was closed or not (see below). |
||||
|
||||
Comments and strings both come in several flavors. To distinguish them, check if |
||||
the token starts with `//`, `/*`, `'`, `"` or `` ` ``. |
||||
|
||||
Names are ECMAScript IdentifierNames, that is, including both identifiers and |
||||
keywords. You may use [is-keyword-js] to tell them apart. |
||||
|
||||
Whitespace includes both line terminators and other whitespace. |
||||
|
||||
For example usage, please see this [gist]. |
||||
|
||||
[is-keyword-js]: https://github.com/crissdev/is-keyword-js |
||||
[gist]: https://gist.github.com/lydell/be49dbf80c382c473004 |
||||
|
||||
|
||||
Invalid code handling |
||||
===================== |
||||
|
||||
Unterminated strings are still matched as strings. JavaScript strings cannot |
||||
contain (unescaped) newlines, so unterminated strings simply end at the end of |
||||
the line. Unterminated template strings can contain unescaped newlines, though, |
||||
so they go on to the end of input. |
||||
|
||||
Unterminated multi-line comments are also still matched as comments. They |
||||
simply go on to the end of the input. |
||||
|
||||
Unterminated regex literals are likely matched as division and whatever is |
||||
inside the regex. |
||||
|
||||
Invalid ASCII characters have their own capturing group. |
||||
|
||||
Invalid non-ASCII characters are treated as names, to simplify the matching of |
||||
names (except unicode spaces which are treated as whitespace). |
||||
|
||||
Regex literals may contain invalid regex syntax. They are still matched as |
||||
regex literals. They may also contain repeated regex flags, to keep the regex |
||||
simple. |
||||
|
||||
Strings may contain invalid escape sequences. |
||||
|
||||
|
||||
Limitations |
||||
=========== |
||||
|
||||
Tokenizing JavaScript using regexes—in fact, _one single regex_—won’t be |
||||
perfect. But that’s not the point either. |
||||
|
||||
You may compare jsTokens with [esprima] by using `esprima-compare.js`. |
||||
See `npm run esprima-compare`! |
||||
|
||||
[esprima]: http://esprima.org/ |
||||
|
||||
### Template string interpolation ### |
||||
|
||||
Template strings are matched as single tokens, from the starting `` ` `` to the |
||||
ending `` ` ``, including interpolations (whose tokens are not matched |
||||
individually). |
||||
|
||||
Matching template string interpolations requires recursive balancing of `{` and |
||||
`}`—something that JavaScript regexes cannot do. Only one level of nesting is |
||||
supported. |
||||
|
||||
### Division and regex literals collision ### |
||||
|
||||
Consider this example: |
||||
|
||||
```js |
||||
var g = 9.82 |
||||
var number = bar / 2/g |
||||
|
||||
var regex = / 2/g |
||||
``` |
||||
|
||||
A human can easily understand that in the `number` line we’re dealing with |
||||
division, and in the `regex` line we’re dealing with a regex literal. How come? |
||||
Because humans can look at the whole code to put the `/` characters in context. |
||||
A JavaScript regex cannot. It only sees forwards. |
||||
|
||||
When the `jsTokens` regex scans throught the above, it will see the following |
||||
at the end of both the `number` and `regex` rows: |
||||
|
||||
```js |
||||
/ 2/g |
||||
``` |
||||
|
||||
It is then impossible to know if that is a regex literal, or part of an |
||||
expression dealing with division. |
||||
|
||||
Here is a similar case: |
||||
|
||||
```js |
||||
foo /= 2/g |
||||
foo(/= 2/g) |
||||
``` |
||||
|
||||
The first line divides the `foo` variable with `2/g`. The second line calls the |
||||
`foo` function with the regex literal `/= 2/g`. Again, since `jsTokens` only |
||||
sees forwards, it cannot tell the two cases apart. |
||||
|
||||
There are some cases where we _can_ tell division and regex literals apart, |
||||
though. |
||||
|
||||
First off, we have the simple cases where there’s only one slash in the line: |
||||
|
||||
```js |
||||
var foo = 2/g |
||||
foo /= 2 |
||||
``` |
||||
|
||||
Regex literals cannot contain newlines, so the above cases are correctly |
||||
identified as division. Things are only problematic when there are more than |
||||
one non-comment slash in a single line. |
||||
|
||||
Secondly, not every character is a valid regex flag. |
||||
|
||||
```js |
||||
var number = bar / 2/e |
||||
``` |
||||
|
||||
The above example is also correctly identified as division, because `e` is not a |
||||
valid regex flag. I initially wanted to future-proof by allowing `[a-zA-Z]*` |
||||
(any letter) as flags, but it is not worth it since it increases the amount of |
||||
ambigous cases. So only the standard `g`, `m`, `i`, `y` and `u` flags are |
||||
allowed. This means that the above example will be identified as division as |
||||
long as you don’t rename the `e` variable to some permutation of `gmiyu` 1 to 5 |
||||
characters long. |
||||
|
||||
Lastly, we can look _forward_ for information. |
||||
|
||||
- If the token following what looks like a regex literal is not valid after a |
||||
regex literal, but is valid in a division expression, then the regex literal |
||||
is treated as division instead. For example, a flagless regex cannot be |
||||
followed by a string, number or name, but all of those three can be the |
||||
denominator of a division. |
||||
- Generally, if what looks like a regex literal is followed by an operator, the |
||||
regex literal is treated as division instead. This is because regexes are |
||||
seldomly used with operators (such as `+`, `*`, `&&` and `==`), but division |
||||
could likely be part of such an expression. |
||||
|
||||
Please consult the regex source and the test cases for precise information on |
||||
when regex or division is matched (should you need to know). In short, you |
||||
could sum it up as: |
||||
|
||||
If the end of a statement looks like a regex literal (even if it isn’t), it |
||||
will be treated as one. Otherwise it should work as expected (if you write sane |
||||
code). |
||||
|
||||
|
||||
License |
||||
======= |
||||
|
||||
[The X11 (“MIT”) License](LICENSE). |
@ -0,0 +1,60 @@
@@ -0,0 +1,60 @@
|
||||
{ |
||||
"name": "loose-envify", |
||||
"version": "1.1.0", |
||||
"description": "Fast (and loose) selective `process.env` replacer using js-tokens instead of an AST", |
||||
"keywords": [ |
||||
"environment", |
||||
"variables", |
||||
"browserify", |
||||
"browserify-transform", |
||||
"transform", |
||||
"source", |
||||
"configuration" |
||||
], |
||||
"homepage": "https://github.com/zertosh/loose-envify", |
||||
"license": "MIT", |
||||
"author": { |
||||
"name": "Andres Suarez", |
||||
"email": "zertosh@gmail.com" |
||||
}, |
||||
"repository": { |
||||
"type": "git", |
||||
"url": "git://github.com/zertosh/loose-envify.git" |
||||
}, |
||||
"scripts": { |
||||
"test": "tap test/*.js" |
||||
}, |
||||
"dependencies": { |
||||
"js-tokens": "^1.0.1" |
||||
}, |
||||
"devDependencies": { |
||||
"browserify": "^11.0.1", |
||||
"envify": "^3.4.0", |
||||
"tap": "^1.4.0" |
||||
}, |
||||
"gitHead": "f536f4fdbde317d77827ac8655c6c8473928b9e1", |
||||
"bugs": { |
||||
"url": "https://github.com/zertosh/loose-envify/issues" |
||||
}, |
||||
"_id": "loose-envify@1.1.0", |
||||
"_shasum": "527582d62cff4e04da3f9976c7110d3392ec7e0c", |
||||
"_from": "loose-envify@^1.0.0", |
||||
"_npmVersion": "2.14.4", |
||||
"_nodeVersion": "4.1.2", |
||||
"_npmUser": { |
||||
"name": "zertosh", |
||||
"email": "zertosh@gmail.com" |
||||
}, |
||||
"maintainers": [ |
||||
{ |
||||
"name": "zertosh", |
||||
"email": "zertosh@gmail.com" |
||||
} |
||||
], |
||||
"dist": { |
||||
"shasum": "527582d62cff4e04da3f9976c7110d3392ec7e0c", |
||||
"tarball": "http://registry.npmjs.org/loose-envify/-/loose-envify-1.1.0.tgz" |
||||
}, |
||||
"directories": {}, |
||||
"_resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.1.0.tgz" |
||||
} |
@ -0,0 +1,65 @@
@@ -0,0 +1,65 @@
|
||||
'use strict'; |
||||
|
||||
var jsTokens = require('js-tokens'); |
||||
|
||||
var processEnvRe = /\bprocess\.env\.[_$a-zA-Z][$\w]+\b/; |
||||
var spaceOrCommentRe = /^(?:\s|\/[/*])/; |
||||
|
||||
function replace(src, envs) { |
||||
if (!processEnvRe.test(src)) { |
||||
return src; |
||||
} |
||||
|
||||
var out = ''; |
||||
var purge = envs.some(function(env) { |
||||
return env._ && env._.indexOf('purge') !== -1; |
||||
}); |
||||
|
||||
jsTokens.lastIndex = 0 |
||||
var parts = src.match(jsTokens); |
||||
|
||||
for (var i = 0; i < parts.length; i++) { |
||||
if (parts[i ] === 'process' && |
||||
parts[i + 1] === '.' && |
||||
parts[i + 2] === 'env' && |
||||
parts[i + 3] === '.') { |
||||
var prevCodeToken = getAdjacentCodeToken(-1, parts, i); |
||||
var nextCodeToken = getAdjacentCodeToken(1, parts, i + 4); |
||||
var replacement = getReplacementString(envs, parts[i + 4], purge); |
||||
if (prevCodeToken !== '.' && |
||||
nextCodeToken !== '.' && |
||||
nextCodeToken !== '=' && |
||||
typeof replacement === 'string') { |
||||
out += replacement; |
||||
i += 4; |
||||
continue; |
||||
} |
||||
} |
||||
out += parts[i]; |
||||
} |
||||
|
||||
return out; |
||||
} |
||||
|
||||
function getAdjacentCodeToken(dir, parts, i) { |
||||
while (true) { |
||||
var part = parts[i += dir]; |
||||
if (!spaceOrCommentRe.test(part)) { |
||||
return part; |
||||
} |
||||
} |
||||
} |
||||
|
||||
function getReplacementString(envs, name, purge) { |
||||
for (var j = 0; j < envs.length; j++) { |
||||
var env = envs[j]; |
||||
if (typeof env[name] !== 'undefined') { |
||||
return JSON.stringify(env[name]); |
||||
} |
||||
} |
||||
if (purge) { |
||||
return 'undefined'; |
||||
} |
||||
} |
||||
|
||||
module.exports = replace; |
@ -0,0 +1,64 @@
@@ -0,0 +1,64 @@
|
||||
{ |
||||
"name": "invariant", |
||||
"version": "2.2.0", |
||||
"description": "invariant", |
||||
"keywords": [ |
||||
"test" |
||||
], |
||||
"license": "BSD-3-Clause", |
||||
"author": { |
||||
"name": "Andres Suarez", |
||||
"email": "zertosh@gmail.com" |
||||
}, |
||||
"files": [ |
||||
"invariant.js", |
||||
"browser.js" |
||||
], |
||||
"repository": { |
||||
"type": "git", |
||||
"url": "git+https://github.com/zertosh/invariant.git" |
||||
}, |
||||
"scripts": { |
||||
"test": "NODE_ENV=production tap test/*.js && NODE_ENV=development tap test/*.js" |
||||
}, |
||||
"dependencies": { |
||||
"loose-envify": "^1.0.0" |
||||
}, |
||||
"devDependencies": { |
||||
"browserify": "^11.0.1", |
||||
"tap": "^1.4.0" |
||||
}, |
||||
"main": "invariant.js", |
||||
"browser": "browser.js", |
||||
"browserify": { |
||||
"transform": [ |
||||
"loose-envify" |
||||
] |
||||
}, |
||||
"gitHead": "1660eab9f183183e71ef57a7765bb1121680fff9", |
||||
"bugs": { |
||||
"url": "https://github.com/zertosh/invariant/issues" |
||||
}, |
||||
"homepage": "https://github.com/zertosh/invariant#readme", |
||||
"_id": "invariant@2.2.0", |
||||
"_shasum": "c8d7e847366a49cc18b622f058a689d481e895f2", |
||||
"_from": "invariant@^2.0.0", |
||||
"_npmVersion": "2.14.7", |
||||
"_nodeVersion": "4.2.2", |
||||
"_npmUser": { |
||||
"name": "zertosh", |
||||
"email": "zertosh@gmail.com" |
||||
}, |
||||
"maintainers": [ |
||||
{ |
||||
"name": "zertosh", |
||||
"email": "zertosh@gmail.com" |
||||
} |
||||
], |
||||
"dist": { |
||||
"shasum": "c8d7e847366a49cc18b622f058a689d481e895f2", |
||||
"tarball": "http://registry.npmjs.org/invariant/-/invariant-2.2.0.tgz" |
||||
}, |
||||
"directories": {}, |
||||
"_resolved": "https://registry.npmjs.org/invariant/-/invariant-2.2.0.tgz" |
||||
} |
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT) |
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com) |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
of this software and associated documentation files (the "Software"), to deal |
||||
in the Software without restriction, including without limitation the rights |
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
copies of the Software, and to permit persons to whom the Software is |
||||
furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included in |
||||
all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||||
THE SOFTWARE. |
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue