Skip to content

Commit

Permalink
Merge pull request #7 from opencollective/dev/add-tests-and-ci
Browse files Browse the repository at this point in the history
Add tests + prettier and configure CI
  • Loading branch information
Betree authored Dec 28, 2023
2 parents 3e3cec4 + 9404388 commit fa83bb3
Show file tree
Hide file tree
Showing 9 changed files with 3,731 additions and 14 deletions.
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

0 comments on commit fa83bb3

Please sign in to comment.