react-imported-component
Version:
I will import your component, and help to handle it
14 lines (13 loc) • 697 B
JavaScript
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');