Skip to content

Commit a49d90b

Browse files
committed
Update README.md
1 parent 939a415 commit a49d90b

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

README.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Tested against ~1.7 million postcodes on ONSPD.
3030
- [API Documentation](https://postcodejs.ideal-postcodes.dev)
3131
- [Try postcode.js on RunKit](https://npm.runkit.com/postcode)
3232
- [Postcode element definitions](#definitions)
33-
- [Caveat on postcode validation](#note-on-postcode-Validation)
33+
- [Notes](#notes)
3434
- [NPM Package](https://www.npmjs.com/package/postcode)
3535

3636
## Guides
@@ -58,7 +58,9 @@ isValid("AA1 1AB"); // => true
5858

5959
Pass a string to `parse`. This will return a valid or invalid postcode instance which can be easily destructured.
6060

61-
#### Valid Postcode `ValidPostcode`
61+
#### Valid Postcode
62+
63+
`ValidPostcode` type definition
6264

6365
```javascript
6466
import { parse } from "postcode";
@@ -76,7 +78,9 @@ const {
7678
} = parse("Sw1A 2aa");
7779
```
7880

79-
#### Invalid Postcode `InvalidPostcode`
81+
#### Invalid Postcode
82+
83+
`InvalidPostcode` type definition
8084

8185
```javascript
8286
const {
@@ -96,7 +100,7 @@ const {
96100

97101
The TypeScript compiler can infer if you have a valid postcode type from `parse` by checking the `valid` attribute
98102

99-
```
103+
```javascript
100104
import { parse } from "postcode";
101105

102106
const postcode = parse("SW1A 2AA");
@@ -130,12 +134,12 @@ If you're just after a single value, you can import a single method.
130134
#### Validation
131135

132136
```javascript
133-
isValid("Sw1A 2aa"); // => true
137+
isValid("Sw1A 2aa"); // => true
134138
```
135139

136140
#### Formatting
137141

138-
```
142+
```javascript
139143
import {
140144
toNormalised,
141145
toOutcode,
@@ -155,6 +159,7 @@ toDistrict("Sw1A 2aa"); // => "SW1"
155159
toSubDistrict("Sw1A 2aa"); // => "SW1A"
156160
toSector("Sw1A 2aa"); // => "SW1A 2"
157161
toUnit("Sw1A 2aa"); // => "AA"
162+
```
158163

159164
#### Extract & Replace
160165

@@ -163,8 +168,9 @@ toUnit("Sw1A 2aa"); // => "AA"
163168
```javascript
164169
const matches = match("The PM and her no.2 live at SW1A2aa and SW1A 2AB"); // => ["SW1A2aa", "SW1A 2AB"]
165170

166-
// Perform transformations like normalisation postcodes using `.map` and `toNormalised`
171+
// Perform transformations like normalisation using `.map` and `toNormalised`
167172
matches.map(toNormalised); // => ["SW1A 2AA", "SW1A 2AB"]
173+
matches.map(toOutcode); // => ["SW1A", "SW1A"]
168174

169175
// No matches yields empty array
170176
match("Some London outward codes are SW1A, NW1 and E1"); // => []
@@ -173,8 +179,9 @@ match("Some London outward codes are SW1A, NW1 and E1"); // => []
173179
`replace`. Replace postcodes in a body of text, returning the updated corpus and any matching postcodes
174180

175181
```javascript
176-
replace("The PM and her no.2 live at SW1A2AA and SW1A 2AB");
177-
// => { match: ["SW1A2AA", "SW1A 2AB"], result: "The PM and her no.2 live at and " }
182+
const { match, result } = replace("The PM and her no.2 live at SW1A2AA and SW1A 2AB");
183+
// => match: ["SW1A2AA", "SW1A 2AB"]
184+
// => result: "The PM and her no.2 live at and "
178185

179186
// Add custom replacement
180187
replace("The PM lives at SW1A 2AA", "Downing Street");

0 commit comments

Comments
 (0)