{"id":19013365,"url":"https://github.com/z41z/sp-area","last_synced_at":"2025-11-11T13:31:28.867Z","repository":{"id":57366600,"uuid":"179643057","full_name":"z41z/sp-area","owner":"z41z","description":"根据区划代码找关联区划。","archived":false,"fork":false,"pushed_at":"2019-04-08T03:00:00.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-02T21:56:39.966Z","etag":null,"topics":["area-code","china-region"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/z41z.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-05T08:15:23.000Z","updated_at":"2019-04-08T03:00:02.000Z","dependencies_parsed_at":"2022-08-23T19:40:39.097Z","dependency_job_id":null,"html_url":"https://github.com/z41z/sp-area","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z41z%2Fsp-area","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z41z%2Fsp-area/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z41z%2Fsp-area/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z41z%2Fsp-area/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/z41z","download_url":"https://codeload.github.com/z41z/sp-area/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240051391,"owners_count":19740340,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["area-code","china-region"],"created_at":"2024-11-08T19:23:38.826Z","updated_at":"2025-11-11T13:31:28.676Z","avatar_url":"https://github.com/z41z.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sp-area\n\n根据区划代码找关联区划。\n\n## Install\n\n``` node\n  npm i sp-area //or yarn add sp-area\n```\n\n## Build\n\n``` node\n  npm run build\n```\n\n## CDN\n\n``` js\n  \u003cscript src=\"https://unpkg.com/sp-area/dist/index.min.js\"\u003e\u003c/script\u003e\n  \u003cscript\u003e\n    let {area} = __AREA;\n    let origion = [\n          { '510000': '四川省'},\n          { '510100': '成都市' },\n          { '510200': '绵阳市' },\n          { '510201': '涪城区' },\n          { '510202': '三台县' },\n          { '510101': '武侯区' },\n          { '510112': '青羊区' },\n          { '520000': '贵州省' },\n          { '520100': '贵阳市' },\n          { '520101': '花溪区' },\n          { '520102': '小河区' },\n          { '520200': '安顺市' },\n          { '520201': '安顺区'}]\n    area({\n      origion: origion,\n      target: '510112',\n      type: 'siblings',\n      hasOwn: true,\n      formatter(result) {\n        result.forEach(item =\u003e {\n          item.name = item.name.replace(/区|县/,'')\n        })\n        return result\n      }\n    })\n    // [ { code: '510101', name: '武侯' },{ code: '510112', name: '青羊' } ]\n  \u003c/script\u003e\n```\n\n### Usage\n\n``` js\n  const {\n    area\n  } = require(\"sp-area\")\n```\n\n* area(obj = {})\n  * {Object} option\n    * {Array} option.origion 区划数组\n    * {String|Number} option.target 区划代码或区划名称\n    * {String} option.type = children、siblings、parent\n    * {Boolean} option.hasOwn 包括本身\n    * {Function} option.formater 回调处理函数\n\n  ``` js\n    let origion = [\n          { '510000': '四川省'},\n          { '510100': '成都市' },\n          { '510200': '绵阳市' },\n          { '510201': '涪城区' },\n          { '510202': '三台县' },\n          { '510101': '武侯区' },\n          { '510112': '青羊区' },\n          { '520000': '贵州省' },\n          { '520100': '贵阳市' },\n          { '520101': '花溪区' },\n          { '520102': '小河区' },\n          { '520200': '安顺市' },\n          { '520201': '安顺区'}];\n    area(\n      {\n        origion: origion,\n        target: '510100',\n        type: 'children',\n        hasOwn: false,\n        formatter(result) {\n          result.forEach(item =\u003e {\n            item.name = item.name.replace(/区|县/,'')\n          })\n          return result\n        }\n      }\n    );\n    // '[ { code: '510101', name: '武侯' },{ code: '510112', name: '青羊' } ]'\n    area(\n      {\n        origion: origion,\n        target: '510100',\n        type: 'children',\n        hasOwn: true,\n        formatter(result) {\n          result.forEach(item =\u003e {\n            item.name = item.name.replace(/区|县/,'')\n          })\n          return result\n        }\n      }\n    );\n    // '[ { code: '510100', name: '成都市' },{ code: '510101', name: '武侯' },{ code: '510112', name: '青羊' } ]'\n    area(\n      {\n        origion: origion,\n        target: '510100',\n        type: 'siblings',\n        hasOwn: false,\n        formatter(result) {\n          result.forEach(item =\u003e {\n            item.name = item.name.replace(/区|县/,'')\n          })\n          return result\n        }\n      }\n    );\n    // '[ { code: '510200', name: '绵阳市' } ]'\n    area(\n      {\n        origion: origion,\n        target: '510100',\n        type: 'siblings',\n        hasOwn: true,\n        formatter(result) {\n          result.forEach(item =\u003e {\n            item.name = item.name.replace(/区|县/,'')\n          })\n          return result\n        }\n      }\n    );\n    // [ { code: '510100', name: '成都市' },{ code: '510200', name: '绵阳市' } ]\n    area(\n      {\n        origion: origion,\n        target: '510100',\n        type: 'parent',\n        formatter(result) {\n          result.forEach(item =\u003e {\n            item.name = item.name.replace(/区|县/,'')\n          })\n          return result\n        }\n      }\n    );\n    // [ { code: '510000', name: '四川省' } ]\n  ```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fz41z%2Fsp-area","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fz41z%2Fsp-area","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fz41z%2Fsp-area/lists"}