New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

berserk

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

berserk

A library of convenient function by Jituan lin

  • 1.0.7
  • unpublished
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

A library of convenient function by Jituan Lin

This is Jituan Lin 's utils library, maybe is also helpful for you.

This project is fork by Ramda.js

How to use

  1. install berserk
    npm install berserk

  2. import or require the berserk, depend your environment.

    1. in node.js
    	const j =require('berserk').default
        // berserk include a whole Ramda.js in it
    	j.log(j.always('hello world'))
        // log: hello world
    
    1. with webpack
        import j from 'berserk'
        //berserk also has it's own function
        j.midFlow(
    	    [
        	    ({a})=>({b:a+1}),
        	    ({b})=>({c:a+b}),
        	    (obj)=>j.log(obj)
            ]
         )({a:1})
        //log: { a:1, b:2 , c:3 }
    
      const {readdir} =require('fs')
      const readdirP=toPromise(readdir)
      readdir(Path)
        .then(
          files=>console.log(files),
          (err)=>console.log(err)
          )
    
    

How to build

npm run build

How to test

npm run test

Generate API doc

npm run doc

API doc

Functions

checkErr(res, rej)function

A convenient function for handle error in callback function. Accept two function res(resolve) and rej(reject) , return a wrap function that accept a list arguments, the first argument as error, if error is null, the res function will call,else the rej function.

isSuperSet(childSet, supperSet)

judge a set is it another set's childSet

midFlow(mids)function
sameTo()any

a function return a unit what pass to it

setEq(set1, set2)boolean

compare whether two set (es6: new Set(iterable)) is same as.

toPromise(fun)function

wrap the callback style function to Promise style function, the callback style function must restrict by convention:

  1. the function must put the callback function where the last of arguments, such as (arg1,arg2,arg3,arg...,callback)
  2. the callback function must call as callback(err,arg1,arg2,arg...)

checkErr(res, rej) ⇒ function

A convenient function for handle error in callback function. Accept two function res(resolve) and rej(reject) , return a wrap function that accept a list arguments, the first argument as error, if error is null, the res function will call,else the rej function.

Kind: global function
Returns: function - return a function that accept a list arguments, the first argument as error, if error is null, the res function will call,else the rej function

ParamTypeDescription
resfunctionthe function which will call when no error throw
rejfunctionthe function which will call when error occur

isSuperSet(childSet, supperSet)

judge a set is it another set's childSet

Kind: global function

ParamType
childSetSet
supperSetSet

midFlow(mids) ⇒ function

Kind: global function
Returns: function - a function that accept a object as initial 'context' pass to first middleware

ParamTypeDescription
midsarraya array of middleware, the middleware must accept a object as 'context' and return a object to merge to context

Example

a function use midFlow for create a element(browser) by option
const elm = j.midFlow(
    [
       ({tag}) => ({el: document.createElement(tag)}),
       ({el, attr = {}}) => {
            R.forEachObjIndexed(
                 (value, name) => el[name] = value,
                 attr
             )
          },
        ({children = [], el}) => {
            j.midFlow(
                 [
                     ({doc}) => {
                         R.forEach(
                             (child) => doc.appendChild(child),
                             children
                         )
                       },
                      ({doc}) => {el.appendChild(doc)}
                  ]
            )({doc: new DocumentFragment})
         },
        ({evtLir = [], el}) => {
              R.forEach(
                 ({handler, type, opt = {}}) => el.addEventListener(type, handler, opt),
                  evtLir
               )
         },
       ({el}) => el
   ]
)

sameTo() ⇒ any

a function return a unit what pass to it

Kind: global function
Params: any

setEq(set1, set2) ⇒ boolean

compare whether two set (es6: new Set(iterable)) is same as.

Kind: global function

ParamType
set1Set
set2Set

toPromise(fun) ⇒ function

wrap the callback style function to Promise style function, the callback style function must restrict by convention:

  1. the function must put the callback function where the last of arguments, such as (arg1,arg2,arg3,arg...,callback)
  2. the callback function must call as callback(err,arg1,arg2,arg...)

Kind: global function
Returns: function - return the new function that will return a Promise, while the origin function throw a error, the Promise will be Promise.reject(error), while the origin function work fine, the Promise will be Promise.resolve(args: array), the args is which callback function accept

ParamTypeDescription
funfunctionthe callback style function to transform

Example

const {readdir} =require('fs')
   const readdirP=toPromise(readdir)
   readdir(Path)
     .then(
       files=>console.log(files),
       (err)=>console.log(err)
       )

Keywords

FAQs

Package last updated on 01 Aug 2017

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc