Created
February 7, 2021 11:42
-
-
Save AlaeddineMessadi/a2452a48fa9131be7055a1e4384dca25 to your computer and use it in GitHub Desktop.
Credit Card Masking #### with RegEx in javascript
This file contains hidden or 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
function maskify(input) { | |
return input.replace(/.(?=.{4})/g, "#"); | |
} | |
/** _Tests__ **/ | |
let assert = require('chai').assert | |
require('mocha').describe; | |
require('mocha').it; | |
describe('Challenge - Maskify', () => { | |
it('should return a string ouput', () => { | |
assert.typeOf(maskify(""), 'string'); | |
}); | |
it('should mask the digits of standard credit cards', () => { | |
assert.equal(maskify("5512103073210694"), "############0694"); | |
}); | |
it('should not mask the digits of short credit cards', () => { | |
assert.equal(maskify("54321"), "54321"); | |
}); | |
it('should return non digit characters without masking', () => { | |
assert.equal(maskify("Skippy"), "Skippy"); | |
}); | |
it('should handle the empty string input correctly', () => { | |
assert.equal(maskify(""), ""); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment