Skip to main content
Home

Built and signed on GitHub Actions

A module to dissect the string; Safe with the emojis, URLs, and words.

This package works with Node.js, Deno, BunIt is unknown whether this package works with Cloudflare Workers, Browsers
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
It is unknown whether this package works with Browsers
JSR Score
94%
Published
4 months ago (4.0.2)

String Dissect (ES)

โš–๏ธ MIT

GitHub: hugoalh/string-dissect-es JSR: @hugoalh/string-dissect NPM: @hugoalh/string-dissect

An ECMAScript (JavaScript & TypeScript) module to dissect the string; Safe with the emojis, URLs, and words.

๐Ÿ”ฐ Begin

๐ŸŽฏ Targets

Targets Remote JSR NPM
Bun >= v1.1.0 โŒ โœ”๏ธ โœ”๏ธ
Deno >= v2.1.0 โœ”๏ธ โœ”๏ธ โœ”๏ธ
NodeJS >= v20.9.0 โŒ โœ”๏ธ โœ”๏ธ
Note

  • It is possible to use this module in other methods/ways which not listed in here, however those methods/ways are not officially supported, and should beware maybe cause security issues.

#๏ธโƒฃ Resources Identifier

  • Remote - GitHub Raw:
    https://raw.githubusercontent.com/hugoalh/string-dissect-es/{Tag}/mod.ts
    
  • JSR:
    [jsr:]@hugoalh/string-dissect[@{Tag}]
    
  • NPM:
    [npm:]@hugoalh/string-dissect[@{Tag}]
    
Note

  • For usage of remote resources, it is recommended to import the entire module with the main path mod.ts, however it is also able to import part of the module with sub path if available, but do not import if:

    • it's path has an underscore prefix (e.g.: _foo.ts, _util/bar.ts), or
    • it is a benchmark or test file (e.g.: foo.bench.ts, foo.test.ts), or
    • it's symbol has an underscore prefix (e.g.: _bar, _foo).

    These elements are not considered part of the public API, thus no stability is guaranteed for them.

  • For usage of JSR or NPM resources, it is recommended to import the entire module with the main entrypoint, however it is also able to import part of the module with sub entrypoint if available, please visit the file jsr.jsonc property exports for available sub entrypoints.

  • It is recommended to use this module with tag for immutability.

๐Ÿ›ก๏ธ Runtime Permissions

This module does not request any runtime permission.

๐Ÿงฉ APIs

  • class StringDissector {
      constructor(options?: StringDissectorOptions);
      dissect(item: string): Generator<StringSegmentDescriptor>;
    }
    
  • interface StringDissectorOptions {
      locales?: Intl.LocalesArgument;
      outputANSI?: boolean;
      safeURLs?: boolean;
      safeWords?: boolean;
    }
    
  • interface StringSegmentDescriptor {
      indexEnd: number;
      indexStart: number;
      type: StringSegmentType;
      value: string;
    }
    
  • type StringSegmentType =
      | "ansi"
      | "character"
      | "emoji"
      | "url"
      | "word";
    
Note

โœ๏ธ Examples

  • const sample1 = "Vel ex sit est sit est tempor enim et voluptua consetetur gubergren gubergren ut.";
    
    Array.from(new StringDissector().dissect(sample1));
    /*=>
    [
      { value: "Vel", type: "word" },
      { value: " ", type: "character" },
      { value: "ex", type: "word" },
      { value: " ", type: "character" },
      { value: "sit", type: "word" },
      { value: " ", type: "character" },
      { value: "est", type: "word" },
      { value: " ", type: "character" },
      ... +20
    ]
    */
    
    Array.from(new StringDissector({ safeWords: false }).dissect(sample1));
    /*=>
    [
      { value: "V", type: "character" },
      { value: "e", type: "character" },
      { value: "l", type: "character" },
      { value: " ", type: "character" },
      { value: "e", type: "character" },
      { value: "x", type: "character" },
      { value: " ", type: "character" },
      { value: "s", type: "character" },
      ... +73
    ]
    */
    
  • Array.from(new StringDissector().dissect("GitHub homepage is https://github.com."));
    /*=>
    [
      { value: "GitHub", type: "word" },
      { value: " ", type: "character" },
      { value: "homepage", type: "word" },
      { value: " ", type: "character" },
      { value: "is", type: "word" },
      { value: " ", type: "character" },
      { value: "https://github.com", type: "url" },
      { value: ".", type: "character" }
    ]
    */
    
  • Array.from(new StringDissector().dissect("๐Ÿค๐Ÿ’‘๐Ÿ’๐Ÿ‘ช๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ๐Ÿ‘ฉโ€๐Ÿ‘ฆ๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ๐Ÿง‘โ€๐Ÿคโ€๐Ÿง‘"), ({ value }) => {
      return value;
    });
    //=> [ "๐Ÿค", "๐Ÿ’‘", "๐Ÿ’", "๐Ÿ‘ช", "๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ", "๐Ÿ‘ฉโ€๐Ÿ‘ฆ", "๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ", "๐Ÿง‘โ€๐Ÿคโ€๐Ÿง‘" ]
    
Built and signed on
GitHub Actions

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@hugoalh/string-dissect

Import symbol

import * as string_dissect from "@hugoalh/string-dissect";
or

Import directly with a jsr specifier

import * as string_dissect from "jsr:@hugoalh/string-dissect";

Add Package

pnpm i jsr:@hugoalh/string-dissect
or (using pnpm 10.8 or older)
pnpm dlx jsr add @hugoalh/string-dissect

Import symbol

import * as string_dissect from "@hugoalh/string-dissect";

Add Package

yarn add jsr:@hugoalh/string-dissect
or (using Yarn 4.8 or older)
yarn dlx jsr add @hugoalh/string-dissect

Import symbol

import * as string_dissect from "@hugoalh/string-dissect";

Add Package

vlt install jsr:@hugoalh/string-dissect

Import symbol

import * as string_dissect from "@hugoalh/string-dissect";

Add Package

npx jsr add @hugoalh/string-dissect

Import symbol

import * as string_dissect from "@hugoalh/string-dissect";

Add Package

bunx jsr add @hugoalh/string-dissect

Import symbol

import * as string_dissect from "@hugoalh/string-dissect";