### Format Code Source: https://github.com/caret-collective/tally-ts/blob/main/docs/CONTRIBUTING.md Format all files in the project according to the established style guide. ```bash deno fmt ``` -------------------------------- ### Install Tally-TS with npm Source: https://github.com/caret-collective/tally-ts/blob/main/README.md Use this command to add the Tally-TS package from npm. ```bash npm install @twocaretcat/tally-ts ``` -------------------------------- ### Install Tally-TS with Deno (npm) Source: https://github.com/caret-collective/tally-ts/blob/main/README.md Use this command to add the Tally-TS package from npm using Deno. ```bash deno add npm:@twocaretcat/tally-ts ``` -------------------------------- ### Install Tally-TS with vlt (npm) Source: https://github.com/caret-collective/tally-ts/blob/main/README.md Use this command to add the Tally-TS package from npm using vlt. ```bash vlt install @twocaretcat/tally-ts ``` -------------------------------- ### Conventional Commits Example Source: https://github.com/caret-collective/tally-ts/blob/main/docs/CONTRIBUTING.md Example of a commit message following Conventional Commits, including a breaking change. ```txt feat: allow provided config object to extend other configs BREAKING CHANGE: `extends` key in config file is now used for extending other config files ``` -------------------------------- ### Install Tally-TS with Bun (npm) Source: https://github.com/caret-collective/tally-ts/blob/main/README.md Use this command to add the Tally-TS package from npm using Bun. ```bash bun add @twocaretcat/tally-ts ``` -------------------------------- ### Install Tally-TS with Deno (JSR) Source: https://github.com/caret-collective/tally-ts/blob/main/README.md Use this command to add the Tally-TS package from JSR using Deno. ```bash deno add jsr:@twocaretcat/tally-ts ``` -------------------------------- ### Install Tally-TS with Bun (JSR) Source: https://github.com/caret-collective/tally-ts/blob/main/README.md Use this command to add the Tally-TS package from JSR using Bun. ```bash bunx jsr add @twocaretcat/tally-ts ``` -------------------------------- ### Install Tally-TS with yarn (npm) Source: https://github.com/caret-collective/tally-ts/blob/main/README.md Use this command to add the Tally-TS package from npm using yarn. ```bash yarn add @twocaretcat/tally-ts ``` -------------------------------- ### Install Tally-TS with vlt (JSR) Source: https://github.com/caret-collective/tally-ts/blob/main/README.md Use this command to add the Tally-TS package from JSR using vlt. ```bash vlt install jsr:@twocaretcat/tally-ts ``` -------------------------------- ### Install Tally-TS with pnpm (npm) Source: https://github.com/caret-collective/tally-ts/blob/main/README.md Use this command to add the Tally-TS package from npm using pnpm. ```bash pnpm add @twocaretcat/tally-ts ``` -------------------------------- ### Install Tally-TS with npm (JSR) Source: https://github.com/caret-collective/tally-ts/blob/main/README.md Use this command to add the Tally-TS package from JSR using npm. ```bash npx jsr add @twocaretcat/tally-ts ``` -------------------------------- ### Install Tally-TS with yarn (JSR) Source: https://github.com/caret-collective/tally-ts/blob/main/README.md Use this command to add the Tally-TS package from JSR using yarn. ```bash yarn add jsr:@twocaretcat/tally-ts ``` -------------------------------- ### Install Tally-TS with pnpm (JSR) Source: https://github.com/caret-collective/tally-ts/blob/main/README.md Use this command to add the Tally-TS package from JSR using pnpm. ```bash pnpm i jsr:@twocaretcat/tally-ts ``` -------------------------------- ### Count Words in a String Source: https://github.com/caret-collective/tally-ts/blob/main/README.md Use the countWords method to get the total number of words in a given string. ```typescript tally.countWords('How are you?'); // → { total: 3 } ``` -------------------------------- ### Count Sentences in a String Source: https://github.com/caret-collective/tally-ts/blob/main/README.md Use the countSentences method to get the total number of sentences in a given string. ```typescript tally.countSentences('¿Como estas?'); // → { total: 1 } ``` -------------------------------- ### Count All Text Elements at Once Source: https://github.com/caret-collective/tally-ts/blob/main/README.md Use the countAll method to get counts for graphemes, words, sentences, paragraphs, and lines in a single operation. ```typescript const all = tally.countAll(`Hello world!\n\nThis is a test.`); console.debug(all); /* → { graphemes: { total: 27, by: { spaces: { total: 4 }, letters: { total: 20 }, digits: { total: 0 }, punctuation: { total: 1 }, symbols: { total: 0 }, }, related: { paragraphs: { total: 2 }, lines: { total: 3 }, } }, words: { total: 5 }, sentences: { total: 2 }, paragraphs: { total: 2 }, lines: { total: 3 } } */ ``` -------------------------------- ### Get All Counts with Legacy getCounts Source: https://github.com/caret-collective/tally-ts/blob/main/README.md Use the legacy getCounts function to obtain character, word, sentence, and other counts from text. Requires import from 'tally-ts/legacy'. ```typescript import { getCounts } from 'tally-ts/legacy'; const counts = await getCounts(`Hello world!\n\nThis is a test.`); console.debug(counts); /* → { characters: 27, words: 5, sentences: 2, paragraphs: 2, lines: 3, spaces: 4, letters: 20, digits: 0, symbols: 1 } */ ``` -------------------------------- ### Count Graphemes with Breakdown Source: https://github.com/caret-collective/tally-ts/blob/main/README.md Use countGraphemes to get the total graphemes and a breakdown by type, along with related counts like paragraphs and lines. ```typescript tally.countGraphemes('Hello world!'); // → { // total: 12, // by: { // spaces: { total: 1 }, // letters: { total: 10 }, // digits: { total: 0 }, // punctuation: { total: 1 }, // symbols: { total: 0 }, // }, // related: { // paragraphs: { total: 1 }, // lines: { total: 1 }, // } // } ``` -------------------------------- ### Get Resolved Locale with Tally Source: https://github.com/caret-collective/tally-ts/blob/main/README.md Retrieve the locale that Intl.Segmenter actually used. This is useful when no locale is explicitly provided. ```typescript const tally = new Tally(); console.debug(tally.getResolvedLocale()); // → "en-US" ``` -------------------------------- ### Get Counts with Legacy getCounts and Locale Source: https://github.com/caret-collective/tally-ts/blob/main/README.md Call the legacy getCounts function with an optional locale to improve segmentation accuracy for non-English text. Note: Affects character segmentation only. ```typescript const counts = await getCounts(`Hello world!\n\nThis is a test.`, 'de-DE'); ``` -------------------------------- ### Build npm Package Source: https://github.com/caret-collective/tally-ts/blob/main/docs/CONTRIBUTING.md Use this script to generate a Node.js-compatible package for npm. You can specify a version or use the one from deno.json. ```bash deno task build:npm # Build with version from deno.json deno task build:npm 0.2.0 # Build with specific version ``` -------------------------------- ### Run Full Test Suite Source: https://github.com/caret-collective/tally-ts/blob/main/docs/CONTRIBUTING.md Execute all tests, including type checks, linting, formatting, and unit tests. ```bash deno task test ``` -------------------------------- ### Clone and Navigate Repository Source: https://github.com/caret-collective/tally-ts/blob/main/docs/CONTRIBUTING.md Clone the tally-ts repository and navigate into the project directory. ```bash git clone https://github.com/YOUR_USERNAME/tally-ts.git cd tally-ts ``` -------------------------------- ### Commit Changes Source: https://github.com/caret-collective/tally-ts/blob/main/docs/CONTRIBUTING.md Stage all changes and commit them with a descriptive message. ```bash git add . git commit -m "feat: add your feature description" ``` -------------------------------- ### Create New Branch Source: https://github.com/caret-collective/tally-ts/blob/main/docs/CONTRIBUTING.md Create a new branch for your feature or bug fix. ```bash git checkout -b feat/your-feature-name ``` -------------------------------- ### Push and Create Pull Request Source: https://github.com/caret-collective/tally-ts/blob/main/docs/CONTRIBUTING.md Push your new branch to the remote repository and initiate a pull request. ```bash git push origin feat/your-feature-name ``` -------------------------------- ### Initialize Tally Instance Source: https://github.com/caret-collective/tally-ts/blob/main/README.md Import the Tally class and create a new instance, optionally specifying the locale. ```typescript import { Tally } from 'tally-ts'; const tally = new Tally({ locales: 'en' }); ``` -------------------------------- ### Check Code Formatting Source: https://github.com/caret-collective/tally-ts/blob/main/docs/CONTRIBUTING.md Check if files are formatted correctly without modifying them. ```bash deno fmt --check ``` -------------------------------- ### Tally-TS Project Structure Source: https://github.com/caret-collective/tally-ts/blob/main/docs/CONTRIBUTING.md Displays the directory and file structure of the Tally-TS project, including source code, tests, build outputs, and configuration files. ```bash 📂 .github ├── 📂 ISSUE_TEMPLATE ├── 📂 workflows 📂 .vscode 📂 docs # Additional documentation 📂 npm # Build output for npm │ # (auto-generated by the `build:npm` task) ├── 📂 esm # ESM output ├── 📂 script # CJS output ├── 📂 src # Source code 📂 scripts # Helper scripts ├── 📄 build-npm.ts # Build script for npm ├── 📄 generate-segments.mjs # Script to compute segments for test input strings ├── 📄 update-version.ts # Script to update deno.json version 📂 src # Source code ├── 📂 __tests__ # Tests │ ├── 📂 fixtures # Test fixtures │ │ └── 📂 [LOCALE] # Fixtures for a given locale │ │ └── 📂 [TEST_CASE_ID] # A single fixture │ │ ├── 📄 expected.ts # Expected outputs for the test case │ │ ├── 📄 input.mjs # Input string for the test case │ │ └── 📄 segments.ts # Computed segments for the input string │ │ # (auto-generated by the `test:segments` task) │ ├── 📄 index.spec.ts # Unit tests for index.ts │ ├── 📄 types.ts # Test-only types │ └── 📄 utils.ts # Test-only utilities ├── 📄 classifier.ts # Module for classifying characters ├── 📄 index.ts # Main counter module with `Tally` class ├── 📄 legacy.ts # Legacy counter module └── 📄 types.ts # Types 📄 .editorconfig 📄 .gitignore 📄 deno.json # Deno config and task definitions 📄 deno.lock 📄 LICENSE 📄 package.json 📄 project-metadata.json 📄 README.md 📄 release.config.js # Semantic Release config ``` -------------------------------- ### Lint Code Source: https://github.com/caret-collective/tally-ts/blob/main/docs/CONTRIBUTING.md Run the linter to check for code style and potential errors. ```bash deno lint ``` -------------------------------- ### Check TypeScript Types Source: https://github.com/caret-collective/tally-ts/blob/main/docs/CONTRIBUTING.md Use Deno to check the TypeScript types in your project. ```bash deno check ``` -------------------------------- ### Generate Test Segments Source: https://github.com/caret-collective/tally-ts/blob/main/docs/CONTRIBUTING.md Generate segment data for test inputs using Node.js. This is automatically run by the 'test' task. ```bash deno task test:segments ``` -------------------------------- ### Update Version in deno.json Source: https://github.com/caret-collective/tally-ts/blob/main/docs/CONTRIBUTING.md This task updates the version field in deno.json. It is automatically run by the publish workflow before publishing. ```bash deno task version 1.0.0 ``` -------------------------------- ### Set Multiple Locales for Tally Instance Source: https://github.com/caret-collective/tally-ts/blob/main/README.md Configure the Tally instance with an array of locale strings to specify a preference order for segmentation. ```typescript // Multiple locales (preference order) new Tally({ locales: ['fr-CA', 'fr'] }); ``` -------------------------------- ### Use Custom Segmenter with Tally Source: https://github.com/caret-collective/tally-ts/blob/main/README.md Provide a custom Segmenter implementation if the environment lacks native support or for consistent results across runtimes. ```typescript new Tally({ Segmenter: SomeSegmenter }); ``` -------------------------------- ### Set Single Locale for Tally Instance Source: https://github.com/caret-collective/tally-ts/blob/main/README.md Configure the Tally instance with a single locale string for accurate segmentation. ```typescript // Single locale new Tally({ locales: 'en' }); ``` -------------------------------- ### Access Grapheme Breakdown by Type Source: https://github.com/caret-collective/tally-ts/blob/main/README.md Access the 'by' property of the countGraphemes result to see counts of spaces, letters, digits, punctuation, and symbols. ```typescript const result = tally.countGraphemes('Hi there!'); console.debug(result.by); // → { // spaces: { total: 1 }, // letters: { total: 7 }, // digits: { total: 0 }, // punctuation: { total: 1 }, // symbols: { total: 0 } // } ``` -------------------------------- ### Access Related Counts from Graphemes Source: https://github.com/caret-collective/tally-ts/blob/main/README.md Access the 'related' property of the countGraphemes result to see computed counts for paragraphs and lines. ```typescript console.debug(result.related); // → { // paragraphs: { total: 1 }, // lines: { total: 1 } // } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.