Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jp-prefecture

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jp-prefecture

Utility library dealing with prefectures and regions in Japan.

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
597
increased by13.07%
Maintainers
1
Weekly downloads
 
Created
Source

jp-prefecture Build Status

Utility library dealing with prefectures and regions in Japan.

Version

0.0.1

Install

Node.js

npm instal jp-prefecture

Require.js

require(["jp-prefecture"], ...

Simple

<script type="text/javascript" src="jp-prefecture.js"></script>

Methods

getAll

jpPrefecture.getAll(type, [select])

type: string("region" or "pref")
select: string | array
return: array

Get all regions or prefectures.

var results = jpPrefecture.getAll("region");
console.log(results); // [Object, Object, Object ...]

results = jpPrefecture.getAll("pref", "name");
console.log(results); // ["北海道", "青森県", "岩手県", ...] 

results = jpPrefecture.getAll("pref", ["id", "name"]);
console.log(results); // [{id:1, name:"北海道"}, {id:2, name:"青森県"}, ...] 

getAllRegion

jpPrefecture.getAllRegion([select])

select: string | array
return: array

Alias for getAll("region").

var results = jpPrefecture.getAllRegion();
console.log(results); // [Object, Object, Object ...]

getAllPref

jpPrefecture.getAllRegion([select])

select: string | array
return: array

Alias for getAll("pref").

var results = jpPrefecture.getAllRegion();
console.log(results); // [Object, Object, Object ...]

find

jpPrefecture.find(type, value, [select])

type: string("region" or "pref")
value: mixed
select: string | array
return: object

Get the single object of regional or prefectures.

var result = jpPrefecture.find("region", "北海道");
console.log(result); // {id:1, name:"北海道", kana:"ホッカイドウ", en:"hokkaido", neighbor:[2]}

result = jpPrefecture.find("region", "北海道", "kana");
console.log(result); // "ホッカイドウ"

result = jpPrefecture.find("region", "北海道", ["id", "kana"]);
console.log(result); // {id:1, kana:"ホッカイドウ"}

result = jpPrefecture.find("pref", "東京都");
console.log(result); // {id:13, region:3, name:"東京都", short:"東京", kana:"トウキョウ", en:"tokyo", neighbor:[11, 12, 14, 19]}

result = jpPrefecture.find("hogefuga", false);
console.log( result ); // undefined

regionFind

jpPrefecture.regionFind(value, [select])

type: string("region" or "pref")
value: mixed
select: string | array
return: object

Get the single object of regional. Alias for find("region").

var result = jpPrefecture.regionFind("北海道");
console.log(result); // {id:1, name:"北海道", kana:"ホッカイドウ", en:"hokkaido", neighbor:[2]}

prefFind

jpPrefecture.prefFind(value, [select])

type: string("region" or "pref")
value: mixed
select: string | array
return: object

Get the single object of prefectures. Alias for find("pref").

var result = jpPrefecture.prefFind("東京都");
console.log(result); // {id:13, region:3, name:"東京都", short:"東京", kana:"トウキョウ", en:"tokyo", neighbor:[11, 12, 14, 19]}

findBy

jpPrefecture.findBy(type, key, value, [select])

type: string("region" or "pref")
value: string
value: mixed
select: string | array
return: object

By specifying the key and value, to get a single object of regional.

var result = jpPrefecture.findBy("region", "id", 8);
console.log(result); // {id:8, name:"九州",   kana:"キュウシュウ", en:"kyusyu",   neighbor:[6, 7]}

result = jpPrefecture.findBy("region", "id", 8, "name");
console.log(result); // "九州"

result = jpPrefecture.findBy("region", "en", "chugoku", ["id", "name"]);
console.log(result); // {id:6, name:"中国"}

result = jpPrefecture.findBy("pref", "short", "宮城");
console.log(result); // {id:4, region:2, name:"宮城県", short:"宮城", kana:"ミヤギ", en:"miyagi", neighbor:[3, 5, 6, 7]}

result = jpPrefecture.findBy("hoge", "fuga");
console.log(result); // undefined

regionFindBy

jpPrefecture.regionFindBy(key, value, [select])

key: string
value: mixed
select: string | array
return: object

Alias for regionFindBy("region").

var result = jpPrefecture.regionFindBy("id", 8);
console.log(result); // {id:8, name:"九州", kana:"キュウシュウ", en:"kyusyu", neighbor:[6, 7]}

prefFindBy

jpPrefecture.prefFindBy(key, value, [select])

key: string
value: mixed
select: string | array
return: object

Alias for prefFindBy("region").

var result = jpPrefecture.prefFindBy("id", 8);
console.log(result); // {id:8, region:3, name:"茨城県", short:"茨城", kana:"イバラキ", en:"ibaraki", neighbor:[7, 9, 11, 12]}

regionFindByPref

jpPrefecture.regionFindByPref(value, [select])

value: mixed
select: string | array
return: object

Get the region corresponding from prefectures.

var result = jpPrefecture.regionFindByPref("東京");
console.log(result); // {id: 3, name: "関東", kana: "カントウ", en: "kanto", neighbor: Array[2]}

result = jpPrefecture.regionFindByPref("fukuoka", "name");
console.log(result); // "九州"

result = jpPrefecture.regionFindByPref("hoge");
console.log(result); // undefined

prefFindByRegion

jpPrefecture.prefFindByRegion(value, [select])

value: mixed
select: string | array
return: array

Get the prefectures corresponding from region.

var results = jpPrefecture.prefFindByRegion("関東");
console.log(results); // [Object, Object, Object ...]

results = jpPrefecture.prefFindByRegion("関東", "name");
console.log(results); //  ["茨城県", "栃木県", "群馬県", "埼玉県", "千葉県", "東京都", "神奈川県"]

results = jpPrefecture.prefFindByRegion("hoge", "fuga");
console.log(results); // undefined

where

jpPrefecture.where(type, attrs, [select])

type: string("region" or "pref")
attrs: object
select: string | array
return: array

Get the regional or province apply to the given conditions.
The return value is returned always an array.

var results = jpPrefecture.where("region", {id:1});
console.log(results); // [{id:1, name:"北海道", kana:"ホッカイドウ", en:"hokkaido", neighbor:[2]}]

results = jpPrefecture.where("region", {id:1}, "name");
console.log(results); // ["北海道"]

results = jpPrefecture.where("pref", {region:3}, "name");
console.log(results); // ["茨城県", "栃木県", "群馬県", "埼玉県", "千葉県", "東京都", "神奈川県"]

results = jpPrefecture.where("hoge", null);
console.log(results); // []

regionWhere

jpPrefecture.regionWhere(attrs, [select])

attrs: object
select: string | array
return: array

Alias for where("region").

var results = jpPrefecture.regionWhere({id:1});
console.log(results); // [{id:1, name:"北海道", kana:"ホッカイドウ", en:"hokkaido", neighbor:[2]}]

prefWhere

jpPrefecture.prefWhere(attrs, [select])

attrs: object
select: string | array
return: array

Alias for where("pref").

var results = jpPrefecture.prefWhere({region:3});
console.log(results); // ["茨城県", "栃木県", "群馬県", "埼玉県", "千葉県", "東京都", "神奈川県"]

convert

jpPrefecture.convert(type, value, key)

type: string("region" or "pref")
value: mixed
key: string
return: mixed

Conversion from the specified value of the region or province to another key.

var result = jpPrefecture.convert("region", "関東", "en");
console.log(result); // "kanto"

result = jpPrefecture.convert("region", "中国", "kana");
console.log(result); // "チュウゴク"

result = jpPrefecture.convert("pref", "ヒョウゴ", "name");
console.log(result); // "兵庫県"

result = jpPrefecture.convert("hoge", "fuga");
console.log(result); // undefined

regionConvert

jpPrefecture.regionConvert(value, key)

value: mixed
key: string
return: mixed

Alias for convert("region").

var result = jpPrefecture.regionConvert("関東", "en");
console.log(result); // "kanto"

result = jpPrefecture.regionConvert("中国", "kana");
console.log(result); // "チュウゴク"

regionConvert

jpPrefecture.regionConvert(value, key)

value: mixed
key: string
return: mixed

Alias for convert("region").

var result = jpPrefecture.prefConvert("ヒョウゴ", "name");
console.log(result); // "兵庫県"

result = jpPrefecture.prefConvert("鳥取県", "en");
console.log(result); // "tottori"

result = jpPrefecture.prefConvert("大分県", "id");
console.log(result); // 44

getNeighbors

jpPrefecture.getNeighbors(type, value, [select])

type: string("region" or "pref")
value: mixed
select: string
return: array

Get the ones that are adjacent to a given region or province.

var result = jpPrefecture.getNeighbors("region", "関東");
console.log(result); // [Object, Object]

result = jpPrefecture.getNeighbors("region", "関東", "name");
console.log(result); // ["東北", "中部"]

result = jpPrefecture.getNeighbors("pref", "東京都", "en");
console.log(result); // ["saitama", "chiba", "kanagawa", "yamanashi"]

result = jpPrefecture.getNeighbors("pref", "hoge", "fuga");
console.log(result); // undefined

getRegionNeighbors

jpPrefecture.getRegionNeighbors(value, [select])

value: mixed
select: string
return: array

Alias for getNeighbors("region").

var result = jpPrefecture.getRegionNeighbors("関東");
console.log(result); // [Object, Object]

result = jpPrefecture.getRegionNeighbors("関東", "name");
console.log(result); // ["東北", "中部"]

getPrefNeighbors

jpPrefecture.getPrefNeighbors(value, [select])

value: mixed
select: string
return: array

Alias for getNeighbors("pref").

var result = jpPrefecture.getPrefNeighbors("東京都", "en");
console.log(result); // ["saitama", "chiba", "kanagawa", "yamanashi"]

result = jpPrefecture.getPrefNeighbors("hoge", "fuga");
console.log(result); // undefined

isNeighbor

jpPrefecture.isNeighbor(type, val1, val2)

type: string("region" or "pref")
val1: mixed
val2: mixed
return: boolean

Determine if the specified two regions or prefectures were are adjacent.

var result = jpPrefecture.isNeighbor("region", "関東", "東北");
console.log(result); // true

result = jpPrefecture.isNeighbor("region", "関東", "中国");
console.log(result); // false

result = jpPrefecture.isNeighbor("pref", "山形", "fukushima");
console.log(result); // true

result = jpPrefecture.isNeighbor("pref", "神奈川県", "hokkaido");
console.log(result); // false

isRegionNeighbor

jpPrefecture.isRegionNeighbor(val1, val2)

val1: mixed
val2: mixed
return: boolean

Alias for isNeighbor("region").

var result = jpPrefecture.isRegionNeighbor("関東", "東北");
console.log(result); // true

result = jpPrefecture.isRegionNeighbor("関東", "中国");
console.log(result); // false

isPrefNeighbor

jpPrefecture.isPrefNeighbor(val1, val2)

val1: mixed
val2: mixed
return: boolean

Alias for isNeighbor("region").

var result = jpPrefecture.isPrefNeighbor("山形", "fukushima");
console.log(result); // true

result = jpPrefecture.isPrefNeighbor("神奈川県", "hokkaido");
console.log(result); // false

neighborSize

jpPrefecture.neighborSize(type, value)

type: string("region" or "pref")
value: mixed
return: integer

Get the number of adjacent of the specified region.

var result = jpPrefecture.neighborSize("region", "九州");
console.log(result); // 2

result = jpPrefecture.neighborSize("region", "tohoku");
console.log(result); // 1

result = jpPrefecture.neighborSize("region", "hoge");
console.log(result); // 0

result = jpPrefecture.neighborSize("pref", "tokyo");
console.log(result); // 4

regionNeighborSize

jpPrefecture.regionNeighborSize(value)

value: mixed
return: integer

Alias for neighborSize("region").

var result = jpPrefecture.regionNeighborSize("九州");
console.log(result); // 2

result = jpPrefecture.regionNeighborSize("tohoku");
console.log(result); // 1

prefNeighborSize

jpPrefecture.prefNeighborSize(value)

value: mixed
return: integer

Alias for neighborSize("pref").

var result = jpPrefecture.prefNeighborSize("北海道");
console.log(result); // 1

result = jpPrefecture.prefNeighborSize("ワカヤマ");
console.log(result); // 5

getAllRegionInPref

jpPrefecture.getAllRegionInPref()

return: integer

Get a list of state that contains the prefectures corresponding to the region in the multidimensional array.
This is useful when the loop of the list was based on the regional.

console.log( jpPrefecture.getAllRegionInPref() );
/*
[
  0: {
    region: {id:1, name:"北海道", kana:"ホッカイドウ", en:"hokkaido", neighbor:[2]},
    prefectures: [
      {id:1,  region:1, name:"北海道",   short:"北海道", kana:"ホッカイドウ", en:"hokkaido",  neighbor:[2]},
    ]
  },
  1: {
    region: {id:2, name:"東北",   kana:"トウホク",     en:"tohoku",   neighbor:[1]},
    prefectures: [
      {id:2, region:2, name:"青森県", short:"青森", kana:"アオモリ", en:"aomori",    neighbor:[1, 3, 5]},
      {id:3, region:2, name:"岩手県", short:"岩手", kana:"イワテ",   en:"iwate",     neighbor:[2, 4, 5]},
      {id:4, region:2, name:"宮城県", short:"宮城", kana:"ミヤギ",   en:"miyagi",    neighbor:[3, 5, 6, 7]},
      {id:5, region:2, name:"秋田県", short:"秋田", kana:"アキタ",   en:"akita",     neighbor:[2, 3, 4, 6]},
      {id:6, region:2, name:"山形県", short:"山形", kana:"ヤマガタ", en:"yamagata",  neighbor:[4, 5, 7, 15]},
      {id:7, region:2, name:"福島県", short:"福島", kana:"フクシマ", en:"fukushima", neighbor:[4, 6, 8, 9, 10, 15]},
    ]
  },

  ...

]
*/

Use DataList

Data regions and prefectures uses the following.
Id prefectures correspond to those integer the region code of ISO.

全国地方公共団体コード

Regions:

[
  {id:1, name:"北海道", kana:"ホッカイドウ", en:"hokkaido", neighbor:[2]},
  {id:2, name:"東北",   kana:"トウホク",     en:"tohoku",   neighbor:[1]},
  {id:3, name:"関東",   kana:"カントウ",     en:"kanto",    neighbor:[2, 4]},
  {id:4, name:"中部",   kana:"チュウブ",     en:"chubu",    neighbor:[2, 3, 5]},
  {id:5, name:"近畿",   kana:"キンキ",       en:"kinki",    neighbor:[4, 6, 7]},
  {id:6, name:"中国",   kana:"チュウゴク",   en:"chugoku",  neighbor:[5, 7, 8]},
  {id:7, name:"四国",   kana:"シコク",       en:"shikoku",  neighbor:[5, 6, 8]},
  {id:8, name:"九州",   kana:"キュウシュウ", en:"kyusyu",   neighbor:[6, 7]}
]

Prefectures:

[
  {id:1,  region:1, name:"北海道",   short:"北海道", kana:"ホッカイドウ", en:"hokkaido",  neighbor:[2]},
  {id:2,  region:2, name:"青森県",   short:"青森",   kana:"アオモリ",     en:"aomori",    neighbor:[1, 3, 5]},
  {id:3,  region:2, name:"岩手県",   short:"岩手",   kana:"イワテ",       en:"iwate",     neighbor:[2, 4, 5]},
  {id:4,  region:2, name:"宮城県",   short:"宮城",   kana:"ミヤギ",       en:"miyagi",    neighbor:[3, 5, 6, 7]},
  {id:5,  region:2, name:"秋田県",   short:"秋田",   kana:"アキタ",       en:"akita",     neighbor:[2, 3, 4, 6]},
  {id:6,  region:2, name:"山形県",   short:"山形",   kana:"ヤマガタ",     en:"yamagata",  neighbor:[4, 5, 7, 15]},
  {id:7,  region:2, name:"福島県",   short:"福島",   kana:"フクシマ",     en:"fukushima", neighbor:[4, 6, 8, 9, 10, 15]},
  {id:8,  region:3, name:"茨城県",   short:"茨城",   kana:"イバラキ",     en:"ibaraki",   neighbor:[7, 9, 11, 12]},
  {id:9,  region:3, name:"栃木県",   short:"栃木",   kana:"トチギ",       en:"tochigi",   neighbor:[8, 7, 10, 11]},
  {id:10, region:3, name:"群馬県",   short:"群馬",   kana:"グンマ",       en:"gunma",     neighbor:[7, 9, 11, 15, 20]},
  {id:11, region:3, name:"埼玉県",   short:"埼玉",   kana:"サイタマ",     en:"saitama",   neighbor:[8, 9, 10, 12, 13, 19, 20]},
  {id:12, region:3, name:"千葉県",   short:"千葉",   kana:"チバ",         en:"chiba",     neighbor:[8, 11, 13, 14]},
  {id:13, region:3, name:"東京都",   short:"東京",   kana:"トウキョウ",   en:"tokyo",     neighbor:[11, 12, 14, 19]},
  {id:14, region:3, name:"神奈川県", short:"神奈川", kana:"カナガワ",     en:"kanagawa",  neighbor:[12, 13, 19, 22]},
  {id:15, region:4, name:"新潟県",   short:"新潟",   kana:"ニイガタ",     en:"niigata",   neighbor:[6, 7, 10, 16, 20]},
  {id:16, region:4, name:"富山県",   short:"富山",   kana:"トヤマ",       en:"toyama",    neighbor:[15, 17, 20, 21]},
  {id:17, region:4, name:"石川県",   short:"石川",   kana:"イシカワ",     en:"ishikawa",  neighbor:[16, 18, 21]},
  {id:18, region:4, name:"福井県",   short:"福井",   kana:"フクイ",       en:"fukui",     neighbor:[17, 21, 25, 26]},
  {id:19, region:4, name:"山梨県",   short:"山梨",   kana:"ヤマナシ",     en:"yamanashi", neighbor:[11, 13, 14, 20, 22]},
  {id:20, region:4, name:"長野県",   short:"長野",   kana:"ナガノ",       en:"nagano",    neighbor:[10, 11, 15, 16, 19, 21, 22, 23]},
  {id:21, region:4, name:"岐阜県",   short:"岐阜",   kana:"ギフ",         en:"gifu",      neighbor:[16, 17, 18, 20, 23, 24, 25]},
  {id:22, region:4, name:"静岡県",   short:"静岡",   kana:"シズオカ",     en:"shizuoka",  neighbor:[14, 19, 20, 23]},
  {id:23, region:4, name:"愛知県",   short:"愛知",   kana:"アイチ",       en:"aichi",     neighbor:[20, 21, 22, 24]},
  {id:24, region:5, name:"三重県",   short:"三重",   kana:"ミエ",         en:"mie",       neighbor:[21, 23, 25, 26, 29, 30]},
  {id:25, region:5, name:"滋賀県",   short:"滋賀",   kana:"シガ",         en:"shiga",     neighbor:[18, 21, 24, 26]},
  {id:26, region:5, name:"京都府",   short:"京都",   kana:"キョウト",     en:"kyoto",     neighbor:[18, 24, 25, 27, 28, 29]},
  {id:27, region:5, name:"大阪府",   short:"大阪",   kana:"オオサカ",     en:"osaka",     neighbor:[26, 28, 29, 30]},
  {id:28, region:5, name:"兵庫県",   short:"兵庫",   kana:"ヒョウゴ",     en:"hyogo",     neighbor:[26, 27, 30, 31, 33, 36, 37]},
  {id:29, region:5, name:"奈良県",   short:"奈良",   kana:"ナラ",         en:"nara",      neighbor:[24, 26, 27, 30]},
  {id:30, region:5, name:"和歌山県", short:"和歌山", kana:"ワカヤマ",     en:"wakayama",  neighbor:[24, 27, 28, 29, 36]},
  {id:31, region:6, name:"鳥取県",   short:"鳥取",   kana:"トットリ",     en:"tottori",   neighbor:[28, 32, 33, 34]},
  {id:32, region:6, name:"島根県",   short:"島根",   kana:"シマネ",       en:"shimane",   neighbor:[31, 34, 35]},
  {id:33, region:6, name:"岡山県",   short:"岡山",   kana:"オカヤマ",     en:"okayama",   neighbor:[28, 31, 34, 37]},
  {id:34, region:6, name:"広島県",   short:"広島",   kana:"ヒロシマ",     en:"hiroshima", neighbor:[31, 32, 33, 35, 37, 38]},
  {id:35, region:6, name:"山口県",   short:"山口",   kana:"ヤマグチ",     en:"yamaguchi", neighbor:[32, 34, 38, 40, 44]},
  {id:36, region:7, name:"徳島県",   short:"徳島",   kana:"トクシマ",     en:"tokushima", neighbor:[28, 30, 37, 38, 39]},
  {id:37, region:7, name:"香川県",   short:"香川",   kana:"カガワ",       en:"kagawa",    neighbor:[28, 33, 34, 36, 38]},
  {id:38, region:7, name:"愛媛県",   short:"愛媛",   kana:"エヒメ",       en:"ehime",     neighbor:[33, 34, 35, 36, 37, 39, 44]},
  {id:39, region:7, name:"高知県",   short:"高知",   kana:"コウチ",       en:"kochi",     neighbor:[36, 38]},
  {id:40, region:8, name:"福岡県",   short:"福岡",   kana:"フクオカ",     en:"fukuoka",   neighbor:[35, 41, 42, 43, 44]},
  {id:41, region:8, name:"佐賀県",   short:"佐賀",   kana:"サガ",         en:"saga",      neighbor:[40, 42]},
  {id:42, region:8, name:"長崎県",   short:"長崎",   kana:"ナガサキ",     en:"nagasaki",  neighbor:[41, 43]},
  {id:43, region:8, name:"熊本県",   short:"熊本",   kana:"クマモト",     en:"kumamoto",  neighbor:[40, 41, 42, 44, 45, 46]},
  {id:44, region:8, name:"大分県",   short:"大分",   kana:"オオイタ",     en:"oita",      neighbor:[35, 38, 40, 43, 45]},
  {id:45, region:8, name:"宮崎県",   short:"宮城",   kana:"ミヤザキ",     en:"miyazaki",  neighbor:[43, 44, 46]},
  {id:46, region:8, name:"鹿児島県", short:"鹿児島", kana:"カゴシマ",     en:"kagoshima", neighbor:[43, 45, 47]},
  {id:47, region:8, name:"沖縄県",   short:"沖縄",   kana:"オキナワ",     en:"okinawa",   neighbor:[46]}
]

Change Log

  • First Release.

License

Released under the MIT Licence

Author

tsuyoshi wada

Keywords

FAQs

Package last updated on 08 Feb 2015

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc