Skip to content

Commit

Permalink
1.7.0 - uuid support
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddentao committed Nov 22, 2018
1 parent b8f2394 commit 3959dc2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wearekickback/shared",
"version": "1.6.0",
"version": "1.7.0",
"description": "Shared utils between client and server",
"main": "dist/index.js",
"module": "src/index.js",
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export * from './strings'
export * from './legal'
export * from './participants'
export * from './social'
export * from './uuid'
15 changes: 15 additions & 0 deletions src/uuid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { isUUID as checkIsUUID } from 'validator'

export const isUUID = str => {
if (typeof str !== 'string') {
return false
}

return checkIsUUID(str)
}

export const assertUUID = str => {
if (!isUUID(str)) {
throw new Error(`Invalid UUID: ${str}`)
}
}
29 changes: 29 additions & 0 deletions src/uuid.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {
isUUID,
assertUUID,
} from './'



describe('uuid', () => {
it('checks and assertions', () => {
const tests = [
[ 1024, false ],
[ '', false ],
[ 'str', false ],
[ 'a21c09cc-f1db-4086-9bd7-e568e23fe160', true ],
]

expect.assertions(tests.length * 2)

tests.forEach(([ input, expected ]) => {
expect(isUUID(input)).toEqual(expected)

if (expected) {
expect(() => assertUUID(input)).not.toThrow()
} else {
expect(() => assertUUID(input)).toThrow()
}
})
})
})

0 comments on commit 3959dc2

Please sign in to comment.