Unosquare Typescript/JavaScript Library, zero dependencies.
String, array, and Date manipulation, easy-to-use fetch controller, and more, written in Typescript.
To install uno-js through npm, you only need to run the following command:
npm install uno-js --save
Check the documentation of this library at https://unosquare.github.io/uno/uno-js.
Many functions in this library can be replaced by modern browser native APIs. Below are the recommended native alternatives:
Status: ❌ DEPRECATED
// ❌ uno-js
import { getAbortController } from 'uno-js';
const controller = getAbortController();
// ✅ Native API (available since 2017)
const controller = new AbortController();
Status: ❌ DEPRECATED
// ❌ uno-js
import { removeDuplicated } from 'uno-js';
const unique = removeDuplicated(array, 'id');
// ✅ Native API with filtering
const unique = array.filter((item, index, arr) =>
arr.findIndex(x => x.id === item.id) === index
);
// ✅ Or using Set for primitives
const unique = [...new Set(array)];
Status: ❌ DEPRECATED
// ❌ uno-js
import { toTitleCase } from 'uno-js';
const title = toTitleCase('hello world');
// ✅ Native CSS
.title-case { text-transform: capitalize; }
// ✅ Or with simple regex
const title = text.toLowerCase().replace(/\b\w/g, l => l.toUpperCase());
Status: ❌ DEPRECATED
// ❌ uno-js
import { onEnterKey } from 'uno-js';
element.addEventListener('keydown', onEnterKey(callback));
// ✅ Modern Native API
element.addEventListener('keydown', (e) => {
if (e.key === 'Enter') callback(); // More semantic than keyCode
});
Status: ❌ DEPRECATED
// ❌ uno-js
import { SimpleObservable } from 'uno-js';
const obs = new SimpleObservable();
// ✅ Native API - EventTarget
class SimpleObservable extends EventTarget {
inform(data) { this.dispatchEvent(new CustomEvent('change', { detail: data })); }
subscribe(callback) {
this.addEventListener('change', callback);
return () => this.removeEventListener('change', callback);
}
}
Status:
// ❌ uno-js money formatting
import { toMoney } from 'uno-js';
const formatted = toMoney(1234.56);
// ✅ Native API - Intl.NumberFormat
const formatted = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD'
}).format(1234.56);
// ❌ uno-js percentage
import { toPercentage } from 'uno-js';
// ✅ Native API
const percentage = new Intl.NumberFormat('en-US', {
style: 'percent',
minimumFractionDigits: 2
}).format(0.1234);
// ❌ uno-js date formatting
// ✅ Native API - Intl.DateTimeFormat
const dateFormatted = new Intl.DateTimeFormat('en-US').format(new Date());
Status:
// ❌ uno-js
import { compareDates } from 'uno-js';
// ✅ Native API - Date comparison
const compareResult = new Date(a) - new Date(b); // Returns difference in ms
const isAfter = new Date(a) > new Date(b);
// ❌ uno-js toLocalTime
// ✅ Native API - Temporal API (upcoming) or Date methods
const localDate = new Date().toLocaleString();
Status:
// ❌ uno-js
import { groupBy } from 'uno-js';
const grouped = groupBy(data, 'category');
// ✅ Native API - Object.groupBy (Stage 3, Chrome 117+)
const grouped = Object.groupBy(data, item => item.category);
// ✅ Alternative with Map.groupBy
const grouped = Map.groupBy(data, item => item.category);
// ✅ Fallback with reduce
const grouped = data.reduce((acc, item) => {
(acc[item.category] ??= []).push(item);
return acc;
}, {});
Status: ✅ KEEP - No native API equivalent, but it's a standard implementation.
Status: ✅ KEEP - Solves JavaScript-specific floating-point precision issues.
Status: ✅ KEEP - Business-specific functionality with no native equivalent.
Status: ✅ KEEP - Complex business logic. Temporal API (future) might partially replace.
Status: ✅ KEEP - Business-specific type, though formatting can use Intl.NumberFormat.
Status: ${variable}
) cover most cases.
Status: ✅ KEEP - Specific mathematical logic with no direct equivalent.
Status: ✅ KEEP - Specific validation utilities.
- Immediate: Replace
abortController
,removeDuplicated
,toTitleCase
,withEnter
,SimpleObservable
- Short term: Migrate formatting to
Intl
APIs where possible - Medium term: Evaluate
groupBy
whenObject.groupBy
has better support - Long term: Monitor Temporal API to replace date utilities
- AbortController: Chrome 66+, Firefox 57+, Safari 11.1+
- Intl.NumberFormat: Chrome 24+, Firefox 29+, Safari 10+
- Object.groupBy: Chrome 117+, Firefox 119+ (Stage 3)
- EventTarget constructor: Chrome 64+, Firefox 59+, Safari 14+