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

lc-simple-js-common

v1.0.8

Published

simple-js-common

Downloads

5

Readme

lc-simple-js-common

项目中,用到的一些公共函数方法集合。

使用方法

例如:

import { assert } from 'chai'
import { L }  from 'lc-simple-js-common'
describe('公共库测试', () => {

  it("1.includeSlash = false value = https://127.0.0.1:8080/ => https://127.0.0.1:8080 value = https://127.0.0.1:8080 => https://127.0.0.1:8080 includeSlash = true value = https://127.0.0.1:8080/ => https://127.0.0.1:8080/ value = https://127.0.0.1:8080 => https://127.0.0.1:8080/", () => {
    assert.equal(L.replacePathLastSlash({ value:'https://127.0.0.1:8080/', includeSlash: true }), 'https://127.0.0.1:8080/')
    assert.equal(L.replacePathLastSlash({ value:'https://127.0.0.1:8080/', includeSlash: false }), 'https://127.0.0.1:8080')
    assert.equal(L.replacePathLastSlash({ value:'https://127.0.0.1:8080', includeSlash: true }), 'https://127.0.0.1:8080/')
    assert.equal(L.removeLashSlash('https://127.0.0.1:8080/'), 'https://127.0.0.1:8080')
    assert.equal(L.removeLashSlash('https://127.0.0.1:8080'), 'https://127.0.0.1:8080')
    assert.equal(L.addLashSlash('https://127.0.0.1:8080'), 'https://127.0.0.1:8080/')
    assert.equal(L.addLashSlash('https://127.0.0.1:8080/'), 'https://127.0.0.1:8080/')
  })
  it("2.includeSlash = false value = /abc/efg => abc/efg value = abc/efg => abc/efg includeSlash = true value = /abc/efg => /abc/efg value = abc/efg => /abc/efg", () => {
    assert.equal(L.replacePathFirstSlash({ value:'/abc/efg', includeSlash: true }), '/abc/efg')
    assert.equal(L.replacePathFirstSlash({ value:'abc/efg', includeSlash: true }), '/abc/efg')
    assert.equal(L.replacePathFirstSlash({ value:'abc/efg', includeSlash: false }), 'abc/efg')
    assert.equal(L.replacePathFirstSlash({ value:'/abc/efg', includeSlash: false }), 'abc/efg')
    assert.equal(L.removeFirstSlash('/abc/efg'), 'abc/efg')
    assert.equal(L.removeFirstSlash('abc/efg'), 'abc/efg')
    assert.equal(L.addFirstSlash('/abc/efg'), '/abc/efg')
    assert.equal(L.addFirstSlash('abc/efg'), '/abc/efg')
  })
  it("3.防抖", () => {
    const obj = {}

    for (let i = 0; i < 10; i++) {
      L.useDebounce(obj,function (){
        console.log(i)
      })
    }
  })
  it("4.随机指定大小的数", () => {
    console.log(L.randomNumberValue(10))
  })

  it("5.获取当前秒的时间戳", () => {
    assert.equal(L.now(), parseInt(new Date() / 1000))
  })

  it("6.获取当天日期", () => {
    console.log(L.getCurrentDay())
  })
  it("7.随机字符数字", () => {
    let data = L.randomCode();
    console.log(data)
    assert.isOk(/^[a-z0-9A-Z]{8}$/.test(data),"默认8位长度的随机值")
    assert.isOk(/^[a-z0-9A-Z]{6}$/.test(L.randomCode(6)),"默认8位长度的随机值")
  })
  it("8.随机数字", () => {
    let data = L.randomNumber();
    console.log(data)
    assert.isOk(/^[0-9]{8}$/.test(data),"默认8位长度的随机值")
    assert.isOk(/^[0-9]{11}$/.test(L.randomNumber(11)),"默认8位长度的随机值")
  })
  it("9.随机带符号的", () => {
    let data = L.randomSymbolCode();
    assert.isOk(data.length === 8,"默认8位长度的随机值")
    console.log(data) // "默认8位长度的随机值"
    console.log(L.randomSymbolCode(16)) // "默认8位长度的随机值"
  })

  it("10.date format", () => {
    console.log(L.dateFormatter(new Date(),'yyyy-MM-dd hh:mm:ss'))
  })
})

更多事例与覆盖请查看单元测试test\test.js