@x-oasis/find-last-index 0.1.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # @x-oasis/find-last-index
2
+
3
+ ## Installation
4
+
5
+ ```bash
6
+ $ npm i @x-oasis/find-last-index
7
+ ```
8
+
9
+ ## How to use
10
+
11
+ ```typescript
12
+ import findLastIndex from '@x-oasis/find-last-index'
13
+ ```
14
+
15
+ ## How to run test
16
+
17
+ ```bash
18
+ $ pnpm test
19
+ ```
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ function findLastIndex(arr, fn) {
6
+ if (Array.prototype.findLastIndex) return arr.findLastIndex(fn);
7
+ var len = arr.length;
8
+ for (var index = len - 1; index > 0; index--) {
9
+ if (fn.apply(arr, [arr[index], index, arr])) {
10
+ return index;
11
+ }
12
+ }
13
+ return -1;
14
+ }
15
+
16
+ exports.default = findLastIndex;
17
+ //# sourceMappingURL=find-last-index.cjs.development.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-last-index.cjs.development.js","sources":["../src/index.ts"],"sourcesContent":["type Fn = (value: any, index: number, arr: Array<any>) => boolean;\n\nexport default function findLastIndex(arr: Array<any>, fn: Fn) {\n // @ts-ignore\n if (Array.prototype.findLastIndex) return arr.findLastIndex(fn);\n const len = arr.length;\n for (let index = len - 1; index > 0; index--) {\n if (fn.apply(arr, [arr[index], index, arr])) {\n return index;\n }\n }\n\n return -1;\n}\n"],"names":["findLastIndex","arr","fn","Array","prototype","len","length","index","apply"],"mappings":";;;;SAEwBA,aAAaA,CAACC,GAAe,EAAEC,EAAM;EAE3D,IAAIC,KAAK,CAACC,SAAS,CAACJ,aAAa,EAAE,OAAOC,GAAG,CAACD,aAAa,CAACE,EAAE,CAAC;EAC/D,IAAMG,GAAG,GAAGJ,GAAG,CAACK,MAAM;EACtB,KAAK,IAAIC,KAAK,GAAGF,GAAG,GAAG,CAAC,EAAEE,KAAK,GAAG,CAAC,EAAEA,KAAK,EAAE,EAAE;IAC5C,IAAIL,EAAE,CAACM,KAAK,CAACP,GAAG,EAAE,CAACA,GAAG,CAACM,KAAK,CAAC,EAAEA,KAAK,EAAEN,GAAG,CAAC,CAAC,EAAE;MAC3C,OAAOM,KAAK;;;EAIhB,OAAO,CAAC,CAAC;AACX;;;;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=function(e,r){if(Array.prototype.findLastIndex)return e.findLastIndex(r);for(var t=e.length-1;t>0;t--)if(r.apply(e,[e[t],t,e]))return t;return-1};
2
+ //# sourceMappingURL=find-last-index.cjs.production.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-last-index.cjs.production.min.js","sources":["../src/index.ts"],"sourcesContent":["type Fn = (value: any, index: number, arr: Array<any>) => boolean;\n\nexport default function findLastIndex(arr: Array<any>, fn: Fn) {\n // @ts-ignore\n if (Array.prototype.findLastIndex) return arr.findLastIndex(fn);\n const len = arr.length;\n for (let index = len - 1; index > 0; index--) {\n if (fn.apply(arr, [arr[index], index, arr])) {\n return index;\n }\n }\n\n return -1;\n}\n"],"names":["arr","fn","Array","prototype","findLastIndex","index","length","apply"],"mappings":"6FAEsCA,EAAiBC,GAErD,GAAIC,MAAMC,UAAUC,cAAe,OAAOJ,EAAII,cAAcH,GAE5D,IADA,IACSI,EADGL,EAAIM,OACO,EAAGD,EAAQ,EAAGA,IACnC,GAAIJ,EAAGM,MAAMP,EAAK,CAACA,EAAIK,GAAQA,EAAOL,IACpC,OAAOK,EAIX,OAAQ"}
@@ -0,0 +1,13 @@
1
+ function findLastIndex(arr, fn) {
2
+ if (Array.prototype.findLastIndex) return arr.findLastIndex(fn);
3
+ var len = arr.length;
4
+ for (var index = len - 1; index > 0; index--) {
5
+ if (fn.apply(arr, [arr[index], index, arr])) {
6
+ return index;
7
+ }
8
+ }
9
+ return -1;
10
+ }
11
+
12
+ export default findLastIndex;
13
+ //# sourceMappingURL=find-last-index.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-last-index.esm.js","sources":["../src/index.ts"],"sourcesContent":["type Fn = (value: any, index: number, arr: Array<any>) => boolean;\n\nexport default function findLastIndex(arr: Array<any>, fn: Fn) {\n // @ts-ignore\n if (Array.prototype.findLastIndex) return arr.findLastIndex(fn);\n const len = arr.length;\n for (let index = len - 1; index > 0; index--) {\n if (fn.apply(arr, [arr[index], index, arr])) {\n return index;\n }\n }\n\n return -1;\n}\n"],"names":["findLastIndex","arr","fn","Array","prototype","len","length","index","apply"],"mappings":"SAEwBA,aAAaA,CAACC,GAAe,EAAEC,EAAM;EAE3D,IAAIC,KAAK,CAACC,SAAS,CAACJ,aAAa,EAAE,OAAOC,GAAG,CAACD,aAAa,CAACE,EAAE,CAAC;EAC/D,IAAMG,GAAG,GAAGJ,GAAG,CAACK,MAAM;EACtB,KAAK,IAAIC,KAAK,GAAGF,GAAG,GAAG,CAAC,EAAEE,KAAK,GAAG,CAAC,EAAEA,KAAK,EAAE,EAAE;IAC5C,IAAIL,EAAE,CAACM,KAAK,CAACP,GAAG,EAAE,CAACA,GAAG,CAACM,KAAK,CAAC,EAAEA,KAAK,EAAEN,GAAG,CAAC,CAAC,EAAE;MAC3C,OAAOM,KAAK;;;EAIhB,OAAO,CAAC,CAAC;AACX;;;;"}
@@ -0,0 +1,3 @@
1
+ declare type Fn = (value: any, index: number, arr: Array<any>) => boolean;
2
+ export default function findLastIndex(arr: Array<any>, fn: Fn): any;
3
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+
2
+ 'use strict'
3
+
4
+ if (process.env.NODE_ENV === 'production') {
5
+ module.exports = require('./find-last-index.cjs.production.min.js')
6
+ } else {
7
+ module.exports = require('./find-last-index.cjs.development.js')
8
+ }
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@x-oasis/find-last-index",
3
+ "version": "0.1.34",
4
+ "description": "find-last-index function",
5
+ "main": "dist/index.js",
6
+ "typings": "dist/index.d.ts",
7
+ "module": "dist/find-last-index.esm.js",
8
+ "files": [
9
+ "dist",
10
+ "index.ts",
11
+ "src"
12
+ ],
13
+ "author": "",
14
+ "license": "ISC",
15
+ "devDependencies": {
16
+ "tsdx": "^0.14.1"
17
+ },
18
+ "scripts": {
19
+ "build": "tsdx build --tsconfig tsconfig.build.json",
20
+ "clean": "rimraf ./dist",
21
+ "test": "vitest",
22
+ "compile": "tsc -p tsconfig.build.json"
23
+ }
24
+ }
package/src/index.ts ADDED
@@ -0,0 +1,14 @@
1
+ type Fn = (value: any, index: number, arr: Array<any>) => boolean;
2
+
3
+ export default function findLastIndex(arr: Array<any>, fn: Fn) {
4
+ // @ts-ignore
5
+ if (Array.prototype.findLastIndex) return arr.findLastIndex(fn);
6
+ const len = arr.length;
7
+ for (let index = len - 1; index > 0; index--) {
8
+ if (fn.apply(arr, [arr[index], index, arr])) {
9
+ return index;
10
+ }
11
+ }
12
+
13
+ return -1;
14
+ }