npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lodash-api-description

v0.0.2

Published

API Description mixins for Lodash

Downloads

22

Readme

API Description Utilities

API Description mixins for Lodash based on the Refract API Description namespace

Usage

This library takes a lodash instance and adds API Description mixins, which are the functions described below. These functions are usable and chainable just like any other Lodash function. Additionally, all Lodash functions are available here.

It is recommended to use these functions and other Lodash functions when interacting with Refract because you get some safety when chaining and looking for data.

content

Takes a Refract element and returns its content, which MAY be of any JavaScript type.

// Returns an array with the resource element
_.content({
  element: 'category',
  content: [
    {
      element: 'resource',
      content: []
    }
  ]
});

contentOrValue

Takes any value and checks if it is Refract element. If it is Refract element then returns its content, which MAY be of any JavaScript type. Otherwise returns value itself.

// Returns passed value
_.contentOrValue('primitive value');

// Returns array with the resource element
_.contentOrValue({
  element: 'category',
  content: [
    {
      element: 'resource',
      content: []
    }
  ]
});

dataStructures

Takes a Refract element and returns an array of all dataStructure elements found in the content.

// Returns array including the one dataStructure element in content
_.dataStructures({
  element: 'category',
  content: [
    {
      element: 'dataStructure',
      content: []
    }
  ]
});

resources

Takes a Refract element and returns an array of all resource elements found in the content.

// Returns array including the one resource element in content
_.resources({
  element: 'category',
  content: [
    {
      element: 'resource',
      content: []
    }
  ]
});

transitions

Takes a Refract element and returns an array of all transition elements found in the content.

// Returns array including the one transition element in content
_.transitions({
  element: 'resource',
  content: [
    {
      element: 'transition',
      content: []
    }
  ]
});

copy

Takes a Refract element and returns an array of all copy elements found in the content.

// Returns array including the one copy element in content
_.copy({
  element: 'category',
  content: [
    {
      element: 'copy',
      content: 'Copy text here'
    }
  ]
});

httpTransactions

Takes a Refract element and returns an array of all httpTransaction elements found in the content.

// Returns array including the one httpTransaction element in content
_.httpTransaction({
  element: 'transition',
  content: [
    {
      element: 'httpTransaction',
      content: []
    }
  ]
});

httpRequests

Takes a Refract element and returns an array of all httpRequest elements found in the content.

// Returns array including the one httpRequest element in content
_.httpRequests({
  element: 'transaction',
  content: [
    {
      element: 'httpRequest',
      content: []
    }
  ]
});

httpResponses

Takes a Refract element and returns an array of all httpResponse elements found in the content.

// Returns array including the one httpResponse element in content
_.httpResponses({
  element: 'transaction',
  content: [
    {
      element: 'httpResponse',
      content: []
    }
  ]
});

messageBodies

Takes a Refract element and returns an array of all messageBody elements found in the content.

// Returns array including the one messageBody element in content
_.messageBodies({
  element: 'httpRequest',
  content: [
    {
      element: 'asset',
      meta: {
        classes: ['messageBody']
      }
      content: 'Body here'
    }
  ]
});

messageBodySchemas

Takes a Refract element and returns an array of all messageBodySchema elements found in the content.

// Returns array including the one messageBodySchema element in content
_.messageBodySchemas({
  element: 'httpRequest',
  content: [
    {
      element: 'asset',
      meta: {
        classes: ['messageBodySchema']
      }
      content: 'Body Schema here'
    }
  ]
});

filterContent

Takes a Refract element and filter condition, gets its content, and filters it.

// Returns array including the one messageBodySchema element in content
_.filterContent({
  element: 'httpRequest',
  content: [
    {
      element: 'asset',
      meta: {
        classes: ['messageBodySchema']
      }
      content: 'Body Schema here'
    },
    {
      element: 'copy',
      content: 'Copy text here.'
    }
  ]
}, {element: 'asset'});

Installation

npm install lodash-api-description --save

Using the library

If you are using this library in a project of yours, we recommend loading Lodash in its own module, using runInContext, and adding mixins. Your module would look like:

// utils.js
var lodash = require('lodash').runInContext(); // creates a copy of lodash
var apiDescriptionMixins = require('lodash-api-description');
apiDescriptionMixins(lodash); // adds API Description mixins

module.exports = lodash;

Then when using this functionality in your project, you can do the following:

// Requiring custom lodash from another file
var lodash = require('./utils.js');

This prevents you from adding mixins to Lodash for entire project.

Development

$ npm install
$ npm test

License

MIT (see LICENSE file)

Apiary Inc. [email protected]