Docs updates

This commit is contained in:
Nemo 2023-07-02 14:48:11 +05:30
parent 2461fc5ace
commit a5adba4a5c
3 changed files with 60 additions and 4 deletions

View File

@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at me@captnemo.in. All
reported by contacting the project team at coc@captnemo.in. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.

38
CONTRIBUTING.md Normal file
View File

@ -0,0 +1,38 @@
# Contribution Guidelines
## Generating the regex
1. Download the latest CSV file from <https://data.gov.in/resources/all-india-pincode-directory-till-last-month>.
2. Copy all the pincodes to a pincodes.csv file
3. Generate all unique pincodes by running `npm run build`
## Regex Notes
Note that the regexes are all PCRE compatible, but do not include `/` at the beginning or end. This is for cross-compatibility and ease of use.
The two files are:
- `regex.txt` - This is the regex for validating a pincode. It is a single regex.
- `regexes.txt` - It is a list of regexes, one per line. One regex is available per area code (the first digit of the PIN, which goes from 1-8).
## Generating the browser-version
1. Make sure development dependencies are installed.
2. `npm run browserify`.
3. Test it by opening `tests/index.html` in your browser.
# PHP Release
1. `git tag v1.2.3`
2. `git push --tags`
## Ruby Development
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
Run `gem build pincode-validator.gemspec` to build the gem, and `tar --to-stdout -xf *.gem data.tar.gz | tar -zt` to validate the list of files inside the gem before publishing it.
## Code of Conduct
Please see [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) for the code of conduct.

View File

@ -4,7 +4,7 @@ Validate a [Postal Index Number][wiki] for India with a few regexes and zero fal
## Why?
A simple `\d{6}` approach marks a lot of invalid pincodes as valid. Out of the 900000 possible combinations, only approximately `155600` are valid pincodes in India. A simple example is `111111` which is an invalid pincode, but any simple 6 digit-check will pass it as a valid one. File a PR to support any other language.
A simple `\d{6}` approach marks a lot of invalid pincodes as valid. Out of the 900000 possible combinations, only approximately `19000` are valid pincodes in India. A simple example is `111111` which is an invalid pincode, but any simple 6 digit-check will pass it as a valid one.
## Source
@ -12,7 +12,7 @@ The source for the data is the ["All India Pincode Directory"](https://data.gov.
## Usage
The `regex.txt` file is 32KB in size, so you can easily use it wherever you want, including browsers. If you are using any of the packages below, this is already delivered compressed.
The `regex.txt` file is 32KB in size, so you can easily use it wherever you want, including browsers. If you are using any of the packages below, this is already delivered compressed. You can use the regex directly, or via a few helper methods.
### PHP
@ -22,7 +22,13 @@ To use the PHP package:
```php
use PIN\Validator as P;
// validates a given pincode
// returns boolean
P::validate('110011'); // returns true;
// Searches for all valid pincodes in a given string.
// returns array(string)
P::search('bangalore 560029'); // returns ["560029"]
```
### Node.js
@ -41,6 +47,8 @@ P.exactRegex.match('560029')
"address with pincode (560029)".matchAll(P.regex)
````
Please see `tests/validate.js` for more examples.
## Ruby
Add this line to your application's Gemfile:
@ -57,6 +65,16 @@ Or install it yourself as:
$ gem install pincode_validator
```ruby
require 'pincode_validator'
Pin::valid?('560029') # returns true
Pin::valid?('111111') # returns false
Pin::search('my pincode is 244713') # returns ['244713']
Pin::search('my pincode is 244713 or 560029') # returns ['244713', '560029']
```
### Browser
To use it in the browser, download the `pincode-regex.js` file and include it in your browser. `Pincode` is available as a Global variable.
@ -68,7 +86,7 @@ Pincode.validate("560029"); // returns true
</script>
```
You can use githack for directly using this in your code: <https://rawcdn.githack.com/captn3m0/india-pincode-regex/1.0.4/pincode-regex.js> (Make sure you use the latest version). Please watch the repo to get notified of new releases.
You can use githack for directly using this in your code: <https://rawcdn.githack.com/captn3m0/india-pincode-regex/v2.0.0/pincode-regex.js> (Make sure you use the latest version). Please watch the repo to get notified of new releases.
## Code of Conduct