@dataforsyningen/gsearch-ui

中文文档
2.2.0发布于 2025/05/09MITES Module零依赖近 30 天下载 3639

UI component for GSearch.

原始使用文档
文档目录8 节
  1. Demo
  2. Installation
  3. npm
  4. Usage
  5. Data attributes
  6. On click event
  7. Publish NPM
  8. Acknowledgements

GSearch-UI

A web component that implements a simple UI for GSearch.

Demo

Demo page at https://sdfidk.github.io/gsearch-ui/

Installation

npm


$ npm i @dataforsyningen/gsearch-ui -S

Usage

To use GSearch-UI you must first create a user at https://dataforsyningen.dk/ and create a token.

You can then use GSearch-UI like in the example below.

<main>
  <g-search data-token="INSERTYOURTOKENHERE"></g-search>
</main>
<script type="module">
  import { GSearchUI } from '@dataforsyningen/gsearch-ui'
  customElements.define('g-search', GSearchUI)
  document.querySelector("g-search").addEventListener('gsearch:select', (event) => {
    // handle the click here
    // event.detail contains the result object
  })
</script>

Data attributes

GSearch-UI is configured using html data attributes.

attribute namedescriptionrequiredupdates dynamicallydefault
data-tokenA valid token from https://dataforsyningen.dk/yesyesNaN
data-resourcesThe resources that should be searched in. See more information in the GSearch documentationnoyesnavngivenvej,husnummer,adresse,stednavn,kommune,region,retskreds,postnummer,opstillingskreds,sogn,politikreds,matrikel,matrikel_udgaaet
resource-filter-enabledShow filter buttons for the selected resources to allow the user to toggle resources.noyesfalse
data-limitThe number of matches for each resource to be shown. The maximum value is 100.noyes10
data-placeholderThe placeholder text to show in the input field.noyessøg...
data-apiUse a custom URL for GSearch API (ie. if you want to use a test API)noyeshttps://api.dataforsyningen.dk/rest/gsearch/v2.0/
data-filterUse a custom filter in the search query. Learn about filters in the GSearch docs.nononone
data-sridThe coordinate system of the returned geometries. The following values are allowed: 2196, 2197, 2198, 3857, 4093, 4094, 4095, 4096, 4326, 25832, 25833.noyes25832

On click event

When clicking on a result displayed in the GSearch-UI it will dispatch a custom event, gsearch:select, that contains the result object in event.detail. The structure of the object depends on the resource. See more information about the different resouces here: https://github.com/SDFIdk/gsearch/tree/v2.0/doc.

Clicking the cross to clear the input field fires a custom event, gsearch:clear.

Publish NPM

Create a new release in Github to publish an updated NPM package. Details are available in the "Npm" section of SDFI ITU's wiki.

Acknowledgements

GSearch-UI is made available under the MIT license by Styrelsen for Dataforsyning og Infrastruktur @ SDFI

版本与发布记录

@dataforsyningen/gsearch-ui 共发布 32 个版本,首次发布于 2022/10/28;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.2.0latest2025/05/091.5 年前
2.1.32024/08/192 年前
2.1.22024/06/062 年前
2.1.02024/05/012 年前
2.0.12024/01/232 年前
2.0.02024/01/172 年前

关于 @dataforsyningen/gsearch-ui 的常见问题

@dataforsyningen/gsearch-ui 是什么?

UI component for GSearch.

如何安装 @dataforsyningen/gsearch-ui?

在项目目录运行 npm install @dataforsyningen/gsearch-ui,或使用 pnpm add / yarn add / bun add。

@dataforsyningen/gsearch-ui 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/dataforsyningen__gsearch-ui 是否存在。

@dataforsyningen/gsearch-ui 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@dataforsyningen/gsearch-ui 可以商用吗?

@dataforsyningen/gsearch-ui 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@dataforsyningen/gsearch-ui 的下载量有多少?

根据 npm 官方下载统计,@dataforsyningen/gsearch-ui 在 2026/10/12 – 2026/11/10 这 30 天内被下载 3,639 次,日均约 121 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dataforsyningen/gsearch-ui 还在维护吗?

最新版本 2.2.0 发布于 2025/05/09(1.5 年前);至今共发布 32 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/10/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。