diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..63a6671 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,10 @@ +{ + "singleQuote": true, + "printWidth": 200, + "proseWrap": "always", + "tabWidth": 4, + "useTabs": false, + "trailingComma": "none", + "bracketSpacing": true, + "semi": true +} \ No newline at end of file diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..d07a5a4 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) [2022] [country-data-codes] + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..682f79d --- /dev/null +++ b/README.md @@ -0,0 +1,128 @@ +Country Data Codes +========== + +A node js package to get country data including country name, code, currency information, emoji etc. + +## Introduction +A simple but useful functional node packages with all country data. It includes all useful country data gives several function to complete your project. + +## Countries + +The data currently provided for each country is: + + * `id` The unique id number for the array + * `name` The english name for the country + * `isoAlpha2` The [ISO 3166-1 alpha 2](http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) code + * `isoAlpha3` The [ISO 3166-1 alpha 3](http://en.wikipedia.org/wiki/ISO_3166-1_alpha-3) code + * `isoNumeric` The [ISO 3166-1 numeric](https://en.wikipedia.org/wiki/ISO_3166-1_numeric) + * `currency` An object with currency info. + + - `code` The [ISO 4217 currency codes](http://en.wikipedia.org/wiki/ISO_4217) + - `name` The currency name + - `symbol` The currency symbol + + * `flag` Country flag base64 data + * `languages` An array of [ISO 639-2](http://en.wikipedia.org/wiki/ISO_639-2) codes for languages. + * `countryCallingCodes` An array of the international call prefixes for this country. + * `emoji` The emoji of country's flag. + +## Installation + +```bash +$ npm i country-data-codes +``` +```bash +import { getCountryList } from "country-data-codes"; +or +const { getCountryList } = require("country-data-codes") +``` +Example +```bash +console.log(getCountryList()); //Returns all country list +``` + +## Methods +### getCurrency(countryCode) +Returns the country's currency info by providing country code. + +Example +```bash +import { getCurrency, GetCurrencyTypes } from "country-data-codes"; + +const currencyInfo: GetCurrencyTypes = getCurrency("BD"); // Here country code can be isoAlpha2 or isoAlpha3 + +console.log(currencyInfo) +``` +Return values- +* `name` currency name +* `code` currency code +* `symbol` currency symbol + +### getCallingCode(countryCode) +Returns the country's calling code. It returns an array of string. + +Example +```bash +import { getCallingCode } from "country-data-codes"; + +console.log(getCallingCode("BD")) // Give the country code(isoAlpha2 or isoAlpha3) +//["+88"] +``` +### getLanguages(countryCode) +Returns the country's languages. It returns an array of string; + +Example +```bash +import { getLanguages } from "country-data-codes"; + +console.log(getLanguages("BD")) // Give the country code(isoAlpha2 or isoAlpha3) +//["ben"] +``` + +### getFlagBase64(countryCode) +Returns the country's flag image as base64 data + +Example +```bash +import { getFlagBase64 } from "country-data-codes"; + +const flag = getFlagBase64("BD") // Give the country code(isoAlpha2 or isoAlpha3) + +// +``` + +### lookup(query) +You can search and find any country's data by any parameter, like- +* by `name`: You can search and find data by country name +* by `countryCode`: You can search and find data by country code +* by `callingCode`: You can search and find data by country calling code +* by `currencyName`: You can search and find data by country currency name +* by `currencyCode`: You can search and find data by country currency code +* by `currencySymbol`: You can search and find data by country currency symbol +* by `isoNumeric`: You can search and find data by country iso numeric + +Example +```bash +import { lookup, CountryDataTypes } from "country-data-codes"; + +const data: CountryDataTypes = lookup({name: "Bangladesh"}) +const data: CountryDataTypes = lookup({countryCode: "BD"}) +const data: CountryDataTypes = lookup({callingCode: "+880"}) +const data: CountryDataTypes = lookup({currencyName: "taka"}) +const data: CountryDataTypes = lookup({currencyCode: "BDT"}) +const data: CountryDataTypes = lookup({currencySymbol: "৳"}) +``` + +## Issues or correction +If you face any issues to any function or see any wrong information about country, please let me know. + +## Stay in touch + +- Author - [Siam Ahnaf](https://www.siamahnaf.com/) +- Website - [https://www.siamahnaf.com/](https://www.siamahnaf.com/) +- Twitter - [https://twitter.com/siamahnaf198](https://twitter.com/siamahnaf198) +- Githup - [https://github.com/siamahnaf198](https://github.com/siamahnaf198) + +## License + +country-data-codes [MIT licensed](LICENSE). \ No newline at end of file diff --git a/example/index.ts b/example/index.ts new file mode 100644 index 0000000..3af7695 --- /dev/null +++ b/example/index.ts @@ -0,0 +1,28 @@ +import { getCountryList, getCurrency, GetCurrencyTypes, getCallingCode, getLanguages, getFlagBase64, lookup, CountryDataTypes } from "country-data-codes"; + +console.log(getCountryList()); + + +const currencyInfo: GetCurrencyTypes = getCurrency("BD"); // Here country code can be isoAlpha2 or isoAlpha3 + +console.log(currencyInfo) + +console.log(getCallingCode("BD")) // Give the country code(isoAlpha2 or isoAlpha3) +//["+88"] + +console.log(getLanguages("BD")) // Give the country code(isoAlpha2 or isoAlpha3) +//["ben"] + +const flag = getFlagBase64("BD") // Give the country code(isoAlpha2 or isoAlpha3) + +// + + +const data1: CountryDataTypes = lookup({ name: "Bangladesh" }) +const data2: CountryDataTypes = lookup({ countryCode: "BD" }) +const data3: CountryDataTypes = lookup({ callingCode: "+880" }) +const data4: CountryDataTypes = lookup({ currencyName: "taka" }) +const data5: CountryDataTypes = lookup({ currencyCode: "BDT" }) +const data6: CountryDataTypes = lookup({ currencySymbol: "৳" }) + +console.log(data1); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..b3142ec --- /dev/null +++ b/package-lock.json @@ -0,0 +1,63 @@ +{ + "name": "country-data-codes", + "version": "4.0.2", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "country-data-codes", + "version": "4.0.2", + "license": "MIT", + "dependencies": { + "country-data-codes": "^4.0.2" + }, + "devDependencies": { + "@types/node": "^18.11.10", + "typescript": "^4.9.3" + } + }, + "node_modules/@types/node": { + "version": "18.11.13", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.13.tgz", + "integrity": "sha512-IASpMGVcWpUsx5xBOrxMj7Bl8lqfuTY7FKAnPmu5cHkfQVWF8GulWS1jbRqA934qZL35xh5xN/+Xe/i26Bod4w==", + "dev": true + }, + "node_modules/country-data-codes": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/country-data-codes/-/country-data-codes-4.0.2.tgz", + "integrity": "sha512-bwg/AtEIgHXYP8z2w3xK7vs/qdAiBBWJ4pGoneTjClfZZq1gO40iqRp+0202k3Dn3c5hIhEX2/6e/uze6C+p5g==" + }, + "node_modules/typescript": { + "version": "4.9.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.4.tgz", + "integrity": "sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=4.2.0" + } + } + }, + "dependencies": { + "@types/node": { + "version": "18.11.13", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.13.tgz", + "integrity": "sha512-IASpMGVcWpUsx5xBOrxMj7Bl8lqfuTY7FKAnPmu5cHkfQVWF8GulWS1jbRqA934qZL35xh5xN/+Xe/i26Bod4w==", + "dev": true + }, + "country-data-codes": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/country-data-codes/-/country-data-codes-4.0.2.tgz", + "integrity": "sha512-bwg/AtEIgHXYP8z2w3xK7vs/qdAiBBWJ4pGoneTjClfZZq1gO40iqRp+0202k3Dn3c5hIhEX2/6e/uze6C+p5g==" + }, + "typescript": { + "version": "4.9.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.4.tgz", + "integrity": "sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==", + "dev": true + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..1c732be --- /dev/null +++ b/package.json @@ -0,0 +1,36 @@ +{ + "name": "country-data-codes", + "version": "4.0.2", + "description": "Easy and Simple Country Data and Code Management solution🤷", + "main": "dist/cjs/index.js", + "module": "dist/esm/index.js", + "homepage": "https://github.com/siamahnaf198/country-data-codes", + "keywords": [ + "country-data-code", + "country code", + "calling code", + "currency-symbol", + "currency-code", + "country-name", + "react", + "node" + ], + "scripts": { + "test": "prettier --write src/ && npm run build:esm && npm run build:cjs", + "build": "rmdir /s /q dist && prettier --write src/ && npm run build:esm && npm run build:cjs", + "build:esm": "tsc", + "build:cjs": "tsc --module CommonJs --outDir dist/cjs" + }, + "author": "Siam Ahnaf", + "license": "MIT", + "devDependencies": { + "@types/node": "^18.11.10", + "typescript": "^4.9.3" + }, + "repository": { + "directory": "https://github.com/siamahnaf198/country-data-codes" + }, + "dependencies": { + "country-data-codes": "^4.0.2" + } +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..4ecd541 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + "allowSyntheticDefaultImports": true, + "declaration": true, + "esModuleInterop": true, + "lib": [ + "es5", + "es2015", + "es2016", + "dom", + "esnext" + ], + "types": [ + "node" + ], + "module": "es2015", + "moduleResolution": "node", + "noImplicitAny": true, + "noUnusedLocals": true, + "outDir": "dist/esm", + "sourceMap": true, + "strict": true, + "target": "es6" + }, + "include": [ + "src/**/*.ts", + "src/**/*.tsx" + ] +} \ No newline at end of file