@creuna/utils
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.default = void 0; | ||
exports["default"] = void 0; | ||
@@ -33,2 +33,2 @@ function anyToKebab(s) { | ||
var _default = anyToKebab; | ||
exports.default = _default; | ||
exports["default"] = _default; |
@@ -6,7 +6,7 @@ "use strict"; | ||
}); | ||
exports.default = void 0; | ||
exports["default"] = void 0; | ||
var _deepClone = _interopRequireDefault(require("./deep-clone")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
@@ -18,3 +18,3 @@ function insert(array, index, item) { | ||
var newArray = (0, _deepClone.default)(array); | ||
var newArray = (0, _deepClone["default"])(array); | ||
newArray.splice(index, 0, item); | ||
@@ -25,2 +25,2 @@ return newArray; | ||
var _default = insert; | ||
exports.default = _default; | ||
exports["default"] = _default; |
@@ -6,7 +6,7 @@ "use strict"; | ||
}); | ||
exports.default = void 0; | ||
exports["default"] = void 0; | ||
var _deepClone = _interopRequireDefault(require("./deep-clone")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
@@ -18,3 +18,3 @@ function move(array, oldIndex, newIndex) { | ||
var newArray = (0, _deepClone.default)(array); | ||
var newArray = (0, _deepClone["default"])(array); | ||
@@ -34,2 +34,2 @@ if (newIndex >= newArray.length) { | ||
var _default = move; | ||
exports.default = _default; | ||
exports["default"] = _default; |
@@ -6,7 +6,7 @@ "use strict"; | ||
}); | ||
exports.default = void 0; | ||
exports["default"] = void 0; | ||
var _deepClone = _interopRequireDefault(require("./deep-clone")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
@@ -18,3 +18,3 @@ function remove(array, index) { | ||
var newArray = (0, _deepClone.default)(array); | ||
var newArray = (0, _deepClone["default"])(array); | ||
newArray.splice(index, 1); | ||
@@ -25,2 +25,2 @@ return newArray; | ||
var _default = remove; | ||
exports.default = _default; | ||
exports["default"] = _default; |
# Changelog | ||
## 1.2.0 | ||
- Adds `filterObject` and `stripPropertiesWithKeys` | ||
## 1.1.0 | ||
@@ -4,0 +8,0 @@ |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.default = void 0; | ||
exports["default"] = void 0; | ||
@@ -14,2 +14,2 @@ function clamp(currentValue, minimumValue, maximumValue) { | ||
var _default = clamp; | ||
exports.default = _default; | ||
exports["default"] = _default; |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.default = void 0; | ||
exports["default"] = void 0; | ||
@@ -21,2 +21,2 @@ var _default = function _default() { | ||
exports.default = _default; | ||
exports["default"] = _default; |
@@ -6,10 +6,10 @@ "use strict"; | ||
}); | ||
exports.default = _default; | ||
exports["default"] = _default; | ||
var _tryParseJson = _interopRequireDefault(require("./try-parse-json")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _default(object) { | ||
return (0, _tryParseJson.default)(JSON.stringify(object)); | ||
return (0, _tryParseJson["default"])(JSON.stringify(object)); | ||
} |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.default = void 0; | ||
exports["default"] = void 0; | ||
@@ -28,2 +28,2 @@ function fromQueryString(queryString) { | ||
var _default = fromQueryString; | ||
exports.default = _default; | ||
exports["default"] = _default; |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.default = void 0; | ||
exports["default"] = void 0; | ||
@@ -15,10 +15,10 @@ var _anyToKebab = _interopRequireDefault(require("./any-to-kebab")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function getData(dataAttributeName) { | ||
if (!_isRunningOnClient.default) { | ||
if (!_isRunningOnClient["default"]) { | ||
return; | ||
} | ||
var kebabedName = (0, _anyToKebab.default)(dataAttributeName); | ||
var kebabedName = (0, _anyToKebab["default"])(dataAttributeName); | ||
var node = document.querySelector("[data-".concat(kebabedName, "]")); | ||
@@ -30,6 +30,6 @@ | ||
return node.dataset[(0, _kebabToCamel.default)(kebabedName)]; | ||
return node.dataset[(0, _kebabToCamel["default"])(kebabedName)]; | ||
} | ||
var _default = getData; | ||
exports.default = _default; | ||
exports["default"] = _default; |
68
index.js
@@ -9,3 +9,3 @@ "use strict"; | ||
get: function get() { | ||
return _anyToKebab.default; | ||
return _anyToKebab["default"]; | ||
} | ||
@@ -16,3 +16,3 @@ }); | ||
get: function get() { | ||
return _arrayInsert.default; | ||
return _arrayInsert["default"]; | ||
} | ||
@@ -23,3 +23,3 @@ }); | ||
get: function get() { | ||
return _arrayMove.default; | ||
return _arrayMove["default"]; | ||
} | ||
@@ -30,3 +30,3 @@ }); | ||
get: function get() { | ||
return _arrayRemove.default; | ||
return _arrayRemove["default"]; | ||
} | ||
@@ -37,3 +37,3 @@ }); | ||
get: function get() { | ||
return _clamp.default; | ||
return _clamp["default"]; | ||
} | ||
@@ -44,3 +44,3 @@ }); | ||
get: function get() { | ||
return _createPipe.default; | ||
return _createPipe["default"]; | ||
} | ||
@@ -51,9 +51,15 @@ }); | ||
get: function get() { | ||
return _deepClone.default; | ||
return _deepClone["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "FilterObject", { | ||
enumerable: true, | ||
get: function get() { | ||
return _filterObject["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "FromQueryString", { | ||
enumerable: true, | ||
get: function get() { | ||
return _fromQueryString.default; | ||
return _fromQueryString["default"]; | ||
} | ||
@@ -64,3 +70,3 @@ }); | ||
get: function get() { | ||
return _getData.default; | ||
return _getData["default"]; | ||
} | ||
@@ -71,3 +77,3 @@ }); | ||
get: function get() { | ||
return _isEqual.default; | ||
return _isEqual["default"]; | ||
} | ||
@@ -78,3 +84,3 @@ }); | ||
get: function get() { | ||
return _isFullyInViewport.default; | ||
return _isFullyInViewport["default"]; | ||
} | ||
@@ -85,3 +91,3 @@ }); | ||
get: function get() { | ||
return _isInViewport.default; | ||
return _isInViewport["default"]; | ||
} | ||
@@ -92,3 +98,3 @@ }); | ||
get: function get() { | ||
return _isRunningOnClient.default; | ||
return _isRunningOnClient["default"]; | ||
} | ||
@@ -99,3 +105,3 @@ }); | ||
get: function get() { | ||
return _kebabToCamel.default; | ||
return _kebabToCamel["default"]; | ||
} | ||
@@ -106,3 +112,3 @@ }); | ||
get: function get() { | ||
return _kebabToPascal.default; | ||
return _kebabToPascal["default"]; | ||
} | ||
@@ -113,3 +119,3 @@ }); | ||
get: function get() { | ||
return _pipe.default; | ||
return _pipe["default"]; | ||
} | ||
@@ -120,3 +126,3 @@ }); | ||
get: function get() { | ||
return _rangeMap.default; | ||
return _rangeMap["default"]; | ||
} | ||
@@ -127,3 +133,3 @@ }); | ||
get: function get() { | ||
return _replaceQueryParameters.default; | ||
return _replaceQueryParameters["default"]; | ||
} | ||
@@ -134,3 +140,3 @@ }); | ||
get: function get() { | ||
return _scrollToElement.default; | ||
return _scrollToElement["default"]; | ||
} | ||
@@ -141,3 +147,3 @@ }); | ||
get: function get() { | ||
return _scrollToPosition.default; | ||
return _scrollToPosition["default"]; | ||
} | ||
@@ -148,9 +154,15 @@ }); | ||
get: function get() { | ||
return _scrollingElement.default; | ||
return _scrollingElement["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "StripPropertiesWithKeys", { | ||
enumerable: true, | ||
get: function get() { | ||
return _stripPropertiesWithKeys["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "StripPropertiesWithValue", { | ||
enumerable: true, | ||
get: function get() { | ||
return _stripPropertiesWithValue.default; | ||
return _stripPropertiesWithValue["default"]; | ||
} | ||
@@ -161,3 +173,3 @@ }); | ||
get: function get() { | ||
return _stripUndefined.default; | ||
return _stripUndefined["default"]; | ||
} | ||
@@ -168,3 +180,3 @@ }); | ||
get: function get() { | ||
return _toQueryString.default; | ||
return _toQueryString["default"]; | ||
} | ||
@@ -175,3 +187,3 @@ }); | ||
get: function get() { | ||
return _tryParseJson.default; | ||
return _tryParseJson["default"]; | ||
} | ||
@@ -194,2 +206,4 @@ }); | ||
var _filterObject = _interopRequireDefault(require("./filter-object")); | ||
var _fromQueryString = _interopRequireDefault(require("./from-query-string")); | ||
@@ -223,2 +237,4 @@ | ||
var _stripPropertiesWithKeys = _interopRequireDefault(require("./strip-properties-with-keys")); | ||
var _stripPropertiesWithValue = _interopRequireDefault(require("./strip-properties-with-value")); | ||
@@ -232,2 +248,2 @@ | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.default = void 0; | ||
exports["default"] = void 0; | ||
@@ -13,2 +13,2 @@ var _default = function _default(a, b) { | ||
exports.default = _default; | ||
exports["default"] = _default; |
@@ -6,13 +6,13 @@ "use strict"; | ||
}); | ||
exports.default = void 0; | ||
exports["default"] = void 0; | ||
var _isInViewport = _interopRequireDefault(require("./is-in-viewport")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function isFullyInViewport(el) { | ||
return el ? (0, _isInViewport.default)(el, el.offsetHeight, el.offsetWidth) : false; | ||
return el ? (0, _isInViewport["default"])(el, el.offsetHeight, el.offsetWidth) : false; | ||
} | ||
var _default = isFullyInViewport; | ||
exports.default = _default; | ||
exports["default"] = _default; |
@@ -6,7 +6,7 @@ "use strict"; | ||
}); | ||
exports.default = void 0; | ||
exports["default"] = void 0; | ||
var _isRunningOnClient = _interopRequireDefault(require("./is-running-on-client")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
@@ -17,3 +17,3 @@ function isElementInViewport(el) { | ||
if (!_isRunningOnClient.default || !el) { | ||
if (!_isRunningOnClient["default"] || !el) { | ||
return false; | ||
@@ -34,2 +34,2 @@ } | ||
var _default = isElementInViewport; | ||
exports.default = _default; | ||
exports["default"] = _default; |
@@ -6,5 +6,5 @@ "use strict"; | ||
}); | ||
exports.default = void 0; | ||
exports["default"] = void 0; | ||
var isRunningOnClient = typeof window !== 'undefined' && window.document ? true : false; | ||
var _default = isRunningOnClient; | ||
exports.default = _default; | ||
exports["default"] = _default; |
@@ -6,7 +6,7 @@ "use strict"; | ||
}); | ||
exports.default = void 0; | ||
exports["default"] = void 0; | ||
var _kebabToPascal = _interopRequireDefault(require("./kebab-to-pascal")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
@@ -18,3 +18,3 @@ function kebabToCamel(s) { | ||
var p = (0, _kebabToPascal.default)(s); | ||
var p = (0, _kebabToPascal["default"])(s); | ||
return p.substr(0, 1).toLowerCase() + p.substring(1); | ||
@@ -24,2 +24,2 @@ } | ||
var _default = kebabToCamel; | ||
exports.default = _default; | ||
exports["default"] = _default; |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.default = void 0; | ||
exports["default"] = void 0; | ||
@@ -29,2 +29,2 @@ function kebabToPascal(s) { | ||
var _default = kebabToPascal; | ||
exports.default = _default; | ||
exports["default"] = _default; |
{ | ||
"name": "@creuna/utils", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Creuna js utils", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -6,7 +6,7 @@ "use strict"; | ||
}); | ||
exports.default = void 0; | ||
exports["default"] = void 0; | ||
var _createPipe = _interopRequireDefault(require("./create-pipe")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
@@ -18,5 +18,5 @@ var _default = function _default(value) { | ||
return _createPipe.default.apply(void 0, functions)(value); | ||
return _createPipe["default"].apply(void 0, functions)(value); | ||
}; | ||
exports.default = _default; | ||
exports["default"] = _default; |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.default = _default; | ||
exports["default"] = _default; | ||
@@ -9,0 +9,0 @@ function _default(val, inMin, inMax, outMin, outMax) { |
@@ -114,2 +114,17 @@ # Creuna JS utils | ||
### filterObject(_object, predicate_) | ||
_@creuna/utils/filter-object_ | ||
- `object`: object | ||
- `value`: (key: string, value: any): boolean | ||
- returns: object | ||
Tests `predicate` (with `key` and `value`) for every entry in `object`. Returns a new object that contains every entry that passed the test. | ||
```js | ||
const obj = { a: 1, b: 2, c: 3 }; | ||
filterObject(obj, (key, value) => key !== "b" && value !== 3); // { a: 1 } | ||
``` | ||
### fromQueryString(_queryString[, prefix]_) | ||
@@ -297,2 +312,17 @@ | ||
### stripPropertiesWithKeys(_object, keys_) | ||
_@creuna/utils/strip-properties-with-keys_ | ||
- `object`: object | ||
- `value`: string[] | ||
- returns: object | ||
Returns a shallow copy of `object` with properties matching any of the `keys` removed | ||
```js | ||
const obj = { a: 1, b: 2, c: 3 }; | ||
stripPropertiesWithKeys(obj, ["b", "c"]); // { a: 1 } | ||
``` | ||
### stripPropertiesWithValue(_object, value_) | ||
@@ -299,0 +329,0 @@ |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.default = void 0; | ||
exports["default"] = void 0; | ||
@@ -13,3 +13,3 @@ var _fromQueryString = _interopRequireDefault(require("./from-query-string")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
@@ -20,8 +20,8 @@ function replaceQueryParameters(url, query) { | ||
var originalQueryString = urlFragments[1]; | ||
var originalQuery = (0, _fromQueryString.default)(originalQueryString); | ||
var originalQuery = (0, _fromQueryString["default"])(originalQueryString); | ||
var newQuery = Object.assign({}, originalQuery, query); | ||
return "".concat(baseUrl).concat((0, _toQueryString.default)(newQuery)); | ||
return "".concat(baseUrl).concat((0, _toQueryString["default"])(newQuery)); | ||
} | ||
var _default = replaceQueryParameters; | ||
exports.default = _default; | ||
exports["default"] = _default; |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.default = void 0; | ||
exports["default"] = void 0; | ||
@@ -13,7 +13,7 @@ var _scrollingElement = _interopRequireDefault(require("./scrolling-element")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function doScrollToElement(element, offset, duration) { | ||
var scrollPos = element.getBoundingClientRect().top + _scrollingElement.default.scrollTop - offset; | ||
(0, _scrollToPosition.default)(scrollPos, duration); | ||
var scrollPos = element.getBoundingClientRect().top + _scrollingElement["default"].scrollTop - offset; | ||
(0, _scrollToPosition["default"])(scrollPos, duration); | ||
} | ||
@@ -37,2 +37,2 @@ | ||
var _default = scrollToElement; | ||
exports.default = _default; | ||
exports["default"] = _default; |
@@ -6,7 +6,7 @@ "use strict"; | ||
}); | ||
exports.default = void 0; | ||
exports["default"] = void 0; | ||
var _scrollingElement = _interopRequireDefault(require("./scrolling-element")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
@@ -16,3 +16,3 @@ function doScrollToPosition(y) { | ||
clearTimeout(window.autoScrollingTimoutId); | ||
var initialY = _scrollingElement.default.scrollTop; | ||
var initialY = _scrollingElement["default"].scrollTop; | ||
var baseY = (initialY + y) * 0.5; | ||
@@ -53,2 +53,2 @@ var difference = initialY - baseY; | ||
var _default = scrollToPosition; | ||
exports.default = _default; | ||
exports["default"] = _default; |
@@ -6,11 +6,11 @@ "use strict"; | ||
}); | ||
exports.default = void 0; | ||
exports["default"] = void 0; | ||
var _isRunningOnClient = _interopRequireDefault(require("./is-running-on-client")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
// NOTE: https://stackoverflow.com/questions/45061901/chrome-61-body-doesnt-scroll | ||
var scrollingElement = _isRunningOnClient.default ? document.scrollingElement || document.documentElement || document.body : undefined; | ||
var scrollingElement = _isRunningOnClient["default"] ? document.scrollingElement || document.documentElement || document.body : undefined; | ||
var _default = scrollingElement; | ||
exports.default = _default; | ||
exports["default"] = _default; |
@@ -6,17 +6,12 @@ "use strict"; | ||
}); | ||
exports.default = void 0; | ||
exports["default"] = stripPropertiesWithValue; | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
var _filterObject = _interopRequireDefault(require("./filter-object")); | ||
function stripPropertiesWithValue(object, value) { | ||
return Object.keys(object).reduce(function (accumulator, key) { | ||
if (object[key] !== value) { | ||
Object.assign(accumulator, _defineProperty({}, key, object[key])); | ||
} | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
return accumulator; | ||
}, {}); | ||
} | ||
var _default = stripPropertiesWithValue; | ||
exports.default = _default; | ||
function stripPropertiesWithValue(object, valueToStrip) { | ||
return (0, _filterObject["default"])(object, function (_key, value) { | ||
return value !== valueToStrip; | ||
}); | ||
} |
@@ -6,13 +6,13 @@ "use strict"; | ||
}); | ||
exports.default = void 0; | ||
exports["default"] = void 0; | ||
var _stripPropertiesWithValue = _interopRequireDefault(require("./strip-properties-with-value")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function stripUndefined(object) { | ||
return (0, _stripPropertiesWithValue.default)(object, undefined); | ||
return (0, _stripPropertiesWithValue["default"])(object, undefined); | ||
} | ||
var _default = stripUndefined; | ||
exports.default = _default; | ||
exports["default"] = _default; |
@@ -6,7 +6,7 @@ "use strict"; | ||
}); | ||
exports.default = void 0; | ||
exports["default"] = void 0; | ||
var _stripUndefined = _interopRequireDefault(require("./strip-undefined")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
@@ -34,3 +34,3 @@ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } | ||
return Object.assign({}, defaultOptions, (0, _stripUndefined.default)(options)); | ||
return Object.assign({}, defaultOptions, (0, _stripUndefined["default"])(options)); | ||
}; | ||
@@ -62,2 +62,2 @@ | ||
var _default = toQueryString; | ||
exports.default = _default; | ||
exports["default"] = _default; |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.default = void 0; | ||
exports["default"] = void 0; | ||
@@ -18,2 +18,2 @@ function tryParseJson(possiblyJson, defaultValue) { | ||
var _default = tryParseJson; | ||
exports.default = _default; | ||
exports["default"] = _default; |
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
36675
32
656
383