🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

faussaire-util

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

faussaire-util

Bundle utilitary functions for faussaire

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

faussaire-util v0.1

Bundle utilitary functions for faussaire

Installation

npm install --save-dev faussaire-util

Overview

Faussaire itself is a pretty low-level library. Being modular, there are many things to be added for it to be really fast and easy to use.

Runner

A Runner is a higher order function returning an other function matching the Controller.run signature.

function(params, options) => Response

To get started with ES6, just import Runner from faussaire-util

import { Runner } from 'faussaire-util'

To start using a Runner in your Controller, set it to your Controller.run method :

Route({
  template: APIRoute("posts"),
  methods: ["GET"],
  controller: Controller({
    run: Runner.group({
      store: posts,
      matcher(){
        return true;
      },
      complete(posts){
        return Response({
          data: {
            posts
          },
          status: 200,
          statusText: "OK"
        });
      }
    })
  })
})

Store

Before starting any example, let's assume we have the following store :

const store = [
  {id: 1, name: "Rewieer", group: "admin"},
  {id: 2, name: "Bardepic", group: "user"},
  {id: 3, name: "Matt", group: "user"}
];

Runner.match(obj)

Match allows you to search in a store an item matching your own defined condition. It works as it follow :

Runner.match({
  store,
  matcher(user, params){
    return user.id === params.id
  },
  success(user){
    return {
      data: { user },
      status: 200
    }
  },
  failure(){
    return {
      data: {},
      status: 404
    }
  }
});

The example pretty self-explanatory.

Runner.group(obj)

Group allows you to fetch all the items from the store matching your condition.

Runner.group({
  store,
  matcher(user, params){
    return user.group === params.group
  },
  complete(users){
    if(users){
      return {
        data: { users },
        status: 200
      }
    } else {
      return {
        data: { },
        status: 404
      }
    }
  }
});

Keywords

faussaire

FAQs

Package last updated on 03 Oct 2016

Did you know?

Socket

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