@rustable/utils
Advanced tools
Comparing version 0.1.4 to 0.1.5
@@ -7,1 +7,2 @@ export * from './clone'; | ||
export * from './type_id'; | ||
export * from './mut'; |
@@ -13,2 +13,4 @@ "use strict"; | ||
var mut = require("./mut.js"); | ||
exports.deepClone = clone.deepClone; | ||
@@ -23,1 +25,3 @@ | ||
exports.typeId = type_id.typeId; | ||
exports.Mut = mut.Mut; |
{ | ||
"name": "@rustable/utils", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "Utility TypeScript utilities inspired by Rust, providing type-safe implementations of HashMap, TypeId, deep cloning, hashing, and equality comparison", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
# @rustable/utils | ||
This is the utilities package of the Rustable project, providing fundamental utilities and type management functionalities. The package implements essential features like type identification, object cloning, hashing, and string manipulation. | ||
This is the utilities package of the Rustable project, providing fundamental utilities and type management functionalities. The package implements essential features like type identification, object cloning, hashing, string manipulation, and mutable references. | ||
@@ -44,2 +44,7 @@ ## Installation | ||
### Mutable Reference (`mut.ts`) | ||
- Provides a mutable reference with getter and setter functions | ||
- Supports generic types for flexible usage | ||
## Usage | ||
@@ -50,3 +55,3 @@ | ||
```typescript | ||
import { typeId, clone, hash, stringify } from '@rustable/utils'; | ||
import { typeId, clone, hash, stringify, Mut } from '@rustable/utils'; | ||
``` | ||
@@ -112,2 +117,28 @@ | ||
### Example: Using Mutable Reference | ||
```typescript | ||
import { Mut } from '@rustable/utils'; | ||
let value = 10; | ||
const mutRef = new Mut( | ||
() => value, | ||
(newValue) => { | ||
value = newValue; | ||
}, | ||
); | ||
console.log(mutRef.value); // Output: 10 | ||
mutRef.value = 20; | ||
console.log(mutRef.value); // Output: 20 | ||
// Using Mut.of static method | ||
const anotherMutRef = Mut.of( | ||
() => value, | ||
(newValue) => { | ||
value = newValue; | ||
}, | ||
); | ||
``` | ||
## Notes | ||
@@ -118,2 +149,3 @@ | ||
- Generic type support is available where applicable | ||
- The `Mut` class provides a way to create mutable references with custom getter and setter functions | ||
@@ -120,0 +152,0 @@ ## License |
Sorry, the diff of this file is not supported yet
29222
24
778
151