great-tariff
Version:
A satirical NPM package that lets you apply fake tariffs to imported modules in your JavaScript project.
169 lines (126 loc) β’ 4.15 kB
Markdown
# πΊπΈ great-tariff
> "The best tariffs. Tremendous tariffs. Nobody does tariffs better than me."
> β Not Actually Donald Trump
**`great-tariff`** is a satirical NPM package that simulates tariffs on your JavaScript imports. Slow them down, block them, or just mock them β all with Trump-style commentary.
## π― Why?
Because your imports are too free. Too wild. It's time for law and order in your `node_modules`.
## π§° Features
- π§± Delay imports with fake tariff percentages
- π« Block certain packages (e.g. `china-module`, `mexico-wall`)
- π Console warnings that rant like a press conference
- π€ Dynamic Trump quotes tied to package names and tariffs
- πΊπΈ MakeImportsGreatAgain mode β because why not?
- π Works with both JavaScript and TypeScript
- π§ͺ Comprehensive test suite
- βοΈ Fully configurable tariff policies
## π¦ Installation
```bash
# Using npm
npm install great-tariff
# Using pnpm
pnpm add great-tariff
# Using yarn
yarn add great-tariff
```
## π Usage
### JavaScript (CommonJS)
```js
const { imposeTariff, setConfig } = require('great-tariff');
// Configure your tariffs
setConfig({
policies: {
'lodash': { tariffRate: 30, action: 'delay' },
'axios': { tariffRate: 20, action: 'log' },
'china-module': { action: 'block' },
}
});
const _ = await imposeTariff('lodash'); // Adds delay
const axios = await imposeTariff('axios'); // Logs a warning
```
### JavaScript (ESM)
```js
import { imposeTariff, setConfig } from 'great-tariff';
// Configure your tariffs
setConfig({
policies: {
'lodash': { tariffRate: 30, action: 'delay' },
'axios': { tariffRate: 20, action: 'log' },
'china-module': { action: 'block' },
}
});
const _ = await imposeTariff('lodash'); // Adds delay
const axios = await imposeTariff('axios'); // Logs a warning
```
### TypeScript
```ts
import { imposeTariff, setConfig, TariffConfig } from 'great-tariff';
// Configure your tariffs
setConfig({
policies: {
'lodash': { tariffRate: 30, action: 'delay' },
'axios': { tariffRate: 20, action: 'log' },
'china-module': { action: 'block' },
}
});
const _ = await imposeTariff('lodash'); // Adds delay
const axios = await imposeTariff('axios'); // Logs a warning
```
## π§ Tariff Actions
| Action | Effect |
| ------- | ------------------------------------------ |
| `delay` | Adds fake loading delay based on rate |
| `log` | Prints a huge warning with a Trump quote |
| `block` | Throws error and refuses to import package |
## π Configuration
The package is fully configurable through the `setConfig` function. You can set different policies for different packages:
```ts
interface TariffPolicy {
tariffRate?: number; // Percentage for delay calculation
action: 'block' | 'delay' | 'log'; // Action to take
}
interface TariffConfig {
policies: Record<string, TariffPolicy>; // Package name -> policy mapping
mode?: string; // Optional mode string
}
// Example configuration
setConfig({
policies: {
'lodash': { tariffRate: 30, action: 'delay' },
'axios': { tariffRate: 20, action: 'log' },
'china-module': { action: 'block' },
'react': { tariffRate: 45, action: 'delay' },
},
mode: 'MakeImportsGreatAgain'
});
```
## π Examples
Check out the `examples` directory for complete working examples in both ESM and CommonJS:
```bash
# Build the package first
npm run build
# Run ESM example
node examples/esm/index.mjs
# Run CommonJS example
node examples/commonjs/index.cjs
```
## π§ͺ Testing
The package includes a comprehensive test suite. Run tests with:
```bash
# Using npm
npm test
# Using pnpm
pnpm test
# Using yarn
yarn test
```
Tests cover:
- Quote generation for different actions
- Tariff imposition timing
- Error handling
- Console output
- Module resolution
- Configuration system
## π€‘ Disclaimer
This package is purely a parody β it doesn't reflect real-world politics or actual economic policy. Don't use it in production unless your app is built on memes.
## π License
MIT β Make Imports Trumpish Again