Skip to content
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

Add tests + prettier and configure CI #7

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Tests

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

jobs:
prettier:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 20.x
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Prettier
run: npm run prettier:check

test:
name: Unit tests
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x, 18.x, 20.x]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## country-currency-emoji-flags

This small package helps to obtain emojis based on the currency
code ([ISO 4217](https://en.wikipedia.org/wiki/ISO_4217)).
code ([ISO 4217](https://en.wikipedia.org/wiki/ISO_4217)) or country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)).

### Install

Expand All @@ -10,14 +10,19 @@ code ([ISO 4217](https://en.wikipedia.org/wiki/ISO_4217)).
### Usage

```js
import {getEmojiByCountryCode, getEmojiByCurrencyCode, countryData, currencyData} from 'country-currency-emoji-flags';
import {
getEmojiByCountryCode,
getEmojiByCurrencyCode,
countryData,
currencyData,
} from "country-currency-emoji-flags";

// Currency lookup
emojiFlags.getEmojiByCurrencyCode('CAD');
emojiFlags.getEmojiByCurrencyCode("CAD");
// => "🇨🇦"

// Country lookup
emojiFlags.getEmojiByCountryCode('CA');
emojiFlags.getEmojiByCountryCode("CA");
// => "🇨🇦"

// entire currency code set
Expand Down
1 change: 0 additions & 1 deletion country-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,3 @@
"ZM": "🇿🇲",
"ZW": "🇿🇼"
}

4 changes: 2 additions & 2 deletions currency-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"COP": "🇨🇴",
"CRC": "🇨🇷",
"CUC": "🇨🇺",
"CUP": "🇨🇺",
"CUP": "🇨🇺",
"CVE": "🇨🇻",
"CZK": "🇨🇿",
"DJF": "🇩🇯",
Expand Down Expand Up @@ -85,7 +85,7 @@
"LSL": "🇱🇸",
"LTL": "🇱🇹",
"LVL": "🇱🇻",
"LYD": "🇱🇾",
"LYD": "🇱🇾",
"MAD": "🇲🇦",
"MDL": "🇲🇩",
"MGA": "🇲🇬",
Expand Down
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
'use strict';
"use strict";

const currencyData = require('./currency-data.json');
const countryData = require('./country-data.json');
const currencyData = require("./currency-data.json");
const countryData = require("./country-data.json");

const methods = {
getEmojiByCountryCode: countryCode => {
getEmojiByCountryCode: (countryCode) => {
if (!countryCode) {
return null;
}

return countryData[countryCode.toUpperCase()];
},

getEmojiByCurrencyCode: currencyCode => {
getEmojiByCurrencyCode: (currencyCode) => {
if (!currencyCode) {
return null;
}
Expand Down
26 changes: 26 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const { getEmojiByCountryCode } = require("./index");
const { getEmojiByCurrencyCode } = require("./index");

describe("getEmojiByCountryCode", () => {
it("should return null if no country code is passed", () => {
expect(getEmojiByCountryCode()).toBeNull();
});

it("should return the emoji for the country code passed", () => {
expect(getEmojiByCountryCode("us")).toBe("🇺🇸");
expect(getEmojiByCountryCode("US")).toBe("🇺🇸");
expect(getEmojiByCountryCode("FR")).toBe("🇫🇷");
});
});

describe("getEmojiByCurrencyCode", () => {
it("should return null if no currency code is passed", () => {
expect(getEmojiByCurrencyCode()).toBeNull();
});

it("should return the emoji for the currency code passed", () => {
expect(getEmojiByCurrencyCode("usd")).toBe("🇺🇸");
expect(getEmojiByCurrencyCode("EUR")).toBe("🇪🇺");
expect(getEmojiByCurrencyCode("GBP")).toBe("🇬🇧");
});
});
Loading