Socket
Socket
Sign inDemoInstall

@leiops/helpers

Package Overview
Dependencies
6
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @leiops/helpers

JavaScript helpers for use within the Ops client.


Version published
Maintainers
1
Install size
8.56 MB
Created

Readme

Source

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

FAQs

Last updated on 07 Nov 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc