@typedly/constructor
v1.0.0
Published
A TypeScript type definitions package to handle various types of constructors.
Maintainers
Readme
typedly/constructor
A TypeScript type definitions package to handle various types of constructors.
Table of contents
Installation
npm install @typedly/constructor --save-peerApi
import {
// Namespace.
Typedly,
// Interface.
ConstrainedConstructor,
Constructor,
DataConstructor,
MapTypeConstructor,
SetTypeConstructor,
WeakMapTypeConstructor,
WeakSetTypeConstructor,
// Type.
ExtractConstructorArgs
} from '@typedly/constructor';Namespace
Typedly
import { ConstrainedConstructor } from '@typedly/constructor';Interface
ConstrainedConstructor
import { ConstrainedConstructor } from '@typedly/constructor';
interface Animal {
speak(): void;
}
class Dog implements Animal {
constructor(public name: string) {}
speak() {
console.log(`${this.name} barks.`);
}
}
const dogCtor: ConstrainedConstructor<Animal, Dog, [string]> = Dog;
const dog = new dogCtor('Buddy');
dog.speak(); // "Buddy barks."
Constructor
import { Constructor } from '@typedly/constructor';DataConstructor
import { DataConstructor } from '@typedly/constructor';
interface DataCore<T> {
value: T;
set(value: T): void;
}
class Data<T> implements DataCore<T> {
constructor(public value: T) {}
set(value: T) {
this.value = value;
}
}
const dataCtor: DataConstructor<number, DataCore<number>, Data<number>, []> = Data;
const data = new dataCtor(123);
console.log(data.value); // 123
MapTypeConstructor
import { MapTypeConstructor } from '@typedly/constructor';
const mapCtor: MapTypeConstructor<string, number, Map<string, number>> = Map;
const myMap = new mapCtor([['a', 1], ['b', 2]]);
console.log(myMap.get('a')); // 1
SetTypeConstructor
import { SetTypeConstructor } from '@typedly/constructor';
const setCtor: SetTypeConstructor<string, Set<string>> = Set;
const mySet = new setCtor(['apple', 'banana']);
console.log(mySet.has('banana')); // true
WeakMapTypeConstructor
import { WeakMapTypeConstructor } from '@typedly/constructor';
const weakMapCtor: WeakMapTypeConstructor<object, string, WeakMap<object, string>> = WeakMap;
const keyObj = {};
const myWeakMap = new weakMapCtor([[keyObj, 'value']]);
console.log(myWeakMap.get(keyObj)); // "value"
WeakSetTypeConstructor
import { WeakSetTypeConstructor } from '@typedly/constructor';
const weakSetCtor: WeakSetTypeConstructor<object, WeakSet<object>> = WeakSet;
const obj = {};
const myWeakSet = new weakSetCtor([obj]);
console.log(myWeakSet.has(obj)); // true
Type
ExtractConstructorArgs
import { ExtractConstructorArgs } from '@typedly/constructor';
class MyData {
constructor(value: number, unit: string, verbose: boolean) {}
}
type Args = ExtractConstructorArgs<typeof MyData>; // type Args = [unit: string, verbose: boolean]
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
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 © typedly (license)
Packages
- @typedly/callback: A TypeScript type definitions package for asynchronous and synchronous callback functions of various types.
- @typedly/character: A TypeScript type definitions package for various character types.
- @typedly/check: A lightweight TypeScript type definitions library for type comparison.
- @typedly/context: A TypeScript type definitions package for context data structures.
- @typedly/descriptor: A TypeScript type definitions package for property descriptor.
- @typedly/digit: A TypeScript type definitions package for digit types.
- @typedly/letter: A TypeScript type definitions package for handling letter types.
- @typedly/object: A TypeScript type definitions package to handle object-related operations.
- @typedly/payload: A TypeScript type definitions package for payload data structures.
- @typedly/property: A TypeScript type definitions package to handle object property-related operations.
- @typedly/regexp: A TypeScript type definitions package for
RegExp. - @typedly/symbol: A TypeScript type definitions package for various symbols.
