Skip to content
Please note that GitHub no longer supports Internet Explorer.

We recommend upgrading to the latest Microsoft Edge, Google Chrome, or Firefox.

Learn more
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Modes #13

Open
lukeed opened this issue Jan 16, 2020 · 0 comments
Open

Multiple Modes #13

lukeed opened this issue Jan 16, 2020 · 0 comments

Comments

@lukeed
Copy link
Owner

@lukeed lukeed commented Jan 16, 2020

As with others of my modules, I think a "choose your path" option for this module would be great.

"default"

By default – aka, the regular import – a middle of the road approach should be offered that covers the majority of cases. As of today, this would be the current klona module, supporting Objects, Arrays, Dates, RegExps, Maps, Sets, all TypedArray variants (includes Buffer), and primitives, of course.

Using this mode will continue to look like this:

import klona from 'klona';

"full"

There will definitely be a "full" mode (name TBD) that does everything "default" does, but with these added features. I originally was going to publish klona with these features to start, but removed them since they don't fit the 90% use case IMO.

Of course, this mode will be a bit larger (~400 bytes) and significantly slower than the current klonahowever it'll still be faster than most contenders of the current benchmark & none of them offer these extra features.

Again, this is opt-in behavior & I'm a fan of being explicit about what you need and where you need it. Using this mode will look like this:

import klona from 'klona/full'; // name TBD

"lite"

There will also be "lite" or "json" mode (name TBD) for handling simpler cases. I actually think the 90% use case doesn't bother with cloning RegExps, TypedArrays, or even Maps & Sets, but "default" included them to be safe.

The lite/json mode, as the name suggests, will handle far fewer cases than the "default" and "full" counterparts. Because of this, this mode will be ~200 bytes and the fastest of the three.

I'm still debating if this mode should handle RegExp and Date. If so, then the name would have to be "lite" – otherwise only valid JSON datatypes will remain, thus making "json" a clear & obvious choice for dealing with JSON data objects.

As with "full", using this mode is an opt-in behavior and should be obvious when you've made that choice. Using this mode will look like:

import klona from 'klona/lite';
// ~ OR ~
import klona from 'klona/json';

Please leave any comments or concerns or naming suggestions that you may have.
This is planned for a minor/feature release since nothing changes to the default mode.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.