Skip to content

Commit 0dda59f

Browse files
committed
Merge pull request #544 from ParsePlatform/nlutsenko.flow
Add ability to use Flow type checking.
2 parents bd54878 + b774c56 commit 0dda59f

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

.babelrc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
2-
"presets": [
3-
"es2015"
4-
]
2+
"plugins": [
3+
"transform-flow-strip-types"
4+
],
5+
"presets": [
6+
"es2015",
7+
"stage-0"
8+
]
59
}

.flowconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[ignore]
2+
.*/node_modules/
3+
.*/lib/
4+
5+
[include]
6+
7+
[libs]
8+
9+
[options]

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,14 @@
2929
"babel-cli": "^6.5.1",
3030
"babel-core": "^6.5.1",
3131
"babel-istanbul": "^0.6.0",
32+
"babel-plugin-transform-flow-strip-types": "^6.5.0",
3233
"babel-preset-es2015": "^6.5.0",
34+
"babel-preset-stage-0": "^6.5.0",
3335
"babel-register": "^6.5.1",
3436
"codecov": "^1.0.1",
3537
"cross-env": "^1.0.7",
3638
"deep-diff": "^0.3.3",
39+
"flow-bin": "^0.22.0",
3740
"gaze": "^0.5.2",
3841
"jasmine": "^2.3.2",
3942
"mongodb-runner": "^3.1.15",

src/cryptoUtils.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
/* @flow */
2+
13
import { randomBytes } from 'crypto';
24

35
// Returns a new random hex string of the given even size.
4-
export function randomHexString(size) {
6+
export function randomHexString(size: number): string {
57
if (size === 0) {
68
throw new Error('Zero-length randomHexString is useless.');
79
}
@@ -17,28 +19,28 @@ export function randomHexString(size) {
1719
// because chars length of 62 doesn't divide the number of all bytes
1820
// (256) evenly. Such bias is acceptable for most cases when the output
1921
// length is long enough and doesn't need to be uniform.
20-
export function randomString(size) {
22+
export function randomString(size: number): string {
2123
if (size === 0) {
2224
throw new Error('Zero-length randomString is useless.');
2325
}
24-
var chars = ('ABCDEFGHIJKLMNOPQRSTUVWXYZ' +
26+
let chars = ('ABCDEFGHIJKLMNOPQRSTUVWXYZ' +
2527
'abcdefghijklmnopqrstuvwxyz' +
2628
'0123456789');
27-
var objectId = '';
28-
var bytes = randomBytes(size);
29-
for (var i = 0; i < bytes.length; ++i) {
29+
let objectId = '';
30+
let bytes = randomBytes(size);
31+
for (let i = 0; i < bytes.length; ++i) {
3032
objectId += chars[bytes.readUInt8(i) % chars.length];
3133
}
3234
return objectId;
3335
}
3436

3537
// Returns a new random alphanumeric string suitable for object ID.
36-
export function newObjectId() {
38+
export function newObjectId(): string {
3739
//TODO: increase length to better protect against collisions.
3840
return randomString(10);
3941
}
4042

4143
// Returns a new random hex string suitable for secure tokens.
42-
export function newToken() {
44+
export function newToken(): string {
4345
return randomHexString(32);
4446
}

0 commit comments

Comments
 (0)