Comments (4)
Prune doesn't allow having non-word characters (like punctuation characters) after the last word. This increases the readability of the truncated phrase.
For example, this is better in sense of truncation:
v.prune('Good day. Little Red Riding Hood', 16, '...');
// => 'Good day...'
Compared to:
v.prune('Good day. Little Red Riding Hood', 16, '...');
// => 'Good day. ...'
from voca.
thanks @panzerdp for the quick answer, really appreciated; my point is that this is not always the case as this is what's happening now:
expect(v.prune('YATTA,', 6, '')).toEqual('YATTA,');
expect(v.prune('YATTA, ', 6, '')).toEqual('YATTA');
the 1st string w/o a final empty space returns the comma, the second one w/ space doesn't; using your example:
expect(v.prune('Good day. Little Red Riding Hood,', 12, '')).toEqual(
'Good day'
);
expect(v.prune('Good day. Little Red Riding Hood,', 33, '')).toEqual(
'Good day. Little Red Riding Hood,'
);
the 1st string does not return the punctuation.
thanks again,
-Mattia
from voca.
Prune is applied (including the removal of non-word chars) only when the string length is bigger than prune length. Otherwise the string is not modified, because there's nothing to remove.
from voca.
oh I see @panzerdp although I still think that
v.prune('YATTA, ', 6, '')
should return
YATTA,
w/ the comma
and not
YATTA
from voca.
Related Issues (20)
- Individual function cannot be imported with ESM imports HOT 3
- I made a demo page for Voca HOT 1
- rsplit would be nice HOT 1
- Title Case feature is wrong HOT 1
- Voca doesn't handle complex characters like కృష్ణ HOT 4
- Support for converting possible boolean strings to actual boolean values HOT 1
- No publishing updates on NPM/Yarn? HOT 1
- Title Abbreviations
- Voca's title case function is capitalizing some words it shouldn't HOT 1
- Default regex for words treats numbers as individual words HOT 2
- [Feature Request] Add Sentence case
- nanDefault - maybe a mistake?
- Error in function getGlobalObject in ./node_modules/voca/index.js:3595
- Reverse camelcase? HOT 1
- Optimization Interests?
- Any plans to handle encodings? HOT 1
- keepAfter, keepBefore, keepBetween, keepChars
- Change required for v1.4.1
- Sanitize logic
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from voca.