An annotation which is shared among all Saber methods. Enforces developer to make a method pure. Other than this, it has nothing but an empty body. Since the library is functional an annotation like that is crucial.
Pure Annotation
1
2
3
4
5
class NativeClass {
@Pure() nativeMethod(){} }
Important Note
PureMethod annotation is used in every Saber method.
SaberCore
classNamestring
returnsSaberCore
Implements IHash and IStringIndex
Creates a new SaberCore. When a class implements IHashit contains a uidproperty. Implementing IStringIndex interface is merely for object indexing in TypeScript. SaberCore is a class which every Saber class should extend. It also has a readonly value for holding value type in a Saber class. But it cannot write the value in the constructor. This property is only defined to compel developer.
Class Initialisation
1
2
3
4
// You can't import SaberCore
const saberCore = new SaberCore('NativeObject') console.log(saberCore)
Output
SaberCore { className:"NativeObject", uid:323920221566, value:"Cannot assign any value to SaberCore." }
Important Note
Every Saber class extends this core class.
SaberObject
Extends SaberCore
A class that encapsulates a JavaScript Object with enhanced immutable methods.
create
valueSaberObject | object | any
returnsSaberObject
static
Creates a new SaberObject. Designed as a static factory method. I totally recommend using this over normal initialisation.
Creating A Tree Object
1
2
3
4
import{ SaberObject }from'@berakocc/saber'
const tree = SaberObject.create({ fruit:'apple'}) console.log(tree)
Output
t { className:"SaberObject", uid:201606621055, value: Object { fruit:"apple" } }
modify
oobject
objectFunctionObjectFunction
propertyChain?string[ ]
returnsobject
static
Modifies an object without mutating it. Then returns the new object. When propertyChain is not given it, function mutates the property at the root level. This is a utility function for the rest of the class. ObjectFunction is a function which uses bound object asthis and returns an object
Updates array value with the given index and value. indexer can be either a value of array or an index. However there can be a confusion when the array value is number. Therefore you have to use a third argument true when you want to use indexer as a value indexer.