
Research
/Security News
11 Malicious NuGet Tools Pose as Game Cheats to Drop a Windows Host-Surveillance Payload
11 malicious NuGet tools pose as game cheats to deploy Windows payloads, track hosts, and use Google Sheets for telemetry and control.
Common Data Trans methods for Date, Array, Object, Array of Objects etc.
npm install --save sp-data
// or yarn add sp-data
<script src="https://unpkg.com/sp-data/index.min.js"></script>
<script>
__DATA.array.create(5, 0);
//=> [0, 0, 0, 0, 0]
</script>
//sp: {date, array, object, parse, entity}
const sp = require('sp-data');
sp.date.format('yyyy-MM-dd', new Date());
//=> 2018-08-06
sp.array.sort(arr = [1, 2, 3, 4, 1], isASC = true)
//=>[1, 1, 2, 3, 4]
sp.array.sort(arr = [1, 2, 3, 4, 1], isASC = false)
//=>[4, 3, 2, 1, 1]
//date: format(), goto(), prevDay(), prevMonth(), prevYear(), nextDay(), nextMonth(), nextYear(), calc()
const date = require('sp-data/date');
date.format('yyyy-MM-dd', new Date());
//=> 2018-08-06
date.goto(year, month, day);
//=> return Date
date.prevDay(dayCount = 0, startDate = new Date());
//=> return Date
date.prevMonth(monthCount = 0, date = new Date());
//=> return Date
date.prevYear(yearCount = 0, date = new Date());
//=> return Date
date.nextDay(dayCount = 0, startDate = new Date());
//=> return Date
date.nextMonth(monthCount = 0, date = new Date());
//=> return Date
date.nextYear(yearCount = 0, date = new Date());
//=> return Date
date.calc(startDate = new Date(2018, 01, 01), endDate = new Date());
//=> { seconds: 20, minutes: 44, hours: 15, days: 188 }
date.calc(startDate = new Date(2018, 01, 01), endDate = new Date(2000, 01, 01));
//=> { seconds: 0, minutes: 0, hours: 0, days: 6575 }
//arr: create(), sort(), sortObj(), unique(), uniqueObj(), filter(), sum(), createByArrObj(), mergeObj()
const arr = require('sp-data/array');
arr.create((length = 5, fillVal = 'a'))
//=>['a', 'a', 'a', 'a', 'a']
arr.sort(arr = [1, 2, 3, 4, 1], isASC = true)
//=>[1, 1, 2, 3, 4]
arr.sort(arr = [1, 2, 3, 4, 1], isASC = false)
//=>[4, 3, 2, 1, 1]
arr.sortObj(arr = [{name: 'Alice', age: 12},{name: 'Bob', age: 14}, {name: 'John', age: 11}], keyName = 'age', isASC = true)
//=>[{name: 'John', age: 11}, {name: 'Alice', age: 12},{name: 'Bob', age: 14}]
arr.sortObj(arr = [{name: 'Alice', age: 12},{name: 'Bob', age: 14}, {name: 'John', age: 11}], keyName = 'age', isASC = false)
//=>[{name: 'Bob', age: 14}, {name: 'Alice', age: 12}, {name: 'John', age: 11}]
arr.unique(arr = [1, 2, 3, 4, 1])
//=>[1, 2, 3, 4]
//unique by all key
arr.uniqueObj(arr = [{a: 1, b: 2}, {a: 2, b: 3}, {a: 1}, {a: 1}])
//=>[{a: 1, b: 2}, {a: 2, b: 3}, {a: 1}]
//unique by key name
arr.uniqueObj(arr = [{a: 1, b: 2}, {a: 2, b: 3}, {a: 1}], keyName = 'a')
//=>[{a: 1, b: 2}, {a: 2, b: 3}]
arr.filter(arr = [1, 3, 4, 5], function(item) {return item > 3;})
//=>[4, 5]
arr.filter(arr = [{name: 'Alice', age: 12},{name: 'Bob', age: 14}, {name: 'John', age: 11}], function(item) {return item.age > 12;})
//=>[{name: 'Bob', age: 14}]
arr.sum(arr = [1, 2, 3])
//=>6
//item is NOT number string return 0
arr.sum(arr = [1, 2, 3, 'a', 'b'])
//=>6
//sum by index => value
arr.sum(arr = [[1, 2, 3], [4, 5, 6], [7, 8], [9]], idDeep = true)
//[1 + 4 + 7 + 9, 2 + 5 + 8, 9]
//=>[ 21, 15, 9]
//sum by key => value
arr.sum(arr = [{a: 1, b: 2, c: 3}, {a: 4, b: 5}, {c: 6}, {d: 7}], idDeep = true)
//[{a: 1 + 4, b: 2 + 5, c: 3 + 6, d: 7}]
//=>[ { a: 5, b: 7, c: 9, d: 7 } ]
arr.createByArrObj(arrObj = [ { a: 3, b: 7}, {a: 0, b: 3}, {a: 2, b: 4} ], indexName = 'a', valueName = 'b')
//=>[ 3, 0, 4 ]
arr.createByArrObj(arrObj = [ { a: 3, b: 7},{a: 0, b: 3}, {a: 2, b: 4} ], indexName = 'a', valueName = 'b', length = 6)
//=>[ 3, 0, 4, 7, 0, 0 ]
arr.createByArrObj(arrObj = [ { a: 3, b: 7}, {a: 0, b: 3}, {a: 2, b: 4} ], indexName = 'a', valueName = 'b', length = 6, defaultValue = 666)
//=>[ 3, 666, 4, 7, 666, 666 ]
let src = [{city:'city1',total:0},{city:'city2',total:0}]
let dest = [{city:'city1',total:10},{city:'city2',total:0}]
arr.mergeObj(src,mergeName = 'city', dest)
//=> [{city:'city1',total:10},{city:'city2',total:0}]
//obj: reverse(), rename()
const obj = require('sp-data/object');
obj.reverse(obj = {a: 1, b: 2})
//=> {1: a, 2: b}
obj.reverse(obj = {a: 1, b: 2}, keyName = 'a')
//=> {1: a, b: 2}
obj.reverse(obj = [{a: 1, b: 2}, {a: 2, b: 3, d: 5}])
//=> [ { '1': 'a', '2': 'b' }, { '2': 'a', '3': 'b', '5': 'd' } ]
//last value will be the last key
obj.reverse(obj = [{a: 1, b: 2}, {a: 2, b: 3, c: 5, d: 5, e: 5}])
//=>[ { '1': 'a', '2': 'b' }, { '2': 'a', '3': 'b', '5': 'e' } ]
obj.reverse(obj = [{a: 1, b: 2}, {a: 2, b: 3, d: 5}], keyName = 'a')
//=> [ { '1': 'a', b: 2 }, { '2': 'a', b: 3, d: 5 } ]
//Object {}
obj.rename(obj = { a: 2, b: 3, c: 5, d: 5, e: 5 })
//=>{ a: 2, b: 3, c: 5, d: 5, e: 5 }
obj.rename(obj = { a: 2, b: 3, c: 5, d: 5, e: 5 }, target = 'a')
//=>{b: 3, c: 5, d: 5, e: 5 }
obj.rename(obj = { a: 2, b: 3, c: 5, d: 5, e: 5 }, target = 'a', replacer = 'x')
//=>{x:2, b: 3, c: 5, d: 5, e: 5 }
//Array of Objects
obj.rename(obj = [{ a: 2, b: 3}, {a: 3, b: 5}])
//=>[{ a: 2, b: 3}, {a: 3, b: 5}]
obj.rename(obj = [{ a: 2, b: 3}, {a: 3, b: 5}], 'a')
//=>[{b: 3}, {b: 5}
obj.rename(obj = [{ a: 2, b: 3, c: 4}, {a: 3, b: 5}], 'c', 'x')
//=>[{ a: 2, b: 3, x: 4}, {a: 3, b: 5}]
//parse: number(), bollean()
const parse = require('sp-data/parse');
//undefined, [] ,{} ,NaN ,'' ,' ', null or not number string return 0
parse.number(num = [], fixedLength = 0)
//=> 0
parse.number(num = {}, fixedLength = 2)
//=> 0.00
parse.number(num = 'a', fixedLength = 2)
//=> 0.00
parse.number(num = '2', fixedLength = 2)
//=> 2.00
parse.number(num = '2.000', fixedLength = 2)
//=> 2.00
//undefined, [] ,{} ,NaN ,'' ,' ', null return false
parse.boolean(0)
//=> false
//undefined, [] ,{} ,NaN ,'' ,' ', null return false
parse.boolean('a')
//=> true
//entity: encode(str), decode(str)
const entity = require('sp-data/entity');
entity.encode('1')
// 1
entity.decode('123')
// 123
MIT
FAQs
Common Data Trans methods for Date, Array, Object, Array of Objects etc.
The npm package sp-data receives a total of 6 weekly downloads. As such, sp-data popularity was classified as not popular.
We found that sp-data demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
/Security News
11 malicious NuGet tools pose as game cheats to deploy Windows payloads, track hosts, and use Google Sheets for telemetry and control.

Research
/Security News
4 compromised asyncapi packages deliver miasma botnet loader on macOS, Linux and Windows.

Research
/Security News
A compromised jscrambler npm release added a malicious preinstall hook that runs hidden native binaries on Linux, macOS, and Windows.