Comments (7)
https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
from camelcase-keys.
I ended up simply using:
_.mapKeys(obj, (v, k) => _.camelCase(k))
Since importing the package was not easily possible with Nest.js unfortunately
from camelcase-keys.
Hello all. I've created a util to convert ESM-only packages to CJS, for those who need it. This is still very much a work in progress, so please open an issue on the repository with any feedback.
This package ([email protected]
) can be installed as CJS via @cjs-exporter/camelcase-keys
.
from camelcase-keys.
@sindresorhus How would this work with Nest.js
from camelcase-keys.
I ended up simply using:
_.mapKeys(obj, (v, k) => _.camelCase(k))Since importing the package was not easily possible with Nest.js unfortunately
What is "_" and obj here?
from camelcase-keys.
I ended up simply using:
_.mapKeys(obj, (v, k) => _.camelCase(k))Since importing the package was not easily possible with Nest.js unfortunately
What is "_" and obj here?
from camelcase-keys.
Because I wanted to use the latest version of this library I used an approach where I used ESBuild to convert this ESM only lib to CJS format. This should work for most of such cases and ideally you wont have to do this often as there aren't many libraries that have removed CJS support. In addition to that doing this for these type small util libraries, you likely don't really need to update ever them unless there is some serious security issue in which case you can use repeat the process again.
So I ran ESBuild, took the built result and the index.d.ts
file, put it into a "vendor" directory and import from there. Problem solved if you don't want to migrate off of CJS if your project already works that way. It took 5 to 10 mins max and got back on track.
npm install esbuild
- git clone repo of the ESM lib you want to use that does not offer CJS support in this case to
./camelcase-keys
- open
package.json
of that repo - remove the line
"type": "module"
- Remove
"exports": { "types": "./index.d.ts", "default": "./index.js" }
- Add
"types": "./index.d.ts"
and"main": "./index.js"
npx esbuild ./camelcase-keys --bundle --platform="node" --outfile=./static-vendor/camelcase-keys/index.js
- import and use in your code like normal
import camelcaseKeys from "../static-vendor/camelcase-keys/index.js";
- Copy
index.d.ts
file from cloned repo to./static-vendor/camelcase-keys/
If you want you can probably alias it or something and make the import cleaner but this is fine for my needs, typing also works perfectly.
Cheers.
from camelcase-keys.
Related Issues (20)
- Trying to use this lib with Nest.js, and getting import error HOT 1
- Unexpected token name «_000», expected punc «,» in file node_modules/camelcase-keys/index.js at 25:16 HOT 1
- Error: Failed to load function definition from source HOT 1
- iOS archive failed - phasescriptexecution failed with a nonzero exit code HOT 1
- This module's config insufficiently robust for use in Typescript HOT 3
- Failed import camelcase-keys HOT 2
- [TypeScript] If the `deep: true` option is set, even the object's properties will be converted.
- type mismatch with reality HOT 1
- Type 'Interface' does not satisfy the constraint 'readonly any[] | ObjectOptional'. HOT 6
- Using function with inferred type does not resolve correct return type defaults HOT 1
- Version 9 does not recursively camelCase keys in nested objects when using union with null HOT 2
- [Safari] Error on page load 12.1 HOT 1
- Documentation doesn't match the types? HOT 1
- Handle underscore as the first character HOT 1
- [TS] Result and result type are different HOT 1
- Why don't you provide cjs build? HOT 1
- An issue of Cannot use import statement outside a module HOT 1
- FYI linter errors importing module HOT 1
- fix: typing errors with typescript 4.8 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from camelcase-keys.