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.8
  • 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

Note: Almost function is curring for you.

  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

Constants

checkErrfunction

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

Judge a set is it another set's childSet

log

Bind console with console.log, then it will called with right 'this' bind

setEqboolean

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

Functions

midFlow(mids)function
sameTo()any

A function return a unit what pass to it

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 ⇒ 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 constant
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

Judge a set is it another set's childSet

Kind: global constant

ParamType
childSetSet
supperSetSet

Example

isSupperSet(
		new Set([1, {a: 2}, 3]),
		new Set([1, {a: 2}, 3, 4])
)
// return false

log

Bind console with console.log, then it will called with right 'this' bind

Kind: global constant
Example

const j =require('berserk')
const fs =require('fs')
fs.readdir(
	'path',
	j.ifErr(j.log,j.log)
)

setEq ⇒ boolean

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

Kind: global constant

ParamType
set1Set
set2Set

Example

j.setEq(
   new Set([1, 2, 3]),
   new Set([3, 2, 1])
) // return true

j.setEq(
   new Set([1, 2]),
     new Set([1, 2, 3])
)// return false

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
Example

sameTo('hello world!')
// return 'hello world!'

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 03 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