![New axobject-query Maintainer Faces Backlash Over Controversial Decision to Support Legacy Node.js Versions](https://cdn.sanity.io/images/cgdhsj6q/production/86e6ebdea652d20da070ebbda20134b839972db7-1024x1024.webp?w=800&fit=max&auto=format)
Security News
New axobject-query Maintainer Faces Backlash Over Controversial Decision to Support Legacy Node.js Versions
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.
strings
Advanced tools
Readme
Easily replace and transform :props in strings.
Strings is the result of many hours on screenhero and a truly collaborative effort between Brian Woodward and Jon Schlinkert.
Please report any bugs or feature requests, thanks!
Install with npm:
npm i strings --save
bower install strings --save
Main Strings concepts:
A prop-string, or propstring
, is a sort of template with one or more delimiters denoting the strings that will replaced with actual values.
Example prop-string:
:a/:b/:c
The data that will be used to replace properties in the prop-strings.
Example context:
{
a: 'aaa',
b: 'bbb',
c: 'ccc'
}
If used to replace the prop-strings in the previous section, the result would be:
aaa/bbb/ccc
By default, Strings will parse and replace the values in the previous examples with no problem. Parsers are used to tell Strings how to process patterns that it can't natively.
Example:
// replace all occurrences of `a` with `b`
strings.parser('a', {pattern: /a/g, replacement: 'b'});
Initialize a new Strings
object.
var strings = new Strings();
Optionally pass a default context to use:
var strings = new Strings({dirname: 'foo/bar'});
An example use case is dynamically generating dest filepaths from source filepaths, in which case you might have "constants" that shouldn't change regardless of the filepath. like destBase
or cwd
etc.
Store a named prop-string:
strings.propstring('foo', ':alpha/:beta/:gamma');
Define a named parser to be used against any given prop-string.
Params:
name
(String
): the name of the parserreplacements
(object|array
): the replacement patterns to use, this is the logic for the parser. Replacement patterns consist of the following properties:
pattern
(regex|string
): the pattern to be replacedreplacement
(string|function
): the actual replacement to use. This is a string value or function used to replace or tranform the prop-strings. Also, in replacement functions this
is the given context.Example:
strings.parser('foo', {
pattern: /a/g, // find all occurences of `a`
replacement: 'b' // and replace them with `b`
});
Or using a function:
strings.parser('foo', {
pattern: /a/g, // find all occurences of `a`
replacement: function(match) {
// and replace them with uppercase `A`
return match.toUpperCase();
}
});
strings.template('{foo}/{bar}/{baz}/index.html', ['path'], context);
strings.template('{{foo}}/{{bar}}/{{baz}}/index.html', ['path'], context);
strings.template(':foo/:bar/:baz/index.html', ['path'], context);
strings.template(':foo/:bar/:baz/index.html', [{
pattern: ':dirname',
replacement: function () {
return path.dirname(this.filepath);
}
}], context);
Process the named propstring using a named collection of replacement patterns, and a context.
Params:
propstring
{String}: Named template used for building the final stringname
{String}: Name of replacement group to use for building the final stringcontext
{Object}: Optional Object to bind to replacment function as this
strings.process('foo', 'a', context);
// or
strings.process('foo', ['a', 'b']);
Store a named group of propstring/parser mappings.
Params:
name
{String} the name of the group to storepropstring
{String}: the propstring to useparsers
{String|Array}: name or array of names of parsers to use.strings.group('mapA', 'foo', ['a', 'b', 'c']);
strings.group('mapB', 'foo', ['d', 'e', 'slugify']);
Run the named group using the given context.
group
{String}: The name of the group to usecontext
{Object}: Optional Object to bind to replacment function as this
strings.run('group-foo', context);
Brian Woodward
Jon Schlinkert
Copyright (c) 2014 Brian Woodward, contributors.
Released under the MIT license
This file was generated by verb-cli on May 21, 2014.
FAQs
Easily replace and transform :props in strings.
The npm package strings receives a total of 293 weekly downloads. As such, strings popularity was classified as not popular.
We found that strings demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.
Security News
Results from the 2023 State of JavaScript Survey highlight key trends, including Vite's dominance, rising TypeScript adoption, and the enduring popularity of React. Discover more insights on developer preferences and technology usage.
Security News
The US Justice Department has penalized two consulting firms $11.3 million for failing to meet cybersecurity requirements on federally funded projects, emphasizing strict enforcement to protect sensitive government data.