# @goldenhippo/gh-surveys 中文文档

规范地址：https://npmcn.com/package/%40goldenhippo/gh-surveys/

版本：0\.0\.46
npm 元数据更新时间：2026-02-05T21:10:37.779Z
中文译文更新时间：2026-11-16T18:35:52.273Z
软件包许可：UNLICENSED

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40goldenhippo/gh-surveys
原文对照：https://npmcn.com/package/%40goldenhippo/gh-surveys/?lang=original
项目主页：https://github.com/GoldenHippoMedia/gh-surveys

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：76 kB，5 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：1 个
- 首次发布：2023-04-26T23:46:51.260Z
- 最新版本发布：2024-02-05T19:00:30.327Z
- 近 30 天下载量：3815（2026-10-17 至 2026-11-15，npm 官方下载统计）
- 已发布版本数：48（近 12 个月 0 个）

## 中文简介

Golden Hippo 初步调查包

## 安装

```sh
npm install @goldenhippo/gh-surveys
```

也可以使用：`pnpm add @goldenhippo/gh-surveys`、`yarn add @goldenhippo/gh-surveys`、`bun add @goldenhippo/gh-surveys`

## README

# 金色希波调查

## 目录

-   [金色希波调查](https://npmcn.com/package/%40goldenhippo/gh-surveys/#readme-golden-hippo-surveys)
    -   [目录](https://npmcn.com/package/%40goldenhippo/gh-surveys/#readme-table-of-contents)
    -   [安装](https://npmcn.com/package/%40goldenhippo/gh-surveys/#readme-installation)
    -   [使用量](https://npmcn.com/package/%40goldenhippo/gh-surveys/#readme-usage)
        -   [调查API](https://npmcn.com/package/%40goldenhippo/gh-surveys/#readme-surveyapi)
            -   [A. 调查方法](https://npmcn.com/package/%40goldenhippo/gh-surveys/#readme-surveyapi-methods)
            -   [调查API 使用情况](https://npmcn.com/package/%40goldenhippo/gh-surveys/#readme-surveyapi-usage)
        -   [调查答复](https://npmcn.com/package/%40goldenhippo/gh-surveys/#readme-surveyresponse)
            -   [问题类型](https://npmcn.com/package/%40goldenhippo/gh-surveys/#readme-question-types)
            -   [答复](https://npmcn.com/package/%40goldenhippo/gh-surveys/#readme-answers)

## 安装

```bash
npm i @goldenhippo/gh-surveys
```

**此软件包需要您使用一个可公开访问的 URL 配置 GH 调查 API 实例 .**

## 使用量

### 调查API

从软件包中导入 SurveyAPI 类,并用连接字符串将其即时化为已部署的API. 连接字符串的格式应该是: `https://surveyapi.herokuapp.com` (或无论部署的API URL是什么).

_注:URL末尾不应有斜线._

```typescript
import { SurveyAPI } from "@goldenhippo/gh-surveys";

const surveyAPI = new SurveyAPI(
  "https://surveyapi.herokuapp.com"
);
```

#### A. 调查方法

调查API类别有以下方法:

-   `retrieve(sessionId: string)` - 获取特定会话ID的所有回复。 返回解析到一系列测量检索回复对象的保证 .
-   `ensureTableExists(create: boolean = false)` - 确认数据库中存在调查-答复表。 如果它不存在,则 `create` 参数可以被传递来创建表格。 返回一个解析为布尔表示表格是否存在的保证。 这个过程只应在应用程序启动时运行,因为它是一个昂贵的操作.
-   `submitToDB(surveyResponse: SurveyResponse)` - 向数据库提交调查答复对象。 返回解决 SurveySubmitResponse 对象的保证.

#### 调查API 使用情况

```typescript
import { SurveyAPI } from "@goldenhippo/gh-surveys";

const surveyAPI = new SurveyConnection(
  "https://surveyapi.herokuapp.com"
);

const responses = surveyAPI.retrieve("1234")
  .then((sessionResponses) => {
      console.log(sessionResponses);
      //Find the age response
      const ageResponse = sessionResponses.find(response => response instanceof SurveyResponse.Age)
      if(ageResponse) {
      const ageSelection = ageResponse.answer
      //Do something based on the answer which will be one of the enum options
    }
  })

const tableExists = await surveyAPI.ensureTableExists(); // Validate that table exists, but do not create it if it does not.
console.log(tableExists);

const tableExistsWithCreate = await surveyAPI.ensureTableExists(true); // Validate that table exists, and create it if it does not.
console.log(tableExistsWithCreate);

```

### 调查答复

调查响应类是一个抽象的类,应当被扩展,为特定的调查问题类型创建一个响应. 创建对象然后可以使用 `SurveyAPI.submitToDB` 方法并返回解析到 `SurveySubmitResponse` 对象.

反应对象的结构如下:

```typescript
{
  success: boolean,
  response: {
    answer: string,
    sessionId: string,
    questionType: string
  } | null
}
```

```typescript
import { SurveyAPI, SurveyResponse } from "@goldenhippo/gh-surveys";

const surveyAPI = new SurveyAPI(
  "https://surveyapi.herokuapp.com"
);

const ageResponse = new SurveyResponse.Age({
  question: "How old are you?",
  rawAnswer: "21",
  answer: "AGE_18_24",
  sessionId: "1234",
});
const ageSubmission = apiConnection.submitToDB(ageResponse)
.then((response) => {
  console.log(response);
  /*
   {
      success: true,
      response: {
        answer: "AGE_18_24",
        sessionId: "1234",
        questionType: "AGE"
      }
   }
   */
}

```

#### 问题类型

调查响应类允许您为下列问题类型创建响应:

-   年龄
-   性别
-   消化问题
-   问题时代
-   周而复始
-   解决方案

_注意: 要查看可用的问答, 您可以从您的 API URL 访问配置文件 `/config`。例如, `https://yourapi.herokuapp.com/config`。 。 。 ._

#### 答复

每个问题类型都有一套可能的答案. 答案被定义为类上的静态属性. 例如 `SurveyResponse.Gender` 类有以下可能的答案:

-   马里
-   妇女
-   非两年期
-   解禁线 TO ANSWER

_注意: 要查看可用的问答, 您可以从您的 API URL 访问配置文件 `/config`。例如, `https://yourapi.herokuapp.com/config`。 。 。 ._

## 常见问题

### @goldenhippo/gh-surveys 是什么？

Golden Hippo 初步调查包

### 如何安装 @goldenhippo/gh-surveys？

在项目目录运行 npm install @goldenhippo/gh-surveys，或使用 pnpm add / yarn add / bun add。

### @goldenhippo/gh-surveys 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @goldenhippo/gh-surveys 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @goldenhippo/gh-surveys 可以商用吗？

@goldenhippo/gh-surveys 使用 UNLICENSED 许可。作者声明为 UNLICENSED，即不授予公开使用许可（与公共领域的 Unlicense 不同）。使用前需获得作者授权。以上为概括，不构成法律意见，请以许可原文为准。

### @goldenhippo/gh-surveys 的下载量有多少？

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

### @goldenhippo/gh-surveys 还在维护吗？

最新版本 0\.0\.46 发布于 2024/02/06（2 年前）；至今共发布 48 个版本，其中过去 12 个月发布了 0 个；首次发布于 2023/04/27。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

