Skip to content

vue-qs v0.1.18


vue-qs / createArrayCodec

Function: createArrayCodec()

createArrayCodec<T>(elementCodec, delimiter): QueryCodec<T[]>

Defined in: serializers.ts:208

Array codec factory for handling arrays with a specific element type

Type Parameters

T

T

The type of array elements

Parameters

elementCodec

QueryCodec<T>

Codec for individual array elements

delimiter

string = ','

String to use for separating array elements (default: ',')

Returns

QueryCodec<T[]>

QueryCodec for arrays of the specified type

Example

ts
// String array: ?tags=vue,react,angular
const tags = queryRef('tags', {
  defaultValue: [],
  codec: createArrayCodec(stringCodec)
});

// Number array: ?pages=1,2,3
const pages = queryRef('pages', {
  defaultValue: [],
  codec: createArrayCodec(numberCodec)
});

// Custom delimiter: ?tags=vue|react|angular
const tags = queryRef('tags', {
  defaultValue: [],
  codec: createArrayCodec(stringCodec, '|')
});

Released under the MIT License.