
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
fw-javascripts
Advanced tools
for test this lib, run
npm run test
import * as $FW from 'fw-javascripts'
// or
import { Request, Browser, ... } from 'fw-javascripts'
Request 方法是非常重要的核心方法, 熟练使用, 非常关键
import * as $FW from 'fw-javascripts'
// user.json
{
"code": 10000,
"data": {
"name": "delong"
}
}
// 通过GET方法, 过去接口数据
$FW.Request('/api/v1/user.json').then(data => {
console.log(data.name) // => "delong"
})
// user.json
{
"code": 60001,
"data": { },
"message": "服务异常"
}
// 通过GET方法, 过去接口数据
$FW.Request('/api/v1/user.json').then(data => {
// 不会执行
}, error => {
console.log(error.code) // => 60001
console.log(error.message) // => "服务异常"
})
// user.json
{
"code": 10000,
"data": {
"new_id": 666
},
}
// 通过GET方法, 过去接口数据
$FW.Request({
url: '/api/v1/user.json',
method: 'post',
data: {
new_name: "new name"
}
}).then(data => {
console.log(data.new_id) // => 666
})
{
url: '',
method: 'GET',
data: {},
withCredentials: false,
timeout: 10,
onStart: n => null,
onTimeout: n => null,
onComplete: n => null
}
import { RequestFactory } from 'fw-components'
let NewRequestObject = new RequestFactory({
error_handler: (code, message, responseText) => {
// 通用异常处理
},
alert: null, // 异常弹窗
capture: captureError, // 异常捕捉
show_loading: null, // 加载动画开始
hide_loading: null // 加载动画结束
})
// 通过工场创建的不是请求方法本身, ajax方法是新对象的一个实例方法
let ajaxInstance = NewRequestObject.ajax
获取网页运行环境, 每个属性都是 true 或 false
注意: 这里调用的是属性, 不是方法
import { BrowserFactory } from 'fw-javascripts'
let Browser = new BrowserFactory(navigator.userAgent, 'Easyloan888')
Browser.inApp //
Browser.appVersion //
Browser.inAndroid //
Browser.inIOS //
Browser.inMobile //
Browser.inIOSApp //
Browser.inAndroidApp //
Browser.inWeixin //
BrowserFactory 简化版, 在实际使用中, 因为 BrowserFacotry 需要初始化, 容易出错(其实是, 经常出错)
所以直接 export 出对象
import { Browser } from 'fw-javascripts'
Browser.inApp
Browser.appVersion
Browser.inAndroid
Browser.inIOS
Browser.inMobile
// ...
import { getJSONP } from 'fw-javascripts'
getJSONP('https://domain.com/path?search').then(data => {
console.log(data)
})
Utils.urlQuery
import { Utils } from 'fw-javascripts'
// 假设 当前浏览器访问url是
// https://a.com?a=sometext&b&c=2
let q = Utils.urlQuery
console.log(q) // => [object object]
console.log(q.a) // => 'sometext' (string type)
console.log(q.b) // => true (boolean type)
console.log(q.c) // => '2' (string type)
Utils.format
Utils.format 是多个格式化方法集合
Utils.format.price
import { Utils } from 'fw-javascripts'
console.log(Utils.format.price(1234567890.45678))
// => '1,234,567,890.45'
console.log(Utils.format.price(1.3, 2))
// => '1.30'
console.log(Utils.format.price(.9, 4))
// => '0.9000'
Utils.Cookie
Utils.Cookie 是操作document的cookie的方法
import { Utils } from 'fw-javascript'
Utils.Cookie.set('a', '123')
console.log(Utils.Cookie.get('a'))
// => 123
Utils.Cookie.delete('a')
console.log(Utils.Cookie.get('a'))
// => ''
简单的内存缓存
创建实例
import { Cache } from 'fw-javascripts'
let cache = new Cache()
set get
set 通过一个key 设置value和有效期
import { Cache } from 'fw-javascript'
let cache = new Cache()
cache.set('key', 'value', 10)
// => null
cache.get('key')
// => 'value'
// ... 10s 后
cache.get('key')
// => null
当前网页嵌入到App中, 需要与app通信时, 需要调用这个方法
import { NativeBridgeFactory } from 'fw-javascripts'
let receive_handler = function(receive_data){
console.log(receive_data) // => {type: '', value: ''}
// use this method receive data from App
}
const NativeBridge = new NativeBridgeFactory('Easyloan888')
// 设置接受来自App的方法
NativeBridge.onReceive(data => (){
console.log(data)
})
NativeBridge.trigger('close') // 关闭当前webview
NativeBridge.toNative('coupon') // 到app原生的优惠券页面
监听浏览器DOM加载状态, 一旦DOM加载完成, 立即执行, 跟jQuery.ready方法相同
import { DOMReady } from 'fw-javascripts'
DOMReady(()=>{
// 会在DOM加载完成之后再执行
somethine()
})
FAQs
common utils
The npm package fw-javascripts receives a total of 53 weekly downloads. As such, fw-javascripts popularity was classified as not popular.
We found that fw-javascripts demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.