1+ /*
2+ This file contains libraries pulled from various sources. Their corresponding licenses are also attached.
3+ */
4+
5+
6+ /*
7+ This is a slightly modified version of rahatarmanahmed's get-key-range npm package. You can see the package at
8+ https://www.npmjs.com/package/get-key-range
9+
10+ License:
11+ The MIT License (MIT)
12+
13+ Copyright (c) 2016 Rahat Ahmed
14+
15+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
16+
17+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
18+
19+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+ */
21+
22+ function getKeyRange ( obj , key ) {
23+ let ranges = Object . keys ( obj ) ;
24+ for ( let i = ranges . length - 1 ; i >= 0 ; i -- ) {
25+ if ( isInRange ( ranges [ i ] , key ) ) return obj [ ranges [ i ] ]
26+ }
27+ }
28+ function isInRange ( ranges , n ) {
29+ ranges = ranges . split ( / \s * , \s * / ) ;
30+ return ranges . some ( inRange . bind ( null , n ) ) ;
31+
32+ function inRange ( n , range ) {
33+ var limits = range . split ( / \s * - \s * / ) ;
34+
35+ if ( limits . length === 1 ) return range == n ;
36+ if ( limits . length !== 2 ) throw new Error ( 'Invalid range:' + range ) ;
37+
38+ var max = Math . max ( limits [ 0 ] , limits [ 1 ] ) ;
39+ var min = Math . min ( limits [ 0 ] , limits [ 1 ] ) ;
40+
41+ return min <= n && n <= max ;
42+ }
43+ }
44+
45+ window . getKeyRange = getKeyRange ;
46+
47+
48+ /*
49+ This is the get-in-range package from npmjs.
50+ https://www.npmjs.com/package/get-in-range
51+
52+ GNU LESSER GENERAL PUBLIC LICENSE
53+ Version 3, 29 June 2007
54+
55+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
56+ Everyone is permitted to copy and distribute verbatim copies
57+ of this license document, but changing it is not allowed.
58+
59+
60+ This version of the GNU Lesser General Public License incorporates
61+ the terms and conditions of version 3 of the GNU General Public
62+ License, supplemented by the additional permissions listed below.
63+
64+ 0. Additional Definitions.
65+
66+ As used herein, "this License" refers to version 3 of the GNU Lesser
67+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
68+ General Public License.
69+
70+ "The Library" refers to a covered work governed by this License,
71+ other than an Application or a Combined Work as defined below.
72+
73+ An "Application" is any work that makes use of an interface provided
74+ by the Library, but which is not otherwise based on the Library.
75+ Defining a subclass of a class defined by the Library is deemed a mode
76+ of using an interface provided by the Library.
77+
78+ A "Combined Work" is a work produced by combining or linking an
79+ Application with the Library. The particular version of the Library
80+ with which the Combined Work was made is also called the "Linked
81+ Version".
82+
83+ The "Minimal Corresponding Source" for a Combined Work means the
84+ Corresponding Source for the Combined Work, excluding any source code
85+ for portions of the Combined Work that, considered in isolation, are
86+ based on the Application, and not on the Linked Version.
87+
88+ The "Corresponding Application Code" for a Combined Work means the
89+ object code and/or source code for the Application, including any data
90+ and utility programs needed for reproducing the Combined Work from the
91+ Application, but excluding the System Libraries of the Combined Work.
92+
93+ 1. Exception to Section 3 of the GNU GPL.
94+
95+ You may convey a covered work under sections 3 and 4 of this License
96+ without being bound by section 3 of the GNU GPL.
97+
98+ 2. Conveying Modified Versions.
99+
100+ If you modify a copy of the Library, and, in your modifications, a
101+ facility refers to a function or data to be supplied by an Application
102+ that uses the facility (other than as an argument passed when the
103+ facility is invoked), then you may convey a copy of the modified
104+ version:
105+
106+ a) under this License, provided that you make a good faith effort to
107+ ensure that, in the event an Application does not supply the
108+ function or data, the facility still operates, and performs
109+ whatever part of its purpose remains meaningful, or
110+
111+ b) under the GNU GPL, with none of the additional permissions of
112+ this License applicable to that copy.
113+
114+ 3. Object Code Incorporating Material from Library Header Files.
115+
116+ The object code form of an Application may incorporate material from
117+ a header file that is part of the Library. You may convey such object
118+ code under terms of your choice, provided that, if the incorporated
119+ material is not limited to numerical parameters, data structure
120+ layouts and accessors, or small macros, inline functions and templates
121+ (ten or fewer lines in length), you do both of the following:
122+
123+ a) Give prominent notice with each copy of the object code that the
124+ Library is used in it and that the Library and its use are
125+ covered by this License.
126+
127+ b) Accompany the object code with a copy of the GNU GPL and this license
128+ document.
129+
130+ 4. Combined Works.
131+
132+ You may convey a Combined Work under terms of your choice that,
133+ taken together, effectively do not restrict modification of the
134+ portions of the Library contained in the Combined Work and reverse
135+ engineering for debugging such modifications, if you also do each of
136+ the following:
137+
138+ a) Give prominent notice with each copy of the Combined Work that
139+ the Library is used in it and that the Library and its use are
140+ covered by this License.
141+
142+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
143+ document.
144+
145+ c) For a Combined Work that displays copyright notices during
146+ execution, include the copyright notice for the Library among
147+ these notices, as well as a reference directing the user to the
148+ copies of the GNU GPL and this license document.
149+
150+ d) Do one of the following:
151+
152+ 0) Convey the Minimal Corresponding Source under the terms of this
153+ License, and the Corresponding Application Code in a form
154+ suitable for, and under terms that permit, the user to
155+ recombine or relink the Application with a modified version of
156+ the Linked Version to produce a modified Combined Work, in the
157+ manner specified by section 6 of the GNU GPL for conveying
158+ Corresponding Source.
159+
160+ 1) Use a suitable shared library mechanism for linking with the
161+ Library. A suitable mechanism is one that (a) uses at run time
162+ a copy of the Library already present on the user's computer
163+ system, and (b) will operate properly with a modified version
164+ of the Library that is interface-compatible with the Linked
165+ Version.
166+
167+ e) Provide Installation Information, but only if you would otherwise
168+ be required to provide such information under section 6 of the
169+ GNU GPL, and only to the extent that such information is
170+ necessary to install and execute a modified version of the
171+ Combined Work produced by recombining or relinking the
172+ Application with a modified version of the Linked Version. (If
173+ you use option 4d0, the Installation Information must accompany
174+ the Minimal Corresponding Source and Corresponding Application
175+ Code. If you use option 4d1, you must provide the Installation
176+ Information in the manner specified by section 6 of the GNU GPL
177+ for conveying Corresponding Source.)
178+
179+ 5. Combined Libraries.
180+
181+ You may place library facilities that are a work based on the
182+ Library side by side in a single library together with other library
183+ facilities that are not Applications and are not covered by this
184+ License, and convey such a combined library under terms of your
185+ choice, if you do both of the following:
186+
187+ a) Accompany the combined library with a copy of the same work based
188+ on the Library, uncombined with any other library facilities,
189+ conveyed under the terms of this License.
190+
191+ b) Give prominent notice with the combined library that part of it
192+ is a work based on the Library, and explaining where to find the
193+ accompanying uncombined form of the same work.
194+
195+ 6. Revised Versions of the GNU Lesser General Public License.
196+
197+ The Free Software Foundation may publish revised and/or new versions
198+ of the GNU Lesser General Public License from time to time. Such new
199+ versions will be similar in spirit to the present version, but may
200+ differ in detail to address new problems or concerns.
201+
202+ Each version is given a distinguishing version number. If the
203+ Library as you received it specifies that a certain numbered version
204+ of the GNU Lesser General Public License "or any later version"
205+ applies to it, you have the option of following the terms and
206+ conditions either of that published version or of any later version
207+ published by the Free Software Foundation. If the Library as you
208+ received it does not specify a version number of the GNU Lesser
209+ General Public License, you may choose any version of the GNU Lesser
210+ General Public License ever published by the Free Software Foundation.
211+
212+ If the Library as you received it specifies that a proxy can decide
213+ whether future versions of the GNU Lesser General Public License shall
214+ apply, that proxy's public statement of acceptance of any version is
215+ permanent authorization for you to choose that version for the
216+ Library.
217+
218+ */
219+
220+ /**
221+ * Returns closest value to input in given range
222+ *
223+ * @param {number } input
224+ * @param {number } min Minimum value of range
225+ * @param {number } max Maximum value of range
226+ * @param {boolean } [onerr] Return NaN instead of throwing error.
227+ * @returns {number } Closest value to input in given range
228+ */
229+ function getInRange ( input , min , max , onerr ) {
230+
231+ let pinput = parseFloat ( input ) ;
232+ let pmin = parseFloat ( min ) ;
233+ let pmax = parseFloat ( max ) ;
234+
235+ if ( isNaN ( pmin ) || isNaN ( pmax ) || isNaN ( pinput ) ) {
236+ if ( onerr ) return NaN ;
237+ throw "given a argument that is NaN" ;
238+ }
239+
240+ if ( pmin > pmax ) {
241+ if ( onerr ) return NaN ;
242+ throw "provided minimum value is larger then maximum value" ;
243+ }
244+
245+ if ( pinput <= pmin ) return pmin ;
246+
247+ if ( pinput >= pmax ) return pmax ;
248+
249+ return pinput ;
250+
251+ }
252+
253+ window . getInRange = getInRange ;
0 commit comments