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

@thi.ng/strings

Package Overview
Dependencies
Maintainers
1
Versions
196
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 1.0.3 to 1.0.4

8

center.js

@@ -29,6 +29,8 @@ import { memoizeJ } from "@thi.ng/memoize";

const r = (n - x.length) / 2;
return x.length < n ?
buf.substr(0, r) + x + buf.substr(0, r + ((n & 1) === (x.length & 1) ? 0 : 1)) :
truncate(n)(x);
return x.length < n
? buf.substr(0, r) +
x +
buf.substr(0, r + ((n & 1) === (x.length & 1) ? 0 : 1))
: truncate(n)(x);
};
});

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

## [1.0.4](https://github.com/thi-ng/umbrella/compare/@thi.ng/strings@1.0.3...@thi.ng/strings@1.0.4) (2019-03-01)
**Note:** Version bump only for package @thi.ng/strings
## [1.0.3](https://github.com/thi-ng/umbrella/compare/@thi.ng/strings@1.0.2...@thi.ng/strings@1.0.3) (2019-02-05)

@@ -8,0 +16,0 @@

@@ -29,18 +29,19 @@ import { memoizeJ } from "@thi.ng/memoize";

return pad(nanOrInf(x) ||
(x === 0 ?
"0" :
ax < pr || ax >= pl ?
exp(x, width) :
x.toFixed(prec - (x < pln ? 1 : 0))));
(x === 0
? "0"
: ax < pr || ax >= pl
? exp(x, width)
: x.toFixed(prec - (x < pln ? 1 : 0))));
};
});
const exp = (x, w) => x.toExponential(Math.max(w - 4 -
(Math.log(Math.abs(x)) / Math.LN10 >= 10 ? 2 : 1)
- (x < 0 ? 1 : 0), 0));
const nanOrInf = (x) => isNaN(x) ?
"NaN" :
x === Infinity ?
"+∞" :
x === -Infinity ?
"-∞" :
undefined;
const exp = (x, w) => x.toExponential(Math.max(w -
4 -
(Math.log(Math.abs(x)) / Math.LN10 >= 10 ? 2 : 1) -
(x < 0 ? 1 : 0), 0));
const nanOrInf = (x) => isNaN(x)
? "NaN"
: x === Infinity
? "+∞"
: x === -Infinity
? "-∞"
: undefined;

@@ -6,9 +6,5 @@ export const format = (fmt, ...args) => {

const t = typeof f;
acc.push(t === "function" ?
f(args[j++]) :
t === "object" ?
f[args[j++]] :
f);
acc.push(t === "function" ? f(args[j++]) : t === "object" ? f[args[j++]] : f);
}
return acc.join("");
};

@@ -18,5 +18,3 @@ 'use strict';

const truncate = memoize.memoizeJ((n, suffix = "") => (x) => x.length > n ?
x.substr(0, n - suffix.length) + suffix :
x);
const truncate = memoize.memoizeJ((n, suffix = "") => (x) => x.length > n ? x.substr(0, n - suffix.length) + suffix : x);

@@ -30,5 +28,7 @@ const center = memoize.memoizeJ((n, pad = " ") => {

const r = (n - x.length) / 2;
return x.length < n ?
buf.substr(0, r) + x + buf.substr(0, r + ((n & 1) === (x.length & 1) ? 0 : 1)) :
truncate(n)(x);
return x.length < n
? buf.substr(0, r) +
x +
buf.substr(0, r + ((n & 1) === (x.length & 1) ? 0 : 1))
: truncate(n)(x);
};

@@ -39,5 +39,5 @@ });

const buf = repeat(ch, n);
return (x) => x != null ?
(x = x.toString(), x.length < n ? buf.substr(x.length) + x : x) :
buf;
return (x) => x != null
? ((x = x.toString()), x.length < n ? buf.substr(x.length) + x : x)
: buf;
});

@@ -55,19 +55,20 @@

return pad(nanOrInf(x) ||
(x === 0 ?
"0" :
ax < pr || ax >= pl ?
exp(x, width) :
x.toFixed(prec - (x < pln ? 1 : 0))));
(x === 0
? "0"
: ax < pr || ax >= pl
? exp(x, width)
: x.toFixed(prec - (x < pln ? 1 : 0))));
};
});
const exp = (x, w) => x.toExponential(Math.max(w - 4 -
(Math.log(Math.abs(x)) / Math.LN10 >= 10 ? 2 : 1)
- (x < 0 ? 1 : 0), 0));
const nanOrInf = (x) => isNaN(x) ?
"NaN" :
x === Infinity ?
"+∞" :
x === -Infinity ?
"-∞" :
undefined;
const exp = (x, w) => x.toExponential(Math.max(w -
4 -
(Math.log(Math.abs(x)) / Math.LN10 >= 10 ? 2 : 1) -
(x < 0 ? 1 : 0), 0));
const nanOrInf = (x) => isNaN(x)
? "NaN"
: x === Infinity
? "+∞"
: x === -Infinity
? "-∞"
: undefined;

