仿互站小程序
This commit is contained in:
4
vant/wxs/array.wxs
Normal file
4
vant/wxs/array.wxs
Normal file
@@ -0,0 +1,4 @@
|
||||
function isArray(array) {
|
||||
return (array && array.constructor === 'Array')
|
||||
};
|
||||
module.exports.isArray = isArray;
|
38
vant/wxs/bem.wxs
Normal file
38
vant/wxs/bem.wxs
Normal file
@@ -0,0 +1,38 @@
|
||||
var array = require('./array.wxs');
|
||||
var object = require('./object.wxs');
|
||||
var PREFIX = 'van-';
|
||||
|
||||
function join(name, mods) {
|
||||
name = PREFIX + name;
|
||||
mods = mods.map(function (mod) {
|
||||
return name + '--' + mod;
|
||||
});
|
||||
mods.unshift(name);
|
||||
return mods.join(' ');
|
||||
}
|
||||
|
||||
function traversing(mods, conf) {
|
||||
if (!conf) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof conf === 'string' || typeof conf === 'number') {
|
||||
mods.push(conf);
|
||||
} else if (array.isArray(conf)) {
|
||||
conf.forEach(function (item) {
|
||||
traversing(mods, item);
|
||||
});
|
||||
} else if (typeof conf === 'object') {
|
||||
object.keys(conf).forEach(function (key) {
|
||||
conf[key] && mods.push(key);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function bem(name, conf) {
|
||||
var mods = [];
|
||||
traversing(mods, conf);
|
||||
return join(name, mods);
|
||||
}
|
||||
|
||||
module.exports.bem = bem;
|
39
vant/wxs/memoize.wxs
Normal file
39
vant/wxs/memoize.wxs
Normal file
@@ -0,0 +1,39 @@
|
||||
function isPrimitive(value) {
|
||||
var type = typeof value;
|
||||
return ((type === 'boolean' || type === 'number' || type === 'string' || type === 'undefined' || value === null))
|
||||
};
|
||||
|
||||
function call(fn, args) {
|
||||
if (args.length === 2) {
|
||||
return (fn(args[(0)], args[(1)]))
|
||||
};
|
||||
if (args.length === 1) {
|
||||
return (fn(args[(0)]))
|
||||
};
|
||||
return (fn())
|
||||
};
|
||||
|
||||
function serializer(args) {
|
||||
if (args.length === 1 && isPrimitive(args[(0)])) {
|
||||
return (args[(0)])
|
||||
};
|
||||
var obj = ({});
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
obj[((nt_5 = ('key' + i), null == nt_5 ? undefined : 'number' === typeof nt_5 ? nt_5 : "" + nt_5))] = args[((nt_6 = (i), null == nt_6 ? undefined : 'number' === typeof nt_6 ? nt_6 : "" + nt_6))]
|
||||
};
|
||||
return (JSON.stringify(obj))
|
||||
};
|
||||
|
||||
function memoize(fn) {
|
||||
arguments.length = arguments.length;
|
||||
var cache = ({});
|
||||
return ((function() {
|
||||
arguments.length = arguments.length;
|
||||
var key = serializer(arguments);
|
||||
if (cache[((nt_7 = (key), null == nt_7 ? undefined : 'number' === typeof nt_7 ? nt_7 : "" + nt_7))] === undefined) {
|
||||
cache[((nt_8 = (key), null == nt_8 ? undefined : 'number' === typeof nt_8 ? nt_8 : "" + nt_8))] = call(fn, arguments)
|
||||
};
|
||||
return (cache[((nt_9 = (key), null == nt_9 ? undefined : 'number' === typeof nt_9 ? nt_9 : "" + nt_9))])
|
||||
}))
|
||||
};
|
||||
module.exports.memoize = memoize;
|
8
vant/wxs/object.wxs
Normal file
8
vant/wxs/object.wxs
Normal file
@@ -0,0 +1,8 @@
|
||||
var REGEXP = getRegExp('{|}|\x22', 'g');
|
||||
|
||||
function keys(obj) {
|
||||
return (JSON.stringify(obj).replace(REGEXP, '').split(',').map((function(item) {
|
||||
return (item.split(':')[(0)])
|
||||
})))
|
||||
};
|
||||
module.exports.keys = keys;
|
11
vant/wxs/utils.wxs
Normal file
11
vant/wxs/utils.wxs
Normal file
@@ -0,0 +1,11 @@
|
||||
var bem = require('./bem.wxs').bem;
|
||||
var memoize = require('./memoize.wxs').memoize;
|
||||
|
||||
function isSrc(url) {
|
||||
return (url.indexOf('http') === 0 || url.indexOf('data:image') === 0 || url.indexOf('//') === 0)
|
||||
};
|
||||
module.exports = ({
|
||||
bem: memoize(bem),
|
||||
isSrc: isSrc,
|
||||
memoize: memoize,
|
||||
});
|
Reference in New Issue
Block a user