Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
text-categorizer
Advanced tools
// Install the package npm install content-type-classifier
// Basic Usage import { ContentTypeClassifier } from 'content-type-classifier';
// Classify any text content const result = ContentTypeClassifier.categorize("your text here");
import { ContentTypeClassifier } from 'content-type-classifier';
// 1. Detecting Links const linkResult = ContentTypeClassifier.categorize("https://www.example.com"); console.log(linkResult); // Output: { // type: "link", // content: "https://www.example.com", // metadata: { links: ["https://www.example.com"] } // }
// 2. Detecting Code
const codeResult = ContentTypeClassifier.categorize(function hello() { return "world"; }
);
console.log(codeResult);
// Output: {
// type: "code",
// content: "function hello() {...}",
// metadata: { codeLanguage: "javascript" }
// }
// 3. Detecting Currency const currencyResult = ContentTypeClassifier.categorize("$1,234.56"); console.log(currencyResult); // Output: { // type: "currency", // content: "$1,234.56", // metadata: { amount: 1234.56, currency: "$" } // }
// 4. Detecting Social Posts const socialResult = ContentTypeClassifier.categorize("Check out #typescript with @johnsmith!"); console.log(socialResult); // Output: { // type: "social", // content: "Check out #typescript with @johnsmith!", // metadata: { // hashtags: ["#typescript"], // mentions: ["@johnsmith"] // } // }
// 5. Detecting CSV
const csvResult = ContentTypeClassifier.categorize(name,age,city John,30,New York Jane,25,Boston
);
console.log(csvResult);
// Output: {
// type: "csv",
// content: "name,age,city...",
// metadata: {
// structured: [
// { name: "John", age: "30", city: "New York" },
// { name: "Jane", age: "25", city: "Boston" }
// ]
// }
// }
// 6. Error Handling try { const result = ContentTypeClassifier.categorize(""); console.log(result); } catch (error) { console.error("Failed to categorize content:", error); }
import { ContentTypeClassifier, ContentCategory } from 'content-type-classifier';
// With type checking function processContent(content: string): void { const result: ContentCategory = ContentTypeClassifier.categorize(content);
switch(result.type) {
case 'link':
console.log("Found links:", result.metadata?.links);
break;
case 'code':
console.log("Code language:", result.metadata?.codeLanguage);
break;
case 'currency':
console.log("Amount:", result.metadata?.amount);
console.log("Currency:", result.metadata?.currency);
break;
// ... handle other types
}
}
// Processing multiple items const contents = [ "https://example.com", "$123.45", "const x = 42;", "#coding @typescript" ];
contents.forEach(content => {
const result = ContentTypeClassifier.categorize(content);
console.log(Content type: ${result.type}
);
console.log("Metadata:", result.metadata);
});
The classifier supports these content types:
Links Code Lists Email JSON Markdown Equations Dates Social posts Search queries Phone numbers Addresses CSV data XML content SQL queries File paths Currency amounts Product codes
FAQs
Intelligent text content type detection and classification
The npm package text-categorizer receives a total of 13 weekly downloads. As such, text-categorizer popularity was classified as not popular.
We found that text-categorizer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.