Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@thi.ng/strings

Package Overview
Dependencies
Maintainers
0
Versions
195
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thi.ng/strings - npm Package Compare versions

Comparing version 3.7.33 to 3.7.34

6

ansi.d.ts

@@ -5,6 +5,8 @@ /**

* @example
* ```ts
* ```ts tangle:../export/strip-ansi.ts
* import { stripAnsi } from "@thi.ng/strings";
*
* stripAnsi("\x1B[32mhello\x1B[0m \x1B[91mworld\x1B[0m!"");
* console.log(
* stripAnsi("\x1B[32mhello\x1B[0m \x1B[91mworld\x1B[0m!")
* );
* // 'hello world!'

@@ -11,0 +13,0 @@ * ```

@@ -7,3 +7,3 @@ import type { Fn, Fn2, FnU } from "@thi.ng/api";

export declare const BOM = "\uFEFF";
export type Stringer<T> = (x: T, ...xs: any[]) => string;
export type Stringer<T> = (x: T, ...args: any[]) => string;
export type FnS = FnU<string>;

@@ -10,0 +10,0 @@ export interface WordWrapOpts {

@@ -25,6 +25,8 @@ import type { FnS, Stringer } from "./api.js";

* @example
* ```ts
* ```ts tangle:../export/kebab.ts
* import { kebab } from "@thi.ng/strings";
*
* kebab("FooBar23Baz");
* console.log(
* kebab("FooBar23Baz")
* );
* // "foo-bar23-baz"

@@ -31,0 +33,0 @@ * ```

@@ -13,6 +13,8 @@ import type { Stringer } from "./api.js";

* @example
* ```ts
* import { center, wrap } from "@thi.ng/strings";
* ```ts tangle:../export/center.ts
* import { center } from "@thi.ng/strings";
*
* center(20, "<>")(wrap(" ")("thi.ng"))
* console.log(
* center(20, "<>")(" thi.ng ")
* );
* // "<><><> thi.ng <><><>"

@@ -22,3 +24,3 @@ * ```

* @example
* ```ts
* ```ts tangle:../export/center-2.ts
* import { comp } from "@thi.ng/compose";

@@ -30,3 +32,3 @@ * import { center, wrap } from "@thi.ng/strings";

*
* fmt("thi.ng")
* console.log(fmt("thi.ng"));
* // "<><><> thi.ng <><><>"

@@ -33,0 +35,0 @@ * ```

# Change Log
- **Last updated**: 2024-05-08T18:24:31Z
- **Last updated**: 2024-06-21T19:34:38Z
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)

@@ -12,2 +12,9 @@

### [3.7.34](https://github.com/thi-ng/umbrella/tree/@thi.ng/strings@3.7.34) (2024-06-21)
#### ♻️ Refactoring
- rename various rest args to be more semantically meaningful ([8088a56](https://github.com/thi-ng/umbrella/commit/8088a56))
- enforce uniform naming convention of internal functions ([56992b2](https://github.com/thi-ng/umbrella/commit/56992b2))
### [3.7.31](https://github.com/thi-ng/umbrella/tree/@thi.ng/strings@3.7.31) (2024-04-20)

@@ -14,0 +21,0 @@

@@ -11,10 +11,14 @@ /**

* @example
* ```ts
* ```ts tangle:../export/compute-cursor-pos.ts
* import { computeCursorPos } from "@thi.ng/strings";
*
* computeCursorPos("thi.ng\numbrella", 10);
* console.log(
* computeCursorPos("thi.ng\numbrella", 10)
* );
* // [ 2, 4 ]
*
* // w/ custom offset
* computeCursorPos("thi.ng\numbrella", 10, "\n", [11, 1]);
* console.log(
* computeCursorPos("thi.ng\numbrella", 10, "\n", [11, 1])
* );
* // [ 12, 4 ]

@@ -21,0 +25,0 @@ * ```

@@ -13,2 +13,4 @@ export declare const ESCAPES: Record<string, string>;

*
* Also see {@link unescape}.
*
* @param src -

@@ -30,7 +32,9 @@ */

