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

smweb

v1.0.6

Published

三木web工具集合

Downloads

3

Readme

Install

npm install smweb

Usage

$sm绑定的方法

dynamicLoadCss(url) 动态加载css dynamicLoadJs(url) 动态加载js

dom查询

$sm() // 获取节点,库所有dom方法都是根据$ic获取到dom节点后进行的

// 页面load后执行该方法
$sm(function() {
})
// 直接复制dom
$sm(document)
// 查询所有div
$sm('div')

find (expr = '*') // 根据查询子孙节点 内部使用querySelectorAll

$sm('ul').find('li')

findOne (expr) // 查询子孙中的第一个节点 内部使用querySelector

$sm('ul').findOne('li')

children (expr = undefined) // 查询所有孩子节点(不包括孙子),传递expr表示查找某种类型孩子

$sm('body').children()

parent (expr = undefined) // 获取直接父亲节点(亲生父亲),传递expr表示查找某种类型的直接父亲节点

$sm('li').parent('ul')

parents (expr = undefined) // 获取所有祖先(父亲,爷爷..),传递expr表示查找某种类型的祖先节点

$sm('li').parents()

siblings (expr = '*') // 获取兄弟节点

$sm('li').siblings('.active')

siblingsPrevAll (expr = '*') // 获取向上的兄弟节点

$sm('li:last-child').siblingsPrevAll()

siblingsNextAll (expr = '*') // 获取向下的兄弟节点

$sm('li:last-child').siblingsNextAll()

filter (expr) // 过滤已经查询到的元素

$sm('li').filter('.active')

first() // 取第一个元素SmArray firstElement // 第一个dom元素,不存在返回null last() // 最后一个元素的SmArray lastElement() // 最后一个dom元素,不存在返回null

事件

on (event, listener, useCapture = false) // 绑定事件 off (event, listener, useCapture = false) // 解绑事件 one (event, listener, useCapture= false) // 绑定的事件只执行一次 trigger (event) // 触发事件

addClass(className) removeClass(className) toggleClass(className) replaceClass(removeClassName, addClassName)

$sm('li').toggleClass('active')
$sm('li').removeClass('active')
$sm('li').toggleClass('active')
$sm('li').replaceClass('active', 'active2')

inViewport (overlapOffset = 0) // 查询视口中的dom(视口内的元素)

$sm('li').inViewport(10) // 所有li元素中和视口重合超过10px的元素

inViewportAddClass (visibleClassName, overlapOffset = 0) // 检测元素在视口是否可见,可见是添加类visibleClassName

// 当li元素在视图可见后,添加类 had-visible
$sm('li').inViewportAddClass('had-visible') // li元素滚动到视口内时候 添加had-visible类

css (name, value) //获取或设置dom样式

$sm('li').css() // 获取查询到的节点内的第一个元素的所有样式
$sm('li').css('width') // 获取查询到的节点内的第一个元素的宽度
$sm('li').css('width', '100px') // 设置所有查询到的节点的width为100px

attr (attribute, value) //获取或设置dom属性

$sm('li').attr('width') // 获取查询到的节点内的第一个元素的宽度属性
$sm('li').attr('width', '100px') // 设置查询到的所有li,添加属性width为100px

dataset (name, value) //获取或设置data-*类型的数据

$sm('li').dataset() // 获取查询到的节点内的第一个元素的dataset
$sm('li').css('width') // 获取查询到的节点内的第一个元素的dataset中width的值
$sm('li').css('width', '100px') // 设置所有查询到的节点的dataset中的width为100px(data-width="100px")

libs

获取网络图片尺寸 fetchImageNetSize[内部网络请求库使用fetch,请自己polyfill]

async function test () {
  let size = await $sm.libs.fetchImageNetSize("http://wise-job.oss-cn-zhangjiakou.aliyuncs.com/webjs/images/chunyun/dongcidaci.gif")
  console.log(size) // {width: 658, height: 494}  或 无法获取到抛异常
}