-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat iranian postal code #340
Open
amir-hossein-karimi
wants to merge
5
commits into
persian-tools:master
Choose a base branch
from
amir-hossein-karimi:feat-iranian-postal-code
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8988f14
feat: add iranian postal code validation
amir-hossein-karimi 6e0eb4e
feat: export iranian postal code validation from src index
amir-hossein-karimi 83b34da
test: add irania postal code validation function test
amir-hossein-karimi dcaf775
docs: add iranian postal code validation feature in readme file
amir-hossein-karimi c445dab
fix: change describe message
amir-hossein-karimi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ | |
- [Get the Remaining Time of the Date](#get-the-remaining-time-of-the-date) | ||
- [Validate and find information of phone number](#validate-and-find-information-of-phone-number). | ||
- [Find capital city by province name ](#find-capital-city-by-province-name) | ||
- [Validate Iranian Postal code](#validate-iranian-postal-code). | ||
|
||
## Getting started | ||
|
||
|
@@ -558,6 +559,23 @@ findCapitalByProvince("آذربایجان شرقی"); // تبریز | |
findCapitalByProvince("دبی"); | ||
``` | ||
|
||
### Validate Iranian Postal code | ||
|
||
**Usage** | ||
|
||
> this function validate entry postal code and return boolean for validation confirm | ||
|
||
```js | ||
import { iranianPostalCodeValidate } from "@persian-tools/persian-tools"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename to |
||
|
||
// valid postal code | ||
iranianPostalCodeValidate("1193653471"); // true | ||
|
||
// invalid postal code | ||
iranianPostalCodeValidate("142386473"); // false | ||
iranianPostalCodeValidate("1111111111"); // false | ||
``` | ||
|
||
### Todo | ||
|
||
- [ ] Write Jalaali and Gregorian functions to convert Date together. | ||
|
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,27 @@ | ||
|
||
/** | ||
* iranianPostalCodeValidate | ||
* | ||
* @description Takes a postal code and validate with return a boolean. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add
and explain the algorithms you've implemented. |
||
* | ||
* | ||
* @param postalCode as string | ||
* @return if postal code is valid return true , but if postal code is not valid return false | ||
*/ | ||
const iranianPostalCodeValidate = (postalCode: string = ""): boolean => { | ||
const pc = postalCode.toString(); | ||
if (/\D/g.test(pc)) return false; | ||
|
||
return ( | ||
pc.length === 10 && | ||
!pc.slice(0, 5).includes("2") && | ||
!pc.slice(0, 5).includes("0") && | ||
pc[4] !== "5" && | ||
pc[5] !== "0" && | ||
pc.slice(-4) !== "0000" && | ||
!pc.split("").every((char) => char === pc[0]) | ||
); | ||
} | ||
|
||
|
||
export default iranianPostalCodeValidate |
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,23 @@ | ||
import { iranianPostalCodeValidate } from "../src"; | ||
import { describe, it, expect } from "vitest"; | ||
|
||
const validPostalCode = "1193653471" | ||
const invalidPostalCodes = [ | ||
'142386473', | ||
'12', | ||
'1111111111', | ||
'0423437584', | ||
"test invalid postalCode" | ||
] | ||
|
||
describe("iranianPostalCode", () => { | ||
it('valid postal code', () => { | ||
expect(iranianPostalCodeValidate(validPostalCode)).toBeTruthy() | ||
}) | ||
|
||
it('invalid postal codes', () => { | ||
invalidPostalCodes.forEach((invalidPostalCode) => { | ||
expect(iranianPostalCodeValidate(invalidPostalCode)).toBeFalsy() | ||
}) | ||
}) | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace with
This function validates the entry postal code and returns a boolean for validation confirmation.