Skip to content

Commit e42929f

Browse files
committed
docs: improve READMEs
1 parent 2491f32 commit e42929f

File tree

3 files changed

+107
-14
lines changed

3 files changed

+107
-14
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ This a monorepo of OBOS' open source frontend modules.
55

66
## Packages
77

8-
* [format](./packages/format)
9-
* [validation](./packages/validation)
8+
* [format](./packages/format) - A collection of formatting methods for 🇳🇴 and 🇸🇪.
9+
* [validation](./packages/validation) - A collection of validation methods for 🇳🇴 and 🇸🇪.
1010

1111
## Contributing
1212

@@ -34,4 +34,4 @@ pnpm build
3434

3535
### Releases and changelogs
3636

37-
We use an automated release process based on [changesets](https://github.com/changesets/changesets) and a [Github action](./.github/workflows/release.yml) to version, release and publish the packages. Meaningful changes should be documented by running pnpm changeset and be a part of the pull request. Remember to follow semver.
37+
We use an automated release process based on [changesets](https://github.com/changesets/changesets) and a [Github action](./.github/workflows/release.yml) to version, release and publish the packages. Meaningful changes should be documented by running `pnpm changeset` and be a part of the pull request. Remember to follow semver.

packages/validation/README.md

Lines changed: 103 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,13 @@ validateOrganizationNumber('000') // => false
3636

3737
## Strictness and formatting characters
3838

39-
The methods are "strict" by default, meaning no formatting characters in the input is allowed.
40-
This is preferrable, for instance when doing server-side validation, where the input is often expected to be a "clean" value.
39+
The methods are "strict" by default, meaning no formatting characters in the input is allowed. This even applies to separators such as in Swedish national identity numbers.
4140

42-
If you want to allow formatting characters in the input, you can pass `allowFormatting: true` in the options object to the method.
41+
When doing server-side validation, for instance, before insertion into a database, strictness is often preferrable. The value is often expected to be a "clean" value in standardized format.
42+
43+
On the client side, formatting characters could be allowed, as they are more user-friendly, for instance, allowing the user to input their phone number in their preferred format.
44+
45+
If you want to allow formatting characters in the value, you can pass `allowFormatting: true` in the options object to the method.
4346

4447

4548
```js
@@ -56,13 +59,103 @@ validateOrganizationNumber('937 052 766', { allowFormatting: true }) // true;
5659

5760
## Methods
5861

59-
* validateNationalIdentityNumber
60-
* validatePostalCode
61-
* validatePhoneNumber
62-
* supports mobileOnly option
63-
* validateOrganizationNumber
64-
* Check digit verification is currently only implemented for Norwegian organization numbers. For Swedish organiation numbers, we only check the length of the input. PRs are welcome to fix this.
65-
* validateObosMembershipNumber
62+
### validateNationalIdentityNumber()
63+
64+
Validates that the value is a valid national identity number.
65+
66+
Validation is done for the both checksum and if the date is a valid date.
67+
It accepts both fødselsnummer and d-nummer for Norway, and personnummer and samordningsnummer for Sweden.
68+
69+
By default, both the short (10 digit) and long (12 digit) format is allowed for Sweden. You can use the `format` option to specify the format to validate.
70+
71+
```js
72+
// 🇳🇴 example
73+
import { validateNationalIdenityNumber } from '@obosbbl/validation/no';
74+
validateNationalIdenityNumber('DDMMYYXXXX') // => true
75+
76+
// 🇸🇪 example
77+
import { validateNationalIdentityNumber } from "@obosbbl/validation/se";
78+
// short
79+
validatePersonalIdentityNumber('YYMMDDXXXX') // => true
80+
// long
81+
validateOrganizationNumber('YYYYMMDDXXXX'') // => true
82+
83+
// separator (formatting) is important for Swedish national identity numbers
84+
validatePersonalIdentityNumber('YYMMDD-XXXX', { allowFormatting: true }) // => true
85+
validateOrganizationNumber('YYYY-MMDDXXXX', { allowFormatting: true })) // => true
86+
87+
// specific format
88+
validatePersonalIdentityNumber('YYMMDDXXXX', { format: 'short' }) // => true
89+
validatePersonalIdentityNumber('YYMMDDXXXX', { format: 'long' }) // => false
90+
91+
validatePersonalIdentityNumber('YYYYMMDDXXXX', { format: 'long' }) // => true
92+
```
93+
94+
> [!TIP]
95+
> Did you know that you cannot assume that the date in the number is person's date of birth? See [Skatteetaten fødselsnummer](https://www.skatteetaten.no/person/folkeregister/identitetsnummer/fodselsnummer/).
96+
97+
### validatePhoneNumber()
98+
99+
Validates that the value is a valid phone number. Specify `mobileOnly` to only allow mobile numbers.
100+
101+
```js
102+
// 🇳🇴 example
103+
import { validatePhoneNumber } from '@obosbbl/validation/no';
104+
validatePhoneNumber('00000000') // => true
105+
validatePhoneNumber('90000000', { mobileOnly: true }) // => true
106+
107+
// 🇸🇪 example
108+
import { validatePhoneNumber } from '@obosbbl/validation/se';
109+
validatePhoneNumber('00000000') // => true
110+
validatePhoneNumber('000000000') // => true
111+
validatePhoneNumber('0000000000') // => true
112+
validatePhoneNumber('0700000000', { mobileOnly: true }) // => true
113+
```
114+
115+
### validatePostalCode()
116+
117+
Validates that the value is a valid postal code.
118+
119+
```js
120+
// 🇳🇴 example
121+
import { validatePostalCode } from '@obosbbl/validation/no';
122+
validatePostalCode('0000') // => true
123+
124+
// 🇸🇪 example
125+
import { validatePostalCode } from '@obosbbl/validation/se';
126+
validatePostalCode('00000') // => true
127+
```
128+
129+
### validateOrganizationNumber()
130+
131+
Validates that the value is a valid organization number. Validates the checksum of the number.
132+
133+
```js
134+
// 🇳🇴 example
135+
import { validateOrganizationNumber } from '@obosbbl/validation/no';
136+
validateOrganizationNumber('937052766') // => true
137+
138+
// 🇸🇪 example
139+
import { validateOrganizationNumber } from '@obosbbl/validation/se';
140+
validateOrganizationNumber('5592221054') // => true
141+
```
142+
143+
### validateObosMembershipNumber()
144+
145+
Validates that the value is a valid OBOS membership number.
146+
147+
> [!NOTE]
148+
> There is no difference between a Norwegian and Swedish OBOS membership number. The method in use is in fact the same one, re-exported for the different locales.
149+
150+
```js
151+
// 🇳🇴 example
152+
import { validateObosMembershipNumber } from '@obosbbl/validation/no';
153+
validateObosMembershipNumber('0000000') // => true
154+
155+
// 🇸🇪 example
156+
import { validateObosMembershipNumber } from '@obosbbl/validation/se';
157+
validateObosMembershipNumber('0000000') // => true
158+
```
66159

67160

68161
## Example usage with Zod

packages/validation/src/no.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ type OrganizationNumberOptions = ValidatorOptions;
7171
*/
7272
export function validateOrganizationNumber(
7373
value: string,
74-
options: PhoneNumberOptions = {},
74+
options: OrganizationNumberOptions = {},
7575
): boolean {
7676
if (options.allowFormatting) {
7777
// biome-ignore lint/style/noParameterAssign:

0 commit comments

Comments
 (0)