A test of lepton flavor universality in B$^{\pm}$$\to$ K$^{\pm}\mu^+\mu^-$ and B$^{\pm}$$\to$ K$^{\pm}$e$^+$e$^-$ decays, as well as a measurement of differential and integrated branching fractions of a nonresonant B$^{\pm}$$\to$ K$^{\pm}\mu^+\mu^-$ decay are presented. The analysis is made possible by a dedicated data set of proton-proton collisions at $\sqrt{s}$ = 13 TeV recorded in 2018, by the CMS experiment at the LHC, using a special high-rate data stream designed for collecting about 10 billion unbiased b hadron decays. The ratio of the branching fractions $\mathcal{B}$(B$^{\pm}$$\to$ K$^{\pm}\mu^+\mu^-$) to $\mathcal{B}$(B$^{\pm}$$\to$ K$^{\pm}$e$^+$e$^-$) is determined from the measured double ratio $R$(K) of these decays to the respective branching fractions of the B$^\pm$$\to$ J/$\psi$K$^\pm$ with J/$\psi$$\to$$\mu^+\mu^-$ and e$^+$e$^-$ decays, which allow for significant cancellation of systematic uncertainties. The ratio $R$(K) is measured in the range 1.1 $\lt$$q^2$$\lt$ 6.0 GeV$^2$, where $q$ is the invariant mass of the lepton pair, and is found to be $R$(K) = 0.78 $^{+0.47}_{-0.23}$, in agreement with the standard model expectation $R$(K) $\approx$ 1. This measurement is limited by the statistical precision of the electron channel. The integrated branching fraction in the same $q^2$ range, $\mathcal{B}$(B$^{\pm}$$\to$ K$^{\pm}\mu^+\mu^-$) = (12.42 $\pm$ 0.68) $\times$ 10$^{-8}$, is consistent with the present world-average value and has a comparable precision.