Comparing version 1.0.1 to 1.0.2
26
index.js
@@ -19,13 +19,13 @@ 'use strict'; | ||
setData (num = "") { | ||
if (num === null) { | ||
num = ""; | ||
} | ||
if (typeof num === 'string') { | ||
if (num === null) { | ||
num = ""; | ||
} | ||
if (typeof num === 'string') { | ||
this.data = num.match(DIGIT_REGEXP); | ||
} else { | ||
} else { | ||
this.data = num.toString().match(DIGIT_REGEXP); | ||
} | ||
if (this.data === null) { | ||
this.data = []; | ||
} | ||
if (this.data === null) { | ||
this.data = []; | ||
} | ||
this.len = this.data.length; | ||
@@ -56,2 +56,5 @@ } | ||
setSigil (sigil) { | ||
if (typeof(sigil) !== 'string' && sigil.length != 1) { | ||
throw new TypeError('IntFormat.setSigil error: bad argument. Argument must be a string, length 1'); | ||
} | ||
this.sig = sigil; | ||
@@ -62,7 +65,10 @@ return this; | ||
setAnchor (anchor) { | ||
if (typeof(anchor) !== 'string' && anchor.length != 1) { | ||
throw new TypeError('IntFormat.setAnchor error: bad argument. Argument must be a string, length 1'); | ||
} | ||
this.anc = anchor; | ||
return this; | ||
} | ||
static getFormatReader (string) { | ||
static getFormatReader (string) { | ||
let str = string, i = 0; | ||
@@ -69,0 +75,0 @@ return () => { |
{ | ||
"name": "int-format", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,2 +0,2 @@ | ||
[![Codecov Coverage](https://img.shields.io/codecov/c/github/ssypachev/secval/master.svg?style=flat-square)](https://codecov.io/gh/ssypachev/int-format/) | ||
[![Codecov Coverage](https://img.shields.io/codecov/c/github/ssypachev/int-format/master.svg?style=flat-square)](https://codecov.io/gh/ssypachev/int-format/) | ||
@@ -59,2 +59,4 @@ # int-format | ||
//#1 \\2 ? | ||
let str = new IntFormat('+# (###) ###-##-##').format('78037764302'); | ||
//+7 (803) 776-43-02 | ||
``` | ||
@@ -61,0 +63,0 @@ |
@@ -90,2 +90,20 @@ const chai = require('chai'), | ||
}); | ||
it ("Should test setSigil with bad argument", () => { | ||
let wasErr = false; | ||
try { | ||
let str = new IntFormat({ format: "!######!!" }).setSigil(1).format("12345"); | ||
} catch (err) { | ||
wasErr = true; | ||
} | ||
chai.expect(wasErr).to.be.true; | ||
}); | ||
it ("Should test setSigil with undefined argument", () => { | ||
let wasErr = false; | ||
try { | ||
let str = new IntFormat({ format: "!######!!" }).setSigil().format("12345"); | ||
} catch (err) { | ||
wasErr = true; | ||
} | ||
chai.expect(wasErr).to.be.true; | ||
}); | ||
it ("Should test setAnchor", () => { | ||
@@ -95,2 +113,20 @@ let str = new IntFormat({ format: "!######!!" }).setAnchor('!').format("12345"); | ||
}); | ||
it ("Should test setAnchor with bad argument", () => { | ||
let wasErr = false; | ||
try { | ||
let str = new IntFormat({ format: "!######!!" }).setAnchor(1).format("12345"); | ||
} catch (err) { | ||
wasErr = true; | ||
} | ||
chai.expect(wasErr).to.be.true; | ||
}); | ||
it ("Should test setAnchor with undefined argument", () => { | ||
let wasErr = false; | ||
try { | ||
let str = new IntFormat({ format: "!######!!" }).setAnchor().format("12345"); | ||
} catch (err) { | ||
wasErr = true; | ||
} | ||
chai.expect(wasErr).to.be.true; | ||
}); | ||
it ("Should test empty input", () => { | ||
@@ -108,2 +144,10 @@ let str = new IntFormat({ format: "######" }).format(); | ||
}); | ||
it ("Should test readme ex 1", () => { | ||
let str = new IntFormat({ padWith: '?', format: "\\## \\\\# #" }).format(12); | ||
chai.expect(str).to.equal('#1 \\2 ?'); | ||
}); | ||
it ("Should test readme ex 2", () => { | ||
let str = new IntFormat('+# (###) ###-##-##').format('78037764302'); | ||
chai.expect(str).to.equal('+7 (803) 776-43-02'); | ||
}); | ||
}); | ||
@@ -110,0 +154,0 @@ |
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
11902
302
88