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

lmtools

v1.1.13

Published

+ upload demo ```typescript import React, { useEffect, useRef, useState } from "react"; import { Progress, Row, Col, } from "antd"; import { ProgressProps } from "antd/lib/progress"; import { UploaderCore } from "lmtools";

Downloads

10

Readme

  • upload demo
import React, { useEffect, useRef, useState } from "react";
import { Progress, Row, Col, } from "antd";
import { ProgressProps } from "antd/lib/progress";
import { UploaderCore } from "lmtools";



export function MyUpload() {
  const [precent, setPrecent] = useState(0);
  const [status, setStatus] = useState<ProgressProps["status"]>("normal");
  const [file, setFile] = useState<File>(null);
  const [downloadurl, setDownloadurl] = useState<string>(null);

  const uploader = useRef<UploaderCore>(null);
  const ok_file = useRef<File>(null);


  useEffect(() => {
    if (!file) {
      return;
    }

    new UploaderCore({
      "downloadUrl": "http://xxx/fastdfs/",
      "endpoint": "http://xxx/upload/part/file",
      "onError": (error) => {
        setStatus("exception");
        console.error("Failed because: " + error);
      },
      "onProgress": (bytesSent, bytesTotal) => {
        const percentage = (bytesSent / bytesTotal * 100).toFixed(2);
        setPrecent(+percentage);
        console.log(bytesSent, bytesTotal, percentage + "%")
      },
      "onSuccess": (url, id, upload) => {
        ok_file.current = upload.file as File;
        setDownloadurl(url);
        setPrecent(100);
        setStatus("success");
        console.log("下载地址 %s, 文件id %s", url, id);
      }
    }).read(file, _uploader => {
      uploader.current = _uploader;
    });

    return () => uploader.current = null;
  }, [file]);

  // new Blob([{}], {"t"})

  useEffect(() => {
    if (!uploader.current) return;

    if (status === "active") {
      uploader.current.start();
    } else if (status === "normal") {
      uploader.current.abort();
    }
  }, [status]);


  return (
    <>
      <Row>
        <Col span={12} push={6}>
          <Progress percent={precent} status={status} />
        </Col>
      </Row>
      <Row>
        <Col span={12} push={6}>
          <input type="file" onChange={(ev) => {
            if (file !== ev.target.files[0]) {
              setPrecent(0);
              setStatus("normal");
            }
            setFile(ev.target.files[0]);
          }} />
          <button onClick={() => {
            if (file) setStatus("active");
          }}>start</button>
          <button onClick={() => {
            if (file) setStatus("normal");
          }}>stop</button>
        </Col>
      </Row>
      <Row>
        <Col span={12} push={6}>
          { status === "success" ? <a href={downloadurl}>{`下载: ${ok_file.current.name}`}</a> : null }
        </Col>
      </Row>
    </>
  );
}
  • 菜单绑定渲染懒加载路由(不再维护dynamic_renders_routers)
/**
 * @interface 权限菜单定义
 * @description page 表示唯一路由,label 表示菜单中文名
 */
export
interface subMenus_t {
  label: string;
  page: string;
  icon?: string;
  subMenus?: subMenus_t[];
  menuApi?: any;
}


const menus: subMenus_t[];
// 之后赋值到menus 


// 一个渲染懒路由的示例
class A extends React.Component {


  render() {

    return (
      <>
      {
        dynamic_renders_routers(menus, {
          "page1": { // <Route /> 组件属性 和其它扩展属性
            "path": "page1", // 相对路由,跟随之前的路由
            "toload": [() => import("../page1.jsx"), { other: "附加属性" }]
          },
          "page2": {
            "path": "/page2", // 绝对路由
            "toload": () => import("../page2.jsx")
          },
          "*": {
            "path": "/404",
            "toload": () => import("../404.jsx")
          }
        }, {
          with_switch: {
            // <Switch />组件属性
          },
          with_Redirect: {
            // <Redirect />组件属性
          }
        })
      }
      </>
    )

  }
}

  • 懒加载路由,单组件
import { LazyRoute } from "lmtools";

const Detail = () => import("../../common/work_order_detail/index.jsx");

function() {

  return (
    <Switch>
      <Route exact path={match.url} render={rest => <Ywgdgl {...rest} menu={menu} snapshot={ref.current} />} />
      <LazyRoute path={match.url + "/查看详情"} renderFactory="component" toload={[Detail, { aaa: 1022 }]} />
      <LazyRoute path={match.url + "/确认处理情况"} renderFactory="component" toload={[Detail, { aaa: 1022 }]} />
      <Redirect to={match.url} />
    </Switch>
  )
  
}
  • 错误捕捉
import { ErrorCatch } from 'lmtools';
import { notification } from 'antd';

function err_handler(error: Error) {
  notification.error({
    message: error.name,
    description: (
      <>
        <code style={{ overflow: 'auto' }}><pre>{`${error.message}`}</pre></code>
      </>
    ),
    duration: null,
  });
}

// 渲染异常
function App() {
  let a = 10;
  return <div>{a.b}</div>;
}

export default ErrorCatch(err_handler)(App);
  • 工具类函数
    • blob转url: BlobToDataURL
    • url转img: DataUrlToImage
    • img转url: ImageToDataURL
    • base64转blob: Base64ToBlob
    • img转blob: ImageToBlob