Comparing version 2.0.0 to 3.0.0
@@ -0,2 +1,23 @@ | ||
export declare type DelimiterType = [string, string]; | ||
/** | ||
* Get all tokens from the string. In this case, only identifiers between | ||
* delimiters. This function doesn't replace identifiers, just returns an | ||
* array with the identifiers name. | ||
* | ||
* @param {string} templateString | ||
* @param {[string,string]|undefined} delimiters | ||
* @returns {string[]} | ||
*/ | ||
export declare const getTokens: (templateString: string, delimiters?: DelimiterType) => string[]; | ||
/** | ||
* Count tokens is a function built on top getTokens. It is just a wrapper | ||
* that pretends to be more concise. Under the hood, this funtion executes | ||
* the parser only one time. | ||
* | ||
* @param {string} templateString | ||
* @param {[string,string]|undefined} delimiters | ||
* @returns {number} | ||
*/ | ||
export declare const countTokens: (templateString: string, delimiters?: DelimiterType) => number; | ||
/** | ||
* Renders a string template and returns it with all variables replaced | ||
@@ -3,0 +24,0 @@ * in the string. |
@@ -6,8 +6,39 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/* eslint-disable @typescript-eslint/no-unsafe-call */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-return */ | ||
/* eslint-disable @typescript-eslint/restrict-plus-operands */ | ||
/* eslint-disable @typescript-eslint/prefer-for-of */ | ||
exports.countTokens = exports.getTokens = void 0; | ||
var escape_string_regexp_1 = __importDefault(require("escape-string-regexp")); | ||
/** | ||
* Get all tokens from the string. In this case, only identifiers between | ||
* delimiters. This function doesn't replace identifiers, just returns an | ||
* array with the identifiers name. | ||
* | ||
* @param {string} templateString | ||
* @param {[string,string]|undefined} delimiters | ||
* @returns {string[]} | ||
*/ | ||
var getTokens = function (templateString, delimiters) { | ||
if (delimiters === void 0) { delimiters = ['{{', '}}']; } | ||
var d = delimiters.map(function (delimiter) { return (0, escape_string_regexp_1.default)(delimiter); }); | ||
var extractVarPattern = new RegExp(d[0] + '\\s*([A-Za-z0-9]+)\\s*' + d[1], 'gm'); | ||
var variables = templateString.match(extractVarPattern); | ||
if (!variables) { | ||
return []; | ||
} | ||
return variables.map(function (variable) { return extractVarPattern.exec(templateString)[1]; }); | ||
}; | ||
exports.getTokens = getTokens; | ||
/** | ||
* Count tokens is a function built on top getTokens. It is just a wrapper | ||
* that pretends to be more concise. Under the hood, this funtion executes | ||
* the parser only one time. | ||
* | ||
* @param {string} templateString | ||
* @param {[string,string]|undefined} delimiters | ||
* @returns {number} | ||
*/ | ||
var countTokens = function (templateString, delimiters) { | ||
if (delimiters === void 0) { delimiters = ['{{', '}}']; } | ||
return (0, exports.getTokens)(templateString, delimiters).length; | ||
}; | ||
exports.countTokens = countTokens; | ||
/** | ||
* Renders a string template and returns it with all variables replaced | ||
@@ -39,3 +70,4 @@ * in the string. | ||
} | ||
for (var i = 0; i < variables.length; i++) { | ||
for (var _i = 0, variables_1 = variables; _i < variables_1.length; _i++) { | ||
var _ = variables_1[_i]; | ||
entries = extractVarPattern.exec(string_); | ||
@@ -42,0 +74,0 @@ var attr = entries[1]; |
{ | ||
"name": "templyte", | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"description": "Simple Javascript string template. Useful for simple string translations and text replacing.", | ||
@@ -19,7 +19,7 @@ "main": "dist/index.js", | ||
"lint": "xo !*.config.js", | ||
"lint:fix": "xo --fix", | ||
"lint:fix": "xo !*.config.js --fix", | ||
"test": "jest --config jest.config.js", | ||
"pretest": "xo !jest.config.js", | ||
"test:watch": "jest --watch", | ||
"prepublish": "npm unlink && npm run build" | ||
"prepublishOnly": "npm run build" | ||
}, | ||
@@ -26,0 +26,0 @@ "repository": { |
# templyte | ||
[![Software License][ico-license]](LICENSE.md) | ||
[![Build Status][ico-travis]][link-travis] | ||
[![Test library](https://github.com/SiroDiaz/templyte/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/SiroDiaz/templyte/actions/workflows/test.yml) | ||
[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3XKLA6VTYVSKW&source=url) | ||
@@ -6,0 +6,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
9507
116
0