Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@rg-dev/stdlib

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rg-dev/stdlib - npm Package Compare versions

Comparing version
1.0.53
to
1.0.54
+12
-0
lib/common-env.cjs

@@ -48,2 +48,3 @@ var __defProp = Object.defineProperty;

isRunningOnServer: () => isRunningOnServer,
lazyValue: () => lazyValue,
promiseRetry: () => promiseRetry,

@@ -263,1 +264,12 @@ promiseWithTimeout: () => promiseWithTimeout,

}
function lazyValue(function_) {
let isCalled = false;
let result = void 0;
return () => {
if (!isCalled) {
isCalled = true;
result = function_();
}
return result;
};
}
+2
-1

@@ -78,3 +78,4 @@ export { VERSION } from './index.cjs';

declare function isNonEmptyString(str?: string): boolean;
declare function lazyValue<T = unknown>(function_: () => T): () => T;
export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, fetchHelperJSON, fetchHelperPost, fetchHelperText, isNonEmptyString, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer };
export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, fetchHelperJSON, fetchHelperPost, fetchHelperText, isNonEmptyString, isNumber, isRunningOnServer, lazyValue, promiseRetry, promiseWithTimeout, sleep, useServer };

@@ -78,3 +78,4 @@ export { VERSION } from './index.js';

declare function isNonEmptyString(str?: string): boolean;
declare function lazyValue<T = unknown>(function_: () => T): () => T;
export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, fetchHelperJSON, fetchHelperPost, fetchHelperText, isNonEmptyString, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer };
export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, fetchHelperJSON, fetchHelperPost, fetchHelperText, isNonEmptyString, isNumber, isRunningOnServer, lazyValue, promiseRetry, promiseWithTimeout, sleep, useServer };

