Comparing version 0.4.1 to 0.5.0
@@ -28,3 +28,3 @@ export as namespace likeAr; | ||
export function toPlainObject<T, K extends keyof any>(arrayKeys:K[], arrayValues:T[]):{[key in K]:T} | ||
export function createIndex<T, K extends keyof T>(array:T[], keyName:K|K[]):{[key:string]:T} | ||
export function createIndex<T, K extends keyof T>(array:T[], keyName:K|K[]|((i:T)=>string)):{[key:string]:T} | ||
export var testingLikeOldJs:boolean | ||
@@ -31,0 +31,0 @@ export const Optimized:typeof likeAr |
@@ -279,9 +279,10 @@ "use strict"; | ||
/** @type {<T, K extends keyof T>(array:T[], keyName:K|K[])=>{[key:string]:T}} */ | ||
/** @type {<T, K extends keyof T>(array:T[], keyName:K|K[]|((i:T)=>string))=>{[key:string]:T}} */ | ||
likeAr.createIndex = function createIndex(array, keyname){ | ||
/** @type {{[key:string]:any}} */ | ||
var o={}; | ||
/** @type {(i:T)=>string} */ | ||
var f | ||
if (keyname instanceof Array) { | ||
var pairs=array; | ||
pairs.forEach(function(pair, i){ | ||
f = (pair) => { | ||
var key = [] | ||
@@ -291,11 +292,15 @@ for (var keyName of keyname) { | ||
} | ||
o[JSON.stringify(key)] = pair; | ||
}); | ||
return JSON.stringify(key); | ||
} | ||
} else if (keyname instanceof Function) { | ||
f = keyname | ||
} else { | ||
var pairs=array; | ||
pairs.forEach(function(pair, i){ | ||
// @ts-expect-error pair[keyname] may be not a string, number or Symbol | ||
o[pair[keyname]]=pair; | ||
}); | ||
f = (pair) => { | ||
return pair[keyname]; | ||
} | ||
} | ||
var pairs=array; | ||
pairs.forEach(function(pair, i){ | ||
o[f(pair)]=pair; | ||
}); | ||
return o; | ||
@@ -302,0 +307,0 @@ }; |
{ | ||
"name": "like-ar", | ||
"description": "Using objects like arrays with map, filter, forEach and others coming soon.", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"author": "Codenautas <codenautas@googlegroups.com>", | ||
@@ -15,3 +15,3 @@ "repository": "codenautas/like-ar", | ||
"devDependencies": { | ||
"@types/mocha": "^10.0.6", | ||
"@types/mocha": "^10.0.7", | ||
"discrepances": "^0.2.8", | ||
@@ -21,5 +21,5 @@ "expect.js": "^0.3.1", | ||
"json4all": "^1.2.1", | ||
"mocha": "^10.4.0", | ||
"nyc": "^15.1.0", | ||
"typescript": "^5.4.5" | ||
"mocha": "^10.7.3", | ||
"nyc": "^17.0.0", | ||
"typescript": "^5.5.4" | ||
}, | ||
@@ -26,0 +26,0 @@ "engines": { |
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
21820
333