@harytempgit01/simplepkg 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # simplepkg
2
+
3
+ A small utility npm package with string helpers, IDs, validation, and a CLI.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install simplepkg
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```js
14
+ import {
15
+ createId,
16
+ createSlug,
17
+ greet,
18
+ parsePackageInput,
19
+ summarizeText
20
+ } from "simplepkg";
21
+
22
+ console.log(greet("World"));
23
+ // Hello, World!
24
+
25
+ console.log(createSlug("Simple NPM Package!"));
26
+ // simple-npm-package
27
+
28
+ console.log(createId("Simple Package"));
29
+ // simple-package_V1StGXR8_Z
30
+
31
+ console.log(summarizeText(" A package helper with spacing ", 18));
32
+ // A package helper...
33
+
34
+ console.log(parsePackageInput({ name: "Simple Package", tags: ["npm", "cli"] }));
35
+ ```
36
+
37
+ ## CLI
38
+
39
+ After install, use the binary:
40
+
41
+ ```sh
42
+ simplepkg greet TanStack
43
+ simplepkg slug "Simple NPM Package!"
44
+ simplepkg id "Simple Package"
45
+ simplepkg summary "A long piece of text to shorten" --max 16
46
+ simplepkg inspect --name "Simple Package" --tag npm cli
47
+ ```
48
+
49
+ ## Scripts
50
+
51
+ ```sh
52
+ npm install
53
+ npm run build
54
+ npm run run -- greet TanStack
55
+ npm test
56
+ ```
57
+
58
+ ## Package Layout
59
+
60
+ - `src/index.js`: package exports
61
+ - `src/cli.js`: CLI source
62
+ - `dist/`: publishable build output
63
+ - `test/`: Node test runner coverage
package/dist/cli.js ADDED
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env node
2
+ import chalk from "chalk";
3
+ import { Command } from "commander";
4
+
5
+ import { createId, createSlug, greet, parsePackageInput, summarizeText } from "./index.js";
6
+
7
+ const program = new Command();
8
+
9
+ program
10
+ .name("simplepkg")
11
+ .description("Small utility CLI for the simplepkg npm package")
12
+ .version("0.2.0");
13
+
14
+ program
15
+ .command("greet")
16
+ .description("Print a friendly greeting")
17
+ .argument("[name]", "name to greet", "World")
18
+ .action((name) => {
19
+ console.log(chalk.green(greet(name)));
20
+ });
21
+
22
+ program
23
+ .command("slug")
24
+ .description("Create a URL-safe slug")
25
+ .argument("<text>", "text to slugify")
26
+ .action((text) => {
27
+ console.log(createSlug(text));
28
+ });
29
+
30
+ program
31
+ .command("id")
32
+ .description("Create a short prefixed ID")
33
+ .argument("[prefix]", "ID prefix", "pkg")
34
+ .action((prefix) => {
35
+ console.log(createId(prefix));
36
+ });
37
+
38
+ program
39
+ .command("summary")
40
+ .description("Trim whitespace and shorten text")
41
+ .argument("<text>", "text to summarize")
42
+ .option("-m, --max <number>", "maximum output length", "80")
43
+ .action((text, options) => {
44
+ console.log(summarizeText(text, Number.parseInt(options.max, 10)));
45
+ });
46
+
47
+ program
48
+ .command("inspect")
49
+ .description("Validate package-like input and print derived data")
50
+ .requiredOption("-n, --name <name>", "package name")
51
+ .option("-d, --description <description>", "package description", "")
52
+ .option("-t, --tag <tag...>", "package tags")
53
+ .action((options) => {
54
+ const result = parsePackageInput({
55
+ name: options.name,
56
+ description: options.description,
57
+ tags: options.tag ?? []
58
+ });
59
+
60
+ console.log(JSON.stringify(result, null, 2));
61
+ });
62
+
63
+ if (process.argv.length <= 2) {
64
+ program.outputHelp();
65
+ process.exit(0);
66
+ }
67
+
68
+ program.parse();
package/dist/index.js ADDED
@@ -0,0 +1,69 @@
1
+ import { nanoid } from "nanoid";
2
+ import slugify from "slugify";
3
+ import { z } from "zod";
4
+
5
+ const displayNameSchema = z.string().trim().min(1).default("World");
6
+
7
+ export function greet(name = "World") {
8
+ if (typeof name !== "string") {
9
+ throw new TypeError("name must be a string");
10
+ }
11
+
12
+ const displayName = displayNameSchema.catch("World").parse(name);
13
+ return `Hello, ${displayName}!`;
14
+ }
15
+
16
+ export function createSlug(value, options = {}) {
17
+ if (typeof value !== "string") {
18
+ throw new TypeError("value must be a string");
19
+ }
20
+
21
+ return slugify(value, {
22
+ lower: true,
23
+ strict: true,
24
+ trim: true,
25
+ ...options
26
+ });
27
+ }
28
+
29
+ export function createId(prefix = "pkg") {
30
+ if (typeof prefix !== "string") {
31
+ throw new TypeError("prefix must be a string");
32
+ }
33
+
34
+ const cleanPrefix = createSlug(prefix || "pkg") || "pkg";
35
+ return `${cleanPrefix}_${nanoid(10)}`;
36
+ }
37
+
38
+ export function summarizeText(text, maxLength = 80) {
39
+ if (typeof text !== "string") {
40
+ throw new TypeError("text must be a string");
41
+ }
42
+
43
+ if (!Number.isInteger(maxLength) || maxLength < 1) {
44
+ throw new RangeError("maxLength must be a positive integer");
45
+ }
46
+
47
+ const normalized = text.replace(/\s+/g, " ").trim();
48
+ if (normalized.length <= maxLength) {
49
+ return normalized;
50
+ }
51
+
52
+ return `${normalized.slice(0, Math.max(0, maxLength - 1)).trimEnd()}...`;
53
+ }
54
+
55
+ export function parsePackageInput(input) {
56
+ const schema = z.object({
57
+ name: z.string().trim().min(1),
58
+ description: z.string().trim().optional().default(""),
59
+ tags: z.array(z.string().trim().min(1)).optional().default([])
60
+ });
61
+
62
+ const parsed = schema.parse(input);
63
+
64
+ return {
65
+ ...parsed,
66
+ slug: createSlug(parsed.name),
67
+ id: createId(parsed.name)
68
+ };
69
+ }
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@harytempgit01/simplepkg",
3
+ "version": "0.2.0",
4
+ "description": "A small utility npm package with string helpers, IDs, validation, and a CLI.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/index.js"
10
+ }
11
+ },
12
+ "bin": {
13
+ "simplepkg": "./dist/cli.js"
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md"
18
+ ],
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/harytempgit01/SimplePkg.git"
25
+ },
26
+ "keywords": [
27
+ "cli",
28
+ "helpers",
29
+ "npm",
30
+ "package",
31
+ "slug"
32
+ ],
33
+ "author": "",
34
+ "license": "MIT",
35
+ "dependencies": {
36
+ "chalk": "^5.3.0",
37
+ "commander": "^12.1.0",
38
+ "nanoid": "^5.0.7",
39
+ "slugify": "^1.6.6",
40
+ "zod": "^3.23.8"
41
+ },
42
+ "engines": {
43
+ "node": ">=18"
44
+ },
45
+ "scripts": {
46
+ "build": "node scripts/build.js",
47
+ "dev": "node src/cli.js",
48
+ "run": "node dist/cli.js",
49
+ "start": "npm run build && npm run run",
50
+ "test": "node --test"
51
+ }
52
+ }