* @example
* ```ts
* ```ts tangle:../export/unescape.ts
* import { unescape } from "@thi.ng/strings";
*
* unescape("\\ud83d\\ude0e \\U0001f60e")
* // '😎'
* console.log(
* unescape("\\ud83d\\ude0e \\U0001f60e")
* );
* // '😎 😎'
* ```

@@ -37,0 +41,0 @@ *

import { memoizeJ } from "@thi.ng/memoize/memoizej";
import { padLeft } from "./pad-left.js";
const float = memoizeJ(
(prec, special = false) => special ? (x) => nanOrInf(x) || x.toFixed(prec) : (x) => x.toFixed(prec)
(prec, special = false) => special ? (x) => __nanOrInf(x) || x.toFixed(prec) : (x) => x.toFixed(prec)
);

@@ -15,7 +15,7 @@ const floatFixedWidth = memoizeJ((width, prec = 3) => {

return pad(
nanOrInf(x) || (x === 0 ? "0" : ax < pr || ax >= pl ? exp(x, width) : x.toFixed(prec - (x < pln ? 1 : 0)))
__nanOrInf(x) || (x === 0 ? "0" : ax < pr || ax >= pl ? __exp(x, width) : x.toFixed(prec - (x < pln ? 1 : 0)))
);
};
});
const exp = (x, w) => x.toExponential(
const __exp = (x, w) => x.toExponential(
Math.max(

@@ -26,3 +26,3 @@ w - 4 - (Math.log(Math.abs(x)) / Math.LN10 >= 10 ? 2 : 1) - (x < 0 ? 1 : 0),

);
const nanOrInf = (x) => isNaN(x) ? "NaN" : x === Infinity ? "+\u221E" : x === -Infinity ? "-\u221E" : void 0;
const __nanOrInf = (x) => isNaN(x) ? "NaN" : x === Infinity ? "+\u221E" : x === -Infinity ? "-\u221E" : void 0;
export {

@@ -29,0 +29,0 @@ float,

import { charRange } from "./range.js";
const defGroup = (...xs) => {
const __defGroup = (...ranges) => {
const acc = {};
for (let range of xs) {
for (let range of ranges) {
for (let c of range) {

@@ -19,4 +19,4 @@ acc[c] = true;

});
const DIGITS = defGroup(charRange("0", "9"));
const HEX = defGroup(
const DIGITS = __defGroup(charRange("0", "9"));
const HEX = __defGroup(
charRange("0", "9"),

@@ -26,4 +26,4 @@ charRange("A", "F"),

);
const LOWER = defGroup(charRange("a", "z"));
const UPPER = defGroup(charRange("A", "Z"));
const LOWER = __defGroup(charRange("a", "z"));
const UPPER = __defGroup(charRange("A", "Z"));
const ALPHA = Object.freeze({ ...UPPER, ...LOWER });

@@ -35,3 +35,3 @@ const ALPHA_NUM = Object.freeze({

});
const PUNCTUATION = defGroup(
const PUNCTUATION = __defGroup(
charRange("!", "/"),

@@ -38,0 +38,0 @@ charRange(":", "@"),

@@ -5,14 +5,17 @@ import type { Stringer } from "./api.js";

*
* @remarks
* References:
* - https://en.wikipedia.org/wiki/Hollerith_constant
* - https://en.wikipedia.org/wiki/IGES#File_format
*
* @example
* ```ts
* ```ts tangle:../export/hstr.ts
* import { hstr } from "@thi.ng/strings";
*
* hstr("abc") // "3Habc"
* hstr(123.45) // "6H123.45"
* hstr("") // "0H"
* hstr(null) // ""
* console.log(hstr("abc")); // "3Habc"
* console.log(hstr(123.45)); // "6H123.45"
* console.log(hstr("")); // "0H"
* console.log(hstr(null)); // ""
* ```
*
* https://en.wikipedia.org/wiki/Hollerith_constant
*
* @param x -

@@ -19,0 +22,0 @@ */

