11'use strict' ;
22
3+ import { Message } from './types' ;
4+
35/**
46 * Module Dependencies.
57 */
@@ -33,33 +35,39 @@ var toplevel = ['integrations', 'anonymousId', 'timestamp', 'context'];
3335
3436/**
3537 * Normalize `msg` based on integrations `list`.
36- *
37- * @param {Object } msg
38- * @param {Array } list
39- * @return {Function }
4038 */
4139
42- function normalize ( msg , list ) {
40+ interface NormalizedMessage {
41+ integrations ?: {
42+ [ key : string ] : string ;
43+ } ;
44+ context ?: unknown ;
45+ }
46+
47+ function normalize ( msg : Message , list : Array < any > ) : NormalizedMessage {
4348 var lower = map ( function ( s ) {
4449 return s . toLowerCase ( ) ;
4550 } , list ) ;
46- var opts = msg . options || { } ;
51+ var opts : Message = msg . options || { } ;
4752 var integrations = opts . integrations || { } ;
4853 var providers = opts . providers || { } ;
4954 var context = opts . context || { } ;
50- var ret = { } ;
55+ var ret : {
56+ integrations ?: { [ key : string ] : string } ;
57+ context ?: unknown ;
58+ } = { } ;
5159 debug ( '<-' , msg ) ;
5260
5361 // integrations.
54- each ( function ( value , key ) {
62+ each ( function ( value : string , key : string ) {
5563 if ( ! integration ( key ) ) return ;
5664 if ( ! has . call ( integrations , key ) ) integrations [ key ] = value ;
5765 delete opts [ key ] ;
5866 } , opts ) ;
5967
6068 // providers.
6169 delete opts . providers ;
62- each ( function ( value , key ) {
70+ each ( function ( value : string , key : string ) {
6371 if ( ! integration ( key ) ) return ;
6472 if ( type ( integrations [ key ] ) === 'object' ) return ;
6573 if ( has . call ( integrations , key ) && typeof providers [ key ] === 'boolean' )
@@ -69,7 +77,7 @@ function normalize(msg, list) {
6977
7078 // move all toplevel options to msg
7179 // and the rest to context.
72- each ( function ( value , key ) {
80+ each ( function ( _value : any , key : string | number ) {
7381 if ( includes ( key , toplevel ) ) {
7482 ret [ key ] = opts [ key ] ;
7583 } else {
@@ -88,7 +96,7 @@ function normalize(msg, list) {
8896 debug ( '->' , ret ) ;
8997 return ret ;
9098
91- function integration ( name ) {
99+ function integration ( name : string ) {
92100 return ! ! (
93101 includes ( name , list ) ||
94102 name . toLowerCase ( ) === 'all' ||
0 commit comments