|
| 1 | + |
| 2 | +<a href="https://www.typescriptlang.org/"> |
| 3 | + <img |
| 4 | + src="https://avatars.githubusercontent.com/u/189666396?s=150&u=9d55b1eb4ce258974ead76bf07ccf49ef0eb0ea7&v=4" |
| 5 | + title="The typescript package enhances the development of typescript-based applications by providing well-structured, reusable, easy-to-use packages." |
| 6 | + /> |
| 7 | +</a> |
| 8 | + |
| 9 | +## typescript-package/data |
| 10 | + |
| 11 | +<!-- npm badge --> |
| 12 | +[![npm version][typescript-package-npm-badge-svg]][typescript-package-npm-badge] |
| 13 | +[![GitHub issues][typescript-package-badge-issues]][typescript-package-issues] |
| 14 | +[![GitHub license][typescript-package-badge-license]][typescript-package-license] |
| 15 | + |
| 16 | +A **TypeScript** library for simple managing data. |
| 17 | + |
| 18 | +## Table of contents |
| 19 | + |
| 20 | +- [Installation](#installation) |
| 21 | +- [Api](#api) |
| 22 | + - [`Data`](#data) |
| 23 | + - [`DataCore`](#datacore) |
| 24 | + - [`Immutability`](#immutability) |
| 25 | + - [`NamedWeakData`](#namedweakdata) |
| 26 | + - [`Value`](#value) |
| 27 | + - [`WeakData`](#weakdata) |
| 28 | +- [Immutability](#immutability) |
| 29 | + - [Sealed](#sealed) |
| 30 | + - [Frozen](#frozen) |
| 31 | + - [Locked](#locked) |
| 32 | +- [Contributing](#contributing) |
| 33 | +- [Support](#support) |
| 34 | +- [Code of Conduct](#code-of-conduct) |
| 35 | +- [Git](#git) |
| 36 | + - [Commit](#commit) |
| 37 | + - [Versioning](#versioning) |
| 38 | +- [License](#license) |
| 39 | + |
| 40 | +## Installation |
| 41 | + |
| 42 | +```bash |
| 43 | +npm install @typescript-package/data --save-peer |
| 44 | +``` |
| 45 | + |
| 46 | +## Api |
| 47 | + |
| 48 | +```typescript |
| 49 | +import { |
| 50 | + // Abstract. |
| 51 | + Data, |
| 52 | + DataCore, |
| 53 | + Immutability, |
| 54 | + NamedWeakData, |
| 55 | + WeakData, |
| 56 | + |
| 57 | + // Class. |
| 58 | + Value |
| 59 | +} from '@typescript-package/data'; |
| 60 | +``` |
| 61 | + |
| 62 | +### `Data` |
| 63 | + |
| 64 | +The `Data` class is an abstract base class that wraps a value and provides methods for setting, retrieving, and destroying the value. |
| 65 | + |
| 66 | +```typescript |
| 67 | +import { Data } from '@typescript-package/data'; |
| 68 | + |
| 69 | +// Example subclass of Data |
| 70 | +class StringData extends Data<string> { |
| 71 | + constructor(value: string) { |
| 72 | + super(value); |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +const data = new StringData("Hello, world!"); |
| 77 | + |
| 78 | +// Access the current value |
| 79 | +console.log(data.value); // Output: Hello, world! |
| 80 | + |
| 81 | +// Update the value |
| 82 | +data.set("New value"); |
| 83 | +console.log(data.value); // Output: New value |
| 84 | + |
| 85 | +// Destroy the value |
| 86 | +data.destroy(); |
| 87 | +console.log(data.value); // Throws error or undefined (based on how it's handled) |
| 88 | +``` |
| 89 | + |
| 90 | +### `DataCore` |
| 91 | + |
| 92 | +The base abstraction for data-related classes. |
| 93 | + |
| 94 | +### `Immutability` |
| 95 | + |
| 96 | +Manages the immutability states of `this` current instance. |
| 97 | + |
| 98 | +### `NamedWeakData` |
| 99 | + |
| 100 | +```typescript |
| 101 | +import { NamedWeakData } from '@typescript-package/data'; |
| 102 | + |
| 103 | +// Define a class that extends NamedWeakData |
| 104 | +export class ProfileData extends NamedWeakData<number, 'age' | 'score'> {} |
| 105 | + |
| 106 | +// Create two instances with different names |
| 107 | +const ageData = new ProfileData(25, 'age'); |
| 108 | +const scoreData = new ProfileData(90, 'score'); |
| 109 | + |
| 110 | +// Access the values stored in each instance using their respective names |
| 111 | +console.log(ageData.value); // Outputs: 25 |
| 112 | +console.log(scoreData.value); // Outputs: 90 |
| 113 | + |
| 114 | +// You can also retrieve the data from another instance using the static method `getFrom` |
| 115 | +console.log(NamedWeakData.getFrom(ageData, 'age')); // Outputs: 25 |
| 116 | +console.log(NamedWeakData.getFrom(scoreData, 'score')); // Outputs: 90 |
| 117 | + |
| 118 | +// Setting new values |
| 119 | +ageData.set(30); |
| 120 | +console.log(ageData.value); // Outputs: 30 |
| 121 | + |
| 122 | +// Destroy an instance and clear its stored data |
| 123 | +ageData.destroy(); |
| 124 | +console.log(NamedWeakData.getFrom(ageData, 'age')); // Outputs: undefined |
| 125 | + |
| 126 | +// Clear all stored values from the map |
| 127 | +scoreData.clear(); |
| 128 | +console.log(NamedWeakData.getFrom(scoreData, 'score')); // Outputs: undefined |
| 129 | + |
| 130 | +``` |
| 131 | + |
| 132 | +### `WeakData` |
| 133 | + |
| 134 | +The `WeakData` class is an abstract base class that stores data in a static `WeakMap`. |
| 135 | + |
| 136 | +```typescript |
| 137 | +import { WeakData } from '@typescript-package/data'; |
| 138 | + |
| 139 | +// Example subclass of WeakData |
| 140 | +class StringWeakData extends WeakData<string> { |
| 141 | + constructor(value: string) { |
| 142 | + super(value); |
| 143 | + } |
| 144 | +} |
| 145 | + |
| 146 | +// Create a new instance of StringWeakData |
| 147 | +const data1 = new StringWeakData("Hello, world!"); |
| 148 | + |
| 149 | +// Access the current value |
| 150 | +console.log(data1.value); // Output: Hello, world! |
| 151 | + |
| 152 | +// Update the value |
| 153 | +data1.set("New value"); |
| 154 | +console.log(data1.value); // Output: New value |
| 155 | + |
| 156 | +// Destroy the value |
| 157 | +data1.destroy(); |
| 158 | +``` |
| 159 | + |
| 160 | +### `Value` |
| 161 | + |
| 162 | +The class to manage the value of generic type variable `Type`. |
| 163 | + |
| 164 | +## Immutability |
| 165 | + |
| 166 | +### Sealed |
| 167 | + |
| 168 | +Provides structural immutability, but not value immutability. The least strict form of immutability. |
| 169 | +Sealing an object prevents adding or removing properties, but it does not restrict modifying the values of existing properties. |
| 170 | + |
| 171 | +### Frozen |
| 172 | + |
| 173 | +Provides structural and shallow immutability. Stricter than seal. |
| 174 | +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. |
| 175 | + |
| 176 | +### Locked |
| 177 | + |
| 178 | +Combines the features of `freeze`, but extends immutability to nested structures(deep immutability). |
| 179 | +Locking(deep) an object prevents changing any properties at any level, including properties within nested objects. |
| 180 | + |
| 181 | +## Contributing |
| 182 | + |
| 183 | +Your contributions are valued! If you'd like to contribute, please feel free to submit a pull request. Help is always appreciated. |
| 184 | + |
| 185 | +## Support |
| 186 | + |
| 187 | +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. |
| 188 | + |
| 189 | +Support via: |
| 190 | + |
| 191 | +- [Stripe](https://donate.stripe.com/dR614hfDZcJE3wAcMM) |
| 192 | +- [Revolut](https://checkout.revolut.com/pay/048b10a3-0e10-42c8-a917-e3e9cb4c8e29) |
| 193 | + |
| 194 | +Thanks for your support! |
| 195 | + |
| 196 | +## Code of Conduct |
| 197 | + |
| 198 | +By participating in this project, you agree to follow **[Code of Conduct](https://www.contributor-covenant.org/version/2/1/code_of_conduct/)**. |
| 199 | + |
| 200 | +## GIT |
| 201 | + |
| 202 | +### Commit |
| 203 | + |
| 204 | +- [AngularJS Git Commit Message Conventions][git-commit-angular] |
| 205 | +- [Karma Git Commit Msg][git-commit-karma] |
| 206 | +- [Conventional Commits][git-commit-conventional] |
| 207 | + |
| 208 | +### Versioning |
| 209 | + |
| 210 | +[Semantic Versioning 2.0.0][git-semver] |
| 211 | + |
| 212 | +**Given a version number MAJOR.MINOR.PATCH, increment the:** |
| 213 | + |
| 214 | +- MAJOR version when you make incompatible API changes, |
| 215 | +- MINOR version when you add functionality in a backwards-compatible manner, and |
| 216 | +- PATCH version when you make backwards-compatible bug fixes. |
| 217 | + |
| 218 | +Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format. |
| 219 | + |
| 220 | +**FAQ** |
| 221 | +How should I deal with revisions in the 0.y.z initial development phase? |
| 222 | + |
| 223 | +> 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. |
| 224 | +
|
| 225 | +How do I know when to release 1.0.0? |
| 226 | + |
| 227 | +> 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. |
| 228 | +
|
| 229 | +## License |
| 230 | + |
| 231 | +MIT © typescript-package ([license][typescript-package-license]) |
| 232 | + |
| 233 | +## Packages |
| 234 | + |
| 235 | +- **[@typescript-package/affix](https://github.com/typescript-package/affix)**: A **lightweight TypeScript** library for the affix - prefix and suffix. |
| 236 | +- **[@typescript-package/are](https://github.com/typescript-package/are)**: Type-safe `are` checkers for validating value types in TypeScript. |
| 237 | +- **[@typescript-package/descriptor](https://github.com/typescript-package/descriptor)**: A **lightweight TypeScript** library for property descriptor. |
| 238 | +- **[@typescript-package/guard](https://github.com/typescript-package/guard)**: Type-safe guards for guarding the value types in TypeScript.c |
| 239 | +- **[@typescript-package/history](https://github.com/typescript-package/history)**: A **TypeScript** package for tracking history of values. |
| 240 | +- **[@typescript-package/is](https://github.com/typescript-package/is)**: Type-safe is checkers for validating value types in TypeScript. |
| 241 | +- **[@typescript-package/name](https://github.com/typescript-package/name)**: A **lightweight TypeScript** library for the name with prefix and suffix. |
| 242 | +- **[@typescript-package/property](https://github.com/typescript-package/property)**: A **lightweight TypeScript** package with features to handle object properties. |
| 243 | +- **[@typescript-package/queue](https://github.com/typescript-package/queue)**: A **lightweight TypeScript** library for managing various queue and stack structures. |
| 244 | +- **[@typescript-package/range](https://github.com/typescript-package/range)**: A **lightweight TypeScript** library for managing various types of ranges. |
| 245 | +- **[@typescript-package/regexp](https://github.com/typescript-package/regexp)**: A **lightweight TypeScript** library for **RegExp**. |
| 246 | +- **[@typescript-package/state](https://github.com/typescript-package/state)**: Simple state management for different types in **TypeScript**. |
| 247 | +- **[@typescript-package/type](https://github.com/typescript-package/type)**: Utility types to enhance and simplify **TypeScript** development. |
| 248 | +- **[@typescript-package/wrapper](https://github.com/typescript-package/wrapper)**: A **lightweight TypeScript** library to wrap the text with the opening and closing chars. |
| 249 | + |
| 250 | +<!-- This package: typescript-package --> |
| 251 | + <!-- GitHub: badges --> |
| 252 | + [typescript-package-badge-issues]: https://img.shields.io/github/issues/typescript-package/data |
| 253 | + [isscript-package-badge-forks]: https://img.shields.io/github/forks/typescript-package/data |
| 254 | + [typescript-package-badge-stars]: https://img.shields.io/github/stars/typescript-package/data |
| 255 | + [typescript-package-badge-license]: https://img.shields.io/github/license/typescript-package/data |
| 256 | + <!-- GitHub: badges links --> |
| 257 | + [typescript-package-issues]: https://github.com/typescript-package/data/issues |
| 258 | + [typescript-package-forks]: https://github.com/typescript-package/data/network |
| 259 | + [typescript-package-license]: https://github.com/typescript-package/data/blob/master/LICENSE |
| 260 | + [typescript-package-stars]: https://github.com/typescript-package/data/stargazers |
| 261 | +<!-- This package --> |
| 262 | + |
| 263 | +<!-- Package: typescript-package --> |
| 264 | + <!-- npm --> |
| 265 | + [typescript-package-npm-badge-svg]: https://badge.fury.io/js/@typescript-package%2Fdata.svg |
| 266 | + [typescript-package-npm-badge]: https://badge.fury.io/js/@typescript-package%2Fdata |
| 267 | + |
| 268 | +<!-- GIT --> |
| 269 | +[git-semver]: http://semver.org/ |
| 270 | + |
| 271 | +<!-- GIT: commit --> |
| 272 | +[git-commit-angular]: https://gist.github.com/stephenparish/9941e89d80e2bc58a153 |
| 273 | +[git-commit-karma]: http://karma-runner.github.io/0.10/dev/git-commit-msg.html |
| 274 | +[git-commit-conventional]: https://www.conventionalcommits.org/en/v1.0.0/ |
0 commit comments