Some core functions and helper classes. List, Dictionary, Stack, Vec2, Rect, Range2, Tree. Optimized for speed and memory efficiency. Also an object pool a few mixins and Helpers for Dom, Array and Object manipulation + general
npm install goodcoreGlobal.noDeprecationWarnings = true;`
- Array functions that had optimized code for older browsers (IE) have had that code removed.
- Obj
- CHANGE: `mixin()` now mixes objects deep in the case when the target and the source both have a property value with the object type.
- Util
- ADDED: `function deprecate(instead: string, fn: T): T `
- REMOVED: `getFunctionName()` in favor of `Function.prototype.name`
- REMOVED: `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.
`typescript
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 = new List();
public id: string = "";
@provided(inWorld)
public log(point: IVec2) {
this._list.add(new Vec2().set(point));
}
public search(point: IVec2): List {
return this._list.select((p, i) => p.equals(point)).clone();
}
public get list(): List {
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});
``