Skip to content

Commit 928fdb0

Browse files
committed
refactor: rename prepend to prefill for clarification
1 parent 94116d7 commit 928fdb0

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

src/component.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ export default {
5757
default: false
5858
},
5959
/**
60-
* If the mask starts with static characters, show them in the field initially before typing anything.
61-
* @since v1.3
60+
* If the mask value starts with static charaters, prefill it with the static charecters at load.
61+
\ * @since v1.3
6262
*/
63-
prepend: {
63+
prefill: {
6464
type: Boolean,
6565
default: false
6666
},
@@ -106,7 +106,7 @@ export default {
106106
mask: this.mask,
107107
tokens: this.tokens,
108108
formatter: this.formatter,
109-
prepend: this.prepend
109+
prefill: this.prefill
110110
}
111111
},
112112
emittedValue() {

src/masker.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,14 @@ export function dynamic(inputValue, config) {
5353
* Formats the value based on the given masking rule
5454
*
5555
* @param {string} value the value to mask
56-
* @param {{mask: String, tokens: Object, prepend: Boolean}} config
5756
* @param {object} config
5857
* @param {string} config.mask the masking string
5958
* @param {object} config.tokens the tokens to add/override to the global
60-
* @param {boolean} config.prepend whether or not to add masking characters to the input before the user types.
59+
* @param {boolean} config.prefill whether or not to add masking characters to the input before the user types
6160
* @param {boolean} config.short to keep the string as short as possible (not append extra chars at the end)
6261
*/
6362
export function formatter(value, config) {
64-
let { mask = '', tokens, prepend = false, short = false } = config
63+
let { mask = '', tokens, prefill = false, short = false } = config
6564

6665
// append/override global tokens instead of complete override
6766
tokens = tokens ? Object.assign({}, tokenDefinitions, tokens) : tokenDefinitions
@@ -108,8 +107,8 @@ export function formatter(value, config) {
108107
}
109108

110109
// if there is no unmasked value, set masked to empty to avoid showing masking
111-
// characters in an otherwise empty input, unless prepend is set ot true
112-
if ((prepend && !output.unmasked) || (!short && output.unmasked)) {
110+
// characters in an otherwise empty input, unless prefill is set ot true
111+
if ((prefill && !output.unmasked) || (!short && output.unmasked)) {
113112
output.masked += accumulator
114113
}
115114

tests/directive.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ describe('Directive', () => {
8787
expect(wrapper.element.unmaskedValue).toBe('1234')
8888
})
8989

90-
test('Should honor prepend modifier', async () => {
91-
buildWrapper({ modifiers: 'prepend', mask: '+1 ###', value: '' })
90+
test('Should honor prefill modifier', async () => {
91+
buildWrapper({ modifiers: 'prefill', mask: '+1 ###', value: '' })
9292
expect(wrapper.element.value).toBe('+1 ')
9393

9494
wrapper.element.value = '777'

tests/formatter.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,5 @@ test('2 -> +1 # 5', () => {
5858
})
5959

6060
test('empty -> +1 # 5', () => {
61-
expect(formatter('', { mask: '+1 # 5', prepend: true })).toMatchObject({ masked: '+1 ', unmasked: '' })
61+
expect(formatter('', { mask: '+1 # 5', prefill: true })).toMatchObject({ masked: '+1 ', unmasked: '' })
6262
})

0 commit comments

Comments
 (0)