maggi64 / moderndash Goto Github PK
View Code? Open in Web Editor NEWA Typescript-First utility library inspired by Lodash. Optimized for modern browsers.
Home Page: https://moderndash.io
License: MIT License
A Typescript-First utility library inspired by Lodash. Optimized for modern browsers.
Home Page: https://moderndash.io
License: MIT License
With tools like hotscript or advanced TS magic we might be able to improve the return type and validate the given path on compile time.
It should be:
const obj = { a: 1 };
const newObj = set(obj, 'a.c', 1);
// ^? { a: { c: number } }
Instead of the current state:
const obj = { a: 1 };
const newObj = set(obj, 'a.c', 1);
// ^? PlainObject
Hello!
I'm probably missing something, but I'm getting an error during my TS build because dist/index.d.ts
from moderndash
imports from hotscript
, but it's not installed as a dependency — it's listed in devDependencies
instead, so it's not in my project at all as a result, although I've run npm install moderndash
previously.
The line at the very top of dist/index.d.ts
import { Call, Tuples, Objects } from 'hotscript';
Should hotscript
be moved to the main dependencies instead?
Lodash features a noop (no operation) function: https://lodash.com/docs/4.17.15#noop
export function noop() {
// Do nothing
}
There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.
Location: renovate.json
Error type: Invalid JSON (parsing failed)
Message: Syntax error near ,{
watch: Observes changes to an object or array and triggers a callback when a change occurs.
Tried to replace lodash
with moderndash
in a small project using Angular Schematics tooling (node) though im having this error, probably due to some module config
Unexpected token '??='
at wrapSafe internal/modules/cjs/loader.js:1001
at Module._compile internal/modules/cjs/loader.js:1049
at Object.Module._extensions..js internal/modules/cjs/loader.js:1114
at Module.load internal/modules/cjs/loader.js:950
at Function.Module._load internal/modules/cjs/loader.js:790
at require internal/modules/cjs/helpers.js:101
at Object.<anonymous> src/core/template.utils.ts:2
at Module._compile internal/modules/cjs/loader.js:1085
typescript: 4.9.4
// tsconfig
{
"compilerOptions": {
"baseUrl": "tsconfig",
"lib": ["es2018", "dom"],
"declaration": true,
"module": "commonjs",
"target": "es6",
"moduleResolution": "node",
"noEmitOnError": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitThis": true,
"noUnusedParameters": true,
"noUnusedLocals": true,
"rootDir": "src/",
"skipDefaultLibCheck": true,
"skipLibCheck": true,
"sourceMap": true,
"strictNullChecks": true,
"types": ["jasmine", "node"]
},
"include": ["src/**/*"],
"exclude": ["src/*/files/**/*"]
}
Probably due to commonjs
? Tried to change module: es2020
target: ES2022
but still no luck
Currently it is 3x slower than lodash when dealing with primitives.
Object.freeze() is not recursive
Possible implementations:
Related Lodash issue: lodash/lodash#4295
Hi, lodash has this property with its throttle
function that I think is more useful to be the default.
The func is invoked with the last arguments provided to the throttled function. Subsequent calls to the throttled function return the result of the last func invocation.
What do you say?
Great library! Would you consider a feature that has no runtime advantage, but improves typings?
Similar to https://github.com/sindresorhus/ts-extras/blob/main/source/object-keys.ts
export type ObjectKeys<T extends object> = `${Exclude<keyof T, symbol>}`;
export const objectKeys = Object.keys as <Type extends object>(value: Type) => Array<ObjectKeys<Type>>;
Hello
I would like to know, if you planning to create a mergeWith
function allowing to customize the merge function. The perfect use exemple is to merge nested array :
mergeWith(
{ a: [1, 2] },
{ a: [3, 4] },
(a, b) => Array.isArray(a) && Array.isArray(b) => [...a, ...b] : undefined
)
// => { a: [1, 2, 3, 4] }
lodash doc: https://lodash.com/docs/4.17.15#mergeWith
In Typescript, in may be preferred to set properties that are already defined in interface rather then adding new properties
So it a variant of set
that can't create properties not defined in the interface in may come useful
The sefSafe
function may either return the input type, or return the input type with removed oprionals ?
on created path.
See https://stackoverflow.com/questions/76255065/typescript-type-safe-version-of-lodashs-set/76280420#1
example usage:
type Pos = { x: number, y: number };
const pos0 = {} as DeepPartial<Pos>;
const pos1 = setSafe(pos0, 'x', 1); // { x: number, y?: number }
const pos2 = setSafe(pos1, 'y', 2); // { x: number, y: number }
const pos3: Pos = pos2;
Lodash features truncate
function: https://lodash.com/docs/4.17.15#truncate
Stack Overflow link to truncate function: https://stackoverflow.com/questions/1199352/smart-way-to-truncate-long-strings
Blocked by evanw/esbuild#104.
Esbuild seems not to support the T39 Standard Decorators yet. Until this is added we stay with the experimentalDecorators
implementation.
The T39 Decorators allow the use in TS5 without the experimentalDecorators
flag set.
Can't find TextEncoder
in Jest tests after 2.2.2 release:
Test suite failed to run
ReferenceError: TextEncoder is not defined
> 1 | import { merge } from 'moderndash';
What is strange it want to get it from src
folder:
at Object.<anonymous> (../../node_modules/moderndash/src/crypto/hash.ts:5:21)
I can see only src
comment in the dist source code:
// src/crypto/hash.ts
var textEncoder = new TextEncoder();
Tsup's --dts-resolve
feature, which bundles dependency types, is experimental and doesn't reliably work with hotscript. We need to wait for improvements in tsup/esbuild to fully support this.
Until then hotscript
needs to be a dependency.
Related: #117
Safari iOS below 16.3 doesn't support certain group specifiers in the below RegEx, probably lookbehind: https://caniuse.com/?search=lookbehind.
const splitWordsRegex = new RegExp(
'[^\\dA-Za-z]' + // match any character that is not a letter or a digit
'|' + // or
'(?<=[a-z])' + // lookbehind for a lowercase letter
'(?=[A-Z])' + // lookahead for an uppercase letter
'|' + // or
'(?<=[A-Z])' + // lookbehind for an uppercase letter
'(?=[A-Z][a-z])' // lookahead for an uppercase letter followed by a lowercase letter
);
I haven't fully tested it, but what about replacing this splitWords
function with something like:
const splitWordsRegex = /([\dA-Z][\da-z]+)|([\dA-Z]+)|([\da-z]+)/g;
export function splitWords(str: string): string[] {
return [...str.matchAll(splitWordsRegex)].map(match => match[0]);
}
Other issues I've encountered with switching from Lodash to moderndash on a medium-size project:
{...{}, ...b}
) could be used in most cases. I've personally used Lodash's merge
in areas of my code specifically because it modifies the input, cutting down on garbage collection.Waiting for upstream fix: gvergnaud/hotscript#83
isEqual
which is used in the example is not auto imported
Every function except `set' creates and returns a new array. I've done this to be consistent, but it doesn't always make sense.
To improve performance, we could switch to in-place mutations where it makes sense. These would be break changes.
Possible candidates:
I am not sure yet. I would love to get some input on this.
version 3.5.0
It is not possible to wait for the queue to complete all tasks unless I use the await method when queueing the task. It would be a significant improvement to wait until all the promises I've queued before finish.
Lodash documentation: https://lodash.com/docs/4.17.15#curry
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
@tsconfig/strictest
, typescript
, vite
)@sveltejs/kit
, marked
, svelte-check
, svelte-meta-tags
, tailwindcss
).github/workflows/image-compression.yml
actions/checkout v4
peter-evans/create-pull-request v6
.github/workflows/image-svg-minifier.yml
actions/checkout v4
ericcornelissen/svgo-action v3
.github/workflows/linter.yml
actions/checkout v4
actions/setup-node v4
stefanzweifel/git-auto-commit-action v5
.github/workflows/no-old-imagetypes.yml
batista/lint-filenames v2
.github/workflows/npm-release.yml
actions/checkout v4
actions/setup-node v4
changesets/action v1
.github/workflows/test.yml
actions/checkout v4
actions/setup-node v4
benchmark/package.json
package.json
@svitejs/changesets-changelog-github-compact 1.1.0
@tsconfig/strictest 2.0.3
@changesets/cli 2.27.1
eslint-config-dewald 1.0.17
eslint 8.57.0
typedoc 0.25.12
typescript 5.4.2
vitest 1.4.0
@vitest/coverage-v8 1.4.0
@vitest/ui 1.4.0
vite 5.1.6
package/package.json
hotscript 1.0.13
tsup 8.0.2
cross-env 7.0.3
website/package.json
typedoc-json-parser 9.0.1
@fortawesome/fontawesome-common-types 6.5.1
@fortawesome/free-brands-svg-icons 6.5.1
@fortawesome/free-regular-svg-icons 6.5.1
@fortawesome/free-solid-svg-icons 6.5.1
svelte-fa 4.0.2
svelte-sitemap 2.6.0
@sveltejs/adapter-static 3.0.1
@sveltejs/kit 2.5.2
@tailwindcss/nesting 0.0.0-insiders.565cd3e
svelte 4.2.12
@sveltejs/vite-plugin-svelte 3.0.2
svelte-check 3.6.6
tailwindcss 3.4.1
marked 12.0.0
svelte-meta-tags 3.1.0
@stackblitz/sdk 1.9.0
Similar to npm:flat
In the example the debounce func runs twice while it should only once.
Lodash is currently faster according to my updated benchmarks
Time to improve it 🚀
JS now natively features Object.groupBy()
Not yet supported by all browsers: https://caniuse.com/mdn-javascript_builtins_object_groupby
There is a polyfill available in core-js: https://github.com/zloirock/core-js#array-grouping
It's not stated in the docs whether you follow data-first or data-last paradigm, but I noticed that you incline towards the latter, e.g. intersection and difference. At the same time unique follows the data-first approach.
Do you have an opinion on what is better and why?
As far as I can judge from the TS perspective it's usually easier to put the callback last because all the typings would be in-place. Otherwise, when you provide the first parameter the types of the arrays are not yet defined which causes inconvenience.
Anyway, following a single paradigm seems a good way to go. What are your thoughts about it?
Add pending
function to debounce
Here the issue on Lodash (2017/09): lodash/lodash#3387
The PR that implements it (2017/09, jdalton himself): lodash/lodash#3388
It is present in Lodash master (2017/09, 6 years ago):
And yet never published as a Lodash npm package:
It should be part of Lodash v5 (which will probably never come)
Other interesting issues related to debounce.pending():
The Type PlainObject
, which is used as type constrain for functions like merge
does not accept interfaces.
type R = Record<PropertyKey, unknown>; // same as PlainObject, but its not exported. So lets rebuild it here
type Foo = {
a: number;
b: number;
};
interface Boo {
a: number;
b: number;
}
function f<x extends R>(x: x): void {
/* NOP */
}
f<Foo>({ a: 1, b: 1 }); // This is OK
f<Boo>({ a: 1, b: 1 }); // This fails and requires a symbol and a string key
/*
Type 'Boo' does not satisfy the constraint 'R'.
Index signature for type 'string' is missing in type 'Boo'.ts(2344)
*/
It would be great if your intersect
method supported a scenario like this:
const arr1 = [{ id: 1, name: 'Yeet' }, { id: 3, name: 'John' }];
const arr2 = [3, 4];
intersection((a, b) => a.id === b, arr1, arr2);
Figure out if i want to keep boolean support and adjust example
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.