Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
idn-area-data
Advanced tools
Provides the administrative areas data of Indonesia (province, regency, district, village, and island) based on the latest official sources.
If you are upgrading from version 2 to version 3, please read the upgrade guide.
npm install --save idn-area-data
Use this for yarn user :
yarn add idn-area-data
Import the package into your project as shown below.
[!NOTE] The following code examples use top level await to run the asynchronous function. You also can use IIFE,
.then()
, or run it inside anontherasync
function instead.
Import specific function only :
import { getProvinces } from 'idn-area-data';
const provinces = await getProvinces();
Import the entire module :
import * as IdnArea from 'idn-area-data';
const provinces = await IdnArea.getProvinces();
Since version 3.0.0, idn-area-data is published as ECMAScript Module (ESM). So that, for CommonJS user, you need to import it using dynamic import like this :
const { getProvinces } = await import('idn-area-data');
const provinces = await getProvinces();
Then, you can get the data you need using these methods below.
getProvinces()
Asynchronous function to get all provinces data.
import { getProvinces } from 'idn-area-data';
const provinces = await getProvinces();
console.log(provinces);
/*
[
{
code: '11',
name: 'ACEH',
},
...
]
*/
getRegencies(?options)
Asynchronous function to get all regencies data
import { getRegencies } from 'idn-area-data';
const regencies = await getRegencies();
console.log(regencies);
/*
[
{
code: '11.01',
name: 'KABUPATEN ACEH SELATAN',
province_code: '11',
},
...
]
*/
If options.transform
argument is true
, the property naming will be changed from snake_case
into camelCase
.
const regencies = await getRegencies({ transform: true });
/*
[
{
code: '11.01',
name: 'KABUPATEN ACEH SELATAN',
provinceCode: '11',
},
...
]
*/
getDistricts(?options)
Asynchronous function to get all districts data.
import { getDistricts } from 'idn-area-data';
const districts = await getDistricts();
console.log(districts);
/*
[
{
code: '11.01.01',
name: 'Bakongan',
regency_code: '11.01',
},
...
]
*/
If options.transform
argument is true
, the property naming will be changed from snake_case
into camelCase
.
const districts = await getDistricts({ transform: true });
/*
[
{
code: '11.01.01',
name: 'Bakongan',
regencyCode: '11.01',
},
...
]
*/
getVillages(?options)
Asynchronous function to get all villages data.
import { getVillages } from 'idn-area-data';
const villages = await getVillages();
console.log(villages);
/*
[
{
code: '11.01.01.2001',
district_code: '11.01.01',
name: 'Keude Bakongan',
},
...
]
*/
If options.transform
argument is true
, the property naming will be changed from snake_case
into camelCase
.
const villages = await getVillages({ transform: true });
/*
[
{
code: '11.01.01.2001',
districtCode: '11.01.01',
name: 'Keude Bakongan',
},
...
]
*/
getIslands(?options)
Asynchronous function to get all islands data.
import { getIslands } from 'idn-area-data';
const islands = await getIslands();
console.log(islands);
/*
[
{
code: '11.01.40001',
coordinate: '03°19'03.44" N 097°07'41.73" E',
name: 'Pulau Batukapal',
is_outermost_small: '0',
is_populated: '0',
regency_code: '11.01',
},
...
]
*/
If options.transform
argument is true
, the property naming will be changed from snake_case
into camelCase
and the data type will be converted (for boolean
and number
).
[!IMPORTANT] The
regencyCode
will benull
if the island doesn't belong to any regency and thetransform
option is enabled.
const islands = await getIslands({ transform: true });
/*
[
{
code: '11.01.40001',
coordinate: '03°19'03.44" N 097°07'41.73" E',
name: 'Pulau Batukapal',
isOutermostSmall: false,
isPopulated: false,
regencyCode: '11.01', <-- It will be `null` if the island doesn't belong to any regency
},
...
]
*/
getData(area, ?options)
If you need to customize the attribute names or values of the data yourself, you can use this asyncronous function and provide the data transformer configuration in options.transform
.
To customize the attribute names, define the pair between the old attribute and the new attribute in options.transform.headers
. The old attributes is equals to the CSV headers of each data.
To customize the attribute values, set the value transformer functions in options.transform.values
.
See the example below :
// .ts
import { getData } from 'idn-area-data';
// Define the custom type of the data
type Provinsi = {
kode: number;
nama: string;
};
// Get the data
const data = await getData<Provinsi>('provinces', {
transform: {
headers: {
code: 'kode',
name: 'nama',
},
values: {
code: (value) => parseInt(value),
},
},
});
console.log(data);
/*
[
{
kode: 11,
nama: 'ACEH',
},
...
]
*/
// .js
import { getData } from 'idn-area-data';
const data = await getData('provinces', {
transform: {
headers: {
code: 'kode',
name: 'nama',
},
values: {
code: (value) => parseInt(value),
},
},
});
You can try to run this package in the code playground :
This package is a solution that addresses the limitations of other existing packages, repositories, or sources that provides Indonesian area data. Here's why it's the perfect choice for developers :
Up-to-date and Government-Sourced Data
This package ensures that you have access to the most current Indonesian area data. We rely on official government sources, guaranteeing that the information provided is reliable and up-to-date.
Seamless Database Integration
This package offers data in a format that seamlessly integrates with various databases. Unlike other sources that provide data solely in SQL query or JSON, this package store the data sources in CSV and use JavaScript to parse it into an array. You can easily insert the data into any database by using database integration tools like Prisma, Sequelize, node-postgres, mongodb, etc. This approach ensures compatibility with a wide range of databases.
Easy Integration and Minimum Package Size
You just need to install this package as a dependency into your project, just like any other library or module. This package has minimal dependencies on other packages, with the majority of its size being attributed to the data source itself.
The data we used is based on official data from the government and stored in separated CSV files by the levels in data
directory.
You can see the list of official sources we refer to here.
We have different channels for each problem, please use them by following these conditions :
To report a bug, please open a new issue following the guide here.
If you have a new feature in mind, please open a new issue following the guide here.
If you have a question, you can search for answers in the GitHub Discussions Q&A category here. If you don't find a relevant discussion already, you can open a new discussion.
These licenses apply to the current and previous versions, and apply to future versions until changed.
Give a ⭐️ if this project helped you!
Also please consider supporting this project by becoming a sponsor. Your donation will help us to maintain and develop this project and provide you with better support.
FAQs
Indonesia administrative area data, based on the latest regulation
We found that idn-area-data demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.