UNPKG

@polkadot/types-codec

Version:
41 lines (40 loc) 1.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.typeToConstructor = typeToConstructor; exports.typesToConstructors = typesToConstructors; exports.mapToTypeMap = mapToTypeMap; /** * @internal * From a type string or class, return the associated type class */ function typeToConstructor(registry, type) { return typeof type === 'function' ? type : registry.createClassUnsafe(type); } /** * @internal * Takes an input array of types and returns the associated classes for it */ function typesToConstructors(registry, types) { const count = types.length; const result = new Array(count); for (let i = 0; i < count; i++) { result[i] = typeToConstructor(registry, types[i]); } return result; } /** * @internal * Takes an input map of the form `{ [string]: string | CodecClass }` and returns a map of `{ [string]: CodecClass }` */ function mapToTypeMap(registry, input) { const entries = Object.entries(input); const count = entries.length; const output = [new Array(count), new Array(count)]; for (let i = 0; i < count; i++) { output[1][i] = entries[i][0]; output[0][i] = typeToConstructor(registry, entries[i][1]); } return output; }