SOITZ

Lodash 라이브러리 함수 정리

Published on

Lodash는 JavaScript의 유틸리티 라이브러리로, 데이터를 쉽고 효율적으로 처리할 수 있게 도와주는 다양한 함수를 제공합니다. 배열, 숫자, 객체, 문자열 등과 같은 다양한 데이터 타입을 처리할 수 있는 유용한 함수들을 제공합니다.

TypeScript 프로젝트에서 Lodash 사용하기

TypeScript 프로젝트에서 Lodash를 사용하기 위해, 먼저 npm을 통해 Lodash와 해당 TypeScript 타입 정의를 설치해야 합니다.

yarn add lodash
yarn add -D @types/lodash
# 또는
npm install lodash
npm install -D @types/lodash

함수 정리

Array

_.chunk(array, [size=1])

배열을 특정 크기의 청크로 나눕니다.

_.chunk(['a', 'b', 'c', 'd', 'e', 'f'], 2);
// => [['a', 'b'], ['c', 'd'], ['e', 'f']]

_.compact(array)

배열에서 거짓 값(false, null, 0, "", undefined, NaN)을 제거합니다.

_.compact([0, 1, false, 2, '', 3]);
// => [1, 2, 3]

_.concat(array, [values])

배열에 값을 연결합니다.

_.concat<number | number[]>([1], 2, [3], [[4]]);
// => [1, 2, 3, [4]]`

_.difference(array, [values])

첫 번째 배열에서 두 번째 배열에 없는 값을 반환합니다.

_.difference([2, 1], [2, 3]);
// => [1]

_.drop(array, [n=1])

배열의 앞에서부터 n개의 요소를 제거합니다.

_.drop([1, 2, 3], 2);
// => [3]

_.dropRight(array, [n=1])

배열의 뒤에서부터 n개의 요소를 제거합니다.

_.dropRight([1, 2, 3], 2);
// => [1]

_.fill(array, value, [start=0], [end=array.length])

배열의 범위를 지정된 값으로 채웁니다.

_.fill(Array(3), 2);
// => [2, 2, 2]

_.findIndex(array, [predicate=_.identity], [fromIndex=0])

조건을 만족하는 배열의 첫 번째 요소의 인덱스를 반환합니다.

const users = [
  { user: 'barney', active: false },
  { user: 'fred', active: false },
  { user: 'pebbles', active: true },
];
_.findIndex(users, function (o) {
  return o.user == 'barney';
});
// => 0

_.findLastIndex(array, [predicate=_.identity], [fromIndex=array.length-1])

뒤에서부터 조건을 만족하는 배열의 요소 인덱스를 찾습니다.

_.findLastIndex([1, 2, 3, 4], function (n) {
  return n % 2 == 1;
});
// => 2 (인덱스 2는 값 3에 해당합니다)

_.flatten(array)

배열을 한 단계 평탄화합니다.

_.flatten([1, [2, [3, [4]], 5]]);
// => [1, 2, [3, [4]], 5]

_.flattenDeep(array)

배열을 재귀적으로 완전히 평탄화합니다.

_.flattenDeep([1, [2, [3, [4]], 5]]);
// => [1, 2, 3, 4, 5]

_.flattenDepth(array, [depth=1])

배열을 지정된 깊이만큼 평탄화합니다.

_.flattenDepth([1, [2, [3, [4]], 5]], 2);
// => [1, 2, 3, [4], 5]

_.fromPairs(pairs)

키-값 쌍의 배열을 객체로 변환합니다.

_.fromPairs([
  ['a', 1],
  ['b', 2],
]);
// => { 'a': 1, 'b': 2 }

_.head(array)

배열의 첫 번째 요소를 반환합니다.

_.head([1, 2, 3]);
// => 1

_.indexOf(array, value, [fromIndex=0])

지정된 값의 첫 번째 인덱스를 반환합니다. 값을 찾지 못하면 -1을 반환합니다.

_.indexOf([1, 2, 1, 2], 2);
// => 1

_.initial(array)

배열의 마지막 요소를 제외한 모든 요소를 반환합니다.

_.initial([1, 2, 3]);
// => [1, 2]

_.intersection([arrays])

모든 배열에 공통으로 존재하는 요소를 반환합니다.

_.intersection([2, 1], [2, 3]);
// => [2]

_.join(array, [separator=','])

배열의 모든 요소를 연결하여 문자열로 반환합니다.

_.join(['a', 'b', 'c'], '~');
// => 'a~b~c'

_.last(array)

배열의 마지막 요소를 반환합니다.

_.last([1, 2, 3]);
// => 3

_.nth(array, [n=0])

배열에서 n번째 요소를 가져옵니다. n이 음수인 경우 끝에서부터의 요소를 가져옵니다.

_.nth(['a', 'b', 'c', 'd'], -2);
// => 'c'

_.pull(array, [values])

배열에서 지정된 값을 모두 제거합니다.

const array = ['a', 'b', 'c', 'a', 'b', 'c'];
_.pull(array, 'a', 'c');
// => array: ['b', 'b']

_.pullAll(array, values)

배열에서 주어진 값들을 모두 제거합니다.

const array = ['a', 'b', 'c', 'a', 'b', 'c'];
_.pullAll(array, ['a', 'c']);
// => array: ['b', 'b']

_.remove(array, predicate=_.identity)

배열에서 조건을 만족하는 모든 요소를 제거하고 제거된 요소들을 배열로 반환합니다.

const array = [1, 2, 3, 4];
const evens = _.remove(array, (n) => n % 2 == 0);
// => evens: [2, 4]
// => array: [1, 3]

_.reverse(array)

배열의 순서를 반전합니다.

_.reverse([1, 2, 3]);
// => [3, 2, 1]

_.slice(array, [start=0], [end=array.length])

배열의 일부분을 추출합니다.

_.slice([1, 2, 3, 4], 1, 3);
// => [2, 3]

_.sortedIndex(array, value)

값이 삽입될 때 배열의 정렬 순서를 유지할 수 있는 인덱스를 반환합니다.

_.sortedIndex([30, 50], 40);
// => 1

_.sortedUniq(array)

정렬된 배열에서 중복된 값을 제거한 후 유니크한 값들만 남깁니다.

_.sortedUniq([1, 1, 2]);
// => [1, 2]

_.tail(array)

배열의 첫 번째 요소를 제외한 나머지 요소들을 반환합니다.

_.tail([1, 2, 3]);
// => [2, 3]

_.take(array, [n=1])

배열에서 n개의 요소를 처음부터 추출합니다.

_.take([1, 2, 3], 2);
// => [1, 2]

_.takeRight(array, [n=1])

배열에서 n개의 요소를 끝에서부터 추출합니다.

_.takeRight([1, 2, 3], 2);
// => [2, 3]

_.union([arrays])

모든 배열의 유니크한 값을 합칩니다.

_.union([2], [1, 2]);
// => [2, 1]

_.uniq(array)

배열에서 중복 값을 제거합니다.

_.uniq([2, 1, 2]);
// => [2, 1]

_.uniqBy(array, [iteratee])

배열에서 각 요소를 iteratee 함수를 적용한 결과가 유니크한 요소만을 남깁니다.

_.uniqBy([2.1, 1.2, 2.3], Math.floor);
// => [2.1, 1.2]

_.unzip(array)

zip으로 묶인 배열의 구조를 해체합니다.

_.unzip([
  ['a', 1, true],
  ['b', 2, false],
]);
// => [['a', 'b'], [1, 2], [true, false]]

_.without(array, [values])

배열에서 제공된 값들을 제외한 나머지를 반환합니다.

_.without([2, 1, 2, 3], 1, 2);
// => [3]

_.xor([arrays])

주어진 배열들 간의 대칭 차집합을 반환합니다.

_.xor([2, 1], [2, 3]);
// => [1, 3]

_.zip([arrays])

주어진 배열들의 같은 인덱스를 가진 요소들을 그룹으로 묶어 새로운 배열을 생성합니다.

_.zip(['a', 'b'], [1, 2], [true, false]);
// => [['a', 1, true], ['b', 2, false]]

_.zipObject([props=[]], [values=[]])

두 배열을 받아 하나는 속성명, 다른 하나는 속성값으로 객체를 생성합니다.

_.zipObject(['a', 'b'], [1, 2]);
// => { 'a': 1, 'b': 2 }

Collection

_.countBy(collection, [iteratee=_.identity])

컬렉션의 각 요소에 대해 iteratee 함수의 결과값을 카운트하여 객체로 반환합니다.

_.countBy([6.1, 4.2, 6.3], Math.floor);
// => { '4': 1, '6': 2 }

_.every(collection, [predicate=_.identity])

컬렉션의 모든 요소가 조건을 만족하는지 확인합니다.

_.every([true, 1, null, 'yes'], Boolean);
// => false

_.filter(collection, [predicate=_.identity])

조건을 만족하는 컬렉션의 모든 요소를 배열로 반환합니다.

const users = [
  { user: 'barney', active: true },
  { user: 'fred', active: false },
];
_.filter(users, function (o) {
  return !o.active;
});
// => objects for ['fred']

_.find(collection, [predicate=_.identity], [fromIndex=0])

컬렉션에서 조건을 만족하는 첫 번째 요소를 찾아 반환합니다.

const users = [
  { user: 'barney', age: 36, active: true },
  { user: 'fred', age: 40, active: false },
];
_.find(users, function (o) {
  return o.age < 40;
});
// => object for 'barney'

_.findLast(collection, [predicate=_.identity], [fromIndex=collection.length-1])

뒤에서부터 조건을 만족하는 첫 번째 요소를 찾아 반환합니다.

_.findLast([1, 2, 3, 4], (n) => n % 2 == 1);
// => 3

_.forEach(collection, [iteratee=_.identity])

컬렉션(배열, 객체)의 각 요소에 대해 iteratee 함수를 실행합니다.

_.forEach([1, 2], (value) => console.log(value));
// => Logs `1` then `2`.

_.groupBy(collection, [iteratee=_.identity])

컬렉션을 iteratee 함수의 결과에 따라 그룹화합니다.

_.groupBy([6.1, 4.2, 6.3], Math.floor);
// => { '4': [4.2], '6': [6.1, 6.3] }

_.keyBy(collection, [iteratee=_.identity])

컬렉션의 각 요소를 iteratee 함수의 결과를 키로 사용하여 객체로 변환합니다.

const array = [
  { dir: 'left', code: 97 },
  { dir: 'right', code: 100 },
];
_.keyBy(array, function (o) {
  return String.fromCharCode(o.code);
});
// => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }

_.map(collection, iteratee=_.identity)

컬렉션의 각 요소에 대해 iterate 함수를 실행한 결과를 배열로 반환합니다.

_.map([4, 8], (n) => n * n);
// => [16, 64]

_.orderBy(collection, [iteratees=[_.identity]], [orders])

컬렉션을 정렬합니다.

const users = [
  { user: 'fred', age: 48 },
  { user: 'barney', age: 34 },
  { user: 'fred', age: 40 },
  { user: 'barney', age: 36 },
];
// Sort by `user` in ascending order and then by `age` in descending order.
_.orderBy(users, ['user', 'age'], ['asc', 'desc']);
// => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]

_.partition(collection, [predicate=_.identity])

조건 함수에 따라 컬렉션을 두 개의 배열로 나눕니다.

_.partition([1, 2, 3, 4], (n) => n % 2);
// => [[1, 3], [2, 4]]

_.reduce(collection, iteratee=_.identity, [accumulator])

컬렉션을 순회하면서 각 요소에 대해 iteratee 함수를 실행하고, 하나의 값으로 줄입니다.

_.reduce([1, 2], (sum, n) => sum + n, 0);
// => 3

_.reduceRight(collection, iteratee=_.identity, [accumulator])

오른쪽부터 시작하여 컬렉션의 각 요소를 축소합니다.

const array = [
  [0, 1],
  [2, 3],
  [4, 5],
];

_.reduceRight(
  array,
  function (flattened: number[], other: number[]) {
    return flattened.concat(other);
  },
  [] as number[],
);
// => [4, 5, 2, 3, 0, 1]`

_.sample(collection)

컬렉션에서 랜덤하게 하나의 요소를 반환합니다.

_.sample([1, 2, 3, 4, 5]);
// => 2 (예시입니다. 실제 결과는 실행할 때마다 달라집니다.)

_.sampleSize(collection, n=1)

컬렉션에서 랜덤하게 요소를 n개만큼 선택합니다.

_.sampleSize([1, 2, 3, 4, 5], 2);
// => [3, 1] (예시입니다. 실제 결과는 실행할 때마다 달라집니다.)

_.shuffle(collection)

