mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-04 21:37:11 -04:00
feat(base64-string-converter): switch to encode and decode url safe base64 strings (#392)
* feat(base64-string-converter): switch to encode and decode url safe * feat(base64-string-converter): changes based on review comments, use config object instead of boolean argument. * feat(base64-string-converter): fix validation, add option to watch additional refs for changes which interfere with validation rules
This commit is contained in:
parent
8c92d56318
commit
0b20f1c16a
4 changed files with 72 additions and 12 deletions
|
@ -8,18 +8,34 @@ describe('base64 utils', () => {
|
|||
expect(textToBase64('a')).to.eql('YQ==');
|
||||
expect(textToBase64('lorem ipsum')).to.eql('bG9yZW0gaXBzdW0=');
|
||||
expect(textToBase64('-1')).to.eql('LTE=');
|
||||
expect(textToBase64('<<<????????>>>', { makeUrlSafe: false })).to.eql('PDw8Pz8/Pz8/Pz8+Pj4=');
|
||||
});
|
||||
it('should convert string into url safe base64', () => {
|
||||
expect(textToBase64('', { makeUrlSafe: true })).to.eql('');
|
||||
expect(textToBase64('a', { makeUrlSafe: true })).to.eql('YQ');
|
||||
expect(textToBase64('lorem ipsum', { makeUrlSafe: true })).to.eql('bG9yZW0gaXBzdW0');
|
||||
expect(textToBase64('<<<????????>>>', { makeUrlSafe: true })).to.eql('PDw8Pz8_Pz8_Pz8-Pj4');
|
||||
});
|
||||
});
|
||||
|
||||
describe('base64ToText', () => {
|
||||
it('should convert base64 into text', () => {
|
||||
expect(base64ToText('')).to.eql('');
|
||||
expect(base64ToText('YQ==')).to.eql('a');
|
||||
expect(base64ToText('YQ==', { makeUrlSafe: false })).to.eql('a');
|
||||
expect(base64ToText('bG9yZW0gaXBzdW0=')).to.eql('lorem ipsum');
|
||||
expect(base64ToText('data:text/plain;base64,bG9yZW0gaXBzdW0=')).to.eql('lorem ipsum');
|
||||
expect(base64ToText('LTE=')).to.eql('-1');
|
||||
});
|
||||
|
||||
it('should convert url safe base64 into text', () => {
|
||||
expect(base64ToText('', { makeUrlSafe: true })).to.eql('');
|
||||
expect(base64ToText('YQ', { makeUrlSafe: true })).to.eql('a');
|
||||
expect(base64ToText('bG9yZW0gaXBzdW0', { makeUrlSafe: true })).to.eql('lorem ipsum');
|
||||
expect(base64ToText('data:text/plain;base64,bG9yZW0gaXBzdW0', { makeUrlSafe: true })).to.eql('lorem ipsum');
|
||||
expect(base64ToText('LTE', { makeUrlSafe: true })).to.eql('-1');
|
||||
expect(base64ToText('PDw8Pz8_Pz8_Pz8-Pj4', { makeUrlSafe: true })).to.eql('<<<????????>>>');
|
||||
});
|
||||
|
||||
it('should throw for incorrect base64 string', () => {
|
||||
expect(() => base64ToText('a')).to.throw('Incorrect base64 string');
|
||||
expect(() => base64ToText(' ')).to.throw('Incorrect base64 string');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue