Socket
Socket
Sign inDemoInstall

@thi.ng/strings

Package Overview
Dependencies
Maintainers
1
Versions
191
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 0.2.0 to 0.3.0

truncate-left.d.ts

2

api.d.ts

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

export declare type Stringer<T> = (x: T) => string;
export declare type Stringer<T> = (x: T, ...xs: any[]) => string;

@@ -20,1 +20,28 @@ import { Stringer } from "./api";

export declare const capitalize: Stringer<string>;
/**
* Converts a CamelCase string into kebab case, with optional custom
* delimiter (`-` by default).
*
* ```
* kebab("FooBar23Baz");
* // "foo-bar23-baz"
* ```
*
* @param x
* @param delim
*/
export declare const kebab: Stringer<string>;
/**
* Short for `kebab` using `_` as delimiter.
*
* @param x
*/
export declare const snake: (x: string) => string;
/**
* Converts a kebab-case or snake_case string into CamelCase. Uses `-`
* as default delimiter.
*
* @param x
* @param delim
*/
export declare const camel: Stringer<string>;

@@ -21,1 +21,28 @@ "use strict";

exports.capitalize = (x) => x[0].toUpperCase() + x.substr(1);
/**
* Converts a CamelCase string into kebab case, with optional custom
* delimiter (`-` by default).
*
* ```
* kebab("FooBar23Baz");
* // "foo-bar23-baz"
* ```
*
* @param x
* @param delim
*/
exports.kebab = (x, delim = "-") => exports.lower(x.replace(/(?<=\w)(?=[A-Z])/g, delim));
/**
* Short for `kebab` using `_` as delimiter.
*
* @param x
*/
exports.snake = (x) => exports.kebab(x, "_");
/**
* Converts a kebab-case or snake_case string into CamelCase. Uses `-`
* as default delimiter.
*
* @param x
* @param delim
*/
exports.camel = (x, delim = "-") => exports.lower(x).replace(new RegExp(`\\${delim}+(\\w)`, "g"), (_, c) => exports.upper(c));
import { Stringer } from "./api";
/**
* @param n target length
* Returns stringer which pads given input with `ch` (default: space) on
* both sides and returns fixed width string of given `lineWidth`.
* Returns string of only pad characters for any `null` or `undefined`
* values. If the string version of an input is > `lineWidth`, no
* centering is performed, but the string will be truncated to
* `lineWidth`.
*
* Note: The padding string can contain multiple characters.
*
* ```
* center(20, "<>")(wrap(" ")("thi.ng"))
* // "<><><> thi.ng <><><>"
* ```
*
* @param lineWidth target length
* @param ch pad character(s)
*/
export declare const center: (n: number, ch?: string | number) => Stringer<any>;
export declare const center: (lineWidth: number, ch?: string | number) => Stringer<any>;

@@ -5,8 +5,23 @@ "use strict";

const repeat_1 = require("./repeat");
const truncate_1 = require("./truncate");
/**
* @param n target length
* Returns stringer which pads given input with `ch` (default: space) on
* both sides and returns fixed width string of given `lineWidth`.
* Returns string of only pad characters for any `null` or `undefined`
* values. If the string version of an input is > `lineWidth`, no
* centering is performed, but the string will be truncated to
* `lineWidth`.
*
* Note: The padding string can contain multiple characters.
*
* ```
* center(20, "<>")(wrap(" ")("thi.ng"))
* // "<><><> thi.ng <><><>"
* ```
*
* @param lineWidth target length
* @param ch pad character(s)
*/
exports.center = memoizej_1.memoizeJ((n, ch = " ") => {
const buf = repeat_1.repeat(ch, ((n + 1) & ~1) / 2);
const buf = repeat_1.repeat(ch, n);
return (x) => {

@@ -19,4 +34,4 @@ if (x == null)

buf.substr(0, r) + x + buf.substr(0, r + ((n & 1) === (x.length & 1) ? 0 : 1)) :
x;
truncate_1.truncate(n)(x);
};
});

@@ -6,2 +6,19 @@ # Change Log

<a name="0.3.0"></a>
# [0.3.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/strings@0.2.0...@thi.ng/strings@0.3.0) (2018-08-24)
### Bug Fixes
* **strings:** buffer length (for null inputs) (`center()`) ([5209c42](https://github.com/thi-ng/umbrella/commit/5209c42))
### Features
* **strings:** add case converters ([653a175](https://github.com/thi-ng/umbrella/commit/653a175))
* **strings:** add truncateLeft() & wrap() stringers ([1a20bc2](https://github.com/thi-ng/umbrella/commit/1a20bc2))
<a name="0.2.0"></a>

@@ -8,0 +25,0 @@ # [0.2.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/strings@0.1.1...@thi.ng/strings@0.2.0) (2018-08-08)

@@ -13,1 +13,3 @@ export * from "./api";

export * from "./truncate";
export * from "./truncate-left";
export * from "./wrap";

@@ -17,1 +17,3 @@ "use strict";

__export(require("./truncate"));
__export(require("./truncate-left"));
__export(require("./wrap"));
{
"name": "@thi.ng/strings",
"version": "0.2.0",
"version": "0.3.0",
"description": "Various string formatting & utility functions",

@@ -31,3 +31,3 @@ "main": "./index.js",

"dependencies": {
"@thi.ng/memoize": "^0.1.0"
"@thi.ng/memoize": "^0.1.1"
},

@@ -34,0 +34,0 @@ "keywords": [

@@ -11,6 +11,25 @@ import { Stringer } from "./api";

export declare const radix: (radix: number, len: number, prefix?: string) => Stringer<number>;
/**
* 8bit binary conversion preset.
*/
export declare const B8: Stringer<number>;
/**
* 8bit hex conversion preset.
* Assumes unsigned inputs.
*/
export declare const U8: Stringer<number>;
/**
* 16bit hex conversion preset.
* Assumes unsigned inputs.
*/
export declare const U16: Stringer<number>;
/**
* 32bit hex conversion preset.
* Assumes unsigned inputs.
*/
export declare const U32: Stringer<number>;
/**
* 64bit hex conversion preset (2x 32bit ints)
* Assumes unsigned inputs.
*/
export declare const U64: (hi: number, lo: number) => string;

@@ -20,6 +20,25 @@ "use strict";

});
/**
* 8bit binary conversion preset.
*/
exports.B8 = exports.radix(2, 8);
/**
* 8bit hex conversion preset.
* Assumes unsigned inputs.
*/
exports.U8 = exports.radix(16, 2);
/**
* 16bit hex conversion preset.
* Assumes unsigned inputs.
*/
exports.U16 = exports.radix(16, 4);
/**
* 32bit hex conversion preset.
* Assumes unsigned inputs.
*/
exports.U32 = exports.radix(16, 8);
/**
* 64bit hex conversion preset (2x 32bit ints)
* Assumes unsigned inputs.
*/
exports.U64 = (hi, lo) => exports.U32(hi) + exports.U32(lo);
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