@@ -7,10 +7,18 @@ /**

* @example
* ```ts
* initials(["alicia", "bella", "carerra"]);
* ```ts tangle:../export/initials.ts
* import { initials } from "@thi.ng/strings";
*
* console.log(
* initials(["alicia", "bella", "carerra"])
* );
* // "ABC"
*
* initials("shader-ast-GLSL".split("-"))
* console.log(
* initials("shader-ast-GLSL".split("-"))
* );
* // "SAG"
*
* initials("Ludwig van Beethoven".split(" "), null)
* console.log(
* initials("Ludwig van Beethoven".split(" "), null)
* );
* // "LvB"

@@ -17,0 +25,0 @@ * ```

@@ -7,5 +7,12 @@ import type { IObjectOf, NumOrString } from "@thi.ng/api";

*
* @remarks
* Also see {@link interpolateKeys}.
*
* @example
* ```ts
* interpolate("let {0}: {2} = {1};", "a", 42, "number")
* ```ts tangle:../export/interpolate.ts
* import { interpolate } from "@thi.ng/strings";
*
* console.log(
* interpolate("let {0}: {2} = {1};", "a", 42, "number")
* );
* // "let a: number = 42;"

@@ -23,7 +30,11 @@ * ```

* @example
* ```ts
* interpolateKeys(
* "let {id}: {type} = {val};",
* { id: "a", type: "number", val: 42 }
* )
* ```ts tangle:../export/interpolate-keys.ts
* import { interpolateKeys } from "@thi.ng/strings";
*
* console.log(
* interpolateKeys(
* "let {id}: {type} = {val};",
* { id: "a", type: "number", val: 42 }
* )
* );
* // "let a: number = 42;"

@@ -30,0 +41,0 @@ * ```

@@ -8,3 +8,3 @@ import type { Stringer } from "./api.js";

* @example
* ```ts
* ```ts tangle:../export/join.ts
* import { format, join } from "@thi.ng/strings";

@@ -15,3 +15,5 @@ * import { partial } from "@thi.ng/compose";

*
* slashes([1, 2, 3]);
* console.log(
* slashes([1, 2, 3])
* );
* // "1/2/3"

@@ -24,3 +26,5 @@ *

*
* formatOBJFace([1, 2], [3, 4], [5, 6]);
* console.log(
* formatOBJFace([1, 2], [3, 4], [5, 6])
* );
* // "f 1/2 3/4 5/6"

@@ -27,0 +31,0 @@ * ```

{
"name": "@thi.ng/strings",
"version": "3.7.33",
"version": "3.7.34",
"description": "Various string formatting & utility functions",

@@ -13,3 +13,3 @@ "type": "module",

},
"homepage": "https://github.com/thi-ng/umbrella/tree/develop/packages/format#readme",
"homepage": "https://thi.ng/format",
"funding": [

@@ -40,12 +40,12 @@ {

"dependencies": {
"@thi.ng/api": "^8.11.2",
"@thi.ng/errors": "^2.5.7",
"@thi.ng/hex": "^2.3.46",
"@thi.ng/memoize": "^3.3.4"
"@thi.ng/api": "^8.11.3",
"@thi.ng/errors": "^2.5.8",
"@thi.ng/hex": "^2.3.47",
"@thi.ng/memoize": "^3.3.5"
},
"devDependencies": {
"@microsoft/api-extractor": "^7.43.2",
"esbuild": "^0.21.1",
"@microsoft/api-extractor": "^7.47.0",
"esbuild": "^0.21.5",
"typedoc": "^0.25.13",
"typescript": "^5.4.5"
"typescript": "^5.5.2"
},

@@ -208,3 +208,3 @@ "keywords": [

},
"gitHead": "df34b4a9e650cc7323575356de207d78933bdcf3\n"
"gitHead": "154c95cf9d6bab32174498ec3b5b5d87e42be7f9\n"
}

@@ -10,3 +10,3 @@ <!-- This file is generated - DO NOT EDIT! -->

> [!NOTE]
> This is one of 192 standalone projects, maintained as part
> This is one of 193 standalone projects, maintained as part
> of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo

@@ -13,0 +13,0 @@ > and anti-framework.

@@ -6,3 +6,3 @@ /**

* @example
* ```ts
* ```ts tangle:../export/ruler.ts
* import { ruler } from "@thi.ng/strings";

@@ -28,3 +28,3 @@ *

* @example
* ```ts
* ```ts tangle:../export/grid.ts
* import { grid } from "@thi.ng/strings";

@@ -31,0 +31,0 @@ *

@@ -7,6 +7,8 @@ import type { Stringer } from "./api.js";

* @example
* ```ts
* ```ts tangle:../export/slugify.ts
* import { slugify } from "@thi.ng/strings";
*
* slugify("Me, myself (& ëye) 😀!")
* console.log(
* slugify("Me, myself (& ëye) 😀!")
* );
* // "me-myself-and-eye"

@@ -23,6 +25,8 @@ * ```

* @example
* ```ts
* ```ts tangle:../export/slugify-gh.ts
* import { slugifyGH } from "@thi.ng/strings";
*
* slugifyGH("Me, myself (& ëye) 😀!")
* console.log(
* slugifyGH("Me, myself (& ëye) 😀!")
* );
* // "me-myself--ëye-"

@@ -29,0 +33,0 @@ * ```

@@ -1,6 +0,6 @@

const src = "\xE0\xE1\xE4\xE2\xE3\xE5\xE8\xE9\xEB\xEA\xEC\xED\xEF\xEE\xF2\xF3\xF6\xF4\xF9\xFA\xFC\xFB\xF1\xE7\xDF\xFF\u0153\xE6\u0155\u015B\u0144\u1E55\u1E83\u01F5\u01F9\u1E3F\u01D8\u1E8D\u017A\u1E27\xB7/_,:;";
const dest = "aaaaaaeeeeiiiioooouuuuncsyoarsnpwgnmuxzh------";
const re = new RegExp(src.split("").join("|"), "g");
const SRC = "\xE0\xE1\xE4\xE2\xE3\xE5\xE8\xE9\xEB\xEA\xEC\xED\xEF\xEE\xF2\xF3\xF6\xF4\xF9\xFA\xFC\xFB\xF1\xE7\xDF\xFF\u0153\xE6\u0155\u015B\u0144\u1E55\u1E83\u01F5\u01F9\u1E3F\u01D8\u1E8D\u017A\u1E27\xB7/_,:;";
const DEST = "aaaaaaeeeeiiiioooouuuuncsyoarsnpwgnmuxzh------";
const RE = new RegExp(SRC.split("").join("|"), "g");
const slugify = (str) => {
return str.toLowerCase().replace(/\s+/g, "-").replace(re, (c) => dest[src.indexOf(c)]).replace(/&+/g, "-and-").replace(/[^\w-]+/g, "").replace(/\p{Emoji_Presentation}/gu, "").replace(/-{2,}/g, "-").replace(/(^-+)|(-+$)/g, "");
return str.toLowerCase().replace(/\s+/g, "-").replace(RE, (c) => DEST[SRC.indexOf(c)]).replace(/&+/g, "-and-").replace(/[^\w-]+/g, "").replace(/\p{Emoji_Presentation}/gu, "").replace(/-{2,}/g, "-").replace(/(^-+)|(-+$)/g, "");
};

@@ -7,0 +7,0 @@ const slugifyGH = (str) => {

@@ -10,12 +10,18 @@ import type { Stringer } from "./api.js";

* @example
* ```ts
* ```ts tangle:../export/stringify.ts
* import { stringify } from "@thi.ng/strings";
*
* stringify()("hello");
* console.log(
* stringify()("hello")
* );
* // hello
*
* stringify(true)("hello");
* console.log(
* stringify(true)("hello")
* );
* // "hello"
*
* stringify()({ a: "hello" })
* console.log(
* stringify()({ a: "hello" })
* );
* // { "a": "hello" }

@@ -22,0 +28,0 @@ * ```

@@ -5,3 +5,3 @@ /**

* @example
* ```ts
* ```ts tangle:../export/tabs-to-spaces.ts
* import { tabsToSpaces } from "@thi.ng/strings";

@@ -27,3 +27,3 @@ *

* Takes a single line string and converts all tab characters to spaces, using
* given `tabSize`.
* given `tabSize` (default: 4).
*

@@ -30,0 +30,0 @@ * @param line -

import { repeat } from "./repeat.js";
const nextTab = (x, tabSize) => Math.floor((x + tabSize) / tabSize) * tabSize;
const __nextTab = (x, tabSize) => Math.floor((x + tabSize) / tabSize) * tabSize;
const tabsToSpaces = (src, tabSize = 4) => src.split(/\r?\n/g).map((line) => tabsToSpacesLine(line, tabSize)).join("\n");

@@ -11,3 +11,3 @@ const tabsToSpacesLine = (line, tabSize = 4) => {

res += w;
res += repeat(" ", nextTab(res.length, tabSize) - res.length);
res += repeat(" ", __nextTab(res.length, tabSize) - res.length);
}

@@ -29,3 +29,3 @@ res += words[n];

while (i < end) {
const j = nextTab(i, tabSize);
const j = __nextTab(i, tabSize);
if (j <= end) {

@@ -32,0 +32,0 @@ res += " ";

@@ -7,9 +7,13 @@ import type { Stringer } from "./api.js";

* @example
* ```ts
* ```ts tangle:../export/trim.ts
* import { trim } from "@thi.ng/strings";
*
* trim()(" Hello ")
* console.log(
* trim()(" Hello ")
* );
* // "Hello"
*
* trim(" -+")("-+-+- Hello -+-+-")
* console.log(
* trim(" -+")("-+-+- Hello -+-+-")
* );
* // "Hello"

@@ -16,0 +20,0 @@ * ```

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

/// <reference types="node" />
/**

@@ -48,6 +47,6 @@ * Returns the number of bytes required to encode the given string as UTF-8.

message: string;
stack?: string | undefined;
stack?: string;
cause?: unknown;
};
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;

@@ -54,0 +53,0 @@ stackTraceLimit: number;

@@ -30,3 +30,3 @@ import { defError } from "@thi.ng/errors/deferror";

c = (c & 7) << 18 | (buf[i++] & 63) << 12 | (buf[i++] & 63) << 6 | buf[i++] & 63;
} else utf8Error();
} else __utf8Error();
result += fromUtf8CodePoint(c);

@@ -68,6 +68,6 @@ }

}
return utf8Error(`invalid codepoint 0x${x.toString(16)}`);
return __utf8Error(`invalid codepoint 0x${x.toString(16)}`);
};
const UTF8Error = defError(() => "UTF-8 error");
const utf8Error = (msg) => {
const __utf8Error = (msg) => {
throw new UTF8Error(msg);

@@ -74,0 +74,0 @@ };

@@ -14,3 +14,3 @@ /**

*/
export declare const uuid: (id: ArrayLike<number>, i?: number | undefined) => string;
export declare const uuid: (id: ArrayLike<number>, i?: number) => string;
//# sourceMappingURL=uuid.d.ts.map

@@ -37,7 +37,7 @@ import { lengthAnsi } from "./ansi.js";

};
const append = (acc, word, wordLen, width) => {
const __append = (acc, word, wordLen, width) => {
const curr = acc[acc.length - 1];
curr && width - curr.n > wordLen ? curr.add(word, wordLen) : acc.push(new Line(word, wordLen));
};
const wrapWord = (word, { width, min, hard, splitter }, offset = 0, acc = []) => {
const __wrapWord = (word, { width, min, hard, splitter }, offset = 0, acc = []) => {
let len = splitter.length(word);

@@ -51,3 +51,3 @@ let free = width - offset;

const chunk = word.substring(0, split2);
append(acc, chunk, free, width);
__append(acc, chunk, free, width);
word = word.substring(split2);

@@ -57,3 +57,3 @@ free = width;

}
append(acc, word, len, width);
__append(acc, word, len, width);
return acc;

@@ -75,3 +75,3 @@ };

const curr = acc[acc.length - 1];
wrapWord(word, $opts, curr && curr.n > 0 ? curr.n + 1 : 0, acc);
__wrapWord(word, $opts, curr && curr.n > 0 ? curr.n + 1 : 0, acc);
}

@@ -78,0 +78,0 @@ return acc;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc