npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hzab/classnames-utils

v0.0.2

Published

类名工具

Downloads

75

Readme

@hzab/classnames-utils

类名工具

组件

示例

import ClassnamesUtils, { PREFIX_TYPE, NO_PREFIX_TYPE } from "@hzab/classnames-utils";

import style from "./index.module.less";
import "./index.less";

/* 普通 className 添加前缀写法,值为 PREFIX_TYPE 会自动添加前缀 */
const clsU = new ClassnamesUtils({
  prefix: "test",
});

/* react */
<div className={cnu.objCls({ demo: PREFIX_TYPE, ss: true })}> demo </div>
<div className={cnu.getPrefix("demo")}> demo </div>
<div className={cnu.arrPrefix(["demo", "a", "b"])}> demo </div>
<div className={cnu.objPrefix({ demo: true, a: true, b: false, c: true, d: NO_PREFIX_TYPE })}> demo </div>

/* 渲染结果 */
<div class="test-prefix-demo ss"> demo </div>
<div class="test-prefix-demo"> demo </div>
<div class="test-prefix-demo test-prefix-a test-prefix-b"> demo </div>
<div class="test-prefix-demo test-prefix-a test-prefix-c d"> demo </div>

/* css module 写法 */
const clsUS = new ClassnamesUtils({
  prefix: "test",
  style,
});

/* react */
<div className={cnuS.objCls({ demo: PREFIX_TYPE, ss: true })}> demo </div>
<div className={cnuS.getPrefix("demo")}> demo </div>
<div className={cnuS.arrPrefix(["demo", "a", "b"])}> demo </div>
<div className={cnuS.objPrefix({ demo: true, a: true, b: false, c: true, d: NO_PREFIX_TYPE })}> demo </div>

/* 渲染结果 */
<div class="style-prefix-demo_QrUVQR09 ss"> demo </div>
<div class="style-prefix-demo_QrUVQR09"> demo </div>
<div class="style-prefix-demo_QrUVQR09 style-prefix-a_jz0PvdWe style-prefix-b_EwNpt8Ts"> demo </div>
<div class="style-prefix-demo_QrUVQR09 style-prefix-a_jz0PvdWe style-prefix-c_Fol8id_I d"> demo </div></div>

API

InfoPanel Attributes

| 参数 | 类型 | 必填 | 默认值 | 说明 | | ------ | ------ | ---- | ------ | --------------------- | | prefix | string | 否 | - | 类名统一的前缀 | | styles | Object | 否 | - | css module 目标 style |

objCls

  • 默认不添加前缀
  • 添加前缀的项值配置 PREFIX_TYPE: prefix

| 参数 | 类型 | 必填 | 默认值 | 说明 | | ------------ | ------ | ---- | ------ | -------- | | classNameObj | Object | 是 | - | 类名数据 | | opt | Object | 否 | - | 配置对象 |

objPrefix

  • 默认添加前缀
  • 不添加前缀的项值配置 NO_PREFIX_TYPE: no-prefix

| 参数 | 类型 | 必填 | 默认值 | 说明 | | ------------ | ------ | ---- | ------ | -------- | | classNameObj | Object | 是 | - | 类名数据 | | opt | Object | 否 | - | 配置对象 |

组件开发流程

  • 在 config/webpack.config.js 中按需修改 library 配置的文件名
  • 在 config/webpack.config.js 中按需修改 alias 配置的包名,便于本地调试
  • 在 tsconfig.json 中按需修改 paths 配置的包名,解决 ts 报错问题
  • npm run dev

文件目录

  • example 本地开发测试代码
  • src 组件源码
  • lib 组件打包编译后的代码

命令

  • Mac 执行该命令,设置 pre-commit 为可执行文件

    • npm run mac-chmod
    • chmod +x .husky && chmod +x .husky/pre-commit
  • 生成文档:npm run docs

  • 本地运行:npm run dev

  • 打包编译:npm run build

发布

  • 注意:示例代码生效,但发布之后未生效。确认是否执行了编译!!!

  • 编译组件:npm run build

  • 命令:npm publish --access public

  • 发布目录:

    • lib
    • src

配置

配置文件

  • 本地配置文件:config/config.js

webpack 配置文件

  • config/webpack.config.js