Initial commit
This commit is contained in:
commit
ec9aee80e2
45
.eslintrc.json
Normal file
45
.eslintrc.json
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
{
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaVersion": 6,
|
||||||
|
"sourceType": "module",
|
||||||
|
"ecmaFeatures": {
|
||||||
|
"jsx": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"env": {
|
||||||
|
"browser": true,
|
||||||
|
"node": true,
|
||||||
|
"es6": true
|
||||||
|
},
|
||||||
|
"rules": {
|
||||||
|
"no-new-object": 1,
|
||||||
|
"no-reserved-keys": 1,
|
||||||
|
"no-array-constructor": 1,
|
||||||
|
"quotes": [1, "single"],
|
||||||
|
"max-len": [1, 80, 2], // 2 spaces per tab, max 80 chars per line
|
||||||
|
"no-inner-declarations": [1, "both"],
|
||||||
|
"no-shadow-restricted-names": 1,
|
||||||
|
"one-var": 0,
|
||||||
|
"vars-on-top": 1,
|
||||||
|
"eqeqeq": 1,
|
||||||
|
"curly": [1, "multi"],
|
||||||
|
"no-mixed-spaces-and-tabs": 1,
|
||||||
|
"space-before-blocks": [1, "always"],
|
||||||
|
"space-infix-ops": 1,
|
||||||
|
"eol-last": 1,
|
||||||
|
"comma-style": [1, "last"],
|
||||||
|
"no-comma-dangle": 1,
|
||||||
|
"semi": [1, "always"],
|
||||||
|
"radix": 1,
|
||||||
|
"camelcase": 1,
|
||||||
|
"new-cap": 1,
|
||||||
|
"consistent-this": [1, "_this"],
|
||||||
|
"func-names": 1,
|
||||||
|
"no-multi-spaces": 2,
|
||||||
|
"brace-style": [2,"1tbs",{}],
|
||||||
|
|
||||||
|
"indent": [2,2],
|
||||||
|
"comma-spacing": ["error", { "before": false, "after": true }]
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
180
.gitignore
vendored
Normal file
180
.gitignore
vendored
Normal file
@ -0,0 +1,180 @@
|
|||||||
|
# Created by .ignore support plugin (hsz.mobi)
|
||||||
|
### Archives template
|
||||||
|
# It's better to unpack these files and commit the raw source because
|
||||||
|
# git has its own built in compression methods.
|
||||||
|
*.7z
|
||||||
|
*.jar
|
||||||
|
*.rar
|
||||||
|
*.zip
|
||||||
|
*.gz
|
||||||
|
*.bzip
|
||||||
|
*.bz2
|
||||||
|
*.xz
|
||||||
|
*.lzma
|
||||||
|
*.cab
|
||||||
|
|
||||||
|
#packing-only formats
|
||||||
|
*.iso
|
||||||
|
*.tar
|
||||||
|
|
||||||
|
#package management formats
|
||||||
|
*.dmg
|
||||||
|
*.xpi
|
||||||
|
*.gem
|
||||||
|
*.egg
|
||||||
|
*.deb
|
||||||
|
*.rpm
|
||||||
|
*.msi
|
||||||
|
*.msm
|
||||||
|
*.msp
|
||||||
|
### Windows template
|
||||||
|
# Windows image file caches
|
||||||
|
Thumbs.db
|
||||||
|
ehthumbs.db
|
||||||
|
|
||||||
|
# Folder config file
|
||||||
|
Desktop.ini
|
||||||
|
|
||||||
|
# Recycle Bin used on file shares
|
||||||
|
$RECYCLE.BIN/
|
||||||
|
|
||||||
|
# Windows Installer files
|
||||||
|
*.cab
|
||||||
|
*.msi
|
||||||
|
*.msm
|
||||||
|
*.msp
|
||||||
|
|
||||||
|
# Windows shortcuts
|
||||||
|
*.lnk
|
||||||
|
### OSX template
|
||||||
|
.DS_Store
|
||||||
|
.AppleDouble
|
||||||
|
.LSOverride
|
||||||
|
|
||||||
|
# Icon must end with two \r
|
||||||
|
Icon
|
||||||
|
|
||||||
|
# Thumbnails
|
||||||
|
._*
|
||||||
|
|
||||||
|
# Files that might appear in the root of a volume
|
||||||
|
.DocumentRevisions-V100
|
||||||
|
.fseventsd
|
||||||
|
.Spotlight-V100
|
||||||
|
.TemporaryItems
|
||||||
|
.Trashes
|
||||||
|
.VolumeIcon.icns
|
||||||
|
|
||||||
|
# Directories potentially created on remote AFP share
|
||||||
|
.AppleDB
|
||||||
|
.AppleDesktop
|
||||||
|
Network Trash Folder
|
||||||
|
Temporary Items
|
||||||
|
.apdisk
|
||||||
|
### JetBrains template
|
||||||
|
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
|
||||||
|
|
||||||
|
*.iml
|
||||||
|
|
||||||
|
## Directory-based project format:
|
||||||
|
.idea/
|
||||||
|
# if you remove the above rule, at least ignore the following:
|
||||||
|
|
||||||
|
# User-specific stuff:
|
||||||
|
# .idea/workspace.xml
|
||||||
|
# .idea/tasks.xml
|
||||||
|
# .idea/dictionaries
|
||||||
|
|
||||||
|
# Sensitive or high-churn files:
|
||||||
|
# .idea/dataSources.ids
|
||||||
|
# .idea/dataSources.xml
|
||||||
|
# .idea/sqlDataSources.xml
|
||||||
|
# .idea/dynamic.xml
|
||||||
|
# .idea/uiDesigner.xml
|
||||||
|
|
||||||
|
# Gradle:
|
||||||
|
# .idea/gradle.xml
|
||||||
|
# .idea/libraries
|
||||||
|
|
||||||
|
# Mongo Explorer plugin:
|
||||||
|
# .idea/mongoSettings.xml
|
||||||
|
|
||||||
|
## File-based project format:
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
## Plugin-specific files:
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
/out/
|
||||||
|
|
||||||
|
# mpeltonen/sbt-idea plugin
|
||||||
|
.idea_modules/
|
||||||
|
|
||||||
|
# JIRA plugin
|
||||||
|
atlassian-ide-plugin.xml
|
||||||
|
|
||||||
|
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||||
|
com_crashlytics_export_strings.xml
|
||||||
|
crashlytics.properties
|
||||||
|
crashlytics-build.properties
|
||||||
|
### Node template
|
||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
|
||||||
|
# Runtime data
|
||||||
|
pids
|
||||||
|
*.pid
|
||||||
|
*.seed
|
||||||
|
|
||||||
|
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||||
|
lib-cov
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
coverage
|
||||||
|
|
||||||
|
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||||
|
.grunt
|
||||||
|
|
||||||
|
# node-waf configuration
|
||||||
|
.lock-wscript
|
||||||
|
|
||||||
|
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||||
|
build/Release
|
||||||
|
|
||||||
|
# Dependency directory
|
||||||
|
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
|
||||||
|
node_modules
|
||||||
|
bower_components
|
||||||
|
|
||||||
|
### VisualStudioCode template
|
||||||
|
.settings
|
||||||
|
|
||||||
|
### Xcode template
|
||||||
|
# Xcode
|
||||||
|
#
|
||||||
|
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
|
||||||
|
|
||||||
|
## Build generated
|
||||||
|
build/
|
||||||
|
DerivedData
|
||||||
|
|
||||||
|
## Various settings
|
||||||
|
*.pbxuser
|
||||||
|
!default.pbxuser
|
||||||
|
*.mode1v3
|
||||||
|
!default.mode1v3
|
||||||
|
*.mode2v3
|
||||||
|
!default.mode2v3
|
||||||
|
*.perspectivev3
|
||||||
|
!default.perspectivev3
|
||||||
|
xcuserdata
|
||||||
|
|
||||||
|
## Other
|
||||||
|
*.xccheckout
|
||||||
|
*.moved-aside
|
||||||
|
*.xcuserstate
|
||||||
|
|
||||||
|
dist
|
46
.jscsrc
Normal file
46
.jscsrc
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
{
|
||||||
|
"disallowKeywords": ["with"],
|
||||||
|
"disallowKeywordsOnNewLine": ["else"],
|
||||||
|
"disallowMixedSpacesAndTabs": true,
|
||||||
|
"disallowMultipleVarDecl": "exceptUndefined",
|
||||||
|
"disallowNewlineBeforeBlockStatements": true,
|
||||||
|
"disallowQuotedKeysInObjects": true,
|
||||||
|
"disallowSpaceAfterObjectKeys": true,
|
||||||
|
"disallowSpaceAfterPrefixUnaryOperators": true,
|
||||||
|
"disallowSpacesInFunction": {
|
||||||
|
"beforeOpeningRoundBrace": true
|
||||||
|
},
|
||||||
|
"disallowSpacesInsideParentheses": true,
|
||||||
|
"disallowTrailingWhitespace": true,
|
||||||
|
"maximumLineLength": 160,
|
||||||
|
"requireCamelCaseOrUpperCaseIdentifiers": false,
|
||||||
|
"requireCapitalizedComments": true,
|
||||||
|
"requireCapitalizedConstructors": true,
|
||||||
|
"requireCurlyBraces": true,
|
||||||
|
"requireSpaceAfterKeywords": [
|
||||||
|
"if",
|
||||||
|
"else",
|
||||||
|
"for",
|
||||||
|
"while",
|
||||||
|
"do",
|
||||||
|
"switch",
|
||||||
|
"case",
|
||||||
|
"return",
|
||||||
|
"try",
|
||||||
|
"catch",
|
||||||
|
"typeof"
|
||||||
|
],
|
||||||
|
"requireSpaceAfterLineComment": true,
|
||||||
|
"requireSpaceAfterBinaryOperators": true,
|
||||||
|
"requireSpaceBeforeBinaryOperators": true,
|
||||||
|
"requireSpaceBeforeBlockStatements": true,
|
||||||
|
"requireSpaceBeforeObjectValues": true,
|
||||||
|
"requireSpacesInFunction": {
|
||||||
|
"beforeOpeningCurlyBrace": true
|
||||||
|
},
|
||||||
|
"requireTrailingComma": false,
|
||||||
|
"requireEarlyReturn": false,
|
||||||
|
"validateIndentation": 2,
|
||||||
|
"validateLineBreaks": "LF",
|
||||||
|
"validateQuoteMarks": "'"
|
||||||
|
}
|
37
.jshintrc
Normal file
37
.jshintrc
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
{
|
||||||
|
"predef": [
|
||||||
|
"Promise",
|
||||||
|
"$"
|
||||||
|
],
|
||||||
|
"globals": {
|
||||||
|
"$": false,
|
||||||
|
"MicroEvent": false
|
||||||
|
},
|
||||||
|
"node":true,
|
||||||
|
"browser": true,
|
||||||
|
"boss": true,
|
||||||
|
"curly": true,
|
||||||
|
"debug": false,
|
||||||
|
"devel": true,
|
||||||
|
"eqeqeq": true,
|
||||||
|
"evil": true,
|
||||||
|
"forin": false,
|
||||||
|
"immed": false,
|
||||||
|
"laxbreak": false,
|
||||||
|
"newcap": true,
|
||||||
|
"noarg": true,
|
||||||
|
"noempty": false,
|
||||||
|
"nonew": false,
|
||||||
|
"nomen": false,
|
||||||
|
"onevar": false,
|
||||||
|
"plusplus": false,
|
||||||
|
"regexp": false,
|
||||||
|
"undef": true,
|
||||||
|
"sub": true,
|
||||||
|
"strict": false,
|
||||||
|
"white": false,
|
||||||
|
"eqnull": true,
|
||||||
|
"esnext": true,
|
||||||
|
"unused": true,
|
||||||
|
"supernew":true
|
||||||
|
}
|
2
Makefile
Normal file
2
Makefile
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
test:
|
||||||
|
@./node_modules/mocha/bin/mocha --reporter spec
|
38
lib/limitedarray.js
Normal file
38
lib/limitedarray.js
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
|
||||||
|
class LimitedArray {
|
||||||
|
|
||||||
|
constructor(size = 100) {
|
||||||
|
let _array = [];
|
||||||
|
let _limit = size;
|
||||||
|
|
||||||
|
this.push = item => {
|
||||||
|
_array.push(item);
|
||||||
|
if (_array.length > _limit)
|
||||||
|
_array.shift();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
this.get = () => _array;
|
||||||
|
|
||||||
|
this.limit = size => {
|
||||||
|
_limit = size;
|
||||||
|
if (_array.length > _limit)
|
||||||
|
_array = _array.slice(_array.length - _limit);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
this.length = () => _array.length;
|
||||||
|
|
||||||
|
this.add = items => {
|
||||||
|
_array = _array.concat(items);
|
||||||
|
|
||||||
|
if (_array.length > _limit)
|
||||||
|
_array = _array.slice(_array.length - _limit);
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = LimitedArray;
|
||||||
|
|
29
makefile.txt
Normal file
29
makefile.txt
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
|
||||||
|
build: components index.js
|
||||||
|
@component build --dev
|
||||||
|
|
||||||
|
components: component.json
|
||||||
|
@component install --dev
|
||||||
|
|
||||||
|
dist: dist-build dist-minify
|
||||||
|
|
||||||
|
test:
|
||||||
|
@./node_modules/mocha/bin/mocha --reporter spec
|
||||||
|
|
||||||
|
dist-build:
|
||||||
|
@component build -s array -o dist -n array
|
||||||
|
|
||||||
|
dist-minify: dist/array.js
|
||||||
|
@curl -s \
|
||||||
|
-d compilation_level=SIMPLE_OPTIMIZATIONS \
|
||||||
|
-d output_format=text \
|
||||||
|
-d output_info=compiled_code \
|
||||||
|
--data-urlencode "js_code@$<" \
|
||||||
|
http://closure-compiler.appspot.com/compile \
|
||||||
|
> $<.tmp
|
||||||
|
@mv $<.tmp dist/array.min.js
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -fr build components template.js
|
||||||
|
|
||||||
|
.PHONY: clean test build dist
|
292
package-lock.json
generated
Normal file
292
package-lock.json
generated
Normal file
@ -0,0 +1,292 @@
|
|||||||
|
{
|
||||||
|
"name": "limitedarray",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"lockfileVersion": 1,
|
||||||
|
"requires": true,
|
||||||
|
"dependencies": {
|
||||||
|
"balanced-match": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
|
||||||
|
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"better-assert": {
|
||||||
|
"version": "1.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/better-assert/-/better-assert-1.0.2.tgz",
|
||||||
|
"integrity": "sha1-QIZrnhueC1W0gYlDEeaPr/rrxSI=",
|
||||||
|
"requires": {
|
||||||
|
"callsite": "1.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"brace-expansion": {
|
||||||
|
"version": "1.1.8",
|
||||||
|
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz",
|
||||||
|
"integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"balanced-match": "1.0.0",
|
||||||
|
"concat-map": "0.0.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"browser-stdout": {
|
||||||
|
"version": "1.3.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.0.tgz",
|
||||||
|
"integrity": "sha1-81HTKWnTL6XXpVZxVCY9korjvR8=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"callsite": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/callsite/-/callsite-1.0.0.tgz",
|
||||||
|
"integrity": "sha1-KAOY5dZkvXQDi28JBRU+borxvCA="
|
||||||
|
},
|
||||||
|
"commander": {
|
||||||
|
"version": "2.9.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/commander/-/commander-2.9.0.tgz",
|
||||||
|
"integrity": "sha1-nJkJQXbhIkDLItbFFGCYQA/g99Q=",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"graceful-readlink": "1.0.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"concat-map": {
|
||||||
|
"version": "0.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||||
|
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"debug": {
|
||||||
|
"version": "2.6.8",
|
||||||
|
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.8.tgz",
|
||||||
|
"integrity": "sha1-5zFTHKLt4n0YgiJCfaF4IdaP9Pw=",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"ms": "2.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"diff": {
|
||||||
|
"version": "3.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/diff/-/diff-3.2.0.tgz",
|
||||||
|
"integrity": "sha1-yc45Okt8vQsFinJck98pkCeGj/k=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"escape-string-regexp": {
|
||||||
|
"version": "1.0.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
|
||||||
|
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"expect.js": {
|
||||||
|
"version": "0.3.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/expect.js/-/expect.js-0.3.1.tgz",
|
||||||
|
"integrity": "sha1-sKWaDS7/VDdUTr8M6qYBWEHQm1s=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"fs.realpath": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
|
||||||
|
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"glob": {
|
||||||
|
"version": "7.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.1.tgz",
|
||||||
|
"integrity": "sha1-gFIR3wT6rxxjo2ADBs31reULLsg=",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"fs.realpath": "1.0.0",
|
||||||
|
"inflight": "1.0.6",
|
||||||
|
"inherits": "2.0.3",
|
||||||
|
"minimatch": "3.0.4",
|
||||||
|
"once": "1.4.0",
|
||||||
|
"path-is-absolute": "1.0.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"graceful-readlink": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/graceful-readlink/-/graceful-readlink-1.0.1.tgz",
|
||||||
|
"integrity": "sha1-TK+tdrxi8C+gObL5Tpo906ORpyU=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"growl": {
|
||||||
|
"version": "1.9.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/growl/-/growl-1.9.2.tgz",
|
||||||
|
"integrity": "sha1-Dqd0NxXbjY3ixe3hd14bRayFwC8=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"has-flag": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-1.0.0.tgz",
|
||||||
|
"integrity": "sha1-nZ55MWXOAXoA8AQYxD+UKnsdEfo=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"inflight": {
|
||||||
|
"version": "1.0.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
|
||||||
|
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"once": "1.4.0",
|
||||||
|
"wrappy": "1.0.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"inherits": {
|
||||||
|
"version": "2.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
|
||||||
|
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"json3": {
|
||||||
|
"version": "3.3.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/json3/-/json3-3.3.2.tgz",
|
||||||
|
"integrity": "sha1-PAQ0dD35Pi9cQq7nsZvLSDV19OE=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"lodash._baseassign": {
|
||||||
|
"version": "3.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/lodash._baseassign/-/lodash._baseassign-3.2.0.tgz",
|
||||||
|
"integrity": "sha1-jDigmVAPIVrQnlnxci/QxSv+Ck4=",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"lodash._basecopy": "3.0.1",
|
||||||
|
"lodash.keys": "3.1.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"lodash._basecopy": {
|
||||||
|
"version": "3.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/lodash._basecopy/-/lodash._basecopy-3.0.1.tgz",
|
||||||
|
"integrity": "sha1-jaDmqHbPNEwK2KVIghEd08XHyjY=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"lodash._basecreate": {
|
||||||
|
"version": "3.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/lodash._basecreate/-/lodash._basecreate-3.0.3.tgz",
|
||||||
|
"integrity": "sha1-G8ZhYU2qf8MRt9A78WgGoCE8+CE=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"lodash._getnative": {
|
||||||
|
"version": "3.9.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/lodash._getnative/-/lodash._getnative-3.9.1.tgz",
|
||||||
|
"integrity": "sha1-VwvH3t5G1hzc3mh9ZdPuy6o6r/U=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"lodash._isiterateecall": {
|
||||||
|
"version": "3.0.9",
|
||||||
|
"resolved": "https://registry.npmjs.org/lodash._isiterateecall/-/lodash._isiterateecall-3.0.9.tgz",
|
||||||
|
"integrity": "sha1-UgOte6Ql+uhCRg5pbbnPPmqsBXw=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"lodash.create": {
|
||||||
|
"version": "3.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/lodash.create/-/lodash.create-3.1.1.tgz",
|
||||||
|
"integrity": "sha1-1/KEnw29p+BGgruM1yqwIkYd6+c=",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"lodash._baseassign": "3.2.0",
|
||||||
|
"lodash._basecreate": "3.0.3",
|
||||||
|
"lodash._isiterateecall": "3.0.9"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"lodash.isarguments": {
|
||||||
|
"version": "3.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz",
|
||||||
|
"integrity": "sha1-L1c9hcaiQon/AGY7SRwdM4/zRYo=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"lodash.isarray": {
|
||||||
|
"version": "3.0.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/lodash.isarray/-/lodash.isarray-3.0.4.tgz",
|
||||||
|
"integrity": "sha1-eeTriMNqgSKvhvhEqpvNhRtfu1U=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"lodash.keys": {
|
||||||
|
"version": "3.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/lodash.keys/-/lodash.keys-3.1.2.tgz",
|
||||||
|
"integrity": "sha1-TbwEcrFWvlCgsoaFXRvQsMZWCYo=",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"lodash._getnative": "3.9.1",
|
||||||
|
"lodash.isarguments": "3.1.0",
|
||||||
|
"lodash.isarray": "3.0.4"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"minimatch": {
|
||||||
|
"version": "3.0.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
|
||||||
|
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"brace-expansion": "1.1.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"minimist": {
|
||||||
|
"version": "0.0.8",
|
||||||
|
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
|
||||||
|
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"mkdirp": {
|
||||||
|
"version": "0.5.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
|
||||||
|
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"minimist": "0.0.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"mocha": {
|
||||||
|
"version": "3.5.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/mocha/-/mocha-3.5.0.tgz",
|
||||||
|
"integrity": "sha512-pIU2PJjrPYvYRqVpjXzj76qltO9uBYI7woYAMoxbSefsa+vqAfptjoeevd6bUgwD0mPIO+hv9f7ltvsNreL2PA==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"browser-stdout": "1.3.0",
|
||||||
|
"commander": "2.9.0",
|
||||||
|
"debug": "2.6.8",
|
||||||
|
"diff": "3.2.0",
|
||||||
|
"escape-string-regexp": "1.0.5",
|
||||||
|
"glob": "7.1.1",
|
||||||
|
"growl": "1.9.2",
|
||||||
|
"json3": "3.3.2",
|
||||||
|
"lodash.create": "3.1.1",
|
||||||
|
"mkdirp": "0.5.1",
|
||||||
|
"supports-color": "3.1.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ms": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||||
|
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"once": {
|
||||||
|
"version": "1.4.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||||
|
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"wrappy": "1.0.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"path-is-absolute": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
|
||||||
|
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"supports-color": {
|
||||||
|
"version": "3.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-3.1.2.tgz",
|
||||||
|
"integrity": "sha1-cqJiiU2dQIuVbKBf83su2KbiotU=",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"has-flag": "1.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"wrappy": {
|
||||||
|
"version": "1.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
||||||
|
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
|
||||||
|
"dev": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
25
package.json
Normal file
25
package.json
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"name": "limitedarray",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"description": "A finite array",
|
||||||
|
"main": "index.js",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git://gitlab.silvrtree.co.uk/martind2000/limitedArray.git"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"array",
|
||||||
|
"finite",
|
||||||
|
"limited"
|
||||||
|
],
|
||||||
|
"author": "Martin Donnelly",
|
||||||
|
"license": "ISC",
|
||||||
|
"devDependencies": {
|
||||||
|
"expect.js": "^0.3.1",
|
||||||
|
"mocha": "^3.5.0"
|
||||||
|
},
|
||||||
|
"dependencies": {}
|
||||||
|
}
|
65
test/limitedarray.js
Normal file
65
test/limitedarray.js
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
const LimitedArray = require('../'),
|
||||||
|
expect = require('expect.js');
|
||||||
|
|
||||||
|
|
||||||
|
describe('limitedArray', () => {
|
||||||
|
let lArray;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
lArray = new LimitedArray();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('() should initialize an empty array', () => {
|
||||||
|
let lArray = new LimitedArray();
|
||||||
|
|
||||||
|
expect(lArray.length()).to.be(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Add an item to the array', () => {
|
||||||
|
let lArray = new LimitedArray();
|
||||||
|
lArray.push('bob');
|
||||||
|
|
||||||
|
expect(lArray.length()).to.be(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Add items to the array', () => {
|
||||||
|
let lArray = new LimitedArray();
|
||||||
|
lArray.add([1, 2, 3, 4, 5]);
|
||||||
|
expect(lArray.length()).to.be(5);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Add too many items', () => {
|
||||||
|
let lArray = new LimitedArray(5);
|
||||||
|
lArray.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
||||||
|
expect(lArray.length()).to.be(5);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Change limit', () => {
|
||||||
|
let lArray = new LimitedArray();
|
||||||
|
|
||||||
|
lArray.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
||||||
|
lArray.limit(5);
|
||||||
|
|
||||||
|
expect(lArray.length()).to.be(5);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Get items', () => {
|
||||||
|
let lArray = new LimitedArray();
|
||||||
|
lArray.push('bob');
|
||||||
|
expect(lArray.get()).to.eql(['bob']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Add too many items and get the results', () => {
|
||||||
|
let lArray = new LimitedArray(5);
|
||||||
|
lArray.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
||||||
|
expect(lArray.get()).to.eql([6, 7, 8, 9, 10]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Add one more', () => {
|
||||||
|
let lArray = new LimitedArray(5);
|
||||||
|
lArray.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
||||||
|
lArray.push(11);
|
||||||
|
expect(lArray.get()).to.eql([7, 8, 9, 10, 11]);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user