diff --git a/dist/index.js b/dist/index.js index bf54fa0..1e5e7eb 100644 --- a/dist/index.js +++ b/dist/index.js @@ -398,6 +398,7 @@ parsed.provinceName = null; parsed.provinceCode = null; parsed.specialCode = null; + parsed.specialName = null; parsed.counter = getCounter(str); parsed.number = getNumber(str); return parsed; @@ -409,6 +410,7 @@ parsed.provinceName = getProvinceName(str); parsed.provinceCode = getProvinceCode(str); parsed.specialCode = null; + parsed.specialName = null; parsed.counter = getCounter(str); parsed.number = getNumber(str); return parsed; @@ -420,6 +422,7 @@ parsed.provinceName = null; parsed.provinceCode = null; parsed.specialCode = getSpecialCode(str); + parsed.specialName = getSpecialName(str); parsed.counter = null; parsed.number = getNumber(str); parsed.isSpecial = true; diff --git a/dist/index.js.map b/dist/index.js.map index cb0eeac..862f2f2 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/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,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C7B,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 +{"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\";\nimport { getSpecialName } from \"./getSpecialName\";\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.specialName = 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.specialName = 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.specialName = getSpecialName(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","specialName","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,S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KAAmB,IAAvB,EAA6B;EAClC,6BACKmG,MADL,EAEKO,aAAa,CAAC1G,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/parse.js b/src/parse.js index 173eada..c28032d 100644 --- a/src/parse.js +++ b/src/parse.js @@ -6,6 +6,7 @@ import { getProvinceCode } from "./getProvinceCode"; import { getCounter } from "./getCounter"; import { getNumber } from "./getNumber"; import { getSpecialCode } from "./getSpecialCode"; +import { getSpecialName } from "./getSpecialName"; function _parseNew(str) { const parsed = {}; @@ -13,6 +14,7 @@ function _parseNew(str) { parsed.provinceName = null; parsed.provinceCode = null; parsed.specialCode = null; + parsed.specialName = null; parsed.counter = getCounter(str); parsed.number = getNumber(str); return parsed; @@ -24,6 +26,7 @@ function _parseOld(str) { parsed.provinceName = getProvinceName(str); parsed.provinceCode = getProvinceCode(str); parsed.specialCode = null; + parsed.specialName = null; parsed.counter = getCounter(str); parsed.number = getNumber(str); return parsed; @@ -35,6 +38,7 @@ function _parseSpecial(str) { parsed.provinceName = null; parsed.provinceCode = null; parsed.specialCode = getSpecialCode(str); + parsed.specialName = getSpecialName(str); parsed.counter = null; parsed.number = getNumber(str); parsed.isSpecial = true; diff --git a/test/parse.test.js b/test/parse.test.js index a3b5993..61238b2 100644 --- a/test/parse.test.js +++ b/test/parse.test.js @@ -27,6 +27,7 @@ describe("#parse", () => { isSpecial: true, isOld: false, specialCode: "DGP", + specialName: "Spanish Police", provinceCode: null, provinceName: null, number: 1234, @@ -41,6 +42,7 @@ describe("#parse", () => { isSpecial: false, isOld: true, specialCode: null, + specialName: null, provinceCode: "GI", provinceName: "Province of Girona", number: 2345, @@ -55,6 +57,7 @@ describe("#parse", () => { isSpecial: false, isOld: false, specialCode: null, + specialName: null, provinceCode: null, provinceName: null, number: 2345, diff --git a/types/index.d.ts b/types/index.d.ts index 8ea3bd0..1437c55 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -2,20 +2,17 @@ declare function getCounter(value: string): string; declare function getNumber(value: string): number; declare function getProvinceCode(value: string): string; declare function getProvinceName(value: string): string; - declare function isSpecial(value: string): boolean; -/** - * Returns true if is a valid (old system 1971-2000) car plate - */ +declare function getSpecialName(value: string): string; +declare function getSpecialCode(value: string): string; declare function isOld(value: string): boolean; -/** - * Returns true if is a valid (post year 2000) car plate - */ declare function isValid(value: string): boolean; interface IPlate { isSpecial: boolean; isOld: boolean; + specialCode: string; + specialName: string; provinceCode: string; provinceName: string; number: number; @@ -35,6 +32,8 @@ export { getCounter, getProvinceName, getProvinceCode, + getSpecialName, + getSpecialCode, getNumber, PROVINCES, SPECIALS