gchq / CyberChef

The Cyber Swiss Army Knife - a web app for encryption, encoding, compression and data analysis
https://gchq.github.io/CyberChef
Apache License 2.0
29.43k stars 3.29k forks source link

Replace lodash #1563

Open depperm opened 1 year ago

depperm commented 1 year ago

Is your feature request related to a problem? Please describe. Lodash is a relatively large utility package but is only used for kebab-case, snake_case, and camelCase

Describe the solution you'd like Use vanilla js. Below algorithms require fine tuning/testing

to kebab case

const kebabCase = string => string
        .replace(/([a-z])([A-Z])/g, "$1-$2")
        .replace(/[\s_]+/g, '-')
        .toLowerCase();

to snake case

const snakeCase = string =>string
      .replace(/\W+/g, " ")
      .split(/ |\B(?=[A-Z])/)
      .map(word => word.toLowerCase())
      .join('_');

to camel case

const camelCase = string => string
    .replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) {
        return index === 0 ? word.toLowerCase() : word.toUpperCase();
    })
    .replace(/\s+/g, '');

Describe alternatives you've considered there are other solutions that don't require lodash

ParkerM commented 1 year ago

Strongly recommend eslint-plugin-you-dont-need-lodash-underscore for some automated detection and quickfixes/suggestions.