New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@acanto/core-helpers

Package Overview
Dependencies
Maintainers
2
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@acanto/core-helpers - npm Package Compare versions

Comparing version 0.1.8 to 0.2.0

96

item.ts

@@ -27,3 +27,3 @@ /**

import { availableItem } from "./itemversion";
import { getQueryParams, mergeUrlParams, updateLinkParams } from "./location";
import { getQueryParams, mergeUrlParams, updateLinkParams, removeUrlParam } from "./location";
import { isUndefined } from "./type";

@@ -84,5 +84,12 @@

syncUrl?: boolean;
syncUrlClear?: string;
};
type Length = number;
type Index = number;
type Product = string | null;
type Typepage = string | null;
}

@@ -146,3 +153,6 @@

options: Item.Options,
product: Item.Product
product: Item.Product,
length: Item.Length,
index: Item.Index,
typepage: Item.Typepage
) {

@@ -168,3 +178,3 @@ if (!$root) {

const { syncUrl } = options || {};
const { syncUrl, syncUrlClear } = options || {};
const { readonlyProperties } = getItemData($root);

@@ -193,3 +203,3 @@ const $properties: Record<string, Item.Property> = {};

// the instance is immediately updated here
update();
update(false, false, length, index);

@@ -239,3 +249,5 @@ /**

domOn($input, "change", handleChange);
domOn($input, "change", (event) => {
handleChange(event);
});
});

@@ -265,4 +277,5 @@

*/
function handleChange(/* event: InputEvent */) {
update();
function handleChange(event: InputEvent) {
const element = event.target;
update(element, true);
itemEmit("change", instance);

@@ -306,8 +319,9 @@ }

*/
function setDataOnElement() {
function setDataOnElement(element = null, interact = false) {
const current = getItemData($root);
const quantity = getQuantityValue();
const data = { ...current };
const data = { ...current };
if (!readonlyProperties) {
resetPropertyExceptPivot(element, interact);
const propertiesMap = getPropertiesMap();

@@ -357,3 +371,3 @@

*/
function validateAddtoCart() {
function validateAddtoCart(lenght, index, interact) {
const errors = validate();

@@ -363,4 +377,5 @@

if (!errors.length) {
const data = setDataOnElement();
return availableItem(product, data);
// const data = setDataOnElement();
const data = getItemData($root);
return availableItem(product, data, lenght, index, interact, typepage);
}

@@ -372,2 +387,27 @@

/**
* Reset every property except the pivot one
*/
function resetPropertyExceptPivot(current, interact) {
if(interact){
const allProperties = $$(`[data-${ATTR_ITEM_PROPERTY}]`, $root);
forEach(allProperties, (element) => {
if(element.name != syncUrlClear && current.name == syncUrlClear){
element.value = "";
}
});
}
}
function resetUrlParams(syncUrlClear) {
const allparams = getQueryParams();
for (const [key, value] of Object.entries(allparams)) {
if(key != syncUrlClear){
removeUrlParam(key);
}
}
}
/**
* Update

@@ -380,9 +420,18 @@ *

*/
function update() {
function update(element = null, interact = false, length = 0, index = 0) {
const errors = validate();
const isValid = !errors.length;
const data = setDataOnElement();
const addToCart = validateAddtoCart();
const data = setDataOnElement(element, interact);
const addToCart = validateAddtoCart(length, index, interact);
if (interact && syncUrlClear) {
if(syncUrlClear != element.name){
updateUrl(data.params, element);
} else {
resetUrlParams(syncUrlClear);
updateUrl(data.params);
}
}
if (syncUrl) {
if(!interact && syncUrl) {
updateUrl(data.params);

@@ -522,4 +571,9 @@ }

*/
function updateUrl(params: Record<string, string>) {
mergeUrlParams(params, true);
function updateUrl(params: Record<string, string>, element = null) {
const value = element ? element.value : null;
if(value == ""){
removeUrlParam(element.name);
} else {
mergeUrlParams(params, true);
}
}

@@ -537,2 +591,3 @@

export function initItems(
typepage?: Typepage,
rooter?: Rooter,

@@ -542,5 +597,6 @@ options?: Item.Options,

) {
forEach($$(`[data-${ATTR_ITEM_ID}]`, getScopedRoot(rooter)), ($item) => {
Item($item, options, product);
const $items = $$(`[data-${ATTR_ITEM_ID}]`, getScopedRoot(rooter));
forEach($items, ($item, index) => {
Item($item, options, product, $items.length, index, typepage);
});
}

@@ -1,38 +0,82 @@

export function availableItem(product = null, attr) {
const item = product ? product : null;
const versions = product ? product.versions : null;
let available = true;
const attrs = attr.params;
const arrayOfObj = Object.entries(attrs).map((e) => (
{ name: e[0], value: e[1] }
));
import { globalConf } from "@acanto/core-data";
import { forEach } from "@acanto/core-dom";
if(versions){
export function availableItem(product = null, attr, lenght, index, interact, typepage) {
for(let i = 0; i < versions.length; i++){
const api = globalConf?.api.name;
if(api != 'olmo'){
const item = product ? product : null;
const versions = product ? product.versions : null;
let available = true;
const attrs = attr.params;
const arrayOfObj = Object.entries(attrs).map((e) => (
{ name: e[0], value: e[1] }
));
if(versions){
for(let i = 0; i < versions.length; i++){
let counter = 0;
for(let n = 0; n < versions[i].properties.length; n++){
for(let x = 0; x < arrayOfObj.length; x++){
if(versions[i].properties[n].name == arrayOfObj[x].name){
for(let z = 0; z < versions[i].properties[n].items.length; z++){
if(versions[i].properties[n].items[z].id == arrayOfObj[x].value){
counter++;
}
if((counter+1) > arrayOfObj.length){
available = versions[i].available ? false : true;
counter = 0;
}
}
}
}
}
}
} else if(item){
available = product.available;
}
return available;
} else {
if((0 == (index) || interact) && typepage == 'singlepage'){
const itemsOrproperty = product?.property ? true : false;
const props = attr.properties.map(function(num) {
return parseInt(num);
});
let counter = 0;
for(let n = 0; n < versions[i].properties.length; n++){
for(let x = 0; x < arrayOfObj.length; x++){
if(versions[i].properties[n].name == arrayOfObj[x].name){
for(let z = 0; z < versions[i].properties[n].items.length; z++){
if(versions[i].properties[n].items[z].id == arrayOfObj[x].value){
counter++;
}
if((counter+1) > arrayOfObj.length){
available = versions[i].available ? false : true;
counter = 0;
}
}
}
}
}
}
} else if(item){
if(!itemsOrproperty){
const items = product.items;
available = product.available;
forEach(items, (item) => {
const properties = item.property;
let counter = 0;
forEach(properties, (property) => {
if(props.includes(property.id)){
counter++;
}
if(counter == properties.length){
const quantity = item.qty == 0 ? false : true;
return quantity;
}
});
});
return false;
} else {
console.error('Build me please!');
}
}
}
return available;
}
}
{
"name": "@acanto/core-helpers",
"version": "0.1.8",
"version": "0.2.0",
"author": "Acanto <info@acanto.net> (https://acanto.agency/)",

@@ -23,3 +23,3 @@ "license": "ISC",

"sideEffects": false,
"gitHead": "18a013ae6bb5de3154774549ba092b445dcb284b"
"gitHead": "c35e804f0c2fde27284ba553920b61338bedea9f"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc