Skip to content

Commit 456bc59

Browse files
authored
Merge pull request #14 from cloudgraphdev/feature/add-generate-unique-id-util
feat: Added util function to generate unique ids
2 parents 71e1d19 + 8d8fc11 commit 456bc59

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
intersectStringArrays,
3838
getKeyByValue,
3939
toCamel,
40+
generateUniqueId,
4041
} from './utils'
4142
import {
4243
mergeSchemas,
@@ -55,6 +56,7 @@ export {
5556
getSchemaFromFolder,
5657
generateSchemaMapDynamically,
5758
generateEntityMutations,
59+
generateUniqueId,
5860
}
5961

6062
export { PluginModule, PluginType, Result, pluginMap }

src/utils/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import crypto from 'crypto'
12
import camelCase from 'lodash/camelCase'
23

34
export const toCamel = (o: any): any => {
@@ -67,3 +68,11 @@ export const sortResourcesDependencies = (
6768
}
6869
return 0
6970
})
71+
72+
/**
73+
* Create an unique hash identifier
74+
* @param entity entire entity to create identifier
75+
* @returns unique identifier
76+
*/
77+
export const generateUniqueId = (entity: any): string =>
78+
crypto.createHash('md5').update(JSON.stringify(entity)).digest('hex')

0 commit comments

Comments
 (0)