npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

array-indicator

v1.0.3

Published

easy to select one array item at a time

Downloads

9

Readme

array-indicator

array-indicator可以將一個array放入,擁有一個指針,指向一個成員,並且提供移動指針的方法。這可以很方便地利用在一些一次只需要鎖定一個array成員的情境,例如圖片輪播器、簡報、導航列表項目的顯示⋯⋯。

安裝

npm install array-indicator --save

用法

CommonJS

var ArrayIndicator = require('array-indicator');

ES6

import ArrayIndicator from 'array-indicator';

ArrayIndicator返回一個實例對象。接受第一個參數必須為array,預設index為0,可以用point()設定指針指向的index。


var ai = ArrayIndicator(['foo', 'bar', 'baz']);

ai.current  // 'foo'

ai.point(2)

ai.current  // 'baz'

使用next()和prev()可以讓指針依序向前或向後,移動數量預設為1。

var ai = ArrayIndicator([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);

ai.current  // 1

ai.next()

ai.current  // 2

ai.prev()

ai.current  // 1

ai.next(5)

ai.current  // 6

可以鏈式操作。

ai.current  // 6

ai.next(4).prev(2).prev(2).current  // 6

啟用循環模式。

var ai = ArrayIndicator([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], {
  cycle: true,  
});

ai.current  // 1

ai.prev().current  // 10

ai.point(0).next(101).current  // 2

API

語法

ArrayIndicator(arr[, config])

參數

  • arr (Array) - 一個Array。
  • config (Object) - 選擇性設定。
    • init (Number) - 初始index值。預設為0。
    • cycle (Boolean) - 是否啟用循環模式。預設為false。

返回值

一個new ArrayIndicator() 實例。

實例屬性

  • index - 指針位置。read-only。
  • length - 陣列長度。read-only。
  • current - 指針指向的成員。read-only。
  • config - read-only。

實例方法

point([index])

將指針指向指定的index。

  • index (Number) - 存在於Array中的index。

next([step])

將指針往前指向step數量的位置。

  • step (Number) - 想要異動的數字。預設為1。

prev([step])

將指針往後指向step數量的位置。

  • step (Number) - 想要異動的數字。預設為1。

atEnd()

若指針在array最後一個成員上,返回true,否則false。

atStart()

若指針在array第一個成員上,返回true,否則false。