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

alaco

v0.0.4

Published

a js tool for ES6.

Downloads

2

Readme

alaco v0.0.4

The alaco is a helper of tools for Javascript .

Installation

  1. Using npm :
$ npm i --save alaco
  1. Using <script> tag :
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <!-- it's usually `node_modules/dist/alaco.js` or other cdn uri. -->
  <script src="path/to/alaco.js"></script>
</head>
<body>
  <script>
    console.log(alaco)
  </script>
</body>
</html>

Usage

  1. Using es module :
import * as tool from "alaco"
console.log(tool)
  1. Using CommonJS
const alaco = require("./dist/alaco")
console.log(alaco)
  1. Using <script> tag :
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="dist/alaco.js"></script>
</head>
<body>
  <script>
    console.log(alaco)
  </script>
</body>
</html>

alaco API

String

getBytes(str[, encodedType])

  • @description 计算字符串在特定编码下占用的字节数
  • @param {String} str 字符串, 必填
  • @param {String} encodedType 编码类型,默认值 'utf8', 可选
  • @returns {Number} 字符串 str 在 encodedType 编码下占用的字节数
import { getBytes } from "alaco" 
getBytes("aaa啊aaa") // 9
getBytes("aaa啊aaa","utf-16") // 14

Fuctions

curry(fn[, ...args])

  • @description 柯里化函数
  • @param {Function} fn 将要被柯里化的函数, 必填
  • @param {Array} args 将要传递给 fn 的参数列表, 可选
  • @returns {Function} 目标函数, 可接收不定长参数
import { curry } from "alaco"
const sum = (a, b, c) => a + b + c
const curriedSum = curry(sum,1)
const res = curriedSum(1,2) // 4
const res1 = curriedSum(3)(3) // 7

const curriedSum2 = curry(sum)
const res2 = curriedSum2(1)(2)(3) // 6

before(targetFn, beforeFn[, maxTimes])

  • @description 拦截函数, 在目标函数执行之前, 先执行自定义函数
  • @param {Function} targetFn 目标函数, 必填
  • @param {Function} beforeFn 自定义函数, 必填
  • @param {Number} maxTimes beforeFn最多执行的次数, 可选
  • @returns {Function} 目标函数, 可接收不定长参数
import { before } from "alaco"
const logName = name => console.log(name)
const bFn = ()=> console.log('this executed bofore...')
const beforeLogName = before(logName,bFn)
beforeLogName('Lucy')

// beforeLogName2 执行两次后便不再执行 
const beforeLogName2 = before(logName,bFn,2)
beforeLogName2('Lucy')
beforeLogName2('Lili')
beforeLogName2('Tom')

after(targetFn, afterFn[, maxTimes])

  • @description 拦截函数, 在目标函数执行之后, 再执行自定义函数
  • @param {Function} targetFn 目标函数, 必填
  • @param {Function} afterFn 自定义函数, 必填
  • @param {Number} maxTimes afterFn最多执行的次数
  • @returns {Function} 目标函数, 可接收不定长参数
const logName = name => console.log(name)
const aFn = () => console.log('this executed after logName...')
const afterLogName = after(logName, aFn)
afterLogName("Sven")

// afterLogName2 执行两次后便不再执行 
const afterLogName2 = after(logName,aFn,2)
afterLogName2('Lucy')
afterLogName2('Lili')
afterLogName2('Tom')

util

isFunc([data])

  • data 将要检测的数据类型, 可选
  • @returns {Boolean} 是函数类型返回 true,否则返回 false

isNum([data])

  • data 将要检测的数据类型, 可选
  • @returns {Boolean} 是数字类型返回 true,否则返回 false

isDate([data])

  • data 将要检测的数据类型, 可选
  • @returns {Boolean} 是日期类型返回 true,否则返回 false

isReg([data])

  • data 将要检测的数据类型, 可选
  • @returns {Boolean} 是正则类型返回 true,否则返回 false

isArray([data])

  • data 将要检测的数据类型, 可选
  • @returns {Boolean} 是数组类型返回 true,否则返回 false

isNull([data])

  • data 将要检测的数据类型, 可选
  • @returns {Boolean} 是 null 返回 true,否则返回 false

isUnd([data])

  • data 将要检测的数据类型, 可选
  • @returns {Boolean} 是 undefined 返回 true,否则返回 false

isSym([data])

  • data 将要检测的数据类型, 可选
  • @returns {Boolean} 是 Symbol 类型返回 true,否则返回 false

isObj([data])

  • data 将要检测的数据类型, 可选
  • @returns {Boolean} 是 Object 类型返回 true,否则返回 false

isBool([data])

  • data 将要检测的数据类型, 可选
  • @returns {Boolean} 是布尔类型返回 true,否则返回 false

isSet([data])

  • data 将要检测的数据类型, 可选
  • @returns {Boolean} 是 Set 集合类型返回 true,否则返回 false

isMap([data])

  • data 将要检测的数据类型, 可选
  • @returns {Boolean} 是 Map 映射类型返回 true,否则返回 false

isUN([data])

  • data 将要检测的数据类型, 可选
  • @returns {Boolean} 是 null 或者是 undefined 返回 true,否则返回 false