diff --git a/dist/index.js b/dist/index.js index 5550466..bf54fa0 100644 --- a/dist/index.js +++ b/dist/index.js @@ -279,6 +279,21 @@ return SPECIALS[code] ? code : null; } + /** + * 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) { + var str = !value ? "" : value; + var code = getSpecialCode(str); + return SPECIALS[code] || null; + } + var PROVINCES = { A: "Province of Alicante", AB: "Province of Albacete", @@ -445,6 +460,7 @@ exports.getCounter = getCounter; exports.getNumber = getNumber; exports.getSpecialCode = getSpecialCode; + exports.getSpecialName = getSpecialName; exports.getProvinceName = getProvinceName; exports.getProvinceCode = getProvinceCode; exports.parse = parse; diff --git a/dist/index.js.map b/dist/index.js.map index 6bd0f9e..cb0eeac 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sources":["../src/_utils.js","../src/isOld.js","../src/isValid.js","../src/specials.js","../src/isSpecial.js","../src/getCounter.js","../src/getNumber.js","../src/getSpecialCode.js","../src/provinces.js","../src/getProvinceCode.js","../src/getProvinceName.js","../src/parse.js"],"sourcesContent":["export function _partsSpecial(str) {\n const cleaned = str.replace(\n /^[\\s]*([CMEDGPNATFSHMORW]{1,5})[^A-Z0-9]*([0-9]{4})[\\s]*$/i,\n \"$1,$2\"\n );\n\n return cleaned.split(\",\");\n}\n\nexport function _partsOld(str) {\n const cleaned = str.replace(\n /^[\\s]*([A-Z]{1,3})[^A-Z0-9]*([0-9]{4})[^A-Z0-9]*([A-Z]{2})[\\s]*$/i,\n \"$1,$2,$3\"\n );\n\n return cleaned.split(\",\");\n}\n\nexport function _partsNew(str) {\n const cleaned = str.replace(\n /^[\\s]*([0-9]{4})[^A-Z0-9]*([BCDFGHJKLMNPRSTVWXYZ]{3})[\\s]*$/i,\n \"$1,$2\"\n );\n\n return cleaned.split(\",\");\n}\n","import { _partsOld } from \"./_utils\";\n\n/**\n * Returns true if is a valid (old system 1971-2000) car plate\n * @param {string} value\n * @returns {boolean}\n * @since 0.0.2\n * @example\n * isOld(\"GI-1234-CS\"); // => true\n */\nfunction isOld(value) {\n const str = !value ? \"\" : value;\n const cleaned = _partsOld(str).join(\"\");\n\n if (cleaned.length < 7 || cleaned.length > 9) {\n return false;\n }\n\n return /^[A-Z]{1,3}[0-9]{4}[A-Z]{2}$/i.test(cleaned);\n}\n\nexport { isOld };\n","import { _partsNew } from \"./_utils\";\nimport { isOld } from \"./isOld\";\n\n/**\n * Returns true if is a valid (post year 2000) car plate\n * @param {string} value\n * @returns {boolean}\n * @since 0.0.1\n * @example\n * isValid(\"2345BCF\"); // => true\n */\nfunction isValid(value) {\n if (isOld(value)) {\n return true;\n }\n\n const str = !value ? \"\" : value;\n const cleaned = _partsNew(str).join(\"\");\n\n if (cleaned.length !== 7) {\n return false;\n }\n\n return /^[0-9]{4}[BCDFGHJKLMNPRSTVWXYZ]{3}$/i.test(cleaned);\n}\n\nexport { isValid };\n","export const SPECIALS = {\n CME: \"Corps of the Mossos d'Esquadra\",\n DGP: \"Spanish Police\",\n CNP: \"Spanish Police\",\n E: \"Autonomous police force of the Basque Country\",\n EA: \"Air Force\",\n ET: \"Spanish Army\",\n FAE: \"Allied Forces in Spain\",\n FN: \"Spanish Navy\",\n GSH: \"Colonial police on Sahara\",\n PGC: \"Spanish civil guard\",\n MF: \"Public Works Ministry\",\n MMA: \"Environment Ministry\",\n MOP: \"Public Works Ministry\",\n PME: \"State owned vehicles\",\n PMM: \"State owned vehicles, on a Ministry\",\n Crown: \"King's Car\"\n};\n","import { _partsSpecial } from \"./_utils\";\nimport { SPECIALS } from \"./specials\";\n\n/**\n * Returns true if is a valid spacial car plate\n * @param {string} value\n * @returns {boolean}\n * @since 0.0.7\n * @example\n * isSpecial(\"CME 2342\"); // => true\n * isSpecial(\"E 1660\"); // => true\n */\nfunction isSpecial(value) {\n const str = !value ? \"\" : value;\n const [code, num] = _partsSpecial(str);\n const cleaned = `${code}${num}`;\n\n if (cleaned.length < 5 || cleaned.length > 9) {\n return false;\n }\n\n if (!SPECIALS[code]) {\n return false;\n }\n\n return /^[CMEDGPNATFSHMORW]{1,5}[0-9]{4}$/i.test(cleaned);\n}\n\nexport { isSpecial };\n","import { isOld } from \"./isOld\";\nimport { isValid } from \"./isValid\";\nimport { _partsOld, _partsNew } from \"./_utils\";\n\n/**\n *\n * @param {string} value\n * @returns {string}\n * @since 0.0.5\n * @example\n * getCounter(\"GI-1234-CS\"); // => \"CS\"\n * getCounter(\"2345BCF\"); // => \"CS\"\n */\nfunction getCounter(value) {\n const str = !value ? \"\" : value;\n\n if (isOld(str) === true) {\n const [, , counter] = _partsOld(str);\n return counter;\n } else if (isValid(str)) {\n const [, counter] = _partsNew(str);\n return counter;\n }\n\n return null;\n}\n\nexport { getCounter };\n","import { isOld } from \"./isOld\";\nimport { isValid } from \"./isValid\";\nimport { isSpecial } from \"./isSpecial\";\nimport { _partsNew, _partsOld, _partsSpecial } from \"./_utils\";\n\n/**\n *\n * @param {string} value\n * @returns {number}\n * @since 0.0.5\n * @example\n * getNumber(\"2345BCF\"); // => 2345\n * getNumber(\"GI-1234-CS\"); // => 1234\n */\nfunction getNumber(value) {\n const str = !value ? \"\" : value;\n\n if (isOld(str) === true) {\n const [, num] = _partsOld(str);\n return parseInt(num, 10);\n } else if (isSpecial(str) === true) {\n const [, num] = _partsSpecial(str);\n return parseInt(num, 10);\n } else if (isValid(str)) {\n const [num] = _partsNew(str);\n return parseInt(num, 10);\n }\n\n return null;\n}\n\nexport { getNumber };\n","import { SPECIALS } from \"./specials\";\nimport { isSpecial } from \"./isSpecial\";\nimport { _partsSpecial } from \"./_utils\";\n\n/**\n * Returns the special code for a valid car plate\n * @param {string} value\n * @returns {string}\n * @since 0.0.7\n * @example\n * getSpecialCode(\"DGP-1234\"); // => \"DGP\"\n */\nfunction getSpecialCode(value) {\n const str = !value ? \"\" : value;\n\n if (!isSpecial(str)) {\n return null;\n }\n\n const [code] = _partsSpecial(str);\n\n return SPECIALS[code] ? code : null;\n}\n\nexport { getSpecialCode };\n","export const PROVINCES = {\n A: \"Province of Alicante\",\n AB: \"Province of Albacete\",\n AL: \"Province of Almería\",\n AV: \"Province of Ávila\",\n B: \"Province of Barcelona\",\n BA: \"Province of Badajoz\",\n BI: \"Bilbao\",\n BU: \"Province of Burgos\",\n C: \"Province of A Coruña\",\n CA: \"Province of Cádiz\",\n CC: \"Province of Cáceres\",\n CE: \"Ceuta\",\n CO: \"Province of Córdoba\",\n CR: \"Province of Ciudad Real\",\n CS: \"Castelló\",\n CU: \"Province of Cuenca\",\n FP: \"Bioko\",\n GC: \"Province of Las Palmas\",\n GE: \"Gerona (Girona)\",\n GI: \"Province of Girona\",\n GR: \"Province of Granada\",\n GU: \"Province of Guadalajara\",\n H: \"Province of Huelva\",\n HU: \"Province of Huesca\",\n IF: \"Ifni\",\n J: \"Province of Jaén\",\n L: \"Province of Lleida\",\n LE: \"Province of León\",\n LO: \"Logroño\",\n LR: \"La Rioja\",\n LU: \"Province of Lugo\",\n M: \"Community of Madrid\",\n MA: \"Province of Málaga\",\n ML: \"Melilla\",\n MU: \"Region of Murcia\",\n NA: \"Navarre\",\n O: \"Oviedo\",\n OU: \"Province of Ourense\",\n P: \"Province of Palencia\",\n PM: \"Palma, Majorca\",\n PO: \"Province of Pontevedra\",\n RM: \"Rio Muni\",\n S: \"Santander\",\n SA: \"Province of Salamanca\",\n SE: \"Province of Seville\",\n SG: \"Province of Segovia\",\n SO: \"Province of Soria\",\n SS: \"Donostia\",\n T: \"Province of Tarragona\",\n TE: \"Province of Teruel\",\n TF: \"Province of Santa Cruz de Tenerife\",\n TO: \"Province of Toledo\",\n V: \"Province of Valencia\",\n VA: \"Province of Valladolid\",\n VI: \"Vitoria\",\n Z: \"Province of Zaragoza\",\n ZA: \"Province of Zamora\"\n};\n","import { PROVINCES } from \"./provinces\";\nimport { isOld } from \"./isOld\";\nimport { _partsOld } from \"./_utils\";\n\n/**\n * Returns the province code for a valid car plate in the old system (1971-2000)\n * @param {string} value\n * @returns {string}\n * @since 0.0.5\n * @example\n * getProvinceCode(\"GI-1234-CS\"); // => \"GI\"\n */\nfunction getProvinceCode(value) {\n const str = !value ? \"\" : value;\n\n if (!isOld(str)) {\n return null;\n }\n\n const [code] = _partsOld(str);\n\n return PROVINCES[code] ? code : null;\n}\n\nexport { getProvinceCode };\n","import { PROVINCES } from \"./provinces\";\nimport { getProvinceCode } from \"./getProvinceCode\";\n\n/**\n * Returns the province name for a valid car plate in the old system (1971-2000)\n * @param {string} value\n * @returns {string}\n * @since 0.0.5\n * @example\n * getProvinceName(\"GI-1234-CS\"); // => \"Province of Girona\"\n */\nfunction getProvinceName(value) {\n const str = !value ? \"\" : value;\n const code = getProvinceCode(str);\n\n return PROVINCES[code] || null;\n}\n\nexport { getProvinceName };\n","import { isValid } from \"./isValid\";\nimport { isOld } from \"./isOld\";\nimport { isSpecial } from \"./isSpecial\";\nimport { getProvinceName } from \"./getProvinceName\";\nimport { getProvinceCode } from \"./getProvinceCode\";\nimport { getCounter } from \"./getCounter\";\nimport { getNumber } from \"./getNumber\";\nimport { getSpecialCode } from \"./getSpecialCode\";\n\nfunction _parseNew(str) {\n const parsed = {};\n parsed.isOld = false;\n parsed.provinceName = null;\n parsed.provinceCode = null;\n parsed.specialCode = null;\n parsed.counter = getCounter(str);\n parsed.number = getNumber(str);\n return parsed;\n}\n\nfunction _parseOld(str) {\n const parsed = {};\n parsed.isOld = true;\n parsed.provinceName = getProvinceName(str);\n parsed.provinceCode = getProvinceCode(str);\n parsed.specialCode = null;\n parsed.counter = getCounter(str);\n parsed.number = getNumber(str);\n return parsed;\n}\n\nfunction _parseSpecial(str) {\n const parsed = {};\n parsed.isOld = false;\n parsed.provinceName = null;\n parsed.provinceCode = null;\n parsed.specialCode = getSpecialCode(str);\n parsed.counter = null;\n parsed.number = getNumber(str);\n parsed.isSpecial = true;\n return parsed;\n}\n\n/**\n * Returns an object containing information about the plate\n * @param {string} value\n * @returns {boolean}\n * @since 0.0.5\n * @example\n * parse(\"2345BCF\"); // => { isSpecial: false, isOld: false, provinceCode: null, provinceName: null, number: 2345, counter: \"BCF\" }\n * parse(\"GI2345BC\"); // => { isSpecial: false, isOld: true, provinceCode: \"GI\", provinceName: \"Province of Girona\", number: 2345, counter: \"BC\" }\n */\nfunction parse(value) {\n const str = !value ? \"\" : value;\n const parsed = {\n isSpecial: false // TODO: not implemented\n };\n\n if (isOld(str) === true) {\n return {\n ...parsed,\n ..._parseOld(str)\n };\n } else if (isSpecial(str) === true) {\n return {\n ...parsed,\n ..._parseSpecial(str)\n };\n } else if (isValid(str) === true) {\n return {\n ...parsed,\n ..._parseNew(str)\n };\n }\n\n return null;\n}\n\nexport { parse };\n"],"names":["_partsSpecial","str","cleaned","replace","split","_partsOld","_partsNew","isOld","value","join","length","test","isValid","SPECIALS","CME","DGP","CNP","E","EA","ET","FAE","FN","GSH","PGC","MF","MMA","MOP","PME","PMM","Crown","isSpecial","code","num","getCounter","counter","getNumber","parseInt","getSpecialCode","PROVINCES","A","AB","AL","AV","B","BA","BI","BU","C","CA","CC","CE","CO","CR","CS","CU","FP","GC","GE","GI","GR","GU","H","HU","IF","J","L","LE","LO","LR","LU","M","MA","ML","MU","NA","O","OU","P","PM","PO","RM","S","SA","SE","SG","SO","SS","T","TE","TF","TO","V","VA","VI","Z","ZA","getProvinceCode","getProvinceName","_parseNew","parsed","provinceName","provinceCode","specialCode","number","_parseOld","_parseSpecial","parse"],"mappings":";;;;;;;;;;;EAAO,SAASA,aAAT,CAAuBC,GAAvB,EAA4B;EACjC,MAAMC,OAAO,GAAGD,GAAG,CAACE,OAAJ,CACd,4DADc,EAEd,OAFc,CAAhB;EAKA,SAAOD,OAAO,CAACE,KAAR,CAAc,GAAd,CAAP;EACD;AAED,EAAO,SAASC,SAAT,CAAmBJ,GAAnB,EAAwB;EAC7B,MAAMC,OAAO,GAAGD,GAAG,CAACE,OAAJ,CACd,mEADc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EACAA,EAAAA,MAAM,CAAC5F,KAAP,GAAe,KAAf;EACA4F,EAAAA,MAAM,CAACC,YAAP,GAAsB,IAAtB;EACAD,EAAAA,MAAM,CAACE,YAAP,GAAsB,IAAtB;EACAF,EAAAA,MAAM,CAACG,WAAP,GAAqBjE,cAAc,CAACpC,GAAD,CAAnC;EACAkG,EAAAA,MAAM,CAACjE,OAAP,GAAiB,IAAjB;EACAiE,EAAAA,MAAM,CAACI,MAAP,GAAgBpE,SAAS,CAAClC,GAAD,CAAzB;EACAkG,EAAAA,MAAM,CAACrE,SAAP,GAAmB,IAAnB;EACA,SAAOqE,MAAP;EACD;EAED;;;;;;;;;;;EASA,SAASO,KAAT,CAAelG,KAAf,EAAsB;EACpB,MAAMP,GAAG,GAAG,CAACO,KAAD,GAAS,EAAT,GAAcA,KAA1B;EACA,MAAM2F,MAAM,GAAG;EACbrE,IAAAA,SAAS,EAAE,KADE;;EAAA,GAAf;;EAIA,MAAIvB,KAAK,CAACN,GAAD,CAAL,KAAe,IAAnB,EAAyB;EACvB,6BACKkG,MADL,EAEKK,SAAS,CAACvG,GAAD,CAFd;EAID,GALD,MAKO,IAAI6B,SAAS,CAAC7B,GAAD,CAAT,KAAmB,IAAvB,EAA6B;EAClC,6BACKkG,MADL,EAEKM,aAAa,CAACxG,GAAD,CAFlB;EAID,GALM,MAKA,IAAIW,OAAO,CAACX,GAAD,CAAP,KAAiB,IAArB,EAA2B;EAChC,6BACKkG,MADL,EAEKD,SAAS,CAACjG,GAAD,CAFd;EAID;;EAED,SAAO,IAAP;EACD;;;;;;;;;;;;;;;;;;;;;;"} \ No newline at end of file +{"version":3,"file":"index.js","sources":["../src/_utils.js","../src/isOld.js","../src/isValid.js","../src/specials.js","../src/isSpecial.js","../src/getCounter.js","../src/getNumber.js","../src/getSpecialCode.js","../src/getSpecialName.js","../src/provinces.js","../src/getProvinceCode.js","../src/getProvinceName.js","../src/parse.js"],"sourcesContent":["export function _partsSpecial(str) {\n const cleaned = str.replace(\n /^[\\s]*([CMEDGPNATFSHMORW]{1,5})[^A-Z0-9]*([0-9]{4})[\\s]*$/i,\n \"$1,$2\"\n );\n\n return cleaned.split(\",\");\n}\n\nexport function _partsOld(str) {\n const cleaned = str.replace(\n /^[\\s]*([A-Z]{1,3})[^A-Z0-9]*([0-9]{4})[^A-Z0-9]*([A-Z]{2})[\\s]*$/i,\n \"$1,$2,$3\"\n );\n\n return cleaned.split(\",\");\n}\n\nexport function _partsNew(str) {\n const cleaned = str.replace(\n /^[\\s]*([0-9]{4})[^A-Z0-9]*([BCDFGHJKLMNPRSTVWXYZ]{3})[\\s]*$/i,\n \"$1,$2\"\n );\n\n return cleaned.split(\",\");\n}\n","import { _partsOld } from \"./_utils\";\n\n/**\n * Returns true if is a valid (old system 1971-2000) car plate\n * @param {string} value\n * @returns {boolean}\n * @since 0.0.2\n * @example\n * isOld(\"GI-1234-CS\"); // => true\n */\nfunction isOld(value) {\n const str = !value ? \"\" : value;\n const cleaned = _partsOld(str).join(\"\");\n\n if (cleaned.length < 7 || cleaned.length > 9) {\n return false;\n }\n\n return /^[A-Z]{1,3}[0-9]{4}[A-Z]{2}$/i.test(cleaned);\n}\n\nexport { isOld };\n","import { _partsNew } from \"./_utils\";\nimport { isOld } from \"./isOld\";\n\n/**\n * Returns true if is a valid (post year 2000) car plate\n * @param {string} value\n * @returns {boolean}\n * @since 0.0.1\n * @example\n * isValid(\"2345BCF\"); // => true\n */\nfunction isValid(value) {\n if (isOld(value)) {\n return true;\n }\n\n const str = !value ? \"\" : value;\n const cleaned = _partsNew(str).join(\"\");\n\n if (cleaned.length !== 7) {\n return false;\n }\n\n return /^[0-9]{4}[BCDFGHJKLMNPRSTVWXYZ]{3}$/i.test(cleaned);\n}\n\nexport { isValid };\n","export const SPECIALS = {\n CME: \"Corps of the Mossos d'Esquadra\",\n DGP: \"Spanish Police\",\n CNP: \"Spanish Police\",\n E: \"Autonomous police force of the Basque Country\",\n EA: \"Air Force\",\n ET: \"Spanish Army\",\n FAE: \"Allied Forces in Spain\",\n FN: \"Spanish Navy\",\n GSH: \"Colonial police on Sahara\",\n PGC: \"Spanish civil guard\",\n MF: \"Public Works Ministry\",\n MMA: \"Environment Ministry\",\n MOP: \"Public Works Ministry\",\n PME: \"State owned vehicles\",\n PMM: \"State owned vehicles, on a Ministry\",\n Crown: \"King's Car\"\n};\n","import { _partsSpecial } from \"./_utils\";\nimport { SPECIALS } from \"./specials\";\n\n/**\n * Returns true if is a valid spacial car plate\n * @param {string} value\n * @returns {boolean}\n * @since 0.0.7\n * @example\n * isSpecial(\"CME 2342\"); // => true\n * isSpecial(\"E 1660\"); // => true\n */\nfunction isSpecial(value) {\n const str = !value ? \"\" : value;\n const [code, num] = _partsSpecial(str);\n const cleaned = `${code}${num}`;\n\n if (cleaned.length < 5 || cleaned.length > 9) {\n return false;\n }\n\n if (!SPECIALS[code]) {\n return false;\n }\n\n return /^[CMEDGPNATFSHMORW]{1,5}[0-9]{4}$/i.test(cleaned);\n}\n\nexport { isSpecial };\n","import { isOld } from \"./isOld\";\nimport { isValid } from \"./isValid\";\nimport { _partsOld, _partsNew } from \"./_utils\";\n\n/**\n *\n * @param {string} value\n * @returns {string}\n * @since 0.0.5\n * @example\n * getCounter(\"GI-1234-CS\"); // => \"CS\"\n * getCounter(\"2345BCF\"); // => \"CS\"\n */\nfunction getCounter(value) {\n const str = !value ? \"\" : value;\n\n if (isOld(str) === true) {\n const [, , counter] = _partsOld(str);\n return counter;\n } else if (isValid(str)) {\n const [, counter] = _partsNew(str);\n return counter;\n }\n\n return null;\n}\n\nexport { getCounter };\n","import { isOld } from \"./isOld\";\nimport { isValid } from \"./isValid\";\nimport { isSpecial } from \"./isSpecial\";\nimport { _partsNew, _partsOld, _partsSpecial } from \"./_utils\";\n\n/**\n *\n * @param {string} value\n * @returns {number}\n * @since 0.0.5\n * @example\n * getNumber(\"2345BCF\"); // => 2345\n * getNumber(\"GI-1234-CS\"); // => 1234\n */\nfunction getNumber(value) {\n const str = !value ? \"\" : value;\n\n if (isOld(str) === true) {\n const [, num] = _partsOld(str);\n return parseInt(num, 10);\n } else if (isSpecial(str) === true) {\n const [, num] = _partsSpecial(str);\n return parseInt(num, 10);\n } else if (isValid(str)) {\n const [num] = _partsNew(str);\n return parseInt(num, 10);\n }\n\n return null;\n}\n\nexport { getNumber };\n","import { SPECIALS } from \"./specials\";\nimport { isSpecial } from \"./isSpecial\";\nimport { _partsSpecial } from \"./_utils\";\n\n/**\n * Returns the special code for a valid car plate\n * @param {string} value\n * @returns {string}\n * @since 0.0.7\n * @example\n * getSpecialCode(\"DGP-1234\"); // => \"DGP\"\n */\nfunction getSpecialCode(value) {\n const str = !value ? \"\" : value;\n\n if (!isSpecial(str)) {\n return null;\n }\n\n const [code] = _partsSpecial(str);\n\n return SPECIALS[code] ? code : null;\n}\n\nexport { getSpecialCode };\n","import { SPECIALS } from \"./specials\";\nimport { getSpecialCode } from \"./getSpecialCode\";\n\n/**\n * Returns the special name for a valid car plate\n * @param {string} value\n * @returns {string}\n * @since 0.0.7\n * @example\n * getSpecialCode(\"CME1234\"); // => \"Corps of the Mossos d'Esquadra\"\n */\nfunction getSpecialName(value) {\n const str = !value ? \"\" : value;\n const code = getSpecialCode(str);\n\n return SPECIALS[code] || null;\n}\n\nexport { getSpecialName };\n","export const PROVINCES = {\n A: \"Province of Alicante\",\n AB: \"Province of Albacete\",\n AL: \"Province of Almería\",\n AV: \"Province of Ávila\",\n B: \"Province of Barcelona\",\n BA: \"Province of Badajoz\",\n BI: \"Bilbao\",\n BU: \"Province of Burgos\",\n C: \"Province of A Coruña\",\n CA: \"Province of Cádiz\",\n CC: \"Province of Cáceres\",\n CE: \"Ceuta\",\n CO: \"Province of Córdoba\",\n CR: \"Province of Ciudad Real\",\n CS: \"Castelló\",\n CU: \"Province of Cuenca\",\n FP: \"Bioko\",\n GC: \"Province of Las Palmas\",\n GE: \"Gerona (Girona)\",\n GI: \"Province of Girona\",\n GR: \"Province of Granada\",\n GU: \"Province of Guadalajara\",\n H: \"Province of Huelva\",\n HU: \"Province of Huesca\",\n IF: \"Ifni\",\n J: \"Province of Jaén\",\n L: \"Province of Lleida\",\n LE: \"Province of León\",\n LO: \"Logroño\",\n LR: \"La Rioja\",\n LU: \"Province of Lugo\",\n M: \"Community of Madrid\",\n MA: \"Province of Málaga\",\n ML: \"Melilla\",\n MU: \"Region of Murcia\",\n NA: \"Navarre\",\n O: \"Oviedo\",\n OU: \"Province of Ourense\",\n P: \"Province of Palencia\",\n PM: \"Palma, Majorca\",\n PO: \"Province of Pontevedra\",\n RM: \"Rio Muni\",\n S: \"Santander\",\n SA: \"Province of Salamanca\",\n SE: \"Province of Seville\",\n SG: \"Province of Segovia\",\n SO: \"Province of Soria\",\n SS: \"Donostia\",\n T: \"Province of Tarragona\",\n TE: \"Province of Teruel\",\n TF: \"Province of Santa Cruz de Tenerife\",\n TO: \"Province of Toledo\",\n V: \"Province of Valencia\",\n VA: \"Province of Valladolid\",\n VI: \"Vitoria\",\n Z: \"Province of Zaragoza\",\n ZA: \"Province of Zamora\"\n};\n","import { PROVINCES } from \"./provinces\";\nimport { isOld } from \"./isOld\";\nimport { _partsOld } from \"./_utils\";\n\n/**\n * Returns the province code for a valid car plate in the old system (1971-2000)\n * @param {string} value\n * @returns {string}\n * @since 0.0.5\n * @example\n * getProvinceCode(\"GI-1234-CS\"); // => \"GI\"\n */\nfunction getProvinceCode(value) {\n const str = !value ? \"\" : value;\n\n if (!isOld(str)) {\n return null;\n }\n\n const [code] = _partsOld(str);\n\n return PROVINCES[code] ? code : null;\n}\n\nexport { getProvinceCode };\n","import { PROVINCES } from \"./provinces\";\nimport { getProvinceCode } from \"./getProvinceCode\";\n\n/**\n * Returns the province name for a valid car plate in the old system (1971-2000)\n * @param {string} value\n * @returns {string}\n * @since 0.0.5\n * @example\n * getProvinceName(\"GI-1234-CS\"); // => \"Province of Girona\"\n */\nfunction getProvinceName(value) {\n const str = !value ? \"\" : value;\n const code = getProvinceCode(str);\n\n return PROVINCES[code] || null;\n}\n\nexport { getProvinceName };\n","import { isValid } from \"./isValid\";\nimport { isOld } from \"./isOld\";\nimport { isSpecial } from \"./isSpecial\";\nimport { getProvinceName } from \"./getProvinceName\";\nimport { getProvinceCode } from \"./getProvinceCode\";\nimport { getCounter } from \"./getCounter\";\nimport { getNumber } from \"./getNumber\";\nimport { getSpecialCode } from \"./getSpecialCode\";\n\nfunction _parseNew(str) {\n const parsed = {};\n parsed.isOld = false;\n parsed.provinceName = null;\n parsed.provinceCode = null;\n parsed.specialCode = null;\n parsed.counter = getCounter(str);\n parsed.number = getNumber(str);\n return parsed;\n}\n\nfunction _parseOld(str) {\n const parsed = {};\n parsed.isOld = true;\n parsed.provinceName = getProvinceName(str);\n parsed.provinceCode = getProvinceCode(str);\n parsed.specialCode = null;\n parsed.counter = getCounter(str);\n parsed.number = getNumber(str);\n return parsed;\n}\n\nfunction _parseSpecial(str) {\n const parsed = {};\n parsed.isOld = false;\n parsed.provinceName = null;\n parsed.provinceCode = null;\n parsed.specialCode = getSpecialCode(str);\n parsed.counter = null;\n parsed.number = getNumber(str);\n parsed.isSpecial = true;\n return parsed;\n}\n\n/**\n * Returns an object containing information about the plate\n * @param {string} value\n * @returns {boolean}\n * @since 0.0.5\n * @example\n * parse(\"2345BCF\"); // => { isSpecial: false, isOld: false, provinceCode: null, provinceName: null, number: 2345, counter: \"BCF\" }\n * parse(\"GI2345BC\"); // => { isSpecial: false, isOld: true, provinceCode: \"GI\", provinceName: \"Province of Girona\", number: 2345, counter: \"BC\" }\n */\nfunction parse(value) {\n const str = !value ? \"\" : value;\n const parsed = {\n isSpecial: false // TODO: not implemented\n };\n\n if (isOld(str) === true) {\n return {\n ...parsed,\n ..._parseOld(str)\n };\n } else if (isSpecial(str) === true) {\n return {\n ...parsed,\n ..._parseSpecial(str)\n };\n } else if (isValid(str) === true) {\n return {\n ...parsed,\n ..._parseNew(str)\n };\n }\n\n return null;\n}\n\nexport { parse };\n"],"names":["_partsSpecial","str","cleaned","replace","split","_partsOld","_partsNew","isOld","value","join","length","test","isValid","SPECIALS","CME","DGP","CNP","E","EA","ET","FAE","FN","GSH","PGC","MF","MMA","MOP","PME","PMM","Crown","isSpecial","code","num","getCounter","counter","getNumber","parseInt","getSpecialCode","getSpecialName","PROVINCES","A","AB","AL","AV","B","BA","BI","BU","C","CA","CC","CE","CO","CR","CS","CU","FP","GC","GE","GI","GR","GU","H","HU","IF","J","L","LE","LO","LR","LU","M","MA","ML","MU","NA","O","OU","P","PM","PO","RM","S","SA","SE","SG","SO","SS","T","TE","TF","TO","V","VA","VI","Z","ZA","getProvinceCode","getProvinceName","_parseNew","parsed","provinceName","provinceCode","specialCode","number","_parseOld","_parseSpecial","parse"],"mappings":";;;;;;;;;;;EAAO,SAASA,aAAT,CAAuBC,GAAvB,EAA4B;EACjC,MAAMC,OAAO,GAAGD,GAAG,CAACE,OAAJ,CACd,4DADc,EAEd,OAFc,CAAhB;EAKA,SAAOD,OAAO,CAACE,KAAR,CAAc,GAAd,CAAP;EACD;AAED,EAAO,SAASC,SAAT,CAAmBJ,GAAnB,EAAwB;EAC7B,MAAMC,OAAO,GAAGD,GAAG,CAACE,OAAJ,CACd,mEADc,EAEd,UAFc,CAAhB;EAKA,SAAOD,OAAO,CAACE,KAAR,CAAc,GAAd,CAAP;EACD;AAED,EAAO,SAASE,SAAT,CAAmBL,GAAnB,EAAwB;EAC7B,MAAMC,OAAO,GAAGD,GAAG,CAACE,OAAJ,CACd,8DADc,EAEd,OAFc,CAAhB;EAKA,SAAOD,OAAO,CAACE,KAAR,CAAc,GAAd,CAAP;EACD;;ECvBD;;;;;;;;;EAQA,SAASG,KAAT,CAAeC,KAAf,EAAsB;EACpB,MAAMP,GAAG,GAAG,CAACO,KAAD,GAAS,EAAT,GAAcA,KAA1B;;EACA,MAAMN,OAAO,GAAGG,SAAS,CAACJ,GAAD,CAAT,CAAeQ,IAAf,CAAoB,EAApB,CAAhB;;EAEA,MAAIP,OAAO,CAACQ,MAAR,GAAiB,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AAA,MAAM,CAACI,MAAP,GAAgBrE,SAAS,CAAClC,GAAD,CAAzB;EACAmG,EAAAA,MAAM,CAACtE,SAAP,GAAmB,IAAnB;EACA,SAAOsE,MAAP;EACD;EAED;;;;;;;;;;;EASA,SAASO,KAAT,CAAenG,KAAf,EAAsB;EACpB,MAAMP,GAAG,GAAG,CAACO,KAAD,GAAS,EAAT,GAAcA,KAA1B;EACA,MAAM4F,MAAM,GAAG;EACbtE,IAAAA,SAAS,EAAE,KADE;;EAAA,GAAf;;EAIA,MAAIvB,KAAK,CAACN,GAAD,CAAL,KAAe,IAAnB,EAAyB;EACvB,6BACKmG,MADL,EAEKK,SAAS,CAACxG,GAAD,CAFd;EAID,GALD,MAKO,IAAI6B,SAAS,CAAC7B,GAAD,CAAT,KAAmB,IAAvB,EAA6B;EAClC,6BACKmG,MADL,EAEKM,aAAa,CAACzG,GAAD,CAFlB;EAID,GALM,MAKA,IAAIW,OAAO,CAACX,GAAD,CAAP,KAAiB,IAArB,EAA2B;EAChC,6BACKmG,MADL,EAEKD,SAAS,CAAClG,GAAD,CAFd;EAID;;EAED,SAAO,IAAP;EACD;;;;;;;;;;;;;;;;;;;;;;;"} \ No newline at end of file diff --git a/src/getSpecialName.js b/src/getSpecialName.js new file mode 100644 index 0000000..1fbf5db --- /dev/null +++ b/src/getSpecialName.js @@ -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 }; diff --git a/src/index.js b/src/index.js index 9c0520a..051768c 100644 --- a/src/index.js +++ b/src/index.js @@ -4,6 +4,7 @@ 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"; diff --git a/test/getSpecialName.test.js b/test/getSpecialName.test.js new file mode 100644 index 0000000..1303076 --- /dev/null +++ b/test/getSpecialName.test.js @@ -0,0 +1,102 @@ +const assert = require("assert"); +const { getSpecialName } = require("../dist/index"); + +describe("#getSpecialName", () => { + describe("invalid", () => { + describe("special plates only", () => { + it("should work only with special plates 1", () => { + assert.equal(getSpecialName("1234BCD"), null); + }); + + it("should work only with special plates 2", () => { + assert.equal(getSpecialName("A 1234 BL"), null); + }); + }); + + describe("unknown special", () => { + it("should not work with unknown code", () => { + assert.equal(getSpecialName("AAA1234"), null); + }); + }); + + describe("wrong input", () => { + it("should return null with null", () => { + assert.equal(getSpecialName(null), null); + }); + + it("should return null with undefined", () => { + assert.equal(getSpecialName(undefined), null); + }); + + it("should return null with empty", () => { + assert.equal(getSpecialName(""), null); + }); + }); + }); + + describe("valid", () => { + it("should get CME", () => { + assert.equal(getSpecialName("CME1234"), "Corps of the Mossos d'Esquadra"); + }); + + it("should get DGP", () => { + assert.equal(getSpecialName("DGP1234"), "Spanish Police"); + }); + + it("should get CNP", () => { + assert.equal(getSpecialName("CNP1234"), "Spanish Police"); + }); + + it("should get E", () => { + assert.equal(getSpecialName("E1234"), "Autonomous police force of the Basque Country"); + }); + + it("should get EA", () => { + assert.equal(getSpecialName("EA1234"), "Air Force"); + }); + + it("should get ET", () => { + assert.equal(getSpecialName("ET1234"), "Spanish Army"); + }); + + it("should get FAE", () => { + assert.equal(getSpecialName("FAE1234"), "Allied Forces in Spain"); + }); + + it("should get FN", () => { + assert.equal(getSpecialName("FN1234"), "Spanish Navy"); + }); + + it("should get GSH", () => { + assert.equal(getSpecialName("GSH1234"), "Colonial police on Sahara"); + }); + + it("should get PGC", () => { + assert.equal(getSpecialName("PGC1234"), "Spanish civil guard"); + }); + + it("should get MF", () => { + assert.equal(getSpecialName("MF1234"), "Public Works Ministry"); + }); + + it("should get MMA", () => { + assert.equal(getSpecialName("MMA1234"), "Environment Ministry"); + }); + + it("should get MOP", () => { + assert.equal(getSpecialName("MOP1234"), "Public Works Ministry"); + }); + + it("should get PME", () => { + assert.equal(getSpecialName("PME1234"), "State owned vehicles"); + }); + + it("should get PMM", () => { + assert.equal(getSpecialName("PMM1234"), "State owned vehicles, on a Ministry"); + }); + + it("should get Crown", () => { + assert.equal(getSpecialName("Crown1234"), "King's Car"); + }); + }); +}); diff --git a/test/index.test.js b/test/index.test.js index e3c61f2..bbb72aa 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -8,6 +8,7 @@ const { getProvinceName, getProvinceCode, getSpecialCode, + getSpecialName, PROVINCES } = require("../dist/index"); @@ -40,6 +41,10 @@ describe("api", () => { assert.ok(getSpecialCode); }); + it("should export getSpecialName", () => { + assert.ok(getSpecialName); + }); + it("should export getCounter", () => { assert.ok(getCounter); });