id
int32
0
58k
repo
stringlengths
5
67
path
stringlengths
4
116
func_name
stringlengths
0
58
original_string
stringlengths
52
373k
language
stringclasses
1 value
code
stringlengths
52
373k
code_tokens
list
docstring
stringlengths
4
11.8k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
86
226
9,300
amqp/rhea
lib/sasl.js
function (connection, mechanisms) { this.connection = connection; this.transport = new Transport(connection.amqp_transport.identifier, SASL_PROTOCOL_ID, frames.TYPE_SASL, this); this.next = connection.amqp_transport; this.mechanisms = mechanisms; this.mechanism = undefined; this.outcome = undefined; this.username = undefined; var mechlist = Object.getOwnPropertyNames(mechanisms); this.transport.encode(frames.sasl_frame(frames.sasl_mechanisms({sasl_server_mechanisms:mechlist}))); }
javascript
function (connection, mechanisms) { this.connection = connection; this.transport = new Transport(connection.amqp_transport.identifier, SASL_PROTOCOL_ID, frames.TYPE_SASL, this); this.next = connection.amqp_transport; this.mechanisms = mechanisms; this.mechanism = undefined; this.outcome = undefined; this.username = undefined; var mechlist = Object.getOwnPropertyNames(mechanisms); this.transport.encode(frames.sasl_frame(frames.sasl_mechanisms({sasl_server_mechanisms:mechlist}))); }
[ "function", "(", "connection", ",", "mechanisms", ")", "{", "this", ".", "connection", "=", "connection", ";", "this", ".", "transport", "=", "new", "Transport", "(", "connection", ".", "amqp_transport", ".", "identifier", ",", "SASL_PROTOCOL_ID", ",", "frames", ".", "TYPE_SASL", ",", "this", ")", ";", "this", ".", "next", "=", "connection", ".", "amqp_transport", ";", "this", ".", "mechanisms", "=", "mechanisms", ";", "this", ".", "mechanism", "=", "undefined", ";", "this", ".", "outcome", "=", "undefined", ";", "this", ".", "username", "=", "undefined", ";", "var", "mechlist", "=", "Object", ".", "getOwnPropertyNames", "(", "mechanisms", ")", ";", "this", ".", "transport", ".", "encode", "(", "frames", ".", "sasl_frame", "(", "frames", ".", "sasl_mechanisms", "(", "{", "sasl_server_mechanisms", ":", "mechlist", "}", ")", ")", ")", ";", "}" ]
The mechanisms argument is a map of mechanism names to factory functions for objects that implement that mechanism.
[ "The", "mechanisms", "argument", "is", "a", "map", "of", "mechanism", "names", "to", "factory", "functions", "for", "objects", "that", "implement", "that", "mechanism", "." ]
f2142dbc4077695141e0f2d62f03575c31e59968
https://github.com/amqp/rhea/blob/f2142dbc4077695141e0f2d62f03575c31e59968/lib/sasl.js#L154-L164
9,301
mapbox/mapbox-gl-geocoder
lib/index.js
function(){ if (this.options.placeholder) return this.options.placeholder; if (this.options.language){ var firstLanguage = this.options.language.split(",")[0]; var language = subtag.language(firstLanguage); var localizedValue = localization.placeholder[language]; if (localizedValue) return localizedValue; } return 'Search'; }
javascript
function(){ if (this.options.placeholder) return this.options.placeholder; if (this.options.language){ var firstLanguage = this.options.language.split(",")[0]; var language = subtag.language(firstLanguage); var localizedValue = localization.placeholder[language]; if (localizedValue) return localizedValue; } return 'Search'; }
[ "function", "(", ")", "{", "if", "(", "this", ".", "options", ".", "placeholder", ")", "return", "this", ".", "options", ".", "placeholder", ";", "if", "(", "this", ".", "options", ".", "language", ")", "{", "var", "firstLanguage", "=", "this", ".", "options", ".", "language", ".", "split", "(", "\",\"", ")", "[", "0", "]", ";", "var", "language", "=", "subtag", ".", "language", "(", "firstLanguage", ")", ";", "var", "localizedValue", "=", "localization", ".", "placeholder", "[", "language", "]", ";", "if", "(", "localizedValue", ")", "return", "localizedValue", ";", "}", "return", "'Search'", ";", "}" ]
Get the text to use as the search bar placeholder If placeholder is provided in options, then use options.placeholder Otherwise, if language is provided in options, then use the localized string of the first language if available Otherwise use the default @returns {String} the value to use as the search bar placeholder @private
[ "Get", "the", "text", "to", "use", "as", "the", "search", "bar", "placeholder" ]
355634a36314c5a2edaecdfefa0d59d1a5007ffd
https://github.com/mapbox/mapbox-gl-geocoder/blob/355634a36314c5a2edaecdfefa0d59d1a5007ffd/lib/index.js#L552-L561
9,302
mapbox/mapbox-gl-geocoder
lib/index.js
function(language){ var browserLocale = navigator.language || navigator.userLanguage || navigator.browserLanguage; this.options.language = language || this.options.language || browserLocale; return this; }
javascript
function(language){ var browserLocale = navigator.language || navigator.userLanguage || navigator.browserLanguage; this.options.language = language || this.options.language || browserLocale; return this; }
[ "function", "(", "language", ")", "{", "var", "browserLocale", "=", "navigator", ".", "language", "||", "navigator", ".", "userLanguage", "||", "navigator", ".", "browserLanguage", ";", "this", ".", "options", ".", "language", "=", "language", "||", "this", ".", "options", ".", "language", "||", "browserLocale", ";", "return", "this", ";", "}" ]
Get the language to use in UI elements and when making search requests Look first at the explicitly set options otherwise use the browser's language settings @param {String} language Specify the language to use for response text and query result weighting. Options are IETF language tags comprised of a mandatory ISO 639-1 language code and optionally one or more IETF subtags for country or script. More than one value can also be specified, separated by commas. @returns {MapboxGeocoder} this
[ "Get", "the", "language", "to", "use", "in", "UI", "elements", "and", "when", "making", "search", "requests" ]
355634a36314c5a2edaecdfefa0d59d1a5007ffd
https://github.com/mapbox/mapbox-gl-geocoder/blob/355634a36314c5a2edaecdfefa0d59d1a5007ffd/lib/index.js#L623-L627
9,303
mapbox/mapbox-gl-geocoder
lib/index.js
function(selected){ // clean up any old marker that might be present this._removeMarker(); var defaultMarkerOptions = { color: '#4668F2' } var markerOptions = extend({}, defaultMarkerOptions, this.options.marker) this.mapMarker = new this._mapboxgl.Marker(markerOptions); this.mapMarker .setLngLat(selected.center) .addTo(this._map); return this; }
javascript
function(selected){ // clean up any old marker that might be present this._removeMarker(); var defaultMarkerOptions = { color: '#4668F2' } var markerOptions = extend({}, defaultMarkerOptions, this.options.marker) this.mapMarker = new this._mapboxgl.Marker(markerOptions); this.mapMarker .setLngLat(selected.center) .addTo(this._map); return this; }
[ "function", "(", "selected", ")", "{", "// clean up any old marker that might be present", "this", ".", "_removeMarker", "(", ")", ";", "var", "defaultMarkerOptions", "=", "{", "color", ":", "'#4668F2'", "}", "var", "markerOptions", "=", "extend", "(", "{", "}", ",", "defaultMarkerOptions", ",", "this", ".", "options", ".", "marker", ")", "this", ".", "mapMarker", "=", "new", "this", ".", "_mapboxgl", ".", "Marker", "(", "markerOptions", ")", ";", "this", ".", "mapMarker", ".", "setLngLat", "(", "selected", ".", "center", ")", ".", "addTo", "(", "this", ".", "_map", ")", ";", "return", "this", ";", "}" ]
Handle the placement of a result marking the selected result @private @param {Object} selected the selected geojson feature @returns {MapboxGeocoder} this
[ "Handle", "the", "placement", "of", "a", "result", "marking", "the", "selected", "result" ]
355634a36314c5a2edaecdfefa0d59d1a5007ffd
https://github.com/mapbox/mapbox-gl-geocoder/blob/355634a36314c5a2edaecdfefa0d59d1a5007ffd/lib/index.js#L807-L819
9,304
mapbox/mapbox-gl-geocoder
lib/events.js
MapboxEventManager
function MapboxEventManager(options) { this.origin = options.origin || 'https://api.mapbox.com'; this.endpoint = 'events/v2'; this.access_token = options.accessToken; this.version = '0.2.0' this.sessionID = this.generateSessionID(); this.userAgent = this.getUserAgent(); this.options = options; this.send = this.send.bind(this); // parse global options to be sent with each request this.countries = (options.countries) ? options.countries.split(",") : null; this.types = (options.types) ? options.types.split(",") : null; this.bbox = (options.bbox) ? options.bbox : null; this.language = (options.language) ? options.language.split(",") : null; this.limit = (options.limit) ? +options.limit : null; this.locale = navigator.language || null; this.enableEventLogging = this.shouldEnableLogging(options); this.eventQueue = new Array(); this.flushInterval = options.flushInterval || 1000; this.maxQueueSize = options.maxQueueSize || 100; this.timer = (this.flushInterval) ? setTimeout(this.flush.bind(this), this.flushInterval) : null; // keep some state to deduplicate requests if necessary this.lastSentInput = ""; this.lastSentIndex = 0; }
javascript
function MapboxEventManager(options) { this.origin = options.origin || 'https://api.mapbox.com'; this.endpoint = 'events/v2'; this.access_token = options.accessToken; this.version = '0.2.0' this.sessionID = this.generateSessionID(); this.userAgent = this.getUserAgent(); this.options = options; this.send = this.send.bind(this); // parse global options to be sent with each request this.countries = (options.countries) ? options.countries.split(",") : null; this.types = (options.types) ? options.types.split(",") : null; this.bbox = (options.bbox) ? options.bbox : null; this.language = (options.language) ? options.language.split(",") : null; this.limit = (options.limit) ? +options.limit : null; this.locale = navigator.language || null; this.enableEventLogging = this.shouldEnableLogging(options); this.eventQueue = new Array(); this.flushInterval = options.flushInterval || 1000; this.maxQueueSize = options.maxQueueSize || 100; this.timer = (this.flushInterval) ? setTimeout(this.flush.bind(this), this.flushInterval) : null; // keep some state to deduplicate requests if necessary this.lastSentInput = ""; this.lastSentIndex = 0; }
[ "function", "MapboxEventManager", "(", "options", ")", "{", "this", ".", "origin", "=", "options", ".", "origin", "||", "'https://api.mapbox.com'", ";", "this", ".", "endpoint", "=", "'events/v2'", ";", "this", ".", "access_token", "=", "options", ".", "accessToken", ";", "this", ".", "version", "=", "'0.2.0'", "this", ".", "sessionID", "=", "this", ".", "generateSessionID", "(", ")", ";", "this", ".", "userAgent", "=", "this", ".", "getUserAgent", "(", ")", ";", "this", ".", "options", "=", "options", ";", "this", ".", "send", "=", "this", ".", "send", ".", "bind", "(", "this", ")", ";", "// parse global options to be sent with each request", "this", ".", "countries", "=", "(", "options", ".", "countries", ")", "?", "options", ".", "countries", ".", "split", "(", "\",\"", ")", ":", "null", ";", "this", ".", "types", "=", "(", "options", ".", "types", ")", "?", "options", ".", "types", ".", "split", "(", "\",\"", ")", ":", "null", ";", "this", ".", "bbox", "=", "(", "options", ".", "bbox", ")", "?", "options", ".", "bbox", ":", "null", ";", "this", ".", "language", "=", "(", "options", ".", "language", ")", "?", "options", ".", "language", ".", "split", "(", "\",\"", ")", ":", "null", ";", "this", ".", "limit", "=", "(", "options", ".", "limit", ")", "?", "+", "options", ".", "limit", ":", "null", ";", "this", ".", "locale", "=", "navigator", ".", "language", "||", "null", ";", "this", ".", "enableEventLogging", "=", "this", ".", "shouldEnableLogging", "(", "options", ")", ";", "this", ".", "eventQueue", "=", "new", "Array", "(", ")", ";", "this", ".", "flushInterval", "=", "options", ".", "flushInterval", "||", "1000", ";", "this", ".", "maxQueueSize", "=", "options", ".", "maxQueueSize", "||", "100", ";", "this", ".", "timer", "=", "(", "this", ".", "flushInterval", ")", "?", "setTimeout", "(", "this", ".", "flush", ".", "bind", "(", "this", ")", ",", "this", ".", "flushInterval", ")", ":", "null", ";", "// keep some state to deduplicate requests if necessary", "this", ".", "lastSentInput", "=", "\"\"", ";", "this", ".", "lastSentIndex", "=", "0", ";", "}" ]
Construct a new mapbox event client to send interaction events to the mapbox event service @param {Object} options options with which to create the service @param {String} options.accessToken the mapbox access token to make requests @param {Number} [options.flushInterval=1000] the number of ms after which to flush the event queue @param {Number} [options.maxQueueSize=100] the number of events to queue before flushing @private
[ "Construct", "a", "new", "mapbox", "event", "client", "to", "send", "interaction", "events", "to", "the", "mapbox", "event", "service" ]
355634a36314c5a2edaecdfefa0d59d1a5007ffd
https://github.com/mapbox/mapbox-gl-geocoder/blob/355634a36314c5a2edaecdfefa0d59d1a5007ffd/lib/events.js#L12-L39
9,305
mapbox/mapbox-gl-geocoder
lib/events.js
function(selected, geocoder){ var resultIndex = this.getSelectedIndex(selected, geocoder); var payload = this.getEventPayload('search.select', geocoder); payload.resultIndex = resultIndex; payload.resultPlaceName = selected.place_name; payload.resultId = selected.id; if ((resultIndex === this.lastSentIndex && payload.queryString === this.lastSentInput) || resultIndex == -1) { // don't log duplicate events if the user re-selected the same feature on the same search return; } this.lastSentIndex = resultIndex; this.lastSentInput = payload.queryString; if (!payload.queryString) return; // will be rejected return this.push(payload) }
javascript
function(selected, geocoder){ var resultIndex = this.getSelectedIndex(selected, geocoder); var payload = this.getEventPayload('search.select', geocoder); payload.resultIndex = resultIndex; payload.resultPlaceName = selected.place_name; payload.resultId = selected.id; if ((resultIndex === this.lastSentIndex && payload.queryString === this.lastSentInput) || resultIndex == -1) { // don't log duplicate events if the user re-selected the same feature on the same search return; } this.lastSentIndex = resultIndex; this.lastSentInput = payload.queryString; if (!payload.queryString) return; // will be rejected return this.push(payload) }
[ "function", "(", "selected", ",", "geocoder", ")", "{", "var", "resultIndex", "=", "this", ".", "getSelectedIndex", "(", "selected", ",", "geocoder", ")", ";", "var", "payload", "=", "this", ".", "getEventPayload", "(", "'search.select'", ",", "geocoder", ")", ";", "payload", ".", "resultIndex", "=", "resultIndex", ";", "payload", ".", "resultPlaceName", "=", "selected", ".", "place_name", ";", "payload", ".", "resultId", "=", "selected", ".", "id", ";", "if", "(", "(", "resultIndex", "===", "this", ".", "lastSentIndex", "&&", "payload", ".", "queryString", "===", "this", ".", "lastSentInput", ")", "||", "resultIndex", "==", "-", "1", ")", "{", "// don't log duplicate events if the user re-selected the same feature on the same search", "return", ";", "}", "this", ".", "lastSentIndex", "=", "resultIndex", ";", "this", ".", "lastSentInput", "=", "payload", ".", "queryString", ";", "if", "(", "!", "payload", ".", "queryString", ")", "return", ";", "// will be rejected", "return", "this", ".", "push", "(", "payload", ")", "}" ]
Send a search.select event to the mapbox events service This event marks the array index of the item selected by the user out of the array of possible options @private @param {Object} selected the geojson feature selected by the user @param {Object} geocoder a mapbox-gl-geocoder instance @returns {Promise}
[ "Send", "a", "search", ".", "select", "event", "to", "the", "mapbox", "events", "service", "This", "event", "marks", "the", "array", "index", "of", "the", "item", "selected", "by", "the", "user", "out", "of", "the", "array", "of", "possible", "options" ]
355634a36314c5a2edaecdfefa0d59d1a5007ffd
https://github.com/mapbox/mapbox-gl-geocoder/blob/355634a36314c5a2edaecdfefa0d59d1a5007ffd/lib/events.js#L50-L64
9,306
mapbox/mapbox-gl-geocoder
lib/events.js
function (payload, callback) { if (!this.enableEventLogging) { if (callback) return callback(); return; } var options = this.getRequestOptions(payload); this.request(options, function(err){ if (err) return this.handleError(err, callback); if (callback) { return callback(); } }.bind(this)) }
javascript
function (payload, callback) { if (!this.enableEventLogging) { if (callback) return callback(); return; } var options = this.getRequestOptions(payload); this.request(options, function(err){ if (err) return this.handleError(err, callback); if (callback) { return callback(); } }.bind(this)) }
[ "function", "(", "payload", ",", "callback", ")", "{", "if", "(", "!", "this", ".", "enableEventLogging", ")", "{", "if", "(", "callback", ")", "return", "callback", "(", ")", ";", "return", ";", "}", "var", "options", "=", "this", ".", "getRequestOptions", "(", "payload", ")", ";", "this", ".", "request", "(", "options", ",", "function", "(", "err", ")", "{", "if", "(", "err", ")", "return", "this", ".", "handleError", "(", "err", ",", "callback", ")", ";", "if", "(", "callback", ")", "{", "return", "callback", "(", ")", ";", "}", "}", ".", "bind", "(", "this", ")", ")", "}" ]
Send an event to the events service The event is skipped if the instance is not enabled to send logging events @private @param {Object} payload the http POST body of the event @param {Function} [callback] a callback function to invoke when the send has completed @returns {Promise}
[ "Send", "an", "event", "to", "the", "events", "service" ]
355634a36314c5a2edaecdfefa0d59d1a5007ffd
https://github.com/mapbox/mapbox-gl-geocoder/blob/355634a36314c5a2edaecdfefa0d59d1a5007ffd/lib/events.js#L109-L121
9,307
mapbox/mapbox-gl-geocoder
lib/events.js
function(payload){ if (!Array.isArray(payload)) payload = [payload]; var options = { // events must be sent with POST method: "POST", host: this.origin, path: this.endpoint + "?access_token=" + this.access_token, headers: { 'Content-Type': 'application/json' }, body:JSON.stringify(payload) //events are arrays } return options }
javascript
function(payload){ if (!Array.isArray(payload)) payload = [payload]; var options = { // events must be sent with POST method: "POST", host: this.origin, path: this.endpoint + "?access_token=" + this.access_token, headers: { 'Content-Type': 'application/json' }, body:JSON.stringify(payload) //events are arrays } return options }
[ "function", "(", "payload", ")", "{", "if", "(", "!", "Array", ".", "isArray", "(", "payload", ")", ")", "payload", "=", "[", "payload", "]", ";", "var", "options", "=", "{", "// events must be sent with POST", "method", ":", "\"POST\"", ",", "host", ":", "this", ".", "origin", ",", "path", ":", "this", ".", "endpoint", "+", "\"?access_token=\"", "+", "this", ".", "access_token", ",", "headers", ":", "{", "'Content-Type'", ":", "'application/json'", "}", ",", "body", ":", "JSON", ".", "stringify", "(", "payload", ")", "//events are arrays", "}", "return", "options", "}" ]
Get http request options @private @param {*} payload
[ "Get", "http", "request", "options" ]
355634a36314c5a2edaecdfefa0d59d1a5007ffd
https://github.com/mapbox/mapbox-gl-geocoder/blob/355634a36314c5a2edaecdfefa0d59d1a5007ffd/lib/events.js#L127-L140
9,308
mapbox/mapbox-gl-geocoder
lib/events.js
function (event, geocoder) { var proximity; if (!geocoder.options.proximity) proximity = null; else proximity = [geocoder.options.proximity.longitude, geocoder.options.proximity.latitude]; var zoom = (geocoder._map) ? geocoder._map.getZoom() : null; var payload = { event: event, created: +new Date(), sessionIdentifier: this.sessionID, country: this.countries, userAgent: this.userAgent, language: this.language, bbox: this.bbox, types: this.types, endpoint: 'mapbox.places', // fuzzyMatch: search.fuzzy, //todo --> add to plugin proximity: proximity, limit: geocoder.options.limit, // routing: search.routing, //todo --> add to plugin mapZoom: zoom, keyboardLocale: this.locale } // get the text in the search bar if (event === "search.select"){ payload.queryString = geocoder.inputString; }else if (event != "search.select" && geocoder._inputEl){ payload.queryString = geocoder._inputEl.value; }else{ payload.queryString = geocoder.inputString; } return payload; }
javascript
function (event, geocoder) { var proximity; if (!geocoder.options.proximity) proximity = null; else proximity = [geocoder.options.proximity.longitude, geocoder.options.proximity.latitude]; var zoom = (geocoder._map) ? geocoder._map.getZoom() : null; var payload = { event: event, created: +new Date(), sessionIdentifier: this.sessionID, country: this.countries, userAgent: this.userAgent, language: this.language, bbox: this.bbox, types: this.types, endpoint: 'mapbox.places', // fuzzyMatch: search.fuzzy, //todo --> add to plugin proximity: proximity, limit: geocoder.options.limit, // routing: search.routing, //todo --> add to plugin mapZoom: zoom, keyboardLocale: this.locale } // get the text in the search bar if (event === "search.select"){ payload.queryString = geocoder.inputString; }else if (event != "search.select" && geocoder._inputEl){ payload.queryString = geocoder._inputEl.value; }else{ payload.queryString = geocoder.inputString; } return payload; }
[ "function", "(", "event", ",", "geocoder", ")", "{", "var", "proximity", ";", "if", "(", "!", "geocoder", ".", "options", ".", "proximity", ")", "proximity", "=", "null", ";", "else", "proximity", "=", "[", "geocoder", ".", "options", ".", "proximity", ".", "longitude", ",", "geocoder", ".", "options", ".", "proximity", ".", "latitude", "]", ";", "var", "zoom", "=", "(", "geocoder", ".", "_map", ")", "?", "geocoder", ".", "_map", ".", "getZoom", "(", ")", ":", "null", ";", "var", "payload", "=", "{", "event", ":", "event", ",", "created", ":", "+", "new", "Date", "(", ")", ",", "sessionIdentifier", ":", "this", ".", "sessionID", ",", "country", ":", "this", ".", "countries", ",", "userAgent", ":", "this", ".", "userAgent", ",", "language", ":", "this", ".", "language", ",", "bbox", ":", "this", ".", "bbox", ",", "types", ":", "this", ".", "types", ",", "endpoint", ":", "'mapbox.places'", ",", "// fuzzyMatch: search.fuzzy, //todo --> add to plugin", "proximity", ":", "proximity", ",", "limit", ":", "geocoder", ".", "options", ".", "limit", ",", "// routing: search.routing, //todo --> add to plugin", "mapZoom", ":", "zoom", ",", "keyboardLocale", ":", "this", ".", "locale", "}", "// get the text in the search bar", "if", "(", "event", "===", "\"search.select\"", ")", "{", "payload", ".", "queryString", "=", "geocoder", ".", "inputString", ";", "}", "else", "if", "(", "event", "!=", "\"search.select\"", "&&", "geocoder", ".", "_inputEl", ")", "{", "payload", ".", "queryString", "=", "geocoder", ".", "_inputEl", ".", "value", ";", "}", "else", "{", "payload", ".", "queryString", "=", "geocoder", ".", "inputString", ";", "}", "return", "payload", ";", "}" ]
Get the event payload to send to the events service Most payload properties are shared across all events @private @param {String} event the name of the event to send to the events service. Valid options are 'search.start', 'search.select', 'search.feedback'. @param {Object} geocoder a mapbox-gl-geocoder instance @returns {Object} an event payload
[ "Get", "the", "event", "payload", "to", "send", "to", "the", "events", "service", "Most", "payload", "properties", "are", "shared", "across", "all", "events" ]
355634a36314c5a2edaecdfefa0d59d1a5007ffd
https://github.com/mapbox/mapbox-gl-geocoder/blob/355634a36314c5a2edaecdfefa0d59d1a5007ffd/lib/events.js#L150-L183
9,309
mapbox/mapbox-gl-geocoder
lib/events.js
function (opts, callback) { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 ) { if (this.status == 204){ //success return callback(null); }else { return callback(this.statusText); } } }; xhttp.open(opts.method, opts.host + '/' + opts.path, true); for (var header in opts.headers){ var headerValue = opts.headers[header]; xhttp.setRequestHeader(header, headerValue) } xhttp.send(opts.body); }
javascript
function (opts, callback) { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 ) { if (this.status == 204){ //success return callback(null); }else { return callback(this.statusText); } } }; xhttp.open(opts.method, opts.host + '/' + opts.path, true); for (var header in opts.headers){ var headerValue = opts.headers[header]; xhttp.setRequestHeader(header, headerValue) } xhttp.send(opts.body); }
[ "function", "(", "opts", ",", "callback", ")", "{", "var", "xhttp", "=", "new", "XMLHttpRequest", "(", ")", ";", "xhttp", ".", "onreadystatechange", "=", "function", "(", ")", "{", "if", "(", "this", ".", "readyState", "==", "4", ")", "{", "if", "(", "this", ".", "status", "==", "204", ")", "{", "//success", "return", "callback", "(", "null", ")", ";", "}", "else", "{", "return", "callback", "(", "this", ".", "statusText", ")", ";", "}", "}", "}", ";", "xhttp", ".", "open", "(", "opts", ".", "method", ",", "opts", ".", "host", "+", "'/'", "+", "opts", ".", "path", ",", "true", ")", ";", "for", "(", "var", "header", "in", "opts", ".", "headers", ")", "{", "var", "headerValue", "=", "opts", ".", "headers", "[", "header", "]", ";", "xhttp", ".", "setRequestHeader", "(", "header", ",", "headerValue", ")", "}", "xhttp", ".", "send", "(", "opts", ".", "body", ")", ";", "}" ]
Wraps the request function for easier testing Make an http request and invoke a callback @private @param {Object} opts options describing the http request to be made @param {Function} callback the callback to invoke when the http request is completed
[ "Wraps", "the", "request", "function", "for", "easier", "testing", "Make", "an", "http", "request", "and", "invoke", "a", "callback" ]
355634a36314c5a2edaecdfefa0d59d1a5007ffd
https://github.com/mapbox/mapbox-gl-geocoder/blob/355634a36314c5a2edaecdfefa0d59d1a5007ffd/lib/events.js#L192-L211
9,310
mapbox/mapbox-gl-geocoder
lib/events.js
function(selected, geocoder){ if (!geocoder._typeahead) return; var results = geocoder._typeahead.data; var selectedID = selected.id; var resultIDs = results.map(function (feature) { return feature.id; }); var selectedIdx = resultIDs.indexOf(selectedID); return selectedIdx; }
javascript
function(selected, geocoder){ if (!geocoder._typeahead) return; var results = geocoder._typeahead.data; var selectedID = selected.id; var resultIDs = results.map(function (feature) { return feature.id; }); var selectedIdx = resultIDs.indexOf(selectedID); return selectedIdx; }
[ "function", "(", "selected", ",", "geocoder", ")", "{", "if", "(", "!", "geocoder", ".", "_typeahead", ")", "return", ";", "var", "results", "=", "geocoder", ".", "_typeahead", ".", "data", ";", "var", "selectedID", "=", "selected", ".", "id", ";", "var", "resultIDs", "=", "results", ".", "map", "(", "function", "(", "feature", ")", "{", "return", "feature", ".", "id", ";", "}", ")", ";", "var", "selectedIdx", "=", "resultIDs", ".", "indexOf", "(", "selectedID", ")", ";", "return", "selectedIdx", ";", "}" ]
Get the 0-based numeric index of the item that the user selected out of the list of options @private @param {Object} selected the geojson feature selected by the user @param {Object} geocoder a Mapbox-GL-Geocoder instance @returns {Number} the index of the selected result
[ "Get", "the", "0", "-", "based", "numeric", "index", "of", "the", "item", "that", "the", "user", "selected", "out", "of", "the", "list", "of", "options" ]
355634a36314c5a2edaecdfefa0d59d1a5007ffd
https://github.com/mapbox/mapbox-gl-geocoder/blob/355634a36314c5a2edaecdfefa0d59d1a5007ffd/lib/events.js#L246-L255
9,311
mapbox/mapbox-gl-geocoder
lib/events.js
function(options){ if (options.enableEventLogging === false) return false; if (options.origin && options.origin.indexOf('api.mapbox.com') == -1) return false; // hard to make sense of events when a local instance is suplementing results from origin if (options.localGeocoder) return false; // hard to make sense of events when a custom filter is in use if (options.filter) return false; return true; }
javascript
function(options){ if (options.enableEventLogging === false) return false; if (options.origin && options.origin.indexOf('api.mapbox.com') == -1) return false; // hard to make sense of events when a local instance is suplementing results from origin if (options.localGeocoder) return false; // hard to make sense of events when a custom filter is in use if (options.filter) return false; return true; }
[ "function", "(", "options", ")", "{", "if", "(", "options", ".", "enableEventLogging", "===", "false", ")", "return", "false", ";", "if", "(", "options", ".", "origin", "&&", "options", ".", "origin", ".", "indexOf", "(", "'api.mapbox.com'", ")", "==", "-", "1", ")", "return", "false", ";", "// hard to make sense of events when a local instance is suplementing results from origin", "if", "(", "options", ".", "localGeocoder", ")", "return", "false", ";", "// hard to make sense of events when a custom filter is in use", "if", "(", "options", ".", "filter", ")", "return", "false", ";", "return", "true", ";", "}" ]
Check whether events should be logged Clients using a localGeocoder or an origin other than mapbox should not have events logged @private
[ "Check", "whether", "events", "should", "be", "logged", "Clients", "using", "a", "localGeocoder", "or", "an", "origin", "other", "than", "mapbox", "should", "not", "have", "events", "logged" ]
355634a36314c5a2edaecdfefa0d59d1a5007ffd
https://github.com/mapbox/mapbox-gl-geocoder/blob/355634a36314c5a2edaecdfefa0d59d1a5007ffd/lib/events.js#L262-L270
9,312
mapbox/mapbox-gl-geocoder
lib/events.js
function(){ if (this.eventQueue.length > 0){ this.send(this.eventQueue); this.eventQueue = new Array(); } // //reset the timer if (this.timer) clearTimeout(this.timer); if (this.flushInterval) this.timer = setTimeout(this.flush.bind(this), this.flushInterval) }
javascript
function(){ if (this.eventQueue.length > 0){ this.send(this.eventQueue); this.eventQueue = new Array(); } // //reset the timer if (this.timer) clearTimeout(this.timer); if (this.flushInterval) this.timer = setTimeout(this.flush.bind(this), this.flushInterval) }
[ "function", "(", ")", "{", "if", "(", "this", ".", "eventQueue", ".", "length", ">", "0", ")", "{", "this", ".", "send", "(", "this", ".", "eventQueue", ")", ";", "this", ".", "eventQueue", "=", "new", "Array", "(", ")", ";", "}", "// //reset the timer", "if", "(", "this", ".", "timer", ")", "clearTimeout", "(", "this", ".", "timer", ")", ";", "if", "(", "this", ".", "flushInterval", ")", "this", ".", "timer", "=", "setTimeout", "(", "this", ".", "flush", ".", "bind", "(", "this", ")", ",", "this", ".", "flushInterval", ")", "}" ]
Flush out the event queue by sending events to the events service @private
[ "Flush", "out", "the", "event", "queue", "by", "sending", "events", "to", "the", "events", "service" ]
355634a36314c5a2edaecdfefa0d59d1a5007ffd
https://github.com/mapbox/mapbox-gl-geocoder/blob/355634a36314c5a2edaecdfefa0d59d1a5007ffd/lib/events.js#L276-L284
9,313
mapbox/mapbox-gl-geocoder
lib/events.js
function(evt, forceFlush){ this.eventQueue.push(evt); if (this.eventQueue.length >= this.maxQueueSize || forceFlush){ this.flush(); } }
javascript
function(evt, forceFlush){ this.eventQueue.push(evt); if (this.eventQueue.length >= this.maxQueueSize || forceFlush){ this.flush(); } }
[ "function", "(", "evt", ",", "forceFlush", ")", "{", "this", ".", "eventQueue", ".", "push", "(", "evt", ")", ";", "if", "(", "this", ".", "eventQueue", ".", "length", ">=", "this", ".", "maxQueueSize", "||", "forceFlush", ")", "{", "this", ".", "flush", "(", ")", ";", "}", "}" ]
Push event into the pending queue @param {Object} evt the event to send to the events service @param {Boolean} forceFlush indicates that the event queue should be flushed after adding this event regardless of size of the queue @private
[ "Push", "event", "into", "the", "pending", "queue" ]
355634a36314c5a2edaecdfefa0d59d1a5007ffd
https://github.com/mapbox/mapbox-gl-geocoder/blob/355634a36314c5a2edaecdfefa0d59d1a5007ffd/lib/events.js#L292-L297
9,314
actionhero/actionhero
config/logger.js
buildConsoleLogger
function buildConsoleLogger (level = 'info') { return function (api) { return winston.createLogger({ format: winston.format.combine( winston.format.timestamp(), winston.format.colorize(), winston.format.printf(info => { return `${api.id} @ ${info.timestamp} - ${info.level}: ${info.message} ${stringifyExtraMessagePropertiesForConsole(info)}` }) ), level, levels: winston.config.syslog.levels, transports: [ new winston.transports.Console() ] }) } }
javascript
function buildConsoleLogger (level = 'info') { return function (api) { return winston.createLogger({ format: winston.format.combine( winston.format.timestamp(), winston.format.colorize(), winston.format.printf(info => { return `${api.id} @ ${info.timestamp} - ${info.level}: ${info.message} ${stringifyExtraMessagePropertiesForConsole(info)}` }) ), level, levels: winston.config.syslog.levels, transports: [ new winston.transports.Console() ] }) } }
[ "function", "buildConsoleLogger", "(", "level", "=", "'info'", ")", "{", "return", "function", "(", "api", ")", "{", "return", "winston", ".", "createLogger", "(", "{", "format", ":", "winston", ".", "format", ".", "combine", "(", "winston", ".", "format", ".", "timestamp", "(", ")", ",", "winston", ".", "format", ".", "colorize", "(", ")", ",", "winston", ".", "format", ".", "printf", "(", "info", "=>", "{", "return", "`", "${", "api", ".", "id", "}", "${", "info", ".", "timestamp", "}", "${", "info", ".", "level", "}", "${", "info", ".", "message", "}", "${", "stringifyExtraMessagePropertiesForConsole", "(", "info", ")", "}", "`", "}", ")", ")", ",", "level", ",", "levels", ":", "winston", ".", "config", ".", "syslog", ".", "levels", ",", "transports", ":", "[", "new", "winston", ".", "transports", ".", "Console", "(", ")", "]", "}", ")", "}", "}" ]
learn more about winston v3 loggers @ - https://github.com/winstonjs/winston - https://github.com/winstonjs/winston/blob/master/docs/transports.md
[ "learn", "more", "about", "winston", "v3", "loggers" ]
046c81f1879efcad47048f4505b215e38bd72b7f
https://github.com/actionhero/actionhero/blob/046c81f1879efcad47048f4505b215e38bd72b7f/config/logger.js#L10-L25
9,315
wnr/element-resize-detector
src/listener-handler.js
getListeners
function getListeners(element) { var id = idHandler.get(element); if (id === undefined) { return []; } return eventListeners[id] || []; }
javascript
function getListeners(element) { var id = idHandler.get(element); if (id === undefined) { return []; } return eventListeners[id] || []; }
[ "function", "getListeners", "(", "element", ")", "{", "var", "id", "=", "idHandler", ".", "get", "(", "element", ")", ";", "if", "(", "id", "===", "undefined", ")", "{", "return", "[", "]", ";", "}", "return", "eventListeners", "[", "id", "]", "||", "[", "]", ";", "}" ]
Gets all listeners for the given element. @public @param {element} element The element to get all listeners for. @returns All listeners for the given element.
[ "Gets", "all", "listeners", "for", "the", "given", "element", "." ]
27983e59dce9d8f1296d8f555dc2340840fb0804
https://github.com/wnr/element-resize-detector/blob/27983e59dce9d8f1296d8f555dc2340840fb0804/src/listener-handler.js#L12-L20
9,316
wnr/element-resize-detector
src/listener-handler.js
addListener
function addListener(element, listener) { var id = idHandler.get(element); if(!eventListeners[id]) { eventListeners[id] = []; } eventListeners[id].push(listener); }
javascript
function addListener(element, listener) { var id = idHandler.get(element); if(!eventListeners[id]) { eventListeners[id] = []; } eventListeners[id].push(listener); }
[ "function", "addListener", "(", "element", ",", "listener", ")", "{", "var", "id", "=", "idHandler", ".", "get", "(", "element", ")", ";", "if", "(", "!", "eventListeners", "[", "id", "]", ")", "{", "eventListeners", "[", "id", "]", "=", "[", "]", ";", "}", "eventListeners", "[", "id", "]", ".", "push", "(", "listener", ")", ";", "}" ]
Stores the given listener for the given element. Will not actually add the listener to the element. @public @param {element} element The element that should have the listener added. @param {function} listener The callback that the element has added.
[ "Stores", "the", "given", "listener", "for", "the", "given", "element", ".", "Will", "not", "actually", "add", "the", "listener", "to", "the", "element", "." ]
27983e59dce9d8f1296d8f555dc2340840fb0804
https://github.com/wnr/element-resize-detector/blob/27983e59dce9d8f1296d8f555dc2340840fb0804/src/listener-handler.js#L28-L36
9,317
wnr/element-resize-detector
src/id-handler.js
getId
function getId(element) { var state = getState(element); if (state && state.id !== undefined) { return state.id; } return null; }
javascript
function getId(element) { var state = getState(element); if (state && state.id !== undefined) { return state.id; } return null; }
[ "function", "getId", "(", "element", ")", "{", "var", "state", "=", "getState", "(", "element", ")", ";", "if", "(", "state", "&&", "state", ".", "id", "!==", "undefined", ")", "{", "return", "state", ".", "id", ";", "}", "return", "null", ";", "}" ]
Gets the resize detector id of the element. @public @param {element} element The target element to get the id of. @returns {string|number|null} The id of the element. Null if it has no id.
[ "Gets", "the", "resize", "detector", "id", "of", "the", "element", "." ]
27983e59dce9d8f1296d8f555dc2340840fb0804
https://github.com/wnr/element-resize-detector/blob/27983e59dce9d8f1296d8f555dc2340840fb0804/src/id-handler.js#L13-L21
9,318
wnr/element-resize-detector
src/id-handler.js
setId
function setId(element) { var state = getState(element); if (!state) { throw new Error("setId required the element to have a resize detection state."); } var id = idGenerator.generate(); state.id = id; return id; }
javascript
function setId(element) { var state = getState(element); if (!state) { throw new Error("setId required the element to have a resize detection state."); } var id = idGenerator.generate(); state.id = id; return id; }
[ "function", "setId", "(", "element", ")", "{", "var", "state", "=", "getState", "(", "element", ")", ";", "if", "(", "!", "state", ")", "{", "throw", "new", "Error", "(", "\"setId required the element to have a resize detection state.\"", ")", ";", "}", "var", "id", "=", "idGenerator", ".", "generate", "(", ")", ";", "state", ".", "id", "=", "id", ";", "return", "id", ";", "}" ]
Sets the resize detector id of the element. Requires the element to have a resize detector state initialized. @public @param {element} element The target element to set the id of. @returns {string|number|null} The id of the element.
[ "Sets", "the", "resize", "detector", "id", "of", "the", "element", ".", "Requires", "the", "element", "to", "have", "a", "resize", "detector", "state", "initialized", "." ]
27983e59dce9d8f1296d8f555dc2340840fb0804
https://github.com/wnr/element-resize-detector/blob/27983e59dce9d8f1296d8f555dc2340840fb0804/src/id-handler.js#L29-L41
9,319
bitpay/bitcore-wallet-service
lib/server.js
chunkArray
function chunkArray(myArray, chunk_size){ var results = []; while (myArray.length) { results.push(myArray.splice(0, chunk_size)); } return results; }
javascript
function chunkArray(myArray, chunk_size){ var results = []; while (myArray.length) { results.push(myArray.splice(0, chunk_size)); } return results; }
[ "function", "chunkArray", "(", "myArray", ",", "chunk_size", ")", "{", "var", "results", "=", "[", "]", ";", "while", "(", "myArray", ".", "length", ")", "{", "results", ".", "push", "(", "myArray", ".", "splice", "(", "0", ",", "chunk_size", ")", ")", ";", "}", "return", "results", ";", "}" ]
Returns an array with arrays of the given size. @param myArray {Array} Array to split @param chunkSize {Integer} Size of every group
[ "Returns", "an", "array", "with", "arrays", "of", "the", "given", "size", "." ]
750172ff7c508a41e612e5ca037094d967964383
https://github.com/bitpay/bitcore-wallet-service/blob/750172ff7c508a41e612e5ca037094d967964383/lib/server.js#L3254-L3262
9,320
mapbox/carto
lib/carto/parser.js
function() { var args = [], arg; arg = $(this.expression); while (arg) { args.push(arg); if (! $(',')) { break; } arg = $(this.expression); } return args; }
javascript
function() { var args = [], arg; arg = $(this.expression); while (arg) { args.push(arg); if (! $(',')) { break; } arg = $(this.expression); } return args; }
[ "function", "(", ")", "{", "var", "args", "=", "[", "]", ",", "arg", ";", "arg", "=", "$", "(", "this", ".", "expression", ")", ";", "while", "(", "arg", ")", "{", "args", ".", "push", "(", "arg", ")", ";", "if", "(", "!", "$", "(", "','", ")", ")", "{", "break", ";", "}", "arg", "=", "$", "(", "this", ".", "expression", ")", ";", "}", "return", "args", ";", "}" ]
Arguments are comma-separated expressions
[ "Arguments", "are", "comma", "-", "separated", "expressions" ]
13a3962315b61b892f4ad64053cd3a2f67824f74
https://github.com/mapbox/carto/blob/13a3962315b61b892f4ad64053cd3a2f67824f74/lib/carto/parser.js#L387-L398
9,321
mapbox/carto
lib/carto/parser.js
function() { var c = input.charCodeAt(i); if ((c > 57 || c < 45) || c === 47) return; var value = $(/^(-?\d*\.?\d+(?:[eE][-+]?\d+)?)(\%|\w+)?/); if (value) { return new tree.Dimension(value[1], value[2], memo, env.filename); } }
javascript
function() { var c = input.charCodeAt(i); if ((c > 57 || c < 45) || c === 47) return; var value = $(/^(-?\d*\.?\d+(?:[eE][-+]?\d+)?)(\%|\w+)?/); if (value) { return new tree.Dimension(value[1], value[2], memo, env.filename); } }
[ "function", "(", ")", "{", "var", "c", "=", "input", ".", "charCodeAt", "(", "i", ")", ";", "if", "(", "(", "c", ">", "57", "||", "c", "<", "45", ")", "||", "c", "===", "47", ")", "return", ";", "var", "value", "=", "$", "(", "/", "^(-?\\d*\\.?\\d+(?:[eE][-+]?\\d+)?)(\\%|\\w+)?", "/", ")", ";", "if", "(", "value", ")", "{", "return", "new", "tree", ".", "Dimension", "(", "value", "[", "1", "]", ",", "value", "[", "2", "]", ",", "memo", ",", "env", ".", "filename", ")", ";", "}", "}" ]
A Dimension, that is, a number and a unit. The only unit that has an effect is %
[ "A", "Dimension", "that", "is", "a", "number", "and", "a", "unit", ".", "The", "only", "unit", "that", "has", "an", "effect", "is", "%" ]
13a3962315b61b892f4ad64053cd3a2f67824f74
https://github.com/mapbox/carto/blob/13a3962315b61b892f4ad64053cd3a2f67824f74/lib/carto/parser.js#L463-L470
9,322
mapbox/carto
lib/carto/parser.js
function() { var a, attachment, e, elements = [], f, filters = new tree.Filterset(), z, zooms = [], segments = 0, conditions = 0; while ( (e = $(this.element)) || (z = $(this.zoom)) || (f = $(this.filter)) || (a = $(this.attachment)) ) { segments++; if (e) { elements.push(e); } else if (z) { zooms.push(z); conditions++; } else if (f) { var err = filters.add(f); if (err) { util.error(env, { message: err, index: i - 1, filename: env.filename }); throw new Error('N/A'); } conditions++; } else if (attachment) { util.error(env, { message: 'Encountered second attachment name.\n', index: i - 1, filename: env.filename }); throw new Error('N/A'); } else { attachment = a; } var c = input.charAt(i); if (c === '{' || c === '}' || c === ';' || c === ',') { break; } } if (segments) { return new tree.Selector(filters, zooms, elements, attachment, conditions, memo); } }
javascript
function() { var a, attachment, e, elements = [], f, filters = new tree.Filterset(), z, zooms = [], segments = 0, conditions = 0; while ( (e = $(this.element)) || (z = $(this.zoom)) || (f = $(this.filter)) || (a = $(this.attachment)) ) { segments++; if (e) { elements.push(e); } else if (z) { zooms.push(z); conditions++; } else if (f) { var err = filters.add(f); if (err) { util.error(env, { message: err, index: i - 1, filename: env.filename }); throw new Error('N/A'); } conditions++; } else if (attachment) { util.error(env, { message: 'Encountered second attachment name.\n', index: i - 1, filename: env.filename }); throw new Error('N/A'); } else { attachment = a; } var c = input.charAt(i); if (c === '{' || c === '}' || c === ';' || c === ',') { break; } } if (segments) { return new tree.Selector(filters, zooms, elements, attachment, conditions, memo); } }
[ "function", "(", ")", "{", "var", "a", ",", "attachment", ",", "e", ",", "elements", "=", "[", "]", ",", "f", ",", "filters", "=", "new", "tree", ".", "Filterset", "(", ")", ",", "z", ",", "zooms", "=", "[", "]", ",", "segments", "=", "0", ",", "conditions", "=", "0", ";", "while", "(", "(", "e", "=", "$", "(", "this", ".", "element", ")", ")", "||", "(", "z", "=", "$", "(", "this", ".", "zoom", ")", ")", "||", "(", "f", "=", "$", "(", "this", ".", "filter", ")", ")", "||", "(", "a", "=", "$", "(", "this", ".", "attachment", ")", ")", ")", "{", "segments", "++", ";", "if", "(", "e", ")", "{", "elements", ".", "push", "(", "e", ")", ";", "}", "else", "if", "(", "z", ")", "{", "zooms", ".", "push", "(", "z", ")", ";", "conditions", "++", ";", "}", "else", "if", "(", "f", ")", "{", "var", "err", "=", "filters", ".", "add", "(", "f", ")", ";", "if", "(", "err", ")", "{", "util", ".", "error", "(", "env", ",", "{", "message", ":", "err", ",", "index", ":", "i", "-", "1", ",", "filename", ":", "env", ".", "filename", "}", ")", ";", "throw", "new", "Error", "(", "'N/A'", ")", ";", "}", "conditions", "++", ";", "}", "else", "if", "(", "attachment", ")", "{", "util", ".", "error", "(", "env", ",", "{", "message", ":", "'Encountered second attachment name.\\n'", ",", "index", ":", "i", "-", "1", ",", "filename", ":", "env", ".", "filename", "}", ")", ";", "throw", "new", "Error", "(", "'N/A'", ")", ";", "}", "else", "{", "attachment", "=", "a", ";", "}", "var", "c", "=", "input", ".", "charAt", "(", "i", ")", ";", "if", "(", "c", "===", "'{'", "||", "c", "===", "'}'", "||", "c", "===", "';'", "||", "c", "===", "','", ")", "{", "break", ";", "}", "}", "if", "(", "segments", ")", "{", "return", "new", "tree", ".", "Selector", "(", "filters", ",", "zooms", ",", "elements", ",", "attachment", ",", "conditions", ",", "memo", ")", ";", "}", "}" ]
Selectors are made out of one or more Elements, see above.
[ "Selectors", "are", "made", "out", "of", "one", "or", "more", "Elements", "see", "above", "." ]
13a3962315b61b892f4ad64053cd3a2f67824f74
https://github.com/mapbox/carto/blob/13a3962315b61b892f4ad64053cd3a2f67824f74/lib/carto/parser.js#L516-L564
9,323
mapbox/carto
lib/carto/parser.js
function() { var m, a, op, operation; m = $(this.operand); if (m) { while ((op = ($('/') || $('*') || $('%'))) && (a = $(this.operand))) { operation = new tree.Operation(op, [operation || m, a], memo, env.filename); } return operation || m; } }
javascript
function() { var m, a, op, operation; m = $(this.operand); if (m) { while ((op = ($('/') || $('*') || $('%'))) && (a = $(this.operand))) { operation = new tree.Operation(op, [operation || m, a], memo, env.filename); } return operation || m; } }
[ "function", "(", ")", "{", "var", "m", ",", "a", ",", "op", ",", "operation", ";", "m", "=", "$", "(", "this", ".", "operand", ")", ";", "if", "(", "m", ")", "{", "while", "(", "(", "op", "=", "(", "$", "(", "'/'", ")", "||", "$", "(", "'*'", ")", "||", "$", "(", "'%'", ")", ")", ")", "&&", "(", "a", "=", "$", "(", "this", ".", "operand", ")", ")", ")", "{", "operation", "=", "new", "tree", ".", "Operation", "(", "op", ",", "[", "operation", "||", "m", ",", "a", "]", ",", "memo", ",", "env", ".", "filename", ")", ";", "}", "return", "operation", "||", "m", ";", "}", "}" ]
This is a misnomer because it actually handles multiplication and division.
[ "This", "is", "a", "misnomer", "because", "it", "actually", "handles", "multiplication", "and", "division", "." ]
13a3962315b61b892f4ad64053cd3a2f67824f74
https://github.com/mapbox/carto/blob/13a3962315b61b892f4ad64053cd3a2f67824f74/lib/carto/parser.js#L733-L742
9,324
mapbox/carto
lib/carto/parser.js
function() { var e, entities = []; e = $(this.addition); while (e || $(this.entity)) { entities.push(e); e = $(this.addition); } if (entities.length > 0) { return new tree.Expression(entities); } }
javascript
function() { var e, entities = []; e = $(this.addition); while (e || $(this.entity)) { entities.push(e); e = $(this.addition); } if (entities.length > 0) { return new tree.Expression(entities); } }
[ "function", "(", ")", "{", "var", "e", ",", "entities", "=", "[", "]", ";", "e", "=", "$", "(", "this", ".", "addition", ")", ";", "while", "(", "e", "||", "$", "(", "this", ".", "entity", ")", ")", "{", "entities", ".", "push", "(", "e", ")", ";", "e", "=", "$", "(", "this", ".", "addition", ")", ";", "}", "if", "(", "entities", ".", "length", ">", "0", ")", "{", "return", "new", "tree", ".", "Expression", "(", "entities", ")", ";", "}", "}" ]
Expressions either represent mathematical operations, or white-space delimited Entities. @var * 2
[ "Expressions", "either", "represent", "mathematical", "operations", "or", "white", "-", "space", "delimited", "Entities", "." ]
13a3962315b61b892f4ad64053cd3a2f67824f74
https://github.com/mapbox/carto/blob/13a3962315b61b892f4ad64053cd3a2f67824f74/lib/carto/parser.js#L763-L775
9,325
mapbox/carto
lib/carto/functions.js
function (val) { var color, mode; if (arguments.length > 1) color = arguments[1]; if (arguments.length > 2) mode = arguments[2]; return { is: 'tag', val: val, color: color, mode: mode, toString: function(env) { var attr = {}; _.set(attr, 'value', val.ev(env).toString()); if (color) { _.set(attr, 'color', color.ev(env).toString()); } if (mode) { _.set(attr, 'mode', mode.ev(env).toString()); } return { '_name': 'stop', '_attributes': attr }; } }; }
javascript
function (val) { var color, mode; if (arguments.length > 1) color = arguments[1]; if (arguments.length > 2) mode = arguments[2]; return { is: 'tag', val: val, color: color, mode: mode, toString: function(env) { var attr = {}; _.set(attr, 'value', val.ev(env).toString()); if (color) { _.set(attr, 'color', color.ev(env).toString()); } if (mode) { _.set(attr, 'mode', mode.ev(env).toString()); } return { '_name': 'stop', '_attributes': attr }; } }; }
[ "function", "(", "val", ")", "{", "var", "color", ",", "mode", ";", "if", "(", "arguments", ".", "length", ">", "1", ")", "color", "=", "arguments", "[", "1", "]", ";", "if", "(", "arguments", ".", "length", ">", "2", ")", "mode", "=", "arguments", "[", "2", "]", ";", "return", "{", "is", ":", "'tag'", ",", "val", ":", "val", ",", "color", ":", "color", ",", "mode", ":", "mode", ",", "toString", ":", "function", "(", "env", ")", "{", "var", "attr", "=", "{", "}", ";", "_", ".", "set", "(", "attr", ",", "'value'", ",", "val", ".", "ev", "(", "env", ")", ".", "toString", "(", ")", ")", ";", "if", "(", "color", ")", "{", "_", ".", "set", "(", "attr", ",", "'color'", ",", "color", ".", "ev", "(", "env", ")", ".", "toString", "(", ")", ")", ";", "}", "if", "(", "mode", ")", "{", "_", ".", "set", "(", "attr", ",", "'mode'", ",", "mode", ".", "ev", "(", "env", ")", ".", "toString", "(", ")", ")", ";", "}", "return", "{", "'_name'", ":", "'stop'", ",", "'_attributes'", ":", "attr", "}", ";", "}", "}", ";", "}" ]
Only require val
[ "Only", "require", "val" ]
13a3962315b61b892f4ad64053cd3a2f67824f74
https://github.com/mapbox/carto/blob/13a3962315b61b892f4ad64053cd3a2f67824f74/lib/carto/functions.js#L28-L54
9,326
mapbox/carto
lib/carto/renderer.js
addRules
function addRules(current, definition, byFilter) { var newFilters = definition.filters, newRules = definition.rules, updatedFilters, clone, previous; // The current definition might have been split up into // multiple definitions already. for (var k = 0; k < current.length; k++) { updatedFilters = current[k].filters.cloneWith(newFilters); if (updatedFilters) { previous = byFilter[updatedFilters]; if (previous) { // There's already a definition with those exact // filters. Add the current definitions' rules // and stop processing it as the existing rule // has already gone down the inheritance chain. previous.addRules(newRules); } else { clone = current[k].clone(updatedFilters); // Make sure that we're only maintaining the clone // when we did actually add rules. If not, there's // no need to keep the clone around. if (clone.addRules(newRules)) { // We inserted an element before this one, so we need // to make sure that in the next loop iteration, we're // not performing the same task for this element again, // hence the k++. byFilter[updatedFilters] = clone; current.splice(k, 0, clone); k++; } } } else if (updatedFilters === null) { // if updatedFilters is null, then adding the filters doesn't // invalidate or split the selector, so we addRules to the // combined selector // Filters can be added, but they don't change the // filters. This means we don't have to split the // definition. // // this is cloned here because of shared classes, see // sharedclass.mss current[k] = current[k].clone(); current[k].addRules(newRules); } // if updatedFeatures is false, then the filters split the rule, // so they aren't the same inheritance chain } return current; }
javascript
function addRules(current, definition, byFilter) { var newFilters = definition.filters, newRules = definition.rules, updatedFilters, clone, previous; // The current definition might have been split up into // multiple definitions already. for (var k = 0; k < current.length; k++) { updatedFilters = current[k].filters.cloneWith(newFilters); if (updatedFilters) { previous = byFilter[updatedFilters]; if (previous) { // There's already a definition with those exact // filters. Add the current definitions' rules // and stop processing it as the existing rule // has already gone down the inheritance chain. previous.addRules(newRules); } else { clone = current[k].clone(updatedFilters); // Make sure that we're only maintaining the clone // when we did actually add rules. If not, there's // no need to keep the clone around. if (clone.addRules(newRules)) { // We inserted an element before this one, so we need // to make sure that in the next loop iteration, we're // not performing the same task for this element again, // hence the k++. byFilter[updatedFilters] = clone; current.splice(k, 0, clone); k++; } } } else if (updatedFilters === null) { // if updatedFilters is null, then adding the filters doesn't // invalidate or split the selector, so we addRules to the // combined selector // Filters can be added, but they don't change the // filters. This means we don't have to split the // definition. // // this is cloned here because of shared classes, see // sharedclass.mss current[k] = current[k].clone(); current[k].addRules(newRules); } // if updatedFeatures is false, then the filters split the rule, // so they aren't the same inheritance chain } return current; }
[ "function", "addRules", "(", "current", ",", "definition", ",", "byFilter", ")", "{", "var", "newFilters", "=", "definition", ".", "filters", ",", "newRules", "=", "definition", ".", "rules", ",", "updatedFilters", ",", "clone", ",", "previous", ";", "// The current definition might have been split up into", "// multiple definitions already.", "for", "(", "var", "k", "=", "0", ";", "k", "<", "current", ".", "length", ";", "k", "++", ")", "{", "updatedFilters", "=", "current", "[", "k", "]", ".", "filters", ".", "cloneWith", "(", "newFilters", ")", ";", "if", "(", "updatedFilters", ")", "{", "previous", "=", "byFilter", "[", "updatedFilters", "]", ";", "if", "(", "previous", ")", "{", "// There's already a definition with those exact", "// filters. Add the current definitions' rules", "// and stop processing it as the existing rule", "// has already gone down the inheritance chain.", "previous", ".", "addRules", "(", "newRules", ")", ";", "}", "else", "{", "clone", "=", "current", "[", "k", "]", ".", "clone", "(", "updatedFilters", ")", ";", "// Make sure that we're only maintaining the clone", "// when we did actually add rules. If not, there's", "// no need to keep the clone around.", "if", "(", "clone", ".", "addRules", "(", "newRules", ")", ")", "{", "// We inserted an element before this one, so we need", "// to make sure that in the next loop iteration, we're", "// not performing the same task for this element again,", "// hence the k++.", "byFilter", "[", "updatedFilters", "]", "=", "clone", ";", "current", ".", "splice", "(", "k", ",", "0", ",", "clone", ")", ";", "k", "++", ";", "}", "}", "}", "else", "if", "(", "updatedFilters", "===", "null", ")", "{", "// if updatedFilters is null, then adding the filters doesn't", "// invalidate or split the selector, so we addRules to the", "// combined selector", "// Filters can be added, but they don't change the", "// filters. This means we don't have to split the", "// definition.", "//", "// this is cloned here because of shared classes, see", "// sharedclass.mss", "current", "[", "k", "]", "=", "current", "[", "k", "]", ".", "clone", "(", ")", ";", "current", "[", "k", "]", ".", "addRules", "(", "newRules", ")", ";", "}", "// if updatedFeatures is false, then the filters split the rule,", "// so they aren't the same inheritance chain", "}", "return", "current", ";", "}" ]
This function currently modifies 'current' @param {Array} current current list of rules @param {Object} definition a Definition object to add to the rules @param {Object} byFilter an object/dictionary of existing filters. This is actually keyed `attachment->filter`
[ "This", "function", "currently", "modifies", "current" ]
13a3962315b61b892f4ad64053cd3a2f67824f74
https://github.com/mapbox/carto/blob/13a3962315b61b892f4ad64053cd3a2f67824f74/lib/carto/renderer.js#L473-L523
9,327
mapbox/carto
lib/carto/renderer.js
inheritDefinitions
function inheritDefinitions(definitions, env) { var inheritTime = +new Date(); // definitions are ordered by specificity, // high (index 0) to low var byAttachment = {}, byFilter = {}; var result = []; var current, attachment; // Evaluate the filters specified by each definition with the given // environment to correctly resolve variable references definitions.forEach(function(d) { d.filters.ev(env); }); for (var i = 0; i < definitions.length; i++) { attachment = definitions[i].attachment; current = [definitions[i]]; if (!byAttachment[attachment]) { byAttachment[attachment] = []; byAttachment[attachment].attachment = attachment; byFilter[attachment] = {}; result.push(byAttachment[attachment]); } // Iterate over all subsequent rules. for (var j = i + 1; j < definitions.length; j++) { if (definitions[j].attachment === attachment) { // Only inherit rules from the same attachment. current = addRules(current, definitions[j], byFilter[attachment]); } } for (var k = 0; k < current.length; k++) { byFilter[attachment][current[k].filters] = current[k]; byAttachment[attachment].push(current[k]); } } if (env.benchmark) console.warn('Inheritance time: ' + ((new Date() - inheritTime)) + 'ms'); return result; }
javascript
function inheritDefinitions(definitions, env) { var inheritTime = +new Date(); // definitions are ordered by specificity, // high (index 0) to low var byAttachment = {}, byFilter = {}; var result = []; var current, attachment; // Evaluate the filters specified by each definition with the given // environment to correctly resolve variable references definitions.forEach(function(d) { d.filters.ev(env); }); for (var i = 0; i < definitions.length; i++) { attachment = definitions[i].attachment; current = [definitions[i]]; if (!byAttachment[attachment]) { byAttachment[attachment] = []; byAttachment[attachment].attachment = attachment; byFilter[attachment] = {}; result.push(byAttachment[attachment]); } // Iterate over all subsequent rules. for (var j = i + 1; j < definitions.length; j++) { if (definitions[j].attachment === attachment) { // Only inherit rules from the same attachment. current = addRules(current, definitions[j], byFilter[attachment]); } } for (var k = 0; k < current.length; k++) { byFilter[attachment][current[k].filters] = current[k]; byAttachment[attachment].push(current[k]); } } if (env.benchmark) console.warn('Inheritance time: ' + ((new Date() - inheritTime)) + 'ms'); return result; }
[ "function", "inheritDefinitions", "(", "definitions", ",", "env", ")", "{", "var", "inheritTime", "=", "+", "new", "Date", "(", ")", ";", "// definitions are ordered by specificity,", "// high (index 0) to low", "var", "byAttachment", "=", "{", "}", ",", "byFilter", "=", "{", "}", ";", "var", "result", "=", "[", "]", ";", "var", "current", ",", "attachment", ";", "// Evaluate the filters specified by each definition with the given", "// environment to correctly resolve variable references", "definitions", ".", "forEach", "(", "function", "(", "d", ")", "{", "d", ".", "filters", ".", "ev", "(", "env", ")", ";", "}", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "definitions", ".", "length", ";", "i", "++", ")", "{", "attachment", "=", "definitions", "[", "i", "]", ".", "attachment", ";", "current", "=", "[", "definitions", "[", "i", "]", "]", ";", "if", "(", "!", "byAttachment", "[", "attachment", "]", ")", "{", "byAttachment", "[", "attachment", "]", "=", "[", "]", ";", "byAttachment", "[", "attachment", "]", ".", "attachment", "=", "attachment", ";", "byFilter", "[", "attachment", "]", "=", "{", "}", ";", "result", ".", "push", "(", "byAttachment", "[", "attachment", "]", ")", ";", "}", "// Iterate over all subsequent rules.", "for", "(", "var", "j", "=", "i", "+", "1", ";", "j", "<", "definitions", ".", "length", ";", "j", "++", ")", "{", "if", "(", "definitions", "[", "j", "]", ".", "attachment", "===", "attachment", ")", "{", "// Only inherit rules from the same attachment.", "current", "=", "addRules", "(", "current", ",", "definitions", "[", "j", "]", ",", "byFilter", "[", "attachment", "]", ")", ";", "}", "}", "for", "(", "var", "k", "=", "0", ";", "k", "<", "current", ".", "length", ";", "k", "++", ")", "{", "byFilter", "[", "attachment", "]", "[", "current", "[", "k", "]", ".", "filters", "]", "=", "current", "[", "k", "]", ";", "byAttachment", "[", "attachment", "]", ".", "push", "(", "current", "[", "k", "]", ")", ";", "}", "}", "if", "(", "env", ".", "benchmark", ")", "console", ".", "warn", "(", "'Inheritance time: '", "+", "(", "(", "new", "Date", "(", ")", "-", "inheritTime", ")", ")", "+", "'ms'", ")", ";", "return", "result", ";", "}" ]
Apply inherited styles from their ancestors to them. called either once per render (in the case of mss) or per layer (for mml) @param {Object} definitions - a list of definitions objects that contain .rules @param {Object} env - the environment @return {Array<Array>} an array of arrays is returned, in which each array refers to a specific attachment
[ "Apply", "inherited", "styles", "from", "their", "ancestors", "to", "them", "." ]
13a3962315b61b892f4ad64053cd3a2f67824f74
https://github.com/mapbox/carto/blob/13a3962315b61b892f4ad64053cd3a2f67824f74/lib/carto/renderer.js#L537-L582
9,328
mapbox/carto
lib/carto/renderer.js
foldStyle
function foldStyle(style) { for (var i = 0; i < style.length; i++) { for (var j = style.length - 1; j > i; j--) { if (style[j].filters.cloneWith(style[i].filters) === null) { style.splice(j, 1); } } } return style; }
javascript
function foldStyle(style) { for (var i = 0; i < style.length; i++) { for (var j = style.length - 1; j > i; j--) { if (style[j].filters.cloneWith(style[i].filters) === null) { style.splice(j, 1); } } } return style; }
[ "function", "foldStyle", "(", "style", ")", "{", "for", "(", "var", "i", "=", "0", ";", "i", "<", "style", ".", "length", ";", "i", "++", ")", "{", "for", "(", "var", "j", "=", "style", ".", "length", "-", "1", ";", "j", ">", "i", ";", "j", "--", ")", "{", "if", "(", "style", "[", "j", "]", ".", "filters", ".", "cloneWith", "(", "style", "[", "i", "]", ".", "filters", ")", "===", "null", ")", "{", "style", ".", "splice", "(", "j", ",", "1", ")", ";", "}", "}", "}", "return", "style", ";", "}" ]
Removes dead style definitions that can never be reached when filter-mode="first". The style is modified in-place and returned. The style must be sorted.
[ "Removes", "dead", "style", "definitions", "that", "can", "never", "be", "reached", "when", "filter", "-", "mode", "=", "first", ".", "The", "style", "is", "modified", "in", "-", "place", "and", "returned", ".", "The", "style", "must", "be", "sorted", "." ]
13a3962315b61b892f4ad64053cd3a2f67824f74
https://github.com/mapbox/carto/blob/13a3962315b61b892f4ad64053cd3a2f67824f74/lib/carto/renderer.js#L611-L620
9,329
mapbox/carto
lib/carto/tree/ruleset.js
function(env) { for (var i = 0; i < this.selectors.length; i++) { var zval = tree.Zoom.all; for (var z = 0; z < this.selectors[i].zoom.length; z++) { zval = zval & this.selectors[i].zoom[z].ev(env).zoom; } this.selectors[i].zoom = zval; } }
javascript
function(env) { for (var i = 0; i < this.selectors.length; i++) { var zval = tree.Zoom.all; for (var z = 0; z < this.selectors[i].zoom.length; z++) { zval = zval & this.selectors[i].zoom[z].ev(env).zoom; } this.selectors[i].zoom = zval; } }
[ "function", "(", "env", ")", "{", "for", "(", "var", "i", "=", "0", ";", "i", "<", "this", ".", "selectors", ".", "length", ";", "i", "++", ")", "{", "var", "zval", "=", "tree", ".", "Zoom", ".", "all", ";", "for", "(", "var", "z", "=", "0", ";", "z", "<", "this", ".", "selectors", "[", "i", "]", ".", "zoom", ".", "length", ";", "z", "++", ")", "{", "zval", "=", "zval", "&", "this", ".", "selectors", "[", "i", "]", ".", "zoom", "[", "z", "]", ".", "ev", "(", "env", ")", ".", "zoom", ";", "}", "this", ".", "selectors", "[", "i", "]", ".", "zoom", "=", "zval", ";", "}", "}" ]
Zooms can use variables. This replaces tree.Zoom objects on selectors with simple bit-arrays that we can compare easily.
[ "Zooms", "can", "use", "variables", ".", "This", "replaces", "tree", ".", "Zoom", "objects", "on", "selectors", "with", "simple", "bit", "-", "arrays", "that", "we", "can", "compare", "easily", "." ]
13a3962315b61b892f4ad64053cd3a2f67824f74
https://github.com/mapbox/carto/blob/13a3962315b61b892f4ad64053cd3a2f67824f74/lib/carto/tree/ruleset.js#L85-L93
9,330
mapbox/carto
lib/carto/tree/definition.js
symbolizerList
function symbolizerList(sym_order) { return sym_order.sort(function(a, b) { return a[1] - b[1]; }) .map(function(v) { return v[0]; }); }
javascript
function symbolizerList(sym_order) { return sym_order.sort(function(a, b) { return a[1] - b[1]; }) .map(function(v) { return v[0]; }); }
[ "function", "symbolizerList", "(", "sym_order", ")", "{", "return", "sym_order", ".", "sort", "(", "function", "(", "a", ",", "b", ")", "{", "return", "a", "[", "1", "]", "-", "b", "[", "1", "]", ";", "}", ")", ".", "map", "(", "function", "(", "v", ")", "{", "return", "v", "[", "0", "]", ";", "}", ")", ";", "}" ]
Get a simple list of the symbolizers, in order
[ "Get", "a", "simple", "list", "of", "the", "symbolizers", "in", "order" ]
13a3962315b61b892f4ad64053cd3a2f67824f74
https://github.com/mapbox/carto/blob/13a3962315b61b892f4ad64053cd3a2f67824f74/lib/carto/tree/definition.js#L96-L99
9,331
mapbox/carto
lib/carto/tree/color.js
function() { if (this.hsl !== null) { if (this.alpha < 1.0) { if (this.perceptual) { return 'rgba(' + hsluv.hsluvToRgb([this.hsl[0], this.hsl[1] * 100, this.hsl[2] * 100]).map(function(c) { return Math.round(c * 255); }).concat(this.round(this.alpha, 2)).join(', ') + ')'; } else { return 'rgba(' + chroma.hsl(this.hsl[0], this.hsl[1], this.hsl[2]).rgb().map(function(c) { return Math.round(c); }).concat(this.round(this.alpha, 2)).join(', ') + ')'; } } else { if (this.perceptual) { return hsluv.hsluvToHex([this.hsl[0], this.hsl[1] * 100, this.hsl[2] * 100]); } else { return chroma.hsl(this.hsl[0], this.hsl[1], this.hsl[2]).hex(); } } } return ''; }
javascript
function() { if (this.hsl !== null) { if (this.alpha < 1.0) { if (this.perceptual) { return 'rgba(' + hsluv.hsluvToRgb([this.hsl[0], this.hsl[1] * 100, this.hsl[2] * 100]).map(function(c) { return Math.round(c * 255); }).concat(this.round(this.alpha, 2)).join(', ') + ')'; } else { return 'rgba(' + chroma.hsl(this.hsl[0], this.hsl[1], this.hsl[2]).rgb().map(function(c) { return Math.round(c); }).concat(this.round(this.alpha, 2)).join(', ') + ')'; } } else { if (this.perceptual) { return hsluv.hsluvToHex([this.hsl[0], this.hsl[1] * 100, this.hsl[2] * 100]); } else { return chroma.hsl(this.hsl[0], this.hsl[1], this.hsl[2]).hex(); } } } return ''; }
[ "function", "(", ")", "{", "if", "(", "this", ".", "hsl", "!==", "null", ")", "{", "if", "(", "this", ".", "alpha", "<", "1.0", ")", "{", "if", "(", "this", ".", "perceptual", ")", "{", "return", "'rgba('", "+", "hsluv", ".", "hsluvToRgb", "(", "[", "this", ".", "hsl", "[", "0", "]", ",", "this", ".", "hsl", "[", "1", "]", "*", "100", ",", "this", ".", "hsl", "[", "2", "]", "*", "100", "]", ")", ".", "map", "(", "function", "(", "c", ")", "{", "return", "Math", ".", "round", "(", "c", "*", "255", ")", ";", "}", ")", ".", "concat", "(", "this", ".", "round", "(", "this", ".", "alpha", ",", "2", ")", ")", ".", "join", "(", "', '", ")", "+", "')'", ";", "}", "else", "{", "return", "'rgba('", "+", "chroma", ".", "hsl", "(", "this", ".", "hsl", "[", "0", "]", ",", "this", ".", "hsl", "[", "1", "]", ",", "this", ".", "hsl", "[", "2", "]", ")", ".", "rgb", "(", ")", ".", "map", "(", "function", "(", "c", ")", "{", "return", "Math", ".", "round", "(", "c", ")", ";", "}", ")", ".", "concat", "(", "this", ".", "round", "(", "this", ".", "alpha", ",", "2", ")", ")", ".", "join", "(", "', '", ")", "+", "')'", ";", "}", "}", "else", "{", "if", "(", "this", ".", "perceptual", ")", "{", "return", "hsluv", ".", "hsluvToHex", "(", "[", "this", ".", "hsl", "[", "0", "]", ",", "this", ".", "hsl", "[", "1", "]", "*", "100", ",", "this", ".", "hsl", "[", "2", "]", "*", "100", "]", ")", ";", "}", "else", "{", "return", "chroma", ".", "hsl", "(", "this", ".", "hsl", "[", "0", "]", ",", "this", ".", "hsl", "[", "1", "]", ",", "this", ".", "hsl", "[", "2", "]", ")", ".", "hex", "(", ")", ";", "}", "}", "}", "return", "''", ";", "}" ]
If we have some transparency, the only way to represent it is via `rgba`. Otherwise, we use the hex representation, which has better compatibility with older browsers.
[ "If", "we", "have", "some", "transparency", "the", "only", "way", "to", "represent", "it", "is", "via", "rgba", ".", "Otherwise", "we", "use", "the", "hex", "representation", "which", "has", "better", "compatibility", "with", "older", "browsers", "." ]
13a3962315b61b892f4ad64053cd3a2f67824f74
https://github.com/mapbox/carto/blob/13a3962315b61b892f4ad64053cd3a2f67824f74/lib/carto/tree/color.js#L41-L64
9,332
mapbox/carto
lib/carto/tree/color.js
function(env, op, other) { var result = [], rgb2; if (other instanceof tree.Color) { rgb2 = chroma(other.toString()).rgb(); } else if (_.isArray(other)) { rgb2 = _.slice(other, 0, Math.max(other.length, 3)); } else if (_.isObject(other)) { if (_.has(other, 'value')) { rgb2 = [other.value, other.value, other.value]; } else { return; } } else { rgb2 = [other, other, other]; } var rgb1 = chroma(this.toString()).rgb(); for (var c = 0; c < 3; c++) { result[c] = tree.operate(op, rgb1[c] , rgb2[c]); } if (this.perceptual) { var normalize = function (x) { return x / 255; }; result = hsluv.rgbToHsluv(_.map(result, normalize)); result[1] = result[1] / 100; result[2] = result[2] / 100; } else { result = chroma(result).hsl(); } return new tree.Color(result, this.alpha, this.perceptual); }
javascript
function(env, op, other) { var result = [], rgb2; if (other instanceof tree.Color) { rgb2 = chroma(other.toString()).rgb(); } else if (_.isArray(other)) { rgb2 = _.slice(other, 0, Math.max(other.length, 3)); } else if (_.isObject(other)) { if (_.has(other, 'value')) { rgb2 = [other.value, other.value, other.value]; } else { return; } } else { rgb2 = [other, other, other]; } var rgb1 = chroma(this.toString()).rgb(); for (var c = 0; c < 3; c++) { result[c] = tree.operate(op, rgb1[c] , rgb2[c]); } if (this.perceptual) { var normalize = function (x) { return x / 255; }; result = hsluv.rgbToHsluv(_.map(result, normalize)); result[1] = result[1] / 100; result[2] = result[2] / 100; } else { result = chroma(result).hsl(); } return new tree.Color(result, this.alpha, this.perceptual); }
[ "function", "(", "env", ",", "op", ",", "other", ")", "{", "var", "result", "=", "[", "]", ",", "rgb2", ";", "if", "(", "other", "instanceof", "tree", ".", "Color", ")", "{", "rgb2", "=", "chroma", "(", "other", ".", "toString", "(", ")", ")", ".", "rgb", "(", ")", ";", "}", "else", "if", "(", "_", ".", "isArray", "(", "other", ")", ")", "{", "rgb2", "=", "_", ".", "slice", "(", "other", ",", "0", ",", "Math", ".", "max", "(", "other", ".", "length", ",", "3", ")", ")", ";", "}", "else", "if", "(", "_", ".", "isObject", "(", "other", ")", ")", "{", "if", "(", "_", ".", "has", "(", "other", ",", "'value'", ")", ")", "{", "rgb2", "=", "[", "other", ".", "value", ",", "other", ".", "value", ",", "other", ".", "value", "]", ";", "}", "else", "{", "return", ";", "}", "}", "else", "{", "rgb2", "=", "[", "other", ",", "other", ",", "other", "]", ";", "}", "var", "rgb1", "=", "chroma", "(", "this", ".", "toString", "(", ")", ")", ".", "rgb", "(", ")", ";", "for", "(", "var", "c", "=", "0", ";", "c", "<", "3", ";", "c", "++", ")", "{", "result", "[", "c", "]", "=", "tree", ".", "operate", "(", "op", ",", "rgb1", "[", "c", "]", ",", "rgb2", "[", "c", "]", ")", ";", "}", "if", "(", "this", ".", "perceptual", ")", "{", "var", "normalize", "=", "function", "(", "x", ")", "{", "return", "x", "/", "255", ";", "}", ";", "result", "=", "hsluv", ".", "rgbToHsluv", "(", "_", ".", "map", "(", "result", ",", "normalize", ")", ")", ";", "result", "[", "1", "]", "=", "result", "[", "1", "]", "/", "100", ";", "result", "[", "2", "]", "=", "result", "[", "2", "]", "/", "100", ";", "}", "else", "{", "result", "=", "chroma", "(", "result", ")", ".", "hsl", "(", ")", ";", "}", "return", "new", "tree", ".", "Color", "(", "result", ",", "this", ".", "alpha", ",", "this", ".", "perceptual", ")", ";", "}" ]
Operations have to be done in RGB per-channel, if not, channels will spill onto each other. Once we have our result, in the form of an integer triplet, we create a new Color node to hold the result.
[ "Operations", "have", "to", "be", "done", "in", "RGB", "per", "-", "channel", "if", "not", "channels", "will", "spill", "onto", "each", "other", ".", "Once", "we", "have", "our", "result", "in", "the", "form", "of", "an", "integer", "triplet", "we", "create", "a", "new", "Color", "node", "to", "hold", "the", "result", "." ]
13a3962315b61b892f4ad64053cd3a2f67824f74
https://github.com/mapbox/carto/blob/13a3962315b61b892f4ad64053cd3a2f67824f74/lib/carto/tree/color.js#L100-L141
9,333
mozilla-comm/ical.js
build/ical.js
function(vcal) { var allsubs, properties, vtimezones, reqTzid, i, tzid; if (!vcal || vcal.name !== "vcalendar") { //not a top-level vcalendar component return vcal; } //Store vtimezone subcomponents in an object reference by tzid. //Store properties from everything else in another array allsubs = vcal.getAllSubcomponents(); properties = []; vtimezones = {}; for (i = 0; i < allsubs.length; i++) { if (allsubs[i].name === "vtimezone") { tzid = allsubs[i].getFirstProperty("tzid").getFirstValue(); vtimezones[tzid] = allsubs[i]; } else { properties = properties.concat(allsubs[i].getAllProperties()); } } //create an object with one entry for each required tz reqTzid = {}; for (i = 0; i < properties.length; i++) { if ((tzid = properties[i].getParameter("tzid"))) { reqTzid[tzid] = true; } } //delete any vtimezones that are not on the reqTzid list. for (i in vtimezones) { if (vtimezones.hasOwnProperty(i) && !reqTzid[i]) { vcal.removeSubcomponent(vtimezones[i]); } } //create any missing, but registered timezones for (i in reqTzid) { if ( reqTzid.hasOwnProperty(i) && !vtimezones[i] && ICAL.TimezoneService.has(i) ) { vcal.addSubcomponent(ICAL.TimezoneService.get(i).component); } } return vcal; }
javascript
function(vcal) { var allsubs, properties, vtimezones, reqTzid, i, tzid; if (!vcal || vcal.name !== "vcalendar") { //not a top-level vcalendar component return vcal; } //Store vtimezone subcomponents in an object reference by tzid. //Store properties from everything else in another array allsubs = vcal.getAllSubcomponents(); properties = []; vtimezones = {}; for (i = 0; i < allsubs.length; i++) { if (allsubs[i].name === "vtimezone") { tzid = allsubs[i].getFirstProperty("tzid").getFirstValue(); vtimezones[tzid] = allsubs[i]; } else { properties = properties.concat(allsubs[i].getAllProperties()); } } //create an object with one entry for each required tz reqTzid = {}; for (i = 0; i < properties.length; i++) { if ((tzid = properties[i].getParameter("tzid"))) { reqTzid[tzid] = true; } } //delete any vtimezones that are not on the reqTzid list. for (i in vtimezones) { if (vtimezones.hasOwnProperty(i) && !reqTzid[i]) { vcal.removeSubcomponent(vtimezones[i]); } } //create any missing, but registered timezones for (i in reqTzid) { if ( reqTzid.hasOwnProperty(i) && !vtimezones[i] && ICAL.TimezoneService.has(i) ) { vcal.addSubcomponent(ICAL.TimezoneService.get(i).component); } } return vcal; }
[ "function", "(", "vcal", ")", "{", "var", "allsubs", ",", "properties", ",", "vtimezones", ",", "reqTzid", ",", "i", ",", "tzid", ";", "if", "(", "!", "vcal", "||", "vcal", ".", "name", "!==", "\"vcalendar\"", ")", "{", "//not a top-level vcalendar component", "return", "vcal", ";", "}", "//Store vtimezone subcomponents in an object reference by tzid.", "//Store properties from everything else in another array", "allsubs", "=", "vcal", ".", "getAllSubcomponents", "(", ")", ";", "properties", "=", "[", "]", ";", "vtimezones", "=", "{", "}", ";", "for", "(", "i", "=", "0", ";", "i", "<", "allsubs", ".", "length", ";", "i", "++", ")", "{", "if", "(", "allsubs", "[", "i", "]", ".", "name", "===", "\"vtimezone\"", ")", "{", "tzid", "=", "allsubs", "[", "i", "]", ".", "getFirstProperty", "(", "\"tzid\"", ")", ".", "getFirstValue", "(", ")", ";", "vtimezones", "[", "tzid", "]", "=", "allsubs", "[", "i", "]", ";", "}", "else", "{", "properties", "=", "properties", ".", "concat", "(", "allsubs", "[", "i", "]", ".", "getAllProperties", "(", ")", ")", ";", "}", "}", "//create an object with one entry for each required tz", "reqTzid", "=", "{", "}", ";", "for", "(", "i", "=", "0", ";", "i", "<", "properties", ".", "length", ";", "i", "++", ")", "{", "if", "(", "(", "tzid", "=", "properties", "[", "i", "]", ".", "getParameter", "(", "\"tzid\"", ")", ")", ")", "{", "reqTzid", "[", "tzid", "]", "=", "true", ";", "}", "}", "//delete any vtimezones that are not on the reqTzid list.", "for", "(", "i", "in", "vtimezones", ")", "{", "if", "(", "vtimezones", ".", "hasOwnProperty", "(", "i", ")", "&&", "!", "reqTzid", "[", "i", "]", ")", "{", "vcal", ".", "removeSubcomponent", "(", "vtimezones", "[", "i", "]", ")", ";", "}", "}", "//create any missing, but registered timezones", "for", "(", "i", "in", "reqTzid", ")", "{", "if", "(", "reqTzid", ".", "hasOwnProperty", "(", "i", ")", "&&", "!", "vtimezones", "[", "i", "]", "&&", "ICAL", ".", "TimezoneService", ".", "has", "(", "i", ")", ")", "{", "vcal", ".", "addSubcomponent", "(", "ICAL", ".", "TimezoneService", ".", "get", "(", "i", ")", ".", "component", ")", ";", "}", "}", "return", "vcal", ";", "}" ]
Compiles a list of all referenced TZIDs in all subcomponents and removes any extra VTIMEZONE subcomponents. In addition, if any TZIDs are referenced by a component, but a VTIMEZONE does not exist, an attempt will be made to generate a VTIMEZONE using ICAL.TimezoneService. @param {ICAL.Component} vcal The top-level VCALENDAR component. @return {ICAL.Component} The ICAL.Component that was passed in.
[ "Compiles", "a", "list", "of", "all", "referenced", "TZIDs", "in", "all", "subcomponents", "and", "removes", "any", "extra", "VTIMEZONE", "subcomponents", ".", "In", "addition", "if", "any", "TZIDs", "are", "referenced", "by", "a", "component", "but", "a", "VTIMEZONE", "does", "not", "exist", "an", "attempt", "will", "be", "made", "to", "generate", "a", "VTIMEZONE", "using", "ICAL", ".", "TimezoneService", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L50-L99
9,334
mozilla-comm/ical.js
build/ical.js
function(string) { var result = parseInt(string, 10); if (ICAL.helpers.isStrictlyNaN(result)) { throw new Error( 'Could not extract integer from "' + string + '"' ); } return result; }
javascript
function(string) { var result = parseInt(string, 10); if (ICAL.helpers.isStrictlyNaN(result)) { throw new Error( 'Could not extract integer from "' + string + '"' ); } return result; }
[ "function", "(", "string", ")", "{", "var", "result", "=", "parseInt", "(", "string", ",", "10", ")", ";", "if", "(", "ICAL", ".", "helpers", ".", "isStrictlyNaN", "(", "result", ")", ")", "{", "throw", "new", "Error", "(", "'Could not extract integer from \"'", "+", "string", "+", "'\"'", ")", ";", "}", "return", "result", ";", "}" ]
Parses a string value that is expected to be an integer, when the valid is not an integer throws a decoration error. @param {String} string Raw string input @return {Number} Parsed integer
[ "Parses", "a", "string", "value", "that", "is", "expected", "to", "be", "an", "integer", "when", "the", "valid", "is", "not", "an", "integer", "throws", "a", "decoration", "error", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L118-L128
9,335
mozilla-comm/ical.js
build/ical.js
formatClassType
function formatClassType(data, type) { if (typeof(data) === 'undefined') { return undefined; } if (data instanceof type) { return data; } return new type(data); }
javascript
function formatClassType(data, type) { if (typeof(data) === 'undefined') { return undefined; } if (data instanceof type) { return data; } return new type(data); }
[ "function", "formatClassType", "(", "data", ",", "type", ")", "{", "if", "(", "typeof", "(", "data", ")", "===", "'undefined'", ")", "{", "return", "undefined", ";", "}", "if", "(", "data", "instanceof", "type", ")", "{", "return", "data", ";", "}", "return", "new", "type", "(", "data", ")", ";", "}" ]
Creates or returns a class instance of a given type with the initialization data if the data is not already an instance of the given type. @example var time = new ICAL.Time(...); var result = ICAL.helpers.formatClassType(time, ICAL.Time); (result instanceof ICAL.Time) // => true result = ICAL.helpers.formatClassType({}, ICAL.Time); (result isntanceof ICAL.Time) // => true @param {Object} data object initialization data @param {Object} type object type (like ICAL.Time) @return {?} An instance of the found type.
[ "Creates", "or", "returns", "a", "class", "instance", "of", "a", "given", "type", "with", "the", "initialization", "data", "if", "the", "data", "is", "not", "already", "an", "instance", "of", "the", "given", "type", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L150-L159
9,336
mozilla-comm/ical.js
build/ical.js
function(buffer, search, pos) { while ((pos = buffer.indexOf(search, pos)) !== -1) { if (pos > 0 && buffer[pos - 1] === '\\') { pos += 1; } else { return pos; } } return -1; }
javascript
function(buffer, search, pos) { while ((pos = buffer.indexOf(search, pos)) !== -1) { if (pos > 0 && buffer[pos - 1] === '\\') { pos += 1; } else { return pos; } } return -1; }
[ "function", "(", "buffer", ",", "search", ",", "pos", ")", "{", "while", "(", "(", "pos", "=", "buffer", ".", "indexOf", "(", "search", ",", "pos", ")", ")", "!==", "-", "1", ")", "{", "if", "(", "pos", ">", "0", "&&", "buffer", "[", "pos", "-", "1", "]", "===", "'\\\\'", ")", "{", "pos", "+=", "1", ";", "}", "else", "{", "return", "pos", ";", "}", "}", "return", "-", "1", ";", "}" ]
Identical to indexOf but will only match values when they are not preceded by a backslash character. @param {String} buffer String to search @param {String} search Value to look for @param {Number} pos Start position @return {Number} The position, or -1 if not found
[ "Identical", "to", "indexOf", "but", "will", "only", "match", "values", "when", "they", "are", "not", "preceded", "by", "a", "backslash", "character", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L170-L179
9,337
mozilla-comm/ical.js
build/ical.js
function(list, seekVal, cmpfunc) { if (!list.length) return 0; var low = 0, high = list.length - 1, mid, cmpval; while (low <= high) { mid = low + Math.floor((high - low) / 2); cmpval = cmpfunc(seekVal, list[mid]); if (cmpval < 0) high = mid - 1; else if (cmpval > 0) low = mid + 1; else break; } if (cmpval < 0) return mid; // insertion is displacing, so use mid outright. else if (cmpval > 0) return mid + 1; else return mid; }
javascript
function(list, seekVal, cmpfunc) { if (!list.length) return 0; var low = 0, high = list.length - 1, mid, cmpval; while (low <= high) { mid = low + Math.floor((high - low) / 2); cmpval = cmpfunc(seekVal, list[mid]); if (cmpval < 0) high = mid - 1; else if (cmpval > 0) low = mid + 1; else break; } if (cmpval < 0) return mid; // insertion is displacing, so use mid outright. else if (cmpval > 0) return mid + 1; else return mid; }
[ "function", "(", "list", ",", "seekVal", ",", "cmpfunc", ")", "{", "if", "(", "!", "list", ".", "length", ")", "return", "0", ";", "var", "low", "=", "0", ",", "high", "=", "list", ".", "length", "-", "1", ",", "mid", ",", "cmpval", ";", "while", "(", "low", "<=", "high", ")", "{", "mid", "=", "low", "+", "Math", ".", "floor", "(", "(", "high", "-", "low", ")", "/", "2", ")", ";", "cmpval", "=", "cmpfunc", "(", "seekVal", ",", "list", "[", "mid", "]", ")", ";", "if", "(", "cmpval", "<", "0", ")", "high", "=", "mid", "-", "1", ";", "else", "if", "(", "cmpval", ">", "0", ")", "low", "=", "mid", "+", "1", ";", "else", "break", ";", "}", "if", "(", "cmpval", "<", "0", ")", "return", "mid", ";", "// insertion is displacing, so use mid outright.", "else", "if", "(", "cmpval", ">", "0", ")", "return", "mid", "+", "1", ";", "else", "return", "mid", ";", "}" ]
Find the index for insertion using binary search. @param {Array} list The list to search @param {?} seekVal The value to insert @param {function(?,?)} cmpfunc The comparison func, that can compare two seekVals @return {Number} The insert position
[ "Find", "the", "index", "for", "insertion", "using", "binary", "search", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L190-L215
9,338
mozilla-comm/ical.js
build/ical.js
function() { if (!ICAL.debug) { return; } if (typeof (console) !== 'undefined' && 'log' in console) { ICAL.helpers.dumpn = function consoleDumpn(input) { console.log(input); }; } else { ICAL.helpers.dumpn = function geckoDumpn(input) { dump(input + '\n'); }; } ICAL.helpers.dumpn(arguments[0]); }
javascript
function() { if (!ICAL.debug) { return; } if (typeof (console) !== 'undefined' && 'log' in console) { ICAL.helpers.dumpn = function consoleDumpn(input) { console.log(input); }; } else { ICAL.helpers.dumpn = function geckoDumpn(input) { dump(input + '\n'); }; } ICAL.helpers.dumpn(arguments[0]); }
[ "function", "(", ")", "{", "if", "(", "!", "ICAL", ".", "debug", ")", "{", "return", ";", "}", "if", "(", "typeof", "(", "console", ")", "!==", "'undefined'", "&&", "'log'", "in", "console", ")", "{", "ICAL", ".", "helpers", ".", "dumpn", "=", "function", "consoleDumpn", "(", "input", ")", "{", "console", ".", "log", "(", "input", ")", ";", "}", ";", "}", "else", "{", "ICAL", ".", "helpers", ".", "dumpn", "=", "function", "geckoDumpn", "(", "input", ")", "{", "dump", "(", "input", "+", "'\\n'", ")", ";", "}", ";", "}", "ICAL", ".", "helpers", ".", "dumpn", "(", "arguments", "[", "0", "]", ")", ";", "}" ]
Convenience function for debug output @private
[ "Convenience", "function", "for", "debug", "output" ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L221-L237
9,339
mozilla-comm/ical.js
build/ical.js
function(aSrc, aDeep) { if (!aSrc || typeof aSrc != "object") { return aSrc; } else if (aSrc instanceof Date) { return new Date(aSrc.getTime()); } else if ("clone" in aSrc) { return aSrc.clone(); } else if (Array.isArray(aSrc)) { var arr = []; for (var i = 0; i < aSrc.length; i++) { arr.push(aDeep ? ICAL.helpers.clone(aSrc[i], true) : aSrc[i]); } return arr; } else { var obj = {}; for (var name in aSrc) { // uses prototype method to allow use of Object.create(null); /* istanbul ignore else */ if (Object.prototype.hasOwnProperty.call(aSrc, name)) { if (aDeep) { obj[name] = ICAL.helpers.clone(aSrc[name], true); } else { obj[name] = aSrc[name]; } } } return obj; } }
javascript
function(aSrc, aDeep) { if (!aSrc || typeof aSrc != "object") { return aSrc; } else if (aSrc instanceof Date) { return new Date(aSrc.getTime()); } else if ("clone" in aSrc) { return aSrc.clone(); } else if (Array.isArray(aSrc)) { var arr = []; for (var i = 0; i < aSrc.length; i++) { arr.push(aDeep ? ICAL.helpers.clone(aSrc[i], true) : aSrc[i]); } return arr; } else { var obj = {}; for (var name in aSrc) { // uses prototype method to allow use of Object.create(null); /* istanbul ignore else */ if (Object.prototype.hasOwnProperty.call(aSrc, name)) { if (aDeep) { obj[name] = ICAL.helpers.clone(aSrc[name], true); } else { obj[name] = aSrc[name]; } } } return obj; } }
[ "function", "(", "aSrc", ",", "aDeep", ")", "{", "if", "(", "!", "aSrc", "||", "typeof", "aSrc", "!=", "\"object\"", ")", "{", "return", "aSrc", ";", "}", "else", "if", "(", "aSrc", "instanceof", "Date", ")", "{", "return", "new", "Date", "(", "aSrc", ".", "getTime", "(", ")", ")", ";", "}", "else", "if", "(", "\"clone\"", "in", "aSrc", ")", "{", "return", "aSrc", ".", "clone", "(", ")", ";", "}", "else", "if", "(", "Array", ".", "isArray", "(", "aSrc", ")", ")", "{", "var", "arr", "=", "[", "]", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "aSrc", ".", "length", ";", "i", "++", ")", "{", "arr", ".", "push", "(", "aDeep", "?", "ICAL", ".", "helpers", ".", "clone", "(", "aSrc", "[", "i", "]", ",", "true", ")", ":", "aSrc", "[", "i", "]", ")", ";", "}", "return", "arr", ";", "}", "else", "{", "var", "obj", "=", "{", "}", ";", "for", "(", "var", "name", "in", "aSrc", ")", "{", "// uses prototype method to allow use of Object.create(null);", "/* istanbul ignore else */", "if", "(", "Object", ".", "prototype", ".", "hasOwnProperty", ".", "call", "(", "aSrc", ",", "name", ")", ")", "{", "if", "(", "aDeep", ")", "{", "obj", "[", "name", "]", "=", "ICAL", ".", "helpers", ".", "clone", "(", "aSrc", "[", "name", "]", ",", "true", ")", ";", "}", "else", "{", "obj", "[", "name", "]", "=", "aSrc", "[", "name", "]", ";", "}", "}", "}", "return", "obj", ";", "}", "}" ]
Clone the passed object or primitive. By default a shallow clone will be executed. @param {*} aSrc The thing to clone @param {Boolean=} aDeep If true, a deep clone will be performed @return {*} The copy of the thing
[ "Clone", "the", "passed", "object", "or", "primitive", ".", "By", "default", "a", "shallow", "clone", "will", "be", "executed", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L247-L275
9,340
mozilla-comm/ical.js
build/ical.js
foldline
function foldline(aLine) { var result = ""; var line = aLine || ""; while (line.length) { result += ICAL.newLineChar + " " + line.substr(0, ICAL.foldLength); line = line.substr(ICAL.foldLength); } return result.substr(ICAL.newLineChar.length + 1); }
javascript
function foldline(aLine) { var result = ""; var line = aLine || ""; while (line.length) { result += ICAL.newLineChar + " " + line.substr(0, ICAL.foldLength); line = line.substr(ICAL.foldLength); } return result.substr(ICAL.newLineChar.length + 1); }
[ "function", "foldline", "(", "aLine", ")", "{", "var", "result", "=", "\"\"", ";", "var", "line", "=", "aLine", "||", "\"\"", ";", "while", "(", "line", ".", "length", ")", "{", "result", "+=", "ICAL", ".", "newLineChar", "+", "\" \"", "+", "line", ".", "substr", "(", "0", ",", "ICAL", ".", "foldLength", ")", ";", "line", "=", "line", ".", "substr", "(", "ICAL", ".", "foldLength", ")", ";", "}", "return", "result", ".", "substr", "(", "ICAL", ".", "newLineChar", ".", "length", "+", "1", ")", ";", "}" ]
Performs iCalendar line folding. A line ending character is inserted and the next line begins with a whitespace. @example SUMMARY:This line will be fold ed right in the middle of a word. @param {String} aLine The line to fold @return {String} The folded line
[ "Performs", "iCalendar", "line", "folding", ".", "A", "line", "ending", "character", "is", "inserted", "and", "the", "next", "line", "begins", "with", "a", "whitespace", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L288-L297
9,341
mozilla-comm/ical.js
build/ical.js
pad
function pad(data) { if (typeof(data) !== 'string') { // handle fractions. if (typeof(data) === 'number') { data = parseInt(data); } data = String(data); } var len = data.length; switch (len) { case 0: return '00'; case 1: return '0' + data; default: return data; } }
javascript
function pad(data) { if (typeof(data) !== 'string') { // handle fractions. if (typeof(data) === 'number') { data = parseInt(data); } data = String(data); } var len = data.length; switch (len) { case 0: return '00'; case 1: return '0' + data; default: return data; } }
[ "function", "pad", "(", "data", ")", "{", "if", "(", "typeof", "(", "data", ")", "!==", "'string'", ")", "{", "// handle fractions.", "if", "(", "typeof", "(", "data", ")", "===", "'number'", ")", "{", "data", "=", "parseInt", "(", "data", ")", ";", "}", "data", "=", "String", "(", "data", ")", ";", "}", "var", "len", "=", "data", ".", "length", ";", "switch", "(", "len", ")", "{", "case", "0", ":", "return", "'00'", ";", "case", "1", ":", "return", "'0'", "+", "data", ";", "default", ":", "return", "data", ";", "}", "}" ]
Pads the given string or number with zeros so it will have at least two characters. @param {String|Number} data The string or number to pad @return {String} The number padded as a string
[ "Pads", "the", "given", "string", "or", "number", "with", "zeros", "so", "it", "will", "have", "at", "least", "two", "characters", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L306-L325
9,342
mozilla-comm/ical.js
build/ical.js
function(base, child, extra) { function F() {} F.prototype = base.prototype; child.prototype = new F(); if (extra) { ICAL.helpers.extend(extra, child.prototype); } }
javascript
function(base, child, extra) { function F() {} F.prototype = base.prototype; child.prototype = new F(); if (extra) { ICAL.helpers.extend(extra, child.prototype); } }
[ "function", "(", "base", ",", "child", ",", "extra", ")", "{", "function", "F", "(", ")", "{", "}", "F", ".", "prototype", "=", "base", ".", "prototype", ";", "child", ".", "prototype", "=", "new", "F", "(", ")", ";", "if", "(", "extra", ")", "{", "ICAL", ".", "helpers", ".", "extend", "(", "extra", ",", "child", ".", "prototype", ")", ";", "}", "}" ]
Poor-man's cross-browser inheritance for JavaScript. Doesn't support all the features, but enough for our usage. @param {Function} base The base class constructor function. @param {Function} child The child class constructor function. @param {Object} extra Extends the prototype with extra properties and methods
[ "Poor", "-", "man", "s", "cross", "-", "browser", "inheritance", "for", "JavaScript", ".", "Doesn", "t", "support", "all", "the", "features", "but", "enough", "for", "our", "usage", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L346-L354
9,343
mozilla-comm/ical.js
build/ical.js
function(source, target) { for (var key in source) { var descr = Object.getOwnPropertyDescriptor(source, key); if (descr && !Object.getOwnPropertyDescriptor(target, key)) { Object.defineProperty(target, key, descr); } } return target; }
javascript
function(source, target) { for (var key in source) { var descr = Object.getOwnPropertyDescriptor(source, key); if (descr && !Object.getOwnPropertyDescriptor(target, key)) { Object.defineProperty(target, key, descr); } } return target; }
[ "function", "(", "source", ",", "target", ")", "{", "for", "(", "var", "key", "in", "source", ")", "{", "var", "descr", "=", "Object", ".", "getOwnPropertyDescriptor", "(", "source", ",", "key", ")", ";", "if", "(", "descr", "&&", "!", "Object", ".", "getOwnPropertyDescriptor", "(", "target", ",", "key", ")", ")", "{", "Object", ".", "defineProperty", "(", "target", ",", "key", ",", "descr", ")", ";", "}", "}", "return", "target", ";", "}" ]
Poor-man's cross-browser object extension. Doesn't support all the features, but enough for our usage. Note that the target's properties are not overwritten with the source properties. @example var child = ICAL.helpers.extend(parent, { "bar": 123 }); @param {Object} source The object to extend @param {Object} target The object to extend with @return {Object} Returns the target.
[ "Poor", "-", "man", "s", "cross", "-", "browser", "object", "extension", ".", "Doesn", "t", "support", "all", "the", "features", "but", "enough", "for", "our", "usage", ".", "Note", "that", "the", "target", "s", "properties", "are", "not", "overwritten", "with", "the", "source", "properties", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L370-L378
9,344
mozilla-comm/ical.js
build/ical.js
function(componentName) { var isInDesign = componentName && componentName in design.components; return isInDesign ? design.components[componentName] : design.defaultSet; }
javascript
function(componentName) { var isInDesign = componentName && componentName in design.components; return isInDesign ? design.components[componentName] : design.defaultSet; }
[ "function", "(", "componentName", ")", "{", "var", "isInDesign", "=", "componentName", "&&", "componentName", "in", "design", ".", "components", ";", "return", "isInDesign", "?", "design", ".", "components", "[", "componentName", "]", ":", "design", ".", "defaultSet", ";", "}" ]
Gets the design set for the given component name. @param {String} componentName The name of the component @return {ICAL.design.designSet} The design set for the component
[ "Gets", "the", "design", "set", "for", "the", "given", "component", "name", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L1359-L1362
9,345
mozilla-comm/ical.js
build/ical.js
ParserError
function ParserError(message) { this.message = message; this.name = 'ParserError'; try { throw new Error(); } catch (e) { if (e.stack) { var split = e.stack.split('\n'); split.shift(); this.stack = split.join('\n'); } } }
javascript
function ParserError(message) { this.message = message; this.name = 'ParserError'; try { throw new Error(); } catch (e) { if (e.stack) { var split = e.stack.split('\n'); split.shift(); this.stack = split.join('\n'); } } }
[ "function", "ParserError", "(", "message", ")", "{", "this", ".", "message", "=", "message", ";", "this", ".", "name", "=", "'ParserError'", ";", "try", "{", "throw", "new", "Error", "(", ")", ";", "}", "catch", "(", "e", ")", "{", "if", "(", "e", ".", "stack", ")", "{", "var", "split", "=", "e", ".", "stack", ".", "split", "(", "'\\n'", ")", ";", "split", ".", "shift", "(", ")", ";", "this", ".", "stack", "=", "split", ".", "join", "(", "'\\n'", ")", ";", "}", "}", "}" ]
An error that occurred during parsing. @param {String} message The error message @memberof ICAL.parse @extends {Error} @class
[ "An", "error", "that", "occurred", "during", "parsing", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L1697-L1710
9,346
mozilla-comm/ical.js
build/ical.js
function(name) { if (name) { var i = 0; var comps = this.jCal[COMPONENT_INDEX]; var len = comps.length; for (; i < len; i++) { if (comps[i][NAME_INDEX] === name) { var result = this._hydrateComponent(i); return result; } } } else { if (this.jCal[COMPONENT_INDEX].length) { return this._hydrateComponent(0); } } // ensure we return a value (strict mode) return null; }
javascript
function(name) { if (name) { var i = 0; var comps = this.jCal[COMPONENT_INDEX]; var len = comps.length; for (; i < len; i++) { if (comps[i][NAME_INDEX] === name) { var result = this._hydrateComponent(i); return result; } } } else { if (this.jCal[COMPONENT_INDEX].length) { return this._hydrateComponent(0); } } // ensure we return a value (strict mode) return null; }
[ "function", "(", "name", ")", "{", "if", "(", "name", ")", "{", "var", "i", "=", "0", ";", "var", "comps", "=", "this", ".", "jCal", "[", "COMPONENT_INDEX", "]", ";", "var", "len", "=", "comps", ".", "length", ";", "for", "(", ";", "i", "<", "len", ";", "i", "++", ")", "{", "if", "(", "comps", "[", "i", "]", "[", "NAME_INDEX", "]", "===", "name", ")", "{", "var", "result", "=", "this", ".", "_hydrateComponent", "(", "i", ")", ";", "return", "result", ";", "}", "}", "}", "else", "{", "if", "(", "this", ".", "jCal", "[", "COMPONENT_INDEX", "]", ".", "length", ")", "{", "return", "this", ".", "_hydrateComponent", "(", "0", ")", ";", "}", "}", "// ensure we return a value (strict mode)", "return", "null", ";", "}" ]
Finds first sub component, optionally filtered by name. @param {String=} name Optional name to filter by @return {?ICAL.Component} The found subcomponent
[ "Finds", "first", "sub", "component", "optionally", "filtered", "by", "name", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L2336-L2356
9,347
mozilla-comm/ical.js
build/ical.js
function(name) { var jCalLen = this.jCal[COMPONENT_INDEX].length; var i = 0; if (name) { var comps = this.jCal[COMPONENT_INDEX]; var result = []; for (; i < jCalLen; i++) { if (name === comps[i][NAME_INDEX]) { result.push( this._hydrateComponent(i) ); } } return result; } else { if (!this._components || (this._hydratedComponentCount !== jCalLen)) { for (; i < jCalLen; i++) { this._hydrateComponent(i); } } return this._components || []; } }
javascript
function(name) { var jCalLen = this.jCal[COMPONENT_INDEX].length; var i = 0; if (name) { var comps = this.jCal[COMPONENT_INDEX]; var result = []; for (; i < jCalLen; i++) { if (name === comps[i][NAME_INDEX]) { result.push( this._hydrateComponent(i) ); } } return result; } else { if (!this._components || (this._hydratedComponentCount !== jCalLen)) { for (; i < jCalLen; i++) { this._hydrateComponent(i); } } return this._components || []; } }
[ "function", "(", "name", ")", "{", "var", "jCalLen", "=", "this", ".", "jCal", "[", "COMPONENT_INDEX", "]", ".", "length", ";", "var", "i", "=", "0", ";", "if", "(", "name", ")", "{", "var", "comps", "=", "this", ".", "jCal", "[", "COMPONENT_INDEX", "]", ";", "var", "result", "=", "[", "]", ";", "for", "(", ";", "i", "<", "jCalLen", ";", "i", "++", ")", "{", "if", "(", "name", "===", "comps", "[", "i", "]", "[", "NAME_INDEX", "]", ")", "{", "result", ".", "push", "(", "this", ".", "_hydrateComponent", "(", "i", ")", ")", ";", "}", "}", "return", "result", ";", "}", "else", "{", "if", "(", "!", "this", ".", "_components", "||", "(", "this", ".", "_hydratedComponentCount", "!==", "jCalLen", ")", ")", "{", "for", "(", ";", "i", "<", "jCalLen", ";", "i", "++", ")", "{", "this", ".", "_hydrateComponent", "(", "i", ")", ";", "}", "}", "return", "this", ".", "_components", "||", "[", "]", ";", "}", "}" ]
Finds all sub components, optionally filtering by name. @param {String=} name Optional name to filter by @return {ICAL.Component[]} The found sub components
[ "Finds", "all", "sub", "components", "optionally", "filtering", "by", "name", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L2364-L2390
9,348
mozilla-comm/ical.js
build/ical.js
function(name) { var props = this.jCal[PROPERTY_INDEX]; var len = props.length; var i = 0; for (; i < len; i++) { // 0 is property name if (props[i][NAME_INDEX] === name) { return true; } } return false; }
javascript
function(name) { var props = this.jCal[PROPERTY_INDEX]; var len = props.length; var i = 0; for (; i < len; i++) { // 0 is property name if (props[i][NAME_INDEX] === name) { return true; } } return false; }
[ "function", "(", "name", ")", "{", "var", "props", "=", "this", ".", "jCal", "[", "PROPERTY_INDEX", "]", ";", "var", "len", "=", "props", ".", "length", ";", "var", "i", "=", "0", ";", "for", "(", ";", "i", "<", "len", ";", "i", "++", ")", "{", "// 0 is property name", "if", "(", "props", "[", "i", "]", "[", "NAME_INDEX", "]", "===", "name", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Returns true when a named property exists. @param {String} name The property name @return {Boolean} True, when property is found
[ "Returns", "true", "when", "a", "named", "property", "exists", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L2398-L2411
9,349
mozilla-comm/ical.js
build/ical.js
function(name) { if (name) { var i = 0; var props = this.jCal[PROPERTY_INDEX]; var len = props.length; for (; i < len; i++) { if (props[i][NAME_INDEX] === name) { var result = this._hydrateProperty(i); return result; } } } else { if (this.jCal[PROPERTY_INDEX].length) { return this._hydrateProperty(0); } } return null; }
javascript
function(name) { if (name) { var i = 0; var props = this.jCal[PROPERTY_INDEX]; var len = props.length; for (; i < len; i++) { if (props[i][NAME_INDEX] === name) { var result = this._hydrateProperty(i); return result; } } } else { if (this.jCal[PROPERTY_INDEX].length) { return this._hydrateProperty(0); } } return null; }
[ "function", "(", "name", ")", "{", "if", "(", "name", ")", "{", "var", "i", "=", "0", ";", "var", "props", "=", "this", ".", "jCal", "[", "PROPERTY_INDEX", "]", ";", "var", "len", "=", "props", ".", "length", ";", "for", "(", ";", "i", "<", "len", ";", "i", "++", ")", "{", "if", "(", "props", "[", "i", "]", "[", "NAME_INDEX", "]", "===", "name", ")", "{", "var", "result", "=", "this", ".", "_hydrateProperty", "(", "i", ")", ";", "return", "result", ";", "}", "}", "}", "else", "{", "if", "(", "this", ".", "jCal", "[", "PROPERTY_INDEX", "]", ".", "length", ")", "{", "return", "this", ".", "_hydrateProperty", "(", "0", ")", ";", "}", "}", "return", "null", ";", "}" ]
Finds the first property, optionally with the given name. @param {String=} name Lowercase property name @return {?ICAL.Property} The found property
[ "Finds", "the", "first", "property", "optionally", "with", "the", "given", "name", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L2419-L2438
9,350
mozilla-comm/ical.js
build/ical.js
function(name) { var jCalLen = this.jCal[PROPERTY_INDEX].length; var i = 0; if (name) { var props = this.jCal[PROPERTY_INDEX]; var result = []; for (; i < jCalLen; i++) { if (name === props[i][NAME_INDEX]) { result.push( this._hydrateProperty(i) ); } } return result; } else { if (!this._properties || (this._hydratedPropertyCount !== jCalLen)) { for (; i < jCalLen; i++) { this._hydrateProperty(i); } } return this._properties || []; } }
javascript
function(name) { var jCalLen = this.jCal[PROPERTY_INDEX].length; var i = 0; if (name) { var props = this.jCal[PROPERTY_INDEX]; var result = []; for (; i < jCalLen; i++) { if (name === props[i][NAME_INDEX]) { result.push( this._hydrateProperty(i) ); } } return result; } else { if (!this._properties || (this._hydratedPropertyCount !== jCalLen)) { for (; i < jCalLen; i++) { this._hydrateProperty(i); } } return this._properties || []; } }
[ "function", "(", "name", ")", "{", "var", "jCalLen", "=", "this", ".", "jCal", "[", "PROPERTY_INDEX", "]", ".", "length", ";", "var", "i", "=", "0", ";", "if", "(", "name", ")", "{", "var", "props", "=", "this", ".", "jCal", "[", "PROPERTY_INDEX", "]", ";", "var", "result", "=", "[", "]", ";", "for", "(", ";", "i", "<", "jCalLen", ";", "i", "++", ")", "{", "if", "(", "name", "===", "props", "[", "i", "]", "[", "NAME_INDEX", "]", ")", "{", "result", ".", "push", "(", "this", ".", "_hydrateProperty", "(", "i", ")", ")", ";", "}", "}", "return", "result", ";", "}", "else", "{", "if", "(", "!", "this", ".", "_properties", "||", "(", "this", ".", "_hydratedPropertyCount", "!==", "jCalLen", ")", ")", "{", "for", "(", ";", "i", "<", "jCalLen", ";", "i", "++", ")", "{", "this", ".", "_hydrateProperty", "(", "i", ")", ";", "}", "}", "return", "this", ".", "_properties", "||", "[", "]", ";", "}", "}" ]
Get all properties in the component, optionally filtered by name. @param {String=} name Lowercase property name @return {ICAL.Property[]} List of properties
[ "Get", "all", "properties", "in", "the", "component", "optionally", "filtered", "by", "name", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L2461-L2487
9,351
mozilla-comm/ical.js
build/ical.js
function(component) { if (!this._components) { this._components = []; this._hydratedComponentCount = 0; } if (component.parent) { component.parent.removeSubcomponent(component); } var idx = this.jCal[COMPONENT_INDEX].push(component.jCal); this._components[idx - 1] = component; this._hydratedComponentCount++; component.parent = this; return component; }
javascript
function(component) { if (!this._components) { this._components = []; this._hydratedComponentCount = 0; } if (component.parent) { component.parent.removeSubcomponent(component); } var idx = this.jCal[COMPONENT_INDEX].push(component.jCal); this._components[idx - 1] = component; this._hydratedComponentCount++; component.parent = this; return component; }
[ "function", "(", "component", ")", "{", "if", "(", "!", "this", ".", "_components", ")", "{", "this", ".", "_components", "=", "[", "]", ";", "this", ".", "_hydratedComponentCount", "=", "0", ";", "}", "if", "(", "component", ".", "parent", ")", "{", "component", ".", "parent", ".", "removeSubcomponent", "(", "component", ")", ";", "}", "var", "idx", "=", "this", ".", "jCal", "[", "COMPONENT_INDEX", "]", ".", "push", "(", "component", ".", "jCal", ")", ";", "this", ".", "_components", "[", "idx", "-", "1", "]", "=", "component", ";", "this", ".", "_hydratedComponentCount", "++", ";", "component", ".", "parent", "=", "this", ";", "return", "component", ";", "}" ]
Adds a single sub component. @param {ICAL.Component} component The component to add @return {ICAL.Component} The passed in component
[ "Adds", "a", "single", "sub", "component", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L2553-L2568
9,352
mozilla-comm/ical.js
build/ical.js
function(name, value) { var prop = new ICAL.Property(name); prop.setValue(value); this.addProperty(prop); return prop; }
javascript
function(name, value) { var prop = new ICAL.Property(name); prop.setValue(value); this.addProperty(prop); return prop; }
[ "function", "(", "name", ",", "value", ")", "{", "var", "prop", "=", "new", "ICAL", ".", "Property", "(", "name", ")", ";", "prop", ".", "setValue", "(", "value", ")", ";", "this", ".", "addProperty", "(", "prop", ")", ";", "return", "prop", ";", "}" ]
Helper method to add a property with a value to the component. @param {String} name Property name to add @param {String|Number|Object} value Property value @return {ICAL.Property} The created property
[ "Helper", "method", "to", "add", "a", "property", "with", "a", "value", "to", "the", "component", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L2631-L2638
9,353
mozilla-comm/ical.js
build/ical.js
function(name, value) { var prop = this.getFirstProperty(name); if (prop) { prop.setValue(value); } else { prop = this.addPropertyWithValue(name, value); } return prop; }
javascript
function(name, value) { var prop = this.getFirstProperty(name); if (prop) { prop.setValue(value); } else { prop = this.addPropertyWithValue(name, value); } return prop; }
[ "function", "(", "name", ",", "value", ")", "{", "var", "prop", "=", "this", ".", "getFirstProperty", "(", "name", ")", ";", "if", "(", "prop", ")", "{", "prop", ".", "setValue", "(", "value", ")", ";", "}", "else", "{", "prop", "=", "this", ".", "addPropertyWithValue", "(", "name", ",", "value", ")", ";", "}", "return", "prop", ";", "}" ]
Helper method that will update or create a property of the given name and sets its value. If multiple properties with the given name exist, only the first is updated. @param {String} name Property name to update @param {String|Number|Object} value Property value @return {ICAL.Property} The created property
[ "Helper", "method", "that", "will", "update", "or", "create", "a", "property", "of", "the", "given", "name", "and", "sets", "its", "value", ".", "If", "multiple", "properties", "with", "the", "given", "name", "exist", "only", "the", "first", "is", "updated", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L2649-L2659
9,354
mozilla-comm/ical.js
build/ical.js
function() { var designSet = this._designSet; if (this.type in designSet.value) { var designType = designSet.value[this.type]; if ('decorate' in designSet.value[this.type]) { this.isDecorated = true; } else { this.isDecorated = false; } if (this.name in designSet.property) { this.isMultiValue = ('multiValue' in designSet.property[this.name]); this.isStructuredValue = ('structuredValue' in designSet.property[this.name]); } } }
javascript
function() { var designSet = this._designSet; if (this.type in designSet.value) { var designType = designSet.value[this.type]; if ('decorate' in designSet.value[this.type]) { this.isDecorated = true; } else { this.isDecorated = false; } if (this.name in designSet.property) { this.isMultiValue = ('multiValue' in designSet.property[this.name]); this.isStructuredValue = ('structuredValue' in designSet.property[this.name]); } } }
[ "function", "(", ")", "{", "var", "designSet", "=", "this", ".", "_designSet", ";", "if", "(", "this", ".", "type", "in", "designSet", ".", "value", ")", "{", "var", "designType", "=", "designSet", ".", "value", "[", "this", ".", "type", "]", ";", "if", "(", "'decorate'", "in", "designSet", ".", "value", "[", "this", ".", "type", "]", ")", "{", "this", ".", "isDecorated", "=", "true", ";", "}", "else", "{", "this", ".", "isDecorated", "=", "false", ";", "}", "if", "(", "this", ".", "name", "in", "designSet", ".", "property", ")", "{", "this", ".", "isMultiValue", "=", "(", "'multiValue'", "in", "designSet", ".", "property", "[", "this", ".", "name", "]", ")", ";", "this", ".", "isStructuredValue", "=", "(", "'structuredValue'", "in", "designSet", ".", "property", "[", "this", ".", "name", "]", ")", ";", "}", "}", "}" ]
Updates the type metadata from the current jCal type and design set. @private
[ "Updates", "the", "type", "metadata", "from", "the", "current", "jCal", "type", "and", "design", "set", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L2830-L2847
9,355
mozilla-comm/ical.js
build/ical.js
function(value, index) { if (!this._values) { this._values = []; } if (typeof(value) === 'object' && 'icaltype' in value) { // decorated value this.jCal[VALUE_INDEX + index] = this._undecorate(value); this._values[index] = value; } else { // undecorated value this.jCal[VALUE_INDEX + index] = value; this._values[index] = this._decorate(value); } }
javascript
function(value, index) { if (!this._values) { this._values = []; } if (typeof(value) === 'object' && 'icaltype' in value) { // decorated value this.jCal[VALUE_INDEX + index] = this._undecorate(value); this._values[index] = value; } else { // undecorated value this.jCal[VALUE_INDEX + index] = value; this._values[index] = this._decorate(value); } }
[ "function", "(", "value", ",", "index", ")", "{", "if", "(", "!", "this", ".", "_values", ")", "{", "this", ".", "_values", "=", "[", "]", ";", "}", "if", "(", "typeof", "(", "value", ")", "===", "'object'", "&&", "'icaltype'", "in", "value", ")", "{", "// decorated value", "this", ".", "jCal", "[", "VALUE_INDEX", "+", "index", "]", "=", "this", ".", "_undecorate", "(", "value", ")", ";", "this", ".", "_values", "[", "index", "]", "=", "value", ";", "}", "else", "{", "// undecorated value", "this", ".", "jCal", "[", "VALUE_INDEX", "+", "index", "]", "=", "value", ";", "this", ".", "_values", "[", "index", "]", "=", "this", ".", "_decorate", "(", "value", ")", ";", "}", "}" ]
Sets the value at the given index while also hydrating it. The passed value can either be a decorated or undecorated value. @private @param {?} value The value to set @param {Number} index The index to set it at
[ "Sets", "the", "value", "at", "the", "given", "index", "while", "also", "hydrating", "it", ".", "The", "passed", "value", "can", "either", "be", "a", "decorated", "or", "undecorated", "value", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L2910-L2924
9,356
mozilla-comm/ical.js
build/ical.js
function(name, value) { var lcname = name.toLowerCase(); if (typeof value === "string" && lcname in this._designSet.param && 'multiValue' in this._designSet.param[lcname]) { value = [value]; } this.jCal[PROP_INDEX][name] = value; }
javascript
function(name, value) { var lcname = name.toLowerCase(); if (typeof value === "string" && lcname in this._designSet.param && 'multiValue' in this._designSet.param[lcname]) { value = [value]; } this.jCal[PROP_INDEX][name] = value; }
[ "function", "(", "name", ",", "value", ")", "{", "var", "lcname", "=", "name", ".", "toLowerCase", "(", ")", ";", "if", "(", "typeof", "value", "===", "\"string\"", "&&", "lcname", "in", "this", ".", "_designSet", ".", "param", "&&", "'multiValue'", "in", "this", ".", "_designSet", ".", "param", "[", "lcname", "]", ")", "{", "value", "=", "[", "value", "]", ";", "}", "this", ".", "jCal", "[", "PROP_INDEX", "]", "[", "name", "]", "=", "value", ";", "}" ]
Sets a parameter on the property. @param {String} name The parameter name @param {Array|String} value The parameter value
[ "Sets", "a", "parameter", "on", "the", "property", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L2962-L2970
9,357
mozilla-comm/ical.js
build/ical.js
function() { var name = this.jCal[NAME_INDEX]; var designSet = this._designSet; if (name in designSet.property) { var details = designSet.property[name]; if ('defaultType' in details) { return details.defaultType; } } return design.defaultType; }
javascript
function() { var name = this.jCal[NAME_INDEX]; var designSet = this._designSet; if (name in designSet.property) { var details = designSet.property[name]; if ('defaultType' in details) { return details.defaultType; } } return design.defaultType; }
[ "function", "(", ")", "{", "var", "name", "=", "this", ".", "jCal", "[", "NAME_INDEX", "]", ";", "var", "designSet", "=", "this", ".", "_designSet", ";", "if", "(", "name", "in", "designSet", ".", "property", ")", "{", "var", "details", "=", "designSet", ".", "property", "[", "name", "]", ";", "if", "(", "'defaultType'", "in", "details", ")", "{", "return", "details", ".", "defaultType", ";", "}", "}", "return", "design", ".", "defaultType", ";", "}" ]
Get the default type based on this property's name. @return {String} The default type for this property
[ "Get", "the", "default", "type", "based", "on", "this", "property", "s", "name", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L2986-L2997
9,358
mozilla-comm/ical.js
build/ical.js
function() { var len = this.jCal.length - VALUE_INDEX; if (len < 1) { // its possible for a property to have no value. return []; } var i = 0; var result = []; for (; i < len; i++) { result[i] = this._hydrateValue(i); } return result; }
javascript
function() { var len = this.jCal.length - VALUE_INDEX; if (len < 1) { // its possible for a property to have no value. return []; } var i = 0; var result = []; for (; i < len; i++) { result[i] = this._hydrateValue(i); } return result; }
[ "function", "(", ")", "{", "var", "len", "=", "this", ".", "jCal", ".", "length", "-", "VALUE_INDEX", ";", "if", "(", "len", "<", "1", ")", "{", "// its possible for a property to have no value.", "return", "[", "]", ";", "}", "var", "i", "=", "0", ";", "var", "result", "=", "[", "]", ";", "for", "(", ";", "i", "<", "len", ";", "i", "++", ")", "{", "result", "[", "i", "]", "=", "this", ".", "_hydrateValue", "(", "i", ")", ";", "}", "return", "result", ";", "}" ]
Gets all values on the property. NOTE: this creates an array during each call. @return {Array} List of values
[ "Gets", "all", "values", "on", "the", "property", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L3027-L3043
9,359
mozilla-comm/ical.js
build/ical.js
function(values) { if (!this.isMultiValue) { throw new Error( this.name + ': does not not support mulitValue.\n' + 'override isMultiValue' ); } var len = values.length; var i = 0; this.removeAllValues(); if (len > 0 && typeof(values[0]) === 'object' && 'icaltype' in values[0]) { this.resetType(values[0].icaltype); } if (this.isDecorated) { for (; i < len; i++) { this._setDecoratedValue(values[i], i); } } else { for (; i < len; i++) { this.jCal[VALUE_INDEX + i] = values[i]; } } }
javascript
function(values) { if (!this.isMultiValue) { throw new Error( this.name + ': does not not support mulitValue.\n' + 'override isMultiValue' ); } var len = values.length; var i = 0; this.removeAllValues(); if (len > 0 && typeof(values[0]) === 'object' && 'icaltype' in values[0]) { this.resetType(values[0].icaltype); } if (this.isDecorated) { for (; i < len; i++) { this._setDecoratedValue(values[i], i); } } else { for (; i < len; i++) { this.jCal[VALUE_INDEX + i] = values[i]; } } }
[ "function", "(", "values", ")", "{", "if", "(", "!", "this", ".", "isMultiValue", ")", "{", "throw", "new", "Error", "(", "this", ".", "name", "+", "': does not not support mulitValue.\\n'", "+", "'override isMultiValue'", ")", ";", "}", "var", "len", "=", "values", ".", "length", ";", "var", "i", "=", "0", ";", "this", ".", "removeAllValues", "(", ")", ";", "if", "(", "len", ">", "0", "&&", "typeof", "(", "values", "[", "0", "]", ")", "===", "'object'", "&&", "'icaltype'", "in", "values", "[", "0", "]", ")", "{", "this", ".", "resetType", "(", "values", "[", "0", "]", ".", "icaltype", ")", ";", "}", "if", "(", "this", ".", "isDecorated", ")", "{", "for", "(", ";", "i", "<", "len", ";", "i", "++", ")", "{", "this", ".", "_setDecoratedValue", "(", "values", "[", "i", "]", ",", "i", ")", ";", "}", "}", "else", "{", "for", "(", ";", "i", "<", "len", ";", "i", "++", ")", "{", "this", ".", "jCal", "[", "VALUE_INDEX", "+", "i", "]", "=", "values", "[", "i", "]", ";", "}", "}", "}" ]
Sets the values of the property. Will overwrite the existing values. This can only be used for multi-value properties. @param {Array} values An array of values
[ "Sets", "the", "values", "of", "the", "property", ".", "Will", "overwrite", "the", "existing", "values", ".", "This", "can", "only", "be", "used", "for", "multi", "-", "value", "properties", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L3061-L3088
9,360
mozilla-comm/ical.js
build/ical.js
function(value) { this.removeAllValues(); if (typeof(value) === 'object' && 'icaltype' in value) { this.resetType(value.icaltype); } if (this.isDecorated) { this._setDecoratedValue(value, 0); } else { this.jCal[VALUE_INDEX] = value; } }
javascript
function(value) { this.removeAllValues(); if (typeof(value) === 'object' && 'icaltype' in value) { this.resetType(value.icaltype); } if (this.isDecorated) { this._setDecoratedValue(value, 0); } else { this.jCal[VALUE_INDEX] = value; } }
[ "function", "(", "value", ")", "{", "this", ".", "removeAllValues", "(", ")", ";", "if", "(", "typeof", "(", "value", ")", "===", "'object'", "&&", "'icaltype'", "in", "value", ")", "{", "this", ".", "resetType", "(", "value", ".", "icaltype", ")", ";", "}", "if", "(", "this", ".", "isDecorated", ")", "{", "this", ".", "_setDecoratedValue", "(", "value", ",", "0", ")", ";", "}", "else", "{", "this", ".", "jCal", "[", "VALUE_INDEX", "]", "=", "value", ";", "}", "}" ]
Sets the current value of the property. If this is a multi-value property, all other values will be removed. @param {String|Object} value New property value.
[ "Sets", "the", "current", "value", "of", "the", "property", ".", "If", "this", "is", "a", "multi", "-", "value", "property", "all", "other", "values", "will", "be", "removed", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L3096-L3107
9,361
mozilla-comm/ical.js
build/ical.js
icaltime_compare
function icaltime_compare(other) { var a = this.toSeconds(); var b = other.toSeconds(); return (a > b) - (b > a); }
javascript
function icaltime_compare(other) { var a = this.toSeconds(); var b = other.toSeconds(); return (a > b) - (b > a); }
[ "function", "icaltime_compare", "(", "other", ")", "{", "var", "a", "=", "this", ".", "toSeconds", "(", ")", ";", "var", "b", "=", "other", ".", "toSeconds", "(", ")", ";", "return", "(", "a", ">", "b", ")", "-", "(", "b", ">", "a", ")", ";", "}" ]
Compare this utc offset with another one. @param {ICAL.UtcOffset} other The other offset to compare with @return {Number} -1, 0 or 1 for less/equal/greater
[ "Compare", "this", "utc", "offset", "with", "another", "one", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L3261-L3265
9,362
mozilla-comm/ical.js
build/ical.js
function() { return ICAL.Period.fromData({ start: this.start ? this.start.clone() : null, end: this.end ? this.end.clone() : null, duration: this.duration ? this.duration.clone() : null }); }
javascript
function() { return ICAL.Period.fromData({ start: this.start ? this.start.clone() : null, end: this.end ? this.end.clone() : null, duration: this.duration ? this.duration.clone() : null }); }
[ "function", "(", ")", "{", "return", "ICAL", ".", "Period", ".", "fromData", "(", "{", "start", ":", "this", ".", "start", "?", "this", ".", "start", ".", "clone", "(", ")", ":", "null", ",", "end", ":", "this", ".", "end", "?", "this", ".", "end", ".", "clone", "(", ")", ":", "null", ",", "duration", ":", "this", ".", "duration", "?", "this", ".", "duration", ".", "clone", "(", ")", ":", "null", "}", ")", ";", "}" ]
Returns a clone of the duration object. @return {ICAL.Period} The cloned object
[ "Returns", "a", "clone", "of", "the", "duration", "object", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L3609-L3615
9,363
mozilla-comm/ical.js
build/ical.js
toSeconds
function toSeconds() { var seconds = this.seconds + 60 * this.minutes + 3600 * this.hours + 86400 * this.days + 7 * 86400 * this.weeks; return (this.isNegative ? -seconds : seconds); }
javascript
function toSeconds() { var seconds = this.seconds + 60 * this.minutes + 3600 * this.hours + 86400 * this.days + 7 * 86400 * this.weeks; return (this.isNegative ? -seconds : seconds); }
[ "function", "toSeconds", "(", ")", "{", "var", "seconds", "=", "this", ".", "seconds", "+", "60", "*", "this", ".", "minutes", "+", "3600", "*", "this", ".", "hours", "+", "86400", "*", "this", ".", "days", "+", "7", "*", "86400", "*", "this", ".", "weeks", ";", "return", "(", "this", ".", "isNegative", "?", "-", "seconds", ":", "seconds", ")", ";", "}" ]
The duration value expressed as a number of seconds. @return {Number} The duration value in seconds
[ "The", "duration", "value", "expressed", "as", "a", "number", "of", "seconds", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L3844-L3848
9,364
mozilla-comm/ical.js
build/ical.js
compare
function compare(aOther) { var thisSeconds = this.toSeconds(); var otherSeconds = aOther.toSeconds(); return (thisSeconds > otherSeconds) - (thisSeconds < otherSeconds); }
javascript
function compare(aOther) { var thisSeconds = this.toSeconds(); var otherSeconds = aOther.toSeconds(); return (thisSeconds > otherSeconds) - (thisSeconds < otherSeconds); }
[ "function", "compare", "(", "aOther", ")", "{", "var", "thisSeconds", "=", "this", ".", "toSeconds", "(", ")", ";", "var", "otherSeconds", "=", "aOther", ".", "toSeconds", "(", ")", ";", "return", "(", "thisSeconds", ">", "otherSeconds", ")", "-", "(", "thisSeconds", "<", "otherSeconds", ")", ";", "}" ]
Compares the duration instance with another one. @param {ICAL.Duration} aOther The instance to compare with @return {Number} -1, 0 or 1 for less/equal/greater
[ "Compares", "the", "duration", "instance", "with", "another", "one", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L3930-L3934
9,365
mozilla-comm/ical.js
build/ical.js
parseDurationChunk
function parseDurationChunk(letter, number, object) { var type; switch (letter) { case 'P': if (number && number === '-') { object.isNegative = true; } else { object.isNegative = false; } // period break; case 'D': type = 'days'; break; case 'W': type = 'weeks'; break; case 'H': type = 'hours'; break; case 'M': type = 'minutes'; break; case 'S': type = 'seconds'; break; default: // Not a valid chunk return 0; } if (type) { if (!number && number !== 0) { throw new Error( 'invalid duration value: Missing number before "' + letter + '"' ); } var num = parseInt(number, 10); if (ICAL.helpers.isStrictlyNaN(num)) { throw new Error( 'invalid duration value: Invalid number "' + number + '" before "' + letter + '"' ); } object[type] = num; } return 1; }
javascript
function parseDurationChunk(letter, number, object) { var type; switch (letter) { case 'P': if (number && number === '-') { object.isNegative = true; } else { object.isNegative = false; } // period break; case 'D': type = 'days'; break; case 'W': type = 'weeks'; break; case 'H': type = 'hours'; break; case 'M': type = 'minutes'; break; case 'S': type = 'seconds'; break; default: // Not a valid chunk return 0; } if (type) { if (!number && number !== 0) { throw new Error( 'invalid duration value: Missing number before "' + letter + '"' ); } var num = parseInt(number, 10); if (ICAL.helpers.isStrictlyNaN(num)) { throw new Error( 'invalid duration value: Invalid number "' + number + '" before "' + letter + '"' ); } object[type] = num; } return 1; }
[ "function", "parseDurationChunk", "(", "letter", ",", "number", ",", "object", ")", "{", "var", "type", ";", "switch", "(", "letter", ")", "{", "case", "'P'", ":", "if", "(", "number", "&&", "number", "===", "'-'", ")", "{", "object", ".", "isNegative", "=", "true", ";", "}", "else", "{", "object", ".", "isNegative", "=", "false", ";", "}", "// period", "break", ";", "case", "'D'", ":", "type", "=", "'days'", ";", "break", ";", "case", "'W'", ":", "type", "=", "'weeks'", ";", "break", ";", "case", "'H'", ":", "type", "=", "'hours'", ";", "break", ";", "case", "'M'", ":", "type", "=", "'minutes'", ";", "break", ";", "case", "'S'", ":", "type", "=", "'seconds'", ";", "break", ";", "default", ":", "// Not a valid chunk", "return", "0", ";", "}", "if", "(", "type", ")", "{", "if", "(", "!", "number", "&&", "number", "!==", "0", ")", "{", "throw", "new", "Error", "(", "'invalid duration value: Missing number before \"'", "+", "letter", "+", "'\"'", ")", ";", "}", "var", "num", "=", "parseInt", "(", "number", ",", "10", ")", ";", "if", "(", "ICAL", ".", "helpers", ".", "isStrictlyNaN", "(", "num", ")", ")", "{", "throw", "new", "Error", "(", "'invalid duration value: Invalid number \"'", "+", "number", "+", "'\" before \"'", "+", "letter", "+", "'\"'", ")", ";", "}", "object", "[", "type", "]", "=", "num", ";", "}", "return", "1", ";", "}" ]
Internal helper function to handle a chunk of a duration. @param {String} letter type of duration chunk @param {String} number numeric value or -/+ @param {Object} dict target to assign values to
[ "Internal", "helper", "function", "to", "handle", "a", "chunk", "of", "a", "duration", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L3994-L4041
9,366
mozilla-comm/ical.js
build/ical.js
utcOffset
function utcOffset(tt) { if (this == ICAL.Timezone.utcTimezone || this == ICAL.Timezone.localTimezone) { return 0; } this._ensureCoverage(tt.year); if (!this.changes.length) { return 0; } var tt_change = { year: tt.year, month: tt.month, day: tt.day, hour: tt.hour, minute: tt.minute, second: tt.second }; var change_num = this._findNearbyChange(tt_change); var change_num_to_use = -1; var step = 1; // TODO: replace with bin search? for (;;) { var change = ICAL.helpers.clone(this.changes[change_num], true); if (change.utcOffset < change.prevUtcOffset) { ICAL.Timezone.adjust_change(change, 0, 0, 0, change.utcOffset); } else { ICAL.Timezone.adjust_change(change, 0, 0, 0, change.prevUtcOffset); } var cmp = ICAL.Timezone._compare_change_fn(tt_change, change); if (cmp >= 0) { change_num_to_use = change_num; } else { step = -1; } if (step == -1 && change_num_to_use != -1) { break; } change_num += step; if (change_num < 0) { return 0; } if (change_num >= this.changes.length) { break; } } var zone_change = this.changes[change_num_to_use]; var utcOffset_change = zone_change.utcOffset - zone_change.prevUtcOffset; if (utcOffset_change < 0 && change_num_to_use > 0) { var tmp_change = ICAL.helpers.clone(zone_change, true); ICAL.Timezone.adjust_change(tmp_change, 0, 0, 0, tmp_change.prevUtcOffset); if (ICAL.Timezone._compare_change_fn(tt_change, tmp_change) < 0) { var prev_zone_change = this.changes[change_num_to_use - 1]; var want_daylight = false; // TODO if (zone_change.is_daylight != want_daylight && prev_zone_change.is_daylight == want_daylight) { zone_change = prev_zone_change; } } } // TODO return is_daylight? return zone_change.utcOffset; }
javascript
function utcOffset(tt) { if (this == ICAL.Timezone.utcTimezone || this == ICAL.Timezone.localTimezone) { return 0; } this._ensureCoverage(tt.year); if (!this.changes.length) { return 0; } var tt_change = { year: tt.year, month: tt.month, day: tt.day, hour: tt.hour, minute: tt.minute, second: tt.second }; var change_num = this._findNearbyChange(tt_change); var change_num_to_use = -1; var step = 1; // TODO: replace with bin search? for (;;) { var change = ICAL.helpers.clone(this.changes[change_num], true); if (change.utcOffset < change.prevUtcOffset) { ICAL.Timezone.adjust_change(change, 0, 0, 0, change.utcOffset); } else { ICAL.Timezone.adjust_change(change, 0, 0, 0, change.prevUtcOffset); } var cmp = ICAL.Timezone._compare_change_fn(tt_change, change); if (cmp >= 0) { change_num_to_use = change_num; } else { step = -1; } if (step == -1 && change_num_to_use != -1) { break; } change_num += step; if (change_num < 0) { return 0; } if (change_num >= this.changes.length) { break; } } var zone_change = this.changes[change_num_to_use]; var utcOffset_change = zone_change.utcOffset - zone_change.prevUtcOffset; if (utcOffset_change < 0 && change_num_to_use > 0) { var tmp_change = ICAL.helpers.clone(zone_change, true); ICAL.Timezone.adjust_change(tmp_change, 0, 0, 0, tmp_change.prevUtcOffset); if (ICAL.Timezone._compare_change_fn(tt_change, tmp_change) < 0) { var prev_zone_change = this.changes[change_num_to_use - 1]; var want_daylight = false; // TODO if (zone_change.is_daylight != want_daylight && prev_zone_change.is_daylight == want_daylight) { zone_change = prev_zone_change; } } } // TODO return is_daylight? return zone_change.utcOffset; }
[ "function", "utcOffset", "(", "tt", ")", "{", "if", "(", "this", "==", "ICAL", ".", "Timezone", ".", "utcTimezone", "||", "this", "==", "ICAL", ".", "Timezone", ".", "localTimezone", ")", "{", "return", "0", ";", "}", "this", ".", "_ensureCoverage", "(", "tt", ".", "year", ")", ";", "if", "(", "!", "this", ".", "changes", ".", "length", ")", "{", "return", "0", ";", "}", "var", "tt_change", "=", "{", "year", ":", "tt", ".", "year", ",", "month", ":", "tt", ".", "month", ",", "day", ":", "tt", ".", "day", ",", "hour", ":", "tt", ".", "hour", ",", "minute", ":", "tt", ".", "minute", ",", "second", ":", "tt", ".", "second", "}", ";", "var", "change_num", "=", "this", ".", "_findNearbyChange", "(", "tt_change", ")", ";", "var", "change_num_to_use", "=", "-", "1", ";", "var", "step", "=", "1", ";", "// TODO: replace with bin search?", "for", "(", ";", ";", ")", "{", "var", "change", "=", "ICAL", ".", "helpers", ".", "clone", "(", "this", ".", "changes", "[", "change_num", "]", ",", "true", ")", ";", "if", "(", "change", ".", "utcOffset", "<", "change", ".", "prevUtcOffset", ")", "{", "ICAL", ".", "Timezone", ".", "adjust_change", "(", "change", ",", "0", ",", "0", ",", "0", ",", "change", ".", "utcOffset", ")", ";", "}", "else", "{", "ICAL", ".", "Timezone", ".", "adjust_change", "(", "change", ",", "0", ",", "0", ",", "0", ",", "change", ".", "prevUtcOffset", ")", ";", "}", "var", "cmp", "=", "ICAL", ".", "Timezone", ".", "_compare_change_fn", "(", "tt_change", ",", "change", ")", ";", "if", "(", "cmp", ">=", "0", ")", "{", "change_num_to_use", "=", "change_num", ";", "}", "else", "{", "step", "=", "-", "1", ";", "}", "if", "(", "step", "==", "-", "1", "&&", "change_num_to_use", "!=", "-", "1", ")", "{", "break", ";", "}", "change_num", "+=", "step", ";", "if", "(", "change_num", "<", "0", ")", "{", "return", "0", ";", "}", "if", "(", "change_num", ">=", "this", ".", "changes", ".", "length", ")", "{", "break", ";", "}", "}", "var", "zone_change", "=", "this", ".", "changes", "[", "change_num_to_use", "]", ";", "var", "utcOffset_change", "=", "zone_change", ".", "utcOffset", "-", "zone_change", ".", "prevUtcOffset", ";", "if", "(", "utcOffset_change", "<", "0", "&&", "change_num_to_use", ">", "0", ")", "{", "var", "tmp_change", "=", "ICAL", ".", "helpers", ".", "clone", "(", "zone_change", ",", "true", ")", ";", "ICAL", ".", "Timezone", ".", "adjust_change", "(", "tmp_change", ",", "0", ",", "0", ",", "0", ",", "tmp_change", ".", "prevUtcOffset", ")", ";", "if", "(", "ICAL", ".", "Timezone", ".", "_compare_change_fn", "(", "tt_change", ",", "tmp_change", ")", "<", "0", ")", "{", "var", "prev_zone_change", "=", "this", ".", "changes", "[", "change_num_to_use", "-", "1", "]", ";", "var", "want_daylight", "=", "false", ";", "// TODO", "if", "(", "zone_change", ".", "is_daylight", "!=", "want_daylight", "&&", "prev_zone_change", ".", "is_daylight", "==", "want_daylight", ")", "{", "zone_change", "=", "prev_zone_change", ";", "}", "}", "}", "// TODO return is_daylight?", "return", "zone_change", ".", "utcOffset", ";", "}" ]
Finds the utcOffset the given time would occur in this timezone. @param {ICAL.Time} tt The time to check for @return {Number} utc offset in seconds
[ "Finds", "the", "utcOffset", "the", "given", "time", "would", "occur", "in", "this", "timezone", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L4262-L4341
9,367
mozilla-comm/ical.js
build/ical.js
function(name, timezone) { if (name instanceof ICAL.Component) { if (name.name === 'vtimezone') { timezone = new ICAL.Timezone(name); name = timezone.tzid; } } if (timezone instanceof ICAL.Timezone) { zones[name] = timezone; } else { throw new TypeError('timezone must be ICAL.Timezone or ICAL.Component'); } }
javascript
function(name, timezone) { if (name instanceof ICAL.Component) { if (name.name === 'vtimezone') { timezone = new ICAL.Timezone(name); name = timezone.tzid; } } if (timezone instanceof ICAL.Timezone) { zones[name] = timezone; } else { throw new TypeError('timezone must be ICAL.Timezone or ICAL.Component'); } }
[ "function", "(", "name", ",", "timezone", ")", "{", "if", "(", "name", "instanceof", "ICAL", ".", "Component", ")", "{", "if", "(", "name", ".", "name", "===", "'vtimezone'", ")", "{", "timezone", "=", "new", "ICAL", ".", "Timezone", "(", "name", ")", ";", "name", "=", "timezone", ".", "tzid", ";", "}", "}", "if", "(", "timezone", "instanceof", "ICAL", ".", "Timezone", ")", "{", "zones", "[", "name", "]", "=", "timezone", ";", "}", "else", "{", "throw", "new", "TypeError", "(", "'timezone must be ICAL.Timezone or ICAL.Component'", ")", ";", "}", "}" ]
Registers a timezone object or component. @param {String=} name The name of the timezone. Defaults to the component's TZID if not passed. @param {ICAL.Component|ICAL.Timezone} zone The initialized zone or vtimezone.
[ "Registers", "a", "timezone", "object", "or", "component", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L4689-L4702
9,368
mozilla-comm/ical.js
build/ical.js
icaltime_fromJSDate
function icaltime_fromJSDate(aDate, useUTC) { if (!aDate) { this.reset(); } else { if (useUTC) { this.zone = ICAL.Timezone.utcTimezone; this.year = aDate.getUTCFullYear(); this.month = aDate.getUTCMonth() + 1; this.day = aDate.getUTCDate(); this.hour = aDate.getUTCHours(); this.minute = aDate.getUTCMinutes(); this.second = aDate.getUTCSeconds(); } else { this.zone = ICAL.Timezone.localTimezone; this.year = aDate.getFullYear(); this.month = aDate.getMonth() + 1; this.day = aDate.getDate(); this.hour = aDate.getHours(); this.minute = aDate.getMinutes(); this.second = aDate.getSeconds(); } } this._cachedUnixTime = null; return this; }
javascript
function icaltime_fromJSDate(aDate, useUTC) { if (!aDate) { this.reset(); } else { if (useUTC) { this.zone = ICAL.Timezone.utcTimezone; this.year = aDate.getUTCFullYear(); this.month = aDate.getUTCMonth() + 1; this.day = aDate.getUTCDate(); this.hour = aDate.getUTCHours(); this.minute = aDate.getUTCMinutes(); this.second = aDate.getUTCSeconds(); } else { this.zone = ICAL.Timezone.localTimezone; this.year = aDate.getFullYear(); this.month = aDate.getMonth() + 1; this.day = aDate.getDate(); this.hour = aDate.getHours(); this.minute = aDate.getMinutes(); this.second = aDate.getSeconds(); } } this._cachedUnixTime = null; return this; }
[ "function", "icaltime_fromJSDate", "(", "aDate", ",", "useUTC", ")", "{", "if", "(", "!", "aDate", ")", "{", "this", ".", "reset", "(", ")", ";", "}", "else", "{", "if", "(", "useUTC", ")", "{", "this", ".", "zone", "=", "ICAL", ".", "Timezone", ".", "utcTimezone", ";", "this", ".", "year", "=", "aDate", ".", "getUTCFullYear", "(", ")", ";", "this", ".", "month", "=", "aDate", ".", "getUTCMonth", "(", ")", "+", "1", ";", "this", ".", "day", "=", "aDate", ".", "getUTCDate", "(", ")", ";", "this", ".", "hour", "=", "aDate", ".", "getUTCHours", "(", ")", ";", "this", ".", "minute", "=", "aDate", ".", "getUTCMinutes", "(", ")", ";", "this", ".", "second", "=", "aDate", ".", "getUTCSeconds", "(", ")", ";", "}", "else", "{", "this", ".", "zone", "=", "ICAL", ".", "Timezone", ".", "localTimezone", ";", "this", ".", "year", "=", "aDate", ".", "getFullYear", "(", ")", ";", "this", ".", "month", "=", "aDate", ".", "getMonth", "(", ")", "+", "1", ";", "this", ".", "day", "=", "aDate", ".", "getDate", "(", ")", ";", "this", ".", "hour", "=", "aDate", ".", "getHours", "(", ")", ";", "this", ".", "minute", "=", "aDate", ".", "getMinutes", "(", ")", ";", "this", ".", "second", "=", "aDate", ".", "getSeconds", "(", ")", ";", "}", "}", "this", ".", "_cachedUnixTime", "=", "null", ";", "return", "this", ";", "}" ]
Set up the current instance from the Javascript date value. @param {?Date} aDate The Javascript Date to read, or null to reset @param {Boolean} useUTC If true, the UTC values of the date will be used
[ "Set", "up", "the", "current", "instance", "from", "the", "Javascript", "date", "value", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L4863-L4887
9,369
mozilla-comm/ical.js
build/ical.js
icaltime_dayOfWeek
function icaltime_dayOfWeek() { var dowCacheKey = (this.year << 9) + (this.month << 5) + this.day; if (dowCacheKey in ICAL.Time._dowCache) { return ICAL.Time._dowCache[dowCacheKey]; } // Using Zeller's algorithm var q = this.day; var m = this.month + (this.month < 3 ? 12 : 0); var Y = this.year - (this.month < 3 ? 1 : 0); var h = (q + Y + ICAL.helpers.trunc(((m + 1) * 26) / 10) + ICAL.helpers.trunc(Y / 4)); /* istanbul ignore else */ if (true /* gregorian */) { h += ICAL.helpers.trunc(Y / 100) * 6 + ICAL.helpers.trunc(Y / 400); } else { h += 5; } // Normalize to 1 = sunday h = ((h + 6) % 7) + 1; ICAL.Time._dowCache[dowCacheKey] = h; return h; }
javascript
function icaltime_dayOfWeek() { var dowCacheKey = (this.year << 9) + (this.month << 5) + this.day; if (dowCacheKey in ICAL.Time._dowCache) { return ICAL.Time._dowCache[dowCacheKey]; } // Using Zeller's algorithm var q = this.day; var m = this.month + (this.month < 3 ? 12 : 0); var Y = this.year - (this.month < 3 ? 1 : 0); var h = (q + Y + ICAL.helpers.trunc(((m + 1) * 26) / 10) + ICAL.helpers.trunc(Y / 4)); /* istanbul ignore else */ if (true /* gregorian */) { h += ICAL.helpers.trunc(Y / 100) * 6 + ICAL.helpers.trunc(Y / 400); } else { h += 5; } // Normalize to 1 = sunday h = ((h + 6) % 7) + 1; ICAL.Time._dowCache[dowCacheKey] = h; return h; }
[ "function", "icaltime_dayOfWeek", "(", ")", "{", "var", "dowCacheKey", "=", "(", "this", ".", "year", "<<", "9", ")", "+", "(", "this", ".", "month", "<<", "5", ")", "+", "this", ".", "day", ";", "if", "(", "dowCacheKey", "in", "ICAL", ".", "Time", ".", "_dowCache", ")", "{", "return", "ICAL", ".", "Time", ".", "_dowCache", "[", "dowCacheKey", "]", ";", "}", "// Using Zeller's algorithm", "var", "q", "=", "this", ".", "day", ";", "var", "m", "=", "this", ".", "month", "+", "(", "this", ".", "month", "<", "3", "?", "12", ":", "0", ")", ";", "var", "Y", "=", "this", ".", "year", "-", "(", "this", ".", "month", "<", "3", "?", "1", ":", "0", ")", ";", "var", "h", "=", "(", "q", "+", "Y", "+", "ICAL", ".", "helpers", ".", "trunc", "(", "(", "(", "m", "+", "1", ")", "*", "26", ")", "/", "10", ")", "+", "ICAL", ".", "helpers", ".", "trunc", "(", "Y", "/", "4", ")", ")", ";", "/* istanbul ignore else */", "if", "(", "true", "/* gregorian */", ")", "{", "h", "+=", "ICAL", ".", "helpers", ".", "trunc", "(", "Y", "/", "100", ")", "*", "6", "+", "ICAL", ".", "helpers", ".", "trunc", "(", "Y", "/", "400", ")", ";", "}", "else", "{", "h", "+=", "5", ";", "}", "// Normalize to 1 = sunday", "h", "=", "(", "(", "h", "+", "6", ")", "%", "7", ")", "+", "1", ";", "ICAL", ".", "Time", ".", "_dowCache", "[", "dowCacheKey", "]", "=", "h", ";", "return", "h", ";", "}" ]
Calculate the day of week. @return {ICAL.Time.weekDay}
[ "Calculate", "the", "day", "of", "week", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L4949-L4972
9,370
mozilla-comm/ical.js
build/ical.js
dayOfYear
function dayOfYear() { var is_leap = (ICAL.Time.isLeapYear(this.year) ? 1 : 0); var diypm = ICAL.Time.daysInYearPassedMonth; return diypm[is_leap][this.month - 1] + this.day; }
javascript
function dayOfYear() { var is_leap = (ICAL.Time.isLeapYear(this.year) ? 1 : 0); var diypm = ICAL.Time.daysInYearPassedMonth; return diypm[is_leap][this.month - 1] + this.day; }
[ "function", "dayOfYear", "(", ")", "{", "var", "is_leap", "=", "(", "ICAL", ".", "Time", ".", "isLeapYear", "(", "this", ".", "year", ")", "?", "1", ":", "0", ")", ";", "var", "diypm", "=", "ICAL", ".", "Time", ".", "daysInYearPassedMonth", ";", "return", "diypm", "[", "is_leap", "]", "[", "this", ".", "month", "-", "1", "]", "+", "this", ".", "day", ";", "}" ]
Calculate the day of year. @return {Number}
[ "Calculate", "the", "day", "of", "year", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L4978-L4982
9,371
mozilla-comm/ical.js
build/ical.js
startDoyWeek
function startDoyWeek(aFirstDayOfWeek) { var firstDow = aFirstDayOfWeek || ICAL.Time.SUNDAY; var delta = this.dayOfWeek() - firstDow; if (delta < 0) delta += 7; return this.dayOfYear() - delta; }
javascript
function startDoyWeek(aFirstDayOfWeek) { var firstDow = aFirstDayOfWeek || ICAL.Time.SUNDAY; var delta = this.dayOfWeek() - firstDow; if (delta < 0) delta += 7; return this.dayOfYear() - delta; }
[ "function", "startDoyWeek", "(", "aFirstDayOfWeek", ")", "{", "var", "firstDow", "=", "aFirstDayOfWeek", "||", "ICAL", ".", "Time", ".", "SUNDAY", ";", "var", "delta", "=", "this", ".", "dayOfWeek", "(", ")", "-", "firstDow", ";", "if", "(", "delta", "<", "0", ")", "delta", "+=", "7", ";", "return", "this", ".", "dayOfYear", "(", ")", "-", "delta", ";", "}" ]
First calculates the start of the week, then returns the day of year for this date. If the day falls into the previous year, the day is zero or negative. @param {ICAL.Time.weekDay=} aFirstDayOfWeek The week start weekday, defaults to SUNDAY @return {Number} The calculated day of year
[ "First", "calculates", "the", "start", "of", "the", "week", "then", "returns", "the", "day", "of", "year", "for", "this", "date", ".", "If", "the", "day", "falls", "into", "the", "previous", "year", "the", "day", "is", "zero", "or", "negative", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L5102-L5107
9,372
mozilla-comm/ical.js
build/ical.js
function(aDayOfWeek, aPos) { var dow = this.dayOfWeek(); if (aPos === 0 && dow === aDayOfWeek) { return true; } // get pos var day = this.nthWeekDay(aDayOfWeek, aPos); if (day === this.day) { return true; } return false; }
javascript
function(aDayOfWeek, aPos) { var dow = this.dayOfWeek(); if (aPos === 0 && dow === aDayOfWeek) { return true; } // get pos var day = this.nthWeekDay(aDayOfWeek, aPos); if (day === this.day) { return true; } return false; }
[ "function", "(", "aDayOfWeek", ",", "aPos", ")", "{", "var", "dow", "=", "this", ".", "dayOfWeek", "(", ")", ";", "if", "(", "aPos", "===", "0", "&&", "dow", "===", "aDayOfWeek", ")", "{", "return", "true", ";", "}", "// get pos", "var", "day", "=", "this", ".", "nthWeekDay", "(", "aDayOfWeek", ",", "aPos", ")", ";", "if", "(", "day", "===", "this", ".", "day", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Checks if current time is the nth weekday, relative to the current month. Will always return false when rule resolves outside of current month. @param {ICAL.Time.weekDay} aDayOfWeek Day of week to check @param {Number} aPos Relative position @return {Boolean} True, if its the nth weekday
[ "Checks", "if", "current", "time", "is", "the", "nth", "weekday", "relative", "to", "the", "current", "month", ".", "Will", "always", "return", "false", "when", "rule", "resolves", "outside", "of", "current", "month", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L5216-L5231
9,373
mozilla-comm/ical.js
build/ical.js
weekNumber
function weekNumber(aWeekStart) { var wnCacheKey = (this.year << 12) + (this.month << 8) + (this.day << 3) + aWeekStart; if (wnCacheKey in ICAL.Time._wnCache) { return ICAL.Time._wnCache[wnCacheKey]; } // This function courtesty of Julian Bucknall, published under the MIT license // http://www.boyet.com/articles/publishedarticles/calculatingtheisoweeknumb.html // plus some fixes to be able to use different week starts. var week1; var dt = this.clone(); dt.isDate = true; var isoyear = this.year; if (dt.month == 12 && dt.day > 25) { week1 = ICAL.Time.weekOneStarts(isoyear + 1, aWeekStart); if (dt.compare(week1) < 0) { week1 = ICAL.Time.weekOneStarts(isoyear, aWeekStart); } else { isoyear++; } } else { week1 = ICAL.Time.weekOneStarts(isoyear, aWeekStart); if (dt.compare(week1) < 0) { week1 = ICAL.Time.weekOneStarts(--isoyear, aWeekStart); } } var daysBetween = (dt.subtractDate(week1).toSeconds() / 86400); var answer = ICAL.helpers.trunc(daysBetween / 7) + 1; ICAL.Time._wnCache[wnCacheKey] = answer; return answer; }
javascript
function weekNumber(aWeekStart) { var wnCacheKey = (this.year << 12) + (this.month << 8) + (this.day << 3) + aWeekStart; if (wnCacheKey in ICAL.Time._wnCache) { return ICAL.Time._wnCache[wnCacheKey]; } // This function courtesty of Julian Bucknall, published under the MIT license // http://www.boyet.com/articles/publishedarticles/calculatingtheisoweeknumb.html // plus some fixes to be able to use different week starts. var week1; var dt = this.clone(); dt.isDate = true; var isoyear = this.year; if (dt.month == 12 && dt.day > 25) { week1 = ICAL.Time.weekOneStarts(isoyear + 1, aWeekStart); if (dt.compare(week1) < 0) { week1 = ICAL.Time.weekOneStarts(isoyear, aWeekStart); } else { isoyear++; } } else { week1 = ICAL.Time.weekOneStarts(isoyear, aWeekStart); if (dt.compare(week1) < 0) { week1 = ICAL.Time.weekOneStarts(--isoyear, aWeekStart); } } var daysBetween = (dt.subtractDate(week1).toSeconds() / 86400); var answer = ICAL.helpers.trunc(daysBetween / 7) + 1; ICAL.Time._wnCache[wnCacheKey] = answer; return answer; }
[ "function", "weekNumber", "(", "aWeekStart", ")", "{", "var", "wnCacheKey", "=", "(", "this", ".", "year", "<<", "12", ")", "+", "(", "this", ".", "month", "<<", "8", ")", "+", "(", "this", ".", "day", "<<", "3", ")", "+", "aWeekStart", ";", "if", "(", "wnCacheKey", "in", "ICAL", ".", "Time", ".", "_wnCache", ")", "{", "return", "ICAL", ".", "Time", ".", "_wnCache", "[", "wnCacheKey", "]", ";", "}", "// This function courtesty of Julian Bucknall, published under the MIT license", "// http://www.boyet.com/articles/publishedarticles/calculatingtheisoweeknumb.html", "// plus some fixes to be able to use different week starts.", "var", "week1", ";", "var", "dt", "=", "this", ".", "clone", "(", ")", ";", "dt", ".", "isDate", "=", "true", ";", "var", "isoyear", "=", "this", ".", "year", ";", "if", "(", "dt", ".", "month", "==", "12", "&&", "dt", ".", "day", ">", "25", ")", "{", "week1", "=", "ICAL", ".", "Time", ".", "weekOneStarts", "(", "isoyear", "+", "1", ",", "aWeekStart", ")", ";", "if", "(", "dt", ".", "compare", "(", "week1", ")", "<", "0", ")", "{", "week1", "=", "ICAL", ".", "Time", ".", "weekOneStarts", "(", "isoyear", ",", "aWeekStart", ")", ";", "}", "else", "{", "isoyear", "++", ";", "}", "}", "else", "{", "week1", "=", "ICAL", ".", "Time", ".", "weekOneStarts", "(", "isoyear", ",", "aWeekStart", ")", ";", "if", "(", "dt", ".", "compare", "(", "week1", ")", "<", "0", ")", "{", "week1", "=", "ICAL", ".", "Time", ".", "weekOneStarts", "(", "--", "isoyear", ",", "aWeekStart", ")", ";", "}", "}", "var", "daysBetween", "=", "(", "dt", ".", "subtractDate", "(", "week1", ")", ".", "toSeconds", "(", ")", "/", "86400", ")", ";", "var", "answer", "=", "ICAL", ".", "helpers", ".", "trunc", "(", "daysBetween", "/", "7", ")", "+", "1", ";", "ICAL", ".", "Time", ".", "_wnCache", "[", "wnCacheKey", "]", "=", "answer", ";", "return", "answer", ";", "}" ]
Calculates the ISO 8601 week number. The first week of a year is the week that contains the first Thursday. The year can have 53 weeks, if January 1st is a Friday. Note there are regions where the first week of the year is the one that starts on January 1st, which may offset the week number. Also, if a different week start is specified, this will also affect the week number. @see ICAL.Time.weekOneStarts @param {ICAL.Time.weekDay} aWeekStart The weekday the week starts with @return {Number} The ISO week number
[ "Calculates", "the", "ISO", "8601", "week", "number", ".", "The", "first", "week", "of", "a", "year", "is", "the", "week", "that", "contains", "the", "first", "Thursday", ".", "The", "year", "can", "have", "53", "weeks", "if", "January", "1st", "is", "a", "Friday", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L5247-L5279
9,374
mozilla-comm/ical.js
build/ical.js
icaltime_add
function icaltime_add(aDuration) { var mult = (aDuration.isNegative ? -1 : 1); // because of the duration optimizations it is much // more efficient to grab all the values up front // then set them directly (which will avoid a normalization call). // So we don't actually normalize until we need it. var second = this.second; var minute = this.minute; var hour = this.hour; var day = this.day; second += mult * aDuration.seconds; minute += mult * aDuration.minutes; hour += mult * aDuration.hours; day += mult * aDuration.days; day += mult * 7 * aDuration.weeks; this.second = second; this.minute = minute; this.hour = hour; this.day = day; this._cachedUnixTime = null; }
javascript
function icaltime_add(aDuration) { var mult = (aDuration.isNegative ? -1 : 1); // because of the duration optimizations it is much // more efficient to grab all the values up front // then set them directly (which will avoid a normalization call). // So we don't actually normalize until we need it. var second = this.second; var minute = this.minute; var hour = this.hour; var day = this.day; second += mult * aDuration.seconds; minute += mult * aDuration.minutes; hour += mult * aDuration.hours; day += mult * aDuration.days; day += mult * 7 * aDuration.weeks; this.second = second; this.minute = minute; this.hour = hour; this.day = day; this._cachedUnixTime = null; }
[ "function", "icaltime_add", "(", "aDuration", ")", "{", "var", "mult", "=", "(", "aDuration", ".", "isNegative", "?", "-", "1", ":", "1", ")", ";", "// because of the duration optimizations it is much", "// more efficient to grab all the values up front", "// then set them directly (which will avoid a normalization call).", "// So we don't actually normalize until we need it.", "var", "second", "=", "this", ".", "second", ";", "var", "minute", "=", "this", ".", "minute", ";", "var", "hour", "=", "this", ".", "hour", ";", "var", "day", "=", "this", ".", "day", ";", "second", "+=", "mult", "*", "aDuration", ".", "seconds", ";", "minute", "+=", "mult", "*", "aDuration", ".", "minutes", ";", "hour", "+=", "mult", "*", "aDuration", ".", "hours", ";", "day", "+=", "mult", "*", "aDuration", ".", "days", ";", "day", "+=", "mult", "*", "7", "*", "aDuration", ".", "weeks", ";", "this", ".", "second", "=", "second", ";", "this", ".", "minute", "=", "minute", ";", "this", ".", "hour", "=", "hour", ";", "this", ".", "day", "=", "day", ";", "this", ".", "_cachedUnixTime", "=", "null", ";", "}" ]
Adds the duration to the current time. The instance is modified in place. @param {ICAL.Duration} aDuration The duration to add
[ "Adds", "the", "duration", "to", "the", "current", "time", ".", "The", "instance", "is", "modified", "in", "place", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L5287-L5311
9,375
mozilla-comm/ical.js
build/ical.js
icaltime_subtract_abs
function icaltime_subtract_abs(aDate) { var unixTime = this.toUnixTime(); var other = aDate.toUnixTime(); return ICAL.Duration.fromSeconds(unixTime - other); }
javascript
function icaltime_subtract_abs(aDate) { var unixTime = this.toUnixTime(); var other = aDate.toUnixTime(); return ICAL.Duration.fromSeconds(unixTime - other); }
[ "function", "icaltime_subtract_abs", "(", "aDate", ")", "{", "var", "unixTime", "=", "this", ".", "toUnixTime", "(", ")", ";", "var", "other", "=", "aDate", ".", "toUnixTime", "(", ")", ";", "return", "ICAL", ".", "Duration", ".", "fromSeconds", "(", "unixTime", "-", "other", ")", ";", "}" ]
Subtract the date details, taking timezones into account. @param {ICAL.Time} aDate The date to subtract @return {ICAL.Duration} The difference in duration
[ "Subtract", "the", "date", "details", "taking", "timezones", "into", "account", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L5333-L5337
9,376
mozilla-comm/ical.js
build/ical.js
icaltime_compare
function icaltime_compare(other) { var a = this.toUnixTime(); var b = other.toUnixTime(); if (a > b) return 1; if (b > a) return -1; return 0; }
javascript
function icaltime_compare(other) { var a = this.toUnixTime(); var b = other.toUnixTime(); if (a > b) return 1; if (b > a) return -1; return 0; }
[ "function", "icaltime_compare", "(", "other", ")", "{", "var", "a", "=", "this", ".", "toUnixTime", "(", ")", ";", "var", "b", "=", "other", ".", "toUnixTime", "(", ")", ";", "if", "(", "a", ">", "b", ")", "return", "1", ";", "if", "(", "b", ">", "a", ")", "return", "-", "1", ";", "return", "0", ";", "}" ]
Compares the ICAL.Time instance with another one. @param {ICAL.Duration} aOther The instance to compare with @return {Number} -1, 0 or 1 for less/equal/greater
[ "Compares", "the", "ICAL", ".", "Time", "instance", "with", "another", "one", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L5345-L5352
9,377
mozilla-comm/ical.js
build/ical.js
icaltime_compareDateOnlyTz
function icaltime_compareDateOnlyTz(other, tz) { function cmp(attr) { return ICAL.Time._cmp_attr(a, b, attr); } var a = this.convertToZone(tz); var b = other.convertToZone(tz); var rc = 0; if ((rc = cmp("year")) != 0) return rc; if ((rc = cmp("month")) != 0) return rc; if ((rc = cmp("day")) != 0) return rc; return rc; }
javascript
function icaltime_compareDateOnlyTz(other, tz) { function cmp(attr) { return ICAL.Time._cmp_attr(a, b, attr); } var a = this.convertToZone(tz); var b = other.convertToZone(tz); var rc = 0; if ((rc = cmp("year")) != 0) return rc; if ((rc = cmp("month")) != 0) return rc; if ((rc = cmp("day")) != 0) return rc; return rc; }
[ "function", "icaltime_compareDateOnlyTz", "(", "other", ",", "tz", ")", "{", "function", "cmp", "(", "attr", ")", "{", "return", "ICAL", ".", "Time", ".", "_cmp_attr", "(", "a", ",", "b", ",", "attr", ")", ";", "}", "var", "a", "=", "this", ".", "convertToZone", "(", "tz", ")", ";", "var", "b", "=", "other", ".", "convertToZone", "(", "tz", ")", ";", "var", "rc", "=", "0", ";", "if", "(", "(", "rc", "=", "cmp", "(", "\"year\"", ")", ")", "!=", "0", ")", "return", "rc", ";", "if", "(", "(", "rc", "=", "cmp", "(", "\"month\"", ")", ")", "!=", "0", ")", "return", "rc", ";", "if", "(", "(", "rc", "=", "cmp", "(", "\"day\"", ")", ")", "!=", "0", ")", "return", "rc", ";", "return", "rc", ";", "}" ]
Compares only the date part of this instance with another one. @param {ICAL.Duration} other The instance to compare with @param {ICAL.Timezone} tz The timezone to compare in @return {Number} -1, 0 or 1 for less/equal/greater
[ "Compares", "only", "the", "date", "part", "of", "this", "instance", "with", "another", "one", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L5361-L5374
9,378
mozilla-comm/ical.js
build/ical.js
convertToZone
function convertToZone(zone) { var copy = this.clone(); var zone_equals = (this.zone.tzid == zone.tzid); if (!this.isDate && !zone_equals) { ICAL.Timezone.convert_time(copy, this.zone, zone); } copy.zone = zone; return copy; }
javascript
function convertToZone(zone) { var copy = this.clone(); var zone_equals = (this.zone.tzid == zone.tzid); if (!this.isDate && !zone_equals) { ICAL.Timezone.convert_time(copy, this.zone, zone); } copy.zone = zone; return copy; }
[ "function", "convertToZone", "(", "zone", ")", "{", "var", "copy", "=", "this", ".", "clone", "(", ")", ";", "var", "zone_equals", "=", "(", "this", ".", "zone", ".", "tzid", "==", "zone", ".", "tzid", ")", ";", "if", "(", "!", "this", ".", "isDate", "&&", "!", "zone_equals", ")", "{", "ICAL", ".", "Timezone", ".", "convert_time", "(", "copy", ",", "this", ".", "zone", ",", "zone", ")", ";", "}", "copy", ".", "zone", "=", "zone", ";", "return", "copy", ";", "}" ]
Convert the instance into another timzone. The returned ICAL.Time instance is always a copy. @param {ICAL.Timezone} zone The zone to convert to @return {ICAL.Time} The copy, converted to the zone
[ "Convert", "the", "instance", "into", "another", "timzone", ".", "The", "returned", "ICAL", ".", "Time", "instance", "is", "always", "a", "copy", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L5383-L5393
9,379
mozilla-comm/ical.js
build/ical.js
function() { var string = this.toString(); if (string.length > 10) { return ICAL.design.icalendar.value['date-time'].toICAL(string); } else { return ICAL.design.icalendar.value.date.toICAL(string); } }
javascript
function() { var string = this.toString(); if (string.length > 10) { return ICAL.design.icalendar.value['date-time'].toICAL(string); } else { return ICAL.design.icalendar.value.date.toICAL(string); } }
[ "function", "(", ")", "{", "var", "string", "=", "this", ".", "toString", "(", ")", ";", "if", "(", "string", ".", "length", ">", "10", ")", "{", "return", "ICAL", ".", "design", ".", "icalendar", ".", "value", "[", "'date-time'", "]", ".", "toICAL", "(", "string", ")", ";", "}", "else", "{", "return", "ICAL", ".", "design", ".", "icalendar", ".", "value", ".", "date", ".", "toICAL", "(", "string", ")", ";", "}", "}" ]
Returns an RFC 5545 compliant ical representation of this object. @return {String} ical date/date-time
[ "Returns", "an", "RFC", "5545", "compliant", "ical", "representation", "of", "this", "object", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L5415-L5423
9,380
mozilla-comm/ical.js
build/ical.js
toJSDate
function toJSDate() { if (this.zone == ICAL.Timezone.localTimezone) { if (this.isDate) { return new Date(this.year, this.month - 1, this.day); } else { return new Date(this.year, this.month - 1, this.day, this.hour, this.minute, this.second, 0); } } else { return new Date(this.toUnixTime() * 1000); } }
javascript
function toJSDate() { if (this.zone == ICAL.Timezone.localTimezone) { if (this.isDate) { return new Date(this.year, this.month - 1, this.day); } else { return new Date(this.year, this.month - 1, this.day, this.hour, this.minute, this.second, 0); } } else { return new Date(this.toUnixTime() * 1000); } }
[ "function", "toJSDate", "(", ")", "{", "if", "(", "this", ".", "zone", "==", "ICAL", ".", "Timezone", ".", "localTimezone", ")", "{", "if", "(", "this", ".", "isDate", ")", "{", "return", "new", "Date", "(", "this", ".", "year", ",", "this", ".", "month", "-", "1", ",", "this", ".", "day", ")", ";", "}", "else", "{", "return", "new", "Date", "(", "this", ".", "year", ",", "this", ".", "month", "-", "1", ",", "this", ".", "day", ",", "this", ".", "hour", ",", "this", ".", "minute", ",", "this", ".", "second", ",", "0", ")", ";", "}", "}", "else", "{", "return", "new", "Date", "(", "this", ".", "toUnixTime", "(", ")", "*", "1000", ")", ";", "}", "}" ]
Converts the current instance to a Javascript date @return {Date}
[ "Converts", "the", "current", "instance", "to", "a", "Javascript", "date" ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L5452-L5463
9,381
mozilla-comm/ical.js
build/ical.js
fromUnixTime
function fromUnixTime(seconds) { this.zone = ICAL.Timezone.utcTimezone; var epoch = ICAL.Time.epochTime.clone(); epoch.adjust(0, 0, 0, seconds); this.year = epoch.year; this.month = epoch.month; this.day = epoch.day; this.hour = epoch.hour; this.minute = epoch.minute; this.second = Math.floor(epoch.second); this._cachedUnixTime = null; }
javascript
function fromUnixTime(seconds) { this.zone = ICAL.Timezone.utcTimezone; var epoch = ICAL.Time.epochTime.clone(); epoch.adjust(0, 0, 0, seconds); this.year = epoch.year; this.month = epoch.month; this.day = epoch.day; this.hour = epoch.hour; this.minute = epoch.minute; this.second = Math.floor(epoch.second); this._cachedUnixTime = null; }
[ "function", "fromUnixTime", "(", "seconds", ")", "{", "this", ".", "zone", "=", "ICAL", ".", "Timezone", ".", "utcTimezone", ";", "var", "epoch", "=", "ICAL", ".", "Time", ".", "epochTime", ".", "clone", "(", ")", ";", "epoch", ".", "adjust", "(", "0", ",", "0", ",", "0", ",", "seconds", ")", ";", "this", ".", "year", "=", "epoch", ".", "year", ";", "this", ".", "month", "=", "epoch", ".", "month", ";", "this", ".", "day", "=", "epoch", ".", "day", ";", "this", ".", "hour", "=", "epoch", ".", "hour", ";", "this", ".", "minute", "=", "epoch", ".", "minute", ";", "this", ".", "second", "=", "Math", ".", "floor", "(", "epoch", ".", "second", ")", ";", "this", ".", "_cachedUnixTime", "=", "null", ";", "}" ]
Sets up the current instance from unix time, the number of seconds since January 1st, 1970. @param {Number} seconds The seconds to set up with
[ "Sets", "up", "the", "current", "instance", "from", "unix", "time", "the", "number", "of", "seconds", "since", "January", "1st", "1970", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L5580-L5593
9,382
mozilla-comm/ical.js
build/ical.js
toUnixTime
function toUnixTime() { if (this._cachedUnixTime !== null) { return this._cachedUnixTime; } var offset = this.utcOffset(); // we use the offset trick to ensure // that we are getting the actual UTC time var ms = Date.UTC( this.year, this.month - 1, this.day, this.hour, this.minute, this.second - offset ); // seconds this._cachedUnixTime = ms / 1000; return this._cachedUnixTime; }
javascript
function toUnixTime() { if (this._cachedUnixTime !== null) { return this._cachedUnixTime; } var offset = this.utcOffset(); // we use the offset trick to ensure // that we are getting the actual UTC time var ms = Date.UTC( this.year, this.month - 1, this.day, this.hour, this.minute, this.second - offset ); // seconds this._cachedUnixTime = ms / 1000; return this._cachedUnixTime; }
[ "function", "toUnixTime", "(", ")", "{", "if", "(", "this", ".", "_cachedUnixTime", "!==", "null", ")", "{", "return", "this", ".", "_cachedUnixTime", ";", "}", "var", "offset", "=", "this", ".", "utcOffset", "(", ")", ";", "// we use the offset trick to ensure", "// that we are getting the actual UTC time", "var", "ms", "=", "Date", ".", "UTC", "(", "this", ".", "year", ",", "this", ".", "month", "-", "1", ",", "this", ".", "day", ",", "this", ".", "hour", ",", "this", ".", "minute", ",", "this", ".", "second", "-", "offset", ")", ";", "// seconds", "this", ".", "_cachedUnixTime", "=", "ms", "/", "1000", ";", "return", "this", ".", "_cachedUnixTime", ";", "}" ]
Converts the current instance to seconds since January 1st 1970. @return {Number} Seconds since 1970
[ "Converts", "the", "current", "instance", "to", "seconds", "since", "January", "1st", "1970", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L5600-L5620
9,383
mozilla-comm/ical.js
build/ical.js
function() { var copy = [ 'year', 'month', 'day', 'hour', 'minute', 'second', 'isDate' ]; var result = Object.create(null); var i = 0; var len = copy.length; var prop; for (; i < len; i++) { prop = copy[i]; result[prop] = this[prop]; } if (this.zone) { result.timezone = this.zone.tzid; } return result; }
javascript
function() { var copy = [ 'year', 'month', 'day', 'hour', 'minute', 'second', 'isDate' ]; var result = Object.create(null); var i = 0; var len = copy.length; var prop; for (; i < len; i++) { prop = copy[i]; result[prop] = this[prop]; } if (this.zone) { result.timezone = this.zone.tzid; } return result; }
[ "function", "(", ")", "{", "var", "copy", "=", "[", "'year'", ",", "'month'", ",", "'day'", ",", "'hour'", ",", "'minute'", ",", "'second'", ",", "'isDate'", "]", ";", "var", "result", "=", "Object", ".", "create", "(", "null", ")", ";", "var", "i", "=", "0", ";", "var", "len", "=", "copy", ".", "length", ";", "var", "prop", ";", "for", "(", ";", "i", "<", "len", ";", "i", "++", ")", "{", "prop", "=", "copy", "[", "i", "]", ";", "result", "[", "prop", "]", "=", "this", "[", "prop", "]", ";", "}", "if", "(", "this", ".", "zone", ")", "{", "result", ".", "timezone", "=", "this", ".", "zone", ".", "tzid", ";", "}", "return", "result", ";", "}" ]
Converts time to into Object which can be serialized then re-created using the constructor. @example // toJSON will automatically be called var json = JSON.stringify(mytime); var deserialized = JSON.parse(json); var time = new ICAL.Time(deserialized); @return {Object}
[ "Converts", "time", "to", "into", "Object", "which", "can", "be", "serialized", "then", "re", "-", "created", "using", "the", "constructor", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L5636-L5663
9,384
mozilla-comm/ical.js
build/ical.js
function() { var res = Object.create(null); res.freq = this.freq; if (this.count) { res.count = this.count; } if (this.interval > 1) { res.interval = this.interval; } for (var k in this.parts) { /* istanbul ignore if */ if (!this.parts.hasOwnProperty(k)) { continue; } var kparts = this.parts[k]; if (Array.isArray(kparts) && kparts.length == 1) { res[k.toLowerCase()] = kparts[0]; } else { res[k.toLowerCase()] = ICAL.helpers.clone(this.parts[k]); } } if (this.until) { res.until = this.until.toString(); } if ('wkst' in this && this.wkst !== ICAL.Time.DEFAULT_WEEK_START) { res.wkst = ICAL.Recur.numericDayToIcalDay(this.wkst); } return res; }
javascript
function() { var res = Object.create(null); res.freq = this.freq; if (this.count) { res.count = this.count; } if (this.interval > 1) { res.interval = this.interval; } for (var k in this.parts) { /* istanbul ignore if */ if (!this.parts.hasOwnProperty(k)) { continue; } var kparts = this.parts[k]; if (Array.isArray(kparts) && kparts.length == 1) { res[k.toLowerCase()] = kparts[0]; } else { res[k.toLowerCase()] = ICAL.helpers.clone(this.parts[k]); } } if (this.until) { res.until = this.until.toString(); } if ('wkst' in this && this.wkst !== ICAL.Time.DEFAULT_WEEK_START) { res.wkst = ICAL.Recur.numericDayToIcalDay(this.wkst); } return res; }
[ "function", "(", ")", "{", "var", "res", "=", "Object", ".", "create", "(", "null", ")", ";", "res", ".", "freq", "=", "this", ".", "freq", ";", "if", "(", "this", ".", "count", ")", "{", "res", ".", "count", "=", "this", ".", "count", ";", "}", "if", "(", "this", ".", "interval", ">", "1", ")", "{", "res", ".", "interval", "=", "this", ".", "interval", ";", "}", "for", "(", "var", "k", "in", "this", ".", "parts", ")", "{", "/* istanbul ignore if */", "if", "(", "!", "this", ".", "parts", ".", "hasOwnProperty", "(", "k", ")", ")", "{", "continue", ";", "}", "var", "kparts", "=", "this", ".", "parts", "[", "k", "]", ";", "if", "(", "Array", ".", "isArray", "(", "kparts", ")", "&&", "kparts", ".", "length", "==", "1", ")", "{", "res", "[", "k", ".", "toLowerCase", "(", ")", "]", "=", "kparts", "[", "0", "]", ";", "}", "else", "{", "res", "[", "k", ".", "toLowerCase", "(", ")", "]", "=", "ICAL", ".", "helpers", ".", "clone", "(", "this", ".", "parts", "[", "k", "]", ")", ";", "}", "}", "if", "(", "this", ".", "until", ")", "{", "res", ".", "until", "=", "this", ".", "until", ".", "toString", "(", ")", ";", "}", "if", "(", "'wkst'", "in", "this", "&&", "this", ".", "wkst", "!==", "ICAL", ".", "Time", ".", "DEFAULT_WEEK_START", ")", "{", "res", ".", "wkst", "=", "ICAL", ".", "Recur", ".", "numericDayToIcalDay", "(", "this", ".", "wkst", ")", ";", "}", "return", "res", ";", "}" ]
The jCal representation of this recurrence type. @return {Object}
[ "The", "jCal", "representation", "of", "this", "recurrence", "type", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L6507-L6539
9,385
mozilla-comm/ical.js
build/ical.js
icalrecur_toString
function icalrecur_toString() { // TODO retain order var str = "FREQ=" + this.freq; if (this.count) { str += ";COUNT=" + this.count; } if (this.interval > 1) { str += ";INTERVAL=" + this.interval; } for (var k in this.parts) { /* istanbul ignore else */ if (this.parts.hasOwnProperty(k)) { str += ";" + k + "=" + this.parts[k]; } } if (this.until) { str += ';UNTIL=' + this.until.toICALString(); } if ('wkst' in this && this.wkst !== ICAL.Time.DEFAULT_WEEK_START) { str += ';WKST=' + ICAL.Recur.numericDayToIcalDay(this.wkst); } return str; }
javascript
function icalrecur_toString() { // TODO retain order var str = "FREQ=" + this.freq; if (this.count) { str += ";COUNT=" + this.count; } if (this.interval > 1) { str += ";INTERVAL=" + this.interval; } for (var k in this.parts) { /* istanbul ignore else */ if (this.parts.hasOwnProperty(k)) { str += ";" + k + "=" + this.parts[k]; } } if (this.until) { str += ';UNTIL=' + this.until.toICALString(); } if ('wkst' in this && this.wkst !== ICAL.Time.DEFAULT_WEEK_START) { str += ';WKST=' + ICAL.Recur.numericDayToIcalDay(this.wkst); } return str; }
[ "function", "icalrecur_toString", "(", ")", "{", "// TODO retain order", "var", "str", "=", "\"FREQ=\"", "+", "this", ".", "freq", ";", "if", "(", "this", ".", "count", ")", "{", "str", "+=", "\";COUNT=\"", "+", "this", ".", "count", ";", "}", "if", "(", "this", ".", "interval", ">", "1", ")", "{", "str", "+=", "\";INTERVAL=\"", "+", "this", ".", "interval", ";", "}", "for", "(", "var", "k", "in", "this", ".", "parts", ")", "{", "/* istanbul ignore else */", "if", "(", "this", ".", "parts", ".", "hasOwnProperty", "(", "k", ")", ")", "{", "str", "+=", "\";\"", "+", "k", "+", "\"=\"", "+", "this", ".", "parts", "[", "k", "]", ";", "}", "}", "if", "(", "this", ".", "until", ")", "{", "str", "+=", "';UNTIL='", "+", "this", ".", "until", ".", "toICALString", "(", ")", ";", "}", "if", "(", "'wkst'", "in", "this", "&&", "this", ".", "wkst", "!==", "ICAL", ".", "Time", ".", "DEFAULT_WEEK_START", ")", "{", "str", "+=", "';WKST='", "+", "ICAL", ".", "Recur", ".", "numericDayToIcalDay", "(", "this", ".", "wkst", ")", ";", "}", "return", "str", ";", "}" ]
The string representation of this recurrence rule. @return {String}
[ "The", "string", "representation", "of", "this", "recurrence", "rule", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L6545-L6567
9,386
mozilla-comm/ical.js
build/ical.js
function(options) { this.rule = ICAL.helpers.formatClassType(options.rule, ICAL.Recur); if (!this.rule) { throw new Error('iterator requires a (ICAL.Recur) rule'); } this.dtstart = ICAL.helpers.formatClassType(options.dtstart, ICAL.Time); if (!this.dtstart) { throw new Error('iterator requires a (ICAL.Time) dtstart'); } if (options.by_data) { this.by_data = options.by_data; } else { this.by_data = ICAL.helpers.clone(this.rule.parts, true); } if (options.occurrence_number) this.occurrence_number = options.occurrence_number; this.days = options.days || []; if (options.last) { this.last = ICAL.helpers.formatClassType(options.last, ICAL.Time); } this.by_indices = options.by_indices; if (!this.by_indices) { this.by_indices = { "BYSECOND": 0, "BYMINUTE": 0, "BYHOUR": 0, "BYDAY": 0, "BYMONTH": 0, "BYWEEKNO": 0, "BYMONTHDAY": 0 }; } this.initialized = options.initialized || false; if (!this.initialized) { this.init(); } }
javascript
function(options) { this.rule = ICAL.helpers.formatClassType(options.rule, ICAL.Recur); if (!this.rule) { throw new Error('iterator requires a (ICAL.Recur) rule'); } this.dtstart = ICAL.helpers.formatClassType(options.dtstart, ICAL.Time); if (!this.dtstart) { throw new Error('iterator requires a (ICAL.Time) dtstart'); } if (options.by_data) { this.by_data = options.by_data; } else { this.by_data = ICAL.helpers.clone(this.rule.parts, true); } if (options.occurrence_number) this.occurrence_number = options.occurrence_number; this.days = options.days || []; if (options.last) { this.last = ICAL.helpers.formatClassType(options.last, ICAL.Time); } this.by_indices = options.by_indices; if (!this.by_indices) { this.by_indices = { "BYSECOND": 0, "BYMINUTE": 0, "BYHOUR": 0, "BYDAY": 0, "BYMONTH": 0, "BYWEEKNO": 0, "BYMONTHDAY": 0 }; } this.initialized = options.initialized || false; if (!this.initialized) { this.init(); } }
[ "function", "(", "options", ")", "{", "this", ".", "rule", "=", "ICAL", ".", "helpers", ".", "formatClassType", "(", "options", ".", "rule", ",", "ICAL", ".", "Recur", ")", ";", "if", "(", "!", "this", ".", "rule", ")", "{", "throw", "new", "Error", "(", "'iterator requires a (ICAL.Recur) rule'", ")", ";", "}", "this", ".", "dtstart", "=", "ICAL", ".", "helpers", ".", "formatClassType", "(", "options", ".", "dtstart", ",", "ICAL", ".", "Time", ")", ";", "if", "(", "!", "this", ".", "dtstart", ")", "{", "throw", "new", "Error", "(", "'iterator requires a (ICAL.Time) dtstart'", ")", ";", "}", "if", "(", "options", ".", "by_data", ")", "{", "this", ".", "by_data", "=", "options", ".", "by_data", ";", "}", "else", "{", "this", ".", "by_data", "=", "ICAL", ".", "helpers", ".", "clone", "(", "this", ".", "rule", ".", "parts", ",", "true", ")", ";", "}", "if", "(", "options", ".", "occurrence_number", ")", "this", ".", "occurrence_number", "=", "options", ".", "occurrence_number", ";", "this", ".", "days", "=", "options", ".", "days", "||", "[", "]", ";", "if", "(", "options", ".", "last", ")", "{", "this", ".", "last", "=", "ICAL", ".", "helpers", ".", "formatClassType", "(", "options", ".", "last", ",", "ICAL", ".", "Time", ")", ";", "}", "this", ".", "by_indices", "=", "options", ".", "by_indices", ";", "if", "(", "!", "this", ".", "by_indices", ")", "{", "this", ".", "by_indices", "=", "{", "\"BYSECOND\"", ":", "0", ",", "\"BYMINUTE\"", ":", "0", ",", "\"BYHOUR\"", ":", "0", ",", "\"BYDAY\"", ":", "0", ",", "\"BYMONTH\"", ":", "0", ",", "\"BYWEEKNO\"", ":", "0", ",", "\"BYMONTHDAY\"", ":", "0", "}", ";", "}", "this", ".", "initialized", "=", "options", ".", "initialized", "||", "false", ";", "if", "(", "!", "this", ".", "initialized", ")", "{", "this", ".", "init", "(", ")", ";", "}", "}" ]
Initialize the recurrence iterator from the passed data object. This method is usually not called directly, you can initialize the iterator through the constructor. @param {Object} options The iterator options @param {ICAL.Recur} options.rule The rule to iterate. @param {ICAL.Time} options.dtstart The start date of the event. @param {Boolean=} options.initialized When true, assume that options are from a previously constructed iterator. Initialization will not be repeated.
[ "Initialize", "the", "recurrence", "iterator", "from", "the", "passed", "data", "object", ".", "This", "method", "is", "usually", "not", "called", "directly", "you", "can", "initialize", "the", "iterator", "through", "the", "constructor", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L6898-L6944
9,387
mozilla-comm/ical.js
build/ical.js
icalrecur_iterator_next
function icalrecur_iterator_next() { var before = (this.last ? this.last.clone() : null); if ((this.rule.count && this.occurrence_number >= this.rule.count) || (this.rule.until && this.last.compare(this.rule.until) > 0)) { //XXX: right now this is just a flag and has no impact // we can simplify the above case to check for completed later. this.completed = true; return null; } if (this.occurrence_number == 0 && this.last.compare(this.dtstart) >= 0) { // First of all, give the instance that was initialized this.occurrence_number++; return this.last; } var valid; do { valid = 1; switch (this.rule.freq) { case "SECONDLY": this.next_second(); break; case "MINUTELY": this.next_minute(); break; case "HOURLY": this.next_hour(); break; case "DAILY": this.next_day(); break; case "WEEKLY": this.next_week(); break; case "MONTHLY": valid = this.next_month(); break; case "YEARLY": this.next_year(); break; default: return null; } } while (!this.check_contracting_rules() || this.last.compare(this.dtstart) < 0 || !valid); // TODO is this valid? if (this.last.compare(before) == 0) { throw new Error("Same occurrence found twice, protecting " + "you from death by recursion"); } if (this.rule.until && this.last.compare(this.rule.until) > 0) { this.completed = true; return null; } else { this.occurrence_number++; return this.last; } }
javascript
function icalrecur_iterator_next() { var before = (this.last ? this.last.clone() : null); if ((this.rule.count && this.occurrence_number >= this.rule.count) || (this.rule.until && this.last.compare(this.rule.until) > 0)) { //XXX: right now this is just a flag and has no impact // we can simplify the above case to check for completed later. this.completed = true; return null; } if (this.occurrence_number == 0 && this.last.compare(this.dtstart) >= 0) { // First of all, give the instance that was initialized this.occurrence_number++; return this.last; } var valid; do { valid = 1; switch (this.rule.freq) { case "SECONDLY": this.next_second(); break; case "MINUTELY": this.next_minute(); break; case "HOURLY": this.next_hour(); break; case "DAILY": this.next_day(); break; case "WEEKLY": this.next_week(); break; case "MONTHLY": valid = this.next_month(); break; case "YEARLY": this.next_year(); break; default: return null; } } while (!this.check_contracting_rules() || this.last.compare(this.dtstart) < 0 || !valid); // TODO is this valid? if (this.last.compare(before) == 0) { throw new Error("Same occurrence found twice, protecting " + "you from death by recursion"); } if (this.rule.until && this.last.compare(this.rule.until) > 0) { this.completed = true; return null; } else { this.occurrence_number++; return this.last; } }
[ "function", "icalrecur_iterator_next", "(", ")", "{", "var", "before", "=", "(", "this", ".", "last", "?", "this", ".", "last", ".", "clone", "(", ")", ":", "null", ")", ";", "if", "(", "(", "this", ".", "rule", ".", "count", "&&", "this", ".", "occurrence_number", ">=", "this", ".", "rule", ".", "count", ")", "||", "(", "this", ".", "rule", ".", "until", "&&", "this", ".", "last", ".", "compare", "(", "this", ".", "rule", ".", "until", ")", ">", "0", ")", ")", "{", "//XXX: right now this is just a flag and has no impact", "// we can simplify the above case to check for completed later.", "this", ".", "completed", "=", "true", ";", "return", "null", ";", "}", "if", "(", "this", ".", "occurrence_number", "==", "0", "&&", "this", ".", "last", ".", "compare", "(", "this", ".", "dtstart", ")", ">=", "0", ")", "{", "// First of all, give the instance that was initialized", "this", ".", "occurrence_number", "++", ";", "return", "this", ".", "last", ";", "}", "var", "valid", ";", "do", "{", "valid", "=", "1", ";", "switch", "(", "this", ".", "rule", ".", "freq", ")", "{", "case", "\"SECONDLY\"", ":", "this", ".", "next_second", "(", ")", ";", "break", ";", "case", "\"MINUTELY\"", ":", "this", ".", "next_minute", "(", ")", ";", "break", ";", "case", "\"HOURLY\"", ":", "this", ".", "next_hour", "(", ")", ";", "break", ";", "case", "\"DAILY\"", ":", "this", ".", "next_day", "(", ")", ";", "break", ";", "case", "\"WEEKLY\"", ":", "this", ".", "next_week", "(", ")", ";", "break", ";", "case", "\"MONTHLY\"", ":", "valid", "=", "this", ".", "next_month", "(", ")", ";", "break", ";", "case", "\"YEARLY\"", ":", "this", ".", "next_year", "(", ")", ";", "break", ";", "default", ":", "return", "null", ";", "}", "}", "while", "(", "!", "this", ".", "check_contracting_rules", "(", ")", "||", "this", ".", "last", ".", "compare", "(", "this", ".", "dtstart", ")", "<", "0", "||", "!", "valid", ")", ";", "// TODO is this valid?", "if", "(", "this", ".", "last", ".", "compare", "(", "before", ")", "==", "0", ")", "{", "throw", "new", "Error", "(", "\"Same occurrence found twice, protecting \"", "+", "\"you from death by recursion\"", ")", ";", "}", "if", "(", "this", ".", "rule", ".", "until", "&&", "this", ".", "last", ".", "compare", "(", "this", ".", "rule", ".", "until", ")", ">", "0", ")", "{", "this", ".", "completed", "=", "true", ";", "return", "null", ";", "}", "else", "{", "this", ".", "occurrence_number", "++", ";", "return", "this", ".", "last", ";", "}", "}" ]
Retrieve the next occurrence from the iterator. @return {ICAL.Time}
[ "Retrieve", "the", "next", "occurrence", "from", "the", "iterator", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L7096-L7163
9,388
mozilla-comm/ical.js
build/ical.js
check_set_position
function check_set_position(aPos) { if (this.has_by_data('BYSETPOS')) { var idx = this.by_data.BYSETPOS.indexOf(aPos); // negative numbers are not false-y return idx !== -1; } return false; }
javascript
function check_set_position(aPos) { if (this.has_by_data('BYSETPOS')) { var idx = this.by_data.BYSETPOS.indexOf(aPos); // negative numbers are not false-y return idx !== -1; } return false; }
[ "function", "check_set_position", "(", "aPos", ")", "{", "if", "(", "this", ".", "has_by_data", "(", "'BYSETPOS'", ")", ")", "{", "var", "idx", "=", "this", ".", "by_data", ".", "BYSETPOS", ".", "indexOf", "(", "aPos", ")", ";", "// negative numbers are not false-y", "return", "idx", "!==", "-", "1", ";", "}", "return", "false", ";", "}" ]
Checks if given value is in BYSETPOS. @private @param {Numeric} aPos position to check for. @return {Boolean} false unless BYSETPOS rules exist and the given value is present in rules.
[ "Checks", "if", "given", "value", "is", "in", "BYSETPOS", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L8073-L8080
9,389
mozilla-comm/ical.js
build/ical.js
function() { var result = Object.create(null); result.initialized = this.initialized; result.rule = this.rule.toJSON(); result.dtstart = this.dtstart.toJSON(); result.by_data = this.by_data; result.days = this.days; result.last = this.last.toJSON(); result.by_indices = this.by_indices; result.occurrence_number = this.occurrence_number; return result; }
javascript
function() { var result = Object.create(null); result.initialized = this.initialized; result.rule = this.rule.toJSON(); result.dtstart = this.dtstart.toJSON(); result.by_data = this.by_data; result.days = this.days; result.last = this.last.toJSON(); result.by_indices = this.by_indices; result.occurrence_number = this.occurrence_number; return result; }
[ "function", "(", ")", "{", "var", "result", "=", "Object", ".", "create", "(", "null", ")", ";", "result", ".", "initialized", "=", "this", ".", "initialized", ";", "result", ".", "rule", "=", "this", ".", "rule", ".", "toJSON", "(", ")", ";", "result", ".", "dtstart", "=", "this", ".", "dtstart", ".", "toJSON", "(", ")", ";", "result", ".", "by_data", "=", "this", ".", "by_data", ";", "result", ".", "days", "=", "this", ".", "days", ";", "result", ".", "last", "=", "this", ".", "last", ".", "toJSON", "(", ")", ";", "result", ".", "by_indices", "=", "this", ".", "by_indices", ";", "result", ".", "occurrence_number", "=", "this", ".", "occurrence_number", ";", "return", "result", ";", "}" ]
Convert iterator into a serialize-able object. Will preserve current iteration sequence to ensure the seamless continuation of the recurrence rule. @return {Object}
[ "Convert", "iterator", "into", "a", "serialize", "-", "able", "object", ".", "Will", "preserve", "current", "iteration", "sequence", "to", "ensure", "the", "seamless", "continuation", "of", "the", "recurrence", "rule", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L8163-L8176
9,390
mozilla-comm/ical.js
build/ical.js
function() { var iter; var ruleOfDay; var next; var compare; var maxTries = 500; var currentTry = 0; while (true) { if (currentTry++ > maxTries) { throw new Error( 'max tries have occured, rule may be impossible to forfill.' ); } next = this.ruleDate; iter = this._nextRecurrenceIter(this.last); // no more matches // because we increment the rule day or rule // _after_ we choose a value this should be // the only spot where we need to worry about the // end of events. if (!next && !iter) { // there are no more iterators or rdates this.complete = true; break; } // no next rule day or recurrence rule is first. if (!next || (iter && next.compare(iter.last) > 0)) { // must be cloned, recur will reuse the time element. next = iter.last.clone(); // move to next so we can continue iter.next(); } // if the ruleDate is still next increment it. if (this.ruleDate === next) { this._nextRuleDay(); } this.last = next; // check the negative rules if (this.exDate) { compare = this.exDate.compare(this.last); if (compare < 0) { this._nextExDay(); } // if the current rule is excluded skip it. if (compare === 0) { this._nextExDay(); continue; } } //XXX: The spec states that after we resolve the final // list of dates we execute exdate this seems somewhat counter // intuitive to what I have seen most servers do so for now // I exclude based on the original date not the one that may // have been modified by the exception. return this.last; } }
javascript
function() { var iter; var ruleOfDay; var next; var compare; var maxTries = 500; var currentTry = 0; while (true) { if (currentTry++ > maxTries) { throw new Error( 'max tries have occured, rule may be impossible to forfill.' ); } next = this.ruleDate; iter = this._nextRecurrenceIter(this.last); // no more matches // because we increment the rule day or rule // _after_ we choose a value this should be // the only spot where we need to worry about the // end of events. if (!next && !iter) { // there are no more iterators or rdates this.complete = true; break; } // no next rule day or recurrence rule is first. if (!next || (iter && next.compare(iter.last) > 0)) { // must be cloned, recur will reuse the time element. next = iter.last.clone(); // move to next so we can continue iter.next(); } // if the ruleDate is still next increment it. if (this.ruleDate === next) { this._nextRuleDay(); } this.last = next; // check the negative rules if (this.exDate) { compare = this.exDate.compare(this.last); if (compare < 0) { this._nextExDay(); } // if the current rule is excluded skip it. if (compare === 0) { this._nextExDay(); continue; } } //XXX: The spec states that after we resolve the final // list of dates we execute exdate this seems somewhat counter // intuitive to what I have seen most servers do so for now // I exclude based on the original date not the one that may // have been modified by the exception. return this.last; } }
[ "function", "(", ")", "{", "var", "iter", ";", "var", "ruleOfDay", ";", "var", "next", ";", "var", "compare", ";", "var", "maxTries", "=", "500", ";", "var", "currentTry", "=", "0", ";", "while", "(", "true", ")", "{", "if", "(", "currentTry", "++", ">", "maxTries", ")", "{", "throw", "new", "Error", "(", "'max tries have occured, rule may be impossible to forfill.'", ")", ";", "}", "next", "=", "this", ".", "ruleDate", ";", "iter", "=", "this", ".", "_nextRecurrenceIter", "(", "this", ".", "last", ")", ";", "// no more matches", "// because we increment the rule day or rule", "// _after_ we choose a value this should be", "// the only spot where we need to worry about the", "// end of events.", "if", "(", "!", "next", "&&", "!", "iter", ")", "{", "// there are no more iterators or rdates", "this", ".", "complete", "=", "true", ";", "break", ";", "}", "// no next rule day or recurrence rule is first.", "if", "(", "!", "next", "||", "(", "iter", "&&", "next", ".", "compare", "(", "iter", ".", "last", ")", ">", "0", ")", ")", "{", "// must be cloned, recur will reuse the time element.", "next", "=", "iter", ".", "last", ".", "clone", "(", ")", ";", "// move to next so we can continue", "iter", ".", "next", "(", ")", ";", "}", "// if the ruleDate is still next increment it.", "if", "(", "this", ".", "ruleDate", "===", "next", ")", "{", "this", ".", "_nextRuleDay", "(", ")", ";", "}", "this", ".", "last", "=", "next", ";", "// check the negative rules", "if", "(", "this", ".", "exDate", ")", "{", "compare", "=", "this", ".", "exDate", ".", "compare", "(", "this", ".", "last", ")", ";", "if", "(", "compare", "<", "0", ")", "{", "this", ".", "_nextExDay", "(", ")", ";", "}", "// if the current rule is excluded skip it.", "if", "(", "compare", "===", "0", ")", "{", "this", ".", "_nextExDay", "(", ")", ";", "continue", ";", "}", "}", "//XXX: The spec states that after we resolve the final", "// list of dates we execute exdate this seems somewhat counter", "// intuitive to what I have seen most servers do so for now", "// I exclude based on the original date not the one that may", "// have been modified by the exception.", "return", "this", ".", "last", ";", "}", "}" ]
Retrieve the next occurrence in the series. @return {ICAL.Time}
[ "Retrieve", "the", "next", "occurrence", "in", "the", "series", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L8427-L8494
9,391
mozilla-comm/ical.js
build/ical.js
function() { function toJSON(item) { return item.toJSON(); } var result = Object.create(null); result.ruleIterators = this.ruleIterators.map(toJSON); if (this.ruleDates) { result.ruleDates = this.ruleDates.map(toJSON); } if (this.exDates) { result.exDates = this.exDates.map(toJSON); } result.ruleDateInc = this.ruleDateInc; result.exDateInc = this.exDateInc; result.last = this.last.toJSON(); result.dtstart = this.dtstart.toJSON(); result.complete = this.complete; return result; }
javascript
function() { function toJSON(item) { return item.toJSON(); } var result = Object.create(null); result.ruleIterators = this.ruleIterators.map(toJSON); if (this.ruleDates) { result.ruleDates = this.ruleDates.map(toJSON); } if (this.exDates) { result.exDates = this.exDates.map(toJSON); } result.ruleDateInc = this.ruleDateInc; result.exDateInc = this.exDateInc; result.last = this.last.toJSON(); result.dtstart = this.dtstart.toJSON(); result.complete = this.complete; return result; }
[ "function", "(", ")", "{", "function", "toJSON", "(", "item", ")", "{", "return", "item", ".", "toJSON", "(", ")", ";", "}", "var", "result", "=", "Object", ".", "create", "(", "null", ")", ";", "result", ".", "ruleIterators", "=", "this", ".", "ruleIterators", ".", "map", "(", "toJSON", ")", ";", "if", "(", "this", ".", "ruleDates", ")", "{", "result", ".", "ruleDates", "=", "this", ".", "ruleDates", ".", "map", "(", "toJSON", ")", ";", "}", "if", "(", "this", ".", "exDates", ")", "{", "result", ".", "exDates", "=", "this", ".", "exDates", ".", "map", "(", "toJSON", ")", ";", "}", "result", ".", "ruleDateInc", "=", "this", ".", "ruleDateInc", ";", "result", ".", "exDateInc", "=", "this", ".", "exDateInc", ";", "result", ".", "last", "=", "this", ".", "last", ".", "toJSON", "(", ")", ";", "result", ".", "dtstart", "=", "this", ".", "dtstart", ".", "toJSON", "(", ")", ";", "result", ".", "complete", "=", "this", ".", "complete", ";", "return", "result", ";", "}" ]
Converts object into a serialize-able format. This format can be passed back into the expansion to resume iteration. @return {Object}
[ "Converts", "object", "into", "a", "serialize", "-", "able", "format", ".", "This", "format", "can", "be", "passed", "back", "into", "the", "expansion", "to", "resume", "iteration", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L8501-L8524
9,392
mozilla-comm/ical.js
build/ical.js
function(component, propertyName) { function handleProp(prop) { idx = ICAL.helpers.binsearchInsert( result, prop, compareTime ); // ordered insert result.splice(idx, 0, prop); } var result = []; var props = component.getAllProperties(propertyName); var len = props.length; var i = 0; var prop; var idx; for (; i < len; i++) { props[i].getValues().forEach(handleProp); } return result; }
javascript
function(component, propertyName) { function handleProp(prop) { idx = ICAL.helpers.binsearchInsert( result, prop, compareTime ); // ordered insert result.splice(idx, 0, prop); } var result = []; var props = component.getAllProperties(propertyName); var len = props.length; var i = 0; var prop; var idx; for (; i < len; i++) { props[i].getValues().forEach(handleProp); } return result; }
[ "function", "(", "component", ",", "propertyName", ")", "{", "function", "handleProp", "(", "prop", ")", "{", "idx", "=", "ICAL", ".", "helpers", ".", "binsearchInsert", "(", "result", ",", "prop", ",", "compareTime", ")", ";", "// ordered insert", "result", ".", "splice", "(", "idx", ",", "0", ",", "prop", ")", ";", "}", "var", "result", "=", "[", "]", ";", "var", "props", "=", "component", ".", "getAllProperties", "(", "propertyName", ")", ";", "var", "len", "=", "props", ".", "length", ";", "var", "i", "=", "0", ";", "var", "prop", ";", "var", "idx", ";", "for", "(", ";", "i", "<", "len", ";", "i", "++", ")", "{", "props", "[", "i", "]", ".", "getValues", "(", ")", ".", "forEach", "(", "handleProp", ")", ";", "}", "return", "result", ";", "}" ]
Extract all dates from the properties in the given component. The properties will be filtered by the property name. @private @param {ICAL.Component} component The component to search in @param {String} propertyName The property name to search for @return {ICAL.Time[]} The extracted dates.
[ "Extract", "all", "dates", "from", "the", "properties", "in", "the", "given", "component", ".", "The", "properties", "will", "be", "filtered", "by", "the", "property", "name", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L8535-L8560
9,393
mozilla-comm/ical.js
build/ical.js
function(component) { this.ruleIterators = []; this.last = this.dtstart.clone(); // to provide api consistency non-recurring // events can also use the iterator though it will // only return a single time. if (!isRecurringComponent(component)) { this.ruleDate = this.last.clone(); this.complete = true; return; } if (component.hasProperty('rdate')) { this.ruleDates = this._extractDates(component, 'rdate'); // special hack for cases where first rdate is prior // to the start date. We only check for the first rdate. // This is mostly for google's crazy recurring date logic // (contacts birthdays). if ((this.ruleDates[0]) && (this.ruleDates[0].compare(this.dtstart) < 0)) { this.ruleDateInc = 0; this.last = this.ruleDates[0].clone(); } else { this.ruleDateInc = ICAL.helpers.binsearchInsert( this.ruleDates, this.last, compareTime ); } this.ruleDate = this.ruleDates[this.ruleDateInc]; } if (component.hasProperty('rrule')) { var rules = component.getAllProperties('rrule'); var i = 0; var len = rules.length; var rule; var iter; for (; i < len; i++) { rule = rules[i].getFirstValue(); iter = rule.iterator(this.dtstart); this.ruleIterators.push(iter); // increment to the next occurrence so future // calls to next return times beyond the initial iteration. // XXX: I find this suspicious might be a bug? iter.next(); } } if (component.hasProperty('exdate')) { this.exDates = this._extractDates(component, 'exdate'); // if we have a .last day we increment the index to beyond it. this.exDateInc = ICAL.helpers.binsearchInsert( this.exDates, this.last, compareTime ); this.exDate = this.exDates[this.exDateInc]; } }
javascript
function(component) { this.ruleIterators = []; this.last = this.dtstart.clone(); // to provide api consistency non-recurring // events can also use the iterator though it will // only return a single time. if (!isRecurringComponent(component)) { this.ruleDate = this.last.clone(); this.complete = true; return; } if (component.hasProperty('rdate')) { this.ruleDates = this._extractDates(component, 'rdate'); // special hack for cases where first rdate is prior // to the start date. We only check for the first rdate. // This is mostly for google's crazy recurring date logic // (contacts birthdays). if ((this.ruleDates[0]) && (this.ruleDates[0].compare(this.dtstart) < 0)) { this.ruleDateInc = 0; this.last = this.ruleDates[0].clone(); } else { this.ruleDateInc = ICAL.helpers.binsearchInsert( this.ruleDates, this.last, compareTime ); } this.ruleDate = this.ruleDates[this.ruleDateInc]; } if (component.hasProperty('rrule')) { var rules = component.getAllProperties('rrule'); var i = 0; var len = rules.length; var rule; var iter; for (; i < len; i++) { rule = rules[i].getFirstValue(); iter = rule.iterator(this.dtstart); this.ruleIterators.push(iter); // increment to the next occurrence so future // calls to next return times beyond the initial iteration. // XXX: I find this suspicious might be a bug? iter.next(); } } if (component.hasProperty('exdate')) { this.exDates = this._extractDates(component, 'exdate'); // if we have a .last day we increment the index to beyond it. this.exDateInc = ICAL.helpers.binsearchInsert( this.exDates, this.last, compareTime ); this.exDate = this.exDates[this.exDateInc]; } }
[ "function", "(", "component", ")", "{", "this", ".", "ruleIterators", "=", "[", "]", ";", "this", ".", "last", "=", "this", ".", "dtstart", ".", "clone", "(", ")", ";", "// to provide api consistency non-recurring", "// events can also use the iterator though it will", "// only return a single time.", "if", "(", "!", "isRecurringComponent", "(", "component", ")", ")", "{", "this", ".", "ruleDate", "=", "this", ".", "last", ".", "clone", "(", ")", ";", "this", ".", "complete", "=", "true", ";", "return", ";", "}", "if", "(", "component", ".", "hasProperty", "(", "'rdate'", ")", ")", "{", "this", ".", "ruleDates", "=", "this", ".", "_extractDates", "(", "component", ",", "'rdate'", ")", ";", "// special hack for cases where first rdate is prior", "// to the start date. We only check for the first rdate.", "// This is mostly for google's crazy recurring date logic", "// (contacts birthdays).", "if", "(", "(", "this", ".", "ruleDates", "[", "0", "]", ")", "&&", "(", "this", ".", "ruleDates", "[", "0", "]", ".", "compare", "(", "this", ".", "dtstart", ")", "<", "0", ")", ")", "{", "this", ".", "ruleDateInc", "=", "0", ";", "this", ".", "last", "=", "this", ".", "ruleDates", "[", "0", "]", ".", "clone", "(", ")", ";", "}", "else", "{", "this", ".", "ruleDateInc", "=", "ICAL", ".", "helpers", ".", "binsearchInsert", "(", "this", ".", "ruleDates", ",", "this", ".", "last", ",", "compareTime", ")", ";", "}", "this", ".", "ruleDate", "=", "this", ".", "ruleDates", "[", "this", ".", "ruleDateInc", "]", ";", "}", "if", "(", "component", ".", "hasProperty", "(", "'rrule'", ")", ")", "{", "var", "rules", "=", "component", ".", "getAllProperties", "(", "'rrule'", ")", ";", "var", "i", "=", "0", ";", "var", "len", "=", "rules", ".", "length", ";", "var", "rule", ";", "var", "iter", ";", "for", "(", ";", "i", "<", "len", ";", "i", "++", ")", "{", "rule", "=", "rules", "[", "i", "]", ".", "getFirstValue", "(", ")", ";", "iter", "=", "rule", ".", "iterator", "(", "this", ".", "dtstart", ")", ";", "this", ".", "ruleIterators", ".", "push", "(", "iter", ")", ";", "// increment to the next occurrence so future", "// calls to next return times beyond the initial iteration.", "// XXX: I find this suspicious might be a bug?", "iter", ".", "next", "(", ")", ";", "}", "}", "if", "(", "component", ".", "hasProperty", "(", "'exdate'", ")", ")", "{", "this", ".", "exDates", "=", "this", ".", "_extractDates", "(", "component", ",", "'exdate'", ")", ";", "// if we have a .last day we increment the index to beyond it.", "this", ".", "exDateInc", "=", "ICAL", ".", "helpers", ".", "binsearchInsert", "(", "this", ".", "exDates", ",", "this", ".", "last", ",", "compareTime", ")", ";", "this", ".", "exDate", "=", "this", ".", "exDates", "[", "this", ".", "exDateInc", "]", ";", "}", "}" ]
Initialize the recurrence expansion. @private @param {ICAL.Component} component The component to initialize from.
[ "Initialize", "the", "recurrence", "expansion", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L8568-L8636
9,394
mozilla-comm/ical.js
build/ical.js
function() { var iters = this.ruleIterators; if (iters.length === 0) { return null; } var len = iters.length; var iter; var iterTime; var iterIdx = 0; var chosenIter; // loop through each iterator for (; iterIdx < len; iterIdx++) { iter = iters[iterIdx]; iterTime = iter.last; // if iteration is complete // then we must exclude it from // the search and remove it. if (iter.completed) { len--; if (iterIdx !== 0) { iterIdx--; } iters.splice(iterIdx, 1); continue; } // find the most recent possible choice if (!chosenIter || chosenIter.last.compare(iterTime) > 0) { // that iterator is saved chosenIter = iter; } } // the chosen iterator is returned but not mutated // this iterator contains the most recent event. return chosenIter; }
javascript
function() { var iters = this.ruleIterators; if (iters.length === 0) { return null; } var len = iters.length; var iter; var iterTime; var iterIdx = 0; var chosenIter; // loop through each iterator for (; iterIdx < len; iterIdx++) { iter = iters[iterIdx]; iterTime = iter.last; // if iteration is complete // then we must exclude it from // the search and remove it. if (iter.completed) { len--; if (iterIdx !== 0) { iterIdx--; } iters.splice(iterIdx, 1); continue; } // find the most recent possible choice if (!chosenIter || chosenIter.last.compare(iterTime) > 0) { // that iterator is saved chosenIter = iter; } } // the chosen iterator is returned but not mutated // this iterator contains the most recent event. return chosenIter; }
[ "function", "(", ")", "{", "var", "iters", "=", "this", ".", "ruleIterators", ";", "if", "(", "iters", ".", "length", "===", "0", ")", "{", "return", "null", ";", "}", "var", "len", "=", "iters", ".", "length", ";", "var", "iter", ";", "var", "iterTime", ";", "var", "iterIdx", "=", "0", ";", "var", "chosenIter", ";", "// loop through each iterator", "for", "(", ";", "iterIdx", "<", "len", ";", "iterIdx", "++", ")", "{", "iter", "=", "iters", "[", "iterIdx", "]", ";", "iterTime", "=", "iter", ".", "last", ";", "// if iteration is complete", "// then we must exclude it from", "// the search and remove it.", "if", "(", "iter", ".", "completed", ")", "{", "len", "--", ";", "if", "(", "iterIdx", "!==", "0", ")", "{", "iterIdx", "--", ";", "}", "iters", ".", "splice", "(", "iterIdx", ",", "1", ")", ";", "continue", ";", "}", "// find the most recent possible choice", "if", "(", "!", "chosenIter", "||", "chosenIter", ".", "last", ".", "compare", "(", "iterTime", ")", ">", "0", ")", "{", "// that iterator is saved", "chosenIter", "=", "iter", ";", "}", "}", "// the chosen iterator is returned but not mutated", "// this iterator contains the most recent event.", "return", "chosenIter", ";", "}" ]
Find and return the recurrence rule with the most recent event and return it. @private @return {?ICAL.RecurIterator} Found iterator.
[ "Find", "and", "return", "the", "recurrence", "rule", "with", "the", "most", "recent", "event", "and", "return", "it", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L8661-L8701
9,395
mozilla-comm/ical.js
build/ical.js
function(obj) { if (this.isRecurrenceException()) { throw new Error('cannot relate exception to exceptions'); } if (obj instanceof ICAL.Component) { obj = new ICAL.Event(obj); } if (this.strictExceptions && obj.uid !== this.uid) { throw new Error('attempted to relate unrelated exception'); } var id = obj.recurrenceId.toString(); // we don't sort or manage exceptions directly // here the recurrence expander handles that. this.exceptions[id] = obj; // index RANGE=THISANDFUTURE exceptions so we can // look them up later in getOccurrenceDetails. if (obj.modifiesFuture()) { var item = [ obj.recurrenceId.toUnixTime(), id ]; // we keep them sorted so we can find the nearest // value later on... var idx = ICAL.helpers.binsearchInsert( this.rangeExceptions, item, compareRangeException ); this.rangeExceptions.splice(idx, 0, item); } }
javascript
function(obj) { if (this.isRecurrenceException()) { throw new Error('cannot relate exception to exceptions'); } if (obj instanceof ICAL.Component) { obj = new ICAL.Event(obj); } if (this.strictExceptions && obj.uid !== this.uid) { throw new Error('attempted to relate unrelated exception'); } var id = obj.recurrenceId.toString(); // we don't sort or manage exceptions directly // here the recurrence expander handles that. this.exceptions[id] = obj; // index RANGE=THISANDFUTURE exceptions so we can // look them up later in getOccurrenceDetails. if (obj.modifiesFuture()) { var item = [ obj.recurrenceId.toUnixTime(), id ]; // we keep them sorted so we can find the nearest // value later on... var idx = ICAL.helpers.binsearchInsert( this.rangeExceptions, item, compareRangeException ); this.rangeExceptions.splice(idx, 0, item); } }
[ "function", "(", "obj", ")", "{", "if", "(", "this", ".", "isRecurrenceException", "(", ")", ")", "{", "throw", "new", "Error", "(", "'cannot relate exception to exceptions'", ")", ";", "}", "if", "(", "obj", "instanceof", "ICAL", ".", "Component", ")", "{", "obj", "=", "new", "ICAL", ".", "Event", "(", "obj", ")", ";", "}", "if", "(", "this", ".", "strictExceptions", "&&", "obj", ".", "uid", "!==", "this", ".", "uid", ")", "{", "throw", "new", "Error", "(", "'attempted to relate unrelated exception'", ")", ";", "}", "var", "id", "=", "obj", ".", "recurrenceId", ".", "toString", "(", ")", ";", "// we don't sort or manage exceptions directly", "// here the recurrence expander handles that.", "this", ".", "exceptions", "[", "id", "]", "=", "obj", ";", "// index RANGE=THISANDFUTURE exceptions so we can", "// look them up later in getOccurrenceDetails.", "if", "(", "obj", ".", "modifiesFuture", "(", ")", ")", "{", "var", "item", "=", "[", "obj", ".", "recurrenceId", ".", "toUnixTime", "(", ")", ",", "id", "]", ";", "// we keep them sorted so we can find the nearest", "// value later on...", "var", "idx", "=", "ICAL", ".", "helpers", ".", "binsearchInsert", "(", "this", ".", "rangeExceptions", ",", "item", ",", "compareRangeException", ")", ";", "this", ".", "rangeExceptions", ".", "splice", "(", "idx", ",", "0", ",", "item", ")", ";", "}", "}" ]
Relates a given event exception to this object. If the given component does not share the UID of this event it cannot be related and will throw an exception. If this component is an exception it cannot have other exceptions related to it. @param {ICAL.Component|ICAL.Event} obj Component or event
[ "Relates", "a", "given", "event", "exception", "to", "this", "object", ".", "If", "the", "given", "component", "does", "not", "share", "the", "UID", "of", "this", "event", "it", "cannot", "be", "related", "and", "will", "throw", "an", "exception", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L8795-L8831
9,396
mozilla-comm/ical.js
build/ical.js
function(time) { if (!this.rangeExceptions.length) { return null; } var utc = time.toUnixTime(); var idx = ICAL.helpers.binsearchInsert( this.rangeExceptions, [utc], compareRangeException ); idx -= 1; // occurs before if (idx < 0) { return null; } var rangeItem = this.rangeExceptions[idx]; /* istanbul ignore next: sanity check only */ if (utc < rangeItem[0]) { return null; } return rangeItem[1]; }
javascript
function(time) { if (!this.rangeExceptions.length) { return null; } var utc = time.toUnixTime(); var idx = ICAL.helpers.binsearchInsert( this.rangeExceptions, [utc], compareRangeException ); idx -= 1; // occurs before if (idx < 0) { return null; } var rangeItem = this.rangeExceptions[idx]; /* istanbul ignore next: sanity check only */ if (utc < rangeItem[0]) { return null; } return rangeItem[1]; }
[ "function", "(", "time", ")", "{", "if", "(", "!", "this", ".", "rangeExceptions", ".", "length", ")", "{", "return", "null", ";", "}", "var", "utc", "=", "time", ".", "toUnixTime", "(", ")", ";", "var", "idx", "=", "ICAL", ".", "helpers", ".", "binsearchInsert", "(", "this", ".", "rangeExceptions", ",", "[", "utc", "]", ",", "compareRangeException", ")", ";", "idx", "-=", "1", ";", "// occurs before", "if", "(", "idx", "<", "0", ")", "{", "return", "null", ";", "}", "var", "rangeItem", "=", "this", ".", "rangeExceptions", "[", "idx", "]", ";", "/* istanbul ignore next: sanity check only */", "if", "(", "utc", "<", "rangeItem", "[", "0", "]", ")", "{", "return", "null", ";", "}", "return", "rangeItem", "[", "1", "]", ";", "}" ]
Finds the range exception nearest to the given date. @param {ICAL.Time} time usually an occurrence time of an event @return {?ICAL.Event} the related event/exception or null
[ "Finds", "the", "range", "exception", "nearest", "to", "the", "given", "date", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L8854-L8881
9,397
mozilla-comm/ical.js
build/ical.js
function() { var rules = this.component.getAllProperties('rrule'); var i = 0; var len = rules.length; var result = Object.create(null); for (; i < len; i++) { var value = rules[i].getFirstValue(); result[value.freq] = true; } return result; }
javascript
function() { var rules = this.component.getAllProperties('rrule'); var i = 0; var len = rules.length; var result = Object.create(null); for (; i < len; i++) { var value = rules[i].getFirstValue(); result[value.freq] = true; } return result; }
[ "function", "(", ")", "{", "var", "rules", "=", "this", ".", "component", ".", "getAllProperties", "(", "'rrule'", ")", ";", "var", "i", "=", "0", ";", "var", "len", "=", "rules", ".", "length", ";", "var", "result", "=", "Object", ".", "create", "(", "null", ")", ";", "for", "(", ";", "i", "<", "len", ";", "i", "++", ")", "{", "var", "value", "=", "rules", "[", "i", "]", ".", "getFirstValue", "(", ")", ";", "result", "[", "value", ".", "freq", "]", "=", "true", ";", "}", "return", "result", ";", "}" ]
Returns the types of recurrences this event may have. Returned as an object with the following possible keys: - YEARLY - MONTHLY - WEEKLY - DAILY - MINUTELY - SECONDLY @return {Object.<ICAL.Recur.frequencyValues, Boolean>} Object of recurrence flags
[ "Returns", "the", "types", "of", "recurrences", "this", "event", "may", "have", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L9025-L9037
9,398
mozilla-comm/ical.js
build/ical.js
function(ical) { //TODO: this is sync now in the future we will have a incremental parser. if (typeof(ical) === 'string') { ical = ICAL.parse(ical); } if (!(ical instanceof ICAL.Component)) { ical = new ICAL.Component(ical); } var components = ical.getAllSubcomponents(); var i = 0; var len = components.length; var component; for (; i < len; i++) { component = components[i]; switch (component.name) { case 'vtimezone': if (this.parseTimezone) { var tzid = component.getFirstPropertyValue('tzid'); if (tzid) { this.ontimezone(new ICAL.Timezone({ tzid: tzid, component: component })); } } break; case 'vevent': if (this.parseEvent) { this.onevent(new ICAL.Event(component)); } break; default: continue; } } //XXX: ideally we should do a "nextTick" here // so in all cases this is actually async. this.oncomplete(); }
javascript
function(ical) { //TODO: this is sync now in the future we will have a incremental parser. if (typeof(ical) === 'string') { ical = ICAL.parse(ical); } if (!(ical instanceof ICAL.Component)) { ical = new ICAL.Component(ical); } var components = ical.getAllSubcomponents(); var i = 0; var len = components.length; var component; for (; i < len; i++) { component = components[i]; switch (component.name) { case 'vtimezone': if (this.parseTimezone) { var tzid = component.getFirstPropertyValue('tzid'); if (tzid) { this.ontimezone(new ICAL.Timezone({ tzid: tzid, component: component })); } } break; case 'vevent': if (this.parseEvent) { this.onevent(new ICAL.Event(component)); } break; default: continue; } } //XXX: ideally we should do a "nextTick" here // so in all cases this is actually async. this.oncomplete(); }
[ "function", "(", "ical", ")", "{", "//TODO: this is sync now in the future we will have a incremental parser.", "if", "(", "typeof", "(", "ical", ")", "===", "'string'", ")", "{", "ical", "=", "ICAL", ".", "parse", "(", "ical", ")", ";", "}", "if", "(", "!", "(", "ical", "instanceof", "ICAL", ".", "Component", ")", ")", "{", "ical", "=", "new", "ICAL", ".", "Component", "(", "ical", ")", ";", "}", "var", "components", "=", "ical", ".", "getAllSubcomponents", "(", ")", ";", "var", "i", "=", "0", ";", "var", "len", "=", "components", ".", "length", ";", "var", "component", ";", "for", "(", ";", "i", "<", "len", ";", "i", "++", ")", "{", "component", "=", "components", "[", "i", "]", ";", "switch", "(", "component", ".", "name", ")", "{", "case", "'vtimezone'", ":", "if", "(", "this", ".", "parseTimezone", ")", "{", "var", "tzid", "=", "component", ".", "getFirstPropertyValue", "(", "'tzid'", ")", ";", "if", "(", "tzid", ")", "{", "this", ".", "ontimezone", "(", "new", "ICAL", ".", "Timezone", "(", "{", "tzid", ":", "tzid", ",", "component", ":", "component", "}", ")", ")", ";", "}", "}", "break", ";", "case", "'vevent'", ":", "if", "(", "this", ".", "parseEvent", ")", "{", "this", ".", "onevent", "(", "new", "ICAL", ".", "Event", "(", "component", ")", ")", ";", "}", "break", ";", "default", ":", "continue", ";", "}", "}", "//XXX: ideally we should do a \"nextTick\" here", "// so in all cases this is actually async.", "this", ".", "oncomplete", "(", ")", ";", "}" ]
Process a string or parse ical object. This function itself will return nothing but will start the parsing process. Events must be registered prior to calling this method. @param {ICAL.Component|String|Object} ical The component to process, either in its final form, as a jCal Object, or string representation
[ "Process", "a", "string", "or", "parse", "ical", "object", ".", "This", "function", "itself", "will", "return", "nothing", "but", "will", "start", "the", "parsing", "process", "." ]
2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d
https://github.com/mozilla-comm/ical.js/blob/2d08c79b4e77bfe4dbf1c9ac0b463580f0605a7d/build/ical.js#L9376-L9419
9,399
serverless/serverless-kubeless
lib/deploy.js
deployMQTrigger
function deployMQTrigger(mqType, name, namespace, topic, options) { const opts = _.defaults({}, options, { log: console.log, }); const trigger = { apiVersion: 'kubeless.io/v1beta1', kind: `${mqType}Trigger`, metadata: { name: _.kebabCase(`${name}-${topic}`), namespace, labels: { 'created-by': 'kubeless', }, }, spec: { functionSelector: { matchLabels: { 'created-by': 'kubeless', function: name, }, }, topic, }, }; const triggerApi = new CRD( 'apis/kubeless.io', 'v1beta1', namespace, `${mqType.toLowerCase()}triggers` ); opts.log(`Deploying ${mqType} trigger: ${trigger.metadata.name}`); return triggerApi.getItem(trigger.metadata.name) .then((res) => { if (res.code === 404) { return triggerApi.post({ body: trigger }); } opts.log(`Updating existing ${mqType} trigger`); return triggerApi.put(trigger.metadata.name, { body: trigger }); }); }
javascript
function deployMQTrigger(mqType, name, namespace, topic, options) { const opts = _.defaults({}, options, { log: console.log, }); const trigger = { apiVersion: 'kubeless.io/v1beta1', kind: `${mqType}Trigger`, metadata: { name: _.kebabCase(`${name}-${topic}`), namespace, labels: { 'created-by': 'kubeless', }, }, spec: { functionSelector: { matchLabels: { 'created-by': 'kubeless', function: name, }, }, topic, }, }; const triggerApi = new CRD( 'apis/kubeless.io', 'v1beta1', namespace, `${mqType.toLowerCase()}triggers` ); opts.log(`Deploying ${mqType} trigger: ${trigger.metadata.name}`); return triggerApi.getItem(trigger.metadata.name) .then((res) => { if (res.code === 404) { return triggerApi.post({ body: trigger }); } opts.log(`Updating existing ${mqType} trigger`); return triggerApi.put(trigger.metadata.name, { body: trigger }); }); }
[ "function", "deployMQTrigger", "(", "mqType", ",", "name", ",", "namespace", ",", "topic", ",", "options", ")", "{", "const", "opts", "=", "_", ".", "defaults", "(", "{", "}", ",", "options", ",", "{", "log", ":", "console", ".", "log", ",", "}", ")", ";", "const", "trigger", "=", "{", "apiVersion", ":", "'kubeless.io/v1beta1'", ",", "kind", ":", "`", "${", "mqType", "}", "`", ",", "metadata", ":", "{", "name", ":", "_", ".", "kebabCase", "(", "`", "${", "name", "}", "${", "topic", "}", "`", ")", ",", "namespace", ",", "labels", ":", "{", "'created-by'", ":", "'kubeless'", ",", "}", ",", "}", ",", "spec", ":", "{", "functionSelector", ":", "{", "matchLabels", ":", "{", "'created-by'", ":", "'kubeless'", ",", "function", ":", "name", ",", "}", ",", "}", ",", "topic", ",", "}", ",", "}", ";", "const", "triggerApi", "=", "new", "CRD", "(", "'apis/kubeless.io'", ",", "'v1beta1'", ",", "namespace", ",", "`", "${", "mqType", ".", "toLowerCase", "(", ")", "}", "`", ")", ";", "opts", ".", "log", "(", "`", "${", "mqType", "}", "${", "trigger", ".", "metadata", ".", "name", "}", "`", ")", ";", "return", "triggerApi", ".", "getItem", "(", "trigger", ".", "metadata", ".", "name", ")", ".", "then", "(", "(", "res", ")", "=>", "{", "if", "(", "res", ".", "code", "===", "404", ")", "{", "return", "triggerApi", ".", "post", "(", "{", "body", ":", "trigger", "}", ")", ";", "}", "opts", ".", "log", "(", "`", "${", "mqType", "}", "`", ")", ";", "return", "triggerApi", ".", "put", "(", "trigger", ".", "metadata", ".", "name", ",", "{", "body", ":", "trigger", "}", ")", ";", "}", ")", ";", "}" ]
Handling Kafka and NATS message queue trigger @param {MQTypes} mqType @param {string} name @param {string} namespace @param {string} topic @param {object} options
[ "Handling", "Kafka", "and", "NATS", "message", "queue", "trigger" ]
b85b77f584139a8d53f06346b3036f8b3017c9f9
https://github.com/serverless/serverless-kubeless/blob/b85b77f584139a8d53f06346b3036f8b3017c9f9/lib/deploy.js#L347-L386