@@ -79,7 +80,3 @@ const format = (fmt, ...args) => {

const t = typeof f;
acc.push(t === "function" ?
f(args[j++]) :
t === "object" ?
f[args[j++]] :
f);
acc.push(t === "function" ? f(args[j++]) : t === "object" ? f[args[j++]] : f);
}

@@ -91,5 +88,5 @@ return acc.join("");

const buf = repeat(ch, n);
return (x) => x != null ?
(x = x.toString(), x.length < n ? x + buf.substr(x.length) : x) :
buf;
return (x) => x != null
? ((x = x.toString()), x.length < n ? x + buf.substr(x.length) : x)
: buf;
});

@@ -129,3 +126,3 @@

.replace(/\s+/g, "-")
.replace(re, c => dest[src.indexOf(c)])
.replace(re, (c) => dest[src.indexOf(c)])
.replace(/&+/g, "-and-")

@@ -149,15 +146,14 @@ .replace(/[^\w\-]+/g, "")

to = Math.max(to, 0);
return from <= 0 ?
insert + src.substr(to) :
from >= src.length ?
src + insert :
src.substr(0, from) + insert + src.substr(to);
return from <= 0
? insert + src.substr(to)
: from >= src.length
? src + insert
: src.substr(0, from) + insert + src.substr(to);
};
const truncateLeft = memoize.memoizeJ((n, prefix = "") => (x) => x.length > n ?
prefix + x.substr(x.length - n + prefix.length) :
x);
const truncateLeft = memoize.memoizeJ((n, prefix = "") => (x) => x.length > n ? prefix + x.substr(x.length - n + prefix.length) : x);
const units = memoize.memoizeJ((exp, base, prec = 2) => {
const groups = exp.map((x) => [x[0], x[2] != null ? x[2] : prec, x[1]])
const groups = exp
.map((x) => [x[0], x[2] != null ? x[2] : prec, x[1]])
.sort((a, b) => a[0] - b[0]);

@@ -179,8 +175,3 @@ return (x) => {

const MB = 1024 * 1024;
const bits = units([
[1, " bits", 0],
[KB, " Kb"],
[MB, " Mb"],
[KB * MB, " Gb"],
], " bits", 2);
const bits = units([[1, " bits", 0], [KB, " Kb"], [MB, " Mb"], [KB * MB, " Gb"]], " bits", 2);
const bytes = units([

@@ -192,3 +183,3 @@ [1, " bytes", 0],

[MB * MB, " TB"],
[KB * MB * MB, " PB"],
[KB * MB * MB, " PB"]
], " bytes", 2);

@@ -203,3 +194,3 @@ const seconds = units([

[60 * 60, " hours"],
[24 * 60 * 60, " days"],
[24 * 60 * 60, " days"]
], " secs", 3);

@@ -213,3 +204,3 @@ const meters = units([

[1, " m"],
[1e3, " km"],
[1e3, " km"]
], " m", 2);

@@ -225,3 +216,3 @@ const grams = units([

[1e9, " kt"],
[1e12, " Mt"],
[1e12, " Mt"]
], " g", 2);

@@ -228,0 +219,0 @@

@@ -17,5 +17,3 @@ (function (global, factory) {

const truncate = memoize.memoizeJ((n, suffix = "") => (x) => x.length > n ?
x.substr(0, n - suffix.length) + suffix :
x);
const truncate = memoize.memoizeJ((n, suffix = "") => (x) => x.length > n ? x.substr(0, n - suffix.length) + suffix : x);

@@ -29,5 +27,7 @@ const center = memoize.memoizeJ((n, pad = " ") => {

const r = (n - x.length) / 2;
return x.length < n ?
buf.substr(0, r) + x + buf.substr(0, r + ((n & 1) === (x.length & 1) ? 0 : 1)) :
truncate(n)(x);
return x.length < n
? buf.substr(0, r) +
x +
buf.substr(0, r + ((n & 1) === (x.length & 1) ? 0 : 1))
: truncate(n)(x);
};

@@ -38,5 +38,5 @@ });

const buf = repeat(ch, n);
return (x) => x != null ?
(x = x.toString(), x.length < n ? buf.substr(x.length) + x : x) :
buf;
return (x) => x != null
? ((x = x.toString()), x.length < n ? buf.substr(x.length) + x : x)
: buf;
});

@@ -54,19 +54,20 @@

return pad(nanOrInf(x) ||
(x === 0 ?
"0" :
ax < pr || ax >= pl ?
exp(x, width) :
x.toFixed(prec - (x < pln ? 1 : 0))));
(x === 0
? "0"
: ax < pr || ax >= pl
? exp(x, width)
: x.toFixed(prec - (x < pln ? 1 : 0))));
};
});
const exp = (x, w) => x.toExponential(Math.max(w - 4 -
(Math.log(Math.abs(x)) / Math.LN10 >= 10 ? 2 : 1)
- (x < 0 ? 1 : 0), 0));
const nanOrInf = (x) => isNaN(x) ?
"NaN" :
x === Infinity ?
"+∞" :
x === -Infinity ?
"-∞" :
undefined;
const exp = (x, w) => x.toExponential(Math.max(w -
4 -
(Math.log(Math.abs(x)) / Math.LN10 >= 10 ? 2 : 1) -
(x < 0 ? 1 : 0), 0));
const nanOrInf = (x) => isNaN(x)
? "NaN"
: x === Infinity
? "+∞"
: x === -Infinity
? "-∞"
: undefined;

