Polyfills for RN support (#275)
* Polyfills for RN support * Expand polyfill tests
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
// Copyright 2017-2018 @polkadot/util authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
describe('padding', () => {
|
||||
let stringEnd: (length: number, fill?: string) => string;
|
||||
let stringStart: (length: number, fill?: string) => string;
|
||||
|
||||
beforeEach(() => {
|
||||
stringEnd = String.prototype.padEnd;
|
||||
stringStart = String.prototype.padStart;
|
||||
|
||||
String.prototype.padEnd = null as any;
|
||||
String.prototype.padStart = null as any;
|
||||
|
||||
require('./padding');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
String.prototype.padEnd = stringEnd;
|
||||
String.prototype.padStart = stringStart;
|
||||
});
|
||||
|
||||
it('does padding', () => {
|
||||
expect('test'.padEnd(8, 'A')).toEqual('testAAAA');
|
||||
expect('test'.padEnd(8)).toEqual('test ');
|
||||
expect('test'.padStart(8, 'A')).toEqual('AAAAtest');
|
||||
expect('test'.padStart(8)).toEqual(' test');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,27 @@
|
||||
// Copyright 2017-2018 @polkadot/util authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
if (!String.prototype.padEnd) {
|
||||
String.prototype.padEnd = function padEnd (length: number, char: string = ' ') {
|
||||
let result: string = String(this);
|
||||
|
||||
while (result.length < length) {
|
||||
result = result + char;
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
if (!String.prototype.padStart) {
|
||||
String.prototype.padStart = function padStart (length: number, char: string = ' ') {
|
||||
let result: string = String(this);
|
||||
|
||||
while (result.length < length) {
|
||||
result = char + result;
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user