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

ddv-util

v0.0.14

Published

ddv-util

Downloads

12

Readme

ddv-util

这是一个工具类库,可以作为 vue 过滤器使用


安装


npm

$ npm install ddv-util - S

使用


import util from 'ddv-util';

你也可以把 ddv-util 映射到全局变量当中

//把util映射到全局变量d中
util.globalInit('d', null, true);

API

ddv-util 默认拥有的api:

  • isFunction
  • 用途:判断是否是 function 类型
var p = function(){};

util.isFunction(p);
==>true
  • isArray
  • 用途:判断是否是一个数组
var p = [];

util.isArray(p);
==>true
  • isGlobal
  • 用途:判断是否是全局变量
window.p = {};
util.isGlobal(p);
==>true
  • isNumber
  • 用途:判断是否是 number 类型
var p = 1;
util.isNumber(p);
==>true
  • type
  • 用途:判断是类型
var p = {};
util.type(p,'object');
==>true
  • argsToArray
  • 用途:把伪数组强转数组
var p = {0:'a',1:'b',length:2};;
util.argsToArray(p);
==>['a','b']

ddv-util 内置 time 时间处理模块,详细使用方式请参PHP对应的方法:time, date, gmdate,strtotime

//引入'ddv-util'
import util from 'ddv-util';
//引入时间处理api模块
import utilTime from 'ddv-util/time';
//安装到'ddv-util'
util.extendInit(utilTime);

//获取当前开始
util.now();

//获取php的时间戳
util.time();

//时间戳格式,格式化后是格林时间
util.gmdate(format,timestamp);
util.date(format,timestamp);
util.strtotime(text, now);

注册过滤器


ddv-util 支持注册过滤器,可使用扩展或安装的方式

扩展

extend

//helper.js
export default{
    add(val){
        return val+1;
    }
}

//use.js
import util from 'ddv-util'
import helper from './helper.js'
//在util下扩展helper
util.extend({
    helper
})

util.helper.add(1);
=>2

安装

extendInit

//helper.js
module.exports = function(util){
    util.extendDeep({
        add(val){
            return val+1;
        }
    })
}

//use.js
import util from 'ddv-util'
import helper from './helper.js'
//在util下安装helper
util.extendInit(helper);

util.add(1);
=>2

关于使用vue在 mustache 使用 ddv-util 过滤器

在mustache下使用过滤器语法基本和 Vue-filter 相同


<template>
    <div>
    <!--1参数代表time以第二个参数传进date里面,'Y-d-m'则为第一个。默认不填是第一个,如此类推-->
    {{time | util('date,1','Y-d-m') }}
    </div>
</template>
import Vue from 'vue';
import util from 'ddv-util';
import utilTime from 'ddv-util/time';
util.extendInit(utilTime);

Vue.filter('util',util);

export default {
    data(){
        return{
            time : '1484379264'
        }
    }
}