A lightweight TypeScript library for basic data management.
- Installation
- Api
abstract
- Base
WeakData
- Immutability
- Contributing
- Support
- Code of Conduct
- Git
- License
npm install @typescript-package/data --save-peer
import {
// Abstract.
DataCore,
Immutability,
// Class.
// Base.
Data,
Value,
// `WeakData`.
NamedWeakData,
// Indexed.
IndexedWeakData,
// Basic.
WeakData,
} from '@typescript-package/data';
The base abstraction with immutability for handling data-related classes.
The Data
class is a concrete class that wraps a value and provides methods for setting, retrieving, and destroying the value.
import { Data } from '@typescript-package/data';
// Example subclass of Data
class StringData extends Data<string> {
constructor(value: string) {
super(value);
}
}
const data = new StringData("Hello, world!");
// Access the current value
console.log(data.value); // Output: Hello, world!
// Update the value
data.set("New value");
console.log(data.value); // Output: New value
// Destroy the value
data.destroy();
console.log(data.value); // Throws error or undefined (based on how it's handled)
The class to manage the value of generic type variable Type
.
import { Value } from '@typescript-package/data';
Manages the immutability states of this
current instance.
import { Immutability } from '@typescript-package/data';
import { IndexedWeakData } from '@typescript-package/data';
// Create an interface.
export interface Profile {
id: number,
age: number;
score: number;
}
// Initialize multiple instances of `IndexedWeakData`.
export const profileData1 = new IndexedWeakData({ id: 1, age: 27, score: 1100 } as Profile, 'id');
export const profileData2 = new IndexedWeakData({ id: 2, age: 127, score: 1200 } as Profile, 'id');
export const profileData3 = new IndexedWeakData({ id: 3, age: 227, score: 1300 } as Profile, 'id');
export const profileData4 = new IndexedWeakData({ id: 4, age: 327, score: 1400 } as Profile, 'id');
// Get the value by using index.
console.log(`profileData1: `, profileData1.getByIndex(1)); // Output: {id: 1, age: 27, score: 1100}
console.log(`profileData3: `, profileData3.getByIndex(3)); // Output: {id: 3, age: 227, score: 1300}
The WeakData
class is a concrete class that stores data in a static WeakMap
.
import { WeakData } from '@typescript-package/data';
// Example subclass of WeakData
export class StringWeakData extends WeakData<string> {
constructor(value: string) {
super(value);
}
}
// Create a new instance of StringWeakData
export const data = new StringWeakData("Hello, world!");
// Access the current value
console.log(data.value); // Output: Hello, world!
// Update the value
data.set("New value");
console.log(data.value); // Output: New value
// Destroy the value
data.destroy();
Provides structural immutability, but not value immutability. The least strict form of immutability. Sealing an object prevents adding or removing properties, but it does not restrict modifying the values of existing properties.
Provides structural and shallow immutability. Stricter than seal. Freezing an object prevents changes to the object’s properties at the top level. This means that you cannot modify, add, or delete properties, but nested objects can still be mutated.
Combines the features of freeze
, but extends immutability to nested structures(deep immutability).
Locking(deep) an object prevents changing any properties at any level, including properties within nested objects.
Your contributions are valued! If you'd like to contribute, please feel free to submit a pull request. Help is always appreciated.
If you find this package useful and would like to support its and general development, you can contribute through one of the following payment methods. Your support helps maintain the packages and continue adding new.
Support via:
Thanks for your support!
By participating in this project, you agree to follow Code of Conduct.
Given a version number MAJOR.MINOR.PATCH, increment the:
- MAJOR version when you make incompatible API changes,
- MINOR version when you add functionality in a backwards-compatible manner, and
- PATCH version when you make backwards-compatible bug fixes.
Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.
FAQ How should I deal with revisions in the 0.y.z initial development phase?
The simplest thing to do is start your initial development release at 0.1.0 and then increment the minor version for each subsequent release.
How do I know when to release 1.0.0?
If your software is being used in production, it should probably already be 1.0.0. If you have a stable API on which users have come to depend, you should be 1.0.0. If you’re worrying a lot about backwards compatibility, you should probably already be 1.0.0.
MIT © typescript-package (license)
- @typescript-package/affix: A lightweight TypeScript library for the affix - prefix and suffix.
- @typescript-package/are: Type-safe
are
checkers for validating value types in TypeScript. - @typescript-package/descriptor: A lightweight TypeScript library for property descriptor.
- @typescript-package/guard: Type-safe guards for guarding the value types in TypeScript.c
- @typescript-package/history: A TypeScript package for tracking history of values.
- @typescript-package/is: Type-safe is checkers for validating value types in TypeScript.
- @typescript-package/name: A lightweight TypeScript library for the name with prefix and suffix.
- @typescript-package/property: A lightweight TypeScript package with features to handle object properties.
- @typescript-package/queue: A lightweight TypeScript library for managing various queue and stack structures.
- @typescript-package/range: A lightweight TypeScript library for managing various types of ranges.
- @typescript-package/regexp: A lightweight TypeScript library for RegExp.
- @typescript-package/state: Simple state management for different types in TypeScript.
- @typescript-package/type: Utility types to enhance and simplify TypeScript development.
- @typescript-package/wrapper: A lightweight TypeScript library to wrap the text with the opening and closing chars.