1.0.9 • Published 5 years ago
lesscript-core v1.0.9
Lesscript-core
Less code - more productivity
Installation
npm install lesscript-coreUsage
require('lesscript-core')()
log('hello Lesscript!!')Loops
repeat(x).do(action)
Repeat one action x times
require('lesscript-core')()
repeat(3).do(i => log(i)) Console output:
0
1
2from(x).to(y).do(action)
Repeat action from start number to end number
require('lesscript-core')()
from(5).to(10).do(index => log(index)) Console output:
5
6
7
8
9from(x).until(y).do(action)
Repeat action from start number to end number(inclusive)
require('lesscript-core')()
from(5).until(10).do(index => log(index)) Console output:
5
6
7
8
9
10each(array).do(action)
Repeat one action for each element of array
require('lesscript-core')()
each(['Mark', 'Tony', 'Carl']).do((el, index) => log(el, index)) Console output:
Mark 0
Tony 1
Carl 2Array operations
uniq(array, predicate): arrayWithNoDuplicateElements
Remove duplicates elements from array of string(or number)
require('lesscript-core')()
const arrayNames = ['Mark', 'Tony', 'Carl', 'Carl', 'Mark']
log(arrayNames)
const arrayUniqNames = uniq(arrayNames)
log(arrayUniqNames) Console output:
[ 'Mark', 'Tony', 'Carl', 'Carl', 'Mark' ]
[ 'Mark', 'Tony', 'Carl' ]Remove duplicates elements from array of objects
require('lesscript-core')()
const arrayNames = [{name: 'Mark', lastname: '3'}, {name: 'Tony', lastname: 'Stark'}, {name: 'Tony', lastname: 'Stark'}, {name: 'Tony', lastname: 'Stark'}]
log(arrayNames)
const isSamePerson = (pA, pB) => pA.name === pB.name
const arrayUniqNames = uniq(arrayNames, isSamePerson)
log(arrayUniqNames) Console output:
[
{ name: 'Mark', lastname: '3' },
{ name: 'Tony', lastname: 'Stark' },
{ name: 'Tony', lastname: 'Stark' },
{ name: 'Tony', lastname: 'Stark' }
]
[
{ name: 'Mark', lastname: '3' },
{ name: 'Tony', lastname: 'Stark' }
]sum(arrayOfNumbers)
Sum all numbers from array
require('lesscript-core')()
const result = sum([1, 2, 3])
log(result) Console output:
6Transformation
pipe(sourceData, functionA , functionB, functionC, etc) : transformedData
Transform a source data to a result data using a combination of functions
require('lesscript-core')()
const multiplyX2 = x => x * 2
const sum2 = x => x + 2
const formatResult = x => 'The result is ' + x
const result = pipe(7, multiplyX2, sum2, formatResult)
log(result) Console output:
The result is 16