mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-09 08:09:32 +08:00
Issue number: internal --------- ## What is the current behavior? - `LogLevel` throws error `Error: Cannot access ambient const enums when 'isolatedModules' is enabled` - Several existing console warns and errors are not calling the function that respects the `logLevel` config ## What is the new behavior? - Remove `const` from the `enum` to work with `isolatedModules` - Update `console.warn`s to `printIonWarning` - Update `console.error`s to `printIonError` ## Does this introduce a breaking change? - [ ] Yes - [x] No ## Other information Dev build: `8.5.5-dev.11744729748.174bf7e0` --------- Co-authored-by: Brandy Smith <6577830+brandyscarney@users.noreply.github.com>
35 lines
979 B
TypeScript
35 lines
979 B
TypeScript
import { printIonError } from '@utils/logging';
|
|
|
|
export const getCounterText = (
|
|
value: string | number | null | undefined,
|
|
maxLength: number,
|
|
counterFormatter?: (inputLength: number, maxLength: number) => string
|
|
) => {
|
|
const valueLength = value == null ? 0 : value.toString().length;
|
|
const defaultCounterText = defaultCounterFormatter(valueLength, maxLength);
|
|
|
|
/**
|
|
* If developers did not pass a custom formatter,
|
|
* use the default one.
|
|
*/
|
|
if (counterFormatter === undefined) {
|
|
return defaultCounterText;
|
|
}
|
|
|
|
/**
|
|
* Otherwise, try to use the custom formatter
|
|
* and fallback to the default formatter if
|
|
* there was an error.
|
|
*/
|
|
try {
|
|
return counterFormatter(valueLength, maxLength);
|
|
} catch (e) {
|
|
printIonError('[ion-input] - Exception in provided `counterFormatter`:', e);
|
|
return defaultCounterText;
|
|
}
|
|
};
|
|
|
|
const defaultCounterFormatter = (length: number, maxlength: number) => {
|
|
return `${length} / ${maxlength}`;
|
|
};
|