@leiops/helpers
JavaScript helpers for use within the Ops client.
Last updated a year ago by gnordhielm .
UNLICENSED · Original npm · Tarball · package.json
$ cnpm install @leiops/helpers 
SYNC missed versions from official npm registry.

@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
}

Current Tags

  • 1.3.6                                ...           latest (a year ago)

21 Versions

  • 1.3.6                                ...           a year ago
  • 1.3.5                                ...           a year ago
  • 1.3.4                                ...           a year ago
  • 1.3.3                                ...           a year ago
  • 1.3.2                                ...           a year ago
  • 1.3.1                                ...           a year ago
  • 1.3.0                                ...           2 years ago
  • 1.2.3                                ...           2 years ago
  • 1.2.2                                ...           2 years ago
  • 1.2.1                                ...           2 years ago
  • 1.2.0                                ...           2 years ago
  • 1.1.6                                ...           2 years ago
  • 1.1.5                                ...           2 years ago
  • 1.1.3                                ...           2 years ago
  • 1.1.2                                ...           2 years ago
  • 1.1.1                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
  • 1.0.0-alpha.2                                ...           2 years ago
  • 1.0.0-alpha.1                                ...           2 years ago
  • 1.0.0-alpha.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 3
Last Day 0
Last Week 2
Last Month 21
Dependencies (6)
Dev Dependencies (12)

Copyright 2014 - 2016 © taobao.org |