UNPKG

@gear-js/api

Version:

A JavaScript library that provides functionality to connect GEAR Component APIs.

46 lines (42 loc) 1.2 kB
'use strict'; var regexp = require('./regexp.js'); function transformTypes(types) { return Object.values(types).reduce((res, types) => ({ ...res, ...types }), {}); } function convertString(string) { const wordsArray = string .replace(/[_:, .]+/g, ' ') .trim() .split(' '); return wordsArray.map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(''); } function joinTypePath(path) { return convertString(path.join('_')); } function typeIsGeneric(type) { const matches = type.match(regexp.REGULAR_EXP.generic); if (matches) { return true; } else { return false; } } function typeIsString(type) { return ['string', 'utf8', 'utf-8', 'text'].includes(type.toLowerCase()); } function getTypeAndPayload(type, payload) { if (payload === undefined) { payload = '0x'; } if (type === undefined) { type = 'Bytes'; } return [type, payload]; } exports.convertString = convertString; exports.getTypeAndPayload = getTypeAndPayload; exports.joinTypePath = joinTypePath; exports.transformTypes = transformTypes; exports.typeIsGeneric = typeIsGeneric; exports.typeIsString = typeIsString;