# @bj-nsc/functions

> 工具函数

Latest version **2.0.4** (published 2026-10-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install @bj-nsc/functions
pnpm add @bj-nsc/functions
yarn add @bj-nsc/functions
bun add @bj-nsc/functions
```

## Health

**Score 55/100 (C)** — status: active.

Positive: no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 2.0.4 |
| Published | 2026-10-30 |
| First published | 2020-10-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | rxzhu |
| Maintainers | wu_han, bjnsc_zrx, zero_zrx |
| Keywords | @bj-nsc/functions |

## Links

- npm: https://www.npmjs.com/package/@bj-nsc/functions
- npm.io page: https://npm.io/package/@bj-nsc/functions

## Recent versions

- 2.0.4 (latest) — 2026-10-30
- 2.0.3 — 2026-10-29
- 2.0.2 — 2026-10-22
- 2.0.1 — 2026-10-22
- 2.0.0 — 2026-10-22
- 1.4.7 — 2026-07-09
- 1.4.6 — 2025-09-22
- 1.4.5 — 2024-11-13
- 1.4.4 — 2023-08-17
- 1.4.3 — 2023-08-17
- 1.4.2 — 2023-08-05
- 1.4.1 — 2023-08-05
- 1.4.0 — 2023-08-05
- 1.3.5 — 2022-10-28
- 1.3.4 — 2022-10-09
- … 80 more at https://npm.io/package/@bj-nsc/functions/versions

## README

### nsc-functions

浏览器和工程项目共用的工具函数库。

### 安装

```javascript
// 安装
npm install @bj-nsc/functions --save;
// 或者
yarn add @bj-nsc/functions;
```

### 工程项目使用

```javascript
import { sm3Encrypt, guid, getStorage } from "@bj-nsc/functions";

console.log(sm3Encrypt("test"));
console.log(guid());
console.log(getStorage("token"));
```

### Script 引入

执行 `npm run build:browser` 后会生成 `dist/nsc-functions.min.js`，可以直接通过 `<script>` 标签使用，默认挂载到全局变量 `NscUtils`。

```html
<script src="https://unpkg.com/@bj-nsc/functions/dist/nsc-functions.min.js"></script>
<script>
  const { sm3Encrypt, guid, getStorage } = NscUtils;

  console.log(sm3Encrypt("test"));
  console.log(guid());
  console.log(getStorage("token"));
</script>
```

也可以使用 jsDelivr：

```html
<script src="https://cdn.jsdelivr.net/npm/@bj-nsc/functions/dist/nsc-functions.min.js"></script>
```

如果需要固定版本，建议在 CDN 地址里显式带上版本号：

```html
<script src="https://unpkg.com/@bj-nsc/functions@2.0.0/dist/nsc-functions.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@bj-nsc/functions@2.0.0/dist/nsc-functions.min.js"></script>
```

### 浏览器构建配置说明

浏览器包通过下面这条命令生成：

```bash
npm run build:browser
```

这条命令会先清理 `dist` 目录，再读取根目录的 `esbuild.browser.config.cjs` 进行构建。

- 构建配置文件：`esbuild.browser.config.cjs`
- 浏览器输出文件：`dist/nsc-functions.min.js`
- 浏览器全局变量：`NscUtils`
- 浏览器输出格式：`iife`

当前这份浏览器构建配置主要负责两件事：

- 把 `src/index.ts` 直接打成浏览器可通过 `<script>` 使用的单文件产物
- 用 `NscUtils` 作为浏览器全局入口，供页面直接访问工具方法

---
_Source: https://npm.io/package/@bj-nsc/functions · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
