sendohjs

0.0.2 • Public • Published

sendohjs

这是最近造的一个小轮子,一个用来操作 DOM 的库,API 基本上和 zepto 兼容的,先看一下怎么用的:

<html>
<head>
    <meta charset="utf-8">
    <title>playground</title>
</head>
<body>
    <div class="xxx">dedara</div>

    <div class="lorem">some</div>
    <div class="lorem">another</div>
    <a href="http://baidu.com", alt="baidu"></a>
    <a href="http://google.com", alt="google"></a>
    <script src="demo.dist.js"></script>
</body>
</html>
'use strict'

let $ = require('sendohjs')

$(function () {
     let $div = $('.xxx')
    $div.removeClass('xxx').addClass('yyy zzz').hasClass('zzz') // true

    let $link = $('a')
    console.log($link.attr('alt')) // 'baidu'
    $link.attr({ alt: '神', class: 'search', }).attr('href', function (idx, oldVal) {
        return oldVal + idx.toString()
    }).attr('target', '_blank')

    console.log($link.attr('alt'), $link.attr('class'), $link.attr('href'), $link.attr('target'))
    $link.removeAttr('href')
    console.log($link.attr('href')) // null
})

一些要点:

  • 目前构造函数还不支持从 html 字符串创建,比如 $('<p>hi</p>') 这种,其它的几种参数类型都支持
  • 单元测试是用 mocha 写的,但是为了兼容 zepto 基本上是从 zepto 的 test 目录下复制过来修改了一下。现在是半自动化的测试,打算过段时间用上 karma
  • 目前只支持 commonjs 格式,没有支持其它格式的打算
  • 代码还是 too young too simple, 还有很多需要改进的地方
  • 具体的用法见测试和代码

Readme

Keywords

Package Sidebar

Install

npm i sendohjs

Weekly Downloads

0

Version

0.0.2

License

MIT

Last publish

Collaborators

  • jiang-di