Sha256: 37ee564b564e2745908fc8117388a1ea23dadba4c6345cd4b309532c16486984

Contents?: true

Size: 734 Bytes

Versions: 10

Compression:

Stored size: 734 Bytes

Contents

import { basename, dirname, extname, sep } from 'path';
import { makeLegalIdentifier } from 'rollup-pluginutils';

export function getName(id) {
	const name = makeLegalIdentifier(basename(id, extname(id)));
	if (name !== 'index') {
		return name;
	} else {
		const segments = dirname(id).split(sep);
		return makeLegalIdentifier(segments[segments.length - 1]);
	}
}

// Return the first non-falsy result from an array of
// maybe-sync, maybe-promise-returning functions
export function first(candidates) {
	return function(...args) {
		return candidates.reduce((promise, candidate) => {
			return promise.then(result =>
				result != null ? result : Promise.resolve(candidate.call(this, ...args))
			);
		}, Promise.resolve());
	};
}

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
condenser-0.3 lib/condenser/processors/node_modules/rollup-plugin-commonjs/src/utils.js
condenser-0.2 lib/condenser/processors/node_modules/rollup-plugin-commonjs/src/utils.js
condenser-0.1 lib/condenser/processors/node_modules/rollup-plugin-commonjs/src/utils.js
condenser-0.0.12 lib/condenser/processors/node_modules/rollup-plugin-commonjs/src/utils.js
condenser-0.0.11 lib/condenser/processors/node_modules/rollup-plugin-commonjs/src/utils.js
condenser-0.0.10 lib/condenser/processors/node_modules/rollup-plugin-commonjs/src/utils.js
condenser-0.0.9 lib/condenser/processors/node_modules/rollup-plugin-commonjs/src/utils.js
condenser-0.0.8 lib/condenser/processors/node_modules/rollup-plugin-commonjs/src/utils.js
condenser-0.0.7 lib/condenser/processors/node_modules/rollup-plugin-commonjs/src/utils.js
condenser-0.0.5 lib/condenser/processors/node_modules/rollup-plugin-commonjs/src/utils.js