컬렉션의 요소들을 무작위로 섞습니다.

_.shuffle([1, 2, 3, 4]);
// => [4, 1, 3, 2] (shuffle 결과는 실행할 때마다 다를 수 있습니다)

_.size(collection)

컬렉션의 길이(배열인 경우) 또는 속성의 개수(객체인 경우)를 반환합니다.

_.size({ a: 1, b: 2 });
// => 2

_.some(collection, [predicate=_.identity])

컬렉션의 요소 중 하나라도 조건을 만족하는지 확인합니다.

_.some([null, 0, 'yes', false], Boolean);
// => true

_.sortBy(collection, [iteratees=[_.identity]])

컬렉션을 iteratee 함수의 결과에 따라 오름차순으로 정렬합니다.

const users = [
  { user: 'fred', age: 48 },
  { user: 'barney', age: 36 },
  { user: 'fred', age: 40 },
  { user: 'barney', age: 34 },
];

_.sortBy(users, [
  function (o) {
    return o.user;
  },
]);
// => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]

Function

_.delay(func, wait, [args])

함수 실행을 지정된 밀리초만큼 지연시킵니다.

_.delay(
  function (text) {
    console.log(text);
  },
  1000,
  'later',
);
// => Logs 'later' after one second.

_.flip(func)

함수의 인수의 순서를 뒤집습니다.

const flipped: (...args: any[]) => any[] = _.flip(function () {
  return _.toArray(arguments);
});
flipped('a', 'b', 'c', 'd');
// => ['d', 'c', 'b', 'a']

_.memoize(func, [resolver])

함수의 결과를 메모이징하여 동일한 인수로 호출될 때 이전에 계산된 결과를 반환합니다.

const fibonacci: (n: number) => number = _.memoize(function (
  n: number,
): number {
  // 재귀 호출은 타입이 명시된 외부 변수 fibonacci를 사용
  return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2);
});
fibonacci(10); // 계산 결과를 메모리에 저장
// => 55

_.negate(predicate)

조건 함수의 반환값을 반전시킵니다.

function isEven(n) {
  return n % 2 == 0;
}
_.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
// => [1, 3, 5]

_.once(func)

함수를 한 번만 호출할 수 있도록 제한합니다.

function createApplication() {
  console.log('createApplication');
}
const initialize = _.once(createApplication);
initialize();
initialize();
// `createApplication`은 단 한 번만 호출됩니다.``

Lang

_.cloneDeep(value)

값의 깊은 복사본을 생성합니다. 객체와 배열에 대해 깊은 복사를 수행합니다.

const objects = [{ a: 1 }, { b: 2 }];
const deep = _.cloneDeep(objects);
console.log(deep[0] === objects[0]);
// => false

_.isEqual(value, other)

두 값이 동등한지 여부를 판단합니다. 객체와 배열의 깊은 비교를 수행할 수 있습니다.

const object = { a: 1 };
const other = { a: 1 };
_.isEqual(object, other);
// => true

_.toInteger(value)

값을 정수로 변환합니다.

_.toInteger('3.2');
// => 3

_.toNumber(value)

주어진 값을 숫자로 변환합니다. 변환할 수 없는 경우 NaN을 반환합니다.

_.toNumber('3.14');
// => 3.14

_.toString(value)

주어진 값을 문자열로 변환합니다. null이나 undefined는 빈 문자열로 변환됩니다.

_.toString(null);
// => ''

Math

_.sum(array)

배열의 합계를 계산합니다.

_.sum([4, 2, 8, 6]);
// => 20

Number

_.clamp(number, [lower], upper)

숫자를 lower와 upper 사이의 값으로 제한합니다. lower가 생략되면 0과 upper 사이로 제한합니다.

_.clamp(-10, -5, 5);
// => -5

_.inRange(number, [start=0], end)

숫자가 특정 범위 내에 있는지 확인합니다. start가 end보다 크면 두 값의 범위가 반전됩니다.

_.inRange(3, 2, 4);
// => true

_.random([lower=0], [upper=1], [floating=false])

lower와 upper 사이의 무작위 숫자를 반환합니다. floating이 true면 소수점 결과를 반환합니다.

_.random(0, 5, true);
// => 3.509 (결과는 실행할 때마다 달라집니다)

Object

_.assign(object, [sources])

