11/** @module common */ /** for typedoc */
2- import { isDefined , isFunction , isNumber , isString , isObject , isArray , isRegExp , isDate } from "./predicates" ;
2+
3+ import { isFunction , isString , isArray , isRegExp , isDate } from "./predicates" ;
4+ import { all , pattern , any , not , prop , curry , val } from "./hof" ;
35
46let angular = ( < any > window ) . angular ;
57export const fromJson = angular && angular . fromJson || _fromJson ;
@@ -11,10 +13,6 @@ export const equals = angular && angular.equals || _equals;
1113export const identity = ( x ) => x ;
1214export const noop = ( ) => undefined ;
1315
14- export * from "./hof" ;
15- import { all , pattern , and , any , not , prop , curry , pipe , val } from "./hof" ;
16- export { isDefined , isFunction , isNumber , isString , isObject , isArray } ;
17-
1816type Mapper < X , T > = ( x : X , key ?: ( string | number ) ) => T ;
1917export interface TypedMap < T > { [ key : string ] : T ; }
2018export type Predicate < X > = ( X ) => boolean ;
@@ -87,7 +85,8 @@ export function bindFunctions(from, to, bindTo, fnNames: string[] = Object.keys(
8785 * prototypal inheritance helper.
8886 * Creates a new object which has `parent` object as its prototype, and then copies the properties from `extra` onto it
8987 */
90- export const inherit = ( parent , extra ) => extend ( new ( extend ( function ( ) { } , { prototype : parent } ) ) ( ) , extra ) ;
88+ export const inherit = ( parent , extra ) =>
89+ extend ( new ( extend ( function ( ) { } , { prototype : parent } ) ) ( ) , extra ) ;
9190
9291/**
9392 * Given an arguments object, converts the arguments at index idx and above to an array.
@@ -401,9 +400,9 @@ export const flatten = (arr: any[]) => arr.reduce(flattenR, []);
401400 * oneString.filter(assertPredicate(isNumber, "Not all numbers")); // throws Error(""Not all numbers"");
402401 * ```
403402 */
404- export function assertPredicate < T > ( fn : Predicate < T > , errMsg : string = "assert failure" ) : Predicate < T > {
403+ export function assertPredicate < T > ( fn : Predicate < T > , errMsg : ( string | Function ) = "assert failure" ) : Predicate < T > {
405404 return ( obj : T ) => {
406- if ( ! fn ( obj ) ) throw new Error ( errMsg ) ;
405+ if ( ! fn ( obj ) ) throw new Error ( isFunction ( errMsg ) ? ( < Function > errMsg ) ( obj ) : errMsg ) ;
407406 return true ;
408407 } ;
409408}
@@ -467,29 +466,6 @@ export function applyPairs(memo: TypedMap<any>, keyValTuple: any[]) {
467466 return memo ;
468467}
469468
470- /**
471- * Predicate which checks if a value is injectable
472- *
473- * A value is "injectable" if it is a function, or if it is an ng1 array-notation-style array
474- * where all the elements in the array are Strings, except the last one, which is a Function
475- */
476- export function isInjectable ( val ) {
477- if ( isArray ( val ) && val . length ) {
478- let head = val . slice ( 0 , - 1 ) , tail = val . slice ( - 1 ) ;
479- return ! ( head . filter ( not ( isString ) ) . length || tail . filter ( not ( isFunction ) ) . length ) ;
480- }
481- return isFunction ( val ) ;
482- }
483- /** Predicate which checks if a value is `=== null` */
484- export const isNull = o => o === null ;
485-
486- /**
487- * Predicate which checks if a value looks like a Promise
488- *
489- * It is probably a Promise if it's an object, and it has a `then` property which is a Function
490- */
491- export const isPromise = and ( isObject , pipe ( prop ( 'then' ) , isFunction ) ) ;
492-
493469export function fnToString ( fn : IInjectable ) {
494470 let _fn = pattern ( [
495471 [ isArray , arr => arr . slice ( - 1 ) [ 0 ] ] ,
@@ -559,8 +535,11 @@ function _forEach(obj: (any[]|any), cb, _this) {
559535 Object . keys ( obj ) . forEach ( key => cb ( obj [ key ] , key ) ) ;
560536}
561537
562- function _extend ( to , from ) {
563- return ! from ? to : Object . keys ( from ) . reduce ( ( m , key ) => { m [ key ] = from [ key ] ; return m ; } , to ) ;
538+ function _copyProps ( to , from ) { Object . keys ( from ) . forEach ( key => to [ key ] = from [ key ] ) ; return to ; }
539+ function _extend ( toObj , fromObj ) ;
540+ function _extend ( toObj , ...fromObj ) ;
541+ function _extend ( toObj , rest ) {
542+ return restArgs ( arguments , 1 ) . filter ( identity ) . reduce ( _copyProps , toObj ) ;
564543}
565544
566545function _equals ( o1 , o2 ) {
0 commit comments