Skip to content

Commit b7fe640

Browse files
committed
Merge branch 'release/v1.0.2'
2 parents 77b3962 + 31a7c43 commit b7fe640

File tree

11 files changed

+265
-68
lines changed

11 files changed

+265
-68
lines changed

test/index.html renamed to dist/browser/index.html

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
<link rel="stylesheet" type="text/css" href="https://raw.githubusercontent.com/twbs/bootstrap/master/dist/css/bootstrap.min.css" />
77
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.1.0/styles/default.min.css">
88
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.1.0/highlight.min.js"></script>
9-
<script type="application/javascript" src="browser/toplevel/eid.min.js"></script>
9+
<script type="application/javascript" src="toplevel/eid.min.js"></script>
1010
<style type="text/css">
1111
@import url(https://fonts.googleapis.com/css?family=PT+Sans|Source+Code+Pro);
1212
body {
1313
font-family: 'PT Sans', sans-serif;
14-
font-size: 1.3em;
14+
font-size: 1em;
1515
padding: 1em;
1616
}
1717
pre, code {
@@ -38,6 +38,7 @@ <h1>ExceptionID.js - showcase</h1>
3838

3939
<h3>Code:</h3>
4040
<pre><code class="javascript" id="code">
41+
var EidRuntimeException = Eid.exceptions.EidRuntimeException;
4142
try {
4243
// Example entity objects
4344
var users = [];
@@ -61,9 +62,11 @@ <h3>Code:</h3>
6162
EidPreconditions.checkState(false, '20160111:224215', 'A extra message');
6263
} catch(e) {
6364
// Top level of your application
64-
log.error(e.toString() + ' - ' + e.stack);
65-
// or better save your exceptions!
66-
logGateway.put(e, {eid: e.eid});
65+
log.error(e.stack);
66+
if (e instanceof EidRuntimeException) {
67+
// or better save your exceptions!
68+
logGateway.put(e, inspectable({eid: e.eid}));
69+
}
6770
}
6871
</code></pre>
6972
<h3>Console:</h3>
@@ -93,9 +96,21 @@ <h3>Console:</h3>
9396
logentry('ERROR', message);
9497
}
9598
};
99+
var inspectable = function(obj) {
100+
obj.toString = function() {
101+
var parts = [];
102+
for (var k in obj) {
103+
if (obj.hasOwnProperty(k) && k !== 'toString') {
104+
parts.push(k.toString() + ': ' + obj[k].toString());
105+
}
106+
}
107+
return '{ ' + parts.join(', ') + ' }';
108+
};
109+
return obj;
110+
};
96111
var logGateway = {
97112
put: function(ex, extra) {
98-
logentry('INFO', 'LogzGetewayFake.io sucessfully PUT an exception: `' + ex.toString() + '` with extra data of: `' + JSON.stringify(extra) + '`');
113+
logentry('INFO', 'FakeLogz.io PUT exception: `' + ex.toString() + '`, payload: `' + extra.toString() + '`');
99114
}
100115
};
101116
var code = document.getElementById('code').textContent;

dist/browser/toplevel/eid.js

Lines changed: 92 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/browser/toplevel/eid.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/browser/toplevel/eid.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gulp/serve.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
var serve = require('gulp-serve');
55
var config = require('./config');
66

7-
module.exports = serve([ config.test, config.dist ]);
7+
module.exports = serve(config.dist + '/browser');

gulp/tests.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ module.exports = {
4444
var src = prependToAll('..', config.sources);
4545
var stream = gulp.src(testSrc, { read: false })
4646
.pipe(cover.instrument({
47-
pattern: src,
48-
debugDirectory: 'debug'
47+
pattern: src
4948
}))
5049
.pipe(mocha())
5150
.pipe(cover.gather());

lib/eid/eid.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,25 +109,28 @@ function MathRandom() {
109109
var LONG_MAX = Math.pow(2, 53) - 1;
110110
var LONG_MIN = -1 * Math.pow(2, 53);
111111
this.nextLong = function() {
112-
return random(LONG_MIN, LONG_MAX);
112+
return this.nextNumber(LONG_MIN, LONG_MAX);
113113
};
114114
this.nextInt = function(max) {
115-
return random(0, max);
115+
return this.nextNumber(0, max);
116116
};
117-
var random = function(min, max) {
117+
this.nextNumber = function(min, max) {
118118
return Math.floor(Math.random() * (max - min + 1)) + min;
119119
};
120120
}
121121

122122
function StdUniqIdGenerator() {
123123
var BASE36 = 36;
124124
var INTEGER_MAX_VALUE = Math.pow(2, 31);
125+
var MIN_6_CHAR_HASH = 60466177; // for '100001' in base64
125126
var generator = new MathRandom();
127+
var padding = generator.nextNumber(MIN_6_CHAR_HASH, INTEGER_MAX_VALUE).toString(BASE36);
126128
this.generateUniqId = function() {
127129
var first = Math.abs(generator.nextLong() + 1);
128130
var second = Math.abs(generator.nextInt(INTEGER_MAX_VALUE));
129131
var calc = first + second;
130-
return (Math.abs(calc) % INTEGER_MAX_VALUE).toString(BASE36);
132+
var hash = (Math.abs(calc) % INTEGER_MAX_VALUE).toString(BASE36);
133+
return String(padding + hash).slice(-6); // pad output string to six chars using random padding
131134
};
132135
}
133136

0 commit comments

Comments
 (0)