@@ -43,6 +43,11 @@ export const MAX_CODE_POINT: number = 0x10FFFF;
43
43
function IDENTITY < T > ( v : T ) : T {
44
44
return v ;
45
45
}
46
+
47
+
48
+ function mod ( x : number , y : number ) : number {
49
+ return x - y * Math . floor ( x / y ) ;
50
+ }
46
51
//#endregion
47
52
48
53
@@ -332,6 +337,7 @@ export function substring(x: string, start: number, end?: number): string {
332
337
export function split ( x : string , separator ?: string | RegExp , limit ?: number ) : string [ ] {
333
338
return x . split ( separator as string | RegExp , limit ) ;
334
339
}
340
+ // splitBy(x: string, separator: function, limit?: number): string[]?
335
341
//#endregion
336
342
337
343
@@ -1385,6 +1391,7 @@ export function toWords(x: string, re: RegExp | null=null): string[] {
1385
1391
}
1386
1392
return words ;
1387
1393
}
1394
+ // NOTE: Shouldn't this be called splitWords() or splitIntoWords() or splitIntoTokens()?
1388
1395
1389
1396
1390
1397
/**
@@ -1504,34 +1511,34 @@ export {toSlugCase as slugify};
1504
1511
1505
1512
1506
1513
1507
- //#region TRANSFORM (TODO)
1514
+ //#region TRANSFORM
1508
1515
/**
1509
1516
* Get characters that cycle through string.
1510
1517
* @param x a string
1511
1518
* @param start start index
1512
1519
* @param count number of characters [length]
1513
1520
*/
1514
- // function cycle(x: string, start: number, count: number=x.length): string {
1515
- // let X = x.length;
1516
- // if(count<=0 || X===0) return "";
1517
- // let start = index(x, start);
1518
- // let a = x.slice(start, start+count);
1519
- // count -= a.length;
1520
- // for(let m=0, M=Math.floor(count/X); m<M; m++)
1521
- // a += x;
1522
- // return a += x.slice(0, count % X);
1523
- // }
1521
+ export function cycle ( x : string , start : number , count : number = x . length ) : string {
1522
+ if ( ! x || count <= 0 ) return "" ;
1523
+ let a = x . slice ( start , start + count ) ;
1524
+ count -= a . length ; // start = index(x, start);
1525
+ const M = Math . floor ( count / x . length ) ;
1526
+ for ( let m = 0 ; m < M ; m ++ )
1527
+ a += x ;
1528
+ return a += x . slice ( 0 , count % x . length ) ;
1529
+ }
1524
1530
1525
1531
1526
1532
/**
1527
1533
* Rotate characters in string.
1528
1534
* @param x a string
1529
1535
* @param n rotate amount (+ve: left, -ve: right)
1530
1536
*/
1531
- // function rotate(x: string, n: number): string {
1532
- // let i = mod(n, x.length);
1533
- // return x.slice(i) + x.slice(0, i);
1534
- // }
1537
+ export function rotate ( x : string , n : number ) : string {
1538
+ const i = mod ( n , x . length ) ;
1539
+ return x . slice ( i ) + x . slice ( 0 , i ) ;
1540
+ }
1541
+
1535
1542
1536
1543
// function replacePrefix(str, pre, rep) {
1537
1544
// return str.startsWith(pre)? rep+str.substr(pre.length):str;
@@ -1559,7 +1566,6 @@ export {toSlugCase as slugify};
1559
1566
1560
1567
// swapRange()
1561
1568
1562
-
1563
1569
// import {cutAt as arrayCut} from "extra-array";
1564
1570
1565
1571
/**
@@ -1582,8 +1588,6 @@ export {toSlugCase as slugify};
1582
1588
// return arrayCutRight(x as any, is as any) as any;
1583
1589
// }
1584
1590
1585
-
1586
-
1587
1591
// function unionCompare(x: string, y: string, fn: any=null): string {
1588
1592
// // let fn = fn||cmp;
1589
1593
// let s = new Set<string>();
0 commit comments