Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.
hb432 edited this page Apr 1, 2021 · 3 revisions

@grakkit/core

This page documents the methods and functions available in this package, given that variable core refers to require('@grakkit/core').

core.array(object: any)

  • Returns: <any[]>

Converts Java Iterables, Java Iterators, and Java Spliterators into JavaScript Arrays. If a JavaScript array is passed, a clone is created and returned. If none of the above is passed, returns null.

core.chain(base: any, modifier: (input: any, callback: (object: any) => any))

  • Returns: <void>

base is any value. modifier is a function with 2 arguments -- input is a value, which refers to base the first time modifier is called, and callback is a function which takes a new value and passes it back through modifier as well as a new callback.

Example: Log all properties of an object recursively

// test variable
const test = { a: 'b', c: 'd', e: [ 'f', 'g', { h: 'i', j: 'k', l: 'm' } ] };

// top-level call
core.chain(test, (input, callback) => {
   if (typeof input === 'object') {
      // pass properties back into modifier
      if (typeof input[Symbol.iterator] === 'function') {
         for (const value of input) callback(value);
      } else {
         for (const value of Object.values(input)) callback(value);
      }
   } else {
      // log non-object input to console
      console.log(input);
   }
});

core.data(path: string, ...more: string[])

  • Returns: <any>

Does a very epic thing (need to write description)