@@ -78,7 +79,3 @@ const format = (fmt, ...args) => {

const t = typeof f;
acc.push(t === "function" ?
f(args[j++]) :
t === "object" ?
f[args[j++]] :
f);
acc.push(t === "function" ? f(args[j++]) : t === "object" ? f[args[j++]] : f);
}

@@ -90,5 +87,5 @@ return acc.join("");

const buf = repeat(ch, n);
return (x) => x != null ?
(x = x.toString(), x.length < n ? x + buf.substr(x.length) : x) :
buf;
return (x) => x != null
? ((x = x.toString()), x.length < n ? x + buf.substr(x.length) : x)
: buf;
});

@@ -128,3 +125,3 @@

.replace(/\s+/g, "-")
.replace(re, c => dest[src.indexOf(c)])
.replace(re, (c) => dest[src.indexOf(c)])
.replace(/&+/g, "-and-")

@@ -148,15 +145,14 @@ .replace(/[^\w\-]+/g, "")

to = Math.max(to, 0);
return from <= 0 ?
insert + src.substr(to) :
from >= src.length ?
src + insert :
src.substr(0, from) + insert + src.substr(to);
return from <= 0
? insert + src.substr(to)
: from >= src.length
? src + insert
: src.substr(0, from) + insert + src.substr(to);
};
const truncateLeft = memoize.memoizeJ((n, prefix = "") => (x) => x.length > n ?
prefix + x.substr(x.length - n + prefix.length) :
x);
const truncateLeft = memoize.memoizeJ((n, prefix = "") => (x) => x.length > n ? prefix + x.substr(x.length - n + prefix.length) : x);
const units = memoize.memoizeJ((exp, base, prec = 2) => {
const groups = exp.map((x) => [x[0], x[2] != null ? x[2] : prec, x[1]])
const groups = exp
.map((x) => [x[0], x[2] != null ? x[2] : prec, x[1]])
.sort((a, b) => a[0] - b[0]);

@@ -178,8 +174,3 @@ return (x) => {

const MB = 1024 * 1024;
const bits = units([
[1, " bits", 0],
[KB, " Kb"],
[MB, " Mb"],
[KB * MB, " Gb"],
], " bits", 2);
const bits = units([[1, " bits", 0], [KB, " Kb"], [MB, " Mb"], [KB * MB, " Gb"]], " bits", 2);
const bytes = units([

@@ -191,3 +182,3 @@ [1, " bytes", 0],

[MB * MB, " TB"],
[KB * MB * MB, " PB"],
[KB * MB * MB, " PB"]
], " bytes", 2);

@@ -202,3 +193,3 @@ const seconds = units([

[60 * 60, " hours"],
[24 * 60 * 60, " days"],
[24 * 60 * 60, " days"]
], " secs", 3);

@@ -212,3 +203,3 @@ const meters = units([

[1, " m"],
[1e3, " km"],
[1e3, " km"]
], " m", 2);

@@ -224,3 +215,3 @@ const grams = units([

[1e9, " kt"],
[1e12, " Mt"],
[1e12, " Mt"]
], " g", 2);

@@ -227,0 +218,0 @@

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

@@ -35,4 +35,4 @@ "module": "./index.js",

"dependencies": {
"@thi.ng/errors": "^1.0.2",
"@thi.ng/memoize": "^1.0.2"
"@thi.ng/errors": "^1.0.3",
"@thi.ng/memoize": "^1.0.3"
},

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

"sideEffects": false,
"gitHead": "74fb4d83013785ce7a95357c565426a046657e74"
"gitHead": "e43f57c7554fd78380bba58d37ae62ca01221eeb"
}

@@ -9,5 +9,5 @@ import { memoizeJ } from "@thi.ng/memoize";

const buf = repeat(ch, n);
return (x) => x != null ?
(x = x.toString(), x.length < n ? buf.substr(x.length) + x : x) :
buf;
return (x) => x != null
? ((x = x.toString()), x.length < n ? buf.substr(x.length) + x : x)
: buf;
});

