Classnamer
The ES6 utility for formatting css classnames written in TypeScript (inspired by classnames). Compatible with TypeScript 1.6+ commonjs module resolution.
Install with npm:
npm install classnamer
Using with node.js (TypeScript ES6 syntax):
; //import classnamer and types;
Usage
The classnamer
function takes any number of ClassNameFragment
arguments and produces the string result.
The ClassNameFragment
type is a union of ClassNamePrimitive
, ClassNameObject
and ClassNameFragmentList
.
The ClassNamePrimitive
type can be string
, number
or boolean
.
The ClassNameObject
is a map with boolean values which indicate should keys be included in the output or not.
The ClassNameFragmentList
type represents a list of ClassNameFragment
objects.
; // => "super man"; // => "super man"; // => "super man" // lots of arguments of various types; // => "super man zor el" // other falsy values are just ignored; // => "super 1"
ClassNameFragmentList
will be recursively flattened as per the rules above:
let fragments: ClassNameFragmentList = "man" kripton: true phantom: false ;; // => "super man kripton"