Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@arcanis/slice-ansi
Advanced tools
@arcanis/slice-ansi is an npm package designed to handle ANSI escape codes in strings, allowing you to slice strings containing these codes without breaking the formatting.
Slicing ANSI strings
This feature allows you to slice a string containing ANSI escape codes without breaking the formatting. In this example, the string 'Hello World' is sliced to 'Hello' while preserving the red color formatting.
const sliceAnsi = require('@arcanis/slice-ansi');
const input = '\u001b[31mHello\u001b[39m World';
const output = sliceAnsi(input, 0, 5);
console.log(output); // '\u001b[31mHello\u001b[39m'
Handling multi-byte characters
This feature ensures that multi-byte characters are handled correctly when slicing. In this example, the Chinese characters '你好,世界' are sliced to '你好' while preserving the red color formatting.
const sliceAnsi = require('@arcanis/slice-ansi');
const input = '\u001b[31m你好,世界\u001b[39m';
const output = sliceAnsi(input, 0, 2);
console.log(output); // '\u001b[31m你好\u001b[39m'
The 'slice-ansi' package provides similar functionality to '@arcanis/slice-ansi' by allowing you to slice strings containing ANSI escape codes without breaking the formatting. It is a well-maintained and widely used package in the community.
The 'string-width' package calculates the visual width of a string, taking into account ANSI escape codes and wide characters. While it does not provide slicing functionality, it can be used in conjunction with slicing packages to handle string widths accurately.
The 'strip-ansi' package removes ANSI escape codes from strings. While it does not provide slicing functionality, it can be useful for cleaning up strings before or after slicing operations.
@arcanis/slice-ansi
Slice strings while preserving ansi characters
yarn add @arcanis/slice-ansi
Unlike the Chalk version, this completely different implementation:
This implementation also doesn't attempt to interpret the escape codes to optimize them away. So for instance, if you start with the following but only want to keep the first 16 characters:
${openBold}This is the header with ${openRed}ansi words${closeRed}${closeBold}
The end result will be:
${openBold}This is the head${openRed}${closeRed}${closeBold}
As you can see, the ${openRed}${closeRed}
didn't get removed, even if they are now empty. This is because this package doesn't know that openRed
(\u001b[31m
) is "closed" by closeRed
(\u001b[39m
). Keeping these information would make the package more complex for a benefit deemed fairly limited, since nothing will be printed anyway.
Copyright © 2020 Mael Nison
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Unknown package
The npm package @arcanis/slice-ansi receives a total of 195,140 weekly downloads. As such, @arcanis/slice-ansi popularity was classified as popular.
We found that @arcanis/slice-ansi demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.