redpeacock78/sushiro.js

View on GitHub
README.md

Summary

Maintainability
Test Coverage
# sushiro.js
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/redpeacock78/sushiro.js/blob/master/LICENSE)  [![npm version](https://badge.fury.io/js/sushiro.js.svg)](https://badge.fury.io/js/sushiro.js) [![Npm Publish](https://github.com/redpeacock78/sushiro.js/actions/workflows/npm-publish.yml/badge.svg?branch=master)](https://github.com/redpeacock78/sushiro.js/actions/workflows/npm-publish.yml) [![Maintainability](https://api.codeclimate.com/v1/badges/1475f12e9437c19434ba/maintainability)](https://codeclimate.com/github/redpeacock78/sushiro.js/maintainability) [![codecov](https://codecov.io/gh/redpeacock78/sushiro.js/branch/master/graph/badge.svg?token=E0WE1464IN)](https://codecov.io/gh/redpeacock78/sushiro.js)  
🍣 A Node.js porting of [sushiro](https://github.com/redpeacock78/sushiro).🍣 

## 🛠 Usage
### đŸ–„ CLI
```console
$ yarn global add sushiro.js  # npm install -g sushiro.js

$ sushiro-js -h
Usage: sushiro-js [options]

Options:
  -r [number]     Randomly display the number of specified menus (By default it
                  display one item)
  -p [menu_name]  Display price of menu corresponding to name (If not
                  specified,all menus and prices will be displayed)
  -k [menu_name]  Display the calorie of the name corresponding menu (If not
                  specified,all menus and prices will be displayed)
  -a              Display names of all menus (158 species in total)
  -v, --version   Output the version number
  -h, --help      display help for command

$ sushiro-js -r
æ‰‹ć·»ăçŽè±†

$ sushiro-js -r 5
é­šăźă‚ąăƒ©ăźè”€ă ă—
ă‚Šă‚“ă”ă‚žăƒ„ăƒŒă‚čă€€ć›œç”Ł100果汁
ăă‚…ă†ă‚Šć·»
ç„ŒăéŻ–
æ•°ăźć­æŸć‰æŒŹă‘

$ sushiro-js -k 〆
性えび3èȫ盛り(æŽ»ă€†ć€§ăˆăłăƒ»ç‰čć€§ă‚žăƒŁăƒłăƒœè”€ăˆăłăƒ»ć€§ćž‹ç”Ÿăˆăł) 121kcal
〆真さば 115kcal
〆真さば(ă”ăŸăƒă‚ź) 117kcal
〆いわし(ăƒă‚źăƒ»ç”Ÿć§œ) 101kcal
```
### 📄 Javascript
```javascript
import { Sushiro } from 'sushiro.js';

(async () => {
    const sushiro = new Sushiro();
    await sushiro.random(5).then((menu) => {
        console.log(menu);
    });
})();
/*
甘えび
ăă‚…ă†ă‚Šć·»
æŠčèŒ¶ăšă‚ă‚“ă“ăźć’Œăƒ‘ăƒ•ă‚§
生たこ
ç‰čネタ侭べろ
*/
(async () => {
    const sushiro = new Sushiro();
    await sushiro.price('さば').then((menu) => {
        console.log(menu);
    });
})();
/*
〆真さば 100憆+繎
〆真さば(ă”ăŸăƒă‚ź) 100憆+皎
*/
(async () => {
    const sushiro = new Sushiro();
    await sushiro.calorie('ă‚łăƒŒăƒ’ăƒŒ').then((menu) => {
        console.log(menu);
    });
})();
/*
ă‚ąă‚€ă‚čă‚łăƒŒăƒ’ăƒŒ 砂糖ăȘしぼ栮搈4kcal
ăƒ›ăƒƒăƒˆă‚łăƒŒăƒ’ăƒŒ 砂糖ăȘしぼ栮搈7kcal
*/
```

## 🔗 API
### `sushiro.all(): Promise<string>`
Get the names of all menus that currently exist in "https://www.akindo-sushiro.co.jp".
```javascript
(async () => {
    const sushiro = new Sushiro();
    console.log(await sushiro.all());
})();
```
### `sushiro.random(random_num?: number): Promise<string>`
If a number is specified as an argument, the specified number of menu names will be returned randomly from the menu names currently available at "https://www.akindo-sushiro.co.jp".  
If no number is specified as an argument, it will randomly extract one of the menu names currently available at "https://www.akindo-sushiro.co.jp" and return it.  
If the number is greater than the number of menus currently available, an error message will be returned.
```javascript
(async () => {
    const sushiro = new Sushiro();
    console.log(await sushiro.random()); // No Argument
    console.log(await sushiro.random(20)); // When 20 is specified as an argument
    await sushiro.random(1000).catch(() => {
      console.error("There aren't that many menus!"); // Too many numbers in the argument
    })
})();
```
### `sushiro.price(search_word?: string): Promise<string>`
If a string is specified as the argument, it will return the names and prices of the menus that partially match the menu names currently available at "https://www.akindo-sushiro.co.jp".  
If no argument is specified, it will return the names and prices of all the menus currently available at "https://www.akindo-sushiro.co.jp".  
If there is no menu that matches the argument, it will return an error.
```javascript
(async () => {
    const sushiro = new Sushiro();
    console.log(await sushiro.price()); // No Argument
    console.log(await sushiro.price('えび')); // When "えび" is specified as an argument
    await sushiro.price('Github').catch(() => {
      console.error('There is no item with that name!'); // When the search result does not exist
    });
})();
```
### `sushiro.calorie(search_word?: string): Promise<string>`
If a string is specified as the argument, it will return the name and calorie (kcal) of the menu that partially matches the menu name currently available at "https://www.akindo-sushiro.co.jp".  
If no argument is specified, it will return the names and calories (kcal) of all the menus currently available at "https://www.akindo-sushiro.co.jp".  
If there is no menu that matches the argument, it will return an error.
```javascript
(async () => {
    const sushiro = new Sushiro();
    console.log(await sushiro.calorie()); // No Argument
    console.log(await sushiro.calorie('ă‚”ăƒŒăƒąăƒł')); // When "ă‚”ăƒŒăƒąăƒł" is specified as an argument
    await sushiro.calorie('Google').catch(() => {
      console.error('There is no item with that name!'); // When the search result does not exist
    });
})();
```

## đŸ” License
[MIT](https://github.com/redpeacock78/sushiro.js/blob/master/LICENSE)