Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ued2345/octopus-util

Package Overview
Dependencies
Maintainers
3
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ued2345/octopus-util - npm Package Compare versions

Comparing version 1.1.3 to 1.1.4

src/vuePlugin/directives/bang/bang.ts

2

dist/octopus-util.min.js

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.OcUtil=t():e.OcUtil=t()}(window,(function(){return function(e){var t={};function n(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(i,r,function(t){return e[t]}.bind(null,r));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}([function(e,t,n){"use strict";t.__esModule=!0,t.default=function(){var e=navigator.userAgent;return{trident:e.indexOf("Trident")>-1,presto:e.indexOf("Presto")>-1,webKit:e.indexOf("AppleWebKit")>-1,gecko:e.indexOf("Gecko")>-1&&-1===e.indexOf("KHTML"),mobile:!!e.match(/AppleWebKit.*Mobile.*/)||e.indexOf("Mobile")>-1,ios:!!e.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),android:e.indexOf("Android")>-1||e.indexOf("Linux")>-1,iPhone:e.indexOf("iPhone")>-1,iPad:e.indexOf("iPad")>-1,webApp:-1===e.indexOf("Safari"),weixin:e.indexOf("MicroMessenger")>-1,qq:null!==e.match(/\sQQ/i)}}},function(e,t,n){"use strict";t.__esModule=!0,t.default=function(e,t,n){var i=new Date;i.setTime(i.getTime()+24*n*60*60*1e3);var r="expires="+i.toUTCString();document.cookie=e+"="+t+";path=/;;"+r}},function(e,t,n){"use strict";var i=function(e){return e&&e.__esModule?e:{default:e}};t.__esModule=!0;var r=i(n(0)),o=i(n(3)),u=i(n(4)),a=i(n(6)),d=i(n(1)),c=i(n(7));e.exports.default=e.exports={getBrowser:r.default,getInApp:o.default,JsBridge:u.default,getCookie:a.default,setCookie:d.default,delCookie:c.default}},function(e,t,n){"use strict";t.__esModule=!0,t.default=function(e){return!!(navigator.userAgent.indexOf(e)>-1)}},function(e,t,n){"use strict";var i,r=(i=function(e,t){return(i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),o=function(e){return e&&e.__esModule?e:{default:e}};t.__esModule=!0;var u=new(function(e){function t(){return e.call(this)||this}return r(t,e),t.prototype.callHandler=function(t,n){e.prototype.init.call(this,(function(e){e.callHandler("jsCallJavaAllInOne",t,n)}))},t.prototype.registerHandler=function(t,n){e.prototype.init.call(this,(function(e){e.registerHandler(t,n)}))},t}(o(n(5)).default));u.first(),t.default={callHandler:u.callHandler,registerHandler:u.registerHandler}},function(e,t,n){"use strict";var i=function(e){return e&&e.__esModule?e:{default:e}};t.__esModule=!0;var r=i(n(0)).default(),o=function(){function e(){this.isIOS=r.ios}return e.prototype.init=function(e){if(this.isIOS){if(window.WebViewJavascriptBridge)return e(window.WebViewJavascriptBridge);if(window.WVJBCallbacks)return window.WVJBCallbacks.push(e);window.WVJBCallbacks=[e];var t=document.createElement("iframe");t.style.display="none",t.src="wvjbscheme://__BRIDGE_LOADED__",document.documentElement.appendChild(t),setTimeout((function(){document.documentElement.removeChild(t)}),0)}else window.WebViewJavascriptBridge?e(window.WebViewJavascriptBridge):document.addEventListener("WebViewJavascriptBridgeReady",(function(){e(window.WebViewJavascriptBridge)}),!1)},e.prototype.first=function(){this.isIOS||this.init((function(e){e.init((function(e,t){t()}))}))},e}();t.default=o},function(e,t,n){"use strict";t.__esModule=!0,t.default=function(e){for(var t=document.cookie.replace(/\s/g,"").split(";"),n=0;n<t.length;n++){var i=t[n].split("=");if(i[0]==e)return decodeURIComponent(i[1])}return""}},function(e,t,n){"use strict";var i=function(e){return e&&e.__esModule?e:{default:e}};t.__esModule=!0;var r=i(n(1));t.default=function(e){r.default(e,"",-1)}}])}));
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.OcUtil=t():e.OcUtil=t()}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}([function(e,t,n){"use strict";t.__esModule=!0,t.default=function(){var e=navigator.userAgent;return{trident:e.indexOf("Trident")>-1,presto:e.indexOf("Presto")>-1,webKit:e.indexOf("AppleWebKit")>-1,gecko:e.indexOf("Gecko")>-1&&-1===e.indexOf("KHTML"),mobile:!!e.match(/AppleWebKit.*Mobile.*/)||e.indexOf("Mobile")>-1,ios:!!e.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),android:e.indexOf("Android")>-1||e.indexOf("Linux")>-1,iPhone:e.indexOf("iPhone")>-1,iPad:e.indexOf("iPad")>-1,webApp:-1===e.indexOf("Safari"),weixin:e.indexOf("MicroMessenger")>-1,qq:null!==e.match(/\sQQ/i)}}},function(e,t,n){"use strict";t.__esModule=!0,t.default=function(e,t,n){var r=new Date;r.setTime(r.getTime()+24*n*60*60*1e3);var o="expires="+r.toUTCString();document.cookie=e+"="+t+";path=/;;"+o}},function(e,t,n){"use strict";var r=function(){return(r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},o=function(e){return e&&e.__esModule?e:{default:e}};t.__esModule=!0;var i=o(n(0)),u=o(n(3)),c=o(n(4)),a=o(n(6)),l=o(n(1)),f=o(n(7)),s=o(n(8));e.exports.default=e.exports=r({getBrowser:i.default,getInApp:u.default,JsBridge:c.default,getCookie:a.default,setCookie:l.default,delCookie:f.default},s.default)},function(e,t,n){"use strict";t.__esModule=!0,t.default=function(e){return!!(navigator.userAgent.indexOf(e)>-1)}},function(e,t,n){"use strict";var r,o=(r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=function(e){return e&&e.__esModule?e:{default:e}};t.__esModule=!0;var u=new(function(e){function t(){return e.call(this)||this}return o(t,e),t.prototype.callHandler=function(t,n){e.prototype.init.call(this,(function(e){e.callHandler("jsCallJavaAllInOne",t,n)}))},t.prototype.registerHandler=function(t,n){e.prototype.init.call(this,(function(e){e.registerHandler(t,n)}))},t}(i(n(5)).default));u.first(),t.default={callHandler:u.callHandler,registerHandler:u.registerHandler}},function(e,t,n){"use strict";var r=function(e){return e&&e.__esModule?e:{default:e}};t.__esModule=!0;var o=r(n(0)).default(),i=function(){function e(){this.isIOS=o.ios}return e.prototype.init=function(e){if(this.isIOS){if(window.WebViewJavascriptBridge)return e(window.WebViewJavascriptBridge);if(window.WVJBCallbacks)return window.WVJBCallbacks.push(e);window.WVJBCallbacks=[e];var t=document.createElement("iframe");t.style.display="none",t.src="wvjbscheme://__BRIDGE_LOADED__",document.documentElement.appendChild(t),setTimeout((function(){document.documentElement.removeChild(t)}),0)}else window.WebViewJavascriptBridge?e(window.WebViewJavascriptBridge):document.addEventListener("WebViewJavascriptBridgeReady",(function(){e(window.WebViewJavascriptBridge)}),!1)},e.prototype.first=function(){this.isIOS||this.init((function(e){e.init((function(e,t){t()}))}))},e}();t.default=i},function(e,t,n){"use strict";t.__esModule=!0,t.default=function(e){for(var t=document.cookie.replace(/\s/g,"").split(";"),n=0;n<t.length;n++){var r=t[n].split("=");if(r[0]==e)return decodeURIComponent(r[1])}return""}},function(e,t,n){"use strict";var r=function(e){return e&&e.__esModule?e:{default:e}};t.__esModule=!0;var o=r(n(1));t.default=function(e){o.default(e,"",-1)}},function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var o=function(e){return e&&e.__esModule?e:{default:e}};t.__esModule=!0;var i=o(n(9));t.default={install:function(e,t){Object.keys(i.default).forEach((function(n){"object"===r(i.default[n])?e.directive(n,i.default[n]):"function"==typeof i.default[n]&&e.directive(n,new i.default[n](t[n]))}))}}},function(e,t,n){"use strict";var r=function(e){return e&&e.__esModule?e:{default:e}};t.__esModule=!0;var o=r(n(10));t.default={bang:o.default}},function(e,t,n){"use strict";var r,o=function(){return(o=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};t.__esModule=!0,function(e){e.Exposure="exposure",e.Click="click",e.Mounted="mounted"}(r||(r={}));var i=function(e){var t=this;this.inserted=function(e,n,o,i){var u,c,a;switch(n.arg){case r.Exposure:new Promise((function(n,r){"IMG"===e.tagName?(e.onload=function(){var r=e.getAttribute("data-src"),o=e.getAttribute("src");((r?r===o:o)||t.config.imgErrExposure)&&n(!0)},e.onerror=function(e){t.config.imgErrExposure?n(!0):r(e)}):n(!0)})).then((function(r){r&&IntersectionObserver&&(e.observer=new IntersectionObserver((function(r){r[0].intersectionRatio>=.95&&(t.callback(e,n,o,i),t.config.exposureMulti||e.observer.unobserve(e))}),{root:null,threshold:[.95]}),e.observer.observe(e))})).catch((function(e){console.error(e)}));break;case r.Click:var l=(u=t.callback,c=(c=t.config.clickThrottleInterval)||2e3,function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=this,r=+new Date;a&&r-a<c||(a=r,u.apply(n,e))});e.bangClickCb=function(){l(e,n,o,i)},e.addEventListener("click",e.bangClickCb);break;case r.Mounted:t.callback(e,n,o,i);break;default:t.callback(e,n,o,i)}},this.unbind=function(e,n){switch(n.arg){case r.Exposure:t.config.exposureMulti&&e.observer&&e.observer.unobserve(e);case r.Click:e.removeEventListener("click",e.bangClickCb)}},this.config=o(o({},this.DefaultConfig),e),this.callback=this.config.cb};t.default=i}])}));
{
"name": "@ued2345/octopus-util",
"version": "1.1.3",
"version": "1.1.4",
"description": "ued2345 utils",

@@ -5,0 +5,0 @@ "main": "dist/octopus-util.min.js",

@@ -26,2 +26,6 @@ ### 技术选型

│ │ └── jsBrige.ts // export jsbridge方法
│ ├── vue-plugin
│ │ │── directives // vue全局指令
│ │ │ └── bang // 埋点指令
│ │ └── vuePlugin.ts // export vuePlugin
│ └── index.ts // webpack打包入口文件

@@ -95,7 +99,55 @@ ├── .babelrc // babel配置文件

### vue相关工具
##### 埋点工具
- 目的
> 优化大部分在项目中业务代码中混入埋点代码的情况
- 适用场景
> 优化大部分曝光、挂载、点击的埋点的上报的书写方式,使用vue指令的方式
- 使用示例
```javascript
// main.js 或单页应用入口js
import OcUtil from '@ued2345/octopus-util'
// 模拟上报函数(参数同vue自定义指令)
const bang = (el, binding) => {console.log(`触发上报,类型:${binding.arg},值: ${binding.value}`)}
Vue.use(OcUtil, {
bang: {
// 自定义配置
cb: bang
}
})
// test.vue
<div v-bang:exposure="`我曝光啦`"></div> //曝光后输出: "触发上报,类型:exposure,值: 我曝光啦"
```
- **低版本兼容**
因为低版本机型不支持intersectionObserver需要安装相应polyfill,具体步骤如下:
1. npm i intersection-observer --save
2. 在单页应用入口文件处顶部引入,如vue-cli里的main.js
```javasccript
import 'intersection-observer'
```
- 支持配置
| 参数 | 说明 | 类型 | 是否必须 | 默认 |
| ------ | ------ |------ | ------ |------ |
| cb | 触发上报后的回调函数 | 同vue自定义指令钩子函数,(el: HTMLElement, binding: DirectiveBinding, vnode: vnode, oldVnode: vnode) => void 详见[官网](https://cn.vuejs.org/v2/guide/custom-directive.html#%E9%92%A9%E5%AD%90%E5%87%BD%E6%95%B0%E5%8F%82%E6%95%B0)| 是 | 无 |
| clickThrottleInterval | 点击事件上报节流的间隙时间 | number | 否 | 2000 |
| exposureMulti | 元素未销毁时是否可以多次发送曝光统计事件 | boolean | false |
| imgErrExposure | 图片加载出错的时候是否算曝光成功(曝光事件绑定在img元素上时) | boolean | false |
- 注意事项
+ 在给**不定高**图片绑定曝光事件时,由于网络原因可能出现后面的图片先加载完曝光的情况,造成未在可视区内但是却曝光的假象。
+ 原因:其实该图确实已经曝光,但是因为时间过短(前面图加载完之后该图就被挤出可视区了)肉眼难以察觉而已。
+ 解决方法: 1.还是定高吧 2.这可能不能算个bug,因为它确实曝光过了(后期可能会加曝光最短时长的功能,能解决该问题)。
+ 若同时给v-if,v-else元素绑定mounted埋点事件时,在两者tagName相同的情况下,切换显示时会造成后一个埋点事件未触发。
+ 原因: 这是因为在切换显示时由于v-if和v-else的标签一样,而且没有key等唯一标识,在dom diff过程中默认该元素未发生变化,所以此时后面元素的指令insert钩子函数不会触发。
+ 解决方法: 给两个元素设置不同的tagName或者给元素绑定唯一key属性, 如下
```html
<div v-if="show" v-bang:mounted="`显示1`" key="显示1">显示1</div>
<div v-else v-bang:mounted="`显示2`" key="显示2">显示2</div>
```

@@ -10,2 +10,3 @@ /**

import delCookie from "./cookie/delCookie";
import VuePlugin from "./vuePlugin/vuePlugin";

@@ -19,2 +20,3 @@ module.exports.default = module.exports = {

delCookie,
...VuePlugin // vue工具(内含insert方法)
};

@@ -8,3 +8,9 @@ {

"sourceMap": false,
"esModuleInterop": true
"esModuleInterop": true,
"lib": [
"dom",
"es2015",
"es5",
"es6"
]
},

@@ -11,0 +17,0 @@ "include": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc