-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1795778
commit 54d9276
Showing
10 changed files
with
214 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
export { isValid } from "./isValid"; | ||
export { isOld } from "./isOld"; | ||
export { isSpecial } from "./isSpecial"; | ||
export { getCounter } from "./getCounter"; | ||
export { getNumber } from "./getNumber"; | ||
export { getProvinceName } from "./getProvinceName"; | ||
export { getProvinceCode } from "./getProvinceCode"; | ||
export { parse } from "./parse"; | ||
export { PROVINCES } from "./provinces"; | ||
export { SPECIALS } from "./specials"; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { _partsSpecial } from "./_utils"; | ||
import { SPECIALS } from "./specials"; | ||
|
||
/** | ||
* Returns true if is a valid spacial car plate | ||
* @param {string} value | ||
* @returns {boolean} | ||
* @since 0.0.7 | ||
* @example | ||
* isSpecial("CME 2342"); // => true | ||
* isSpecial("E 1660"); // => true | ||
*/ | ||
function isSpecial(value) { | ||
const str = !value ? "" : value; | ||
const [code, num] = _partsSpecial(str); | ||
const cleaned = `${code}${num}`; | ||
|
||
if (cleaned.length < 5 || cleaned.length > 9) { | ||
return false; | ||
} | ||
|
||
if (!SPECIALS[code]) { | ||
return false; | ||
} | ||
|
||
return /^[CMEDGPNATFSHMORW]{1,5}[0-9]{4}$/i.test(cleaned); | ||
} | ||
|
||
export { isSpecial }; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export const SPECIALS = { | ||
CME: "Corps of the Mossos d'Esquadra", | ||
DGP: "Spanish Police", | ||
CNP: "Spanish Police", | ||
E: "Autonomous police force of the Basque Country", | ||
EA: "Air Force", | ||
ET: "Spanish Army", | ||
FAE: "Allied Forces in Spain", | ||
FN: "Spanish Navy", | ||
GSH: "Colonial police on Sahara", | ||
PGC: "Spanish civil guard", | ||
MF: "Public Works Ministry", | ||
MMA: "Environment Ministry", | ||
MOP: "Public Works Ministry", | ||
PME: "State owned vehicles", | ||
PMM: "State owned vehicles, on a Ministry", | ||
Crown: "King's Car" | ||
}; |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
const assert = require("assert"); | ||
const { isSpecial } = require("../dist/index"); | ||
|
||
describe("#isSpecial", () => { | ||
describe("invalid", () => { | ||
it("should not be valid without all chars required", () => { | ||
assert.equal(isSpecial("X"), false); | ||
}); | ||
|
||
it("should not be valid with null", () => { | ||
assert.equal(isSpecial(null), false); | ||
}); | ||
|
||
it("should not be valid with undefined", () => { | ||
assert.equal(isSpecial(undefined), false); | ||
}); | ||
|
||
it("should not be valid with empty string", () => { | ||
assert.equal(isSpecial(""), false); | ||
}); | ||
}); | ||
|
||
describe("valid", () => { | ||
it("should be valid with Crown", () => { | ||
assert.equal(isSpecial("Crown 0000"), true); | ||
}); | ||
|
||
it("should be valid with CME", () => { | ||
assert.equal(isSpecial("CME 0001"), true); | ||
}); | ||
|
||
it("should be valid with DGP", () => { | ||
assert.equal(isSpecial("DGP 0001"), true); | ||
}); | ||
|
||
it("should be valid with CNP", () => { | ||
assert.equal(isSpecial("CNP 0001"), true); | ||
}); | ||
|
||
it("should be valid with E", () => { | ||
assert.equal(isSpecial("E 0001"), true); | ||
}); | ||
|
||
it("should be valid with EA", () => { | ||
assert.equal(isSpecial("EA 0001"), true); | ||
}); | ||
|
||
it("should be valid with ET", () => { | ||
assert.equal(isSpecial("ET 0001"), true); | ||
}); | ||
|
||
it("should be valid with FAE", () => { | ||
assert.equal(isSpecial("FAE 0001"), true); | ||
}); | ||
|
||
it("should be valid with FN", () => { | ||
assert.equal(isSpecial("FN 0001"), true); | ||
}); | ||
|
||
it("should be valid with GSH", () => { | ||
assert.equal(isSpecial("GSH 0001"), true); | ||
}); | ||
|
||
it("should be valid with PGC", () => { | ||
assert.equal(isSpecial("PGC 0001"), true); | ||
}); | ||
|
||
it("should be valid with MF", () => { | ||
assert.equal(isSpecial("MF 0001"), true); | ||
}); | ||
|
||
it("should be valid with MMA", () => { | ||
assert.equal(isSpecial("MMA 0001"), true); | ||
}); | ||
|
||
it("should be valid with MOP", () => { | ||
assert.equal(isSpecial("MOP 0001"), true); | ||
}); | ||
|
||
it("should be valid with PME", () => { | ||
assert.equal(isSpecial("PME 0001"), true); | ||
}); | ||
|
||
it("should be valid with PMM", () => { | ||
assert.equal(isSpecial("PMM 0001"), true); | ||
}); | ||
}); | ||
}); |
This file contains 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