소스 객체의 자체 열거 가능한 속성을 대상 객체에 할당합니다. 할당은 소스 객체의 순서대로 수행됩니다.

_.assign({ a: 0 }, { a: 1 }, { b: 2 });
// => { 'a': 1, 'b': 2 }

_.defaults(object, [sources])

소스 객체들의 속성을 대상 객체에 할당합니다. 대상 객체에 이미 해당 키가 존재하면 무시됩니다.

_.defaults({ a: 1 }, { b: 2 }, { a: 3 });
// => { 'a': 1, 'b': 2 }

_.findKey(object, [predicate=_.identity])

조건을 만족하는 객체의 첫 번째 키를 반환합니다.

const users = {
  barney: { age: 36, active: true },
  fred: { age: 40, active: false },
};
_.findKey(users, function (o) {
  return o.age < 40;
});
// => 'barney'

_.get(object, path, [defaultValue])

객체의 path에 해당하는 값을 가져옵니다. 값이 없는 경우 기본값을 반환할 수 있습니다.

const object = { a: [{ b: { c: 3 } }] };
_.get(object, 'a[0].b.c');
// => 3

_.has(object, path)

객체가 특정 경로의 속성을 가지고 있는지 확인합니다.

const object = { a: { b: { c: 3 } } };
_.has(object, 'a.b.c');
// => true

_.invert(object)

객체의 키와 값을 서로 바꿉니다.

_.invert({ one: 1, two: 2, three: 3 });
// => { '1': 'one', '2': 'two', '3': 'three' }

_.invoke(object, path, [args])

객체의 경로에 해당하는 메소드를 호출합니다.

const object = { a: [{ b: { c: [1, 2, 3, 4] } }] };
_.invoke(object, 'a[0].b.c.slice', 1, 3);
// => [2, 3]

_.keys(object)

객체의 모든 키를 배열로 반환합니다.

_.keys({ one: 1, two: 2, three: 3 });
// => ['one', 'two', 'three']

_.mapKeys(object, [iteratee=_.identity])

객체의 키를 iteratee 함수의 결과로 재구성합니다.

const users = { fred: { user: 'fred', age: 40 } };
_.mapKeys(users, (value, key) => key + value.age);
// => { 'fred40': { 'user': 'fred', 'age': 40 } }

_.mapValues(object, [iteratee=_.identity])

객체의 값을 iteratee 함수의 결과로 재구성합니다.

const users = { fred: { age: 40 }, pebbles: { age: 1 } };
_.mapValues(users, (o) => o.age);
// => { 'fred': 40, 'pebbles': 1 }

_.merge(object, [sources])

두 개 이상의 객체를 병합합니다. 충돌하는 속성은 뒤의 객체에서 가져온 값으로 덮어씁니다.

const object = { a: [{ b: 2 }, { d: 4 }] };
const other = { a: [{ c: 3 }, { e: 5 }] };
_.merge(object, other);
// => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }

_.mergeWith(object, sources, customizer)

두 개 이상의 객체를 병합할 때 커스텀 병합 함수를 사용합니다.

function customizer(objValue: any, srcValue: any) {
  if (_.isArray(objValue)) {
    return objValue.concat(srcValue);
  }
}
const object = { a: [1], b: [2] };
const other = { a: [3], b: [4] };
_.mergeWith(object, other, customizer);
// => { 'a': [1, 3], 'b': [2, 4] }

_.omit(object, [paths])

객체에서 지정된 경로의 속성을 제외한 복사본을 반환합니다.

const object = { a: 1, b: '2', c: 3 };
_.omit(object, ['a', 'c']);
// => { 'b': '2' }

_.pick(object, [paths])

객체에서 지정된 속성만을 포함하는 객체를 반환합니다.

const object = { a: 1, b: '2', c: 3 };
_.pick(object, ['a', 'c']);
// => { 'a': 1, 'c': 3 }

_.set(object, path, value)

객체의 path에 값을 설정합니다. 필요한 경우 중간 객체들을 생성합니다.

const object = { a: [{ b: { c: 3 } }] };
_.set(object, 'a[0].b.d', 4);
console.log(object);
// => { 'a': [{ 'b': { 'c': 3, 'd': 4 } }] }

_.toPairs(object)

객체의 [키, 값] 쌍의 배열을 반환합니다.

