sm-utility
raw JSON → 2.4.29 verified Sat Apr 25 auth: no javascript
Reusable utility codes for internal SmariTrips projects, bundled with TypeScript types. Version 2.4.29 is the current stable release. It provides common helpers (e.g., date formatting, number parsing) to standardize code across the company. No external dependencies. Unlike broader libraries (lodash, date-fns), it is purpose-built for SM's internal conventions and is not intended for public use. Development is ongoing within the organization, with npm link as the primary install method.
Common errors
error Cannot find module 'sm-utility' or its corresponding type declarations. ↓
cause Missing installation or package not linked locally.
fix
Run
npm link path-to/sm-utils or install from registry with npm install sm-utility. error ERR_REQUIRE_ESM: require() of ES Module ↓
cause The package is ESM-only, but a require() was used.
fix
Replace
require('sm-utility') with import('sm-utility') or use an ESM wrapper. error Uncaught TypeError: date is not a function ↓
cause Importing the default export, but there is no default export.
fix
Use named import:
import { formatDate } from 'sm-utility'. Warnings
gotcha Package is ESModule-only; it cannot be required() in CommonJS. ↓
fix Use dynamic import() or configure Node.js to load ESM packages.
gotcha All functions have locale-specific behavior (pt-BR assumed). Working with non-BR dates/numbers may produce unexpected results. ↓
fix Verify expected locale; the package is designed for Brazilian Portuguese.
deprecated Function `toCurrency` is deprecated in 2.4.0+ in favor of `formatCurrency`. ↓
fix Replace `toCurrency` calls with `formatCurrency`.
Install
npm install sm-utility yarn add sm-utility pnpm add sm-utility Imports
- formatDate wrong
import formatDate from 'sm-utility'correctimport { formatDate } from 'sm-utility' - parseNumber wrong
const parseNumber = require('sm-utility').parseNumbercorrectimport { parseNumber } from 'sm-utility' - type Helpers
import type { Helpers } from 'sm-utility'
Quickstart
import { formatDate, parseNumber } from 'sm-utility';
const date = formatDate('2024-01-15', 'DD/MM/YYYY');
console.log(date); // '15/01/2024'
const num = parseNumber('1.234,56');
console.log(num); // 1234.56