Skip to content

Commit 67badb0

Browse files
authored
Merge pull request #2 from Runninghill/feature/documentation
Create documentation.
2 parents fc4e323 + 04438b0 commit 67badb0

File tree

5 files changed

+63
-21
lines changed

5 files changed

+63
-21
lines changed

CONTRIBUTOR_README.md

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
![Runninghill Logo](./docs/runninghill.png "Runninghill")
2+
13
# Angular South African Form Validators
24

35
A set of South African specific validators for Angular forms.
46

5-
# Getting Started
7+
# Getting Started🏁
68

79
1. Clone the repo.
810

@@ -14,34 +16,26 @@ A set of South African specific validators for Angular forms.
1416

1517
3. Make your changes.
1618

17-
4. Ensure that your changes are of good quality and comply with our [Coding Standards](#coding-standards).
19+
4. Ensure that your changes are of good quality.
1820

1921
5. Commit your changes and submit a PR to merge your changes into `main`.
2022

21-
# NPM Scripts
23+
# NPM Scripts📜
2224

2325
To check eslint, run command `npm run lint`.
2426

2527
To check unit tests, run command `npm run test`.
2628

27-
# Contribute
29+
# Contribute🌳
2830

2931
Ensure you work out of the project itself (`projects/rh-rsa-form-validators`) and not the Angular workspace
3032

3133
Always make the code better, if you see errors, please fix them.
3234

3335
Add tests and try to move the code coverage up to 90%.
3436

35-
Update the [usage documentation](/projects/rh-rsa-form-validators/README.md).
37+
Update the [usage documentation](https://github.com/Runninghill/rh-angular-rsa-form-validators/blob/main/projects/rh-rsa-form-validators/README.md).
3638

3739
Bump the version number according to [semantic versioning](https://semver.org/#semantic-versioning-200).
3840

39-
Adhere to the [Coding Standards](#coding-standards).
40-
4141
Only the classes and models exported in `public-api.ts` will be exposed through the package.
42-
43-
# Coding Standards
44-
45-
TODO: Define coding standards
46-
47-
- Form validators should not make the form control required.

docs/runninghill.png

14.6 KB
Loading

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"lint": "ng lint"
1010
},
1111
"private": true,
12+
"readme": "CONTRIBUTOR_README",
1213
"dependencies": {
1314
"@angular/animations": "~10.2.0",
1415
"@angular/common": "~10.2.0",
Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,68 @@
1+
![Runninghill Logo](../../docs/runninghill.png "Runninghill")
2+
13
# Angular South African Form Validators
24

35
A set of South African specific validators for Angular forms.
46

5-
TODO: Add the Runninghill and Angular logos as well as some emojis
6-
7-
# Getting Started
7+
# Getting Started🏁
88

99
If you plan on contributing to the package please read the contributor readme.
1010

1111
1. Run `npm install rh-angular-rsa-form-validators` in your Angular project.
1212

1313
2. Import and use the exposed classes to validate your Angular form controls.
1414

15-
# Usage
15+
# Usage💡
16+
17+
To begin validating your South African specific form fields, start by importing
18+
the _RsaFormValidators_ class.
19+
20+
```Javascript
21+
import { RsaFormValidator } from 'rh-angular-rsa-form-validators'
22+
```
23+
24+
Add the appropriate validator to your form control(s).
25+
26+
```Javascript
27+
// When creating your form
28+
this.form = this.formBuilder.group({
29+
name: ['', Validators.required],
30+
mobileNumber: ['', [Validators.required, RsaFormValidator.phoneNumber(false, true)]],
31+
workNumber: ['']
32+
})
33+
34+
// After the form is already created
35+
this.form.controls['workNumber'].setValidators([RsaFormValidators.phoneNumber(false, true)])
36+
```
37+
38+
To determine if the form control passed the validation, check the errors object on the form control.
39+
40+
RsaFormValidator error objects on form controls will always be the name of the validator,
41+
prefixed with 'rsa' eg; for the rsa phone number validator, the error object is `rsaPhoneNumber`
42+
(rsa + phoneNumber = rsaPhoneNumber)
43+
44+
```Javascript
45+
if (this.form.controls['mobileNumber'].errors.rsaPhoneNumber)
46+
errorMessage = 'Mobile number must be a valid South African phone number.'
47+
```
48+
49+
# API Reference📖
50+
51+
### RsaFormValidator
52+
53+
Contains form control validators used to validate South African specific form fields.
54+
55+
[_source code_](https://github.com/Runninghill/rh-angular-rsa-form-validators/blob/main/projects/rh-rsa-form-validators/src/lib/validators/rsa-form-validator.ts)
56+
57+
#### Methods
58+
59+
##### phoneNumber(allowCountryCode, allowSpaces)
1660

17-
TODO: Fill out usage section
61+
Returns a validator which determines if a form control is a valid South African phone number.
1862

19-
# API Reference
63+
Parameters
2064

21-
TODO: Fill out api reference section
65+
|Name|Type|Description|Default|
66+
|----|----|-----------|-------|
67+
|allowCountryCode|boolean|determines if the phone number is allowed to contain the South African country code (+27)|true|
68+
|allowSpaces|boolean|determines if a phone number is allowed to contain spaces|true|

projects/rh-rsa-form-validators/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@
4040
"bugs": {
4141
"url": "https://github.com/Runninghill/rh-angular-rsa-form-validators/issues"
4242
},
43-
"homepage": "https://github.com/Runninghill/rh-angular-rsa-form-validators#readme"
43+
"homepage": "https://github.com/Runninghill/rh-angular-rsa-form-validators/projects/rh-rsa-form-validators#readme"
4444
}

0 commit comments

Comments
 (0)