### Setup Project with Git, PNPM Source: https://github.com/profullstack/text-type-detection/blob/master/README.md Clones the project repository, navigates into the directory, and installs project dependencies using PNPM. Assumes Git and PNPM are already installed. ```bash # Clone the repository git clone https://github.com/profullstack/text-type-detection.git cd text-type-detection # Install dependencies pnpm install ``` -------------------------------- ### Install @profullstack/text-type-detection with pnpm Source: https://github.com/profullstack/text-type-detection/blob/master/README.md This command installs the @profullstack/text-type-detection package using the pnpm package manager. It is a direct dependency for the project. ```bash pnpm add @profullstack/text-type-detection ``` -------------------------------- ### Install @profullstack/text-type-detection with npm Source: https://github.com/profullstack/text-type-detection/blob/master/README.md This command installs the @profullstack/text-type-detection package using the npm package manager. It is a direct dependency for the project. ```bash npm install @profullstack/text-type-detection ``` -------------------------------- ### Run Project Tests with PNPM Source: https://github.com/profullstack/text-type-detection/blob/master/README.md Executes the project's test suite using PNPM. Includes options to run all tests or run tests in watch mode for continuous feedback during development. ```bash # Run all tests pnpm test # Run tests in watch mode pnpm run test:watch ``` -------------------------------- ### Basic Text Format Detection in JavaScript Source: https://github.com/profullstack/text-type-detection/blob/master/README.md Demonstrates the basic usage of the `detectTextFormat` function from the `@profullstack/text-type-detection` module. It takes a string as input and returns an object containing the detected text format and associated statistics. ```javascript import { detectTextFormat } from '@profullstack/text-type-detection'; const text = '# Hello World\n\nThis is a markdown document.'; const result = detectTextFormat(text); console.log(result); // {\n// text_format: 'markdown',\n// asciiArt: 0.000,\n// markdown: 0.180,\n// reasons: {\n// ascii: [],\n// markdown: ['heading'],\n// codePenaltyApplied: false\n// },\n// stats: { lines: 3, mean: 20.67, std: 12.34, symD: 0.05, alpha: 0.75 }\n// } ``` -------------------------------- ### Lint and Format Code with PNPM Source: https://github.com/profullstack/text-type-detection/blob/master/README.md Manages code quality and consistency using PNPM commands for ESLint and Prettier. Allows running linters and formatters, including an option to automatically fix linting issues. ```bash # Run ESLint pnpm run lint # Fix linting issues pnpm run lint:fix # Format code with Prettier pnpm run format ``` -------------------------------- ### Detecting Plain Text Format in JavaScript Source: https://github.com/profullstack/text-type-detection/blob/master/README.md Illustrates how to use the `detectTextFormat` function to identify plain text. The function analyzes the input string and returns 'plain' as the `text_format` if no other specific format is detected. ```javascript const plainText = 'This is just a simple sentence.'; const result = detectTextFormat(plainText); console.log(result.text_format); // 'plain' ``` -------------------------------- ### Detecting Markdown Format in JavaScript Source: https://github.com/profullstack/text-type-detection/blob/master/README.md Shows how to detect markdown formatted text using the `detectTextFormat` function. The output includes the detected format ('markdown') and specific markdown features found, such as headings, lists, and links. ```javascript const markdown = `# Title\n\n## Subtitle\n\n- Item 1\n- Item 2\n\n[Link](https://example.com)`; const result = detectTextFormat(markdown); console.log(result.text_format); // 'markdown' console.log(result.reasons.markdown); // ['heading', 'list', 'link'] ``` -------------------------------- ### Detecting JSON Format in JavaScript Source: https://github.com/profullstack/text-type-detection/blob/master/README.md Demonstrates the detection of JSON formatted data. The `detectTextFormat` function correctly parses and identifies the string containing JSON key-value pairs as 'json'. ```javascript const json = '{"name": "John", "age": 30}'; const result = detectTextFormat(json); console.log(result.text_format); // 'json' ``` -------------------------------- ### Detecting HTML Format in JavaScript Source: https://github.com/profullstack/text-type-detection/blob/master/README.md Shows how the `detectTextFormat` function identifies standard HTML markup. The input string containing HTML tags is correctly classified as 'html'. ```javascript const html = '
Hello World