
Research
Security News
Malicious PyPI Package Exploits Deezer API for Coordinated Music Piracy
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
A really small, zero-dependency, unicode-aware library for working with Strings in Node.js.
Javascript has a serious problem with unicode. Even ES6 can’t solve the problem entirely since some characters like the
new colored emojis are three bytes instead of two bytes. Sometimes even more! "👍🏽".length
returns 4
which is totally
wrong (hint: it should be 1!). ES6's Array.from
tried to solve this, but that even fails: Array.from("👍🏽")
returns
["👍", "🏽"]
which is incorrect. This library tries to tackle all these problems with a mega RegExp.
Read More Here.
🎈 Based on a RegExp copied from the Lodash library.
🔥 Please note that this library is built for accuracy, not performance. It uses complex regular expressions to
calculate the string length and perform other operations which are not particularly super-jawdropping-fast like
the native String.prototype.length
.
$ npm install stringz --save
And import it in your awesome node app:
// ES2015+
import * as stringz from 'stringz'; // OR:
import { limit, substring, length } from 'stringz';
// CommonJS
var stringz = require('stringz');
// use like: stringz.limit ...
function limit(str[, limit[, padStr[, padPosition]]])
Param | Type | Default | Description |
---|---|---|---|
str | String | none | The string to be limited |
limit | Number | 16 | Desired string length |
padStr | String | "#" | Character to pad the output with |
padPosition | String | "right" | Pad position: "right" or "left" |
// Truncate:
limit("Life’s like a box of chocolates.", 20); // "Life's like a box of"
// Pad:
limit("Make emojis great again", 26, "💩"); // "Make emojis great again💩💩💩"
limit("What are you looking at?", 30, "+", "left"); // "++++++What are you looking at?"
// Unicode Aware:
limit("🤔🤔🤔", 2); // "🤔🤔"
limit("👍🏽👍🏽", 4, "👍🏽"); // "👍🏽👍🏽👍🏽👍🏽"
function length(str)
Param | Type | Default | Description |
---|---|---|---|
str | String | none | String to return the length for |
length("Iñtërnâtiônàlizætiøn☃💩"); // 22
function substring(str, start[, end])
Param | Type | Default | Description |
---|---|---|---|
str | String | none | String to be devided |
start | Number | none | Start position |
end | Number | End of string | End position |
substring("Emojis 👍🏽 are 🍆 poison. 🌮s are bad.", 7, 14); // "👍🏽 are 🍆"
$ npm test
Version | Date | Notes |
---|---|---|
0.1.2 | 2017-04-25 | Fix null length issue #8 |
0.1.1 | 2016-07-31 | More strict type checking, more tests |
0.1.0 | 2016-07-29 | Renamed to Stringz, more tools |
0.0.10 | 2016-07-29 | Fixed substring issue |
0.0.9 | 2016-07-28 | Fixed unicode string length issue |
0.0.8 | 2016-07-26 | First usable release |
This software is released under the MIT License.
Uses a RegExp from the Lodash which is released under the MIT License.
FAQs
Zero-dependency unicode-aware string tools
The npm package stringz receives a total of 267,621 weekly downloads. As such, stringz popularity was classified as popular.
We found that stringz demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.
Security News
Newly introduced telemetry in devenv 1.4 sparked a backlash over privacy concerns, leading to the removal of its AI-powered feature after strong community pushback.