supercharge / strings Goto Github PK
View Code? Open in Web Editor NEWString utilities for Node.js
Home Page: https://superchargejs.com/docs/strings
License: MIT License
String utilities for Node.js
Home Page: https://superchargejs.com/docs/strings
License: MIT License
Add a new .prepend(...values)
method that prepends the given values onto the string:
Example
Str('awesome').prepend('Supercharge ', 'is ').get()
// 'Supercharge is awesome'
Add a new .beforeLast(delimiter)
method that returns everything from the string before the last occurrence of the given delimiter
. This method returns the entire string if the delimiter doesn’t exist in the string.
Example
Str('Supercharge-is-awesome').beforeLast('-').get()
// 'Supercharge-is'
Add a new .padLeft(length, pad)
method that pads the current string with another string (multiple times, if needed) until the resulting string reaches the given length
. The padding is applied from the start of the current string.
Example
Str('Marcus').padLeft(10, '.').get()
// '....Marcus'
Is there a way to limit a string by the number of words? I tried a few ways to get at it.
Str("To be or not to be").words().limit(3).get()
I'm doing it right now with:
Str(text).words().slice(0,5).join(" ") + "...
The str.concat(addon)
method appends the given addon
to the string.
Example
const str = Str('Supercharge').concat('is awesome').get()
// 'Supercharge is awesome'
Hey! What about adding a new method to check whether a given string is written in CamelCase or not? This should work with a simple Regex like: /^[a-z]+([A-Z][a-z]+)+$/g
.
Examples:
Str("helloWorld").isCamelCase() // true
Str("helloWOrld").isCamelCase() // false
Str("hello").isCamelCase() // false
Str("hellO").isCamelCase() // false
Str("Hello").isCamelCase() // false
If that's okay I would like to submit a PR :)
Add a new .append(...values)
method that appends the given values to the string:
Example
Str('Supercharge').append(' is', ' awesome').get()
// 'Supercharge is awesome'
The str.trimStart()
method removes all whitespace at the beginning of a string.
Example
Str(' Supercharge ').trimStart().get()
// 'Supercharge '
I want to propose to add new methods: kebab()
, snake()
, pascal()
Example
Str('Supercharge kebab case').kebab().get()
// 'supercharge-kebab-case'
Str('Supercharge snake case').snake().get()
// 'supercharge_snake_case'
Str('Supercharge pascal case').pascal().get()
// 'SuperchargePascalCase'
Add a new .afterLast(delimiter)
method that returns everything from the string after the last occurrence of the given delimiter
. This method returns the entire string if the delimiter doesn’t exist in the string.
Example
Str('Supercharge-is-awesome').afterLast('-').get()
// 'awesome'
Add a new .padRight(length, pad)
method that pads the current string with a given string (repeated, if needed) so that the resulting string reaches a given length. The padding is applied from the end of the current string.
Example
Str('Marcus').padRight(10, '.').get()
// 'Marcus....'
Add a new .finish(suffix)
method that adds a single instance of the given suffix
value to the end of the string if it doesn’t already ends with the given suffix
.
Example
Str('https://github.com').finish('/').get()
// 'https://github.com/'
Str('https://github.com/').finish('/').get()
// 'https://github.com/'
Implement an at
method that returns the character at a given index
.
proposal for an
at` methodmethod-at
branch (contains tests)The str.endsWith(needle)
method determines whether a string ends with the given needle
.
Example
Str('Supercharge is awesome').endsWith('some')
// true
Str('Supercharge is awesome').endsWith('Super')
// false
Implement a static isSymbol
method that returns true if the given value is a JavaScript Symbol
. Returns false otherwise.
method-is-symbol
branch (contains tests and extended interfaces)Hello, I think a useful method to add would be one that checks for equality while ignoring the character cases. This would be called something like equalsIgnoreCase
Some examples:
Str('SUPERCHARGE').equalsIgnoreCase('supercharge') //true
Str('SuPeRcHaRgE').equalsIgnoreCase('sUpErChArGe') //true
Str('SUPERCHARGE').equalsIgnoreCase('SLOWCHARGE') //false
Str('SuPeR').equalsIgnoreCase('sUpErChArGe') //false
If this sounds good I'd love to create a PR
The str.limit(limit, end = '…')
method returns the first limit
characters and ends the limited string with end
.
Example
Str('Supercharge').limit(5, ' ->').get()
// 'Super ->'
The str.substr(start, length)
method returns the substring of length length
starting from position start
.
Example
Str('Supercharge').substr(0, 5).get()
// 'Super'
Implement an isUuid
method that returns true if the wrapped string value is a valid UUID. Returns false otherwise
validate
function. You may reuse the available helper functionmethod-is-uuid
branch (contains tests)The str.ucFirst()
method uppercases the first character of the string.
Example
Str('superCHARGE').ucFirst().get()
// 'SuperCHARGE'
import Str from '@supercharge/strings';
Str('thisIsInCamelCase').pascal().get(); // returns 'Thisisincamelcase'. It should be 'ThisIsInCamelCase'
I am using random function to generate a token as shown in the code below
const Str=require('@supercharge/strings); const token = Str.random(50);
but its giving me the error
TypeError: Str.random is not a function
The same code was working when i used it some months before.
Is random function is removed ?
Could you please explain why you used an || statement with empty quotes in the constructor? Couldn't you just "slice" it?
Line 17 in 6abd687
The str.trimEnd()
method removes all whitespace at the end of a string.
Example
Str(' Supercharge ').trimEnd().get()
// ' Supercharge'
The str.startsWith(needle)
method determines whether a string starts with the given needle
.
Example
Str('Supercharge').startsWith('Super')
// true
Str('Supercharge').startsWith('super')
// false
The search method returns the position of the first occurrence of a specified text in a string
@marcuspoehls can you assign this to me and add label as hactoberfest
.
The str.split(separator)
splits the string at the given separator
and returns an array of all separated strings.
Example
Str('Supercharge-is-awesome!').split('-')
// [ 'Supercharge', 'is', 'awesome!' ]
Add a new .replace(search, replace)
method that replaces the first occurrence of the given search
value with the replacing value
.
Example
Str('Supercharge is nice').replace('nice', 'sweet').get()
// 'Supercharge is sweet'
Add a new .start(prefix)
method that prepends a single instance of the given prefix
value to the start of the string if it doesn’t already start with the given prefix
.
Example
Str('repos/supercharge').start('/').get()
// '/repos/supercharge'
Str('/repos/supercharge').start('/').get()
// '/repos/supercharge'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.