code
stringlengths 24
2.07M
| docstring
stringlengths 25
85.3k
| func_name
stringlengths 1
92
| language
stringclasses 1
value | repo
stringlengths 5
64
| path
stringlengths 4
172
| url
stringlengths 44
218
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
onOrderBook ({ symbol, prec, len, cbGID }, cb) {
this._registerListener('orderbook', {
0: symbol,
1: prec,
2: len
}, OrderBook, cbGID, cb)
}
|
Register a handler to be called with each received candle
@param {object} opts - options
@param {string} opts.symbol - book symbol
@param {string} opts.prec - book precision, i.e. 'R0'
@param {string} opts.len - book length, i.e. '25'
@param {string|number} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-public-order-books
@see WSv2#subscribeOrderBook
@see WSv2#unsubscribeOrderBook
|
onOrderBook
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onOrderBookChecksum ({ symbol, prec, len, cbGID }, cb) {
this._registerListener('ob_checksum', {
0: symbol,
1: prec,
2: len
}, null, cbGID, cb)
}
|
Register a handler to be called with each received order book checksum
@param {object} opts - options
@param {string} opts.symbol - book symbol
@param {string} opts.prec - book precision, i.e. 'R0'
@param {string} opts.len - book length, i.e. '25'
@param {string|number} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-public-order-books
@see WSv2#subscribeOrderBook
@see WSv2#unsubscribeOrderBook
|
onOrderBookChecksum
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onTrades ({ symbol, pair, cbGID }, cb) {
const id = pair || symbol || ''
const model = id[0] === 'f' ? FundingTrade : PublicTrade
this._registerListener('trades', { 0: id }, model, cbGID, cb)
}
|
Register a handler to be called with each received trade (pair or symbol
required)
@param {object} opts - options
@param {string} [opts.pair] - required if no symbol specified
@param {string} [opts.symbol] - required if no pair specified
@param {string|number} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-public-trades
@see WSv2#subscribeTrades
@see WSv2#unsubscribeTrades
|
onTrades
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onTradeEntry ({ pair, symbol, cbGID }, cb) {
const id = pair || symbol || ''
this._registerListener('trade-entry', { 0: id }, PublicTrade, cbGID, cb)
}
|
Register a handler to be called on each trade `'te'` event
@param {object} opts - options
@param {string} [opts.pair] - required if no symbol specified
@param {string} [opts.symbol] - required if no pair specified
@param {string|number} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-public-trades
@see WSv2#subscribeTrades
@see WSv2#unsubscribeTrades
|
onTradeEntry
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onAccountTradeEntry ({ symbol, cbGID }, cb) {
this._registerListener('auth-te', { 1: symbol }, Trade, cbGID, cb)
}
|
Register a handler to be called on each personal trade `'te'` event
@param {object} opts - options
@param {string} [opts.pair] - required if no symbol specified
@param {string} [opts.symbol] - required if no pair specified
@param {string|number} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-public-trades
|
onAccountTradeEntry
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onAccountTradeUpdate ({ symbol, cbGID }, cb) {
this._registerListener('auth-tu', { 1: symbol }, Trade, cbGID, cb)
}
|
Register a handler to be called on each personal trade `'tu'` event
@param {object} opts - options
@param {string} [opts.pair] - required if no symbol specified
@param {string} [opts.symbol] - required if no pair specified
@param {string|number} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-auth-trades
|
onAccountTradeUpdate
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onTicker ({ symbol = '', cbGID } = {}, cb) {
const m = symbol[0] === 'f' ? FundingTicker : TradingTicker
this._registerListener('ticker', { 0: symbol }, m, cbGID, cb)
}
|
Register a handler to be called on each received ticker
@param {object} opts - options
@param {string} opts.symbol - symbol for tickers
@param {string|number} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-public-ticker
@see WSv2#subscribeTicker
@see WSv2#unsubscribeTicker
|
onTicker
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onStatus ({ key = '', cbGID } = {}, cb) {
this._registerListener('status', { 0: key }, null, cbGID, cb)
}
|
Register a handler to be called on each message for the desired status
feed.
@param {object} opts - options
@param {string} opts.key - key of feed to listen on
@param {string|number} [opts.cbGID] - callback group ID
@param {Function} cb - callback
@see WSv2#subscribeStatus
|
onStatus
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onOrderSnapshot ({ symbol, id, cid, gid, cbGID }, cb) {
this._registerListener('os', {
0: id,
1: gid,
2: cid,
3: symbol
}, Order, cbGID, cb)
}
|
Register a handler to be called on each full order snapshot (sent on auth)
@param {object} opts - options
@param {string} [opts.symbol] - symbol to match
@param {number} [opts.id] - order ID to match
@param {number} [opts.cid] - order client ID to match
@param {number} [opts.gid] - order group ID to match
@param {string|number} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-auth-orders
@see WSv2#auth
|
onOrderSnapshot
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onOrderUpdate ({ symbol, id, cid, gid, cbGID }, cb) {
this._registerListener('ou', {
0: id,
1: gid,
2: cid,
3: symbol
}, Order, cbGID, cb)
}
|
Register a handler to be called on each order update packet
@param {object} opts - options
@param {string} [opts.symbol] - symbol to match
@param {number} [opts.id] - order ID to match
@param {number} [opts.cid] - order client ID to match
@param {number} [opts.gid] - order group ID to match
@param {string} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-auth-orders
@see WSv2#updateOrder
|
onOrderUpdate
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onOrderClose ({ symbol, id, cid, gid, cbGID }, cb) {
this._registerListener('oc', {
0: id,
1: gid,
2: cid,
3: symbol
}, Order, cbGID, cb)
}
|
Register a handler to be called on each order close packet
@param {object} opts - options
@param {string} [opts.symbol] - symbol to match
@param {number} [opts.id] - order ID to match
@param {number} [opts.cid] - order client ID to match
@param {number} [opts.gid] - order group ID to match
@param {string} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-auth-orders
@see WSv2#cancelOrder
|
onOrderClose
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onPositionSnapshot ({ symbol, cbGID }, cb) {
this._registerListener('ps', { 0: symbol }, Position, cbGID, cb)
}
|
Register a handler to be called on each position snapshot (sent on auth)
@param {object} opts - options
@param {string} [opts.symbol] - symbol to match
@param {string} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-auth-position
@see WSv2#auth
|
onPositionSnapshot
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onPositionNew ({ symbol, cbGID }, cb) {
this._registerListener('pn', { 0: symbol }, Position, cbGID, cb)
}
|
Register a handler to be called when a position is opened
@param {object} opts - options
@param {string} [opts.symbol] - symbol to match
@param {string} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-auth-position
|
onPositionNew
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onPositionUpdate ({ symbol, cbGID }, cb) {
this._registerListener('pu', { 0: symbol }, Position, cbGID, cb)
}
|
Register a handler to be called when a position is updated
@param {object} opts - options
@param {string} [opts.symbol] - symbol to match
@param {string} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-auth-position
|
onPositionUpdate
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onPositionClose ({ symbol, cbGID }, cb) {
this._registerListener('pc', { 0: symbol }, Position, cbGID, cb)
}
|
Register a handler to be called when a position is closed
@param {object} opts - options
@param {string} [opts.symbol] - symbol to match
@param {string} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-auth-position
|
onPositionClose
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onFundingOfferSnapshot ({ symbol, cbGID }, cb) {
this._registerListener('fos', { 1: symbol }, FundingOffer, cbGID, cb)
}
|
Register a handler to be called on each fundign offer snapshot (sent on
auth)
@param {object} opts - options
@param {string} [opts.symbol] - symbol to match
@param {string} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-auth-offers
@see WSv2#auth
|
onFundingOfferSnapshot
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onFundingOfferNew ({ symbol, cbGID }, cb) {
this._registerListener('fon', { 1: symbol }, FundingOffer, cbGID, cb)
}
|
Register a handler to be called when a funding offer is created
@param {object} opts - options
@param {string} [opts.symbol] - symbol to match
@param {string} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-auth-offers
|
onFundingOfferNew
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onFundingOfferUpdate ({ symbol, cbGID }, cb) {
this._registerListener('fou', { 1: symbol }, FundingOffer, cbGID, cb)
}
|
Register a handler to be called when a funding offer is updated
@param {object} opts - options
@param {string} [opts.symbol] - symbol to match
@param {string} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-auth-offers
|
onFundingOfferUpdate
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onFundingOfferClose ({ symbol, cbGID }, cb) {
this._registerListener('foc', { 1: symbol }, FundingOffer, cbGID, cb)
}
|
Register a handler to be called when a funding offer is closed
@param {object} opts - options
@param {string} [opts.symbol] - symbol to match
@param {string} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-auth-offers
|
onFundingOfferClose
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onFundingCreditSnapshot ({ symbol, cbGID }, cb) {
this._registerListener('fcs', { 1: symbol }, FundingCredit, cbGID, cb)
}
|
Register a handler to be called on each funding credit snapshot (sent on
auth)
@param {object} opts - options
@param {string} [opts.symbol] - symbol to match
@param {string} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-auth-credits
@see WSv2#auth
|
onFundingCreditSnapshot
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onFundingCreditNew ({ symbol, cbGID }, cb) {
this._registerListener('fcn', { 1: symbol }, FundingCredit, cbGID, cb)
}
|
Register a handler to be called when a funding credit is created
@param {object} opts - options
@param {string} [opts.symbol] - symbol to match
@param {string} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-auth-credits
|
onFundingCreditNew
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onFundingCreditUpdate ({ symbol, cbGID }, cb) {
this._registerListener('fcu', { 1: symbol }, FundingCredit, cbGID, cb)
}
|
Register a handler to be called when a funding credit is updated
@param {object} opts - options
@param {string} [opts.symbol] - symbol to match
@param {string} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-auth-credits
|
onFundingCreditUpdate
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onFundingCreditClose ({ symbol, cbGID }, cb) {
this._registerListener('fcc', { 1: symbol }, FundingCredit, cbGID, cb)
}
|
Register a handler to be called when a funding credit is closed
@param {object} opts - options
@param {string} [opts.symbol] - symbol to match
@param {string} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-auth-credits
|
onFundingCreditClose
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onFundingLoanSnapshot ({ symbol, cbGID }, cb) {
this._registerListener('fls', { 1: symbol }, FundingLoan, cbGID, cb)
}
|
Register a handler to be called on each funding loan snapshot (sent on
auth)
@param {object} opts - options
@param {string} [opts.symbol] - symbol to match
@param {string} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-auth-loans
@see WSv2#auth
|
onFundingLoanSnapshot
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onFundingLoanNew ({ symbol, cbGID }, cb) {
this._registerListener('fln', { 1: symbol }, FundingLoan, cbGID, cb)
}
|
Register a handler to be called when a funding loan is created
@param {object} opts - options
@param {string} [opts.symbol] - symbol to match
@param {string} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-auth-loans
|
onFundingLoanNew
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onFundingLoanUpdate ({ symbol, cbGID }, cb) {
this._registerListener('flu', { 1: symbol }, FundingLoan, cbGID, cb)
}
|
Register a handler to be called when a funding loan is updated
@param {object} opts - options
@param {string} [opts.symbol] - symbol to match
@param {string} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-auth-loans
|
onFundingLoanUpdate
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onFundingLoanClose ({ symbol, cbGID }, cb) {
this._registerListener('flc', { 1: symbol }, FundingLoan, cbGID, cb)
}
|
Register a handler to be called when a funding loan is closed
@param {object} opts - options
@param {string} [opts.symbol] - symbol to match
@param {string} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-auth-loans
|
onFundingLoanClose
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onWalletSnapshot ({ cbGID }, cb) {
this._registerListener('ws', null, Wallet, cbGID, cb)
}
|
Register a handler to be called on each wallet snapshot (sent on auth)
@param {object} opts - options
@param {string} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-auth-wallets
|
onWalletSnapshot
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onWalletUpdate ({ cbGID }, cb) {
this._registerListener('wu', null, Wallet, cbGID, cb)
}
|
Register a handler to be called on each wallet update
@param {object} opts - options
@param {string} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-auth-wallets
|
onWalletUpdate
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onBalanceInfoUpdate ({ cbGID }, cb) {
this._registerListener('bu', null, BalanceInfo, cbGID, cb)
}
|
Register a handler to be called on each balance info update
@param {object} opts - options
@param {string} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-auth-balance
|
onBalanceInfoUpdate
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onMarginInfoUpdate ({ cbGID }, cb) {
this._registerListener('miu', null, MarginInfo, cbGID, cb)
}
|
Register a handler to be called on each margin info update
@param {object} opts - options
@param {string} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-auth-margin
|
onMarginInfoUpdate
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onFundingInfoUpdate ({ cbGID }, cb) {
this._registerListener('fiu', null, FundingInfo, cbGID, cb)
}
|
Register a handler to be called on each funding info update
@param {object} opts - options
@param {string} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-auth-funding
|
onFundingInfoUpdate
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onFundingTradeEntry ({ symbol, cbGID }, cb) {
this._registerListener('fte', { 0: symbol }, FundingTrade, cbGID, cb)
}
|
Register a handler to be called on each funding trade `'te'` event
@param {object} opts - options
@param {string} [opts.symbol] - symbol to match
@param {string} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-auth-funding-trades
|
onFundingTradeEntry
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onFundingTradeUpdate ({ symbol, cbGID }, cb) {
this._registerListener('ftu', { 0: symbol }, FundingTrade, cbGID, cb)
}
|
Register a handler to be called on each funding trade `'tu'` event
@param {object} opts - options
@param {string} [opts.symbol] - symbol to match
@param {string} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-auth-funding-trades
|
onFundingTradeUpdate
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
onNotification ({ type, cbGID }, cb) {
this._registerListener('n', { 1: type }, Notification, cbGID, cb)
}
|
Register a handler to be called on each notification
@param {object} opts - options
@param {string} [opts.type] - type to match
@param {string} [opts.cbGID] - callback group id
@param {Function} cb - callback
@see https://docs.bitfinex.com/v2/reference#ws-auth-notifications
|
onNotification
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/transports/ws2.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/transports/ws2.js
|
MIT
|
setSigFig = (number = 0, maxSigs = DEFAULT_SIG_FIGS) => {
const n = +(number)
if (!isFinite(n)) {
return number
}
const value = n.toPrecision(maxSigs)
return /e/.test(value)
? new Big(value).toString()
: value
}
|
Smartly set the precision (decimal) on a value based off of the significant
digit maximum. For example, calling with 3.34 when the max sig figs allowed
is 5 would return '3.3400', the representation number of decimals IF they
weren't zeros.
@param {number} number - number to manipulate
@param {number} [maxSigs] - default 5
@returns {string} str
|
setSigFig
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/util/precision.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/util/precision.js
|
MIT
|
setSigFig = (number = 0, maxSigs = DEFAULT_SIG_FIGS) => {
const n = +(number)
if (!isFinite(n)) {
return number
}
const value = n.toPrecision(maxSigs)
return /e/.test(value)
? new Big(value).toString()
: value
}
|
Smartly set the precision (decimal) on a value based off of the significant
digit maximum. For example, calling with 3.34 when the max sig figs allowed
is 5 would return '3.3400', the representation number of decimals IF they
weren't zeros.
@param {number} number - number to manipulate
@param {number} [maxSigs] - default 5
@returns {string} str
|
setSigFig
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/util/precision.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/util/precision.js
|
MIT
|
setPrecision = (number = 0, decimals = 0) => {
const n = +(number)
return (isFinite(n))
? n.toFixed(decimals)
: number
}
|
Smartly set the precision (decimal) on a value based off of the significant
digit maximum. For example, calling with 3.34 when the max sig figs allowed
is 5 would return '3.3400', the representation number of decimals IF they
weren't zeros.
@param {number} number - number to manipulate
@param {number} [maxSigs] - default 5
@returns {string} str
|
setPrecision
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/util/precision.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/util/precision.js
|
MIT
|
setPrecision = (number = 0, decimals = 0) => {
const n = +(number)
return (isFinite(n))
? n.toFixed(decimals)
: number
}
|
Smartly set the precision (decimal) on a value based off of the significant
digit maximum. For example, calling with 3.34 when the max sig figs allowed
is 5 would return '3.3400', the representation number of decimals IF they
weren't zeros.
@param {number} number - number to manipulate
@param {number} [maxSigs] - default 5
@returns {string} str
|
setPrecision
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/util/precision.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/util/precision.js
|
MIT
|
prepareAmount = (amount = 0) => {
return setPrecision(amount, AMOUNT_DECIMALS)
}
|
Smartly set the precision (decimal) on a value based off of the significant
digit maximum. For example, calling with 3.34 when the max sig figs allowed
is 5 would return '3.3400', the representation number of decimals IF they
weren't zeros.
@param {number} number - number to manipulate
@param {number} [maxSigs] - default 5
@returns {string} str
|
prepareAmount
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/util/precision.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/util/precision.js
|
MIT
|
prepareAmount = (amount = 0) => {
return setPrecision(amount, AMOUNT_DECIMALS)
}
|
Smartly set the precision (decimal) on a value based off of the significant
digit maximum. For example, calling with 3.34 when the max sig figs allowed
is 5 would return '3.3400', the representation number of decimals IF they
weren't zeros.
@param {number} number - number to manipulate
@param {number} [maxSigs] - default 5
@returns {string} str
|
prepareAmount
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/util/precision.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/util/precision.js
|
MIT
|
preparePrice = (price = 0) => {
return setSigFig(price, PRICE_SIG_FIGS)
}
|
Smartly set the precision (decimal) on a value based off of the significant
digit maximum. For example, calling with 3.34 when the max sig figs allowed
is 5 would return '3.3400', the representation number of decimals IF they
weren't zeros.
@param {number} number - number to manipulate
@param {number} [maxSigs] - default 5
@returns {string} str
|
preparePrice
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/util/precision.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/util/precision.js
|
MIT
|
preparePrice = (price = 0) => {
return setSigFig(price, PRICE_SIG_FIGS)
}
|
Smartly set the precision (decimal) on a value based off of the significant
digit maximum. For example, calling with 3.34 when the max sig figs allowed
is 5 would return '3.3400', the representation number of decimals IF they
weren't zeros.
@param {number} number - number to manipulate
@param {number} [maxSigs] - default 5
@returns {string} str
|
preparePrice
|
javascript
|
bitfinexcom/bitfinex-api-node
|
lib/util/precision.js
|
https://github.com/bitfinexcom/bitfinex-api-node/blob/master/lib/util/precision.js
|
MIT
|
function processResponse() {
// attempt to parse the json now
if(util.isJsonResponse(res)) {
if(body) {
try {
body = JSON.parse(body);
} catch (e) {
return resolver.reject(errors.invalidJson());
}
}
}
// salesforce returned an ok of some sort
if(res.statusCode >= 200 && res.statusCode <= 204) {
// attach the id back to the sobject on insert
if(sobject) {
if(sobject._reset) {
sobject._reset();
}
if(body && _.isObject(body) && body.id) {
sobject._fields.id = body.id;
}
}
return resolver.resolve(body);
}
// error handling
var e;
// error: no body
if(!body) {
e = new Error('Salesforce returned no body and status code ' + res.statusCode);
// error: array body
} else if (_.isArray(body) && body.length > 0) {
e = new Error(body[0].message);
e.errorCode = body[0].errorCode;
e.body = body;
// error: string body
} else if(_.isString(body)) {
e = new Error(body);
e.errorCode = body;
e.body = body;
} else if (_.isObject(body) && findValueForKeyInObject(body, 'message', 0, 5) && findValueForKeyInObject(body, 'errorCode', 0, 5)) {
e = new Error(findValueForKeyInObject(body, 'message'));
e.body = findValueForKeyInObject(body, 'message');
e.errorCode = findValueForKeyInObject(body, 'errorCode');
} else {
e = new Error('Salesforce returned an unrecognized error ' + res.statusCode);
e.body = body;
}
e.statusCode = res.statusCode;
// confirm auto-refresh support
if(e.errorCode &&
(e.errorCode === 'INVALID_SESSION_ID' || e.errorCode === 'Bad_OAuth_Token') &&
self.autoRefresh === true &&
(opts.oauth.refresh_token || (self.getUsername() && self.getPassword())) &&
!opts._retryCount) {
// attempt the autorefresh
Connection.prototype.autoRefreshToken.call(self, opts, function(err2, res2) {
if(err2) {
return resolver.reject(err2);
} else {
opts._retryCount = 1;
opts._resolver = resolver;
return Connection.prototype._apiRequest.call(self, opts);
}
});
} else {
return resolver.reject(e);
}
}
|
options:
- sobject
- uri
- callback
- oauth
- multipart
- method
- encoding
- body
- qs
- headers
|
processResponse
|
javascript
|
kevinohara80/nforce
|
index.js
|
https://github.com/kevinohara80/nforce/blob/master/index.js
|
MIT
|
authenticate = (username, password, securityToken) =>
new Promise((resolve, reject) => {
// Authenticate using multi user mode
org.authenticate(
{
username: username,
password: password,
securityToken: securityToken
},
(error, response) => {
if (!error) {
resolve(response)
} else {
reject(error)
}
}
)
})
|
Authenticate to login a user in the org
@param {string} username - e.g. [email protected]
@param {string} password
@param {string} securityToken - Your user's security token.
This can be reset in the org if needed.
|
authenticate
|
javascript
|
kevinohara80/nforce
|
examples/async-await-cruds.js
|
https://github.com/kevinohara80/nforce/blob/master/examples/async-await-cruds.js
|
MIT
|
authenticate = (username, password, securityToken) =>
new Promise((resolve, reject) => {
// Authenticate using multi user mode
org.authenticate(
{
username: username,
password: password,
securityToken: securityToken
},
(error, response) => {
if (!error) {
resolve(response)
} else {
reject(error)
}
}
)
})
|
Authenticate to login a user in the org
@param {string} username - e.g. [email protected]
@param {string} password
@param {string} securityToken - Your user's security token.
This can be reset in the org if needed.
|
authenticate
|
javascript
|
kevinohara80/nforce
|
examples/async-await-cruds.js
|
https://github.com/kevinohara80/nforce/blob/master/examples/async-await-cruds.js
|
MIT
|
query = (queryString, oauth) =>
new Promise((resolve, reject) => {
org.query(
{
query: queryString,
oauth: oauth
},
(error, response) => {
if (!error) {
resolve(response.records)
} else {
reject(error)
}
}
)
})
|
Perform a SOQL Query
@param {string} queryString - SOQL query
@param {object} oauth - OAuth string received from successful authentication
|
query
|
javascript
|
kevinohara80/nforce
|
examples/async-await-cruds.js
|
https://github.com/kevinohara80/nforce/blob/master/examples/async-await-cruds.js
|
MIT
|
query = (queryString, oauth) =>
new Promise((resolve, reject) => {
org.query(
{
query: queryString,
oauth: oauth
},
(error, response) => {
if (!error) {
resolve(response.records)
} else {
reject(error)
}
}
)
})
|
Perform a SOQL Query
@param {string} queryString - SOQL query
@param {object} oauth - OAuth string received from successful authentication
|
query
|
javascript
|
kevinohara80/nforce
|
examples/async-await-cruds.js
|
https://github.com/kevinohara80/nforce/blob/master/examples/async-await-cruds.js
|
MIT
|
createRecord = (sobjectName, recordData, oauth) => {
const sobj = nforce.createSObject(sobjectName, recordData)
return new Promise((resolve, reject) => {
org.insert(
{
sobject: sobj,
oauth: oauth
},
(error, response) => {
if (!error) {
resolve(response)
} else {
reject(error)
}
}
)
})
}
|
Create a record
@param {string} sobjectName - Name of the SObject (e.g. Account)
@param {object} recordData - Key value pair of Field Names and Field Values
@param {object} oauth - OAuth string received from successful authentication
|
createRecord
|
javascript
|
kevinohara80/nforce
|
examples/async-await-cruds.js
|
https://github.com/kevinohara80/nforce/blob/master/examples/async-await-cruds.js
|
MIT
|
createRecord = (sobjectName, recordData, oauth) => {
const sobj = nforce.createSObject(sobjectName, recordData)
return new Promise((resolve, reject) => {
org.insert(
{
sobject: sobj,
oauth: oauth
},
(error, response) => {
if (!error) {
resolve(response)
} else {
reject(error)
}
}
)
})
}
|
Create a record
@param {string} sobjectName - Name of the SObject (e.g. Account)
@param {object} recordData - Key value pair of Field Names and Field Values
@param {object} oauth - OAuth string received from successful authentication
|
createRecord
|
javascript
|
kevinohara80/nforce
|
examples/async-await-cruds.js
|
https://github.com/kevinohara80/nforce/blob/master/examples/async-await-cruds.js
|
MIT
|
updateRecord = (sobjectName, recordDataWithID, oauth) => {
const sobj = nforce.createSObject(sobjectName, recordDataWithID)
return new Promise((resolve, reject) => {
org.update(
{
sobject: sobj,
oauth: oauth
},
(error, response) => {
if (!error) {
resolve(response)
} else {
reject(error)
}
}
)
})
}
|
Update a record
@param {string} sobjectName - Name of the SObject (e.g. Account)
@param {object} recordDataWithID - Key value pair of Field Names and Field Values
@param {object} oauth - OAuth string received from successful authentication
|
updateRecord
|
javascript
|
kevinohara80/nforce
|
examples/async-await-cruds.js
|
https://github.com/kevinohara80/nforce/blob/master/examples/async-await-cruds.js
|
MIT
|
updateRecord = (sobjectName, recordDataWithID, oauth) => {
const sobj = nforce.createSObject(sobjectName, recordDataWithID)
return new Promise((resolve, reject) => {
org.update(
{
sobject: sobj,
oauth: oauth
},
(error, response) => {
if (!error) {
resolve(response)
} else {
reject(error)
}
}
)
})
}
|
Update a record
@param {string} sobjectName - Name of the SObject (e.g. Account)
@param {object} recordDataWithID - Key value pair of Field Names and Field Values
@param {object} oauth - OAuth string received from successful authentication
|
updateRecord
|
javascript
|
kevinohara80/nforce
|
examples/async-await-cruds.js
|
https://github.com/kevinohara80/nforce/blob/master/examples/async-await-cruds.js
|
MIT
|
upsertRecord = (sobjectName, recordDataWithID, oauth) => {
const sobj = nforce.createSObject(sobjectName)
const recordId = !!recordDataWithID.id ? recordDataWithID.id : ''
sobj.setExternalId('Id', recordId)
Object.entries(recordDataWithID).map(([key, value]) => {
sobj.set(key, value)
})
return new Promise((resolve, reject) => {
org.upsert(
{
sobject: sobj,
oauth: oauth,
requestOpts: {
method: !recordId ? 'POST' : 'PATCH'
}
},
(error, response) => {
if (!error) {
if(!recordId) {
resolve(response)
} else {
resolve(recordDataWithID)
}
} else {
reject(error)
}
}
)
})
}
|
Upsert a record
@param {string} sobjectName - Name of the SObject (e.g. Account)
@param {object} recordDataWithID - Key value pair of Field Names and Field Values
@param {object} oauth - OAuth string received from successful authentication
|
upsertRecord
|
javascript
|
kevinohara80/nforce
|
examples/async-await-cruds.js
|
https://github.com/kevinohara80/nforce/blob/master/examples/async-await-cruds.js
|
MIT
|
upsertRecord = (sobjectName, recordDataWithID, oauth) => {
const sobj = nforce.createSObject(sobjectName)
const recordId = !!recordDataWithID.id ? recordDataWithID.id : ''
sobj.setExternalId('Id', recordId)
Object.entries(recordDataWithID).map(([key, value]) => {
sobj.set(key, value)
})
return new Promise((resolve, reject) => {
org.upsert(
{
sobject: sobj,
oauth: oauth,
requestOpts: {
method: !recordId ? 'POST' : 'PATCH'
}
},
(error, response) => {
if (!error) {
if(!recordId) {
resolve(response)
} else {
resolve(recordDataWithID)
}
} else {
reject(error)
}
}
)
})
}
|
Upsert a record
@param {string} sobjectName - Name of the SObject (e.g. Account)
@param {object} recordDataWithID - Key value pair of Field Names and Field Values
@param {object} oauth - OAuth string received from successful authentication
|
upsertRecord
|
javascript
|
kevinohara80/nforce
|
examples/async-await-cruds.js
|
https://github.com/kevinohara80/nforce/blob/master/examples/async-await-cruds.js
|
MIT
|
deleteRecord = (sobjectName, recordDataWithID, oauth) => {
const sobj = nforce.createSObject(sobjectName, recordDataWithID)
return new Promise((resolve, reject) => {
org.delete(
{
sobject: sobj,
oauth: oauth
},
(error, response) => {
if (!error) {
resolve(response)
} else {
reject(error)
}
}
)
})
}
|
Delete a record
@param {string} sobjectName - Name of the SObject (e.g. Account)
@param {object} recordDataWithID - Key value pair of Field Names and Field Values
@param {object} oauth - OAuth string received from successful authentication
|
deleteRecord
|
javascript
|
kevinohara80/nforce
|
examples/async-await-cruds.js
|
https://github.com/kevinohara80/nforce/blob/master/examples/async-await-cruds.js
|
MIT
|
deleteRecord = (sobjectName, recordDataWithID, oauth) => {
const sobj = nforce.createSObject(sobjectName, recordDataWithID)
return new Promise((resolve, reject) => {
org.delete(
{
sobject: sobj,
oauth: oauth
},
(error, response) => {
if (!error) {
resolve(response)
} else {
reject(error)
}
}
)
})
}
|
Delete a record
@param {string} sobjectName - Name of the SObject (e.g. Account)
@param {object} recordDataWithID - Key value pair of Field Names and Field Values
@param {object} oauth - OAuth string received from successful authentication
|
deleteRecord
|
javascript
|
kevinohara80/nforce
|
examples/async-await-cruds.js
|
https://github.com/kevinohara80/nforce/blob/master/examples/async-await-cruds.js
|
MIT
|
Usage = (props) => {
return <HelloWorld />
}
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!
DO NOT DELETE OR CHANGE THIS.
This is how you would use your above component and
the output of this code is displayed on the browser
|
Usage
|
javascript
|
tyroprogrammer/learn-react-app
|
src/exercise/solution/01-HelloWorld-solution.js
|
https://github.com/tyroprogrammer/learn-react-app/blob/master/src/exercise/solution/01-HelloWorld-solution.js
|
MIT
|
Usage = (props) => {
return <HelloWorld />
}
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!
DO NOT DELETE OR CHANGE THIS.
This is how you would use your above component and
the output of this code is displayed on the browser
|
Usage
|
javascript
|
tyroprogrammer/learn-react-app
|
src/exercise/solution/01-HelloWorld-solution.js
|
https://github.com/tyroprogrammer/learn-react-app/blob/master/src/exercise/solution/01-HelloWorld-solution.js
|
MIT
|
Usage = (props) => {
return <HelloWorld />
}
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!
DO NOT DELETE OR CHANGE THIS.
This is how you would use your above component and
the output of this code is displayed on the browser
|
Usage
|
javascript
|
tyroprogrammer/learn-react-app
|
src/exercise/solution/02-IntroToJSX-solution.js
|
https://github.com/tyroprogrammer/learn-react-app/blob/master/src/exercise/solution/02-IntroToJSX-solution.js
|
MIT
|
Usage = (props) => {
return <HelloWorld />
}
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!
DO NOT DELETE OR CHANGE THIS.
This is how you would use your above component and
the output of this code is displayed on the browser
|
Usage
|
javascript
|
tyroprogrammer/learn-react-app
|
src/exercise/solution/02-IntroToJSX-solution.js
|
https://github.com/tyroprogrammer/learn-react-app/blob/master/src/exercise/solution/02-IntroToJSX-solution.js
|
MIT
|
install(app) {
app.component('Swiper', Swiper);
app.component('SwiperSlide', SwiperSlide);
}
|
@file vue-awesome-swiper
@author Surmon <https://github.com/surmon-china>
|
install
|
javascript
|
surmon-china/vue-awesome-swiper
|
index.js
|
https://github.com/surmon-china/vue-awesome-swiper/blob/master/index.js
|
MIT
|
render = async (fullMarkdown, extraOptions = {}) => {
const { yamlOptions, markdown: contentOnlyMarkdown } = parseYamlFrontMatter(fullMarkdown);
const options = Object.assign(getSlideOptions(yamlOptions), extraOptions);
const { title } = options;
const themeUrl = getThemeUrl(options.theme, options.assetsDir, options.base);
const highlightThemeUrl = getHighlightThemeUrl(options.highlightTheme);
const scriptPaths = getScriptPaths(options.scripts, options.assetsDir, options.base);
const cssPaths = getCssPaths(options.css, options.assetsDir, options.base);
const revealOptions = Object.assign({}, getRevealOptions(options.revealOptions), yamlOptions.revealOptions);
const slidifyOptions = _.pick(options, Object.keys(slidifyAttributeNames));
let slidifyAttributes = [];
for (const [key, value] of Object.entries(slidifyOptions)) {
const escaped_value = value.replace(/\n/g, '\\n').replace(/\r/g, '\\r');
slidifyAttributes.push(`${slidifyAttributeNames[key]}="${escaped_value}"`);
}
const preprocessorFn = await getPreprocessor(options.preprocessor);
const processedMarkdown = await preprocessorFn(contentOnlyMarkdown, options);
const revealOptionsStr = JSON.stringify(revealOptions);
const mermaidOptionsStr = options.mermaid === false ? undefined : JSON.stringify(options.mermaid);
const template = await getTemplate(options.template);
const context = Object.assign(options, {
title,
slidifyAttributes: slidifyAttributes.join(' '),
markdown: processedMarkdown,
themeUrl,
highlightThemeUrl,
scriptPaths,
cssPaths,
revealOptionsStr,
mermaidOptionsStr,
watch: getWatch()
});
const markup = Mustache.render(template, context);
return markup;
}
|
Renders the given markdown content into HTML.
@param {string} fullMarkdown - The contents of the markdown file, including a possible YAML front matter
@param {Object} extraOptions - Additional options (mostly used by tests)
@returns {string} The rendered HTML compatible with reveal.js
|
render
|
javascript
|
webpro/reveal-md
|
lib/render.js
|
https://github.com/webpro/reveal-md/blob/master/lib/render.js
|
MIT
|
render = async (fullMarkdown, extraOptions = {}) => {
const { yamlOptions, markdown: contentOnlyMarkdown } = parseYamlFrontMatter(fullMarkdown);
const options = Object.assign(getSlideOptions(yamlOptions), extraOptions);
const { title } = options;
const themeUrl = getThemeUrl(options.theme, options.assetsDir, options.base);
const highlightThemeUrl = getHighlightThemeUrl(options.highlightTheme);
const scriptPaths = getScriptPaths(options.scripts, options.assetsDir, options.base);
const cssPaths = getCssPaths(options.css, options.assetsDir, options.base);
const revealOptions = Object.assign({}, getRevealOptions(options.revealOptions), yamlOptions.revealOptions);
const slidifyOptions = _.pick(options, Object.keys(slidifyAttributeNames));
let slidifyAttributes = [];
for (const [key, value] of Object.entries(slidifyOptions)) {
const escaped_value = value.replace(/\n/g, '\\n').replace(/\r/g, '\\r');
slidifyAttributes.push(`${slidifyAttributeNames[key]}="${escaped_value}"`);
}
const preprocessorFn = await getPreprocessor(options.preprocessor);
const processedMarkdown = await preprocessorFn(contentOnlyMarkdown, options);
const revealOptionsStr = JSON.stringify(revealOptions);
const mermaidOptionsStr = options.mermaid === false ? undefined : JSON.stringify(options.mermaid);
const template = await getTemplate(options.template);
const context = Object.assign(options, {
title,
slidifyAttributes: slidifyAttributes.join(' '),
markdown: processedMarkdown,
themeUrl,
highlightThemeUrl,
scriptPaths,
cssPaths,
revealOptionsStr,
mermaidOptionsStr,
watch: getWatch()
});
const markup = Mustache.render(template, context);
return markup;
}
|
Renders the given markdown content into HTML.
@param {string} fullMarkdown - The contents of the markdown file, including a possible YAML front matter
@param {Object} extraOptions - Additional options (mostly used by tests)
@returns {string} The rendered HTML compatible with reveal.js
|
render
|
javascript
|
webpro/reveal-md
|
lib/render.js
|
https://github.com/webpro/reveal-md/blob/master/lib/render.js
|
MIT
|
renderFile = async (filePath, extraOptions) => {
try {
const content = await readFile(filePath);
return render(content.toString(), extraOptions);
} catch (e) {
return render('File not found.', extraOptions);
}
}
|
Renders the given markdown content into HTML.
@param {string} fullMarkdown - The contents of the markdown file, including a possible YAML front matter
@param {Object} extraOptions - Additional options (mostly used by tests)
@returns {string} The rendered HTML compatible with reveal.js
|
renderFile
|
javascript
|
webpro/reveal-md
|
lib/render.js
|
https://github.com/webpro/reveal-md/blob/master/lib/render.js
|
MIT
|
renderFile = async (filePath, extraOptions) => {
try {
const content = await readFile(filePath);
return render(content.toString(), extraOptions);
} catch (e) {
return render('File not found.', extraOptions);
}
}
|
Renders the given markdown content into HTML.
@param {string} fullMarkdown - The contents of the markdown file, including a possible YAML front matter
@param {Object} extraOptions - Additional options (mostly used by tests)
@returns {string} The rendered HTML compatible with reveal.js
|
renderFile
|
javascript
|
webpro/reveal-md
|
lib/render.js
|
https://github.com/webpro/reveal-md/blob/master/lib/render.js
|
MIT
|
replaceArgs = (cmd, shell) => {
const replacements = { f: this._getFile(shell), d: this._getFolder(shell), m: this._getMountFolder(shell) }
return cmd.replace(/\$([fdm])\b/g, match => `"${replacements[match.slice(1)]}"`)
}
|
Implementing this plugin requires three types of compatibility:
1. Abstracting operating system differences to support Windows and Linux.
2. Abstracting shell differences to support cmd, WSL, and bash, including nested shell calls.
3. Abstracting parameter differences, where cmd uses %VAR% and bash uses $VAR.
|
replaceArgs
|
javascript
|
obgnail/typora_plugin
|
plugin/commander.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/commander.js
|
MIT
|
replaceArgs = (cmd, shell) => {
const replacements = { f: this._getFile(shell), d: this._getFolder(shell), m: this._getMountFolder(shell) }
return cmd.replace(/\$([fdm])\b/g, match => `"${replacements[match.slice(1)]}"`)
}
|
Implementing this plugin requires three types of compatibility:
1. Abstracting operating system differences to support Windows and Linux.
2. Abstracting shell differences to support cmd, WSL, and bash, including nested shell calls.
3. Abstracting parameter differences, where cmd uses %VAR% and bash uses $VAR.
|
replaceArgs
|
javascript
|
obgnail/typora_plugin
|
plugin/commander.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/commander.js
|
MIT
|
getShellCommand = shell => {
switch (shell) {
case this.SHELL.GIT_BASH:
return `bash.exe -c`
case this.SHELL.POWER_SHELL:
return `powershell /C`
case this.SHELL.WSL:
return `wsl.exe -e bash -c`
default:
return File.isWin ? "cmd /C" : "bash -c"
}
}
|
Implementing this plugin requires three types of compatibility:
1. Abstracting operating system differences to support Windows and Linux.
2. Abstracting shell differences to support cmd, WSL, and bash, including nested shell calls.
3. Abstracting parameter differences, where cmd uses %VAR% and bash uses $VAR.
|
getShellCommand
|
javascript
|
obgnail/typora_plugin
|
plugin/commander.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/commander.js
|
MIT
|
getShellCommand = shell => {
switch (shell) {
case this.SHELL.GIT_BASH:
return `bash.exe -c`
case this.SHELL.POWER_SHELL:
return `powershell /C`
case this.SHELL.WSL:
return `wsl.exe -e bash -c`
default:
return File.isWin ? "cmd /C" : "bash -c"
}
}
|
Implementing this plugin requires three types of compatibility:
1. Abstracting operating system differences to support Windows and Linux.
2. Abstracting shell differences to support cmd, WSL, and bash, including nested shell calls.
3. Abstracting parameter differences, where cmd uses %VAR% and bash uses $VAR.
|
getShellCommand
|
javascript
|
obgnail/typora_plugin
|
plugin/commander.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/commander.js
|
MIT
|
callback_ = (err, stdout, stderr) => {
const hasError = err || stderr.length > 0
const errorMessage = hasError ? (err || stderr.toString()) : null
if (reject && hasError) {
reject(errorMessage)
} else if (resolve && !hasError) {
resolve(stdout)
}
if (callback) {
callback(err, stdout, stderr)
}
}
|
Implementing this plugin requires three types of compatibility:
1. Abstracting operating system differences to support Windows and Linux.
2. Abstracting shell differences to support cmd, WSL, and bash, including nested shell calls.
3. Abstracting parameter differences, where cmd uses %VAR% and bash uses $VAR.
|
callback_
|
javascript
|
obgnail/typora_plugin
|
plugin/commander.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/commander.js
|
MIT
|
callback_ = (err, stdout, stderr) => {
const hasError = err || stderr.length > 0
const errorMessage = hasError ? (err || stderr.toString()) : null
if (reject && hasError) {
reject(errorMessage)
} else if (resolve && !hasError) {
resolve(stdout)
}
if (callback) {
callback(err, stdout, stderr)
}
}
|
Implementing this plugin requires three types of compatibility:
1. Abstracting operating system differences to support Windows and Linux.
2. Abstracting shell differences to support cmd, WSL, and bash, including nested shell calls.
3. Abstracting parameter differences, where cmd uses %VAR% and bash uses $VAR.
|
callback_
|
javascript
|
obgnail/typora_plugin
|
plugin/commander.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/commander.js
|
MIT
|
reject = data => {
this.entities.pre.textContent += data.toString();
this.entities.pre.classList.add("error");
}
|
Implementing this plugin requires three types of compatibility:
1. Abstracting operating system differences to support Windows and Linux.
2. Abstracting shell differences to support cmd, WSL, and bash, including nested shell calls.
3. Abstracting parameter differences, where cmd uses %VAR% and bash uses $VAR.
|
reject
|
javascript
|
obgnail/typora_plugin
|
plugin/commander.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/commander.js
|
MIT
|
reject = data => {
this.entities.pre.textContent += data.toString();
this.entities.pre.classList.add("error");
}
|
Implementing this plugin requires three types of compatibility:
1. Abstracting operating system differences to support Windows and Linux.
2. Abstracting shell differences to support cmd, WSL, and bash, including nested shell calls.
3. Abstracting parameter differences, where cmd uses %VAR% and bash uses $VAR.
|
reject
|
javascript
|
obgnail/typora_plugin
|
plugin/commander.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/commander.js
|
MIT
|
constructor(plugin, formatBrushString) {
this.utils = plugin.utils
this.formatBrushObj = this.parseStyleString(formatBrushString)
}
|
This code contains workarounds and hacks to address specific behaviors of Typora.
Understanding the intricacies may be challenging. This documentation outlines the implementation logic for future modifications.
Core Idea: Simplify the problem by initially focusing on single-line selections.
1. Single-Line Selection Scenarios:
Consider the example: `123<span style="color:#FF0000;">abc</span>defg`
Four selection possibilities exist:
a. No selection.
b. Standard selection (e.g., "efg" - anything not covered by c and d).
c. Selection within an existing styled span (e.g., "abc").
d. Selection encompassing an entire styled span (e.g., `<span style="color:#FF0000;">abc</span>`).
2. Handling Simple Scenarios (a, b, and c):
a. No selection: Insert an empty styled span (`<span style="XXX"></span>`) at the cursor.
b. Standard selection: Wrap the selected text (e.g., "efg") with a styled span: `<span style="XXX">efg</span>`. Then, insert it back into the document.
c. Selection within a span: Transform the selection into scenario d. For example, "abc" becomes `<span style="color:#FF0000;">abc</span>`.
3. Handling Scenario d (Selecting an Existing Span):
a. Deconstruct the example `123<span style="color:#FF0000;">abc</span>defg` into:
- `beforeText`: "123" (Text before the span)
- `innerText`: "abc" (Text inside the span)
- `outerText`: `<span style="color:#FF0000;">abc</span>` (The entire span element)
- `styleObject`: A JavaScript object representing the CSS style of the span (e.g., `{ color: '#FF0000' }`)
b. Modify the `styleObject` as needed to apply the new styling.
c. Reconstruct the `outerText` using the updated `innerText` and `styleObject`. Insert this new `outerText` back into the document.
d. Use the `beforeText` and modified `styleObject` to determine the final position of the `innerText`.
Move the bookmark (selection) to correctly re-select the `innerText`.
e. The above steps are encapsulated in the `setInlineStyle` function.
4. Handling Multi-Line Selections:
When the user selects text across multiple lines and potentially multiple tags, the process involves:
a. Breaking the multi-line selection into individual lines.
b. Applying the `setInlineStyle` function to each line.
Implementation details for multi-line handling (`genRanges` function):
a. Use `TreeWalker` along with the `range` object's `commonAncestorContainer`, `startContainer`, and `endContainer` to get an array of all selected nodes (`nodeList`).
b. Filter out unnecessary text nodes within `<span md-inline="softbreak" class="md-softbreak"> </span>` tags (generated by shift+enter for soft line breaks).
c. Split the `nodeList` into lines based on `node.classList.contains("md-softbreak")` (soft breaks) and `!!node.getAttribute("cid")` (hard breaks).
Use `range.setStart(startContainer, startOffset)` and `range.setEnd(endContainer, endOffset)` to define the selection range for each line.
d. The `startContainer` and `endContainer` will be TEXT_NODEs. Filter out any ELEMENT_NODEs to get an array of lines (`selectLines`).
e. `selectLines` is a 2D array where each element is an array of TEXT_NODEs for a single line.
The `startContainer` and `endContainer` correspond to the first and last TEXT_NODEs of each line, respectively.
f. Special handling is required for the first and last lines, as they might not be fully selected.
g. After splitting, you'll have the `startContainer`, `startOffset`, `endContainer`, and `endOffset` for each individual line.
5. Addressing Typora's DOM Manipulation Issues:
Typora modifies the paragraph's `innerHTML` after inserting a span, invalidating the previously obtained TEXT_NODEs in the ranges. The solution is:
a. The `textContent` of the paragraph remains unchanged after the span insertion. Record the position of the old TEXT_NODEs in the document *before* inserting the span.
b. After Typora updates the DOM, use the recorded positions to find the *new* TEXT_NODEs.
c. Replace the old TEXT_NODEs with the new TEXT_NODEs in the ranges.
d. Now the (updated) TEXT_NODEs are valid. Proceed to call `setInlineStyle`.
e. The above process is implemented in `setMultilineStyle`. `recordTEXTPosition` handles the recording, and `renewRange` handles the replacement.
6. Overall Styling Process:
The main function `setStyle` orchestrates the entire process, calling `genRanges`, `setMultilineStyle`, and the helper functions as needed.
|
constructor
|
javascript
|
obgnail/typora_plugin
|
plugin/text_stylize.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/text_stylize.js
|
MIT
|
innerSelected = () => {
if (line.substring(bookmark.start, bookmark.end + suffix.length).endsWith(suffix)) {
const result = beforeText.match(/<span .*?>/g);
if (!result) return;
const last = result[result.length - 1];
if (last && beforeText.endsWith(last)) {
return last
}
}
}
|
There are four possible user selection scenarios, for example: `123<span style="color:#FF0000;">abc</span>defg`
a. No selection.
b. Standard selection (e.g., "efg").
c. Selection within an existing styled span (e.g., "abc"): Modify the outer text.
d. Selection encompassing an entire styled span (e.g., `<span style="color:#FF0000;">abc</span>`): Modify the inner text.
|
innerSelected
|
javascript
|
obgnail/typora_plugin
|
plugin/text_stylize.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/text_stylize.js
|
MIT
|
innerSelected = () => {
if (line.substring(bookmark.start, bookmark.end + suffix.length).endsWith(suffix)) {
const result = beforeText.match(/<span .*?>/g);
if (!result) return;
const last = result[result.length - 1];
if (last && beforeText.endsWith(last)) {
return last
}
}
}
|
There are four possible user selection scenarios, for example: `123<span style="color:#FF0000;">abc</span>defg`
a. No selection.
b. Standard selection (e.g., "efg").
c. Selection within an existing styled span (e.g., "abc"): Modify the outer text.
d. Selection encompassing an entire styled span (e.g., `<span style="color:#FF0000;">abc</span>`): Modify the inner text.
|
innerSelected
|
javascript
|
obgnail/typora_plugin
|
plugin/text_stylize.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/text_stylize.js
|
MIT
|
outerSelected = () => {
const result = innerText.match(matcher);
return result && result.groups && result.groups.wrapper;
}
|
There are four possible user selection scenarios, for example: `123<span style="color:#FF0000;">abc</span>defg`
a. No selection.
b. Standard selection (e.g., "efg").
c. Selection within an existing styled span (e.g., "abc"): Modify the outer text.
d. Selection encompassing an entire styled span (e.g., `<span style="color:#FF0000;">abc</span>`): Modify the inner text.
|
outerSelected
|
javascript
|
obgnail/typora_plugin
|
plugin/text_stylize.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/text_stylize.js
|
MIT
|
outerSelected = () => {
const result = innerText.match(matcher);
return result && result.groups && result.groups.wrapper;
}
|
There are four possible user selection scenarios, for example: `123<span style="color:#FF0000;">abc</span>defg`
a. No selection.
b. Standard selection (e.g., "efg").
c. Selection within an existing styled span (e.g., "abc"): Modify the outer text.
d. Selection encompassing an entire styled span (e.g., `<span style="color:#FF0000;">abc</span>`): Modify the inner text.
|
outerSelected
|
javascript
|
obgnail/typora_plugin
|
plugin/text_stylize.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/text_stylize.js
|
MIT
|
splitArray = (array, separatorFunc) => {
return array.reduce((acc, current) => {
if (separatorFunc(current)) {
acc.push([]);
} else {
if (acc.length === 0) {
acc.push([]);
}
acc[acc.length - 1].push(current);
}
return acc;
}, []);
}
|
There are four possible user selection scenarios, for example: `123<span style="color:#FF0000;">abc</span>defg`
a. No selection.
b. Standard selection (e.g., "efg").
c. Selection within an existing styled span (e.g., "abc"): Modify the outer text.
d. Selection encompassing an entire styled span (e.g., `<span style="color:#FF0000;">abc</span>`): Modify the inner text.
|
splitArray
|
javascript
|
obgnail/typora_plugin
|
plugin/text_stylize.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/text_stylize.js
|
MIT
|
splitArray = (array, separatorFunc) => {
return array.reduce((acc, current) => {
if (separatorFunc(current)) {
acc.push([]);
} else {
if (acc.length === 0) {
acc.push([]);
}
acc[acc.length - 1].push(current);
}
return acc;
}, []);
}
|
There are four possible user selection scenarios, for example: `123<span style="color:#FF0000;">abc</span>defg`
a. No selection.
b. Standard selection (e.g., "efg").
c. Selection within an existing styled span (e.g., "abc"): Modify the outer text.
d. Selection encompassing an entire styled span (e.g., `<span style="color:#FF0000;">abc</span>`): Modify the inner text.
|
splitArray
|
javascript
|
obgnail/typora_plugin
|
plugin/text_stylize.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/text_stylize.js
|
MIT
|
isEqualRange = (a, b) => (
a && b && a.startContainer === b.startContainer && a.startOffset === b.startOffset
&& a.endContainer === b.endContainer && a.endOffset === b.endOffset
)
|
There are four possible user selection scenarios, for example: `123<span style="color:#FF0000;">abc</span>defg`
a. No selection.
b. Standard selection (e.g., "efg").
c. Selection within an existing styled span (e.g., "abc"): Modify the outer text.
d. Selection encompassing an entire styled span (e.g., `<span style="color:#FF0000;">abc</span>`): Modify the inner text.
|
isEqualRange
|
javascript
|
obgnail/typora_plugin
|
plugin/text_stylize.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/text_stylize.js
|
MIT
|
isEqualRange = (a, b) => (
a && b && a.startContainer === b.startContainer && a.startOffset === b.startOffset
&& a.endContainer === b.endContainer && a.endOffset === b.endOffset
)
|
There are four possible user selection scenarios, for example: `123<span style="color:#FF0000;">abc</span>defg`
a. No selection.
b. Standard selection (e.g., "efg").
c. Selection within an existing styled span (e.g., "abc"): Modify the outer text.
d. Selection encompassing an entire styled span (e.g., `<span style="color:#FF0000;">abc</span>`): Modify the inner text.
|
isEqualRange
|
javascript
|
obgnail/typora_plugin
|
plugin/text_stylize.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/text_stylize.js
|
MIT
|
newRange = (startContainer, startOffset, endContainer, endOffset) => ({
startContainer, startOffset, endContainer, endOffset
})
|
There are four possible user selection scenarios, for example: `123<span style="color:#FF0000;">abc</span>defg`
a. No selection.
b. Standard selection (e.g., "efg").
c. Selection within an existing styled span (e.g., "abc"): Modify the outer text.
d. Selection encompassing an entire styled span (e.g., `<span style="color:#FF0000;">abc</span>`): Modify the inner text.
|
newRange
|
javascript
|
obgnail/typora_plugin
|
plugin/text_stylize.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/text_stylize.js
|
MIT
|
newRange = (startContainer, startOffset, endContainer, endOffset) => ({
startContainer, startOffset, endContainer, endOffset
})
|
There are four possible user selection scenarios, for example: `123<span style="color:#FF0000;">abc</span>defg`
a. No selection.
b. Standard selection (e.g., "efg").
c. Selection within an existing styled span (e.g., "abc"): Modify the outer text.
d. Selection encompassing an entire styled span (e.g., `<span style="color:#FF0000;">abc</span>`): Modify the inner text.
|
newRange
|
javascript
|
obgnail/typora_plugin
|
plugin/text_stylize.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/text_stylize.js
|
MIT
|
getTextNodes = node => {
if (node.nodeType === document.TEXT_NODE) {
textNodes.push(node);
} else if (node.nodeType === document.ELEMENT_NODE && (node.classList.contains("md-raw-inline") || node.classList.contains("md-softbreak"))) {
} else {
for (let i = 0; i < node.childNodes.length; i++) {
getTextNodes(node.childNodes[i]);
}
}
}
|
There are four possible user selection scenarios, for example: `123<span style="color:#FF0000;">abc</span>defg`
a. No selection.
b. Standard selection (e.g., "efg").
c. Selection within an existing styled span (e.g., "abc"): Modify the outer text.
d. Selection encompassing an entire styled span (e.g., `<span style="color:#FF0000;">abc</span>`): Modify the inner text.
|
getTextNodes
|
javascript
|
obgnail/typora_plugin
|
plugin/text_stylize.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/text_stylize.js
|
MIT
|
getTextNodes = node => {
if (node.nodeType === document.TEXT_NODE) {
textNodes.push(node);
} else if (node.nodeType === document.ELEMENT_NODE && (node.classList.contains("md-raw-inline") || node.classList.contains("md-softbreak"))) {
} else {
for (let i = 0; i < node.childNodes.length; i++) {
getTextNodes(node.childNodes[i]);
}
}
}
|
There are four possible user selection scenarios, for example: `123<span style="color:#FF0000;">abc</span>defg`
a. No selection.
b. Standard selection (e.g., "efg").
c. Selection within an existing styled span (e.g., "abc"): Modify the outer text.
d. Selection encompassing an entire styled span (e.g., `<span style="color:#FF0000;">abc</span>`): Modify the inner text.
|
getTextNodes
|
javascript
|
obgnail/typora_plugin
|
plugin/text_stylize.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/text_stylize.js
|
MIT
|
_getLatestVersion = async () => {
const resp = await this.utils.fetch(url, this.requestOption);
return resp.json()
}
|
Force update: skip the check and directly update using the URL.
|
_getLatestVersion
|
javascript
|
obgnail/typora_plugin
|
plugin/updater.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/updater.js
|
MIT
|
_getLatestVersion = async () => {
const resp = await this.utils.fetch(url, this.requestOption);
return resp.json()
}
|
Force update: skip the check and directly update using the URL.
|
_getLatestVersion
|
javascript
|
obgnail/typora_plugin
|
plugin/updater.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/updater.js
|
MIT
|
_getCurrentVersion = async () => {
try {
const exist = await this.utils.existPath(this.versionFile)
if (exist) {
return this.pkgFsExtra.readJson(this.versionFile);
}
} catch (e) {
console.debug("not exist version.json");
}
}
|
Force update: skip the check and directly update using the URL.
|
_getCurrentVersion
|
javascript
|
obgnail/typora_plugin
|
plugin/updater.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/updater.js
|
MIT
|
_getCurrentVersion = async () => {
try {
const exist = await this.utils.existPath(this.versionFile)
if (exist) {
return this.pkgFsExtra.readJson(this.versionFile);
}
} catch (e) {
console.debug("not exist version.json");
}
}
|
Force update: skip the check and directly update using the URL.
|
_getCurrentVersion
|
javascript
|
obgnail/typora_plugin
|
plugin/updater.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/updater.js
|
MIT
|
constructor(controller) {
this.utils = controller.utils
}
|
Force update: skip the check and directly update using the URL.
|
constructor
|
javascript
|
obgnail/typora_plugin
|
plugin/updater.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/updater.js
|
MIT
|
initGlobalVars = settings => {
// "global" is a general setting, not a plugin setting
Object.defineProperty(settings, "global", { enumerable: false })
global.BasePlugin = BasePlugin
global.BaseCustomPlugin = BaseCustomPlugin
global.LoadPlugins = LoadPlugins
global.__plugins__ = null
global.__plugin_utils__ = utils
global.__plugin_i18n__ = i18n
global.__plugin_settings__ = settings
}
|
Initializes global variables.
The plugin system exposes the following global variables, but only 3 are actually useful: BasePlugin, BaseCustomPlugin, and LoadPlugins.
The remaining variables are exposed by the static class `utils` and should never be referenced by business plugins.
Furthermore, `utils` is also an instance property of BasePlugin and BaseCustomPlugin, so `utils` itself doesn't need to be exposed.
Since they will never be referenced by business plugins, why are they set as global variables? Answer: For debugging convenience.
|
initGlobalVars
|
javascript
|
obgnail/typora_plugin
|
plugin/global/core/index.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/global/core/index.js
|
MIT
|
initGlobalVars = settings => {
// "global" is a general setting, not a plugin setting
Object.defineProperty(settings, "global", { enumerable: false })
global.BasePlugin = BasePlugin
global.BaseCustomPlugin = BaseCustomPlugin
global.LoadPlugins = LoadPlugins
global.__plugins__ = null
global.__plugin_utils__ = utils
global.__plugin_i18n__ = i18n
global.__plugin_settings__ = settings
}
|
Initializes global variables.
The plugin system exposes the following global variables, but only 3 are actually useful: BasePlugin, BaseCustomPlugin, and LoadPlugins.
The remaining variables are exposed by the static class `utils` and should never be referenced by business plugins.
Furthermore, `utils` is also an instance property of BasePlugin and BaseCustomPlugin, so `utils` itself doesn't need to be exposed.
Since they will never be referenced by business plugins, why are they set as global variables? Answer: For debugging convenience.
|
initGlobalVars
|
javascript
|
obgnail/typora_plugin
|
plugin/global/core/index.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/global/core/index.js
|
MIT
|
loadPlugins = async () => {
const { enable, disable, stop, error, nosetting } = await LoadPlugins(global.__plugin_settings__)
global.__plugins__ = enable
}
|
Initializes global variables.
The plugin system exposes the following global variables, but only 3 are actually useful: BasePlugin, BaseCustomPlugin, and LoadPlugins.
The remaining variables are exposed by the static class `utils` and should never be referenced by business plugins.
Furthermore, `utils` is also an instance property of BasePlugin and BaseCustomPlugin, so `utils` itself doesn't need to be exposed.
Since they will never be referenced by business plugins, why are they set as global variables? Answer: For debugging convenience.
|
loadPlugins
|
javascript
|
obgnail/typora_plugin
|
plugin/global/core/index.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/global/core/index.js
|
MIT
|
loadPlugins = async () => {
const { enable, disable, stop, error, nosetting } = await LoadPlugins(global.__plugin_settings__)
global.__plugins__ = enable
}
|
Initializes global variables.
The plugin system exposes the following global variables, but only 3 are actually useful: BasePlugin, BaseCustomPlugin, and LoadPlugins.
The remaining variables are exposed by the static class `utils` and should never be referenced by business plugins.
Furthermore, `utils` is also an instance property of BasePlugin and BaseCustomPlugin, so `utils` itself doesn't need to be exposed.
Since they will never be referenced by business plugins, why are they set as global variables? Answer: For debugging convenience.
|
loadPlugins
|
javascript
|
obgnail/typora_plugin
|
plugin/global/core/index.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/global/core/index.js
|
MIT
|
warn = () => {
const incompatible = utils.compareVersion(utils.typoraVersion, "0.9.98") < 0
if (incompatible) {
const msg = i18n.t("global", "incompatibilityWarning")
utils.notification.show(msg, "warning", 5000)
}
}
|
For Typora versions below 0.9.98, a compatibility warning is issued when running the plugin system.
|
warn
|
javascript
|
obgnail/typora_plugin
|
plugin/global/core/index.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/global/core/index.js
|
MIT
|
warn = () => {
const incompatible = utils.compareVersion(utils.typoraVersion, "0.9.98") < 0
if (incompatible) {
const msg = i18n.t("global", "incompatibilityWarning")
utils.notification.show(msg, "warning", 5000)
}
}
|
For Typora versions below 0.9.98, a compatibility warning is issued when running the plugin system.
|
warn
|
javascript
|
obgnail/typora_plugin
|
plugin/global/core/index.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/global/core/index.js
|
MIT
|
LoadPlugin = async (fixedName, setting, isBasePlugin) => {
const path = isBasePlugin ? "./plugin" : "./plugin/custom/plugins"
const { plugin } = utils.requireFilePath(path, fixedName)
if (!plugin) {
return new Error(`There is not ${fixedName} in ${path}`)
}
const instance = new plugin(fixedName, setting, i18n.bind(fixedName))
const error = await instance.beforeProcess()
if (error === utils.stopLoadPluginError) {
return
}
utils.registerStyle(instance.fixedName, instance.style())
const renderArgs = instance.styleTemplate()
if (renderArgs) {
await utils.styleTemplater.register(instance.fixedName, { ...renderArgs, this: instance })
}
utils.insertElement(instance.html())
if (isBasePlugin) {
utils.hotkeyHub.register(instance.hotkey())
}
instance.init()
instance.process()
instance.afterProcess()
return instance
}
|
Cleanup, generally used for memory reclamation, used infrequently.
|
LoadPlugin
|
javascript
|
obgnail/typora_plugin
|
plugin/global/core/plugin.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/global/core/plugin.js
|
MIT
|
LoadPlugin = async (fixedName, setting, isBasePlugin) => {
const path = isBasePlugin ? "./plugin" : "./plugin/custom/plugins"
const { plugin } = utils.requireFilePath(path, fixedName)
if (!plugin) {
return new Error(`There is not ${fixedName} in ${path}`)
}
const instance = new plugin(fixedName, setting, i18n.bind(fixedName))
const error = await instance.beforeProcess()
if (error === utils.stopLoadPluginError) {
return
}
utils.registerStyle(instance.fixedName, instance.style())
const renderArgs = instance.styleTemplate()
if (renderArgs) {
await utils.styleTemplater.register(instance.fixedName, { ...renderArgs, this: instance })
}
utils.insertElement(instance.html())
if (isBasePlugin) {
utils.hotkeyHub.register(instance.hotkey())
}
instance.init()
instance.process()
instance.afterProcess()
return instance
}
|
Cleanup, generally used for memory reclamation, used infrequently.
|
LoadPlugin
|
javascript
|
obgnail/typora_plugin
|
plugin/global/core/plugin.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/global/core/plugin.js
|
MIT
|
LoadPlugins = async (settings) => {
const isBase = settings.hasOwnProperty("global")
const plugins = { enable: {}, disable: {}, stop: {}, error: {}, nosetting: {} }
const promises = Object.entries(settings).map(async ([fixedName, setting]) => {
if (!setting) {
plugins.nosetting[fixedName] = fixedName
} else if (!setting.ENABLE && !setting.enable) {
plugins.disable[fixedName] = setting
} else {
try {
const instance = await LoadPlugin(fixedName, setting, isBase)
if (instance) {
plugins.enable[fixedName] = instance
} else {
plugins.stop[fixedName] = setting
}
} catch (error) {
console.error(error)
plugins.error[fixedName] = error
}
}
})
await Promise.all(promises)
// log
const COLORS = { enable: "32", disable: "33", stop: "34", error: "31", nosetting: "35" }
console.group(`${isBase ? "Base" : "Custom"} Plugin`)
Object.entries(plugins).forEach(([t, p]) => console.debug(`[ \x1B[${COLORS[t]}m${t}\x1b[0m ] [ ${Object.keys(p).length} ]:`, p))
console.groupEnd()
return plugins
}
|
Cleanup, generally used for memory reclamation, used infrequently.
|
LoadPlugins
|
javascript
|
obgnail/typora_plugin
|
plugin/global/core/plugin.js
|
https://github.com/obgnail/typora_plugin/blob/master/plugin/global/core/plugin.js
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.