Skip to content

Commit

Permalink
Merge pull request #49 from shoonia/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
shoonia committed Mar 3, 2024
2 parents 28d289e + 376782d commit 5fe6a6c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion css-loader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const miniCssClassName = require('../index.js');
/**
* @typedef {Pick<Map<string, string>, 'has' | 'get' | 'set'>} CacheMap
* @param {miniCssClassName.Options & { cache?: CacheMap }} [options] options
* @returns {function(): string} Generate
* @returns {function(): string}
*/
module.exports = ({ cache, ...options } = {}) => {
const map = cache || new Map();
Expand Down
30 changes: 15 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ const hasInvalidStartChar = (char) => /[^a-z_]/i.test(char);

/**
* @param {Options} options generation
* @returns {function(): string} Generate
* @returns {function(): string}
*/
module.exports = ({
prefix = '',
suffix = '',
excludePattern = null,
excludePattern,
} = {}) => {
if (typeof prefix !== 'string') {
throw ex('`prefix` must be a String');
Expand All @@ -80,7 +80,7 @@ module.exports = ({
throw ex('`suffix` must be a String');
}

if (excludePattern !== null && !(excludePattern instanceof RegExp)) {
if (excludePattern != null && !(excludePattern instanceof RegExp)) {
throw ex('`excludePattern` must be a RegExp');
}

Expand All @@ -93,9 +93,9 @@ module.exports = ({
}

let firstChar = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_';
let afterChar = `${firstChar}-0123456789`;
let afterChar = `${firstChar}-0123456789`;

if (excludePattern !== null) {
if (excludePattern != null) {
firstChar = firstChar.replace(excludePattern, '');
afterChar = afterChar.replace(excludePattern, '');
}
Expand All @@ -107,23 +107,24 @@ module.exports = ({
const accumulator = [];

/**
* Generate
* @returns {string} unique class name
* @type {*}
*/
const generate = () => {
increment(accumulator, 0, START_LENGTH, AFTER_LENGTH);

return prefix + createClassName(accumulator, afterChar) + suffix;
};
const generate = prefix || suffix
? () => (
increment(accumulator, 0, START_LENGTH, AFTER_LENGTH),
prefix + createClassName(accumulator, afterChar) + suffix
)
: () => (
increment(accumulator, 0, START_LENGTH, AFTER_LENGTH),
createClassName(accumulator, afterChar)
);

/**
* @memberof Generate
* @returns {number[]} accumulator
*/
generate.getAccumulator = () => [...accumulator];

/**
* @memberof Generate
* @param {number[]} acc accumulator
* @returns {number[]} accumulator
*/
Expand All @@ -135,7 +136,6 @@ module.exports = ({
};

/**
* @memberof Generate
* @returns {void}
*/
generate.reset = () => {
Expand Down
48 changes: 24 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mini-css-class-name",
"version": "0.15.0",
"version": "0.15.1",
"description": "Minimum size unique CSS class names generator",
"main": "index.js",
"exports": {
Expand All @@ -14,8 +14,8 @@
"test": "uvu tests"
},
"devDependencies": {
"@evilmartians/lefthook": "^1.6.1",
"eslint": "^8.56.0",
"@evilmartians/lefthook": "^1.6.4",
"eslint": "^8.57.0",
"uvu": "^0.5.6"
},
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion postcss-modules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const miniCssClassName = require('../index.js');
/**
* @typedef {Pick<Map<string, string>, 'has' | 'get' | 'set'>} CacheMap
* @param {miniCssClassName.Options & { cache?: CacheMap }} [options] options
* @returns {function(): string} Generate
* @returns {function(): string}
*/
module.exports = ({ cache, ...options } = {}) => {
const map = cache || new Map();
Expand Down

0 comments on commit 5fe6a6c

Please sign in to comment.