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 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-samurai-toolkit

v1.0.0

Published

Methods that's helps to work with css modules

Downloads

4

Readme

logo-bg

react-samurai-toolkit

Is a bunch of helpers to work with react and nextjs

react-samurai-toolkit/classes

react-samurai-toolkit/utils

addClassIf([condition], [ifClass], [elseClass]) ⇒ string

add a class if the condition is true.

Kind: global function
Returns: string - ifClass or elseClass

| Param | Type | Default | Description | | --- | --- | --- | --- | | [condition] | boolean | true | condition to display the class | | [ifClass] | string | null | class to be returned if condition is true | | [elseClass] | string | null | class to be returned if condition is false |

Example

// returns 'on'
addClassIf(true, 'on', 'off')

Example

// returns 'off'
addClassIf(false, 'on', 'off') 

concatClass(...classes) ⇒ string

concatenate all params as a class

Kind: global function
Returns: string - all the params together as html classes

| Param | Type | Description | | --- | --- | --- | | ...classes | string | classes to be concatenated |

Example

// returns 'my-component my-second-class ...'
concatClass('my-component', 'my-second-class', '...')

toggleClass([condition], [baseClass], [classIf], [classElse]) ⇒ string

add base class and a class if certain condition is true

Kind: global function
Returns: string - the base class and if or else class

| Param | Type | Default | Description | | --- | --- | --- | --- | | [condition] | boolean | false | condition to display de class | | [baseClass] | string | null | the base class is always in the return | | [classIf] | string | null | the class to be returned if condition is true | | [classElse] | string | null | the class to be returned if condition is false |

Example

// returns 'base-classe on'
toggleClass(true, 'base-class', 'on', 'off')

Example

// returns 'base-class off'
toggleClass(false, 'base-class', 'on', 'off')

gst([styles], [className]) ⇒ string

gst is a acronym to getStyleClass - A css module function to get and return classes inside styles object

Kind: global function
Returns: string - string of classes

| Param | Type | Default | Description | | --- | --- | --- | --- | | [styles] | object | {} | The css module object with hashed classes | | [className] | string | "''" | The classes separated by space |

Example

const styles = { 
   container: 'Component_container__WQ2uP', 
   content: 'Component_content__uP24c' 
} 
getStyleClass(styles, 'container content')
// returns 'Component_container__WQ2uP Component_content__uP24c'

c([styles], [baseClass], ...restClass)

A function mix all helpers together, to prevent verbose code like concacClass(gst(styles, 'container'), 'on')

Kind: global function

| Param | Type | Default | Description | | --- | --- | --- | --- | | [styles] | object | {} | object css module of css or scss file | | [baseClass] | string | "''" | A classes in styles object separated by space | | ...restClass | string | | strings that will be included (concatenated) with base class |

Example

const styles = { 
   container: 'Component_container__WQ2uP', 
   content: 'Component_content__uP24c' 
} 
c(styles, 'container content', 'my-other-class')
// returns 'Component_container__WQ2uP Component_content__uP24c my-other-class' 

isServer() ⇒ boolean

help method to detect if code runs on server

Kind: global function
Example

// returns true if is in server
isServer()

isClient() ⇒ boolean

help method to detect if code runs on client

Kind: global function
Example

// returns true if is in server
isClient()

getRefValue(ref) ⇒ any

get input value from react ref.

Kind: global function
Returns: any - Current value of input

| Param | Type | Description | | --- | --- | --- | | ref | object | the ref of element |

Example

getRefValue(inputRef)

renderIf([condition], [ifComponent], [elseComponent]) ⇒ ReactComponent

method to render conditionally a react component.

Kind: global function

| Param | Type | Default | Description | | --- | --- | --- | --- | | [condition] | boolean | true | condition to display the component | | [ifComponent] | string | null | component to render if condition is true | | [elseComponent] | string | null | component to render if condition is false |

Example

const loading = true
renderIf(loading, (<span>loading</span>)) // return <span>loading</span>

Example

const loading = false
renderIf(loading, (<span>loading</span>), (<span>loaded</span>)) // <span>loaded</span>

redirect404([redirect])

return this method on getServerSideProps to 404 redirect

Kind: global function

| Param | Type | Default | Description | | --- | --- | --- | --- | | [redirect] | object | | redirect object |

Example

export async function getServerSideProps(res){

    try {

        return await SomePromise();

    } catch(e){
        return redirect404()
    }
}

moneyFormatter([lang], [style], [currency]) ⇒ Object

Method to format number as money / currency

Kind: global function
Returns: Object - - new Intl.NumberFormat(lang, { style, currency })

| Param | Type | Default | Description | | --- | --- | --- | --- | | [lang] | string | "pt-BR" | language | | [style] | string | "currency" | style | | [currency] | string | "BRL" | currency |

Example

const Formarter = moneyFormatter();
Formarter.format(10) // 'R$ 10,00'

isProduction() ⇒ boolean

check if process.env.NODE_ENV === 'production'

Kind: global function
Example

isProduction() // true or false

cacheServeSideProps([res], [maxage], [revalidate])

cache server side props (Only production env)

Kind: global function

| Param | Type | Default | Description | | --- | --- | --- | --- | | [res] | object | | response object from nextjs | | [maxage] | string | 900 | maxage param | | [revalidate] | string | 910 | revalidate param |

Example

export async function getServerSideProps(res){

    //will cache this request
    cacheServeSideProps(res);

    try {
        return await SomePromise();

    } catch(e){
        return redirect404()
    }
}