**DEPRECATED** Object-oriented utility framework written in TypeScript
MIT License
DEPRECATED: This package is no longer maintained.
The goal of this package was to create a pure object-oriented generic utility library (no static methods, no code in constructors, no class inheritance, etc.).
While achievable, the limitations of the JavaScript/TypeScript language make this goal very cumbersome to reach and I feel the performance penalties and extra verbosity from this approach in this context is not justified in the end.
Object-oriented utility framework written in TypeScript. Heavily inspired by Cactoos.
smalltypes
is available on npm. You can install it using:
npm install --save smalltypes
Using random numbers, mapping values, calculating sum, rounding result, and caching value.
const randomFloat: Scalar<number> =
new RandomizedFloat(// randomized floating point number
new ParkMillerRandom(), // random number generator
1,
10
);
new Cached(// make sure value is only computed once
new Rounded(// round number to desired precision
new Sum(// calculate total from iterable of numbers
new Mapped(// map each item in an iterable to a different value
[
{ id: 1, value: randomFloat.value() },
{ id: 2, value: randomFloat.value() },
{ id: 3, value: randomFloat.value() },
{ id: 4, value: randomFloat.value() },
{ id: 5, value: randomFloat.value() }
],
(item: { readonly value: number }): number =>
item.value // only want the value from each item
)
),
3
)
).value() // calculate and retrieve value
Filtering, limiting, and mapping collection. Comparing two collections for equality.
new EqualIterables(// compare iterables for equality
['Hello', 'World', '!'],
new Mapped(// map each item in an iterable to a different value
new Limited(// limit an iterable to a certain amount of items
new Filtered(// filter an iterable to a subset of items that match callback
[
{ id: 1, name: 'Hello', age: 21 },
{ id: 2, name: 'World', age: 22 },
{ id: 3, name: '!', age: 23 },
{ id: 4, name: 'Not', age: 16 }
],
(item: { readonly age: number }): boolean =>
item.age > 20 // only get items with age greater than 20
),
3
),
(item: { readonly name: string }): string =>
item.name // only want the name from each item
)
).value() // calculate and retrieve value
Clone the repository:
git clone https://github.com/nunof07/smalltypes.git
Change the working directoy:
cd smalltypes
Install dependencies:
npm install
Main tasks:
npm run dev
: Lint, test, and watch for changes.npm run build
: Build library and documentation.npm run coverage
: Test coverage report.npm run commit
: Adds and commits all current changes.Execute npm run info
for information about all available tasks.
dist
: Built files.docs
: API documentation.src/main
: Main source code of the library.src/test
: Unit tests.tasks
: Source code for build tasks and static integration.typings
: Manually specified TypeScript definition files.Note: the Babel configuration at .babelrc
is mainly used for gulp. For the Babel configuration used to build the library see how the Babel Rollup plugin is setup.