Provides the administrative areas data of Indonesia, from the province, regency, district, to village levels based on the latest official sources. It also provides island data since version 1.3.0.
New PAPUA provinces data is available in version 2.0.0
npm install --save idn-area-data
Use this for yarn user :
yarn add idn-area-data
Import the package into your project :
// CommonJS
const IdnArea = require('idn-area-data');
// or using ES6
import IdnArea from 'idn-area-data';
Then, you can get the data you need using these methods below.
Get all provinces data.
const provinces = await IdnArea.provinces();
/*
[
{
code: '11',
name: 'ACEH',
},
]
*/
Get all regencies data.
const regencies = await IdnArea.regencies();
/*
[
{
code: '1101',
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 IdnArea.regencies({ transform: true });
/*
[
{
code: '1101',
name: 'KABUPATEN ACEH SELATAN',
provinceCode: '11',
},
]
*/
Get all districts data.
const districts = await IdnArea.districts();
/*
[
{
code: '110101',
name: 'BAKONGAN',
regency_code: '1101',
},
]
*/
If options.transform
argument is true
, the property naming will be changed from snake_case
into camelCase
.
const districts = await IdnArea.districts({ transform: true });
/*
[
{
code: '110101',
name: 'BAKONGAN',
regencyCode: '1101',
},
]
*/
Get all villages data.
const villages = await IdnArea.villages();
/*
[
{
code: '1101012001',
district_code: '110101',
name: 'KEUDE BAKONGAN',
},
]
*/
If options.transform
argument is true
, the property naming will be changed from snake_case
into camelCase
.
const villages = await IdnArea.villages({ transform: true });
/*
[
{
code: '1101012001',
districtCode: '110101',
name: 'KEUDE BAKONGAN',
},
]
*/
Get all islands data.
const islands = await IdnArea.islands();
/*
[
{
code: '110140001',
coordinate: '03°19'03.44" N 097°07'41.73" E',
name: 'Pulau Batukapal',
is_outermost_small: '0',
is_populated: '0',
regency_code: '1101',
},
]
*/
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
).
const islands = await IdnArea.islands({ transform: true });
/*
[
{
code: '110140001',
coordinate: '03°19'03.44" N 097°07'41.73" E',
name: 'Pulau Batukapal',
isOutermostSmall: false,
isPopulated: false,
regencyCode: '1101',
},
]
*/
The
regencyCode
will benull
if the island doesn't belong to any regency and thetransform
option is enabled.
You also can use getData()
function to get the data by providing the area
parameter.
const provinces = await IdnArea.getData('provinces');
const regencies = await IdnArea.getData('regencies');
const districts = await IdnArea.getData('districts');
const villages = await IdnArea.getData('villages');
const islands = await IdnArea.getData('islands');
You also can put the options
as the second argument :
const regencies = await IdnArea.getData('regencies', { transform: true });
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.
- This package and repository are licensed under the MIT License.
- All data that included in this package and repository are made available under the Open Database License.
These licenses apply to the current and previous versions, and apply to future versions until changed.