You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| AA9 9AA | AA9 | 9AA | AA | AA9 |`null`| AA9 9 | AA |
106
123
| AA99 9AA | AA99 | 9AA | AA | AA99 |`null`| AA99 9 | AA |
107
124
108
-
### Static Methods
125
+
### Exported Methods
126
+
127
+
If you're just after a single value, you can import a single method.
128
+
129
+
```javascript
130
+
# Validation
131
+
isValid("Sw1A 2aa"); // => true
132
+
133
+
# Formatting
134
+
toNormalised("Sw1A 2aa"); // => "SW1A 2AA"
135
+
toOutcode("Sw1A 2aa"); // => "SW1A"
136
+
toIncode("Sw1A 2aa"); // => "2AA"
137
+
toArea("Sw1A 2aa"); // => "AA"
138
+
toDistrict("Sw1A 2aa"); // => "SW1"
139
+
toSubDistrict("Sw1A 2aa"); // => "SW1A"
140
+
toSector("Sw1A 2aa"); // => "SW1A 2"
141
+
toUnit("Sw1A 2aa"); // => "AA"
142
+
143
+
# Replacement
144
+
match("The PM and her no.2 live at SW1A2AA and SW1A 2AB"); // => ["SW1A2AA", "SW1A 2AB"]
145
+
replace("The PM and her no.2 live at SW1A2AA and SW1A 2AB"); // => { match: ["SW1A2AA", "SW1A 2AB"], result: "The PM and her no.2 live at and " }
146
+
```
147
+
148
+
## Version 5.0.0
149
+
150
+
5.0.0 brings changes which allows for better treeshaking and interopability with ES Modules. It also deprecates legacy class based APIs in favour of single purpose methods.
109
151
110
-
If you're just after a single value, you would be better served by calling a static method on `Postcode`.
152
+
### Breaking Changes
111
153
154
+
-`postcode` no longer exports a class. Legacy `new Postcode()` functionality has been removed. Methods attached to `Postcode` are all available as named exports.
155
+
-`postcode` no longer uses default exports. All exports are named. E.g.
In many cases, migration can be achieved by changing `import Postcode from "postcode"` to `import * as Postcode from "postcode"`, however this gives up treeshaking advantages.
167
+
168
+
### New Features
126
169
127
-
The legacy object based API is documented in [LEGACY.md](LEGACY.md)
170
+
-`postcode` now exports a ES Module build
171
+
- Exports regular expressions
172
+
-`match` accepts a string and returns all valid postcodes
173
+
-`replace` accepts a string and replaces valid postcodes with an optional second argument. Default replacement text is empty string `""`
0 commit comments