1+ import { EncodedValue } from "types" ;
2+
13/**
24 * Interprets an encoded string and returns either the string or null/undefined if not available.
35 * Ignores array inputs (takes just first element in array)
46 * @param input encoded string
57 */
68function getEncodedValue (
7- input : string | ( string | null ) [ ] | null | undefined ,
9+ input : EncodedValue ,
810 allowEmptyString ?: boolean
911) : string | null | undefined {
1012 if ( input == null ) {
@@ -35,7 +37,7 @@ function getEncodedValue(
3537 * @param input encoded string
3638 */
3739function getEncodedValueArray (
38- input : string | ( string | null ) [ ] | null | undefined
40+ input : EncodedValue
3941) : ( string | null ) [ ] | null | undefined {
4042 if ( input == null ) {
4143 return input ;
@@ -78,7 +80,7 @@ export function encodeDate(
7880 * @return {Date } parsed date
7981 */
8082export function decodeDate (
81- input : string | ( string | null ) [ ] | null | undefined
83+ input : EncodedValue
8284) : Date | null | undefined {
8385 const dateString = getEncodedValue ( input ) ;
8486 if ( dateString == null ) return dateString ;
@@ -130,7 +132,7 @@ export function encodeDateTime(
130132 * @return {Date } parsed date
131133 */
132134export function decodeDateTime (
133- input : string | ( string | null ) [ ] | null | undefined
135+ input : EncodedValue
134136) : Date | null | undefined {
135137 const dateString = getEncodedValue ( input ) ;
136138 if ( dateString == null ) return dateString ;
@@ -170,7 +172,7 @@ export function encodeBoolean(
170172 * @return {Boolean } the boolean value
171173 */
172174export function decodeBoolean (
173- input : string | ( string | null ) [ ] | null | undefined
175+ input : EncodedValue
174176) : boolean | null | undefined {
175177 const boolStr = getEncodedValue ( input ) ;
176178 if ( boolStr == null ) return boolStr ;
@@ -210,7 +212,7 @@ export function encodeNumber(
210212 * @return {Number } the number value
211213 */
212214export function decodeNumber (
213- input : string | ( string | null ) [ ] | null | undefined
215+ input : EncodedValue
214216) : number | null | undefined {
215217 const numStr = getEncodedValue ( input ) ;
216218 if ( numStr == null ) return numStr ;
@@ -227,7 +229,7 @@ export function decodeNumber(
227229 * @return {String } the encoded string
228230 */
229231export function encodeString (
230- str : string | ( string | null ) [ ] | null | undefined
232+ str : EncodedValue
231233) : string | null | undefined {
232234 if ( str == null ) {
233235 return str ;
@@ -245,7 +247,7 @@ export function encodeString(
245247 * @return {String } the string value
246248 */
247249export function decodeString (
248- input : string | ( string | null ) [ ] | null | undefined
250+ input : EncodedValue
249251) : string | null | undefined {
250252 const str = getEncodedValue ( input , true ) ;
251253 if ( str == null ) return str ;
@@ -263,7 +265,7 @@ export function decodeString(
263265 * @return {String } the string value from enumValues
264266 */
265267export function decodeEnum < T extends string > (
266- input : string | ( string | null ) [ ] | null | undefined ,
268+ input : EncodedValue ,
267269 enumValues : T [ ]
268270) : T | null | undefined {
269271 const str = decodeString ( input ) ;
@@ -280,7 +282,7 @@ export function decodeEnum<T extends string>(
280282 * @return {T[] } the string value from enumValues
281283 */
282284export function decodeArrayEnum < T extends string > (
283- input : string | ( string | null ) [ ] | null | undefined ,
285+ input : EncodedValue ,
284286 enumValues : T [ ]
285287) : T [ ] | null | undefined {
286288 const arr = decodeArray ( input ) ;
@@ -302,7 +304,7 @@ export function decodeArrayEnum<T extends string>(
302304 * @return {T[] } the string value from enumValues
303305 */
304306export function decodeDelimitedArrayEnum < T extends string > (
305- input : string | ( string | null ) [ ] | null | undefined ,
307+ input : EncodedValue ,
306308 enumValues : T [ ] ,
307309 entrySeparator = '_'
308310) : T [ ] | null | undefined {
@@ -336,7 +338,7 @@ export function encodeJson(
336338 * @return {Any } The javascript representation
337339 */
338340export function decodeJson (
339- input : string | ( string | null ) [ ] | null | undefined
341+ input : EncodedValue
340342) : any | null | undefined {
341343 const jsonStr = getEncodedValue ( input ) ;
342344 if ( jsonStr == null ) return jsonStr ;
@@ -376,7 +378,7 @@ export function encodeArray(
376378 * @return {Array } The javascript representation
377379 */
378380export function decodeArray (
379- input : string | ( string | null ) [ ] | null | undefined
381+ input : EncodedValue
380382) : ( string | null ) [ ] | null | undefined {
381383 const arr = getEncodedValueArray ( input ) ;
382384 if ( arr == null ) return arr ;
@@ -409,7 +411,7 @@ export function encodeNumericArray(
409411 * @return {Array } The javascript representation
410412 */
411413export function decodeNumericArray (
412- input : string | ( string | null ) [ ] | null | undefined
414+ input : EncodedValue
413415) : ( number | null ) [ ] | null | undefined {
414416 const arr = decodeArray ( input ) ;
415417 if ( arr == null ) return arr ;
@@ -449,7 +451,7 @@ export function encodeDelimitedArray(
449451 * @return {Array } The javascript representation
450452 */
451453export function decodeDelimitedArray (
452- input : string | ( string | null ) [ ] | null | undefined ,
454+ input : EncodedValue ,
453455 entrySeparator = '_'
454456) : ( string | null ) [ ] | null | undefined {
455457 const arrayStr = getEncodedValue ( input , true ) ;
@@ -481,7 +483,7 @@ export const encodeDelimitedNumericArray = encodeDelimitedArray as (
481483 * @return {Array } The javascript representation
482484 */
483485export function decodeDelimitedNumericArray (
484- arrayStr : string | ( string | null ) [ ] | null | undefined ,
486+ arrayStr : EncodedValue ,
485487 entrySeparator = '_'
486488) : ( number | null ) [ ] | null | undefined {
487489 const decoded = decodeDelimitedArray ( arrayStr , entrySeparator ) ;
@@ -528,7 +530,7 @@ export function encodeObject(
528530 * @return {Object } The javascript object
529531 */
530532export function decodeObject (
531- input : string | ( string | null ) [ ] | null | undefined ,
533+ input : EncodedValue ,
532534 keyValSeparator = '-' ,
533535 entrySeparator = '_'
534536) : { [ key : string ] : string } | null | undefined {
@@ -577,7 +579,7 @@ export const encodeNumericObject = encodeObject as (
577579 * @return {Object } The javascript object
578580 */
579581export function decodeNumericObject (
580- input : string | ( string | null ) [ ] | null | undefined ,
582+ input : EncodedValue ,
581583 keyValSeparator = '-' ,
582584 entrySeparator = '_'
583585) : { [ key : string ] : number | null | undefined } | null | undefined {
0 commit comments