A Good Core typescript library with utility functions and effective data structures for use with both Node and browser.
It brings:
It contains ...
the following JSON.stringify -able data structures:
general utility objects:
method combinator decorators:
mixins:
and lots of utility functions for:
Version 1.0.0 Changes
Global.noDeprecationWarnings = true;
mixin()
now mixes objects deep in the case when the target and the source both have a property value with the object type.function deprecate<T extends Function>(instead: string, fn: T): T
getFunctionName()
in favor of Function.prototype.name
getFunctionCode()
since it did not feel very "core" and was not handling any variations of arrow functions. Replace with .toString and a regex of your choice.Caveat
Iterator support in List and SortedList requires that the browser supports it too. So if you have to support a browser which do not such as IE11 then please use a polyfill like core.js.
Examples
Here is a small example that makes no sense other than show what the lib looks like in use.
import { Initable, List, provided, Range2, Util, Vec2 } from "goodcore";
let world = new Range2(2, 2, 8, 8); //x,y,h,w
function inWorld(point: IVec2): boolean {
return world.containsPoint(point);
}
class BaseLogger {
private _list: List<Vec2> = new List<Vec2>();
public id: string = "";
@provided(inWorld)
public log(point: IVec2) {
this._list.add(new Vec2().set(point));
}
public search(point: IVec2): List<Vec2> {
return this._list.select((p, i) => p.equals(point)).clone();
}
public get list(): List<Vec2> {
return this._list.clone();
}
}
class Logger extends Initable(BaseLogger) {}
// log in the order of distance from 0,0
let logger: Logger = new Logger().init({id: Util.newUUID()}) as Logger;
logger.log({x: 1, y: 3});
logger.log({x: 4, y: 4});
logger.log({x: 5, y: 5});
logger.log({x: 7, y: 8});
logger.log({x: 9, y: 3});
console.log(logger.id);
logger.list
.orderBy((a, b) => a.length() - b.length())
.forEach((p) => console.log(p.x, p.y));
let contains = logger.search({x: 4, y: 4});
console.log(`does the log contain point 4,4? ${contains.count > 0}`);
Contribute
Found a bug? GREAT! Raise an issue!
When developing, please:
Author: allnamesrtaken
Source Code: https://github.com/allnamesrtaken/goodcore
License: MIT license