melody-runtime
Advanced tools
Comparing version 1.2.0-commit.b0c42b3d to 1.2.0-commit.cd6a9bf1
@@ -762,2 +762,33 @@ import _isString from 'lodash/isString'; | ||
function trim(str, charList) { | ||
var side = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'both'; | ||
if (charList === undefined && side === 'both') { | ||
// Use String.prototype.trim() for efficiency | ||
return String(str).trim(); | ||
} | ||
if (side !== 'both' && side !== 'left' && side !== 'right') { | ||
throw new Error('Filter "trim". Invalid value ' + side + ' for parameter "side". Valid values are "both", "left", "right".'); | ||
} | ||
var strLen = str.length; | ||
var trimStart = 0; | ||
if (side === 'both' || side === 'left') { | ||
while (trimStart < strLen && charList.indexOf(str[trimStart]) !== -1) { | ||
trimStart++; | ||
} | ||
} | ||
var trimEnd = strLen; | ||
if (side === 'both' || side === 'right') { | ||
while (trimEnd > 0 && charList.indexOf(str[trimEnd - 1]) !== -1) { | ||
trimEnd--; | ||
} | ||
} | ||
return str.substr(trimStart, trimEnd - trimStart); | ||
} | ||
var MAX_SAFE_INTEGER = 'MAX_SAFE_INTEGER' in Number ? Number.MAX_SAFE_INTEGER : 9007199254740991; | ||
@@ -879,2 +910,2 @@ | ||
export { createSubContext, batch, attrs, styles, classes, merge, replace, reverse, round, striptags, number_format, format, title, url_encode, strtotime, random, min, max, cycle, attribute, isEmpty, inheritBlocks }; | ||
export { createSubContext, batch, attrs, styles, classes, merge, replace, reverse, round, striptags, number_format, format, title, url_encode, strtotime, trim, random, min, max, cycle, attribute, isEmpty, inheritBlocks }; |
@@ -768,2 +768,33 @@ 'use strict'; | ||
function trim(str, charList) { | ||
var side = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'both'; | ||
if (charList === undefined && side === 'both') { | ||
// Use String.prototype.trim() for efficiency | ||
return String(str).trim(); | ||
} | ||
if (side !== 'both' && side !== 'left' && side !== 'right') { | ||
throw new Error('Filter "trim". Invalid value ' + side + ' for parameter "side". Valid values are "both", "left", "right".'); | ||
} | ||
var strLen = str.length; | ||
var trimStart = 0; | ||
if (side === 'both' || side === 'left') { | ||
while (trimStart < strLen && charList.indexOf(str[trimStart]) !== -1) { | ||
trimStart++; | ||
} | ||
} | ||
var trimEnd = strLen; | ||
if (side === 'both' || side === 'right') { | ||
while (trimEnd > 0 && charList.indexOf(str[trimEnd - 1]) !== -1) { | ||
trimEnd--; | ||
} | ||
} | ||
return str.substr(trimStart, trimEnd - trimStart); | ||
} | ||
var MAX_SAFE_INTEGER = 'MAX_SAFE_INTEGER' in Number ? Number.MAX_SAFE_INTEGER : 9007199254740991; | ||
@@ -900,2 +931,3 @@ | ||
exports.strtotime = strtotime; | ||
exports.trim = trim; | ||
exports.random = random; | ||
@@ -902,0 +934,0 @@ exports.min = min; |
{ | ||
"name": "melody-runtime", | ||
"version": "1.2.0-commit.b0c42b3d", | ||
"version": "1.2.0-commit.cd6a9bf1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -964,1 +964,34 @@ /** | ||
} | ||
export function trim(str, charList, side = 'both') { | ||
if (charList === undefined && side === 'both') { | ||
// Use String.prototype.trim() for efficiency | ||
return String(str).trim(); | ||
} | ||
if (side !== 'both' && side !== 'left' && side !== 'right') { | ||
throw new Error( | ||
'Filter "trim". Invalid value ' + | ||
side + | ||
' for parameter "side". Valid values are "both", "left", "right".' | ||
); | ||
} | ||
const strLen = str.length; | ||
let trimStart = 0; | ||
if (side === 'both' || side === 'left') { | ||
while (trimStart < strLen && charList.indexOf(str[trimStart]) !== -1) { | ||
trimStart++; | ||
} | ||
} | ||
let trimEnd = strLen; | ||
if (side === 'both' || side === 'right') { | ||
while (trimEnd > 0 && charList.indexOf(str[trimEnd - 1]) !== -1) { | ||
trimEnd--; | ||
} | ||
} | ||
return str.substr(trimStart, trimEnd - trimStart); | ||
} |
@@ -32,4 +32,5 @@ /** | ||
strtotime, | ||
trim, | ||
} from './filters'; | ||
export { random, min, max, cycle, attribute } from './functions'; | ||
export { isEmpty, inheritBlocks } from './helpers'; |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
104042
2763
0