short-string
Function to create short strings based on given alphabets for the first char and the remaining ones. Default strings are valid CSS identifiers.
Can for example be used to generate short CSS identifiers as part of a custom encoder for postcss-reduce-idents or a namer for modular-css.
Installation
npm install --save short-string
Usage
shortString(num)
; // ⇒ 'a'
Parameters:
num
- ANumber
identifying the index of the occurrence.
shortStringFactory(characters, charactersExtra)
; const customShortString = ; ;// ⇒ 'ba'
Parameters:
characters
- AString
containing all valid characters for the first char of the generated short string.charactersExtra
- AString
containing all valid characters for the remaining chars of the generated short string. Must start withcharacters
.
Examples
postcss-reduce-idents
This is the configuration of postcss-reduce-idents to use short-string as encoder.
const options =
modular-css
This is an example namer function for modular-css using short-string to generate short selector names.
{ const known = {}; let nextIndex = 0; return { const id = file + selector; return ; }} namer: ;
License
short-string is licensed under the MIT License.