.extend()
Extends the base Database class by adding/overwriting methods.
extend(extensions)
Parameter
Description
extensions
An object with the methods
Returns
Description
A modified version of the base Database class with the new methods
const extendedDb = db.extend({
  // Add new methods
  chunk(key, count) {
    const array = this.get(key);
    const newArr = [];
    for (var i = 0; i < array.length; i+=count)
      newArr[i/count] = array.slice(i, i+count);
      
    return newArr;
  },
  // Overwrite existing methods
  delete: (key) => {
    // Whatever you wanna do here.
  }
})
extendedDb.set('someArray', [1,2,3,4,5]); // [1,2,3,4,5]
extendedDb.chunk('someArray', 2); // [[1,2], [3,4], [5]]Last updated
Was this helpful?