UNPKG

@gear-js/api

Version:

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

39 lines (36 loc) 1.05 kB
import { REGULAR_EXP } from './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(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]; } export { convertString, getTypeAndPayload, joinTypePath, transformTypes, typeIsGeneric, typeIsString };