@@ -9,5 +9,5 @@ import { memoizeJ } from "@thi.ng/memoize";

const buf = repeat(ch, n);
return (x) => x != null ?
(x = x.toString(), x.length < n ? x + buf.substr(x.length) : x) :
buf;
return (x) => x != null
? ((x = x.toString()), x.length < n ? x + buf.substr(x.length) : x)
: buf;
});

@@ -14,3 +14,3 @@ const src = "àáäâãåèéëêìíïîòóöôùúüûñçßÿœæŕśńṕẃǵǹḿǘẍźḧ·/_,:;";

.replace(/\s+/g, "-")
.replace(re, c => dest[src.indexOf(c)])
.replace(re, (c) => dest[src.indexOf(c)])
.replace(/&+/g, "-and-")

@@ -17,0 +17,0 @@ .replace(/[^\w\-]+/g, "")

@@ -26,7 +26,7 @@ import { illegalArgs } from "@thi.ng/errors";

to = Math.max(to, 0);
return from <= 0 ?
insert + src.substr(to) :
from >= src.length ?
src + insert :
src.substr(0, from) + insert + src.substr(to);
return from <= 0
? insert + src.substr(to)
: from >= src.length
? src + insert
: src.substr(0, from) + insert + src.substr(to);
};
import { memoizeJ } from "@thi.ng/memoize";
export const truncateLeft = memoizeJ((n, prefix = "") => (x) => x.length > n ?
prefix + x.substr(x.length - n + prefix.length) :
x);
export const truncateLeft = memoizeJ((n, prefix = "") => (x) => x.length > n ? prefix + x.substr(x.length - n + prefix.length) : x);
import { memoizeJ } from "@thi.ng/memoize";
export const truncate = memoizeJ((n, suffix = "") => (x) => x.length > n ?
x.substr(0, n - suffix.length) + suffix :
x);
export const truncate = memoizeJ((n, suffix = "") => (x) => x.length > n ? x.substr(0, n - suffix.length) + suffix : x);
import { memoizeJ } from "@thi.ng/memoize";
export const units = memoizeJ((exp, base, prec = 2) => {
const groups = exp.map((x) => [x[0], x[2] != null ? x[2] : prec, x[1]])
const groups = exp
.map((x) => [x[0], x[2] != null ? x[2] : prec, x[1]])
.sort((a, b) => a[0] - b[0]);

@@ -20,8 +21,3 @@ return (x) => {

const MB = 1024 * 1024;
export const bits = units([
[1, " bits", 0],
[KB, " Kb"],
[MB, " Mb"],
[KB * MB, " Gb"],
], " bits", 2);
export const bits = units([[1, " bits", 0], [KB, " Kb"], [MB, " Mb"], [KB * MB, " Gb"]], " bits", 2);
export const bytes = units([

@@ -33,3 +29,3 @@ [1, " bytes", 0],

[MB * MB, " TB"],
[KB * MB * MB, " PB"],
[KB * MB * MB, " PB"]
], " bytes", 2);

@@ -44,3 +40,3 @@ export const seconds = units([

[60 * 60, " hours"],
[24 * 60 * 60, " days"],
[24 * 60 * 60, " days"]
], " secs", 3);

@@ -54,3 +50,3 @@ export const meters = units([

[1, " m"],
[1e3, " km"],
[1e3, " km"]
], " m", 2);

@@ -66,3 +62,3 @@ export const grams = units([

[1e9, " kt"],
[1e12, " Mt"],
[1e12, " Mt"]
], " g", 2);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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