getBody()
Extracts just the body (without verifier digit) from a RUT string.
Basic Usage#
TypeScript
import { getBody } from 'rut.ts'
getBody('12.345.678-5') // '12345678'
getBody('9068826K') // '9068826'Type Signature#
TypeScript
function getBody(rut: string): string
function getBody(rut: string, options: { throwOnError: false }): string | null
function getBody(rut: string, options: { throwOnError: true }): stringParameters#
rut(string) - The RUT stringoptions(optional)throwOnError(boolean, default:true) - If false, returnsnullinstead of throwing
Return Value#
- Default mode: Returns body string (7-8 digits) or throws a generic
Invalid RUT inputerror - Safe mode: Returns body string or
nullif invalid
v4.0.0: non-string inputs (numbers,
null,undefined, objects) are treated like any other invalid input — they returnnullin safe mode and throw the generic error otherwise, instead of throwing aTypeError.
Examples#
Basic Extraction#
TypeScript
import { getBody } from 'rut.ts'
getBody('12.345.678-5') // '12345678'
getBody('18.972.631-7') // '18972631'
getBody('9.068.826-K') // '9068826'Safe Mode#
TypeScript
import { getBody } from 'rut.ts'
const body = getBody('invalid', { throwOnError: false })
console.log(body) // nullUse Cases#
- ✅ Extract body for database queries
- ✅ Compare RUT bodies (ignoring verifier)
- ✅ Process body separately
- ✅ Quick body extraction without full decomposition
Related Functions#
getVerifier()- Extract verifier digitdecompose()- Get both body and verifier