public class TypeBasedVariableNameStrategy implements VariableNameStrategy {
private final Map<String, AtomicLong> counters = new HashMap<>();
@Override
public String nextName(@NonNull String type) {
// NOTE: issue#145 careful with custom element about casing and dash, not to translate in JavaScript identifiers
var identifier = type;
final var HAS_DASH = type.contains("-");
final var IS_ROOT = "targetElement".equals(type);
final var HAS_UPPER_CASE = !type.chars()
.allMatch(character -> Character.toLowerCase(character) == character);
if (!IS_ROOT) {
identifier = HAS_UPPER_CASE ? type.toLowerCase() : identifier;
identifier = HAS_DASH
? type.replaceAll("-", "_").replaceAll("_+", "_") : identifier;
if (HAS_DASH || HAS_UPPER_CASE) {
identifier = "custom_%s".formatted(identifier);
}
}
return format("%s_%03d", identifier, counters.computeIfAbsent(type, __ -> new AtomicLong()).getAndIncrement());
}
}
1- How to run only one test ?
2- Meaning of this code in ApiTest ?
3- What happens if we have 2000 divs ? The program goes from 0 to 999 as you can see 03d. Should we not start at 001 instead of 000 ? https://github.com/osscameroon/js-generator/issues/239 https://github.com/osscameroon/js-generator/issues/240