Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(taxes_and_fees): update a logic of calculation taxes and fees #41

Merged
merged 4 commits into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 46 additions & 3 deletions compiled/occupancy/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use strict";

function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
Expand All @@ -12,7 +14,7 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

var match = function match(occupancy) {
var _match = function match(occupancy) {
return !(occupancy.match(/^[0-9]{1,2}-[0-9]{1,2}-[0-9]{1,2}?$/gi) == null) || !(occupancy.match(/^[0-9]{1,2}(-[0-9]{1,2}?(,[0-9]{1,2})*)?$/ig) == null);
};

Expand Down Expand Up @@ -81,9 +83,50 @@ var get = function get(occupancy) {
return occupancies;
};

var strummerMatcher = {
match: function match(path, value) {
var dataCheck = value;

if (typeof value === 'string') {
if (value.split(',').every(function (occupancy) {
return !!occupancy.match(/^[0-9]{1,2}-[0-9]{1,2}-[0-9]{1,2}?$/gi);
})) {
dataCheck = [value.split(',')].flat();
} else {
dataCheck = [value];
}
}

var _iterator = _createForOfIteratorHelper(dataCheck),
_step;

try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var occupancy = _step.value;

if (!_match(occupancy)) {
return 'Invalid occupancy format';
}
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}

return null;
},
toJSONSchema: function toJSONSchema() {
return {
type: 'string',
properties: {}
};
}
};
module.exports = {
parse: parse,
get: get,
match: match,
toString: toString
match: _match,
toString: toString,
strummerMatcher: strummerMatcher
};
5 changes: 5 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ declare module "@luxuryescapes/lib-global" {
childrenAge?: Array<number>;
}

interface JSONSchema {
type: "string";
}

export type LeHotelOfferType =
| "hotel"
| "last_minute_hotel"
Expand Down Expand Up @@ -69,6 +73,7 @@ declare module "@luxuryescapes/lib-global" {
parse: (occupancy: string) => Occupants;
match: (occupancy: string) => boolean;
toString: (occupancy: Occupants) => string;
strummerMatcher: { match: (path: string, value: any) => string | undefined, toJSONSchema?: () => JSONSchema };
};
const currency: {
addDollarType: (
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@luxuryescapes/lib-global",
"version": "2.4.9",
"version": "2.5.0",
"description": "Lib for expanding functionality and deduplicating code between services",
"main": "compiled/index.js",
"types": "index.d.ts",
Expand Down
22 changes: 22 additions & 0 deletions src/occupancy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,31 @@ const get = occupancy => {
return occupancies
}

const strummerMatcher = {
match: (path, value) => {
let dataCheck = value
if (typeof value === 'string') {
if (value.split(',').every(occupancy => !!occupancy.match(/^[0-9]{1,2}-[0-9]{1,2}-[0-9]{1,2}?$/gi))) {
dataCheck = [value.split(',')].flat()
} else {
dataCheck = [value]
}
}
for (const occupancy of dataCheck) {
if (!match(occupancy)) {
return 'Invalid occupancy format'
}
}

return null
},
toJSONSchema: () => ({ type: 'string', properties: {} }),
}

module.exports = {
parse: parse,
get: get,
match: match,
toString: toString,
strummerMatcher: strummerMatcher,
}