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
function getCurrentScope() { return activeEffectScope; }
This should only be called on non-detached scopes @internal
getCurrentScope
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
function onScopeDispose(fn) { if (activeEffectScope) { activeEffectScope.cleanups.push(fn); } else { warn$2( `onScopeDispose() is called when there is no active effect scope to be associated with.` ); } }
This should only be called on non-detached scopes @internal
onScopeDispose
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
constructor(fn, trigger, scheduler, scope) { this.fn = fn; this.trigger = trigger; this.scheduler = scheduler; this.active = true; this.deps = []; /** * @internal */ this._dirtyLevel = 3; /** * @internal */ this._trackId = 0; /** * @internal */ this._runnings = 0; /** * @internal */ this._queryings = 0; /** * @internal */ this._depsLength = 0; recordEffectScope(this, scope); }
This should only be called on non-detached scopes @internal
constructor
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
_resolveDef() { this._resolved = true; for (let i = 0; i < this.attributes.length; i++) { this._setAttr(this.attributes[i].name); } this._ob = new MutationObserver((mutations) => { for (const m of mutations) { this._setAttr(m.attributeName); } }); this._ob.observe(this, { attributes: true }); const resolve = (def, isAsync = false) => { const { props, styles } = def; let numberProps; if (props && !isArray(props)) { for (const key in props) { const opt = props[key]; if (opt === Number || opt && opt.type === Number) { if (key in this._props) { this._props[key] = toNumber(this._props[key]); } (numberProps || (numberProps = /* @__PURE__ */ Object.create(null)))[camelize(key)] = true; } } } this._numberProps = numberProps; if (isAsync) { this._resolveProps(def); } this._applyStyles(styles); this._update(); }; const asyncDef = this._def.__asyncLoader; if (asyncDef) { asyncDef().then((def) => resolve(def, true)); } else { resolve(this._def); } }
resolve inner component definition (handle possible async component)
_resolveDef
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
resolve = (def, isAsync = false) => { const { props, styles } = def; let numberProps; if (props && !isArray(props)) { for (const key in props) { const opt = props[key]; if (opt === Number || opt && opt.type === Number) { if (key in this._props) { this._props[key] = toNumber(this._props[key]); } (numberProps || (numberProps = /* @__PURE__ */ Object.create(null)))[camelize(key)] = true; } } } this._numberProps = numberProps; if (isAsync) { this._resolveProps(def); } this._applyStyles(styles); this._update(); }
resolve inner component definition (handle possible async component)
resolve
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
resolve = (def, isAsync = false) => { const { props, styles } = def; let numberProps; if (props && !isArray(props)) { for (const key in props) { const opt = props[key]; if (opt === Number || opt && opt.type === Number) { if (key in this._props) { this._props[key] = toNumber(this._props[key]); } (numberProps || (numberProps = /* @__PURE__ */ Object.create(null)))[camelize(key)] = true; } } } this._numberProps = numberProps; if (isAsync) { this._resolveProps(def); } this._applyStyles(styles); this._update(); }
resolve inner component definition (handle possible async component)
resolve
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
_resolveProps(def) { const { props } = def; const declaredPropKeys = isArray(props) ? props : Object.keys(props || {}); for (const key of Object.keys(this)) { if (key[0] !== "_" && declaredPropKeys.includes(key)) { this._setProp(key, this[key], true, false); } } for (const key of declaredPropKeys.map(camelize)) { Object.defineProperty(this, key, { get() { return this._getProp(key); }, set(val) { this._setProp(key, val); } }); } }
resolve inner component definition (handle possible async component)
_resolveProps
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
get() { return this._getProp(key); }
resolve inner component definition (handle possible async component)
get
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
set(val) { this._setProp(key, val); }
resolve inner component definition (handle possible async component)
set
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
_setAttr(key) { let value = this.getAttribute(key); const camelKey = camelize(key); if (this._numberProps && this._numberProps[camelKey]) { value = toNumber(value); } this._setProp(camelKey, value, false); }
resolve inner component definition (handle possible async component)
_setAttr
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
get inSFCRoot() { return this.mode === 2 && this.stack.length === 0; }
Record newline positions for fast line / column calculation
inSFCRoot
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
reset() { this.state = 1; this.mode = 0; this.buffer = ""; this.sectionStart = 0; this.index = 0; this.baseState = 1; this.inRCDATA = false; this.currentSequence = void 0; this.newlines.length = 0; this.delimiterOpen = defaultDelimitersOpen; this.delimiterClose = defaultDelimitersClose; }
Record newline positions for fast line / column calculation
reset
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
getPos(index) { let line = 1; let column = index + 1; for (let i = this.newlines.length - 1; i >= 0; i--) { const newlineIndex = this.newlines[i]; if (index > newlineIndex) { line = i + 2; column = index - newlineIndex; break; } } return { column, line, offset: index }; }
Generate Position object with line / column information using recorded newline positions. We know the index is always going to be an already processed index, so all the newlines up to this index should have been recorded.
getPos
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
peek() { return this.buffer.charCodeAt(this.index + 1); }
Generate Position object with line / column information using recorded newline positions. We know the index is always going to be an already processed index, so all the newlines up to this index should have been recorded.
peek
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
stateText(c) { if (c === 60) { if (this.index > this.sectionStart) { this.cbs.ontext(this.sectionStart, this.index); } this.state = 5; this.sectionStart = this.index; } else if (!this.inVPre && c === this.delimiterOpen[0]) { this.state = 2; this.delimiterIndex = 0; this.stateInterpolationOpen(c); } }
Generate Position object with line / column information using recorded newline positions. We know the index is always going to be an already processed index, so all the newlines up to this index should have been recorded.
stateText
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
stateInterpolationOpen(c) { if (c === this.delimiterOpen[this.delimiterIndex]) { if (this.delimiterIndex === this.delimiterOpen.length - 1) { const start = this.index + 1 - this.delimiterOpen.length; if (start > this.sectionStart) { this.cbs.ontext(this.sectionStart, start); } this.state = 3; this.sectionStart = start; } else { this.delimiterIndex++; } } else if (this.inRCDATA) { this.state = 32; this.stateInRCDATA(c); } else { this.state = 1; this.stateText(c); } }
Generate Position object with line / column information using recorded newline positions. We know the index is always going to be an already processed index, so all the newlines up to this index should have been recorded.
stateInterpolationOpen
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
stateInterpolation(c) { if (c === this.delimiterClose[0]) { this.state = 4; this.delimiterIndex = 0; this.stateInterpolationClose(c); } }
Generate Position object with line / column information using recorded newline positions. We know the index is always going to be an already processed index, so all the newlines up to this index should have been recorded.
stateInterpolation
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
stateInterpolationClose(c) { if (c === this.delimiterClose[this.delimiterIndex]) { if (this.delimiterIndex === this.delimiterClose.length - 1) { this.cbs.oninterpolation(this.sectionStart, this.index + 1); if (this.inRCDATA) { this.state = 32; } else { this.state = 1; } this.sectionStart = this.index + 1; } else { this.delimiterIndex++; } } else { this.state = 3; this.stateInterpolation(c); } }
Generate Position object with line / column information using recorded newline positions. We know the index is always going to be an already processed index, so all the newlines up to this index should have been recorded.
stateInterpolationClose
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
stateSpecialStartSequence(c) { const isEnd = this.sequenceIndex === this.currentSequence.length; const isMatch = isEnd ? ( // If we are at the end of the sequence, make sure the tag name has ended isEndOfTagSection(c) ) : ( // Otherwise, do a case-insensitive comparison (c | 32) === this.currentSequence[this.sequenceIndex] ); if (!isMatch) { this.inRCDATA = false; } else if (!isEnd) { this.sequenceIndex++; return; } this.sequenceIndex = 0; this.state = 6; this.stateInTagName(c); }
Generate Position object with line / column information using recorded newline positions. We know the index is always going to be an already processed index, so all the newlines up to this index should have been recorded.
stateSpecialStartSequence
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
stateInRCDATA(c) { if (this.sequenceIndex === this.currentSequence.length) { if (c === 62 || isWhitespace(c)) { const endOfText = this.index - this.currentSequence.length; if (this.sectionStart < endOfText) { const actualIndex = this.index; this.index = endOfText; this.cbs.ontext(this.sectionStart, endOfText); this.index = actualIndex; } this.sectionStart = endOfText + 2; this.stateInClosingTagName(c); this.inRCDATA = false; return; } this.sequenceIndex = 0; } if ((c | 32) === this.currentSequence[this.sequenceIndex]) { this.sequenceIndex += 1; } else if (this.sequenceIndex === 0) { if (this.currentSequence === Sequences.TitleEnd || this.currentSequence === Sequences.TextareaEnd && !this.inSFCRoot) { if (c === this.delimiterOpen[0]) { this.state = 2; this.delimiterIndex = 0; this.stateInterpolationOpen(c); } } else if (this.fastForwardTo(60)) { this.sequenceIndex = 1; } } else { this.sequenceIndex = Number(c === 60); } }
Look for an end tag. For <title> and <textarea>, also decode entities.
stateInRCDATA
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
stateCDATASequence(c) { if (c === Sequences.Cdata[this.sequenceIndex]) { if (++this.sequenceIndex === Sequences.Cdata.length) { this.state = 28; this.currentSequence = Sequences.CdataEnd; this.sequenceIndex = 0; this.sectionStart = this.index + 1; } } else { this.sequenceIndex = 0; this.state = 23; this.stateInDeclaration(c); } }
Look for an end tag. For <title> and <textarea>, also decode entities.
stateCDATASequence
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
fastForwardTo(c) { while (++this.index < this.buffer.length) { const cc = this.buffer.charCodeAt(this.index); if (cc === 10) { this.newlines.push(this.index); } if (cc === c) { return true; } } this.index = this.buffer.length - 1; return false; }
When we wait for one specific character, we can speed things up by skipping through the buffer until we find it. @returns Whether the character was found.
fastForwardTo
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
stateInCommentLike(c) { if (c === this.currentSequence[this.sequenceIndex]) { if (++this.sequenceIndex === this.currentSequence.length) { if (this.currentSequence === Sequences.CdataEnd) { this.cbs.oncdata(this.sectionStart, this.index - 2); } else { this.cbs.oncomment(this.sectionStart, this.index - 2); } this.sequenceIndex = 0; this.sectionStart = this.index + 1; this.state = 1; } } else if (this.sequenceIndex === 0) { if (this.fastForwardTo(this.currentSequence[0])) { this.sequenceIndex = 1; } } else if (c !== this.currentSequence[this.sequenceIndex - 1]) { this.sequenceIndex = 0; } }
Comments and CDATA end with `-->` and `]]>`. Their common qualities are: - Their end sequences have a distinct character they start with. - That character is then repeated, so we have to check multiple repeats. - All characters but the start character of the sequence can be skipped.
stateInCommentLike
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
startSpecial(sequence, offset) { this.enterRCDATA(sequence, offset); this.state = 31; }
Comments and CDATA end with `-->` and `]]>`. Their common qualities are: - Their end sequences have a distinct character they start with. - That character is then repeated, so we have to check multiple repeats. - All characters but the start character of the sequence can be skipped.
startSpecial
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
enterRCDATA(sequence, offset) { this.inRCDATA = true; this.currentSequence = sequence; this.sequenceIndex = offset; }
Comments and CDATA end with `-->` and `]]>`. Their common qualities are: - Their end sequences have a distinct character they start with. - That character is then repeated, so we have to check multiple repeats. - All characters but the start character of the sequence can be skipped.
enterRCDATA
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
stateBeforeTagName(c) { if (c === 33) { this.state = 22; this.sectionStart = this.index + 1; } else if (c === 63) { this.state = 24; this.sectionStart = this.index + 1; } else if (isTagStartChar(c)) { this.sectionStart = this.index; if (this.mode === 0) { this.state = 6; } else if (this.inSFCRoot) { this.state = 34; } else if (!this.inXML) { const lower = c | 32; if (lower === 116) { this.state = 30; } else { this.state = lower === 115 ? 29 : 6; } } else { this.state = 6; } } else if (c === 47) { this.state = 8; } else { this.state = 1; this.stateText(c); } }
Comments and CDATA end with `-->` and `]]>`. Their common qualities are: - Their end sequences have a distinct character they start with. - That character is then repeated, so we have to check multiple repeats. - All characters but the start character of the sequence can be skipped.
stateBeforeTagName
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
stateInTagName(c) { if (isEndOfTagSection(c)) { this.handleTagName(c); } }
Comments and CDATA end with `-->` and `]]>`. Their common qualities are: - Their end sequences have a distinct character they start with. - That character is then repeated, so we have to check multiple repeats. - All characters but the start character of the sequence can be skipped.
stateInTagName
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
stateInSFCRootTagName(c) { if (isEndOfTagSection(c)) { const tag = this.buffer.slice(this.sectionStart, this.index); if (tag !== "template") { this.enterRCDATA(toCharCodes(`</` + tag), 0); } this.handleTagName(c); } }
Comments and CDATA end with `-->` and `]]>`. Their common qualities are: - Their end sequences have a distinct character they start with. - That character is then repeated, so we have to check multiple repeats. - All characters but the start character of the sequence can be skipped.
stateInSFCRootTagName
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
handleTagName(c) { this.cbs.onopentagname(this.sectionStart, this.index); this.sectionStart = -1; this.state = 11; this.stateBeforeAttrName(c); }
Comments and CDATA end with `-->` and `]]>`. Their common qualities are: - Their end sequences have a distinct character they start with. - That character is then repeated, so we have to check multiple repeats. - All characters but the start character of the sequence can be skipped.
handleTagName
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
stateBeforeClosingTagName(c) { if (isWhitespace(c)) ; else if (c === 62) { { this.cbs.onerr(14, this.index); } this.state = 1; this.sectionStart = this.index + 1; } else { this.state = isTagStartChar(c) ? 9 : 27; this.sectionStart = this.index; } }
Comments and CDATA end with `-->` and `]]>`. Their common qualities are: - Their end sequences have a distinct character they start with. - That character is then repeated, so we have to check multiple repeats. - All characters but the start character of the sequence can be skipped.
stateBeforeClosingTagName
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
stateInClosingTagName(c) { if (c === 62 || isWhitespace(c)) { this.cbs.onclosetag(this.sectionStart, this.index); this.sectionStart = -1; this.state = 10; this.stateAfterClosingTagName(c); } }
Comments and CDATA end with `-->` and `]]>`. Their common qualities are: - Their end sequences have a distinct character they start with. - That character is then repeated, so we have to check multiple repeats. - All characters but the start character of the sequence can be skipped.
stateInClosingTagName
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
stateAfterClosingTagName(c) { if (c === 62) { this.state = 1; this.sectionStart = this.index + 1; } }
Comments and CDATA end with `-->` and `]]>`. Their common qualities are: - Their end sequences have a distinct character they start with. - That character is then repeated, so we have to check multiple repeats. - All characters but the start character of the sequence can be skipped.
stateAfterClosingTagName
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
stateBeforeAttrName(c) { if (c === 62) { this.cbs.onopentagend(this.index); if (this.inRCDATA) { this.state = 32; } else { this.state = 1; } this.sectionStart = this.index + 1; } else if (c === 47) { this.state = 7; if (this.peek() !== 62) { this.cbs.onerr(22, this.index); } } else if (c === 60 && this.peek() === 47) { this.cbs.onopentagend(this.index); this.state = 5; this.sectionStart = this.index; } else if (!isWhitespace(c)) { if (c === 61) { this.cbs.onerr( 19, this.index ); } this.handleAttrStart(c); } }
Comments and CDATA end with `-->` and `]]>`. Their common qualities are: - Their end sequences have a distinct character they start with. - That character is then repeated, so we have to check multiple repeats. - All characters but the start character of the sequence can be skipped.
stateBeforeAttrName
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
handleAttrStart(c) { if (c === 118 && this.peek() === 45) { this.state = 13; this.sectionStart = this.index; } else if (c === 46 || c === 58 || c === 64 || c === 35) { this.cbs.ondirname(this.index, this.index + 1); this.state = 14; this.sectionStart = this.index + 1; } else { this.state = 12; this.sectionStart = this.index; } }
Comments and CDATA end with `-->` and `]]>`. Their common qualities are: - Their end sequences have a distinct character they start with. - That character is then repeated, so we have to check multiple repeats. - All characters but the start character of the sequence can be skipped.
handleAttrStart
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
stateInSelfClosingTag(c) { if (c === 62) { this.cbs.onselfclosingtag(this.index); this.state = 1; this.sectionStart = this.index + 1; this.inRCDATA = false; } else if (!isWhitespace(c)) { this.state = 11; this.stateBeforeAttrName(c); } }
Comments and CDATA end with `-->` and `]]>`. Their common qualities are: - Their end sequences have a distinct character they start with. - That character is then repeated, so we have to check multiple repeats. - All characters but the start character of the sequence can be skipped.
stateInSelfClosingTag
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
stateInAttrName(c) { if (c === 61 || isEndOfTagSection(c)) { this.cbs.onattribname(this.sectionStart, this.index); this.handleAttrNameEnd(c); } else if (c === 34 || c === 39 || c === 60) { this.cbs.onerr( 17, this.index ); } }
Comments and CDATA end with `-->` and `]]>`. Their common qualities are: - Their end sequences have a distinct character they start with. - That character is then repeated, so we have to check multiple repeats. - All characters but the start character of the sequence can be skipped.
stateInAttrName
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
stateInDirName(c) { if (c === 61 || isEndOfTagSection(c)) { this.cbs.ondirname(this.sectionStart, this.index); this.handleAttrNameEnd(c); } else if (c === 58) { this.cbs.ondirname(this.sectionStart, this.index); this.state = 14; this.sectionStart = this.index + 1; } else if (c === 46) { this.cbs.ondirname(this.sectionStart, this.index); this.state = 16; this.sectionStart = this.index + 1; } }
Comments and CDATA end with `-->` and `]]>`. Their common qualities are: - Their end sequences have a distinct character they start with. - That character is then repeated, so we have to check multiple repeats. - All characters but the start character of the sequence can be skipped.
stateInDirName
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
stateInDirArg(c) { if (c === 61 || isEndOfTagSection(c)) { this.cbs.ondirarg(this.sectionStart, this.index); this.handleAttrNameEnd(c); } else if (c === 91) { this.state = 15; } else if (c === 46) { this.cbs.ondirarg(this.sectionStart, this.index); this.state = 16; this.sectionStart = this.index + 1; } }
Comments and CDATA end with `-->` and `]]>`. Their common qualities are: - Their end sequences have a distinct character they start with. - That character is then repeated, so we have to check multiple repeats. - All characters but the start character of the sequence can be skipped.
stateInDirArg
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
stateInDynamicDirArg(c) { if (c === 93) { this.state = 14; } else if (c === 61 || isEndOfTagSection(c)) { this.cbs.ondirarg(this.sectionStart, this.index + 1); this.handleAttrNameEnd(c); { this.cbs.onerr( 27, this.index ); } } }
Comments and CDATA end with `-->` and `]]>`. Their common qualities are: - Their end sequences have a distinct character they start with. - That character is then repeated, so we have to check multiple repeats. - All characters but the start character of the sequence can be skipped.
stateInDynamicDirArg
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
stateInDirModifier(c) { if (c === 61 || isEndOfTagSection(c)) { this.cbs.ondirmodifier(this.sectionStart, this.index); this.handleAttrNameEnd(c); } else if (c === 46) { this.cbs.ondirmodifier(this.sectionStart, this.index); this.sectionStart = this.index + 1; } }
Comments and CDATA end with `-->` and `]]>`. Their common qualities are: - Their end sequences have a distinct character they start with. - That character is then repeated, so we have to check multiple repeats. - All characters but the start character of the sequence can be skipped.
stateInDirModifier
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
handleAttrNameEnd(c) { this.sectionStart = this.index; this.state = 17; this.cbs.onattribnameend(this.index); this.stateAfterAttrName(c); }
Comments and CDATA end with `-->` and `]]>`. Their common qualities are: - Their end sequences have a distinct character they start with. - That character is then repeated, so we have to check multiple repeats. - All characters but the start character of the sequence can be skipped.
handleAttrNameEnd
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
stateAfterAttrName(c) { if (c === 61) { this.state = 18; } else if (c === 47 || c === 62) { this.cbs.onattribend(0, this.sectionStart); this.sectionStart = -1; this.state = 11; this.stateBeforeAttrName(c); } else if (!isWhitespace(c)) { this.cbs.onattribend(0, this.sectionStart); this.handleAttrStart(c); } }
Comments and CDATA end with `-->` and `]]>`. Their common qualities are: - Their end sequences have a distinct character they start with. - That character is then repeated, so we have to check multiple repeats. - All characters but the start character of the sequence can be skipped.
stateAfterAttrName
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
stateBeforeAttrValue(c) { if (c === 34) { this.state = 19; this.sectionStart = this.index + 1; } else if (c === 39) { this.state = 20; this.sectionStart = this.index + 1; } else if (!isWhitespace(c)) { this.sectionStart = this.index; this.state = 21; this.stateInAttrValueNoQuotes(c); } }
Comments and CDATA end with `-->` and `]]>`. Their common qualities are: - Their end sequences have a distinct character they start with. - That character is then repeated, so we have to check multiple repeats. - All characters but the start character of the sequence can be skipped.
stateBeforeAttrValue
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
handleInAttrValue(c, quote) { if (c === quote || this.fastForwardTo(quote)) { this.cbs.onattribdata(this.sectionStart, this.index); this.sectionStart = -1; this.cbs.onattribend( quote === 34 ? 3 : 2, this.index + 1 ); this.state = 11; } }
Comments and CDATA end with `-->` and `]]>`. Their common qualities are: - Their end sequences have a distinct character they start with. - That character is then repeated, so we have to check multiple repeats. - All characters but the start character of the sequence can be skipped.
handleInAttrValue
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
stateInAttrValueDoubleQuotes(c) { this.handleInAttrValue(c, 34); }
Comments and CDATA end with `-->` and `]]>`. Their common qualities are: - Their end sequences have a distinct character they start with. - That character is then repeated, so we have to check multiple repeats. - All characters but the start character of the sequence can be skipped.
stateInAttrValueDoubleQuotes
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
stateInAttrValueSingleQuotes(c) { this.handleInAttrValue(c, 39); }
Comments and CDATA end with `-->` and `]]>`. Their common qualities are: - Their end sequences have a distinct character they start with. - That character is then repeated, so we have to check multiple repeats. - All characters but the start character of the sequence can be skipped.
stateInAttrValueSingleQuotes
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
stateInAttrValueNoQuotes(c) { if (isWhitespace(c) || c === 62) { this.cbs.onattribdata(this.sectionStart, this.index); this.sectionStart = -1; this.cbs.onattribend(1, this.index); this.state = 11; this.stateBeforeAttrName(c); } else if (c === 34 || c === 39 || c === 60 || c === 61 || c === 96) { this.cbs.onerr( 18, this.index ); } else ; }
Comments and CDATA end with `-->` and `]]>`. Their common qualities are: - Their end sequences have a distinct character they start with. - That character is then repeated, so we have to check multiple repeats. - All characters but the start character of the sequence can be skipped.
stateInAttrValueNoQuotes
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
stateBeforeDeclaration(c) { if (c === 91) { this.state = 26; this.sequenceIndex = 0; } else { this.state = c === 45 ? 25 : 23; } }
Comments and CDATA end with `-->` and `]]>`. Their common qualities are: - Their end sequences have a distinct character they start with. - That character is then repeated, so we have to check multiple repeats. - All characters but the start character of the sequence can be skipped.
stateBeforeDeclaration
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
stateInDeclaration(c) { if (c === 62 || this.fastForwardTo(62)) { this.state = 1; this.sectionStart = this.index + 1; } }
Comments and CDATA end with `-->` and `]]>`. Their common qualities are: - Their end sequences have a distinct character they start with. - That character is then repeated, so we have to check multiple repeats. - All characters but the start character of the sequence can be skipped.
stateInDeclaration
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
stateInProcessingInstruction(c) { if (c === 62 || this.fastForwardTo(62)) { this.cbs.onprocessinginstruction(this.sectionStart, this.index); this.state = 1; this.sectionStart = this.index + 1; } }
Comments and CDATA end with `-->` and `]]>`. Their common qualities are: - Their end sequences have a distinct character they start with. - That character is then repeated, so we have to check multiple repeats. - All characters but the start character of the sequence can be skipped.
stateInProcessingInstruction
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
stateBeforeComment(c) { if (c === 45) { this.state = 28; this.currentSequence = Sequences.CommentEnd; this.sequenceIndex = 2; this.sectionStart = this.index + 1; } else { this.state = 23; } }
Comments and CDATA end with `-->` and `]]>`. Their common qualities are: - Their end sequences have a distinct character they start with. - That character is then repeated, so we have to check multiple repeats. - All characters but the start character of the sequence can be skipped.
stateBeforeComment
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
stateInSpecialComment(c) { if (c === 62 || this.fastForwardTo(62)) { this.cbs.oncomment(this.sectionStart, this.index); this.state = 1; this.sectionStart = this.index + 1; } }
Comments and CDATA end with `-->` and `]]>`. Their common qualities are: - Their end sequences have a distinct character they start with. - That character is then repeated, so we have to check multiple repeats. - All characters but the start character of the sequence can be skipped.
stateInSpecialComment
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
stateBeforeSpecialS(c) { const lower = c | 32; if (lower === Sequences.ScriptEnd[3]) { this.startSpecial(Sequences.ScriptEnd, 4); } else if (lower === Sequences.StyleEnd[3]) { this.startSpecial(Sequences.StyleEnd, 4); } else { this.state = 6; this.stateInTagName(c); } }
Comments and CDATA end with `-->` and `]]>`. Their common qualities are: - Their end sequences have a distinct character they start with. - That character is then repeated, so we have to check multiple repeats. - All characters but the start character of the sequence can be skipped.
stateBeforeSpecialS
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
stateBeforeSpecialT(c) { const lower = c | 32; if (lower === Sequences.TitleEnd[3]) { this.startSpecial(Sequences.TitleEnd, 4); } else if (lower === Sequences.TextareaEnd[3]) { this.startSpecial(Sequences.TextareaEnd, 4); } else { this.state = 6; this.stateInTagName(c); } }
Comments and CDATA end with `-->` and `]]>`. Their common qualities are: - Their end sequences have a distinct character they start with. - That character is then repeated, so we have to check multiple repeats. - All characters but the start character of the sequence can be skipped.
stateBeforeSpecialT
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
parse(input) { this.buffer = input; while (this.index < this.buffer.length) { const c = this.buffer.charCodeAt(this.index); if (c === 10) { this.newlines.push(this.index); } switch (this.state) { case 1: { this.stateText(c); break; } case 2: { this.stateInterpolationOpen(c); break; } case 3: { this.stateInterpolation(c); break; } case 4: { this.stateInterpolationClose(c); break; } case 31: { this.stateSpecialStartSequence(c); break; } case 32: { this.stateInRCDATA(c); break; } case 26: { this.stateCDATASequence(c); break; } case 19: { this.stateInAttrValueDoubleQuotes(c); break; } case 12: { this.stateInAttrName(c); break; } case 13: { this.stateInDirName(c); break; } case 14: { this.stateInDirArg(c); break; } case 15: { this.stateInDynamicDirArg(c); break; } case 16: { this.stateInDirModifier(c); break; } case 28: { this.stateInCommentLike(c); break; } case 27: { this.stateInSpecialComment(c); break; } case 11: { this.stateBeforeAttrName(c); break; } case 6: { this.stateInTagName(c); break; } case 34: { this.stateInSFCRootTagName(c); break; } case 9: { this.stateInClosingTagName(c); break; } case 5: { this.stateBeforeTagName(c); break; } case 17: { this.stateAfterAttrName(c); break; } case 20: { this.stateInAttrValueSingleQuotes(c); break; } case 18: { this.stateBeforeAttrValue(c); break; } case 8: { this.stateBeforeClosingTagName(c); break; } case 10: { this.stateAfterClosingTagName(c); break; } case 29: { this.stateBeforeSpecialS(c); break; } case 30: { this.stateBeforeSpecialT(c); break; } case 21: { this.stateInAttrValueNoQuotes(c); break; } case 7: { this.stateInSelfClosingTag(c); break; } case 23: { this.stateInDeclaration(c); break; } case 22: { this.stateBeforeDeclaration(c); break; } case 25: { this.stateBeforeComment(c); break; } case 24: { this.stateInProcessingInstruction(c); break; } case 33: { this.stateInEntity(); break; } } this.index++; } this.cleanup(); this.finish(); }
Iterates through the buffer, calling the function corresponding to the current state. States that are more likely to be hit are higher up, as a performance improvement.
parse
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
cleanup() { if (this.sectionStart !== this.index) { if (this.state === 1 || this.state === 32 && this.sequenceIndex === 0) { this.cbs.ontext(this.sectionStart, this.index); this.sectionStart = this.index; } else if (this.state === 19 || this.state === 20 || this.state === 21) { this.cbs.onattribdata(this.sectionStart, this.index); this.sectionStart = this.index; } } }
Remove data that has already been consumed from the buffer.
cleanup
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
finish() { this.handleTrailingData(); this.cbs.onend(); }
Remove data that has already been consumed from the buffer.
finish
javascript
icai/vue3-calendar
lib/calendar.js
https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js
MIT
function removeRipple(e, el, ripple) { // Check if the ripple still exist if (!ripple) { return; } ripple.classList.remove('waves-rippling'); var relativeX = ripple.getAttribute('data-x'); var relativeY = ripple.getAttribute('data-y'); var scale = ripple.getAttribute('data-scale'); var translate = ripple.getAttribute('data-translate'); // Get delay beetween mousedown and mouse leave var diff = Date.now() - Number(ripple.getAttribute('data-hold')); var delay = 350 - diff; if (delay < 0) { delay = 0; } if (e.type === 'mousemove') { delay = 150; } // Fade out ripple after delay var duration = e.type === 'mousemove' ? 2500 : Effect.duration; setTimeout(function() { var style = { top: relativeY + 'px', left: relativeX + 'px', opacity: '0', // Duration '-webkit-transition-duration': duration + 'ms', '-moz-transition-duration': duration + 'ms', '-o-transition-duration': duration + 'ms', 'transition-duration': duration + 'ms', '-webkit-transform': scale + ' ' + translate, '-moz-transform': scale + ' ' + translate, '-ms-transform': scale + ' ' + translate, '-o-transform': scale + ' ' + translate, 'transform': scale + ' ' + translate }; ripple.setAttribute('style', convertStyle(style)); setTimeout(function() { try { el.removeChild(ripple); } catch (e) { return false; } }, duration); }, delay); }
Hide the effect and remove the ripple. Must be a separate function to pass the JSLint...
removeRipple
javascript
fians/Waves
dist/waves.js
https://github.com/fians/Waves/blob/master/dist/waves.js
MIT
function getWavesEffectElement(e) { if (TouchHandler.allowEvent(e) === false) { return null; } var element = null; var target = e.target || e.srcElement; while (target.parentElement) { if ( (!(target instanceof SVGElement)) && target.classList.contains('waves-effect')) { element = target; break; } target = target.parentElement; } return element; }
Delegated click handler for .waves-effect element. returns null when .waves-effect element not in "click tree"
getWavesEffectElement
javascript
fians/Waves
dist/waves.js
https://github.com/fians/Waves/blob/master/dist/waves.js
MIT
function showEffect(e) { // Disable effect if element has "disabled" property on it // In some cases, the event is not triggered by the current element // if (e.target.getAttribute('disabled') !== null) { // return; // } var element = getWavesEffectElement(e); if (element !== null) { // Make it sure the element has either disabled property, disabled attribute or 'disabled' class if (element.disabled || element.getAttribute('disabled') || element.classList.contains('disabled')) { return; } TouchHandler.registerEvent(e); if (e.type === 'touchstart' && Effect.delay) { var hidden = false; var timer = setTimeout(function () { timer = null; Effect.show(e, element); }, Effect.delay); var hideEffect = function(hideEvent) { // if touch hasn't moved, and effect not yet started: start effect now if (timer) { clearTimeout(timer); timer = null; Effect.show(e, element); } if (!hidden) { hidden = true; Effect.hide(hideEvent, element); } removeListeners(); }; var touchMove = function(moveEvent) { if (timer) { clearTimeout(timer); timer = null; } hideEffect(moveEvent); removeListeners(); }; element.addEventListener('touchmove', touchMove, false); element.addEventListener('touchend', hideEffect, false); element.addEventListener('touchcancel', hideEffect, false); var removeListeners = function() { element.removeEventListener('touchmove', touchMove); element.removeEventListener('touchend', hideEffect); element.removeEventListener('touchcancel', hideEffect); }; } else { Effect.show(e, element); if (isTouchAvailable) { element.addEventListener('touchend', Effect.hide, false); element.addEventListener('touchcancel', Effect.hide, false); } element.addEventListener('mouseup', Effect.hide, false); element.addEventListener('mouseleave', Effect.hide, false); } } }
Bubble the click and show effect if .waves-effect elem was found
showEffect
javascript
fians/Waves
dist/waves.js
https://github.com/fians/Waves/blob/master/dist/waves.js
MIT
hideEffect = function(hideEvent) { // if touch hasn't moved, and effect not yet started: start effect now if (timer) { clearTimeout(timer); timer = null; Effect.show(e, element); } if (!hidden) { hidden = true; Effect.hide(hideEvent, element); } removeListeners(); }
Bubble the click and show effect if .waves-effect elem was found
hideEffect
javascript
fians/Waves
dist/waves.js
https://github.com/fians/Waves/blob/master/dist/waves.js
MIT
touchMove = function(moveEvent) { if (timer) { clearTimeout(timer); timer = null; } hideEffect(moveEvent); removeListeners(); }
Bubble the click and show effect if .waves-effect elem was found
touchMove
javascript
fians/Waves
dist/waves.js
https://github.com/fians/Waves/blob/master/dist/waves.js
MIT
removeListeners = function() { element.removeEventListener('touchmove', touchMove); element.removeEventListener('touchend', hideEffect); element.removeEventListener('touchcancel', hideEffect); }
Bubble the click and show effect if .waves-effect elem was found
removeListeners
javascript
fians/Waves
dist/waves.js
https://github.com/fians/Waves/blob/master/dist/waves.js
MIT
hideRipple = function(mouseup, element) { return function() { Effect.hide(mouseup, element); }; }
Cause a ripple to appear in an element via code.
hideRipple
javascript
fians/Waves
dist/waves.js
https://github.com/fians/Waves/blob/master/dist/waves.js
MIT
function removeRipple(e, el, ripple) { // Check if the ripple still exist if (!ripple) { return; } ripple.classList.remove('waves-rippling'); var relativeX = ripple.getAttribute('data-x'); var relativeY = ripple.getAttribute('data-y'); var scale = ripple.getAttribute('data-scale'); var translate = ripple.getAttribute('data-translate'); // Get delay beetween mousedown and mouse leave var diff = Date.now() - Number(ripple.getAttribute('data-hold')); var delay = 350 - diff; if (delay < 0) { delay = 0; } if (e.type === 'mousemove') { delay = 150; } // Fade out ripple after delay var duration = e.type === 'mousemove' ? 2500 : Effect.duration; setTimeout(function() { var style = { top: relativeY + 'px', left: relativeX + 'px', opacity: '0', // Duration '-webkit-transition-duration': duration + 'ms', '-moz-transition-duration': duration + 'ms', '-o-transition-duration': duration + 'ms', 'transition-duration': duration + 'ms', '-webkit-transform': scale + ' ' + translate, '-moz-transform': scale + ' ' + translate, '-ms-transform': scale + ' ' + translate, '-o-transform': scale + ' ' + translate, 'transform': scale + ' ' + translate }; ripple.setAttribute('style', convertStyle(style)); setTimeout(function() { try { el.removeChild(ripple); } catch (e) { return false; } }, duration); }, delay); }
Hide the effect and remove the ripple. Must be a separate function to pass the JSLint...
removeRipple
javascript
fians/Waves
src/js/waves.js
https://github.com/fians/Waves/blob/master/src/js/waves.js
MIT
function getWavesEffectElement(e) { if (TouchHandler.allowEvent(e) === false) { return null; } var element = null; var target = e.target || e.srcElement; while (target.parentElement) { if ( (!(target instanceof SVGElement)) && target.classList.contains('waves-effect')) { element = target; break; } target = target.parentElement; } return element; }
Delegated click handler for .waves-effect element. returns null when .waves-effect element not in "click tree"
getWavesEffectElement
javascript
fians/Waves
src/js/waves.js
https://github.com/fians/Waves/blob/master/src/js/waves.js
MIT
function showEffect(e) { // Disable effect if element has "disabled" property on it // In some cases, the event is not triggered by the current element // if (e.target.getAttribute('disabled') !== null) { // return; // } var element = getWavesEffectElement(e); if (element !== null) { // Make it sure the element has either disabled property, disabled attribute or 'disabled' class if (element.disabled || element.getAttribute('disabled') || element.classList.contains('disabled')) { return; } TouchHandler.registerEvent(e); if (e.type === 'touchstart' && Effect.delay) { var hidden = false; var timer = setTimeout(function () { timer = null; Effect.show(e, element); }, Effect.delay); var hideEffect = function(hideEvent) { // if touch hasn't moved, and effect not yet started: start effect now if (timer) { clearTimeout(timer); timer = null; Effect.show(e, element); } if (!hidden) { hidden = true; Effect.hide(hideEvent, element); } removeListeners(); }; var touchMove = function(moveEvent) { if (timer) { clearTimeout(timer); timer = null; } hideEffect(moveEvent); removeListeners(); }; element.addEventListener('touchmove', touchMove, false); element.addEventListener('touchend', hideEffect, false); element.addEventListener('touchcancel', hideEffect, false); var removeListeners = function() { element.removeEventListener('touchmove', touchMove); element.removeEventListener('touchend', hideEffect); element.removeEventListener('touchcancel', hideEffect); }; } else { Effect.show(e, element); if (isTouchAvailable) { element.addEventListener('touchend', Effect.hide, false); element.addEventListener('touchcancel', Effect.hide, false); } element.addEventListener('mouseup', Effect.hide, false); element.addEventListener('mouseleave', Effect.hide, false); } } }
Bubble the click and show effect if .waves-effect elem was found
showEffect
javascript
fians/Waves
src/js/waves.js
https://github.com/fians/Waves/blob/master/src/js/waves.js
MIT
hideEffect = function(hideEvent) { // if touch hasn't moved, and effect not yet started: start effect now if (timer) { clearTimeout(timer); timer = null; Effect.show(e, element); } if (!hidden) { hidden = true; Effect.hide(hideEvent, element); } removeListeners(); }
Bubble the click and show effect if .waves-effect elem was found
hideEffect
javascript
fians/Waves
src/js/waves.js
https://github.com/fians/Waves/blob/master/src/js/waves.js
MIT
touchMove = function(moveEvent) { if (timer) { clearTimeout(timer); timer = null; } hideEffect(moveEvent); removeListeners(); }
Bubble the click and show effect if .waves-effect elem was found
touchMove
javascript
fians/Waves
src/js/waves.js
https://github.com/fians/Waves/blob/master/src/js/waves.js
MIT
removeListeners = function() { element.removeEventListener('touchmove', touchMove); element.removeEventListener('touchend', hideEffect); element.removeEventListener('touchcancel', hideEffect); }
Bubble the click and show effect if .waves-effect elem was found
removeListeners
javascript
fians/Waves
src/js/waves.js
https://github.com/fians/Waves/blob/master/src/js/waves.js
MIT
hideRipple = function(mouseup, element) { return function() { Effect.hide(mouseup, element); }; }
Cause a ripple to appear in an element via code.
hideRipple
javascript
fians/Waves
src/js/waves.js
https://github.com/fians/Waves/blob/master/src/js/waves.js
MIT
constructor(code, message) { super(`${code}: ${message}`); this.code = code; }
@class BaseError @constructor @private @param {String} code Error code @param {String} message Error message
constructor
javascript
yagop/node-telegram-bot-api
src/errors.js
https://github.com/yagop/node-telegram-bot-api/blob/master/src/errors.js
MIT
toJSON() { return { code: this.code, message: this.message, }; }
@class BaseError @constructor @private @param {String} code Error code @param {String} message Error message
toJSON
javascript
yagop/node-telegram-bot-api
src/errors.js
https://github.com/yagop/node-telegram-bot-api/blob/master/src/errors.js
MIT
constructor(data) { const error = (typeof data === 'string') ? null : data; const message = error ? error.message : data; super('EFATAL', message); if (error) { this.stack = error.stack; this.cause = error; } }
Fatal Error. Error code is `"EFATAL"`. @class FatalError @constructor @param {String|Error} data Error object or message
constructor
javascript
yagop/node-telegram-bot-api
src/errors.js
https://github.com/yagop/node-telegram-bot-api/blob/master/src/errors.js
MIT
constructor(message, response) { super('EPARSE', message); this.response = response; }
Error during parsing. Error code is `"EPARSE"`. @class ParseError @constructor @param {String} message Error message @param {http.IncomingMessage} response Server response
constructor
javascript
yagop/node-telegram-bot-api
src/errors.js
https://github.com/yagop/node-telegram-bot-api/blob/master/src/errors.js
MIT
constructor(message, response) { super('ETELEGRAM', message); this.response = response; }
Error returned from Telegram. Error code is `"ETELEGRAM"`. @class TelegramError @constructor @param {String} message Error message @param {http.IncomingMessage} response Server response
constructor
javascript
yagop/node-telegram-bot-api
src/errors.js
https://github.com/yagop/node-telegram-bot-api/blob/master/src/errors.js
MIT
function stringify(data) { if (typeof data === 'string') { return data; } return JSON.stringify(data); }
JSON-serialize data. If the provided data is already a String, return it as is. @private @param {*} data @return {String}
stringify
javascript
yagop/node-telegram-bot-api
src/telegram.js
https://github.com/yagop/node-telegram-bot-api/blob/master/src/telegram.js
MIT
static get errors() { return errors; }
The different errors the library uses. @type {Object}
errors
javascript
yagop/node-telegram-bot-api
src/telegram.js
https://github.com/yagop/node-telegram-bot-api/blob/master/src/telegram.js
MIT
static get messageTypes() { return _messageTypes; }
The types of message updates the library handles. @type {String[]}
messageTypes
javascript
yagop/node-telegram-bot-api
src/telegram.js
https://github.com/yagop/node-telegram-bot-api/blob/master/src/telegram.js
MIT
_buildURL(_path) { return `${this.options.baseApiUrl}/bot${this.token}${this.options.testEnvironment ? '/test' : ''}/${_path}`; }
Generates url with bot token and provided path/method you want to be got/executed by bot @param {String} path @return {String} url @private @see https://core.telegram.org/bots/api#making-requests
_buildURL
javascript
yagop/node-telegram-bot-api
src/telegram.js
https://github.com/yagop/node-telegram-bot-api/blob/master/src/telegram.js
MIT
_fixReplyMarkup(obj) { const replyMarkup = obj.reply_markup; if (replyMarkup && typeof replyMarkup !== 'string') { obj.reply_markup = stringify(replyMarkup); } }
Fix 'reply_markup' parameter by making it JSON-serialized, as required by the Telegram Bot API @param {Object} obj Object; either 'form' or 'qs' @private @see https://core.telegram.org/bots/api#sendmessage
_fixReplyMarkup
javascript
yagop/node-telegram-bot-api
src/telegram.js
https://github.com/yagop/node-telegram-bot-api/blob/master/src/telegram.js
MIT
_fixEntitiesField(obj) { const entities = obj.entities; const captionEntities = obj.caption_entities; const explanationEntities = obj.explanation_entities; if (entities && typeof entities !== 'string') { obj.entities = stringify(entities); } if (captionEntities && typeof captionEntities !== 'string') { obj.caption_entities = stringify(captionEntities); } if (explanationEntities && typeof explanationEntities !== 'string') { obj.explanation_entities = stringify(explanationEntities); } }
Fix 'entities' or 'caption_entities' or 'explanation_entities' parameter by making it JSON-serialized, as required by the Telegram Bot API @param {Object} obj Object; @private @see https://core.telegram.org/bots/api#sendmessage @see https://core.telegram.org/bots/api#copymessage @see https://core.telegram.org/bots/api#sendpoll
_fixEntitiesField
javascript
yagop/node-telegram-bot-api
src/telegram.js
https://github.com/yagop/node-telegram-bot-api/blob/master/src/telegram.js
MIT
_fixAddFileThumbnail(options, opts) { if (options.thumb) { if (opts.formData === null) { opts.formData = {}; } const attachName = 'photo'; const [formData] = this._formatSendData(attachName, options.thumb.replace('attach://', '')); if (formData) { opts.formData[attachName] = formData[attachName]; opts.qs.thumbnail = `attach://${attachName}`; } } }
Fix 'entities' or 'caption_entities' or 'explanation_entities' parameter by making it JSON-serialized, as required by the Telegram Bot API @param {Object} obj Object; @private @see https://core.telegram.org/bots/api#sendmessage @see https://core.telegram.org/bots/api#copymessage @see https://core.telegram.org/bots/api#sendpoll
_fixAddFileThumbnail
javascript
yagop/node-telegram-bot-api
src/telegram.js
https://github.com/yagop/node-telegram-bot-api/blob/master/src/telegram.js
MIT
_fixReplyParameters(obj) { if (obj.hasOwnProperty('reply_parameters') && typeof obj.reply_parameters !== 'string') { obj.reply_parameters = stringify(obj.reply_parameters); } }
Fix 'reply_parameters' parameter by making it JSON-serialized, as required by the Telegram Bot API @param {Object} obj Object; either 'form' or 'qs' @private @see https://core.telegram.org/bots/api#sendmessage
_fixReplyParameters
javascript
yagop/node-telegram-bot-api
src/telegram.js
https://github.com/yagop/node-telegram-bot-api/blob/master/src/telegram.js
MIT
_request(_path, options = {}) { if (!this.token) { return Promise.reject(new errors.FatalError('Telegram Bot Token not provided!')); } if (this.options.request) { Object.assign(options, this.options.request); } if (options.form) { this._fixReplyMarkup(options.form); this._fixEntitiesField(options.form); this._fixReplyParameters(options.form); } if (options.qs) { this._fixReplyMarkup(options.qs); this._fixReplyParameters(options.qs); } options.method = 'POST'; options.url = this._buildURL(_path); options.simple = false; options.resolveWithFullResponse = true; options.forever = true; debug('HTTP request: %j', options); return request(options) .then(resp => { let data; try { data = resp.body = JSON.parse(resp.body); } catch (err) { throw new errors.ParseError(`Error parsing response: ${resp.body}`, resp); } if (data.ok) { return data.result; } throw new errors.TelegramError(`${data.error_code} ${data.description}`, resp); }).catch(error => { // TODO: why can't we do `error instanceof errors.BaseError`? if (error.response) throw error; throw new errors.FatalError(error); }); }
Make request against the API @param {String} _path API endpoint @param {Object} [options] @private @return {Promise}
_request
javascript
yagop/node-telegram-bot-api
src/telegram.js
https://github.com/yagop/node-telegram-bot-api/blob/master/src/telegram.js
MIT
_formatSendData(type, data, fileOptions = {}) { const deprecationMessage = 'See https://github.com/yagop/node-telegram-bot-api/blob/master/doc/usage.md#sending-files' + ' for more information on how sending files has been improved and' + ' on how to disable this deprecation message altogether.'; let filedata = data; let filename = fileOptions.filename; let contentType = fileOptions.contentType; if (data instanceof stream.Stream) { if (!filename && data.path) { // Will be 'null' if could not be parsed. // For example, 'data.path' === '/?id=123' from 'request("https://example.com/?id=123")' const url = URL.parse(path.basename(data.path.toString())); if (url.pathname) { filename = qs.unescape(url.pathname); } } } else if (Buffer.isBuffer(data)) { if (!filename && !process.env.NTBA_FIX_350) { deprecate(`Buffers will have their filenames default to "filename" instead of "data". ${deprecationMessage}`); filename = 'data'; } if (!contentType) { const filetype = fileType(data); if (filetype) { contentType = filetype.mime; const ext = filetype.ext; if (ext && !process.env.NTBA_FIX_350) { filename = `${filename}.${ext}`; } } else if (!process.env.NTBA_FIX_350) { deprecate(`An error will no longer be thrown if file-type of buffer could not be detected. ${deprecationMessage}`); throw new errors.FatalError('Unsupported Buffer file-type'); } } } else if (data) { if (this.options.filepath && fs.existsSync(data)) { filedata = fs.createReadStream(data); if (!filename) { filename = path.basename(data); } } else { return [null, data]; } } else { return [null, data]; } filename = filename || 'filename'; contentType = contentType || mime.lookup(filename); if (process.env.NTBA_FIX_350) { contentType = contentType || 'application/octet-stream'; } else { deprecate(`In the future, content-type of files you send will default to "application/octet-stream". ${deprecationMessage}`); } // TODO: Add missing file extension. return [{ [type]: { value: filedata, options: { filename, contentType, }, }, }, null]; }
Format data to be uploaded; handles file paths, streams and buffers @param {String} type @param {String|stream.Stream|Buffer} data @param {Object} fileOptions File options @param {String} [fileOptions.filename] File name @param {String} [fileOptions.contentType] Content type (i.e. MIME) @return {Array} formatted @return {Object} formatted[0] formData @return {String} formatted[1] fileId @throws Error if Buffer file type is not supported. @see https://npmjs.com/package/file-type @private
_formatSendData
javascript
yagop/node-telegram-bot-api
src/telegram.js
https://github.com/yagop/node-telegram-bot-api/blob/master/src/telegram.js
MIT
_formatSendMultipleData(type, files, fileOptions = {}) { const formData = {}; const fileIds = {}; files.forEach((file, index) => { let filedata = file.media || file.data || file[type]; let filename = file.filename || fileOptions.filename; let contentType = file.contentType || fileOptions.contentType; if (filedata instanceof stream.Stream) { if (!filename && filedata.path) { const url = URL.parse(path.basename(filedata.path.toString()), true); if (url.pathname) { filename = qs.unescape(url.pathname); } } } else if (Buffer.isBuffer(filedata)) { filename = `filename_${index}`; if (!contentType) { const filetype = fileType(filedata); if (filetype) { contentType = filetype.mime; const ext = filetype.ext; if (ext) { filename = `${filename}.${ext}`; } } else { throw new errors.FatalError('Unsupported Buffer file-type'); } } } else if (fs.existsSync(filedata)) { filedata = fs.createReadStream(filedata); if (!filename) { filename = path.basename(filedata.path); } } else { fileIds[index] = filedata; return; } filename = filename || `filename_${index}`; contentType = contentType || 'application/octet-stream'; formData[`${type}_${index}`] = { value: filedata, options: { filename, contentType, }, }; }); return { formData, fileIds }; }
Format multiple files to be uploaded; handles file paths, streams, and buffers @param {String} type @param {Array} files Array of file data objects @param {Object} fileOptions File options @param {String} [fileOptions.filename] File name @param {String} [fileOptions.contentType] Content type (i.e. MIME) @return {Object} formatted @return {Object} formatted.formData Form data object with all files @return {Array} formatted.fileIds Array of fileIds for non-file data @throws Error if Buffer file type is not supported. @see https://npmjs.com/package/file-type @private
_formatSendMultipleData
javascript
yagop/node-telegram-bot-api
src/telegram.js
https://github.com/yagop/node-telegram-bot-api/blob/master/src/telegram.js
MIT
startPolling(options = {}) { if (this.hasOpenWebHook()) { return Promise.reject(new errors.FatalError('Polling and WebHook are mutually exclusive')); } options.restart = typeof options.restart === 'undefined' ? true : options.restart; if (!this._polling) { this._polling = new TelegramBotPolling(this); } return this._polling.start(options); }
Start polling. Rejects returned promise if a WebHook is being used by this instance. @param {Object} [options] @param {Boolean} [options.restart=true] Consecutive calls to this method causes polling to be restarted @return {Promise}
startPolling
javascript
yagop/node-telegram-bot-api
src/telegram.js
https://github.com/yagop/node-telegram-bot-api/blob/master/src/telegram.js
MIT
initPolling() { deprecate('TelegramBot#initPolling() is deprecated. Use TelegramBot#startPolling() instead.'); return this.startPolling(); }
Alias of `TelegramBot#startPolling()`. This is **deprecated**. @param {Object} [options] @return {Promise} @deprecated
initPolling
javascript
yagop/node-telegram-bot-api
src/telegram.js
https://github.com/yagop/node-telegram-bot-api/blob/master/src/telegram.js
MIT
stopPolling(options) { if (!this._polling) { return Promise.resolve(); } return this._polling.stop(options); }
Stops polling after the last polling request resolves. Multiple invocations do nothing if polling is already stopped. Returning the promise of the last polling request is **deprecated**. @param {Object} [options] Options @param {Boolean} [options.cancel] Cancel current request @param {String} [options.reason] Reason for stopping polling @return {Promise}
stopPolling
javascript
yagop/node-telegram-bot-api
src/telegram.js
https://github.com/yagop/node-telegram-bot-api/blob/master/src/telegram.js
MIT
getFileLink(fileId, form = {}) { return this.getFile(fileId, form) .then(resp => `${this.options.baseApiUrl}/file/bot${this.token}/${resp.file_path}`); }
Get link for file. Use this method to get link for file for subsequent use. Attention: link will be valid for 1 hour. This method is a sugar extension of the (getFile)[#getfilefileid] method, which returns just path to file on remote server (you will have to manually build full uri after that). @param {String} fileId File identifier to get info about @param {Object} [options] Additional Telegram query options @return {Promise} Promise which will have *fileURI* in resolve callback @see https://core.telegram.org/bots/api#getfile
getFileLink
javascript
yagop/node-telegram-bot-api
src/telegram.js
https://github.com/yagop/node-telegram-bot-api/blob/master/src/telegram.js
MIT
downloadFile(fileId, downloadDir, form = {}) { let resolve; let reject; const promise = new Promise((a, b) => { resolve = a; reject = b; }); const fileStream = this.getFileStream(fileId, form); fileStream.on('info', (info) => { const fileName = info.uri.slice(info.uri.lastIndexOf('/') + 1); // TODO: Ensure fileName doesn't contains slashes const filePath = path.join(downloadDir, fileName); pump(fileStream, fs.createWriteStream(filePath), (error) => { if (error) { return reject(error); } return resolve(filePath); }); }); fileStream.on('error', (err) => { reject(err); }); return promise; }
Downloads file in the specified folder. This method is a sugar extension of the [getFileStream](#TelegramBot+getFileStream) method, which returns a readable file stream. @param {String} fileId File identifier to get info about @param {String} downloadDir Absolute path to the folder in which file will be saved @param {Object} [options] Additional Telegram query options @return {Promise} Promise, which will have *filePath* of downloaded file in resolve callback
downloadFile
javascript
yagop/node-telegram-bot-api
src/telegram.js
https://github.com/yagop/node-telegram-bot-api/blob/master/src/telegram.js
MIT
onText(regexp, callback) { this._textRegexpCallbacks.push({ regexp, callback }); }
Register a RegExp to test against an incomming text message. @param {RegExp} regexpRexecuted with `exec`. @param {Function} callback Callback will be called with 2 parameters, the `msg` and the result of executing `regexp.exec` on message text.
onText
javascript
yagop/node-telegram-bot-api
src/telegram.js
https://github.com/yagop/node-telegram-bot-api/blob/master/src/telegram.js
MIT
removeTextListener(regexp) { const index = this._textRegexpCallbacks.findIndex((textListener) => { return String(textListener.regexp) === String(regexp); }); if (index === -1) { return null; } return this._textRegexpCallbacks.splice(index, 1)[0]; }
Remove a listener registered with `onText()`. @param {RegExp} regexp RegExp used previously in `onText()` @return {Object} deletedListener The removed reply listener if found. This object has `regexp` and `callback` properties. If not found, returns `null`.
removeTextListener
javascript
yagop/node-telegram-bot-api
src/telegram.js
https://github.com/yagop/node-telegram-bot-api/blob/master/src/telegram.js
MIT
clearTextListeners() { this._textRegexpCallbacks = []; }
Remove all listeners registered with `onText()`.
clearTextListeners
javascript
yagop/node-telegram-bot-api
src/telegram.js
https://github.com/yagop/node-telegram-bot-api/blob/master/src/telegram.js
MIT
onReplyToMessage(chatId, messageId, callback) { const id = ++this._replyListenerId; this._replyListeners.push({ id, chatId, messageId, callback }); return id; }
Register a reply to wait for a message response. @param {Number|String} chatId The chat id where the message cames from. @param {Number|String} messageId The message id to be replied. @param {Function} callback Callback will be called with the reply message. @return {Number} id The ID of the inserted reply listener.
onReplyToMessage
javascript
yagop/node-telegram-bot-api
src/telegram.js
https://github.com/yagop/node-telegram-bot-api/blob/master/src/telegram.js
MIT
removeReplyListener(replyListenerId) { const index = this._replyListeners.findIndex((replyListener) => { return replyListener.id === replyListenerId; }); if (index === -1) { return null; } return this._replyListeners.splice(index, 1)[0]; }
Removes a reply that has been prev. registered for a message response. @param {Number} replyListenerId The ID of the reply listener. @return {Object} deletedListener The removed reply listener if found. This object has `id`, `chatId`, `messageId` and `callback` properties. If not found, returns `null`.
removeReplyListener
javascript
yagop/node-telegram-bot-api
src/telegram.js
https://github.com/yagop/node-telegram-bot-api/blob/master/src/telegram.js
MIT
clearReplyListeners() { this._replyListeners = []; }
Removes all replies that have been prev. registered for a message response. @return {Array} deletedListeners An array of removed listeners.
clearReplyListeners
javascript
yagop/node-telegram-bot-api
src/telegram.js
https://github.com/yagop/node-telegram-bot-api/blob/master/src/telegram.js
MIT
isPolling() { return this._polling ? this._polling.isPolling() : false; }
Return true if polling. Otherwise, false. @return {Boolean}
isPolling
javascript
yagop/node-telegram-bot-api
src/telegram.js
https://github.com/yagop/node-telegram-bot-api/blob/master/src/telegram.js
MIT
openWebHook() { if (this.isPolling()) { return Promise.reject(new errors.FatalError('WebHook and Polling are mutually exclusive')); } if (!this._webHook) { this._webHook = new TelegramBotWebHook(this); } return this._webHook.open(); }
Open webhook. Multiple invocations do nothing if webhook is already open. Rejects returned promise if Polling is being used by this instance. @return {Promise}
openWebHook
javascript
yagop/node-telegram-bot-api
src/telegram.js
https://github.com/yagop/node-telegram-bot-api/blob/master/src/telegram.js
MIT