style-factory
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

style-factory

npm version License: MIT issues downloads Code Coverage Node.js Package

将 style 文本内容转化为 function 函数,可附加 prefix、换算 rpx、:host 选择符的操作。

作为小程序样式转换使用

Usage

import styleFactory from 'style-factory';

const code = styleFactory(css);

Input

/* 注释 */
.foo {
  color: red;
  height: 100rpx;
}

Output

function styleFactory(options) {
  const prefix = options.prefix || '';
  const rpx = options.rpx;
  const host = options.host || 'host-placeholder';
  return (
    '/* 注释 */\n.' +
    prefix +
    'foo{\n    color: red;\n    height: ' +
    rpx(100) +
    'px' +
    ';\n}'
  );
}

调用该方法

styleFactory({
  prefix: 'foo--',
  rpx: function (size) {
    return size * 0.5;
  },
});

输出以下内容

/* 注释 */
.foo--foo {
  color: red;
  height: 50px;
}

Readme

Keywords

none

Package Sidebar

Install

npm i style-factory

Weekly Downloads

18

Version

2.1.0

License

MIT

Unpacked Size

36.5 kB

Total Files

21

Last publish

Collaborators

  • noyobo