npm package: 1min
Description: A command-line application for 30 seconds of code snippets
Author: Oskar Grunning
Latest version: 0.0.4

# 30s 命令应用

_A command-line application for [`30 seconds of code`](https://github.com/30-seconds/30-seconds-of-code/) snippets（一个基于  [`30 seconds of code`](https://github.com/30-seconds/30-seconds-of-code/) 的命令应用）._

[![NPM](https://img.shields.io/npm/v/30s.svg)](https://www.npmjs.com/package/30s) [![build status](https://travis-ci.org/sQVe/30s.svg?branch=master)](https://travis-ci.org/sQVe/30s) [![coveralls](https://coveralls.io/repos/github/sQVe/30s/badge.svg)](https://coveralls.io/github/sQVe/30s) [![dependabot status](https://api.dependabot.com/badges/status?host=github&repo=sQVe/30s)](https://dependabot.com) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) [![license](https://img.shields.io/badge/license-CC0--1.0-blue.svg)](https://github.com/sQVe/30s/blob/develop/LICENSE)

![示例](/.github/demo.gif?raw=true)

<hr>

## Features（功能点）

- Written in JavaScript (ES6)（使用 ES6 编写）
- View, view by tag and search snippets（查看，按标签查看并搜索代码片段）
- Show what you find necessary by picking a layout（通过选择布局显示您认为必要的内容）
- Colorful output or JSON（高亮色彩输出或者输出 JSON 格式）
- Copy all code to clipboard（拷贝所有的代码到剪切板）
- Automatically updates with new snippet changes（自动更新新的代码片段）
- Works on Linux, Mac and Windows（适用于 Linux，Mac 和 Window 系统）

## Installation（安装）

Pick one of the following options to install the command-line application:（选择以下选项中的一种来安装命令行应用）

#### Option 1: NPM / Yarn（选项 1：NPM / Yarn）

```bash
npm install -g 30s
```

```bash
yarn add -g 30s
```

#### Option 2: Source（选项 2：源码）

```bash
$ git clone https://github.com/effiyichengliang/30s-command-line.git
$ cd 30s-command-line/
$ npm install
$ node lib/index.js <command> <query>
```

## Usage（使用）

#### Commands（命令）

| Short version | Long version | Description（描述）                   |
| :-----------: | :----------: | ------------------------------------ |
|      `r`      |   `random`   | View random snippet（随机产看代码片段）                  |
|      `s`      |   `search`   | Fuzzy search (RegExp) snippets by id（通过 ID 来模糊搜索（正则表达式）代码片段） |
|      `t`      |    `tag`     | View snippets by tag（通过标签来查看代码片段）                 |
|      `v`      |    `view`    | View snippet with id（查看带有 ID 的代码片段）                 |

#### Options（选项）

| Short version | Long version | Description（描述）                                                      |
| :-----------: | :----------: | ---------------------------------------------------------------- |
|     `-c`      |    `--cp`    | Copy snippet code to clipboard（拷贝代码片段到剪切板）                                   |
|     `-j`      |   `--json`   | Print output in JSON format（以 JSON 格式打印输出）                                      |
|     `-l`      |  `--layout`  | Print output with specified [layout](#layout) (default: "itced") |
|     `-h`      |   `--help`   | Output usage information                                         |

##### Layout

| Layout key | Description                |
| :--------: | -------------------------- |
|    `i`     | Output snippet id          |
|    `t`     | Output snippet tags        |
|    `c`     | Output snippet code        |
|    `e`     | Output snippet examples    |
|    `d`     | Output snippet description |

#### Examples

| Example                      | Description                                                                  |
| :--------------------------- | ---------------------------------------------------------------------------- |
| `30s v head`                 | View snippet with id `head`                                                  |
| `30s view head`              | View snippet with id `head`                                                  |
| `30s r`                      | View random snippet                                                          |
| `30s random`                 | View random snippet                                                          |
| `30s t array`                | View snippets by tag `array`                                                 |
| `30s tag array`              | View snippets by tag `array`                                                 |
| `30s s all`                  | Find all snippets with an id that contains `all`                             |
| `30s search all`             | Find all snippets with an id that contains `all`                             |
| `30s view merge --cp`        | View snippet with id `merge` and copy its code                               |
| `30s view merge --json`      | View snippet with id `merge` and output as JSON                              |
| `30s search all --layout ce` | Find all snippets with an id that contains `all` and output code and example |

## Contributing（贡献）

#### Bug reports & feature requests（Bug 报告 & 功能需求）

Please use the [issue tracker](https://github.com/sQVe/30s/issues) to report bugs or file feature requests（请使用[issue tracker](https://github.com/sQVe/30s/issues)来报告 Bug 和提交功能需求）.

#### Developing（开发）

Pull requests are more than welcome. Do the following to start helping out（请使用拉请求的方式，并遵循以下规则来提供您的帮助）:

1. [Fork](https://help.github.com/articles/fork-a-repo/) this repository to your own GitHub account and then [clone](https://help.github.com/articles/cloning-a-repository/) it to your local device（[Fork](https://help.github.com/articles/fork-a-repo/) 这个项目到你自己的 GitHub 账号，然后 [clone](https://help.github.com/articles/cloning-a-repository/) 它到你的本地机器上）.
2. Run `npm install` in the created directory to install all necessary dependencies（在 clone 下来的项目目录下运行 `npm install` 来安装必须的依赖包）.

Optional steps （可选步骤）:

3. Uninstall `30s` if it's already installed（如果你已经装过 `30`，请先卸载）: `npm uninstall -g 30s`
4. Link it to the global module directory: `npm link`（将本项目软链接到你的全局模块目录）

#### Style guide & conventions（风格指南 & 协议约定）

Try to follow [functional programming](https://en.wikipedia.org/wiki/Functional_programming) best practices. Use pure functions and [`Ramda`](https://github.com/ramda/ramda) when possible（尽量遵循函数式编程来练习。尽可能的使用纯函数和 Ramda 表达式）.

Write commits following（遵循日志提交书写格式）: [Angular Commit Message Conventions](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines). This enables us to automatically release new versions together with（保证我们的自动版本更新遵循） [`semantic-release`](https://github.com/semantic-release/semantic-release) on `fix` and `feat` commit types.

[`prettier`](https://github.com/prettier/prettier) and [`eslint-config-sqve`](https://github.com/sQVe/eslint-config-sqve) (a config based on [`standardjs`](https://standardjs.com)) enforces our styling and formatting. It runs automatically on `pre-commit` and is also checked for issues on **Travis CI**（强制使用 [`standardjs`](https://standardjs.com)) 配置 [`prettier`](https://github.com/prettier/prettier) 和 [`eslint-config-sqve`](https://github.com/sQVe/eslint-config-sqve)）来保持我们的风格和格式化。我们将在你日志提交时运行自动化检测.

#### Roadmap（路标）

See the [development board](https://github.com/sQVe/30s/projects/1) for a detailed development roadmap. Below are a short outline of important improvements:

- Autocomplete with `omelette`
- Replace `commander` with basic `yargs` and own logic

## Thanks

A big thank you to the core team and all the contributers at [`30-seconds-of-code`](https://github.com/Chalarangelo/30-seconds-of-code) for creating an awesome curated collection of snippets.

## License

```
Creative Commons License
CC0 1.0 Universal
```