-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature #332] Changed mask behavior - use standard symbols for date/…
…time masks (YMDhms). Display the mask as input placeholder.
- Loading branch information
Showing
4 changed files
with
74 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
|
||
const REPLACEMENTS = { | ||
'D': '1', | ||
'M': '1', | ||
'Y': '1', | ||
'h': '1', | ||
'm': '1', | ||
's': '1' | ||
}; | ||
|
||
module.exports = { | ||
|
||
/** | ||
* Attempts to map regular mask (e.g. date) to the format supported by inputmask-core. | ||
* | ||
* E.g. it maps (DD-MM-YYYY) to 11-11-1111. | ||
* | ||
* If an unsupported mask character is encountered, it is simply skipped. Datetime masks are processed according to | ||
* ISO 8601 acronyms (e.g. M for month and m for minute). | ||
* @param mask The mask to map | ||
*/ | ||
mapMask(mask) { | ||
if (!mask) { | ||
return mask; | ||
} | ||
let result = '', | ||
character; | ||
for (let i = 0, len = mask.length; i < len; i++) { | ||
character = mask.charAt(i); | ||
result += REPLACEMENTS[character] ? REPLACEMENTS[character] : character; | ||
} | ||
return result; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict'; | ||
|
||
import MaskMapper from "../../src/util/MaskMapper"; | ||
|
||
describe('MaskMapper', () => { | ||
|
||
it('maps date/time/datetime masks to numeric input mask', () => { | ||
const data = [{ | ||
mask: 'DD-MM-YYYY', | ||
expected: '11-11-1111' | ||
}, { | ||
mask: 'hh:mm:ss', | ||
expected: '11:11:11' | ||
}, { | ||
mask: 'DD/MM/YYYY hh:mm:ss', | ||
expected: '11/11/1111 11:11:11' | ||
}]; | ||
|
||
data.forEach(d => { | ||
expect(MaskMapper.mapMask(d.mask)).toEqual(d.expected); | ||
}); | ||
}); | ||
|
||
it('returns null form null value passed in', () => { | ||
expect(MaskMapper.mapMask(null)).toBeNull(); | ||
}); | ||
|
||
it('returns undefined for undefined passed in', () => { | ||
expect(MaskMapper.mapMask(undefined)).not.toBeDefined(); | ||
}); | ||
}); |