@fdograph/rut-utilities

中文文档
1.4.0发布于 2022/03/02Apache-2.0TypeScriptCommonJS零依赖近 30 天下载 1.9万

Fully typed set of utility functions to parse, validate and generate a Chilean R.U.T. Set de funciones utilitarias para generar, procesar y validar un R.U.T. Chileno completamente tipado.

原始使用文档
文档目录6 节
  1. :es: Versión en Español
  2. :speech_balloon: Intro
  3. :rocket: Getting started
  4. Npm & Yarn install:
  5. :wrench: Usage
  6. :page_facing_up: License

🇨🇱 Chilean Rut Utilities 🇨🇱

Coverage - Branches Coverage - Functions Coverage - Lines Coverage - Statements

:es: Versión en Español


Table of Contents

:speech_balloon: Intro

Fully typed set of utility functions to parse, validate and generate a Chilean R.U.T.

Meant for developers who want to interact, manipulate and validate Chilean R.U.T.

:rocket: Getting started

Npm & Yarn install:

$ npm install @fdograph/rut-utilities

$ yarn add @fdograph/rut-utilities

:top: back to top

:wrench: Usage

validateRut(rut?: string, noSuspicious = true) => boolean

Returns true if the passed string corresponds to a fully valid R.U.T. This is a valid rut-like string that passes the official mathematical validation algorithm and does not conform to the "suspicious" R.U.T. pattern. Eg: 44.444.444-4, 22.222.222-2, 3.333.333-3, 9999999-9

import { validateRut } from '@fdograph/rut-utilities';

validateRut('18585543-0');
> true

validateRut('18.585.543-0');
> true

validateRut('9.999.999-9');
> false

validateRut('44.444.444-4');
> false

To avoid the "suspicious" R.U.T. validation we can override the noSuspicious argument and pass it as false. This will change the behaviour of this method making it skip the "suspicious" pattern validation.

import { validateRut } from '@fdograph/rut-utilities';

validateRut('18585543-0', false);
> true

validateRut('18.585.543-0', false);
> true

validateRut('9.999.999-9', false);
> true

validateRut('44.444.444-4', false);
> true

validateRutList(ruts: Iterable<string>, noSuspicious = false) => Map<string, boolean>

Returns a results Map in which each entry has a key corresponding to the input and the value corresponding to its validation result.

import { validateRutList } from '@fdograph/rut-utilities';

const validRuts = ['7775735-k', '18585543-0', '18348353-6'];
const result = validateRutList(validRuts);

result.get('7775735-k');
> true

result.get(validRuts[1]);
> true


formatRut(rut?: string, format?: RutFormat = RutFormat.DASH) => string

Formats a rut-like string according to the format parameter or returns the intact string if this doesn't match a rut-like string pattern.

enum RutFormat {
    DOTS,
    DASH,
    DOTS_DASH
}
import { formatRut, RutFormat } from '@fdograph/rut-utilities';

formatRut('44.333.222-1');
> '44333222-1'

formatRut('44333222-1', RutFormat.DOTS_DASH);
> '44.333.222-1'

formatRut('44333222-1', RutFormat.DOTS);
> '44.333.2221'

formatRut('jg7gk-1', RutFormat.DOTS);
> 'jg7gk-1'

deconstructRut(rut: string) => DeconstructedRut

Returns an object containing the RUT's digits and verifier.

You can use Destructuring to access each.

type DeconstructedRut = {
  digits: string;
  verifier: string;
}
import { deconstructRut } from '@fdograph/rut-utilities';

const { digits, verifier } = deconstructRut('7775735-k');

console.log(digits);
> '7775735'

console.log(verifier);
> 'k'


You can see the full set of utility functions in the Tests

:page_facing_up: License

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.

:top: back to top

版本与发布记录

@fdograph/rut-utilities 共发布 27 个版本,首次发布于 2020/01/21;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.4.0latest2022/03/024 年前
1.3.72021/08/195 年前
1.3.62021/08/195 年前
1.3.52021/08/055 年前
1.3.42021/08/055 年前
1.3.32021/08/055 年前

关于 @fdograph/rut-utilities 的常见问题

@fdograph/rut-utilities 是什么?

Fully typed set of utility functions to parse, validate and generate a Chilean R.U.T. Set de funciones utilitarias para generar, procesar y validar un R.U.T. Chileno completamente tipado.

如何安装 @fdograph/rut-utilities?

在项目目录运行 npm install @fdograph/rut-utilities,或使用 pnpm add / yarn add / bun add。

@fdograph/rut-utilities 支持 TypeScript 吗?

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

@fdograph/rut-utilities 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@fdograph/rut-utilities 可以商用吗?

@fdograph/rut-utilities 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@fdograph/rut-utilities 的下载量有多少?

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

@fdograph/rut-utilities 还在维护吗?

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