UNPKG

react-imported-component

Version:
14 lines (13 loc) 697 B
import { readFile, writeFile } from 'fs'; import { relative, sep } from 'path'; import { promisify } from 'util'; export const normalizePath = (path) => path.split(sep).join('/'); export const getRelative = (from, to) => { // force one unit paths const rel = normalizePath(relative(from, to)); return rel[0] !== '.' ? './' + rel : rel; }; export const getMatchString = (pattern, selected) => (str) => (str.match(new RegExp(pattern, 'g')) || []).map((statement) => (statement.match(new RegExp(pattern, 'i')) || [])[selected]); export const pReadFile = promisify(readFile); export const pWriteFile = promisify(writeFile); export const getFileContent = (file) => pReadFile(file, 'utf8');