
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
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 73 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
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.