typefix
v0.0.2
Published
Type Normalizer & Data Utility untuk JavaScript / Node.js
Downloads
172
Readme
typefix
Utilitas JavaScript ringan untuk normalisasi tipe dan pengelolaan data yang aman
factory, normalizer, dan utility lengkap untuk pengelolaan tipe dan nilai JavaScript — mulai dari tipe primitif, struktur kompleks, data biner, hingga utilitas lanjutan seperti deep clone, deep freeze, dan type detection.
Fitur
- Semua tipe data primitif JavaScript
- Struktur kompleks: Array, Object, Map, Set, WeakMap, WeakSet
- Data biner: Buffer, ArrayBuffer, TypedArray
- Deep clone (aman untuk circular reference)
- Deep freeze (immutable object)
- Normalisasi string → value JavaScript
- Deteksi tipe data yang konsisten
- Builder otomatis dari value
Instalasi
npm install typefixPenggunaan
import typefix from 'typefix';
console.log(typefix.string(123)); // '123'
console.log(typefix.number('42')); // 42
console.log(typefix.boolean('')); // false
console.log(typefix.bigint('9000')); // 9000nAPI
Tipe Primitif
typefix.string(value);
typefix.number(value);
typefix.boolean(value);
typefix.bigint(value);
typefix.symbol(description);
typefix.null();
typefix.undefined();Fungsi & Promise
typefix.fn(() => {});
typefix.fn('return 1 + 1');
typefix.promise((resolve) => resolve(123));
typefix.promise(123); // Promise.resolve(123)⚠️
fn(string)menggunakannew Function— hindari input tak terpercaya.
Struktur Data
Array & Object
typefix.array([1, 2, 3]);
typefix.object({ a: 1 });Map & Set
typefix.map([[key, value]]);
typefix.set([1, 2, 3]);WeakMap & WeakSet
typefix.weakMap([[obj, value]]);
typefix.weakSet([obj]);Tanggal & Regex
typefix.date();
typefix.date('2025-12-23');
typefix.regex('abc', 'i');Data Biner
Buffer (Node.js)
typefix.buffer('hello');ArrayBuffer
typefix.arrayBuffer(8);
typefix.arrayBuffer(existingBuffer);TypedArray
typefix.typedArray('Uint8Array', 8);
typefix.typedArray(Int16Array, [1, 2, 3]);JSON Helper
typefix.json('{"a":1}');
typefix.json({ a: 1 }); // deep clone
typefix.jsonStringify(obj);Utilitas
Deteksi Tipe
typefix.typeOf([]); // 'Array'
typefix.typeOf(new Date()); // 'Date'Normalisasi Value
typefix.normalize('true'); // true
typefix.normalize('42'); // 42
typefix.normalize('{"a":1}'); // { a: 1 }Builder Otomatis
typefix.from('123');
typefix.from([1, 2, 3]);
typefix.from(new Map());Builder ini akan:
- mengkloning struktur data
- mempertahankan tipe aslinya
- aman dari mutasi tidak sengaja
Deep Clone
typefix.deepClone(obj);✔️ Aman untuk:
- circular reference
- Map / Set
- Buffer
- TypedArray
Deep Freeze
typefix.deepFreeze(config);Membuat seluruh struktur objek menjadi immutable secara rekursif.
Filosofi Desain
- Eksplisit lebih baik daripada implisit
- Tidak mengubah data input
- Mengikuti perilaku native JavaScript
- Error lebih baik daripada silent failure
Keamanan
- Tidak melakukan
eval new Functionhanya digunakan secara opsional- Tidak memodifikasi prototype global
