@scaff/kit
Advanced tools
| // Use Is | ||
| import is from './is'; | ||
| // Use Replace | ||
| import replace from './replace'; | ||
| // Bless Host on API | ||
| export default registry => { | ||
| // Check Constructor of API | ||
| if (is(registry.api, Function)) { | ||
| // Self Execution API | ||
| registry.api = registry.api(registry.host || {}, replace); | ||
| } | ||
| // Export | ||
| return registry; | ||
| }; |
| // Translate Camel to Cross | ||
| export default template => { | ||
| // Return | ||
| return template.replace(/[A-Z]/g, $0 => `-${$0.toLowerCase()}`).replace(/^-/, ''); | ||
| }; |
| // Use Support | ||
| import support from './support'; | ||
| // Use Def | ||
| import def from './def'; | ||
| /** | ||
| * Catcher Modules from Context | ||
| * ========== ========== ========== | ||
| */ | ||
| export default (context, callback) => { | ||
| // Set Modules | ||
| const modules = {}; | ||
| // CLI | ||
| if (support) { | ||
| // Loop Context Keys | ||
| context.keys().forEach(key => (context[key] = context(key))); | ||
| } | ||
| // Loop Context | ||
| for (const path in context) { | ||
| // Get Depend | ||
| const depend = def(context[path]); | ||
| // Get Result | ||
| const result = callback(depend, path); | ||
| // Get Key-Value | ||
| const { name, pkg } = result || {}; | ||
| // Check Name of Result | ||
| if (name) { | ||
| // Set Package into Modules | ||
| modules[name] = pkg; | ||
| } | ||
| } | ||
| // Return | ||
| return modules; | ||
| }; |
| // Use Foreach | ||
| import foreach from './foreach'; | ||
| /** | ||
| * Console Extension - Message | ||
| * ========== ========== ========== | ||
| */ | ||
| export default (options = {}) => { | ||
| // Preset | ||
| const preset = Object.assign( | ||
| { | ||
| log: { | ||
| label: '调试', | ||
| color: 'green', | ||
| }, | ||
| warn: { | ||
| label: '警告', | ||
| color: 'orange', | ||
| }, | ||
| error: { | ||
| label: '错误', | ||
| color: 'red', | ||
| }, | ||
| }, | ||
| options, | ||
| ); | ||
| // Set Styles | ||
| const css = (color = 'green') => `background: ${color}; color: white; padding: 2px 4px; border-radius: 3px; font-weight: bold;`; | ||
| // Set Binding | ||
| const bind = (name, label, color) => ({ [name]: console.log.bind(console, `%c${label}`, css(color)) }); | ||
| // Set Target | ||
| const target = {}; | ||
| // Preset Loop | ||
| foreach(preset, ({ label, color }, name) => Object.assign(target, bind(name, label, color))); | ||
| // Export | ||
| return target; | ||
| }; |
| // Translate Cross to Camel | ||
| export default template => { | ||
| // Return | ||
| return template.replace(/\-([a-z])/g, ($0, $1) => $1.toUpperCase()); | ||
| }; |
| // Export default with Dependency if Has | ||
| export default dependency => dependency.default || dependency; |
| export default target => { | ||
| if ([undefined, 'undefined'].includes(target)) { | ||
| return true; | ||
| } | ||
| for (let i in target) { | ||
| return false; | ||
| } | ||
| return true; | ||
| }; |
| export default (source = {}, handler = () => {}) => { | ||
| // Set Express for Save | ||
| let express = {}; | ||
| // Export a Standardization Vue Extension APIs | ||
| return { | ||
| // Install | ||
| install(app, options = {}) { | ||
| return handler(Object.assign({}, source, express), express); | ||
| }, | ||
| // Extension | ||
| extension(callback = () => {}) { | ||
| // Merge Result | ||
| Object.assign(express, callback(source) || {}); | ||
| }, | ||
| // Get for Use | ||
| get() { | ||
| return source; | ||
| }, | ||
| }; | ||
| }; |
| // Use foreach.js - https://www.npmjs.com/package/foreach.js | ||
| import foreach from 'foreach.js'; | ||
| // Use Gatherer | ||
| import gatherer from './gatherer'; | ||
| /** | ||
| * Filter Empty | ||
| * ========== ========== ========== | ||
| */ | ||
| export default (source, callback) => { | ||
| // Keys & Resolve in Source | ||
| if (source.keys && source.resolve) { | ||
| return gatherer(source, callback); | ||
| } | ||
| // Set Result as Json | ||
| const result = {}; | ||
| // Loop | ||
| foreach(source, (value, key) => { | ||
| // Get Item as Running | ||
| const item = callback(value, key); | ||
| // Insert Item into Result | ||
| if (item) { | ||
| // Change Key of Result | ||
| if (item.key) { | ||
| // Insert Value into Key in Result | ||
| result[item.key] = item.value; | ||
| // Next | ||
| return; | ||
| } | ||
| result[key] = item; | ||
| } | ||
| }); | ||
| // Usage | ||
| return result; | ||
| }; |
| // Use Matcher | ||
| import matcher from './matcher'; | ||
| // Use Def | ||
| import def from './def'; | ||
| // Export | ||
| export default (source, callback) => { | ||
| // Set Result | ||
| const result = {}; | ||
| // Loop Source | ||
| source.keys().forEach(key => { | ||
| // Set Item as Running | ||
| const item = callback(source(key), key); | ||
| // Insert Item into Result | ||
| if (item) { | ||
| // Change Key of Result | ||
| if (item.key) { | ||
| // Insert Value into Key in Result | ||
| result[item.key] = item.value; | ||
| // Next | ||
| return; | ||
| } | ||
| result[key] = item; | ||
| } | ||
| }); | ||
| // Export | ||
| return result; | ||
| }; |
| // Usse Kit | ||
| import http from './http'; | ||
| /** | ||
| * Gemini as Hard Code | ||
| * ========== ========== ========== | ||
| */ | ||
| export default (app, { registry, resource }) => { | ||
| // Set Http and Api as $ | ||
| const $api = registry.api; | ||
| const $http = http; | ||
| // Set Global | ||
| app.config.globalProperties.$api = $api; | ||
| app.config.globalProperties.$http = $http; | ||
| // Bind Http and Api on Util | ||
| if (resource.util) { | ||
| resource.util = { ...resource.util, $http, $api }; | ||
| } | ||
| // Bind Http on Resource for Extension | ||
| resource.$http = $http; | ||
| // Export for Useage | ||
| return { resource, registry }; | ||
| }; |
| // Use Axios | ||
| import Axios from 'axios'; | ||
| // Global Ext | ||
| const ext = { | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| data: {}, | ||
| request: (data, headers) => ({}), | ||
| response: data => data, | ||
| }; | ||
| // Classic | ||
| class HTTP { | ||
| constructor() { | ||
| // Method Mode | ||
| this.methods = ['get', 'post', 'put', 'delete', 'connect', 'head', 'options', 'trace']; | ||
| // Export APIs | ||
| return this.init(); | ||
| } | ||
| init() { | ||
| // Set Scope for Interceptor | ||
| const scope = (api, option) => { | ||
| // Set Modules | ||
| const modules = {}; | ||
| // Traversal | ||
| this.methods.forEach(method => { | ||
| // Set Func by Method | ||
| modules[method] = (param, conf) => this.send(option, method, api, param, conf); | ||
| }); | ||
| // Export Modules | ||
| return modules; | ||
| }; | ||
| return (scope.interceptor = this.interceptor), scope; | ||
| } | ||
| interceptor(custom = {}) { | ||
| // Get Headers and Data | ||
| const { headers, data } = custom.request(ext.data, ext.headers); | ||
| // Tolerant Headers and Data | ||
| ext.headers = headers || ext.headers; | ||
| ext.data = data || ext.data; | ||
| // Bind Request & Response on Ext | ||
| ext.request = custom.request || ext.request; | ||
| ext.response = custom.response || ext.response; | ||
| } | ||
| send(option = {}, method = 'get', api = '', param = {}, conf = {}) { | ||
| // Request Interceptor First | ||
| this.interceptor(ext); | ||
| // Use Axios | ||
| return Axios({ | ||
| ...ext, | ||
| method, | ||
| headers: { | ||
| ...ext.headers, | ||
| ...(conf.headers || {}), | ||
| }, | ||
| data: { | ||
| ...ext.data, | ||
| ...param, | ||
| }, | ||
| url: api, | ||
| ...option, | ||
| }) | ||
| .then(data => ext.response(data, true)) | ||
| .catch(error => ext.response(error, false)); | ||
| /** | ||
| * Use Promise for ES7 -- uni | ||
| * ========== ========== ========== | ||
| */ | ||
| return new Promise((resolve, reject) => | ||
| // Send | ||
| uni.request({ | ||
| // Conf | ||
| ...ext, | ||
| // Method | ||
| method, | ||
| // Headers | ||
| header: { | ||
| ...ext.headers, | ||
| ...(conf.headers || {}), | ||
| }, | ||
| // Param | ||
| data: { | ||
| ...ext.data, | ||
| ...param, | ||
| }, | ||
| // Request Address | ||
| url: api, | ||
| // Call Success | ||
| success: ({ data }) => resolve(ext.response(data)), | ||
| // Call Error | ||
| fail: reject, | ||
| // Extension of Option for Highest | ||
| ...option, | ||
| }), | ||
| ); | ||
| } | ||
| response() {} | ||
| } | ||
| export default new HTTP(); |
+127
| /** | ||
| * https://developer.mozilla.org/zh-CN/docs/Web/API/Fetch_API | ||
| * ========== ========== ========== | ||
| */ | ||
| // Global Ext | ||
| const ext = { | ||
| data: {}, // must match 'Content-Type' header | ||
| cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached | ||
| credentials: 'same-origin', // include, same-origin, *omit | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| method: 'POST', // *GET, POST, PUT, DELETE, etc. | ||
| mode: 'cors', // no-cors, cors, *same-origin | ||
| redirect: 'follow', // manual, *follow, error | ||
| referrer: 'no-referrer', // *client, no-referrer | ||
| request: (data, headers) => ({}), | ||
| response: data => data, | ||
| }; | ||
| // Classic | ||
| class HTTP { | ||
| constructor() { | ||
| // Method Mode | ||
| this.methods = ['get', 'post', 'put', 'delete', 'connect', 'head', 'options', 'trace']; | ||
| // Export APIs | ||
| return this.init(); | ||
| } | ||
| init() { | ||
| // Set Scope for Interceptor | ||
| const scope = (api, option) => { | ||
| // Set Modules | ||
| const modules = {}; | ||
| // Traversal | ||
| this.methods.forEach(method => { | ||
| // Set Func by Method | ||
| modules[method] = (param, conf) => this.send(option, method, api, param, conf); | ||
| }); | ||
| // Export Modules | ||
| return modules; | ||
| }; | ||
| return (scope.interceptor = this.interceptor), scope; | ||
| } | ||
| interceptor(custom = {}) { | ||
| // Get Headers and Data | ||
| const { headers, data } = custom.request(ext.data, ext.headers); | ||
| // Tolerant Headers and Data | ||
| ext.headers = headers || ext.headers; | ||
| ext.data = data || ext.data; | ||
| // Bind Request & Response on Ext | ||
| ext.request = custom.request || ext.request; | ||
| ext.response = custom.response || ext.response; | ||
| } | ||
| format(api = '', data = {}) { | ||
| // Get Search | ||
| let { search = '' } = new URL(api) || {}; | ||
| // Loop Data | ||
| for (let key in data) { | ||
| search += `${search ? '&' : '?'}${key}=${data[key]}`; | ||
| } | ||
| // Return | ||
| return `${api}${search}`; | ||
| } | ||
| clean(plex = {}) { | ||
| delete plex.data; | ||
| return plex; | ||
| } | ||
| send(option = {}, method = 'get', api = '', param = {}, conf = {}) { | ||
| // Request Interceptor First | ||
| this.interceptor(ext); | ||
| // Clean Properties | ||
| const plex = this.clean({ | ||
| ...ext, | ||
| method, | ||
| headers: { | ||
| ...ext.headers, | ||
| ...(conf.headers || {}), | ||
| }, | ||
| body: { | ||
| ...ext.data, | ||
| ...param, | ||
| }, | ||
| mode: conf.mode || ext.mode, | ||
| cache: conf.cache || ext.cache, | ||
| credentials: conf.credentials || ext.credentials, | ||
| ...option, | ||
| }); | ||
| // Format for Get Method | ||
| if (method === 'get') { | ||
| // Reset API | ||
| api = this.format(api, plex.body); | ||
| // Remove Body | ||
| delete plex.body; | ||
| } | ||
| // Use Fetch | ||
| return fetch(api, plex) | ||
| .then(data => ext.response(data, true)) | ||
| .catch(error => ext.response(error, false)); | ||
| } | ||
| response() {} | ||
| } | ||
| export default new HTTP(); |
| import support from './support'; | ||
| import noop from './noop'; | ||
| import console from './console'; | ||
| import def from './def'; | ||
| import catcher from './catcher'; | ||
| import gatherer from './gatherer'; | ||
| import is from './is'; | ||
| import empty from './empty'; | ||
| import foreach from './foreach'; | ||
| import merge from './merge'; | ||
| import suffix from './suffix'; | ||
| import translate from './translate'; | ||
| import matcher from './matcher'; | ||
| import bless from './bless'; | ||
| import http from './http'; | ||
| import camel2cross from './camel2cross'; | ||
| import cross2camel from './cross2camel'; | ||
| import replace from './replace'; | ||
| import gemini from './gemini'; | ||
| import extensor from './extensor'; | ||
| export { support, noop, console, def, catcher, gatherer, is, empty, foreach, merge, suffix, translate, matcher, bless, http, camel2cross, cross2camel, replace, gemini, extensor }; |
+12
| /** | ||
| * @property target { Any } | ||
| * @property type { Object, Array, Number, String, Function, Promise, Symbol } | ||
| * ========== ========== ========== | ||
| */ | ||
| export default (target, type) => { | ||
| if ([undefined, 'undefined'].includes(target)) { | ||
| return false; | ||
| } | ||
| return target.constructor === type; | ||
| }; |
| // Match Name of Path with Rule | ||
| export default (path, exp) => { | ||
| if (exp) { | ||
| // Get Raggae | ||
| const raggae = path.match(exp)[2]; | ||
| // Only has Raggae | ||
| if (raggae) { | ||
| return raggae; | ||
| } | ||
| } | ||
| // Default Rule | ||
| return path.match(/([\w\-]+)(\.\S+)?\.\w+$/)[1]; | ||
| }; |
| function merge(origin, target) { | ||
| for (let key in target) { | ||
| origin[key] = origin[key] && origin[key].constructor === Object ? merge(origin[key], target[key]) : (origin[key] = target[key]); | ||
| } | ||
| return origin; | ||
| } | ||
| export default merge; |
| export default new Function(); |
| export default (uri, exp = new RegExp(/\{\S+\}/g)) => { | ||
| if (exp.test(uri)) { | ||
| uri.replace(exp, word => {}); | ||
| } | ||
| return exp.test(uri) ? (j, o, e, n, i, x, a = 0, cache = [j, o, e, n, i, x]) => uri.replace(exp, word => cache[a++]) : uri; | ||
| }; |
| /** | ||
| * Matcher as Suffix | ||
| * ========== ========== ========== | ||
| */ | ||
| export default template => { | ||
| // Get Matcher of Template | ||
| const matcher = template.match(/\.(\w+)$/); | ||
| // Get Suffix as Key | ||
| return matcher ? matcher[1] : false; | ||
| }; |
| // Use Empty | ||
| import empty from './empty'; | ||
| // Support CLI | ||
| export default empty(import.meta); |
| /** | ||
| * Translate Template to Regexp | ||
| * "\": %5C | ||
| * "/": %2F | ||
| * ========== ========== ========== | ||
| */ | ||
| export default template => { | ||
| // Change . to \. | ||
| template = template.replace(/\./g, '%5C.'); | ||
| // Change ** to Path | ||
| template = template.replace(/\/\*{2}/g, '(/([%5Cw%5C-%5C.]+)){1,}'); | ||
| // Change * to File | ||
| template = template.replace(/\*/g, '([%5Cw%5C-%5C.]+)'); | ||
| // Change / to \/ | ||
| template = template.replace(/\//g, '%5C%2F'); | ||
| // Instantiate Template | ||
| return new RegExp(decodeURIComponent(template)); | ||
| }; |
+4
-4
| { | ||
| "name": "@scaff/kit", | ||
| "version": "3.1.72", | ||
| "main": "index.js", | ||
| "version": "3.1.74", | ||
| "main": "dist/index.js", | ||
| "author": "joenix", | ||
| "license": "MIT", | ||
| "dependencies": { | ||
| "merge-deep": "^3.0.3" | ||
| "foreach.js": "^2.1.6" | ||
| }, | ||
| "gitHead": "c6a976a5f6307a870cb8ccb928c46682e5281b59" | ||
| "gitHead": "f798aca2cdac45acdbc1e41565069439313a3b59" | ||
| } |
-1
| module.exports = require('./kitchen'); |
| // Use Inf | ||
| const { path, fs, root } = require('./inf'); | ||
| /** | ||
| * Path Resolve | ||
| * @param dir {string} | ||
| * ======== ======== ======== | ||
| */ | ||
| function resolve(dir) { | ||
| return path.join(root, dir); | ||
| } | ||
| /** | ||
| * Check Presence | ||
| * @param path {string} | ||
| * ======== ======== ======== | ||
| */ | ||
| function presence(path, must) { | ||
| return fs.existsSync(`${root}${path}`) ? require(`${root}${path}`) : must === true ? null : {}; | ||
| } | ||
| // Export | ||
| module.exports = { resolve, presence }; |
| // Use Root | ||
| const { root } = require('./inf'); | ||
| // Get confAlias | ||
| const { configAlias } = require(`${root}/package.json`); | ||
| // Set configAlias | ||
| module.exports = configAlias || 'vuescaffrc'; |
| module.exports = require('merge-deep'); |
| // Use Inf | ||
| const { path, fs, root } = require('./inf'); | ||
| // Use Concert | ||
| const { resolve, presence } = require('./concert'); | ||
| // Set RC | ||
| exports.rc = require('./rc'); | ||
| // Set Deepmerge | ||
| exports.deepmerge = require('./deepmerge'); | ||
| // Set Path | ||
| exports.path = path; | ||
| // Set Fs | ||
| exports.fs = fs; | ||
| // Set Root | ||
| exports.root = root; | ||
| // Set Resolve | ||
| exports.resolve = resolve; | ||
| // Set Presence | ||
| exports.presence = presence; |
| // Path | ||
| const path = require('path'); | ||
| // Fs | ||
| const fs = require('fs'); | ||
| // Root | ||
| const root = process.cwd(); | ||
| // Export | ||
| module.exports = { path, fs, root }; |
| /** | ||
| * Preset for RC | ||
| * ========== ========== ========== | ||
| */ | ||
| module.exports = { | ||
| /** | ||
| * Main of Entry | ||
| * @property app { Path } | ||
| * ========== ========== ========== | ||
| */ | ||
| main: { | ||
| app: `App.vue`, | ||
| mount: `#app`, | ||
| }, | ||
| /** | ||
| * Data Mock | ||
| * @value { Boolean } | ||
| * ========== ========== ========== | ||
| */ | ||
| mock: false, | ||
| /** | ||
| * GraphQL Client | ||
| * @property uri { String } | ||
| * ========== ========== ========== | ||
| */ | ||
| apollo: false, | ||
| /** | ||
| * Registry | ||
| * @property host { Boolean } | ||
| * @property api { Boolean } | ||
| * @property route { Boolean } | ||
| * @property store { Boolean } | ||
| * @property mixin { Boolean } | ||
| * ========== ========== ========== | ||
| */ | ||
| registry: { | ||
| host: true, | ||
| api: true, | ||
| route: true, | ||
| store: true, | ||
| mixin: true, | ||
| }, | ||
| /** | ||
| * Extract | ||
| * @property util { Json } | ||
| * @property filter { Json } | ||
| * @property directive { Json } | ||
| * @property route { Json } | ||
| * @property store { Json } | ||
| * @property component { Json } | ||
| * @property style { Json } | ||
| * @property i18n { Json } | ||
| * ========== ========== ========== | ||
| */ | ||
| extract: { | ||
| util: '/utils/*.js', | ||
| filter: '/filters/*.js', | ||
| directive: '/directives/*.js', | ||
| route: '/pages/**/route.js', | ||
| store: '/pages/**/store.js', | ||
| component: '/components/*.vue', | ||
| style: '/styles/*.less', | ||
| i18n: '/i18n/*.js', | ||
| }, | ||
| }; |
| // Use Concert | ||
| const { presence } = require('./concert'); | ||
| // Use Deepmerge | ||
| const deepmerge = require('./deepmerge'); | ||
| // Use confAlias | ||
| const confAlias = require('./config'); | ||
| // Get Preset | ||
| const preset = require('./preset'); | ||
| // Get RC | ||
| const rc = presence(`/${confAlias}.js`); | ||
| // Factory RC as Function | ||
| module.exports = typeof rc === 'function' ? rc(preset) : deepmerge(preset, rc); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Network access
Supply chain riskThis module accesses the network.
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
14399
233.39%24
140%498
280.15%1
-50%3
Infinity%+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed