🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@rg-dev/stdlib

Package Overview
Dependencies
Maintainers
1
Versions
68
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.18
to
1.0.19
+29
-0
lib/common-env.cjs

@@ -23,4 +23,6 @@ var __defProp = Object.defineProperty;

Optional: () => Optional,
StringBuilder: () => StringBuilder,
catchInline: () => catchInline,
doSafe: () => doSafe,
isNonEmptyString: () => isNonEmptyString,
isNumber: () => isNumber,

@@ -63,2 +65,26 @@ isRunningOnServer: () => isRunningOnServer,

// src/StringBuilder.ts
var StringBuilder = class {
_chunks;
constructor() {
this._chunks = [];
}
/** {@inheritDoc IStringBuilder.append} */
append(text) {
this._chunks.push(text);
}
/** {@inheritDoc IStringBuilder.toString} */
toString() {
if (this._chunks.length === 0) {
return "";
}
if (this._chunks.length > 1) {
const joined = this._chunks.join("");
this._chunks.length = 1;
this._chunks[0] = joined;
}
return this._chunks[0];
}
};
// src/common-env.ts

@@ -170,1 +196,4 @@ var Optional = class _Optional {

}
function isNonEmptyString(str) {
return typeof str == "string" && str.trim().length > 0;
}
+38
-1

@@ -8,2 +8,38 @@ type Options = {

interface IStringBuilder {
/**
* Append the specified text to the buffer.
*/
append(text: string): void;
/**
* Returns a single string containing all the text that was appended to the buffer so far.
*
* @remarks
*
* This is a potentially expensive operation.
*/
toString(): string;
}
/**
* This class allows a large text string to be constructed incrementally by appending small chunks. The final
* string can be obtained by calling StringBuilder.toString().
*
* @remarks
* A naive approach might use the `+=` operator to append strings: This would have the downside of copying
* the entire string each time a chunk is appended, resulting in `O(n^2)` bytes of memory being allocated
* (and later freed by the garbage collector), and many of the allocations could be very large objects.
* StringBuilder avoids this overhead by accumulating the chunks in an array, and efficiently joining them
* when `getText()` is finally called.
*
* @public
*/
declare class StringBuilder implements IStringBuilder {
private _chunks;
constructor();
/** {@inheritDoc IStringBuilder.append} */
append(text: string): void;
/** {@inheritDoc IStringBuilder.toString} */
toString(): string;
}
type MyFn<T extends Record<string, (...args: any[]) => any>> = {

@@ -36,3 +72,4 @@ [K in keyof T]: (...args: Parameters<T[K]>) => void;

declare function useServer(fn: () => (Promise<any> | void), onError?: (err: Error) => void): Promise<any>;
declare function isNonEmptyString(str: string): boolean;
export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, catchInline, doSafe, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer };
export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, isNonEmptyString, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer };

@@ -8,2 +8,38 @@ type Options = {

interface IStringBuilder {
/**
* Append the specified text to the buffer.
*/
append(text: string): void;
/**
* Returns a single string containing all the text that was appended to the buffer so far.
*
* @remarks
*
* This is a potentially expensive operation.
*/
toString(): string;
}
/**
* This class allows a large text string to be constructed incrementally by appending small chunks. The final
* string can be obtained by calling StringBuilder.toString().
*
* @remarks
* A naive approach might use the `+=` operator to append strings: This would have the downside of copying
* the entire string each time a chunk is appended, resulting in `O(n^2)` bytes of memory being allocated
* (and later freed by the garbage collector), and many of the allocations could be very large objects.
* StringBuilder avoids this overhead by accumulating the chunks in an array, and efficiently joining them
* when `getText()` is finally called.
*
* @public
*/
declare class StringBuilder implements IStringBuilder {
private _chunks;
constructor();
/** {@inheritDoc IStringBuilder.append} */
append(text: string): void;
/** {@inheritDoc IStringBuilder.toString} */
toString(): string;
}
type MyFn<T extends Record<string, (...args: any[]) => any>> = {

@@ -36,3 +72,4 @@ [K in keyof T]: (...args: Parameters<T[K]>) => void;

declare function useServer(fn: () => (Promise<any> | void), onError?: (err: Error) => void): Promise<any>;
declare function isNonEmptyString(str: string): boolean;
export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, catchInline, doSafe, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer };
export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, isNonEmptyString, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer };

@@ -29,2 +29,26 @@ // src/promise-retry.ts

// src/StringBuilder.ts
var StringBuilder = class {
_chunks;
constructor() {
this._chunks = [];
}
/** {@inheritDoc IStringBuilder.append} */
append(text) {
this._chunks.push(text);
}
/** {@inheritDoc IStringBuilder.toString} */
toString() {
if (this._chunks.length === 0) {
return "";
}
if (this._chunks.length > 1) {
const joined = this._chunks.join("");
this._chunks.length = 1;
this._chunks[0] = joined;
}
return this._chunks[0];
}
};
// src/common-env.ts

@@ -136,6 +160,11 @@ var Optional = class _Optional {

}
function isNonEmptyString(str) {
return typeof str == "string" && str.trim().length > 0;
}
export {
Optional,
StringBuilder,
catchInline,
doSafe,
isNonEmptyString,
isNumber,

@@ -142,0 +171,0 @@ isRunningOnServer,

+10
-4
{
"name": "@rg-dev/stdlib",
"version": "1.0.18",
"version": "1.0.19",
"description": "",

@@ -14,2 +14,5 @@ "scripts": {

],
"typesVersions": {

@@ -33,11 +36,14 @@ "*": {

"import": "./lib/node-env.js",
"require": "./lib/node-env.cjs"
"require": "./lib/node-env.cjs",
"types": "./lib/node-env.d.ts"
},
"./lib/common-env": {
"import": "./lib/common-env.js",
"require": "./lib/common-env.cjs"
"require": "./lib/common-env.cjs",
"types": "./lib/common-env.d.ts"
},
"./lib/node-download": {
"import": "./lib/node-download.js",
"require": "./lib/node-download.cjs"
"require": "./lib/node-download.cjs",
"types": "./lib/node-download.d.ts"
}

@@ -44,0 +50,0 @@ },