@@ -226,2 +226,13 @@ var __defProp = Object.defineProperty;

}
function lazyValue(function_) {
let isCalled = false;
let result = void 0;
return () => {
if (!isCalled) {
isCalled = true;
result = function_();
}
return result;
};
}
export {

@@ -239,2 +250,3 @@ Optional,

isRunningOnServer,
lazyValue,
promiseRetry,

@@ -241,0 +253,0 @@ promiseWithTimeout,

@@ -0,3 +1,5 @@

export { VERSION } from './index.cjs';
declare function downloadFile(url: string, destination: string, headers?: Record<string, any>): Promise<string>;
export { downloadFile };

@@ -0,3 +1,5 @@

export { VERSION } from './index.js';
declare function downloadFile(url: string, destination: string, headers?: Record<string, any>): Promise<string>;
export { downloadFile };

@@ -54,3 +54,3 @@ var __create = Object.create;

var fs2 = require("fs");
var path2 = require("path");
var path3 = require("path");
var access = fs2.access;

@@ -159,4 +159,4 @@ var accessSync = fs2.accessSync;

if (isPathName) {
var dirname = '"' + path2.dirname(s) + '"';
var basename = '"' + path2.basename(s) + '"';
var dirname = '"' + path3.dirname(s) + '"';
var basename = '"' + path3.basename(s) + '"';
return dirname + ":" + basename;

@@ -216,2 +216,3 @@ }

createTempFilePath: () => createTempFilePath,
getEnvPaths: () => getEnvPaths,
isWindows: () => isWindows,

@@ -348,3 +349,62 @@ throwIfDirNotEmpty: () => throwIfDirNotEmpty,

// node_modules/env-paths/index.js
var import_node_path = __toESM(require("path"), 1);
var import_node_os = __toESM(require("os"), 1);
var import_node_process = __toESM(require("process"), 1);
var homedir = import_node_os.default.homedir();
var tmpdir = import_node_os.default.tmpdir();
var { env } = import_node_process.default;
var macos = (name) => {
const library = import_node_path.default.join(homedir, "Library");
return {
data: import_node_path.default.join(library, "Application Support", name),
config: import_node_path.default.join(library, "Preferences", name),
cache: import_node_path.default.join(library, "Caches", name),
log: import_node_path.default.join(library, "Logs", name),
temp: import_node_path.default.join(tmpdir, name)
};
};
var windows = (name) => {
const appData = env.APPDATA || import_node_path.default.join(homedir, "AppData", "Roaming");
const localAppData = env.LOCALAPPDATA || import_node_path.default.join(homedir, "AppData", "Local");
return {
// Data/config/cache/log are invented by me as Windows isn't opinionated about this
data: import_node_path.default.join(localAppData, name, "Data"),
config: import_node_path.default.join(appData, name, "Config"),
cache: import_node_path.default.join(localAppData, name, "Cache"),
log: import_node_path.default.join(localAppData, name, "Log"),
temp: import_node_path.default.join(tmpdir, name)
};
};
var linux = (name) => {
const username = import_node_path.default.basename(homedir);
return {
data: import_node_path.default.join(env.XDG_DATA_HOME || import_node_path.default.join(homedir, ".local", "share"), name),
config: import_node_path.default.join(env.XDG_CONFIG_HOME || import_node_path.default.join(homedir, ".config"), name),
cache: import_node_path.default.join(env.XDG_CACHE_HOME || import_node_path.default.join(homedir, ".cache"), name),
// https://wiki.debian.org/XDGBaseDirectorySpecification#state
log: import_node_path.default.join(env.XDG_STATE_HOME || import_node_path.default.join(homedir, ".local", "state"), name),
temp: import_node_path.default.join(tmpdir, username, name)
};
};
function envPaths(name, { suffix = "nodejs" } = {}) {
if (typeof name !== "string") {
throw new TypeError(`Expected a string, got ${typeof name}`);
}
if (suffix) {
name += `-${suffix}`;
}
if (import_node_process.default.platform === "darwin") {
return macos(name);
}
if (import_node_process.default.platform === "win32") {
return windows(name);
}
return linux(name);
}
// src/node-env.ts
function getEnvPaths(name, options) {
return envPaths(name, options);
}
function isWindows() {

@@ -369,10 +429,10 @@ return import_os.default.platform() === "win32";

}
async function checkIfDirExistsOrThrow(path2) {
if (!path2) throw "path is empty";
path2 = removeQuotes(path2);
if (!await fs.pathExists(path2)) {
throw new Error(`path ${path2} not exists`);
async function checkIfDirExistsOrThrow(path3) {
if (!path3) throw "path is empty";
path3 = removeQuotes(path3);
if (!await fs.pathExists(path3)) {
throw new Error(`path ${path3} not exists`);
}
if (!(await fs.stat(path2)).isDirectory()) {
throw new Error(`${path2} is a file, require dir`);
if (!(await fs.stat(path3)).isDirectory()) {
throw new Error(`${path3} is a file, require dir`);
}

@@ -379,0 +439,0 @@ }

@@ -31,2 +31,71 @@ import { Response } from 'express';

interface Options {
/**
__Don't use this option unless you really have to!__
Suffix appended to the project name to avoid name conflicts with native apps. Pass an empty string to disable it.
@default 'nodejs'
*/
readonly suffix?: string;
}
interface Paths {
/**
Directory for data files.
Example locations (with the default `nodejs` suffix):
- macOS: `~/Library/Application Support/MyApp-nodejs`
- Windows: `%LOCALAPPDATA%\MyApp-nodejs\Data` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Data`)
- Linux: `~/.local/share/MyApp-nodejs` (or `$XDG_DATA_HOME/MyApp-nodejs`)
*/
readonly data: string;
/**
Directory for data files.
Example locations (with the default `nodejs` suffix):
- macOS: `~/Library/Preferences/MyApp-nodejs`
- Windows: `%APPDATA%\MyApp-nodejs\Config` (for example, `C:\Users\USERNAME\AppData\Roaming\MyApp-nodejs\Config`)
- Linux: `~/.config/MyApp-nodejs` (or `$XDG_CONFIG_HOME/MyApp-nodejs`)
*/
readonly config: string;
/**
Directory for non-essential data files.
Example locations (with the default `nodejs` suffix):
- macOS: `~/Library/Caches/MyApp-nodejs`
- Windows: `%LOCALAPPDATA%\MyApp-nodejs\Cache` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Cache`)
- Linux: `~/.cache/MyApp-nodejs` (or `$XDG_CACHE_HOME/MyApp-nodejs`)
*/
readonly cache: string;
/**
Directory for log files.
Example locations (with the default `nodejs` suffix):
- macOS: `~/Library/Logs/MyApp-nodejs`
- Windows: `%LOCALAPPDATA%\MyApp-nodejs\Log` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Log`)
- Linux: `~/.local/state/MyApp-nodejs` (or `$XDG_STATE_HOME/MyApp-nodejs`)
*/
readonly log: string;
/**
Directory for temporary files.
Example locations (with the default `nodejs` suffix):
- macOS: `/var/folders/jf/f2twvvvs5jl_m49tf034ffpw0000gn/T/MyApp-nodejs`
- Windows: `%LOCALAPPDATA%\Temp\MyApp-nodejs` (for example, `C:\Users\USERNAME\AppData\Local\Temp\MyApp-nodejs`)
- Linux: `/tmp/USERNAME/MyApp-nodejs`
*/
readonly temp: string;
}
declare function getEnvPaths(name: string, options?: Options): Paths;
declare function isWindows(): boolean;

@@ -46,2 +115,2 @@ type SystemArch = "x64" | "arm64" | "arm" | "ia32" | "ppc64" | "s390x" | "loong64" | "riscv64";

export { SSEClient, SSEResponse, type SystemArch, checkCommandExistsOrThrow, checkIfDirExistsOrThrow, checkIfFileExistsOrThrow, chmodPlusX, createTempDir, createTempFilePath, isWindows, throwIfDirNotEmpty, typedSystemArch };
export { SSEClient, SSEResponse, type SystemArch, checkCommandExistsOrThrow, checkIfDirExistsOrThrow, checkIfFileExistsOrThrow, chmodPlusX, createTempDir, createTempFilePath, getEnvPaths, isWindows, throwIfDirNotEmpty, typedSystemArch };

@@ -31,2 +31,71 @@ import { Response } from 'express';

interface Options {
/**
__Don't use this option unless you really have to!__
Suffix appended to the project name to avoid name conflicts with native apps. Pass an empty string to disable it.
@default 'nodejs'
*/
readonly suffix?: string;
}
interface Paths {
/**
Directory for data files.
Example locations (with the default `nodejs` suffix):
- macOS: `~/Library/Application Support/MyApp-nodejs`
- Windows: `%LOCALAPPDATA%\MyApp-nodejs\Data` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Data`)
- Linux: `~/.local/share/MyApp-nodejs` (or `$XDG_DATA_HOME/MyApp-nodejs`)
*/
readonly data: string;
/**
Directory for data files.
Example locations (with the default `nodejs` suffix):
- macOS: `~/Library/Preferences/MyApp-nodejs`
- Windows: `%APPDATA%\MyApp-nodejs\Config` (for example, `C:\Users\USERNAME\AppData\Roaming\MyApp-nodejs\Config`)
- Linux: `~/.config/MyApp-nodejs` (or `$XDG_CONFIG_HOME/MyApp-nodejs`)
*/
readonly config: string;
/**
Directory for non-essential data files.
Example locations (with the default `nodejs` suffix):
- macOS: `~/Library/Caches/MyApp-nodejs`
- Windows: `%LOCALAPPDATA%\MyApp-nodejs\Cache` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Cache`)
- Linux: `~/.cache/MyApp-nodejs` (or `$XDG_CACHE_HOME/MyApp-nodejs`)
*/
readonly cache: string;
/**
Directory for log files.
Example locations (with the default `nodejs` suffix):
- macOS: `~/Library/Logs/MyApp-nodejs`
- Windows: `%LOCALAPPDATA%\MyApp-nodejs\Log` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Log`)
- Linux: `~/.local/state/MyApp-nodejs` (or `$XDG_STATE_HOME/MyApp-nodejs`)
*/
readonly log: string;
/**
Directory for temporary files.
Example locations (with the default `nodejs` suffix):
- macOS: `/var/folders/jf/f2twvvvs5jl_m49tf034ffpw0000gn/T/MyApp-nodejs`
- Windows: `%LOCALAPPDATA%\Temp\MyApp-nodejs` (for example, `C:\Users\USERNAME\AppData\Local\Temp\MyApp-nodejs`)
- Linux: `/tmp/USERNAME/MyApp-nodejs`
*/
readonly temp: string;
}
declare function getEnvPaths(name: string, options?: Options): Paths;
declare function isWindows(): boolean;

@@ -46,2 +115,2 @@ type SystemArch = "x64" | "arm64" | "arm" | "ia32" | "ppc64" | "s390x" | "loong64" | "riscv64";

export { SSEClient, SSEResponse, type SystemArch, checkCommandExistsOrThrow, checkIfDirExistsOrThrow, checkIfFileExistsOrThrow, chmodPlusX, createTempDir, createTempFilePath, isWindows, throwIfDirNotEmpty, typedSystemArch };
export { SSEClient, SSEResponse, type SystemArch, checkCommandExistsOrThrow, checkIfDirExistsOrThrow, checkIfFileExistsOrThrow, chmodPlusX, createTempDir, createTempFilePath, getEnvPaths, isWindows, throwIfDirNotEmpty, typedSystemArch };

@@ -55,3 +55,3 @@ var __create = Object.create;

var fs2 = __require("fs");
var path2 = __require("path");
var path3 = __require("path");
var access = fs2.access;

@@ -160,4 +160,4 @@ var accessSync = fs2.accessSync;

if (isPathName) {
var dirname = '"' + path2.dirname(s) + '"';
var basename = '"' + path2.basename(s) + '"';
var dirname = '"' + path3.dirname(s) + '"';
var basename = '"' + path3.basename(s) + '"';
return dirname + ":" + basename;

@@ -208,4 +208,4 @@ }

import * as fs from "fs-extra";
import os from "os";
import path from "path";
import os2 from "os";
import path2 from "path";

@@ -333,15 +333,74 @@ // src/SSEResponse.ts

// node_modules/env-paths/index.js
import path from "path";
import os from "os";
import process2 from "process";
var homedir = os.homedir();
var tmpdir = os.tmpdir();
var { env } = process2;
var macos = (name) => {
const library = path.join(homedir, "Library");
return {
data: path.join(library, "Application Support", name),
config: path.join(library, "Preferences", name),
cache: path.join(library, "Caches", name),
log: path.join(library, "Logs", name),
temp: path.join(tmpdir, name)
};
};
var windows = (name) => {
const appData = env.APPDATA || path.join(homedir, "AppData", "Roaming");
const localAppData = env.LOCALAPPDATA || path.join(homedir, "AppData", "Local");
return {
// Data/config/cache/log are invented by me as Windows isn't opinionated about this
data: path.join(localAppData, name, "Data"),
config: path.join(appData, name, "Config"),
cache: path.join(localAppData, name, "Cache"),
log: path.join(localAppData, name, "Log"),
temp: path.join(tmpdir, name)
};
};
var linux = (name) => {
const username = path.basename(homedir);
return {
data: path.join(env.XDG_DATA_HOME || path.join(homedir, ".local", "share"), name),
config: path.join(env.XDG_CONFIG_HOME || path.join(homedir, ".config"), name),
cache: path.join(env.XDG_CACHE_HOME || path.join(homedir, ".cache"), name),
// https://wiki.debian.org/XDGBaseDirectorySpecification#state
log: path.join(env.XDG_STATE_HOME || path.join(homedir, ".local", "state"), name),
temp: path.join(tmpdir, username, name)
};
};
function envPaths(name, { suffix = "nodejs" } = {}) {
if (typeof name !== "string") {
throw new TypeError(`Expected a string, got ${typeof name}`);
}
if (suffix) {
name += `-${suffix}`;
}
if (process2.platform === "darwin") {
return macos(name);
}
if (process2.platform === "win32") {
return windows(name);
}
return linux(name);
}
// src/node-env.ts
function getEnvPaths(name, options) {
return envPaths(name, options);
}
function isWindows() {
return os.platform() === "win32";
return os2.platform() === "win32";
}
function typedSystemArch() {
return os.arch();
return os2.arch();
}
function chmodPlusX(filePath) {
if (os.platform() === "win32") {
if (os2.platform() === "win32") {
return;
}
try {
const resolvedPath = path.resolve(filePath);
const resolvedPath = path2.resolve(filePath);
const stats = fs.statSync(resolvedPath);

@@ -354,17 +413,17 @@ const newMode = stats.mode | 73;

}
async function checkIfDirExistsOrThrow(path2) {
if (!path2) throw "path is empty";
path2 = removeQuotes(path2);
if (!await fs.pathExists(path2)) {
throw new Error(`path ${path2} not exists`);
async function checkIfDirExistsOrThrow(path3) {
if (!path3) throw "path is empty";
path3 = removeQuotes(path3);
if (!await fs.pathExists(path3)) {
throw new Error(`path ${path3} not exists`);
}
if (!(await fs.stat(path2)).isDirectory()) {
throw new Error(`${path2} is a file, require dir`);
if (!(await fs.stat(path3)).isDirectory()) {
throw new Error(`${path3} is a file, require dir`);
}
}
function createTempDir() {
const tmpDir = os.tmpdir();
const tmpDir = os2.tmpdir();
const timestamp = Date.now();
const tempDirName = `temp_dir_${timestamp}_${Math.random().toString(36).slice(2)}`;
const tempDirPath = path.join(tmpDir, tempDirName);
const tempDirPath = path2.join(tmpDir, tempDirName);
console.log("tempDir", tempDirPath);

@@ -383,3 +442,3 @@ fs.mkdirSync(tempDirPath);

const name = `temp_file_${process.pid}_${Date.now()}_${Math.random().toString(36).slice(2)}${ext ? `.${ext}` : ""}`;
const fullPath = path.join(os.tmpdir(), name);
const fullPath = path2.join(os2.tmpdir(), name);
return {

@@ -438,2 +497,3 @@ getName: () => fullPath,

createTempFilePath,
getEnvPaths,
isWindows,

@@ -440,0 +500,0 @@ throwIfDirNotEmpty,

{
"name": "@rg-dev/stdlib",
"version": "1.0.53",
"version": "1.0.54",
"description": "",

@@ -8,3 +8,3 @@ "scripts": {

"build": "tsup && node after-build.mjs",
"ts":"tsdown"
"ts": "tsdown"
},

@@ -38,4 +38,3 @@ "author": "",

"exports": {
".":{
".": {
"import": "./lib/index.js",

@@ -45,4 +44,2 @@ "require": "./lib/index.cjs",

},
"./lib/trpc-helpers": {

@@ -80,3 +77,3 @@ "import": "./lib/trpc-helpers.js",

"devDependencies": {
"tsdown": "^0.19.0",
"env-paths": "^3.0.0",
"@trpc/server": "^11.1.1",

@@ -92,2 +89,3 @@ "@types/command-exists": "^1.2.3",

"superjson": "^2.2.6",
"tsdown": "^0.19.0",
"tsup": "^8.0.1",

@@ -94,0 +92,0 @@ "typescript": "^5.9.3"

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display