array-kit 0.2.6 → 0.2.8

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/lib/delete.js CHANGED
@@ -38,7 +38,7 @@
38
38
  module.exports = ( src , index ) => {
39
39
  if ( index >= src.length ) { return ; }
40
40
 
41
- var iMax = src.length - 2 ;
41
+ const iMax = src.length - 2 ;
42
42
 
43
43
  while ( index <= iMax ) {
44
44
  src[ index ] = src[ index + 1 ] ;
@@ -37,7 +37,7 @@
37
37
  * value: the value to delete
38
38
  */
39
39
  module.exports = ( src , value ) => {
40
- var currentValue , deletedCount ,
40
+ let currentValue ,
41
41
  i = 0 ,
42
42
  j = 0 ;
43
43
 
@@ -54,7 +54,7 @@ module.exports = ( src , value ) => {
54
54
  i ++ ;
55
55
  }
56
56
 
57
- deletedCount = src.length - j ;
57
+ const deletedCount = src.length - j ;
58
58
  src.length = j ;
59
59
 
60
60
  return deletedCount ;
@@ -37,11 +37,12 @@
37
37
  * index the index of the current element
38
38
  * the array
39
39
  * thisArg: what is used as `this` inside the callback function
40
- * forceKey: for that key instead of the index of the current element (useful for other libs)
40
+ * forceKey: force that key instead of the index of the current element (useful for other libs)
41
41
  */
42
- module.exports = ( src , fn , thisArg , forceKey ) => {
43
- var hasForcedKey = arguments.length >= 4 ,
44
- value ,
42
+ module.exports = function( src , fn , thisArg , forceKey ) {
43
+ const hasForcedKey = arguments.length >= 4 ;
44
+
45
+ let value ,
45
46
  i = 0 ,
46
47
  j = 0 ;
47
48
 
package/lib/range.js CHANGED
@@ -31,33 +31,46 @@
31
31
  /*
32
32
  Create an array.
33
33
 
34
- .range( [start] , end , [step] ), where:
34
+ .range( length )
35
+ .range( start , end )
36
+ .range( start , end , step )
37
+ .range( [start] , end , [step] )
35
38
 
39
+ * length `number` the length of the array
36
40
  * start `number` (default: 0) the value of the first item
37
41
  * end `number` the values end at this number (excluded)
38
42
  * step `number` (default: 1) the value of the increment
39
43
  */
40
44
  module.exports = function( start , end , step ) {
41
- if ( ! arguments.length ) { return [] ; }
42
-
45
+ // Fast exit / common path first
43
46
  if ( arguments.length === 1 ) {
44
- end = start ;
45
- start = 0 ;
47
+ const length = start ;
48
+ const output = new Array( length ) ;
49
+ for ( let i = 0 ; i < length ; i ++ ) { output[ i ] = i ; }
50
+ return output ;
46
51
  }
47
52
 
48
- if ( ! step ) { step = start <= end ? 1 : -1 ; }
53
+ if ( ! arguments.length ) { return [] ; }
49
54
 
50
- if ( ( step > 0 && start >= end ) || ( step < 0 && start <= end ) ) {
51
- return [] ;
55
+ if ( ! step ) {
56
+ step = start <= end ? 1 : - 1 ;
52
57
  }
53
58
 
54
- var i = 0 , v = start , output = [] ;
59
+ const length = Math.ceil( ( end - start ) / step ) ;
60
+
61
+ if ( length <= 0 ) { return [] ; }
62
+
63
+ const output = new Array( length ) ;
55
64
 
56
65
  if ( step > 0 ) {
57
- for ( ; v < end ; i ++ , v += step ) { output[ i ] = v ; }
66
+ for ( let i = 0 , v = start ; v < end ; i ++ , v += step ) {
67
+ output[ i ] = v ;
68
+ }
58
69
  }
59
70
  else {
60
- for ( ; v > end ; i ++ , v += step ) { output[ i ] = v ; }
71
+ for ( let i = 0 , v = start ; v > end ; i ++ , v += step ) {
72
+ output[ i ] = v ;
73
+ }
61
74
  }
62
75
 
63
76
  return output ;
package/lib/sample.js CHANGED
@@ -36,8 +36,9 @@
36
36
  * inPlace: boolean, true if the array should be shuffled in-place
37
37
  */
38
38
  module.exports = ( array , count = Infinity , inPlace = false ) => {
39
- var currentIndex , randomIndex , temp ,
40
- sample = inPlace ? array : [ ... array ] ;
39
+ const sample = inPlace ? array : Array.from( array ) ;
40
+
41
+ let currentIndex , randomIndex , temp ;
41
42
 
42
43
  count = Math.max( Math.min( count , array.length ) , 0 ) ;
43
44
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "array-kit",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "An array manipulation toolbox.",
5
5
  "main": "lib/array-kit.js",
6
6
  "directories": {
package/.eslintrc.js DELETED
@@ -1,168 +0,0 @@
1
- module.exports = {
2
- 'root': true ,
3
- 'env': {
4
- 'browser': true ,
5
- 'es6': true ,
6
- 'node': true
7
- } ,
8
- 'parserOptions': {
9
- 'ecmaVersion': 2018
10
- } ,
11
- 'extends': [ 'eslint:recommended' ] ,
12
- 'rules': {
13
-
14
- /*
15
- Bad code -- detect anything that can be broken or lead to bugs
16
- */
17
-
18
-
19
-
20
- 'strict': [ 'error' , 'global' ] ,
21
- 'unicode-bom': [ 'error' , 'never' ] ,
22
- 'radix': 'error' ,
23
- 'eqeqeq': 'error' ,
24
- 'consistent-return': 'off' ,
25
- 'valid-typeof': 'error' ,
26
- 'no-unneeded-ternary': 'error' ,
27
- 'no-unused-vars': 'warn' , // During development phase, it's boring to clean unused var since they can be used later
28
- 'no-lonely-if': 'error' ,
29
- 'no-nested-ternary': 'off' , // Now I use the streamlined ternary operator a lot
30
- 'no-shadow': 'warn' ,
31
- 'no-shadow-restricted-names': 'error' ,
32
- 'require-atomic-updates': 'off' , // check for possible race condition on assignment, interesting but too nitpicky
33
-
34
-
35
-
36
- /*
37
- Code preferences
38
- */
39
-
40
-
41
-
42
- 'prefer-arrow-callback': 'error' ,
43
- 'prefer-spread': 'warn' ,
44
- 'prefer-rest-params': 'warn' ,
45
- 'no-control-regex': 'off' , // because thing like \x00 are considered like a control even if escaped...
46
- 'no-fallthrough': 'off' ,
47
- 'no-empty': [ 'error' , {
48
- 'allowEmptyCatch': true
49
- } ] ,
50
-
51
-
52
-
53
- /*
54
- Coding styles -- cosmetic rules and opinionated preferences
55
- */
56
-
57
-
58
-
59
- // Indent & spaces (general)
60
- 'indent': [ 'error' , 'tab' , {
61
- 'SwitchCase': 1 ,
62
- 'MemberExpression': 1 ,
63
- 'flatTernaryExpressions': true
64
- } ] ,
65
- 'newline-per-chained-call': [ 'error', {
66
- 'ignoreChainWithDepth': 2
67
- } ] ,
68
- 'no-multi-spaces': 'off' ,
69
- 'block-spacing': 'error' ,
70
- 'comma-spacing': [ 'error' , {
71
- 'before': true ,
72
- 'after': true
73
- } ] ,
74
- 'no-whitespace-before-property': 'error' ,
75
- 'space-before-blocks': 'error' ,
76
- 'space-before-function-paren': [ 'error' , {
77
- 'anonymous': 'never',
78
- 'named': 'never',
79
- 'asyncArrow': 'always'
80
- } ] ,
81
- 'space-infix-ops': 'error' ,
82
- 'space-unary-ops': [ 'error' , {
83
- 'words': true ,
84
- 'nonwords': true ,
85
- 'overrides': {
86
- '-': false ,
87
- }
88
- } ] ,
89
- 'space-in-parens': [ 'error' , 'always' , {
90
- 'exceptions': [ 'empty' ]
91
- } ] ,
92
- 'no-trailing-spaces': 'error' ,
93
- 'switch-colon-spacing': [ 'error' , {
94
- 'after': true ,
95
- 'before': true
96
- } ] ,
97
- 'arrow-spacing': 'error' ,
98
- 'rest-spread-spacing': [ 'error' , 'always' ] ,
99
- /* Troublesome with commented line of code
100
- 'spaced-comment': [ 'error' , 'always' , {
101
- 'line': {
102
- 'markers': [ '/' ],
103
- 'exceptions': [ '-', '*', '/' ]
104
- } ,
105
- 'block': {
106
- 'exceptions': [ '*' ] ,
107
- 'balanced': true
108
- }
109
- } ] ,
110
- */
111
-
112
-
113
- // Semi-colon
114
- 'semi': [ 'error' , 'always' ] ,
115
- 'semi-style': [ 'error' , 'last' ] ,
116
- 'semi-spacing': [ 'error' , {
117
- 'before': true ,
118
- 'after': true
119
- } ] ,
120
-
121
- // Objects
122
- 'key-spacing': [ 'error' , {
123
- 'beforeColon': false ,
124
- 'afterColon': true ,
125
- 'mode': 'strict'
126
- } ] ,
127
- 'object-curly-newline': [ 'error' , {
128
- 'ObjectExpression' : {
129
- 'consistent': true ,
130
- 'minProperties': 4
131
- } ,
132
- 'ObjectPattern' : {
133
- // object destructuring assigment
134
- 'consistent': true ,
135
- 'minProperties': 8
136
- }
137
- } ] ,
138
- 'object-curly-spacing': [ 'error' , 'always' ] ,
139
- 'object-property-newline': [ 'error' , { 'allowMultiplePropertiesPerLine': true } ] ,
140
-
141
-
142
- // Arrays
143
- 'array-bracket-newline': [ 'error' , 'consistent' ] ,
144
- //'array-element-newline': [ 'error' , { 'multiline': true , 'minItems': 5 } ] ,
145
- 'array-bracket-spacing': [ 'error' , 'always' ],
146
-
147
- 'brace-style': [ 'error' , 'stroustrup' , {
148
- 'allowSingleLine': true
149
- } ] ,
150
-
151
-
152
- // Misc style
153
- 'no-else-return': 'warn' ,
154
- 'comma-dangle': [ 'error' , 'never' ] ,
155
- 'quotes': 'off' ,
156
- 'camelcase': 'warn' ,
157
-
158
-
159
-
160
- /*
161
- Method limitation
162
- */
163
-
164
-
165
-
166
- 'no-console': 'off'
167
- }
168
- } ;
package/Makefile DELETED
@@ -1,97 +0,0 @@
1
-
2
-
3
-
4
- # User rules
5
-
6
- # The first rule is the default rule, when invoking "make" without argument...
7
- # Build every buildable things
8
- all: install doc
9
-
10
- # Just install things so it works, basicaly: it just performs a "npm install --production" ATM
11
- install: log/npm-install.log
12
-
13
- # Just install things so it works, basicaly: it just performs a "npm install" ATM
14
- dev-install: log/npm-dev-install.log
15
-
16
- # This run the JsHint & Mocha BDD test, display it to STDOUT & save it to log/mocha.log and log/jshint.log
17
- test: log/jshint.log log/mocha.log
18
-
19
- # This run the JsHint, display it to STDOUT & save it to log/jshint.log
20
- lint: log/jshint.log
21
-
22
- # This run the Mocha BDD test, display it to STDOUT & save it to log/mocha.log
23
- unit: log/mocha.log
24
-
25
- # This build the doc and README.md
26
- doc: README.md
27
-
28
- # This publish to NPM and push to Github, if we are on master branch only
29
- publish: log/npm-publish.log log/github-push.log
30
-
31
- # Clean temporary things, or things that can be automatically regenerated
32
- clean: clean-all
33
-
34
-
35
-
36
- # Variables
37
-
38
- MOCHA=mocha -c
39
- JSHINT=jshint --verbose
40
-
41
-
42
-
43
- # Files rules
44
-
45
- # JsHint STDOUT test
46
- log/jshint.log: log/npm-dev-install.log lib/*.js test/*.js
47
- ${JSHINT} lib/*.js test/*.js | tee log/jshint.log ; exit $${PIPESTATUS[0]}
48
-
49
- # Mocha BDD STDOUT test
50
- log/mocha.log: log/npm-dev-install.log lib/*.js test/*.js
51
- ${MOCHA} test/*.js -R spec | tee log/mocha.log ; exit $${PIPESTATUS[0]}
52
-
53
- # README
54
- README.md: documentation.md
55
- cat documentation.md > README.md
56
-
57
- # Mocha Markdown BDD spec
58
- bdd-spec.md: log/npm-dev-install.log lib/*.js test/*.js
59
- ${MOCHA} test/*.js -R markdown > bdd-spec.md
60
-
61
- # Upgrade version in package.json
62
- log/upgrade-package.log: lib/*.js test/*.js documentation.md
63
- npm version patch -m "Upgrade package.json version to %s" | tee log/upgrade-package.log ; exit $${PIPESTATUS[0]}
64
-
65
- # Publish to NPM
66
- log/npm-publish.log: check-if-master-branch log/upgrade-package.log
67
- npm publish | tee log/npm-publish.log ; exit $${PIPESTATUS[0]}
68
-
69
- # Push to Github/master
70
- log/github-push.log: lib/*.js test/*.js package.json
71
- #'npm version patch' create the git tag by itself...
72
- #git tag v`cat package.json | grep version | sed -r 's/.*"([0-9.]*)".*/\1/'`
73
- git push origin master --tags | tee log/github-push.log ; exit $${PIPESTATUS[0]}
74
-
75
- # NPM install
76
- log/npm-install.log: package.json
77
- npm install --production | tee log/npm-install.log ; exit $${PIPESTATUS[0]}
78
-
79
- # NPM install for developpement usage
80
- log/npm-dev-install.log: package.json
81
- npm install | tee log/npm-dev-install.log ; exit $${PIPESTATUS[0]}
82
-
83
-
84
-
85
- # PHONY rules
86
-
87
- .PHONY: clean-all check-if-master-branch
88
-
89
- # Delete files, mostly log and non-versioned files
90
- clean-all:
91
- rm -rf log/*.log README.md bdd-spec.md node_modules
92
-
93
- # This will fail if we are not on master branch (grep exit 1 if nothing found)
94
- check-if-master-branch:
95
- git branch | grep "^* master$$"
96
-
97
-
package/bdd-spec.md DELETED
File without changes
package/documentation.md DELETED
@@ -1,8 +0,0 @@
1
-
2
-
3
- # Array Kit
4
-
5
- An array manipulation toolbox.
6
-
7
- Early alpha.
8
-