Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

auto-group-strings-array

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

auto-group-strings-array

Small JS library to group array of strings by common substring

  • 1.1.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

auto-group-strings-array

Small JS library to group array of strings by common substring

Node.js

npm install auto-group-strings-array

Browser

Use auto-group-strings.min.js file from dist/

Function Arguments:

  1. inputStrings (type: Array<string>)

  2. options, type: Object (optional), properties:

    • delimiter (type: string, default: " ")
    • delimiterRegExp (type: RegExp, default: undefined)
      • if delimiterRegExp is provided, delimiter (string) will only be used as a fallback when there is no match for delimiterRegExp
    • direction (type: string, default: "rtl")
      • Its possible values are "ltr" for searching left to right or, "rtl" for right to left.
    • caseSensitive (type: boolean, default: false)
    • includeSingleElementMembers (type: boolean, default: false)
      • this option includes every input string from the first argument as common and at least one element (index) in members array.

Return Type:

  • Array<Object> where
    • common property is a string
    • members property is an Array<number>

Usage

const autoGroupStrings = require("auto-group-strings");

const result = autoGroupStrings(
  [
    "hello code", // 0
    "apple and orange", // 1
    "for the happy code", // 2
    "i don't know", // 3
    "is it?", // 4
    "it's a happy code", // 5
  ],
  {
    delimiter: " ",
    direction: "rtl",
  },
);

console.log(result);
/*
[
  { common: 'code', members: [ 0, 2, 5 ] },
  { common: 'happy code', members: [ 2, 5 ] }
]
*/
  • For more examples, please check examples directory.

Keywords

FAQs

Package last updated on 28 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc