From dc6531ee98cd6896da812a8f79fc411c73200d3a Mon Sep 17 00:00:00 2001 From: Nemo Date: Sun, 19 Dec 2021 19:18:41 +0530 Subject: [PATCH] Minor updates --- .editorconfig | 2 +- .gitignore | 3 +++ CHANGELOG.md | 11 +++++++++++ HACKING.md | 2 +- Pipfile | 11 ----------- src/generate.js | 16 ++++++++++------ 6 files changed, 26 insertions(+), 19 deletions(-) create mode 100644 CHANGELOG.md delete mode 100644 Pipfile diff --git a/.editorconfig b/.editorconfig index 85a3ce7..ba2e75b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -2,7 +2,7 @@ root = true [*] indent_style = space -# indent_size = 2 +indent_size = 2 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true diff --git a/.gitignore b/.gitignore index 5315270..eac44e4 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,6 @@ __pycache__/ Gemfile.lock *.gem *.csv +.pdm.toml +__pypackages__/ +src/pincode.egg-info/ diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..bed6530 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,11 @@ +# Changelog + +All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [UNRELEASED][unreleased] + +## [1.0.5][1.0.5] +## + +[1.0.5]: https://github.com/captn3m0/india-pincode-regex/releases/tag/1.0.5 diff --git a/HACKING.md b/HACKING.md index 0c13c39..2ec61f8 100644 --- a/HACKING.md +++ b/HACKING.md @@ -1,6 +1,6 @@ # Generating the regex -1. Download the latest CSV file from or . +1. Download the latest CSV file from . 2. Copy all the pincodes to a pincodes.txt file 3. Generate all unique pincodes by running `sort -u pincodes.txt > /tmp/pin.txt` 4. `npm install` diff --git a/Pipfile b/Pipfile deleted file mode 100644 index 9c7ae7b..0000000 --- a/Pipfile +++ /dev/null @@ -1,11 +0,0 @@ -[[source]] -name = "pypi" -url = "https://pypi.org/simple" -verify_ssl = true - -[dev-packages] - -[packages] - -[requires] -python_version = "3.5" diff --git a/src/generate.js b/src/generate.js index feafd26..fdc2ee2 100644 --- a/src/generate.js +++ b/src/generate.js @@ -9,26 +9,30 @@ if (!process.argv[2]) { const readInterface = readline.createInterface({ input: fs.createReadStream(process.argv[2]), - console: false + console: false, }); regexes = []; +// There are 3 Pincodes that start with 9, but we +// ignore those as test offices. for (var i = 0; i < 8; i++) { regexes.push(new Trie()); } -readInterface.on("line", function(line) { +readInterface.on("line", function (line) { if (line.length === 6) { // First character of the PIN let areaCode = parseInt(line.charAt(0), 10); - let areaCodeIndex = areaCode - 1; - regexes[areaCodeIndex].add(line); + if (areaCode < 9 && areaCode > 0) { + let areaCodeIndex = areaCode - 1; + regexes[areaCodeIndex].add(line); + } } }); -readInterface.on("close", function() { - for(i in regexes) { +readInterface.on("close", function () { + for (i in regexes) { console.log(regexes[i].toRegExp()); } });