How to use the ramda-extension.memoizeWithIdentity function in ramda-extension

To help you get started, we’ve selected a few ramda-extension examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lundegaard / react-union / packages / react-union-scripts / scripts / lib / fs.js View on Github external
const makeDir = name =>
	new Promise((resolve, reject) => {
		mkdirp(name, err => (err ? reject(err) : resolve()));
	});

const isDirectory = source => fs.lstatSync(source).isDirectory();

const readDirs = dir =>
	fs.existsSync(dir)
		? R.compose(
				R.filter(name => isDirectory(path.join(dir, name))),
				fs.readdirSync
		  )(dir)
		: [];

const getRootPackageJSON = R_.memoizeWithIdentity(() =>
	fs.readJsonSync(path.join(process.cwd(), 'package.json'))
);

const readAllWorkspacesFlatten = R_.memoizeWithIdentity(() =>
	R.o(R.flatten, R.map(glob.sync))(getWorkspacesPatterns())
);

const getWorkspacesPatterns = () => {
	const rootPackage = getRootPackageJSON();
	return rootPackage.private && rootPackage.workspaces;
};

const resolveWorkspacesPackagePattern = R.cond([
	[R.is(RegExp), R.identity],
	[R_.isString, pattern => R_.constructRegExp(pattern, 'i')],
	[R_.isArray, pattern => R_.constructRegExp(`(${R.join('|', pattern)})`, 'i')],
github lundegaard / react-union / packages / react-union-scripts / scripts / lib / fs.js View on Github external
const isDirectory = source => fs.lstatSync(source).isDirectory();

const readDirs = dir =>
	fs.existsSync(dir)
		? R.compose(
				R.filter(name => isDirectory(path.join(dir, name))),
				fs.readdirSync
		  )(dir)
		: [];

const getRootPackageJSON = R_.memoizeWithIdentity(() =>
	fs.readJsonSync(path.join(process.cwd(), 'package.json'))
);

const readAllWorkspacesFlatten = R_.memoizeWithIdentity(() =>
	R.o(R.flatten, R.map(glob.sync))(getWorkspacesPatterns())
);

const getWorkspacesPatterns = () => {
	const rootPackage = getRootPackageJSON();
	return rootPackage.private && rootPackage.workspaces;
};

const resolveWorkspacesPackagePattern = R.cond([
	[R.is(RegExp), R.identity],
	[R_.isString, pattern => R_.constructRegExp(pattern, 'i')],
	[R_.isArray, pattern => R_.constructRegExp(`(${R.join('|', pattern)})`, 'i')],
	[
		R.T,
		() =>
			invariant(