Skip to content

Commit 09b21dd

Browse files
feat(util): add more robust library
we now use the most popular uuid library out there, which is also environment aware. This means the lib provides a browser field in package.json which will be used by bundlers to use the correct implementation to generate secure Random numbers. (using the native crypto implementation if available falling back to Math.random)
1 parent 85f098d commit 09b21dd

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

package-lock.json

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

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,14 @@
7171
"tslint": "^5.11.0",
7272
"tslint-config-prettier": "^1.16.0",
7373
"typedoc": "^0.13.0",
74-
"typescript": "^3.1.6"
74+
"typescript": "^3.1.6",
75+
"uuid": "^3.3.2"
7576
},
7677
"peerDependencies": {
7778
"aws-sdk": "^2.286.1",
7879
"lodash": "^4.17.10",
7980
"reflect-metadata": "^0.1.12",
80-
"rxjs": "^6.0.0"
81+
"rxjs": "^6.0.0",
82+
"uuid": "^3.3.2"
8183
}
8284
}

src/mapper/util.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { isNumber, isString } from 'lodash'
2+
import {v4} from 'uuid'
23
import { AttributeCollectionType, AttributeType } from './type/attribute-type.type'
34
import { AttributeValueType } from './type/attribute-value-type.type'
45
import { Attribute } from './type/attribute.type'
@@ -252,12 +253,6 @@ export function typeName(type: any): 'Null' | 'Undefined' | string {
252253
throw new Error(`was not able to resolve type name for type ${type}`)
253254
}
254255

255-
// FIXME UUID replace with a more bullet proof implementation node uuid module requires crypto, need to figure out how to use it with browser
256256
export function uuidv4() {
257-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
258-
// tslint:disable
259-
let r = (Math.random() * 16) | 0,
260-
v = c == 'x' ? r : (r & 0x3) | 0x8
261-
return v.toString(16)
262-
})
257+
return v4()
263258
}

0 commit comments

Comments
 (0)