npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@fdograph/rut-utilities

v1.4.0

Published

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.

Downloads

26,124

Readme

🇨🇱 Chilean Rut Utilities 🇨🇱

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

:es: Versión en Español


  • :es: Versión en Español
  • :speech_balloon: Intro
  • :rocket: Getting Started
  • :wrench: Usage
  • :page_facing_up: License

: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