Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Extract/interpolate strings.
##Usage
###Node.js and Browserify
Install from npm
npm install extractjs
var extractjs = require('extractjs'),
extractor = extractjs();
var captured = extractor("This is a {name} library",
"This is a extractjs library");
// > { name: 'extractjs'}
var defaults = {
startExtract: '{',
endExtract: '}',
extractors: { /* capture functions */ }
initValue: void 0
}
Templates can be redefined as below:
var extractjs = require('extractjs'),
settings = { startExtract: '[[', endExtract: ']]'}
extractor = extractjs(settings);
var captured = extractor("This is [[name]], [[age]] years old",
"This is John, 26 years old");
// > { name: 'John', age: 26 } <-- age is no longer string
// Settings can be overridden at the time of extraction
var date = extractor("Date is |date|/|month|/|year|", "Date is 26/04/2015",
{ startExtract: '|', endExtract: '|'})
// > { date: 26, month: 4, year: 2015 }
Its possible to build a pattern before extract/interpolate data.
var extractjs = require('extractjs'),
extractor = extractjs();
var loginPattern = extractor("You are logged in as {name}.");
var name = loginPattern.extract('You are logged in as John. Last login: Today')
.name;
// > John
var output = loginPattern.interpolate({name: 'John'});
//> You are loggin in as John.
extractors are used to override or manipulate captured values.
var extractjs = require('extractjs'),
settings = {
extractors: {
name: function(value) {
var names = value.split(' ');
return {
firstName: names[0],
lastName: value.substring(names[0].length).trim(),
fullName: value
};
}
}
},
extractor = extractjs(settings);
var captured = extractor("This is {name}, {age} years old",
"This is John Wesley, 26 years old");
// > { name: {
// firstName: 'John',
// lastName: 'Wesley',
// fullName: 'John Wesley'
// }, age: 26 }
###Web page Access from window/global as extractjs.
This plugin is licensed under the MIT license.
Copyright (c) 2015 Prince John Wesley
FAQs
Extract/interpolate string
The npm package extractjs receives a total of 195 weekly downloads. As such, extractjs popularity was classified as not popular.
We found that extractjs 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.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.