-
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
Showing
18 changed files
with
550 additions
and
19 deletions.
There are no files selected for viewing
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
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
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,25 @@ | ||
import { SPECIALS } from "./specials"; | ||
import { isSpecial } from "./isSpecial"; | ||
import { _partsSpecial } from "./_utils"; | ||
|
||
/** | ||
* Returns the special code for a valid car plate | ||
* @param {string} value | ||
* @returns {string} | ||
* @since 0.0.7 | ||
* @example | ||
* getSpecialCode("DGP-1234"); // => "DGP" | ||
*/ | ||
function getSpecialCode(value) { | ||
const str = !value ? "" : value; | ||
|
||
if (!isSpecial(str)) { | ||
return null; | ||
} | ||
|
||
const [code] = _partsSpecial(str); | ||
|
||
return SPECIALS[code] ? code : null; | ||
} | ||
|
||
export { getSpecialCode }; |
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,19 @@ | ||
import { SPECIALS } from "./specials"; | ||
import { getSpecialCode } from "./getSpecialCode"; | ||
|
||
/** | ||
* Returns the special name for a valid car plate | ||
* @param {string} value | ||
* @returns {string} | ||
* @since 0.0.7 | ||
* @example | ||
* getSpecialCode("CME1234"); // => "Corps of the Mossos d'Esquadra" | ||
*/ | ||
function getSpecialName(value) { | ||
const str = !value ? "" : value; | ||
const code = getSpecialCode(str); | ||
|
||
return SPECIALS[code] || null; | ||
} | ||
|
||
export { getSpecialName }; |
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,12 @@ | ||
export { isValid } from "./isValid"; | ||
export { isOld } from "./isOld"; | ||
export { isSpecial } from "./isSpecial"; | ||
export { getCounter } from "./getCounter"; | ||
export { getNumber } from "./getNumber"; | ||
export { getSpecialCode } from "./getSpecialCode"; | ||
export { getSpecialName } from "./getSpecialName"; | ||
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 }; |
Oops, something went wrong.