Skip to content

typescript-package/set

Repository files navigation

typescript-package/set

npm version GitHub issues GitHub license

A lightweight TypeScript library for enhanced set management.

Table of contents

Installation

1. Install peer data dependencies

npm install @typescript-package/data --save-peer

2. Install the set package

npm install @typescript-package/set --save-peer

Api

import {
  // Abstract.
  CoreSet,
  SetOnHook,

  // Class.
  DataSet,
  ImmutableSet,
} from '@typescript-package/set';

CoreSet

The abstract core class for building customizable Set and DataCore related classes.

import { CoreSet } from '@typescript-package/set';

DataSet

The DataSet is a concrete class that extends CoreSet and encapsulates its data within a DataCore store, providing additional data management capabilities.

import { DataSet } from '@typescript-package/data';

// Define a `DataCore` implementation for holding a data in `DataSet`.
export class CustomSetData<Type> extends Data<Set<Type>> {
  constructor(initialValue?: Set<Type>, ...args: any[]) {
    super(initialValue ?? new Set());
    console.log(`...args: any[]`, args);
  }
}

// Create a new `DataSet` instance with predefined entries and customized data holder.
export const dataSet = new DataSet
(
  [0, 27, 37, 47],
  [CustomSetData, 'a', 'b', 1]
);

console.debug(`dataSet`, dataSet);

// Check the `CustomSetData`.
console.log(`Data holder of \`CustomSetData\`:`, dataSet.data); // Output: CustomSetData {#locked: false, #value: Value}

// Log the size of the set
console.log("Size:", dataSet.size); // Output: Size: 4

// Check if a value exists
console.log("Has 27?", dataSet.has(27)); // Output: Has '27'? true

// Add a new value
dataSet.add(57);
console.log("Size after add:", dataSet.size); // Output: Size after add: 5

// Iterate over entries
dataSet.forEach(value => console.log(`${value}`));
// Output:
// 0
// 27
// 37
// 47
// 57

console.debug(`SymbolValue`, dataSet[SymbolValue]());

// Delete an entry
dataSet.delete(0);
console.log("Size after delete:", dataSet.size); // Output: Size after delete: 4

// Clear the set
dataSet.clear();
console.log("Size after clear:", dataSet.size); // Output: Size after clear: 0

Contributing

Your contributions are valued! If you'd like to contribute, please feel free to submit a pull request. Help is always appreciated.

Support

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!

Code of Conduct

By participating in this project, you agree to follow Code of Conduct.

GIT

Commit

Versioning

Semantic Versioning 2.0.0

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.

License

MIT © typescript-package (license)

Packages

About

A lightweight TypeScript library for enhanced `set` management.

Resources

License

Stars

Watchers

Forks

Packages

No packages published