# onetotwo

> A simple CLI to separate html and css.

Latest version **2.0.7** (published 2019-03-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install onetotwo
pnpm add onetotwo
yarn add onetotwo
bun add onetotwo
```

Provides the command `onetotwo`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.7 |
| Published | 2019-03-26 |
| First published | 2018-01-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 62.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | hong |
| Maintainers | swifterjh |
| Keywords | onetotwo |

## Links

- npm: https://www.npmjs.com/package/onetotwo
- Repository: https://github.com/appswifter/onetotwo
- Homepage: https://github.com/appswifter/onetotwo#readme
- Issues: https://github.com/appswifter/onetotwo/issues
- npm.io page: https://npm.io/package/onetotwo

## Dependencies (3)

- [chalk](https://npm.io/package/chalk.md) ^2.4.1
- [chokidar](https://npm.io/package/chokidar.md) ^2.0.4
- [commander](https://npm.io/package/commander.md) ^2.19.0

## Recent versions

- 2.0.7 (latest) — 2019-03-26
- 2.0.6 — 2019-03-26
- 2.0.5 — 2019-01-17
- 2.0.4 — 2019-01-10
- 2.0.3 — 2019-01-10
- 2.0.2 — 2019-01-10
- 2.0.1 — 2019-01-08
- 2.0.0 — 2019-01-08
- 1.2.3 — 2018-08-16
- 1.2.2 — 2018-08-16
- 1.2.1 — 2018-02-27
- 1.2.0 — 2018-02-27
- 1.1.9 — 2018-02-26
- 1.1.8 — 2018-02-26
- 1.1.7 — 2018-02-25
- … 17 more at https://npm.io/package/onetotwo/versions

## README

# Introduction

A simple CLI to separate html and css (working for mini program)

# Installation
```npm
$ npm install -g onetotwo
```

# Usage
```npm
$ onetotwo mini <project-directory>
```
The above command will create `.jhml.wxml` file in each directory containing the `.wxml` file.
Then you can write the inline style html in `.jhml.wxml` file, and CLI will automatically separate the styles into the respective wxml and wxss files.

# Example 

In `test.jhml.wxml` file write:

```html
<!-- test.jhml.wxml -->
<view class='container' style='background: red'>
  <view class='header' style='background: green;'> 
    header
  </view>
  // pseudo-class :after
  <view class='content' style='background: pink; width: 100%;' :after='content: ""; width: 100%; height: r1; background: black;'>
    content
  </view>
  <view class='footer' style='background: yellow;'>
    footer
  </view>
</view>
```

CLI will watch the change of `test.jhml.wxml` and separate html and css into:

```html 
<!-- test.wxml -->
<view class="container">
  <view class="header"> 
    header
  </view>
  <view class="content">
    content
  </view>
  <view class="footer">
    footer
  </view>
</view>
```
and 

```css
<!-- test.wxss -->
.container  { background: red }
.container .header  { background: green; }
.container .content  { background: pink; width: 100%; }
.container .content:after { content: ""; width: 100%; height: 2rpx; background: black; }.container .footer  { background: yellow; }
```

# Config

CLI will create `jhml.config.js` file in `[project-directory]`, you can add regular expressions to handle your style

```js
/** jhml.config.js */
module.exports = {
  styleREG: [
    {
      reg: 'r\\(?(\\d+(?:\\.\\d+)?)\\)?;?', // translate n px => 2n rpx
      exp:  function($0, $1) {
        return $1 * 2 + 'rpx'
      }
    },{
      reg: 'line: \\s(\\d+);',  // over n line auto hidden
      exp: 'overflow: hidden;text-overflow: ellipsis;display: box;display: -webkit-box;line-clamp: $1; -webkit-line-clamp: $1; -webkit-box-orient: vertical;'
    }
  ]
}
```
you can add other handler such as:

```js
/** jhml.config.js */
module.exports = {
  styleREG: [
    {
      reg: 'hc', // horizontal center
      exp:  'position: absolute; left: 50%; transform: translateX(-50%);'
    },
    {
      reg: 'vc', // vertical center
      exp: 'position: absolute; top: 50%; transform: translateY(-50%);'
    }
// ...
  ]
}
```
then you can write:

```html
<!-- test.jhml.wxml -->
<view class='container'>
    <view class='box' style='hc;'></view>
</view>
```
CLI will generate style:

```css
<!-- test.wxss -->
.container .box { position: absolute; left: 50%; transform: translateX(-50%); }
```

---
_Source: https://npm.io/package/onetotwo · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
