![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
conditional-export
Advanced tools
Find entry or path in package.json exports or imports.
https://nodejs.org/docs/latest-v12.x/api/packages.html#packages_exports
Apis usage description.
Debugging platform: https://imtaotao.github.io/conditional-export/
import { findEntryInExports } from 'conditional-export';
const exports = {
'.': {
require: './index.cjs',
development: './index.development.js',
default: './index.js',
},
}
findEntryInExports(exports); // ./index.cjs
findEntryInExports(exports, ['development']); // ./index.development.js
findEntryInExports(exports, ['production']); // ./index.js
import { findPathInExports } from 'conditional-export';
const exports = {
'./lib/*': {
require: './src/*.cjs',
development: './src/*.development.js',
default: './src/*.js',
},
}
findPathInExports('./lib/index', exports); // ./src/index.cjs
findPathInExports('./lib/index', exports, ['development']); // ./src/index.development.js
findPathInExports('./lib/index', exports, ['production']); // ./src/index.js
Multiple conditions, default conditions is ['require']
.
You can specify multiple conditions.
import { findPathInExports } from 'conditional-export';
const exports = {
'./a': {
node: {
import: './feature-node.mjs',
require: './feature-node.cjs',
},
default: './feature.default.mjs',
}
};
findPathInExports('./a', exports); // './feature.default.mjs'
findPathInExports('./a', exports, ['node', 'require']); // './feature-node.cjs'
import { findPathInImports } from 'conditional-export';
const imports = {
'#timezones/': './data/timezones/',
'#timezones/utc': './data/timezones/utc/index.mjs',
'#external-feature': 'external-pkg/feature',
'#moment/': './'
}
findPathInImports('#timezones/utc', imports); // ./data/timezones/utc/index.mjs
findPathInImports('#external-feature', imports); // external-pkg/feature
findPathInImports('#timezones/utc/index.mjs', imports); // ./data/timezones/utc/index.mjs
findPathInImports('#moment/data/timezones/utc/index.mjs', imports); // ./data/timezones/utc/index.mjs
findPathInImports('#timezones/utc/', imports); // ./data/timezones/utc/
findPathInImports('#unknown', imports); // null
findPathInImports('#moment', imports); // null
import { findPkgData } from 'conditional-export';
const exports = {
'./': './src/util/',
'./timezones/': './data/timezones/',
'./timezones/utc': './data/timezones/utc/index.mjs',
}
const data = findPkgData('@vue/core/timezones/pdt.mjs', exports);
// {
// name: '@vue/core',
// version: '',
// path: './data/timezones/pdt.mjs',
// resolve: '@vue/core/data/timezones/pdt.mjs',
// raw: '@vue/core/timezones/pdt.mjs',
// }
import { parseModuleId } from 'conditional-export';
parseModuleId('vue')
// {
// name: 'vue',
// path: '',
// version: '',
// raw: 'vue',
// }
parseModuleId('vue/');
// {
// name: 'vue',
// path: './',
// version: '',
// raw: 'vue/',
// }
parseModuleId('@vue/core@v1.0.0/a.js');
// {
// name: '@vue/core',
// path: './a.js',
// version: 'v1.0.0',
// raw: '@vue/core@v1.0.0/a.js',
// }
When you want to convert to absolute path, you can handle it like this.
import { findPkgData } from 'conditional-export';
const data = findPkgData('vue/src/index.js', exports, ['require', ...]);
if (data.path !== null) {
const resolvePath = isNodeEnv
? path.resolve(pkgDir, data.path) // NodeJs
: new URL(data.path, pkgDir).href; // Browser
} else {
// If the module doesn't exist, you should throw an error.
throw new Error(`Module '${data.raw}' Not Found`);
}
<!DOCTYPE html>
<html lang='en'>
<body>
<script src='https://unpkg.com/conditional-export/dist/entry.umd.js'></script>
<script>
const {
findPkgData,
findPathInImports,
findPathInExports,
findEntryInExports,
parseModuleId,
} = NodePackageExports;
// ...
</script>
</body>
</html>
FAQs
find node package entry or path in exports
We found that conditional-export demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.