Skip to content

Commit

Permalink
2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaporjawn committed Dec 14, 2023
1 parent 53dfc7b commit c3af885
Show file tree
Hide file tree
Showing 26 changed files with 359 additions and 14 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@Vaporjawn:registry=https://npm.pkg.github.com
80 changes: 79 additions & 1 deletion README.md
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)&#160;[![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)&#160;[![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)&#160;[![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)&#160;[![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/)&#160;![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)&#160;![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)&#160;![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)&#160;

## 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)&#160;[![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)&#160;[![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)&#160;[![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)&#160;[![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.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "snapple-facts",
"version": "1.0.1",
"version": "2.0.0",
"description": "Every Snapple Fact",
"main": "./src/index.js",
"scripts": {
Expand Down
Binary file added src/assets/Snapple_logo_(2020).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions src/functions/getFactByNumber/getFactByNumber.js
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;
9 changes: 9 additions & 0 deletions src/functions/getFactByNumber/getFactByNumber.ts
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 src/functions/getFactByNumber/tests/getFactByNumber.test.js
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 src/functions/getFactByNumber/tests/getFactByNumber.test.ts
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');
});
});
10 changes: 10 additions & 0 deletions src/functions/getFacts/getFacts.js
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;
8 changes: 8 additions & 0 deletions src/functions/getFacts/getFacts.ts
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;
20 changes: 20 additions & 0 deletions src/functions/getFacts/tests/getFacts.test.js
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();
});
});
18 changes: 18 additions & 0 deletions src/functions/getFacts/tests/getFacts.test.ts
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();
});
});
6 changes: 6 additions & 0 deletions src/functions/listFacts/listFacts.js
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;
7 changes: 7 additions & 0 deletions src/functions/listFacts/listFacts.ts
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;
24 changes: 24 additions & 0 deletions src/functions/listFacts/tests/listFacts.test.js
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);
});
});
22 changes: 22 additions & 0 deletions src/functions/listFacts/tests/listFacts.test.ts
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);
});
});
7 changes: 7 additions & 0 deletions src/functions/randomFact/randomFact.js
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;
8 changes: 8 additions & 0 deletions src/functions/randomFact/randomFact.ts
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;
16 changes: 16 additions & 0 deletions src/functions/randomFact/tests/randomFact.test.js
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();
});
});
12 changes: 12 additions & 0 deletions src/functions/randomFact/tests/randomFact.test.ts
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();
});
});
24 changes: 22 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,26 @@ 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("./functions/getFactByNumber/getFactByNumber"));
const getFacts_1 = __importDefault(require("./functions/getFacts/getFacts"));
const listFacts_1 = __importDefault(require("./functions/listFacts/listFacts"));
const randomFact_1 = __importDefault(require("./functions/randomFact/randomFact"));
const snappleFacts_json_1 = __importDefault(require("./snappleFacts.json"));
const snappleFacts = snappleFacts_json_1.default.snapplefacts;
exports.default = snappleFacts;
class SnappleFacts {
constructor() {
this.snappleFacts = snappleFacts_json_1.default.snapplefacts;
}
getFacts() {
return (0, getFacts_1.default)();
}
listFacts() {
return (0, listFacts_1.default)(this.snappleFacts);
}
getFactByNumber(number) {
return (0, getFactByNumber_1.default)({ snappleFacts: this.snappleFacts, number });
}
randomFact() {
return (0, randomFact_1.default)(this.snappleFacts);
}
}
exports.default = SnappleFacts;
Loading

0 comments on commit c3af885

Please sign in to comment.