Nostradamus Prophecy Machine

    @leiops/helpers

    1.3.6 • Public • Published

    @leiops/helpers

    npm npm

    A collection of JavaScript helper functions.

    Usage

    import { startCase } from '@leiops/helpers'
     
    export const filterName = name => startCase(startCase(name.split(" ")[0]))
     

    Adapter

    This library provides an adapter function which allows you to augment and customize our helpers.

    We keep a libraries directory for external code which we've altered slightly to fit our needs. This is the perfect place for our configuration file. The directory structure looks something like this:

    libraries/
      ...
      helpers/
        adapter.js
        sortUsers.js
      ...

    You could also place this directly within a helpers directory and treat it like internal code.

    adapter.js takes advantage of several of the features explained in the following sections, so we won't go into that now.

    import { adapter } from '../../node_modules/@leiops/helpers'
    import { sortUsers } from './sortUsers.js'
     
    export default adapter({
      // add your own helpers to the library
      inject: {
        sortUsers,
      },
      // access helpers already in the library using different names
      alias: {
        arrangeUsers: 'sortUsers',
      },
    })

    Note that all injections and aliases will overwrite existing functions.

    Finally, you can provide an alias in your webpack configuration:

      ...
      resolve: {
        ...
        alias: {
          'helpers': './libraries/helpers/adapter',
          ...
        },
        ...
      }
      ...

    Helper Structure

    helper(...args, options={})

    Args is the arbitrary number of arguments a helper needs to to its work, and options is an object of configuration flags or other settings.

    Helpers should be complete with their own jsdoc-style documentation, or at least a simple comment above describing what they expect and return.

    /**
     * Creates an array of given `length`, where each item is the specified `filler` or null.
     *
     * @param {number} [number=0] The desired length of the array.
     * @param {any} [any=null] What to fill the array with.
     * @returns {array} Returns the constructed array.
     */
     
    export function constructArray(length=0, filler=null) {
      const result = []
      for (let i = 0; i < length; i++) result.push(filler)
      return result
    }

    Keywords

    none

    Install

    npm i @leiops/helpers

    DownloadsWeekly Downloads

    0

    Version

    1.3.6

    License

    UNLICENSED

    Unpacked Size

    708 kB

    Total Files

    27

    Last publish

    Collaborators

    • gnordhielm