Comparing version 1.2.0 to 1.3.0
@@ -1,7 +0,9 @@ | ||
// Type definitions for left-pad 1.1 | ||
// Type definitions for left-pad 1.2.0 | ||
// Project: https://github.com/stevemao/left-pad | ||
// Definitions by: Zlatko Andonovski <https://github.com/Goldsmith42> | ||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
// Definitions by: Zlatko Andonovski, Andrew Yang, Chandler Fang and Zac Xu | ||
declare function leftPad(str: string|number, len: number, ch?: string|number): string; | ||
declare namespace leftPad { } | ||
export = leftPad; |
{ | ||
"name": "left-pad", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "String left pad", | ||
@@ -13,2 +13,3 @@ "main": "index.js", | ||
"benchmark": "^2.1.0", | ||
"fast-check": "0.0.8", | ||
"tape": "*" | ||
@@ -15,0 +16,0 @@ }, |
@@ -33,7 +33,5 @@ ## left-pad | ||
**NOTE:** Characters having code points outside of [BMP plan](https://en.wikipedia.org/wiki/Plane_(Unicode)#Basic_Multilingual_Plane) are considered a two distinct characters. See [#58](https://github.com/stevemao/left-pad/issues/58). | ||
[travis-image]: https://travis-ci.org/stevemao/left-pad.svg?branch=master | ||
[travis-url]: https://travis-ci.org/stevemao/left-pad | ||
## Typings | ||
Typings copied from [@types/left-pad](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/left-pad) for convenience. |
36
test.js
@@ -8,2 +8,3 @@ /* This program is free software. It comes without any warranty, to | ||
var test = require("tape"); | ||
var fc = require("fast-check"); | ||
@@ -54,1 +55,36 @@ test('edge cases', function (assert) { | ||
}); | ||
var runProperty = function(assert, name, checkFn) { | ||
var prop = fc.property(fc.string(), fc.nat(1000), fc.char(), checkFn); | ||
var result = fc.check(prop); | ||
var message = ''; | ||
if (result.failed) { | ||
message = 'Property "' + name + '" failed on counterexample ' + JSON.stringify(result.counterexample) + ' (seed: ' + result.seed + ')'; | ||
} | ||
assert.strictEqual(message, '', name); | ||
}; | ||
test('properties', function (assert) { | ||
assert.plan(4); | ||
runProperty(assert, 'starts by ch', function(str, len, ch) { | ||
var beg = leftPad(str, len, ch).substr(0, len -str.length); | ||
for (var idx = 0 ; idx != beg.length ; ++idx) | ||
if (beg[idx] !== ch) | ||
return false; | ||
return true; | ||
}); | ||
runProperty(assert, 'ends by str', function(str, len, ch) { | ||
var out = leftPad(str, len, ch); | ||
for (var idx = 0 ; idx != str.length ; ++idx) | ||
if (str[str.length -idx -1] !== out[out.length -idx -1]) | ||
return false; | ||
return true; | ||
}); | ||
runProperty(assert, 'len char long if padded (unchanged otherwise)', function(str, len, ch) { | ||
var out = leftPad(str, len, ch); | ||
return str.length < len ? out.length === len : str === out; | ||
}); | ||
runProperty(assert, 'no ch equivalent to space', function(str, len) { | ||
return leftPad(str, len) === leftPad(str, len, ' '); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9752
193
3
10
37