_.toPairs({ one: 1, two: 2, three: 3 });
// => [['one', 1], ['two', 2], ['three', 3]]

_.unset(object, path)

객체의 지정된 경로에 해당하는 속성을 제거합니다.

const object = { a: [{ b: { c: 7 } }] };
_.unset(object, 'a[0].b.c');
// => true

_.update(object, path, updater)

객체의 지정된 경로에 해당하는 속성을 업데이트합니다. 업데이트 함수가 제공됩니다.

var object = { a: [{ b: { c: 3 } }] };
_.update(object, 'a[0].b.c', (n) => n * n);
console.log(object);
// => { 'a': [{ 'b': { 'c': 9 } }] }

_.values(object)

객체의 모든 값을 배열로 반환합니다.

_.values({ one: 1, two: 2, three: 3 });
// => [1, 2, 3]

String

_.capitalize(string)

문자열의 첫 글자를 대문자로 변환하고 나머지는 소문자로 변환합니다.

_.capitalize('FRED');
// => 'Fred'

_.deburr([string=''])

문자열에서 diacritical marks(예: ü => u)를 제거합니다.

_.deburr('déjà vu');
// => 'deja vu'

_.endsWith(string, target, [position=string.length])

문자열이 특정 문자로 끝나는지 확인합니다.

_.endsWith('abc', 'c');
// => true

_.escape(string)

문자열에서 HTML 엔티티를 이스케이프합니다.

_.escape('fred, barney, & pebbles');
// => 'fred, barney, &amp; pebbles'

_.kebabCase(string)

문자열을 kebab-case로 변환합니다.

_.kebabCase('Foo Bar');
// => 'foo-bar'

_.lowerCase(string)

문자열을 소문자로 변환하고, 단어들은 공백으로 구분합니다.

_.lowerCase('--Foo-Bar--');
// => 'foo bar'

_.pad(string, [length=0], [chars=' '])

문자열을 지정된 길이가 되도록 양쪽에서 패딩합니다.

_.pad('abc', 8);
// => ' abc '

_.repeat(string, [n=1])

문자열을 지정된 횟수만큼 반복한 새 문자열을 반환합니다.

_.repeat('*', 3);
// => '***'

_.replace(string, pattern, replacement)

문자열에서 패턴에 매칭되는 부분을 다른 문자열로 교체합니다.

_.replace('Hi Fred', 'Fred', 'Barney');
// => 'Hi Barney'

_.split(string, separator, [limit])

문자열을 구분자에 따라 분할하여 배열로 반환합니다.

_.split('a-b-c', '-', 2);
// => ['a', 'b']

_.startsWith(string, target, [position=0])

문자열이 특정 문자로 시작하는지 확인합니다.

_.startsWith('abc', 'a');
// => true

_.toLower(string)

문자열의 모든 문자를 소문자로 변환합니다.

_.toLower('--Foo-Bar--');
// => '--foo-bar--'

_.toUpper(string)

문자열의 모든 문자를 대문자로 변환합니다.

_.toUpper('--foo-bar--');
// => '--FOO-BAR--'

_.trim(string, [chars=whitespace])

문자열 양쪽의 공백 또는 지정된 문자들을 제거합니다.

_.trim('  abc  ');
// => 'abc'

_.trimEnd(string, [chars=whitespace])

문자열 뒤쪽의 공백 또는 지정된 문자들을 제거합니다.

_.trimEnd('  abc  ');
// => '  abc'

_.trimStart(string, [chars=whitespace])

문자열 앞쪽의 공백 또는 지정된 문자들을 제거합니다.

_.trimStart('  abc  ');
// => 'abc  '

_.upperCase(string)

문자열을 대문자로 변환하고, 단어들은 공백으로 구분합니다.

_.upperCase('--foo-bar');
// => 'FOO BAR'

_.upperCase(string)

문자열을 대문자로 변환하고, 단어들은 공백으로 구분합니다.

_.upperCase('--foo-bar');
// => 'FOO BAR'

Util

_.flow([funcs])

여러 함수를 연결하여 새로운 함수를 생성합니다. 첫 번째 함수의 반환값은 두 번째 함수의 입력값이 됩니다.

function square(n: number) {
  return n * n;
}
const addSquare = _.flow([_.add, square]);
addSquare(1, 2);
// => 9

참고