Skip to content

Commit 41b526c

Browse files
authoredNov 4, 2016
Merge pull request #23 from kasunkv/add-guid
Add guid
2 parents dbef0cf + 6af511f commit 41b526c

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed
 

‎README.md

+15
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ console.log(profile);
4444
// Output
4545
/*
4646
{
47+
id: 'dc3800ea-0ae8-592a-bcd6-2012667c3ccc',
4748
fullName: 'Della Edwards',
4849
firstName: 'Della',
4950
lastName: 'Edwards',
@@ -71,6 +72,7 @@ console.log(profile);
7172
// Output
7273
/*
7374
{
75+
id: '137b6d33-51f2-5994-8250-92667dc5679d',
7476
fullName: 'Emerson Nicholson', // <= Fullname is MALE name.
7577
firstName: 'Emerson',
7678
lastName: 'Nicholson',
@@ -97,6 +99,7 @@ console.log(profile);
9799
// Output
98100
/*
99101
{
102+
id: 'b0443ec8-4a00-55aa-8f74-6af0b6c26e17',
100103
fullName: 'Julie Lewis', // <= Fullname is FEMALE name.
101104
firstName: 'Julie',
102105
lastName: 'Lewis',
@@ -271,6 +274,18 @@ console.log(twitterHandle);
271274
```
272275

273276

277+
### guid()
278+
Returns a random GUID.
279+
280+
```js
281+
var guid = randomProfile.guid();
282+
console.log(guid);
283+
284+
// Output
285+
// => b0443ec8-4a00-55aa-8f74-6af0b6c26e17
286+
```
287+
288+
274289
# Contributing
275290
All contributions from the GitHub community are welcome.
276291

‎src/index.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ function profile(gender) {
4040
profileGender = 'Female';
4141
}
4242

43+
profile.id = chance.guid();
4344
profile.fullName = fullName;
4445
profile.firstName = fullName.split(' ')[0];
4546
profile.lastName = fullName.split(' ')[1];
@@ -100,6 +101,10 @@ function state() {
100101
return chance.state();
101102
}
102103

104+
function guid() {
105+
return chance.guid();
106+
}
107+
103108
module.exports = {
104109
profile,
105110
name,
@@ -113,5 +118,6 @@ module.exports = {
113118
phone,
114119
email,
115120
twitter,
116-
ssn
121+
ssn,
122+
guid
117123
};

‎tests/index.test.js

+21
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ describe('Random Profile Generator', () => {
1515
expect(randomProfiles.profile()).to.be.a('object');
1616
});
1717

18+
it('Should contain `id` property, it should a string that is a GUID', () => {
19+
expect(randomProfiles.profile()).to.have.property('id');
20+
expect(randomProfiles.profile().id).to.be.a('string');
21+
expect(randomProfiles.profile().id).to.match(/[\da-zA-Z]{8}-([\da-zA-Z]{4}-){3}[\da-zA-Z]{12}/);
22+
});
23+
1824
it('Should contain `fullName` property, it should a string', () => {
1925
expect(randomProfiles.profile()).to.have.property('fullName');
2026
expect(randomProfiles.profile().fullName).to.be.a('string');
@@ -307,4 +313,19 @@ describe('Random Profile Generator', () => {
307313
expect(randomProfiles.ssn()).to.match(/(\d{3}[-]\d{2}[-]\d{4})/);
308314
});
309315
});
316+
317+
describe('Calling `guid', () => {
318+
it('Should be a function', () => {
319+
expect(randomProfiles.guid).to.be.a('function');
320+
});
321+
322+
it('Should return a string', () => {
323+
expect(randomProfiles.guid()).to.be.a('string');
324+
});
325+
326+
it('Should be a valid GUID', () => {
327+
expect(randomProfiles.guid()).to.match(/[\da-zA-Z]{8}-([\da-zA-Z]{4}-){3}[\da-zA-Z]{12}/);
328+
});
329+
});
330+
310331
});

0 commit comments

Comments
 (0)
Please sign in to comment.