@scaff/kit
Advanced tools
+24
| // No Use Empty in Kit | ||
| function empty(target) { | ||
| return [undefined, null].includes(target); | ||
| } | ||
| /** | ||
| * @param target { function | any } | ||
| * @param params { any } | ||
| * @param defers { any } | ||
| * ========== ========== ========== | ||
| */ | ||
| export default (target, params, defers) => { | ||
| // Check Function Type | ||
| const is = typeof target === 'function'; | ||
| // Tolerant Defers | ||
| defers = empty(defers) ? params : defers; | ||
| // Get Result | ||
| const result = is ? target(params) : empty(target) ? defers : target; | ||
| // Return Result or Defers | ||
| return empty(result) ? defers : result; | ||
| }; |
+5
-1
| export default target => { | ||
| if ([undefined, 'undefined'].includes(target)) { | ||
| if (target === 'undefined' || typeof target === 'undefined') { | ||
| return true; | ||
| } | ||
| if (typeof target === 'function') { | ||
| return false; | ||
| } | ||
| for (let i in target) { | ||
@@ -7,0 +11,0 @@ return false; |
+72
-9
@@ -0,16 +1,77 @@ | ||
| // Use Empty | ||
| import empty from './empty'; | ||
| // Use Hand | ||
| import hand from './hand'; | ||
| /** | ||
| * @param source { function | object } - for Instant | ||
| * @param handler { function } - for App Use | ||
| * ========== ========== ========== | ||
| */ | ||
| export default (source = {}, handler = () => {}) => { | ||
| // Set Express for Save | ||
| let express = {}; | ||
| // Preset Express | ||
| const express = { | ||
| // Configure | ||
| configure: null, | ||
| // Instanter | ||
| instanter: null, | ||
| // Extension | ||
| extension: null, | ||
| }; | ||
| // Preset Functional | ||
| const factory = { | ||
| config(value) { | ||
| express.configure = value; | ||
| }, | ||
| extension(value) { | ||
| express.extension = value; | ||
| }, | ||
| }; | ||
| // Set Proxy | ||
| const proxy = new Proxy( | ||
| { | ||
| config() { | ||
| /** | ||
| * API Config Merge in Instantiation | ||
| * ========== ========== ========== | ||
| */ | ||
| }, | ||
| extension() { | ||
| /** | ||
| * API Extension after Instantiation | ||
| * ========== ========== ========== | ||
| */ | ||
| }, | ||
| }, | ||
| { | ||
| get(target, key, receiver) { | ||
| return target[key]; | ||
| }, | ||
| set(target, key, value, receiver) { | ||
| // Temporary Value into Factory as Key | ||
| factory[key](value); | ||
| // No Prejudice | ||
| return receiver; | ||
| }, | ||
| }, | ||
| ); | ||
| // Export a Standardization Vue Extension APIs | ||
| return { | ||
| // Install | ||
| // Use Proxy | ||
| proxy, | ||
| // Install for Use | ||
| install(app, options = {}) { | ||
| return handler(Object.assign({}, source, express), express); | ||
| }, | ||
| // Step 1. Trigger Source | ||
| express.instanter = hand(source, express.configure); | ||
| // Extension | ||
| extension(callback = () => {}) { | ||
| // Merge Result | ||
| Object.assign(express, callback(source) || {}); | ||
| // Step 2. Trigger Handler | ||
| return handler(hand(express.extension, express.instanter)); | ||
| }, | ||
@@ -24,1 +85,3 @@ | ||
| }; | ||
| // 如果这里 source 传入的是 function,尝试用 function.get 监听,触发,稍微设计下 |
+3
-1
@@ -7,2 +7,4 @@ import support from './support'; | ||
| import hand from './hand'; | ||
| import def from './def'; | ||
@@ -42,2 +44,2 @@ | ||
| export { support, noop, console, def, catcher, gatherer, is, empty, foreach, merge, suffix, translate, matcher, bless, http, camel2cross, cross2camel, replace, gemini, extensor }; | ||
| export { support, noop, console, hand, def, catcher, gatherer, is, empty, foreach, merge, suffix, translate, matcher, bless, http, camel2cross, cross2camel, replace, gemini, extensor }; |
+2
-2
| { | ||
| "name": "@scaff/kit", | ||
| "version": "3.3.4", | ||
| "version": "3.4.0", | ||
| "main": "dist/index.js", | ||
@@ -11,3 +11,3 @@ "author": "joenix", | ||
| }, | ||
| "gitHead": "f9eb416f82f137ca1d001aade30daa752ec81a4e" | ||
| "gitHead": "b115ad6fc0f2c2d184e5d86da01bd694c8cabeff" | ||
| } |
+2
-0
| # @scaff/kit | ||
| > a package for kit use in vue | ||
| 2020.4 |
16151
13.57%26
4%608
14.72%6
50%