nekos 1.2.0 → 2.0.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 CHANGED
@@ -135,3 +135,7 @@ nekos({ colors: ["#ff00ff", "#00ffff"] });
135
135
  ## コントリビューション
136
136
 
137
137
  コントリビューションを歓迎します!詳細は[コントリビューションガイドライン](CONTRIBUTING.md)をご覧ください。
138
+
139
+ # Contributors
140
+
141
+ [![Contributors](https://contrib.rocks/image?repo=otoneko1102/nekos)](https://github.com/otoneko1102/nekos/graphs/contributors)
package/dist/index.cjs ADDED
@@ -0,0 +1,101 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // cjs-source-ns:cjs-entry
30
+ var cjs_entry_exports = {};
31
+ __export(cjs_entry_exports, {
32
+ default: () => cjs_entry_default
33
+ });
34
+ module.exports = __toCommonJS(cjs_entry_exports);
35
+ var import_fs = __toESM(require("fs"));
36
+ var import_path = __toESM(require("path"));
37
+ var import_color = require("@randplus/color");
38
+ var import_gradient_string = __toESM(require("gradient-string"));
39
+ var aaDir = import_path.default.join(__dirname, "../aa");
40
+ function nekos(options = {}) {
41
+ const { id } = options;
42
+ let { colors } = options;
43
+ let catAscii = "";
44
+ try {
45
+ const files = import_fs.default.readdirSync(aaDir);
46
+ if (files.length === 0) {
47
+ console.error("Error: 'aa' directory is empty or does not exist.");
48
+ return;
49
+ }
50
+ let targetFile;
51
+ if (id && files.includes(`${id}.txt`)) {
52
+ targetFile = `${id}.txt`;
53
+ } else {
54
+ const randomIndex = Math.floor(Math.random() * files.length);
55
+ targetFile = files[randomIndex];
56
+ }
57
+ const filePath = import_path.default.join(aaDir, targetFile);
58
+ catAscii = import_fs.default.readFileSync(filePath, "utf-8");
59
+ } catch (error) {
60
+ console.error("Error reading ascii art file:", error);
61
+ return;
62
+ }
63
+ if (colors) {
64
+ let processedColors;
65
+ const rainbowColors = [
66
+ "red",
67
+ "orange",
68
+ "yellow",
69
+ "green",
70
+ "blue",
71
+ "violet"
72
+ ];
73
+ if (typeof colors === "string") {
74
+ const upperCaseColor = colors.toUpperCase();
75
+ if (upperCaseColor === "RAINBOW") {
76
+ processedColors = rainbowColors;
77
+ } else if (upperCaseColor === "RANDOM") {
78
+ processedColors = [(0, import_color.hex)("#")];
79
+ } else {
80
+ processedColors = [colors];
81
+ }
82
+ } else if (Array.isArray(colors)) {
83
+ processedColors = colors.map(
84
+ (color) => typeof color === "string" && color.toUpperCase() === "RANDOM" ? (0, import_color.hex)("#") : color
85
+ );
86
+ } else {
87
+ processedColors = colors;
88
+ }
89
+ if (Array.isArray(processedColors) && processedColors.length === 1) {
90
+ processedColors.push(processedColors[0]);
91
+ }
92
+ if (processedColors && processedColors.length > 0) {
93
+ console.log((0, import_gradient_string.default)(processedColors)(catAscii));
94
+ } else {
95
+ console.log(catAscii);
96
+ }
97
+ } else {
98
+ console.log(catAscii);
99
+ }
100
+ }
101
+ var cjs_entry_default = nekos;
@@ -0,0 +1,13 @@
1
+ type ColorKeyword = "RANDOM" | "RAINBOW";
2
+ type HexColor = `#${string}`;
3
+ type ColorValue = ColorKeyword | HexColor;
4
+ interface NekosOptions {
5
+ id?: string;
6
+ colors?: ColorValue | ColorValue[];
7
+ }
8
+ /**
9
+ * Logs a cat ASCII art to the console.
10
+ * @param {NekosOptions} [options={}] - The options object.
11
+ */
12
+ declare function nekos(options?: NekosOptions): void;
13
+ export default nekos;
@@ -1,55 +1,35 @@
1
+ // src/index.ts
1
2
  import fs from "fs";
2
3
  import path from "path";
3
4
  import { fileURLToPath } from "url";
5
+ import { hex } from "@randplus/color";
4
6
  import gradient from "gradient-string";
5
-
6
- /**
7
- * Generates a random HEX color code (e.g., #1a2b3c).
8
- * @returns {string} A random color code.
9
- */
10
- function getRandomHexColor() {
11
- const randomColor = Math.floor(Math.random() * 16777216).toString(16);
12
- return `#${randomColor.padStart(6, "0")}`;
13
- }
14
-
15
- const __filename = fileURLToPath(import.meta.url);
16
- const __dirname = path.dirname(__filename);
17
- const aaDir = path.join(__dirname, "aa");
18
-
19
- /**
20
- * Logs a cat ASCII art to the console.
21
- * @param {object} [options={}] - The options object.
22
- * @param {string|string[]} [options.colors] - A single color, a keyword ("RANDOM", "RAINBOW"), or an array of colors/keywords.
23
- * @param {string} [options.id] - The ID (filename without .txt) of a specific ASCII art file to display.
24
- */
7
+ var __filename = fileURLToPath(import.meta.url);
8
+ var __dirname = path.dirname(__filename);
9
+ var aaDir = path.join(__dirname, "../aa");
25
10
  function nekos(options = {}) {
26
11
  const { id } = options;
27
12
  let { colors } = options;
28
13
  let catAscii = "";
29
-
30
14
  try {
31
15
  const files = fs.readdirSync(aaDir);
32
16
  if (files.length === 0) {
33
17
  console.error("Error: 'aa' directory is empty or does not exist.");
34
18
  return;
35
19
  }
36
-
37
20
  let targetFile;
38
-
39
21
  if (id && files.includes(`${id}.txt`)) {
40
22
  targetFile = `${id}.txt`;
41
23
  } else {
42
24
  const randomIndex = Math.floor(Math.random() * files.length);
43
25
  targetFile = files[randomIndex];
44
26
  }
45
-
46
27
  const filePath = path.join(aaDir, targetFile);
47
28
  catAscii = fs.readFileSync(filePath, "utf-8");
48
29
  } catch (error) {
49
30
  console.error("Error reading ascii art file:", error);
50
31
  return;
51
32
  }
52
-
53
33
  if (colors) {
54
34
  let processedColors;
55
35
  const rainbowColors = [
@@ -58,32 +38,27 @@ function nekos(options = {}) {
58
38
  "yellow",
59
39
  "green",
60
40
  "blue",
61
- "violet",
41
+ "violet"
62
42
  ];
63
-
64
43
  if (typeof colors === "string") {
65
44
  const upperCaseColor = colors.toUpperCase();
66
45
  if (upperCaseColor === "RAINBOW") {
67
46
  processedColors = rainbowColors;
68
47
  } else if (upperCaseColor === "RANDOM") {
69
- processedColors = [getRandomHexColor()];
48
+ processedColors = [hex("#")];
70
49
  } else {
71
50
  processedColors = [colors];
72
51
  }
73
52
  } else if (Array.isArray(colors)) {
74
- processedColors = colors.map((color) =>
75
- typeof color === "string" && color.toUpperCase() === "RANDOM"
76
- ? getRandomHexColor()
77
- : color
53
+ processedColors = colors.map(
54
+ (color) => typeof color === "string" && color.toUpperCase() === "RANDOM" ? hex("#") : color
78
55
  );
79
56
  } else {
80
57
  processedColors = colors;
81
58
  }
82
-
83
59
  if (Array.isArray(processedColors) && processedColors.length === 1) {
84
60
  processedColors.push(processedColors[0]);
85
61
  }
86
-
87
62
  if (processedColors && processedColors.length > 0) {
88
63
  console.log(gradient(processedColors)(catAscii));
89
64
  } else {
@@ -93,5 +68,7 @@ function nekos(options = {}) {
93
68
  console.log(catAscii);
94
69
  }
95
70
  }
96
-
97
- export default nekos;
71
+ var index_default = nekos;
72
+ export {
73
+ index_default as default
74
+ };
package/package.json CHANGED
@@ -1,16 +1,21 @@
1
1
  {
2
2
  "name": "nekos",
3
- "version": "1.2.0",
3
+ "version": "2.0.0",
4
4
  "description": "Let's have cute cats mess around in the log!",
5
- "main": "index.js",
5
+ "type": "module",
6
+ "main": "dist/index.cjs",
7
+ "module": "dist/index.js",
6
8
  "exports": {
7
- "import": "./index.js",
8
- "require": "./index.cjs"
9
+ "import": "./dist/index.js",
10
+ "require": "./dist/index.cjs"
9
11
  },
10
- "types": "index.d.ts",
12
+ "types": "dist/index.d.ts",
11
13
  "scripts": {
12
- "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
13
- "build": "node build.js"
14
+ "test": "cross-env FORCE_COLOR=1 node --experimental-vm-modules node_modules/jest/bin/jest.js",
15
+ "clean": "rimraf dist",
16
+ "build:types": "tsc",
17
+ "build:js": "node scripts/build.js",
18
+ "build": "npm run clean && npm run build:types && npm run build:js"
14
19
  },
15
20
  "repository": {
16
21
  "type": "git",
@@ -32,10 +37,15 @@
32
37
  },
33
38
  "homepage": "https://github.com/otoneko1102/nekos#readme",
34
39
  "dependencies": {
40
+ "@randplus/color": "^3.0.0",
35
41
  "gradient-string": "^3.0.0"
36
42
  },
37
43
  "devDependencies": {
44
+ "@types/node": "^24.3.0",
45
+ "cross-env": "^10.0.0",
38
46
  "esbuild": "^0.25.9",
39
- "jest": "^30.1.1"
47
+ "jest": "^30.1.1",
48
+ "rimraf": "^6.0.1",
49
+ "typescript": "^5.9.2"
40
50
  }
41
51
  }