tdesign-mobile-vue
Version:
tdesign-mobile-vue
71 lines (67 loc) • 2.46 kB
JavaScript
/**
* tdesign v1.7.0
* (c) 2024 TDesign Group
* @license MIT
*/
import { computed } from 'vue';
import { i as isNumber_1 } from '../_chunks/dep-52fdc8e1.mjs';
import { i as isObject_1 } from '../_chunks/dep-e6c129ab.mjs';
import '../_common/js/log/index.mjs';
import { limitUnicodeMaxLength, getCharacterLength, getUnicodeLength } from '../_common/js/utils/helper.mjs';
import log from '../_common/js/log/log.mjs';
import '../_chunks/dep-8bf3054e.mjs';
import '../_chunks/dep-3d249f65.mjs';
import '../_chunks/dep-620d73f7.mjs';
import '../_chunks/dep-9b2de386.mjs';
import '../_chunks/dep-f0f403be.mjs';
import '../_chunks/dep-8d37dbf8.mjs';
import '../_chunks/dep-8ece47c6.mjs';
import '../_chunks/dep-cd74809c.mjs';
import '../_chunks/dep-219bb5a7.mjs';
import '../_chunks/dep-6303c50c.mjs';
import '../_chunks/dep-019e292f.mjs';
import '../_chunks/dep-32364550.mjs';
import '../_chunks/dep-74a5dff9.mjs';
import '../_chunks/dep-1bbfa76e.mjs';
function useLengthLimit(params) {
var getValueByLimitNumber = function getValueByLimitNumber(inputValue) {
var _params$value = params.value,
allowInputOverMax = _params$value.allowInputOverMax,
maxlength = _params$value.maxlength,
maxcharacter = _params$value.maxcharacter;
if (!(maxlength || maxcharacter) || allowInputOverMax || !inputValue) return inputValue;
if (maxlength) {
return limitUnicodeMaxLength(inputValue, maxlength);
}
if (maxcharacter) {
var r = getCharacterLength(inputValue, maxcharacter);
if (isObject_1(r)) {
return r.characters;
}
}
};
var limitNumber = computed(function () {
var _params$value2 = params.value,
maxlength = _params$value2.maxlength,
maxcharacter = _params$value2.maxcharacter,
value = _params$value2.value;
if (isNumber_1(value)) return String(value);
if (maxlength && maxcharacter) {
log.warn("Input", "Pick one of maxlength and maxcharacter please.");
}
if (maxlength) {
var length = value !== null && value !== void 0 && value.length ? getUnicodeLength(value) : 0;
return "".concat(length, "/").concat(maxlength);
}
if (maxcharacter) {
return "".concat(getCharacterLength(value || ""), "/").concat(maxcharacter);
}
return "";
});
return {
limitNumber: limitNumber,
getValueByLimitNumber: getValueByLimitNumber
};
}
export { useLengthLimit as default };
//# sourceMappingURL=useLengthLimit.mjs.map