Comparing version 3.0.1 to 3.1.0
@@ -5,2 +5,9 @@ # Changelog | ||
## [3.1.0][] - 2021-01-22 | ||
- Added isFirstUpper to check is first char an upper case letter | ||
- Added isConstant to check is string UPPER_SNAKE case | ||
- Added makePrivate to emulate protected fields for objects | ||
- Added protect to freeze interfaces except listed | ||
## [3.0.1][] - 2021-01-18 | ||
@@ -20,5 +27,6 @@ | ||
[unreleased]: https://github.com/metarhia/metautil/compare/v3.0.1...HEAD | ||
[unreleased]: https://github.com/metarhia/metautil/compare/v3.1.0...HEAD | ||
[3.1.0]: https://github.com/metarhia/metautil/compare/v3.0.1...v3.1.0 | ||
[3.0.1]: https://github.com/metarhia/metautil/compare/v3.0.0...v3.0.1 | ||
[3.0.0]: https://github.com/metarhia/metautil/compare/v2.2.0...v3.0.0 | ||
[2.2.0]: https://github.com/metarhia/common/releases/tag/v2.2.0 |
@@ -87,2 +87,6 @@ 'use strict'; | ||
const isFirstUpper = (s) => !!s && s[0] === s[0].toUpperCase(); | ||
const isConstant = (s) => s === s.toUpperCase(); | ||
const twoDigit = (n) => { | ||
@@ -151,2 +155,28 @@ const s = n.toString(); | ||
const makePrivate = (instance) => { | ||
const iface = {}; | ||
const fields = Object.keys(instance); | ||
for (const fieldName of fields) { | ||
const field = instance[fieldName]; | ||
if (isConstant(fieldName)) { | ||
iface[fieldName] = field; | ||
} else if (typeof field === 'function') { | ||
const bindedMethod = field.bind(instance); | ||
iface[fieldName] = bindedMethod; | ||
instance[fieldName] = bindedMethod; | ||
} | ||
} | ||
return iface; | ||
}; | ||
const protect = (allowMixins, ...namespaces) => { | ||
for (const namespace of namespaces) { | ||
const names = Object.keys(namespace); | ||
for (const name of names) { | ||
const target = namespace[name]; | ||
if (!allowMixins.includes(name)) Object.freeze(target); | ||
} | ||
} | ||
}; | ||
module.exports = { | ||
@@ -159,2 +189,4 @@ sample, | ||
between, | ||
isFirstUpper, | ||
isConstant, | ||
nowDate, | ||
@@ -168,2 +200,4 @@ duration, | ||
cryptoRandom, | ||
makePrivate, | ||
protect, | ||
}; |
{ | ||
"name": "metautil", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"author": "Timur Shemsedinov <timur.shemsedinov@gmail.com>", | ||
@@ -38,3 +38,3 @@ "license": "MIT", | ||
"eslint-config-metarhia": "^7.0.1", | ||
"eslint-config-prettier": "^7.0.0", | ||
"eslint-config-prettier": "^7.2.0", | ||
"eslint-plugin-import": "^2.22.1", | ||
@@ -41,0 +41,0 @@ "eslint-plugin-prettier": "^3.3.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
8831
175