-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
359 additions
and
14 deletions.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
@Vaporjawn:registry=https://npm.pkg.github.com |
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 |
---|---|---|
@@ -1 +1,79 @@ | ||
# snapple-facts | ||
<h1 align="center"><img src='./src/assets/Snapple_logo_(2020).png' width='50' height='30' align='center' alt='Snapple Logo' /> | ||
Snapple Facts | ||
<img src='./src/assets/Snapple_logo_(2020).png' width='50' height='30' align='center' alt='Snapple Logo' /> | ||
</h1> | ||
|
||
[![Installation](https://github.com/Vaporjawn/snapple-facts/actions/workflows/install.js.yml/badge.svg)](https://github.com/Vaporjawn/snapple-facts/actions/workflows/install.js.yml) | ||
[![Build](https://github.com/Vaporjawn/snapple-facts/actions/workflows/build.js.yml/badge.svg)](https://github.com/Vaporjawn/snapple-facts/actions/workflows/build.js.yml) | ||
[![Linting](https://github.com/Vaporjawn/snapple-facts/actions/workflows/lint.js.yml/badge.svg)](https://github.com/Vaporjawn/snapple-facts/actions/workflows/lint.js.yml) | ||
[![Tests](https://github.com/Vaporjawn/snapple-facts/actions/workflows/tests.js.yml/badge.svg)](https://github.com/Vaporjawn/snapple-facts/actions/workflows/tests.js.yml) | ||
[![Security Scan](https://github.com/Vaporjawn/snapple-facts/actions/workflows/securityScan.yml/badge.svg)](https://github.com/Vaporjawn/snapple-facts/actions/workflows/securityScan.yml) | ||
|
||
[![GitHub repo forks](https://img.shields.io/github/forks/Vaporjawn/snapple-facts?style=flat&logo=github&logoColor=whitesmoke&label=Forks)](https://github.com/Vaporjawn/snapple-facts/network) [![GitHub repo stars](https://img.shields.io/github/stars/Vaporjawn/snapple-facts?style=flat&logo=github&logoColor=whitesmoke&label=Stars)](https://github.com/Vaporjawn/snapple-facts/stargazers) [![GitHub repo contributors](https://img.shields.io/github/contributors-anon/Vaporjawn/snapple-facts?style=flat&logo=github&logoColor=whitesmoke&label=Contributors)](https://github.com/Vaporjawn/snapple-facts/graphs/contributors)[![GitHub org sponsors](https://img.shields.io/github/sponsors/Vaporjawn?style=flat&logo=github&logoColor=whitesmoke&label=Sponsors)](https://github.com/sponsors/Vaporjawn) [![GitHub repo watchers](https://img.shields.io/github/watchers/Vaporjawn/snapple-facts?style=flat&logo=github&logoColor=whitesmoke&label=Watchers)](https://github.com/Vaporjawn/snapple-facts/watchers) [![GitHub repo size](https://img.shields.io/github/repo-size/Vaporjawn/snapple-facts?style=flat&logo=github&logoColor=whitesmoke&label=Repo%20Size)](https://github.com/Vaporjawn/snapple-facts/archive/refs/heads/main.zip) | ||
|
||
<!-- add ts node --> | ||
|
||
[![GitHub package.json dependency version (dev dep on branch)](https://img.shields.io/github/package-json/dependency-version/Vaporjawn/snapple-facts/dev/typescript/main?style=flat&logo=typescript&logoColor=whitesmoke&label=TypeScript)](https://www.typescriptlang.org/) ![GitHub package.json dependency version (dev dep on branch)](https://img.shields.io/github/package-json/dependency-version/Vaporjawn/snapple-facts/dev/prettier/main?style=flat&logo=prettier&logoColor=whitesmoke&label=Prettier) ![GitHub package.json dependency version (dev dep on branch)](https://img.shields.io/github/package-json/dependency-version/Vaporjawn/snapple-facts/dev/eslint/main?style=flat&logo=eslint&logoColor=whitesmoke&label=ESLint) ![GitHub package.json dependency version (dev dep on branch)](https://img.shields.io/github/package-json/dependency-version/Vaporjawn/snapple-facts/dev/jest/main?style=flat&logo=jest&logoColor=whitesmoke&label=Jest)  | ||
|
||
## Technologies | ||
|
||
<img alt="TypeScript" src="https://img.shields.io/badge/typescript-%233178C6.svg?style=for-the-badge&logo=typescript&logoColor=white"/><img alt="Prettier" src="https://img.shields.io/badge/prettier-%23F7B93E.svg?style=for-the-badge&logo=prettier&logoColor=white"/><img alt="ESLint" src="https://img.shields.io/badge/eslint-%234B32C3.svg?style=for-the-badge&logo=eslint&logoColor=white"/><img alt="Jest" src="https://img.shields.io/badge/jest-%23C21325.svg?style=for-the-badge&logo=jest&logoColor=white"/><img alt="NodeJS" src="https://img.shields.io/badge/nodejs-%23339933.svg?style=for-the-badge&logo=node.js&logoColor=white"/><img alt="NPM" src="https://img.shields.io/badge/npm-%23CB3837.svg?style=for-the-badge&logo=npm&logoColor=white"/> | ||
|
||
## Installation | ||
|
||
[![Installation](https://github.com/Vaporjawn/snapple-facts/actions/workflows/install.js.yml/badge.svg)](https://github.com/Vaporjawn/snapple-facts/actions/workflows/install.js.yml) | ||
|
||
```bash | ||
npm install | ||
``` | ||
|
||
## Running | ||
|
||
```bash | ||
npm start | ||
``` | ||
|
||
or | ||
|
||
```bash | ||
npm run dev | ||
``` | ||
|
||
## Testing | ||
|
||
[![Tests](https://github.com/Vaporjawn/snapple-facts/actions/workflows/tests.js.yml/badge.svg)](https://github.com/Vaporjawn/snapple-facts/actions/workflows/tests.js.yml) | ||
|
||
```bash | ||
npm test | ||
``` | ||
|
||
## Building | ||
|
||
[![Build](https://github.com/Vaporjawn/snapple-facts/actions/workflows/build.js.yml/badge.svg)](https://github.com/Vaporjawn/snapple-facts/actions/workflows/build.js.yml) | ||
|
||
```bash | ||
npm run build | ||
``` | ||
|
||
## How To Contribute | ||
|
||
Click on these badges to see how you might be able to help: | ||
|
||
<div align="center" markdown="1"> | ||
|
||
[![GitHub repo Issues](https://img.shields.io/github/issues/Vaporjawn/snapple-facts?style=flat&logo=github&logoColor=red&label=Issues)](https://github.com/Vaporjawn/snapple-facts/issues) [![GitHub repo Good Issues for newbies](https://img.shields.io/github/issues/Vaporjawn/snapple-facts/good%20first%20issue?style=flat&logo=github&logoColor=green&label=Good%20First%20issues)](https://github.com/Vaporjawn/snapple-facts/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22) [![GitHub Help Wanted issues](https://img.shields.io/github/issues/Vaporjawn/snapple-facts/help%20wanted?style=flat&logo=github&logoColor=b545d1&label=%22Help%20Wanted%22%20issues)](https://github.com/Vaporjawn/snapple-facts/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22)[![GitHub repo PRs](https://img.shields.io/github/issues-pr/Vaporjawn/snapple-facts?style=flat&logo=github&logoColor=orange&label=PRs)](https://github.com/Vaporjawn/snapple-facts/pulls) [![GitHub repo Merged PRs](https://img.shields.io/github/issues-search/Vaporjawn/snapple-facts?style=flat&logo=github&logoColor=green&label=Merged%20PRs&query=is%3Amerged)](https://github.com/Vaporjawn/snapple-facts/pulls?q=is%3Apr+is%3Amerged) [![GitHub Help Wanted PRs](https://img.shields.io/github/issues-pr/Vaporjawn/snapple-facts/help%20wanted?style=flat&logo=github&logoColor=b545d1&label=%22Help%20Wanted%22%20PRs)](https://github.com/Vaporjawn/snapple-facts/pulls?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22) | ||
|
||
</div> | ||
|
||
## Thanks to all Contributors 💪 | ||
|
||
- **Thank you** for considering to contribute | ||
- Feel free to submit feature requests, UI updates, bugs as issues. | ||
- Checkout [Contribution Guidelines](https://github.com/Vaporjawn/snapple-facts/blob/master/CONTRIBUTING.md) for more information. | ||
- Have a feature request? Feel free to create a issue for it. | ||
|
||
[![Contributors](https://contrib.rocks/image?repo=Vaporjawn/snapple-facts)](https://github.com/Vaporjawn/snapple-facts/graphs/contributors) | ||
|
||
## Your Support means a lot | ||
|
||
Give a ⭐ to show support for the project. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,9 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const GetFactByNumber = (args) => { | ||
const { snappleFacts, number } = args; | ||
if (number < 1 || number > snappleFacts.length) | ||
throw new Error('Invalid number'); | ||
return snappleFacts.find(fact => fact.number === number); | ||
}; | ||
exports.default = GetFactByNumber; |
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,9 @@ | ||
import { SnappleFact } from '../../interfaces/snappleFact'; | ||
|
||
const GetFactByNumber = (args: { snappleFacts: SnappleFact[]; number: number }): SnappleFact | undefined => { | ||
const { snappleFacts, number } = args; | ||
if (number < 1 || number > snappleFacts.length) throw new Error('Invalid number'); | ||
return snappleFacts.find(fact => fact.number === number); | ||
}; | ||
|
||
export default GetFactByNumber; |
23 changes: 23 additions & 0 deletions
23
src/functions/getFactByNumber/tests/getFactByNumber.test.js
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 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const getFactByNumber_1 = __importDefault(require("../getFactByNumber")); | ||
describe('getFactByNumber', () => { | ||
it('should return a fact for a valid number', () => { | ||
const snappleFacts = [ | ||
{ number: 1, fact: 'fact 1' }, | ||
{ number: 2, fact: 'fact 2' }, | ||
]; | ||
const fact = (0, getFactByNumber_1.default)({ snappleFacts, number: 1 }); | ||
expect(fact).toEqual({ number: 1, fact: 'fact 1' }); | ||
}); | ||
it('should throw an error for an invalid number', () => { | ||
const snappleFacts = [ | ||
{ number: 1, fact: 'fact 1' }, | ||
{ number: 2, fact: 'fact 2' }, | ||
]; | ||
expect(() => (0, getFactByNumber_1.default)({ snappleFacts, number: 3 })).toThrow('Invalid number'); | ||
}); | ||
}); |
20 changes: 20 additions & 0 deletions
20
src/functions/getFactByNumber/tests/getFactByNumber.test.ts
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,20 @@ | ||
import GetFactByNumber from '../getFactByNumber'; | ||
|
||
describe('getFactByNumber', () => { | ||
it('should return a fact for a valid number', () => { | ||
const snappleFacts = [ | ||
{ number: 1, fact: 'fact 1' }, | ||
{ number: 2, fact: 'fact 2' }, | ||
]; | ||
const fact = GetFactByNumber({ snappleFacts, number: 1 }); | ||
expect(fact).toEqual({ number: 1, fact: 'fact 1' }); | ||
}); | ||
|
||
it('should throw an error for an invalid number', () => { | ||
const snappleFacts = [ | ||
{ number: 1, fact: 'fact 1' }, | ||
{ number: 2, fact: 'fact 2' }, | ||
]; | ||
expect(() => GetFactByNumber({ snappleFacts, number: 3 })).toThrow('Invalid number'); | ||
}); | ||
}); |
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,10 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const snappleFacts_json_1 = __importDefault(require("../../snappleFacts.json")); | ||
const GetFacts = () => { | ||
return snappleFacts_json_1.default.snapplefacts; | ||
}; | ||
exports.default = GetFacts; |
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,8 @@ | ||
import { SnappleFact } from '../../interfaces/snappleFact'; | ||
import data from '../../snappleFacts.json'; | ||
|
||
const GetFacts = (): SnappleFact[] => { | ||
return data.snapplefacts; | ||
}; | ||
|
||
export default GetFacts; |
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,20 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const getFacts_1 = __importDefault(require("../getFacts")); | ||
describe('GetFacts', () => { | ||
it('should return an array of SnappleFacts', () => { | ||
const facts = (0, getFacts_1.default)(); | ||
expect(facts.length).toBeGreaterThan(0); | ||
}); | ||
it('should return an array of SnappleFacts with numbers', () => { | ||
const facts = (0, getFacts_1.default)(); | ||
expect(facts[0].number).toBeDefined(); | ||
}); | ||
it('should return an array of SnappleFacts with facts', () => { | ||
const facts = (0, getFacts_1.default)(); | ||
expect(facts[0].fact).toBeDefined(); | ||
}); | ||
}); |
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,18 @@ | ||
import GetFacts from '../getFacts'; | ||
|
||
describe('GetFacts', () => { | ||
it('should return an array of SnappleFacts', () => { | ||
const facts = GetFacts(); | ||
expect(facts.length).toBeGreaterThan(0); | ||
}); | ||
|
||
it('should return an array of SnappleFacts with numbers', () => { | ||
const facts = GetFacts(); | ||
expect(facts[0].number).toBeDefined(); | ||
}); | ||
|
||
it('should return an array of SnappleFacts with facts', () => { | ||
const facts = GetFacts(); | ||
expect(facts[0].fact).toBeDefined(); | ||
}); | ||
}); |
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,6 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const ListFacts = (snappleFacts) => { | ||
return snappleFacts.map(fact => fact.fact); | ||
}; | ||
exports.default = ListFacts; |
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,7 @@ | ||
import { SnappleFact } from '../../interfaces/snappleFact'; | ||
|
||
const ListFacts = (snappleFacts: SnappleFact[]): string[] => { | ||
return snappleFacts.map(fact => fact.fact); | ||
}; | ||
|
||
export default ListFacts; |
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,24 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const listFacts_1 = __importDefault(require("../listFacts")); | ||
describe('ListFacts', () => { | ||
it('should return an array of strings', () => { | ||
const snappleFacts = [ | ||
{ fact: 'Fact 1', number: 1 }, | ||
{ fact: 'Fact 2', number: 2 }, | ||
{ fact: 'Fact 3', number: 3 }, | ||
]; | ||
const expected = ['Fact 1', 'Fact 2', 'Fact 3']; | ||
const actual = (0, listFacts_1.default)(snappleFacts); | ||
expect(actual).toEqual(expected); | ||
}); | ||
it('should return an empty array when given an empty array', () => { | ||
const snappleFacts = []; | ||
const expected = []; | ||
const actual = (0, listFacts_1.default)(snappleFacts); | ||
expect(actual).toEqual(expected); | ||
}); | ||
}); |
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,22 @@ | ||
import { SnappleFact } from '../../../interfaces/snappleFact'; | ||
import ListFacts from '../listFacts'; | ||
|
||
describe('ListFacts', () => { | ||
it('should return an array of strings', () => { | ||
const snappleFacts: SnappleFact[] = [ | ||
{ fact: 'Fact 1', number: 1 }, | ||
{ fact: 'Fact 2', number: 2 }, | ||
{ fact: 'Fact 3', number: 3 }, | ||
]; | ||
const expected = ['Fact 1', 'Fact 2', 'Fact 3']; | ||
const actual = ListFacts(snappleFacts); | ||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('should return an empty array when given an empty array', () => { | ||
const snappleFacts: SnappleFact[] = []; | ||
const expected: string[] = []; | ||
const actual = ListFacts(snappleFacts); | ||
expect(actual).toEqual(expected); | ||
}); | ||
}); |
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,7 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const RandomFact = (snappleFacts) => { | ||
const randomIndex = Math.floor(Math.random() * snappleFacts.length); | ||
return snappleFacts[randomIndex]; | ||
}; | ||
exports.default = RandomFact; |
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,8 @@ | ||
import { SnappleFact } from '../../interfaces/snappleFact'; | ||
|
||
const RandomFact = (snappleFacts: SnappleFact[]): SnappleFact => { | ||
const randomIndex = Math.floor(Math.random() * snappleFacts.length); | ||
return snappleFacts[randomIndex]; | ||
}; | ||
|
||
export default RandomFact; |
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,16 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const randomFact_1 = __importDefault(require("../randomFact")); | ||
describe('RandomFact', () => { | ||
it('should return a random fact', () => { | ||
const snappleFacts = [ | ||
{ number: 1, fact: 'fact 1' }, | ||
{ number: 2, fact: 'fact 2' }, | ||
]; | ||
const fact = (0, randomFact_1.default)(snappleFacts); | ||
expect(fact).toBeDefined(); | ||
}); | ||
}); |
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,12 @@ | ||
import RandomFact from '../randomFact'; | ||
|
||
describe('RandomFact', () => { | ||
it('should return a random fact', () => { | ||
const snappleFacts = [ | ||
{ number: 1, fact: 'fact 1' }, | ||
{ number: 2, fact: 'fact 2' }, | ||
]; | ||
const fact = RandomFact(snappleFacts); | ||
expect(fact).toBeDefined(); | ||
}); | ||
}); |
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
Oops, something went wrong.