-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathindex.js
More file actions
53 lines (45 loc) · 1.7 KB
/
index.js
File metadata and controls
53 lines (45 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// ES Modules example for Node.js
import {
findCities,
findPostcode,
getCities,
getPostcodes,
getRandomCity,
getRandomPostcode,
getRandomState,
getStates,
searchAll
} from 'malaysia-postcodes';
console.log('🇲🇾 Malaysia Postcodes - Node.js ES Modules Example\n');
// Get all states
console.log('📍 All states:');
const states = getStates();
console.log(states.slice(0, 5), '...\n'); // Show first 5
// Get cities for a specific state
console.log('🏙️ Cities in Selangor:');
const selangorCities = getCities('Selangor');
console.log(selangorCities.slice(0, 5), '...\n'); // Show first 5
// Find a specific city
console.log('🔍 Find cities containing "Shah":');
const shahCities = findCities('Shah', false);
console.log(shahCities, '\n');
// Get postcodes for a specific area
console.log('📮 Postcodes for Shah Alam, Selangor:');
const shahAlamPostcodes = getPostcodes('Selangor', 'Shah Alam');
console.log(shahAlamPostcodes.slice(0, 5), '...\n'); // Show first 5
// Find location by postcode
console.log('📍 Location for postcode 40170:');
const location = findPostcode('40170');
console.log(location, '\n');
// Universal search
console.log('🔎 Universal search for "Kuala":');
const searchResults = searchAll('Kuala');
console.log('States found:', searchResults.states);
console.log('Cities found:', searchResults.cities.length, 'cities');
console.log('Postcodes found:', searchResults.postcodes.length, 'postcodes\n');
// Random data examples
console.log('🎲 Random data examples:');
console.log('Random postcode:', getRandomPostcode());
console.log('Random city:', getRandomCity());
console.log('Random city in Penang:', getRandomCity('Penang'));
console.log('Random state:', getRandomState());