🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@uoctamika/libraryjs

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@uoctamika/libraryjs - npm Package Compare versions

Comparing version
1.0.0
to
1.1.2
+10
-1
dist/cjs/stdio/printf.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.printf = printf;
const util_1 = require("util");
function formatArg(arg, specifier) {

@@ -8,4 +9,11 @@ switch (specifier) {

case 'd': return Number.isInteger(arg) ? String(arg) : 'NaN';
case 'i': return typeof arg === 'number' ? String(parseInt(String(arg), 10)) : 'NaN';
case 'f': return typeof arg === 'number' ? arg.toFixed(6) : 'NaN';
case 'c': return typeof arg === 'string' && arg.length === 1 ? arg : String(arg)[0] || '';
case 'o': return String(arg);
case 'O': return (0, util_1.inspect)(arg, { depth: null, colors: false });
case 'x': return typeof arg === 'number' ? arg.toString(16) : 'NaN';
case 'X': return typeof arg === 'number' ? arg.toString(16).toUpperCase() : 'NaN';
case 'b': return typeof arg === 'number' ? arg.toString(2) : 'NaN';
case 'j': return JSON.stringify(arg);
case '%': return '%';

@@ -20,2 +28,3 @@ default: return String(arg);

const len = format.length;
const validSpecifiers = ['s', 'd', 'i', 'f', 'c', 'o', 'O', 'x', 'X', 'b', 'j', '%'];
while (i < len) {

@@ -30,3 +39,3 @@ if (format[i] === '%') {

}
if (['s', 'd', 'f', 'c'].includes(spec)) {
if (validSpecifiers.includes(spec)) {
const value = args[argIndex++];

@@ -33,0 +42,0 @@ output += formatArg(value, spec);

@@ -0,1 +1,2 @@

import { inspect } from 'util';
function formatArg(arg, specifier) {

@@ -5,4 +6,11 @@ switch (specifier) {

case 'd': return Number.isInteger(arg) ? String(arg) : 'NaN';
case 'i': return typeof arg === 'number' ? String(parseInt(String(arg), 10)) : 'NaN';
case 'f': return typeof arg === 'number' ? arg.toFixed(6) : 'NaN';
case 'c': return typeof arg === 'string' && arg.length === 1 ? arg : String(arg)[0] || '';
case 'o': return String(arg);
case 'O': return inspect(arg, { depth: null, colors: false });
case 'x': return typeof arg === 'number' ? arg.toString(16) : 'NaN';
case 'X': return typeof arg === 'number' ? arg.toString(16).toUpperCase() : 'NaN';
case 'b': return typeof arg === 'number' ? arg.toString(2) : 'NaN';
case 'j': return JSON.stringify(arg);
case '%': return '%';

@@ -17,2 +25,3 @@ default: return String(arg);

const len = format.length;
const validSpecifiers = ['s', 'd', 'i', 'f', 'c', 'o', 'O', 'x', 'X', 'b', 'j', '%'];
while (i < len) {

@@ -27,3 +36,3 @@ if (format[i] === '%') {

}
if (['s', 'd', 'f', 'c'].includes(spec)) {
if (validSpecifiers.includes(spec)) {
const value = args[argIndex++];

@@ -30,0 +39,0 @@ output += formatArg(value, spec);

+2
-6
{
"name": "@uoctamika/libraryjs",
"version": "1.0.0",
"version": "1.1.2",
"description": " A lightweight JavaScript & TypeScript utility library - just import and use. No configuration needed, functions are ready to use",

@@ -24,9 +24,5 @@ "main": "./dist/cjs/index.js",

"clean": "rm -rf dist",
"prepublishOnly": "npm run clean && npm run build",
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint src --ext .ts",
"format": "prettier --write \"src/**/*.ts\"",
"preversion": "npm run lint && npm run test",
"version": "npm run format && git add -A src",
"postversion": "git push && git push --tags"
"format": "prettier --write \"src/**/*.ts\""
},

@@ -33,0 +29,0 @@ "repository": {

@@ -73,12 +73,27 @@ # libraryjs

| `%d` | Decimal integer | `42` | `"42"` |
| `%i` | Integer (parsed from input) | `"42px"` | `"42"` |
| `%f` | Floating-point number (6 decimal places) | `3.14159` | `"3.141590"` |
| `%c` | Character (first character of string) | `"ABC"` | `"A"` |
| `%o` | Object (default string representation) | `{a:1}` | `"[object Object]"` |
| `%O` | Object (full inspection, unlimited depth) | `{a:{b:2}}` | `"{ a: { b: 2 } }"` |
| `%x` | Hexadecimal (lowercase) | `255` | `"ff"` |
| `%X` | Hexadecimal (uppercase) | `255` | `"FF"` |
| `%b` | Binary | `5` | `"101"` |
| `%j` | JSON stringify | `{name:"Uoc"}` | `"{\"name\":\"Uoc\"}"` |
| `%%` | Literal percent sign | - | `"%"` |
Behavior for invalid arguments:
| Specifier | Invalid Input Behavior |
|-----------|------------------------|
| `%d` | Returns `"NaN"` when the value is not an integer |
| `%f` | Returns `"NaN"` when the value is not a number |
| `%c` | Returns an empty string when the input string is empty |
| `%d` | Returns `"NaN"` when the value is not a valid integer |
| `%i` | Returns `"NaN"` when no integer can be parsed from the input |
| `%f` | Returns `"NaN"` when the value is not a valid number |
| `%c` | Returns an empty string (`""`) when the input string is empty |
| `%o` | Returns `"[object Object]"` for non-null values using default object conversion |
| `%O` | Returns a string representation of the value, including nested structures |
| `%x` | Returns `"NaN"` when the value cannot be converted to an integer |
| `%X` | Returns `"NaN"` when the value cannot be converted to an integer |
| `%b` | Returns `"NaN"` when the value cannot be converted to an integer |
| `%j` | Returns `"undefined"` when JSON serialization fails or the value cannot be serialized |

@@ -85,0 +100,0 @@ <br>