fela-utils
Advanced tools
Comparing version 5.0.5 to 6.0.0
var chars = 'abcdefghijklmnopqrstuvwxyz'; | ||
var charLength = chars.length; | ||
export default function generateClassName(id) { | ||
export default function generateClassName(getId) { | ||
var filterClassName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () { | ||
return true; | ||
}; | ||
var startId = getId(); | ||
var generatedClassName = generateUniqueClassName(startId); | ||
if (!filterClassName(generatedClassName)) { | ||
return generateClassName(getId, filterClassName); | ||
} | ||
return generatedClassName; | ||
} | ||
function generateUniqueClassName(id) { | ||
var className = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; | ||
var filterClassName = arguments[2]; | ||
if (id <= charLength) { | ||
var generatedClassName = chars[id - 1] + className; | ||
var hasFilter = typeof filterClassName === 'function'; | ||
if (hasFilter && !filterClassName(generatedClassName)) { | ||
return generateClassName(id + 1, className, filterClassName); | ||
} | ||
return generatedClassName; | ||
return chars[id - 1] + className; | ||
} | ||
@@ -21,3 +28,3 @@ | ||
// https://jsperf.com/math-floor-vs-math-round-vs-parseint/55 | ||
return generateClassName(id / charLength | 0, chars[id % charLength] + className, filterClassName); | ||
return generateUniqueClassName(id / charLength | 0, chars[id % charLength] + className); | ||
} |
@@ -10,15 +10,22 @@ 'use strict'; | ||
function generateClassName(id) { | ||
function generateClassName(getId) { | ||
var filterClassName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () { | ||
return true; | ||
}; | ||
var startId = getId(); | ||
var generatedClassName = generateUniqueClassName(startId); | ||
if (!filterClassName(generatedClassName)) { | ||
return generateClassName(getId, filterClassName); | ||
} | ||
return generatedClassName; | ||
} | ||
function generateUniqueClassName(id) { | ||
var className = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; | ||
var filterClassName = arguments[2]; | ||
if (id <= charLength) { | ||
var generatedClassName = chars[id - 1] + className; | ||
var hasFilter = typeof filterClassName === 'function'; | ||
if (hasFilter && !filterClassName(generatedClassName)) { | ||
return generateClassName(id + 1, className, filterClassName); | ||
} | ||
return generatedClassName; | ||
return chars[id - 1] + className; | ||
} | ||
@@ -28,3 +35,3 @@ | ||
// https://jsperf.com/math-floor-vs-math-round-vs-parseint/55 | ||
return generateClassName(id / charLength | 0, chars[id % charLength] + className, filterClassName); | ||
return generateUniqueClassName(id / charLength | 0, chars[id % charLength] + className); | ||
} |
{ | ||
"name": "fela-utils", | ||
"version": "5.0.5", | ||
"version": "6.0.0", | ||
"description": "Internal utilities for Fela", | ||
@@ -26,4 +26,4 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"fela": "^5.1.0" | ||
"fela": "^5.1.1" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43822
981